@scayle/storefront-core
Version:
Collection of essential utilities to work with the Storefront API
23 lines (22 loc) • 781 B
JavaScript
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
import { defineRpcHandler } from "../../utils/rpc.mjs";
const defaultWith = {
attributes: "all"
};
export const getVariantById = defineRpcHandler(
async ({ ids, include = defaultWith, pricePromotionKey = "default" }, context) => {
const { sapiClient, cached, withParams } = context;
const campaignKey = await context.callRpc?.("getCampaignKey");
const resolvedWith = include ?? withParams?.variant ?? defaultWith;
return await cached(
mapSAPIFetchErrorToResponse(sapiClient.variants.getByIds),
{
cacheKeyPrefix: "getByIds-variants"
}
)(
ids,
include ? { with: resolvedWith, campaignKey, pricePromotionKey } : void 0
);
},
{ method: "GET" }
);