GetAvailableShippingMethods
Implements GetAvailableShippingMethods
Unified Method.
Source
import { defineApi, getShipmentId } from "@vsf-enterprise/unified-api-sfcc";
import { type SfShippingMethod, getNormalizers } from "@vsf-enterprise/unified-api-sfcc/udl";
declare module "@vsf-enterprise/unified-api-sfcc" {
interface GetAvailableShippingMethodsExtendedArgs {}
}
export const getAvailableShippingMethods = defineApi.getAvailableShippingMethods(
async (context) => {
const shipmentId = getShipmentId(context);
const { normalizeShippingMethod } = getNormalizers(context);
const { applicableShippingMethods } = await context.api.getApplicableShippingMethods({
shipmentId,
});
let methods: SfShippingMethod[] = [];
if (applicableShippingMethods) {
methods = applicableShippingMethods
.map((shippingMethod) => normalizeShippingMethod(shippingMethod))
.filter(Boolean);
}
return { methods };
},
);