@scayle/storefront-core
Version:
Collection of essential utilities to work with the Storefront API
37 lines (36 loc) • 1.22 kB
TypeScript
import type { ProductWith, VariantDetail } from '@scayle/storefront-api';
import type { RpcHandler } from '../../types';
/**
* Parameters for fetching variants.
*/
export interface FetchVariantsParams {
/**
* Array of variant IDs.
*/
ids: number[];
/**
* Include related data for the variant.
*/
include?: ProductWith;
/**
* Price promotion key.
*/
pricePromotionKey?: string;
}
/**
* Retrieves variant details by their IDs.
*
* This function uses the Storefront cache (`cached()`) with a `getByIds-variants` key prefix to improve performance.
* Cached entries are returned if found; otherwise, data is fetched and cached.
*
* @param params Parameters for fetching the variants.
* @param params.ids Array of variant IDs.
* @param params.include Include related data for the variant. Defaults to `defaultWith`.
* @param params.pricePromotionKey Price promotion key. Defaults to 'default'.
* @param context The RPC context.
*
* @returns A Promise that resolves to an array of `VariantDetail` objects.
*
* @throws Will throw an error if the SAPI request fails.
*/
export declare const getVariantById: RpcHandler<FetchVariantsParams, VariantDetail[]>;