HEX
Server: LiteSpeed
System: Linux premium127.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User: luxbsolr (925)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: /home/luxbsolr/cardsord.store/wp-content/plugins/woocommerce-shipping/client/utils/package.ts
import { mapValues } from 'lodash';
import { AvailablePackages, CamelCaseType, CustomPackageResponse } from 'types';
import { camelCaseKeys } from './common';

export const camelCasePackageResponse = ( packages: {
	custom: CustomPackageResponse[];
	predefined: Record< string, string[] >;
} ) =>
	mapValues( packages, ( value, key ) => {
		if ( key === 'custom' ) {
			return ( value as CustomPackageResponse[] ).map(
				( v: CustomPackageResponse ) => camelCaseKeys( v )
			);
		}
		return value;
	} ) as {
		custom: CamelCaseType< CustomPackageResponse >[];
		predefined: Record< string, string[] >;
	};

export const getSelectedCarrierIdFromPackage = (
	availablePackages: AvailablePackages,
	packageId: string
) =>
	Object.entries( availablePackages ).find( ( [ , groups ] ) =>
		Object.values( groups )
			.map( ( group ) => group.definitions )
			.flat()
			.map( ( { id } ) => id )
			.includes( packageId )
	)?.[ 0 ];