GetAvailableShippingMethods
Implements GetAvailableShippingMethods
Unified Method.
Source
import { getCartId, defineApi } from "@vsf-enterprise/unified-api-sapcc";
import { getNormalizers } from "@vsf-enterprise/unified-api-sapcc/udl";
declare module "@vsf-enterprise/unified-api-sapcc" {
interface GetAvailableShippingMethodsExtendedArgs {
/**
* Response configuration. List of fields returned in the response body.
*/
fields?: "BASIC" | "DEFAULT" | "FULL" | string | string[];
}
}
export const getAvailableShippingMethods = defineApi.getAvailableShippingMethods(
async (context) => {
const cartId = getCartId(context);
const { normalizeShippingMethod } = getNormalizers(context);
try {
const { data } = await context.api.getCartDeliveryModes({ cartId });
return {
methods:
data.deliveryModes
?.map((deliveryMode) => normalizeShippingMethod(deliveryMode))
.filter(Boolean) ?? [],
};
} catch {
throw new Error("Error getting available shipping methods");
}
},
);