GetCustomerAddresses
Implements GetCustomerAddresses
Unified Method.
Source
import { assertAuthorized, defineApi, query } from "@vsf-enterprise/unified-api-magento";
import type { CustomerAddressInput } from "@vsf-enterprise/unified-api-magento/ecommerceTypes";
import { getNormalizers } from "@vsf-enterprise/unified-api-magento/udl";
export const getCustomerAddresses = defineApi.getCustomerAddresses(async (context) => {
await assertAuthorized(context);
const addresses = await query(context.api.getCustomerAddresses());
const { normalizeCustomerAddress } = getNormalizers(context);
return {
addresses:
addresses.customer?.addresses
?.filter(Boolean)
.map((address) => normalizeCustomerAddress(address as CustomerAddressInput)) || [],
};
});