@scayle/storefront-core 8.8.0 → 8.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/dist/helpers/advancedAttributeHelpers.d.ts +27 -0
  3. package/dist/helpers/arrayHelpers.d.ts +7 -0
  4. package/dist/helpers/attributeHelpers.d.ts +32 -0
  5. package/dist/helpers/basketHelpers.d.ts +7 -0
  6. package/dist/helpers/categoryHelper.d.ts +38 -0
  7. package/dist/helpers/filterHelper.d.ts +96 -10
  8. package/dist/helpers/formHelpers.d.ts +57 -24
  9. package/dist/helpers/imageHelpers.d.ts +18 -0
  10. package/dist/helpers/localization.d.ts +6 -4
  11. package/dist/helpers/objectHelpers.d.ts +7 -0
  12. package/dist/helpers/orderHelpers.d.ts +31 -16
  13. package/dist/helpers/productDisruptorHelper.d.ts +43 -0
  14. package/dist/helpers/productHelpers.d.ts +169 -0
  15. package/dist/helpers/sanitizationHelpers.d.ts +61 -0
  16. package/dist/helpers/sortingHelper.d.ts +16 -0
  17. package/dist/helpers/stringHelpers.d.ts +14 -0
  18. package/dist/index.d.ts +3 -1
  19. package/dist/rpc/methods/basket/basket.d.ts +95 -10
  20. package/dist/rpc/methods/basket/basket.mjs +4 -5
  21. package/dist/rpc/methods/brands.d.ts +26 -0
  22. package/dist/rpc/methods/campaign.d.ts +8 -4
  23. package/dist/rpc/methods/categories.d.ts +65 -5
  24. package/dist/rpc/methods/categories.mjs +2 -1
  25. package/dist/rpc/methods/cbd.d.ts +10 -0
  26. package/dist/rpc/methods/checkout/checkout.d.ts +42 -3
  27. package/dist/rpc/methods/checkout/checkout.mjs +2 -3
  28. package/dist/rpc/methods/checkout/order.d.ts +12 -0
  29. package/dist/rpc/methods/checkout/shopUser.d.ts +20 -0
  30. package/dist/rpc/methods/checkout/shopUserAddresses.d.ts +7 -0
  31. package/dist/rpc/methods/navigationTrees.d.ts +27 -0
  32. package/dist/rpc/methods/oauth/idp.d.ts +24 -0
  33. package/dist/rpc/methods/products.d.ts +160 -36
  34. package/dist/rpc/methods/products.mjs +8 -11
  35. package/dist/rpc/methods/promotion.d.ts +46 -4
  36. package/dist/rpc/methods/search.d.ts +17 -12
  37. package/dist/rpc/methods/search.mjs +4 -2
  38. package/dist/rpc/methods/session.d.ts +71 -0
  39. package/dist/rpc/methods/session.mjs +13 -13
  40. package/dist/rpc/methods/shopConfiguration.d.ts +12 -1
  41. package/dist/rpc/methods/shopConfiguration.mjs +2 -1
  42. package/dist/rpc/methods/user.d.ts +34 -4
  43. package/dist/rpc/methods/variants.d.ts +30 -2
  44. package/dist/rpc/methods/variants.mjs +1 -2
  45. package/dist/rpc/methods/wishlist.d.ts +42 -7
  46. package/dist/rpc/methods/wishlist.mjs +3 -4
  47. package/dist/test/factories/user.d.ts +10 -0
  48. package/dist/types/api/auth.d.ts +67 -0
  49. package/dist/types/api/context.d.ts +82 -1
  50. package/dist/types/api/rpc.d.ts +19 -0
  51. package/dist/types/breadcrumb.d.ts +9 -0
  52. package/dist/types/promises.d.ts +10 -0
  53. package/dist/types/sapi/basket.d.ts +26 -1
  54. package/dist/types/sapi/filter.d.ts +37 -0
  55. package/dist/types/sapi/navigation.d.ts +16 -4
  56. package/dist/types/sapi/order.d.ts +137 -242
  57. package/dist/types/sapi/product.d.ts +85 -0
  58. package/dist/types/sapi/productFilter.d.ts +14 -0
  59. package/dist/types/sapi/router.d.ts +3 -0
  60. package/dist/types/sapi/search.d.ts +19 -0
  61. package/dist/types/sapi/sorting.d.ts +7 -0
  62. package/dist/types/sapi/wishlist.d.ts +6 -0
  63. package/dist/types/user.d.ts +102 -0
  64. package/dist/utils/campaign.d.ts +25 -10
  65. package/package.json +4 -4
@@ -1,33 +1,93 @@
1
- import type { Category, ProductCategoryPropertyWith } from '../../types';
1
+ import type { Category, ProductCategoryPropertyWith, RpcContext } from '../../types';
2
+ /**
3
+ * Retrieves the root categories.
4
+ *
5
+ * This function uses the Storefront cache (`cached()`) with a `root-categories` key prefix to improve performance.
6
+ * Cached entries are returned if found; otherwise, data is fetched and cached.
7
+ *
8
+ * @param params The parameters for retrieving the root category.
9
+ * @param params.children The number of child categories to include.
10
+ * @param params.includeHidden Whether to include hidden categories.
11
+ * @param params.properties The properties to include for each category.
12
+ * @param context The RPC context.
13
+ *
14
+ * @returns The root categories and the active node (undefined).
15
+ */
2
16
  export declare const getRootCategories: ({ children, includeHidden, properties }: {
3
17
  children?: number;
4
18
  includeHidden?: true;
5
19
  properties?: ProductCategoryPropertyWith;
6
- }, { cached, sapiClient }: import("../../types").RpcContext) => Promise<{
20
+ }, context: RpcContext) => Promise<{
7
21
  categories: Category[];
8
22
  activeNode: undefined;
9
23
  }>;
24
+ /**
25
+ * Retrieves a category by its path.
26
+ *
27
+ * This function uses the Storefront cache (`cached()`) with a `getByPath-category-${sanitizedPath}` key prefix to improve performance.
28
+ * Cached entries are returned if found; otherwise, data is fetched and cached.
29
+ *
30
+ * @param params The parameters for retrieving a category by its path.
31
+ * @param params.path The path of the category.
32
+ * @param params.children The number of child categories to include, default to `1`.
33
+ * @param params.includeHidden Whether to include hidden categories.
34
+ * @param params.properties The properties to include for each category.
35
+ * @param context The RPC context.
36
+ *
37
+ * @returns The category or undefined if not found.
38
+ * It will return an `ErrorResponse` if an error occurs during the API call.
39
+ */
10
40
  export declare const getCategoryByPath: ({ path, children, includeHidden, properties }: {
11
41
  path: string;
12
42
  children?: number;
13
43
  includeHidden?: true;
14
44
  properties?: ProductCategoryPropertyWith;
15
- }, context: import("../../types").RpcContext) => Promise<Response | Category>;
45
+ }, context: RpcContext) => Promise<Response | Category>;
46
+ /**
47
+ * Retrieves categories by path.
48
+ *
49
+ * This function uses the Storefront cache (`cached()`) with a `getById-categories-${id}` key prefix to improve performance.
50
+ * Cached entries are returned if found; otherwise, data is fetched and cached.
51
+ *
52
+ * @param params The parameters for retrieving multiple categories by path.
53
+ * @param params.path The path of the categories.
54
+ * @param params.children The number of children categories to include, default o `1`.
55
+ * @param params.includeHidden Whether to include hidden categories.
56
+ * @param params.properties The properties to include for each category.
57
+ * @param context The RPC context.
58
+ *
59
+ * @returns The categories data.
60
+ */
16
61
  export declare const getCategoriesByPath: ({ path, children, includeHidden, properties }: {
17
62
  path: string;
18
63
  children?: number;
19
64
  includeHidden?: true;
20
65
  properties?: ProductCategoryPropertyWith;
21
- }, context: import("../../types").RpcContext) => Promise<{
66
+ }, context: RpcContext) => Promise<{
22
67
  categories: Category[];
23
68
  activeNode: undefined;
24
69
  } | {
25
70
  categories: Category;
26
71
  activeNode: Category;
27
72
  }>;
73
+ /**
74
+ * Retrieves a category by ID.
75
+ *
76
+ * This function uses the Storefront cache (`cached()`) with a `getById-categories-${id}` key prefix to improve performance.
77
+ * Cached entries are returned if found; otherwise, data is fetched and cached.
78
+ *
79
+ * @param params The parameters for retrieving a category by ID.
80
+ * @param params.id The category ID.
81
+ * @param params.children The number of child categories to include.
82
+ * @param params.includeHidden Whether to include hidden categories.
83
+ * @param params.properties The properties to include for each category.
84
+ * @param context The RPC context.
85
+ *
86
+ * @returns The category. It will return an `ErrorResponse` if category retrieval fails.
87
+ */
28
88
  export declare const getCategoryById: ({ id, children, includeHidden, properties }: {
29
89
  id: number;
30
90
  children?: number;
31
91
  includeHidden?: true;
32
92
  properties?: ProductCategoryPropertyWith;
33
- }, context: import("../../types").RpcContext) => Promise<Response | Category>;
93
+ }, context: RpcContext) => Promise<Response | Category>;
@@ -1,6 +1,7 @@
1
1
  import { splitAndRemoveEmpty } from "../../helpers/index.mjs";
2
2
  import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
3
- export const getRootCategories = async function getRootCategories2({ children = 1, includeHidden, properties }, { cached, sapiClient }) {
3
+ export const getRootCategories = async function getRootCategories2({ children = 1, includeHidden, properties }, context) {
4
+ const { cached, sapiClient } = context;
4
5
  const result = await cached(sapiClient.categories.getRoots, {
5
6
  cacheKeyPrefix: "root-categories"
6
7
  })({
@@ -1,5 +1,15 @@
1
1
  import { ErrorResponse } from '../../errors';
2
2
  import type { Order, RpcContext } from '../../types';
3
+ /**
4
+ * Retrieves order data using a CBD token.
5
+ *
6
+ * @param params The parameters for retrieving order data.
7
+ * @param params.cbdToken The CBD token used for authentication and order identification.
8
+ * @param context The RPC context.
9
+ *
10
+ * @returns The order data. It will return an `ErrorResponse` alternatively if
11
+ * the CBD token is invalid, expired, or if an error occurs during the order retrieval.
12
+ */
3
13
  export declare const getOrderDataByCbd: ({ cbdToken }: {
4
14
  cbdToken: string;
5
15
  }, context: RpcContext) => Promise<ErrorResponse | Order>;
@@ -1,15 +1,54 @@
1
- import { ErrorResponse } from '../../../errors';
2
- import type { RpcContext } from '../../../types';
1
+ import type { RpcHandler } from '../../../types';
2
+ /**
3
+ * Representation of the payload for the JWT used in the checkout process.
4
+ * This is used to supplement checkout-related information, such as voucher codes,
5
+ * custom data, preferred collection point, and selected carrier.
6
+ * This allows pre-filling checkout information and ensures data integrity.
7
+ */
3
8
  interface CheckoutJwtPayload {
9
+ /**
10
+ * The voucher code.
11
+ */
4
12
  voucher?: string;
13
+ /**
14
+ * Arbitrary custom data associated with the checkout process. This can be used to store
15
+ * any additional information relevant to the checkout.
16
+ */
5
17
  customData?: Record<string, unknown>;
18
+ /**
19
+ * The preferred collection point.
20
+ */
6
21
  preferredCollectionPoint?: {
22
+ /**
23
+ * The collection point Id.
24
+ */
7
25
  id: number;
26
+ /**
27
+ * The collection point type.
28
+ */
8
29
  type: string;
9
30
  };
31
+ /**
32
+ * The selected carrier.
33
+ */
10
34
  carrier?: string;
11
35
  }
12
- export declare const getCheckoutToken: (jwtPayload: CheckoutJwtPayload | undefined, context: RpcContext) => Promise<ErrorResponse | {
36
+ /**
37
+ * Generates a checkout token, which includes a refreshed access token and
38
+ * a JWT containing checkout information.
39
+ *
40
+ * The generated JWT is signed with a secret and includes information from the
41
+ * provided `jwtPayload`, along with the `basketId` and `campaignKey`.
42
+ * It is used to pre-fill checkout details and maintain data integrity during
43
+ * the checkout process.
44
+ *
45
+ * @param jwtPayload The payload for the JWT. Provides checkout-related data to embed within the token.
46
+ * @param context The RPC context.
47
+ *
48
+ * @returns An object containing the access token and checkout JWT.
49
+ * It will return an `ErrorResponse` if no session is found, no access token is present.
50
+ */
51
+ export declare const getCheckoutToken: RpcHandler<CheckoutJwtPayload | undefined, {
13
52
  accessToken: string;
14
53
  checkoutJwt: string;
15
54
  }>;
@@ -3,7 +3,6 @@ import { hasSession } from "../../../types/index.mjs";
3
3
  import { ErrorResponse } from "../../../errors/index.mjs";
4
4
  import { HttpStatusCode, HttpStatusMessage } from "../../../constants/index.mjs";
5
5
  import { getAccessToken } from "../user.mjs";
6
- import { getCampaignKey } from "../campaign.mjs";
7
6
  export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}, context) {
8
7
  if (!hasSession(context)) {
9
8
  return new ErrorResponse(
@@ -29,7 +28,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
29
28
  const secret = new TextEncoder().encode(context.checkout.secret);
30
29
  const now = /* @__PURE__ */ new Date();
31
30
  const { voucher, customData, preferredCollectionPoint, carrier } = jwtPayload;
32
- const campaignKey = await getCampaignKey(context);
31
+ const campaignKey = await context.callRpc?.("getCampaignKey");
33
32
  const checkoutJwt = await new SignJWT({
34
33
  voucher,
35
34
  customData,
@@ -37,7 +36,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
37
36
  carrier,
38
37
  basketId: context.basketKey,
39
38
  campaignKey
40
- }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.8.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
39
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.10.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
41
40
  return {
42
41
  accessToken: refreshedAccessToken,
43
42
  checkoutJwt
@@ -1,5 +1,17 @@
1
1
  import { ErrorResponse } from '../../../errors';
2
2
  import type { Order } from '../../../types';
3
+ /**
4
+ * Retrieves an order by its ID.
5
+ *
6
+ * @param params The parameters for retrieving an order by its ID.
7
+ * @param params.orderId The ID of the order to retrieve.
8
+ * @param context The RPC context.
9
+ *
10
+ * @returns The order details if found. It will return an `ErrorResponse` alternatively
11
+ * if the order ID is invalid, no access token is present,
12
+ * the order does not belong to the current user, the order is not found,
13
+ * or an unknown error occurs.
14
+ */
3
15
  export declare const getOrderById: ({ orderId }: {
4
16
  orderId: number;
5
17
  }, context: import("../../../types").RpcContext) => Promise<ErrorResponse | Order>;
@@ -1,8 +1,28 @@
1
1
  import { ErrorResponse } from '../../../errors';
2
2
  import type { ShopUser, UpdatePasswordParams } from '../../../types';
3
+ /**
4
+ * Updates the shop user.
5
+ *
6
+ * @param payload The payload containing partial user data to update.
7
+ * @param context The RPC context.
8
+ *
9
+ * @returns The updated user. It will return an `ErrorResponse` alternatively
10
+ * if updating user information fails.
11
+ */
3
12
  export declare const updateShopUser: (payload: Partial<ShopUser>, context: import("../../../types").RpcContext) => Promise<ErrorResponse | {
4
13
  user: ShopUser;
5
14
  }>;
15
+ /**
16
+ * Updates the user's password.
17
+ *
18
+ * @param payload The payload with old and new password.
19
+ * @param payload.oldPassword The current password.
20
+ * @param payload.newPassword The new password.
21
+ * @param context The RPC context.
22
+ *
23
+ * @returns The user object (or undefined if an error occurs and shopUser is undefined).
24
+ * It will return an `ErrorResponse` if updating the password fails.
25
+ */
6
26
  export declare const updatePassword: ({ oldPassword, newPassword }: UpdatePasswordParams, context: import("../../../types").RpcContext) => Promise<ErrorResponse | {
7
27
  user: ShopUser | undefined;
8
28
  }>;
@@ -1,3 +1,10 @@
1
1
  import type { ShopUserAddress } from '../../../types';
2
+ /**
3
+ * Retrieves the shop user addresses.
4
+ *
5
+ * @param context The RPC context.
6
+ *
7
+ * @returns The shop user addresses.
8
+ */
2
9
  declare const getShopUserAddresses: (context: import("../../../types").RpcContext) => Promise<ShopUserAddress[]>;
3
10
  export { getShopUserAddresses };
@@ -1,6 +1,33 @@
1
1
  import type { NavigationAllEndpointResponseData, NavigationTree } from '@scayle/storefront-api';
2
2
  import type { FetchNavigationTreeByIdParams, FetchNavigationTreeByNameParams, FetchNavigationTreesParams } from '../../types';
3
3
  import { ErrorResponse } from '../../errors';
4
+ /**
5
+ * Fetches all navigation trees.
6
+ *
7
+ * This function uses the Storefront cache (`cached()`) with a `getAll-navigation-trees` key prefix to improve performance.
8
+ * Cached entries are returned if found; otherwise, data is fetched and cached.
9
+ *
10
+ * @param params The parameters for retrieving all navigation tress.
11
+ * @param params.params The parameters for fetching navigation trees.
12
+ * @param context The RPC context.
13
+ *
14
+ * @returns The navigation trees data. It will return an `ErrorResponse`
15
+ * if an error occurs during fetching.
16
+ */
4
17
  export declare const fetchAllNavigationTrees: ({ params }: FetchNavigationTreesParams, { sapiClient: { navigation }, cached }: import("../../types").RpcContext) => Promise<NavigationAllEndpointResponseData>;
18
+ /**
19
+ * Fetches a navigation tree by its ID.
20
+ *
21
+ * This function uses the Storefront cache (`cached()`) with a `getById-navigation-trees-${treeId}` key prefix to improve performance.
22
+ * Cached entries are returned if found; otherwise, data is fetched and cached.
23
+ *
24
+ * @param params The parameters for retrieving a navigation tree by its ID.
25
+ * @param params.treeId The ID of the navigation tree.
26
+ * @param params.params The parameters for fetching navigation trees.
27
+ * @param context The RPC context.
28
+ *
29
+ * @returns The navigation tree data. It will return an `ErrorResponse`
30
+ * if an error occurs during fetching.
31
+ */
5
32
  export declare const fetchNavigationTreeById: ({ treeId, params }: FetchNavigationTreeByIdParams, { sapiClient: { navigation }, cached }: import("../../types").RpcContext) => Promise<NavigationTree>;
6
33
  export declare const fetchNavigationTreeByName: ({ treeName, params }: FetchNavigationTreeByNameParams, { sapiClient: { navigation }, cached }: import("../../types").RpcContext) => Promise<ErrorResponse | NavigationTree>;
@@ -1,10 +1,34 @@
1
1
  import { ErrorResponse } from '../../../errors';
2
2
  import type { RpcContext } from '../../../types';
3
+ /**
4
+ * Retrieves external IDP redirect URLs.
5
+ *
6
+ * @see https://scayle.dev/en/storefront-guide/developer-guide/basic-setup/authentication#overview
7
+ *
8
+ * @param params The parameters for retrieving the external IDP redirect.
9
+ * @param params.queryParams Optional query parameters to include in the redirect URLs.
10
+ * @param context The RPC context.
11
+ *
12
+ * @returns A record mapping IDP keys to their corresponding redirect URLs,
13
+ * or an ErrorResponse if an error occurs. It will return an `ErrorResponse`
14
+ * if JWT signing fails or another unexpected error occurs.
15
+ */
3
16
  export declare const getExternalIdpRedirect: ({ queryParams }: {
4
17
  queryParams?: Record<string, string>;
5
18
  }, context: RpcContext) => Promise<ErrorResponse | {
6
19
  [k: string]: string;
7
20
  }>;
21
+ /**
22
+ * Handles the IDP login callback.
23
+ *
24
+ * @see https://scayle.dev/en/storefront-guide/developer-guide/basic-setup/authentication#overview
25
+ *
26
+ * @param payload The payload containing the authorization code.
27
+ * @param payload.code The authorization code.
28
+ * @param context The RPC context.
29
+ *
30
+ * @returns A success message, or an `ErrorResponse` an error during login occurs.
31
+ */
8
32
  export declare const handleIDPLoginCallback: (payload: {
9
33
  code: string;
10
34
  }, context: RpcContext) => Promise<ErrorResponse | {
@@ -1,14 +1,17 @@
1
- import type { FiltersEndpointResponseData } from '@scayle/storefront-api';
2
- import type { FetchFiltersParams, FetchProductParams, FetchProductsByCategoryParams, FetchProductsByIdsParams, FetchProductsByReferenceKeysParams, FetchProductsCountParams, Product, RpcContext } from '../../types';
3
- import { ErrorResponse } from '../../errors';
4
- /**
5
- * For functions which accept either a category path or category ID,
6
- * this function can resolve the ID which is necessary for the calling
7
- * the Storefront APIs.
8
- * @param context
9
- * @param params
10
- * @returns A object with `category` and `categoryId` properties.
11
- * If no `category` was provided in the params, it will be undefined or '/'
1
+ import type { FetchFiltersParams, FetchFiltersResponse, FetchProductParams, FetchProductsByCategoryParams, FetchProductsByCategoryResponse, FetchProductsByIdsParams, FetchProductsByReferenceKeysParams, FetchProductsCountParams, FetchProductsCountResponse, Product, RpcContext, RpcHandler } from '../../types';
2
+ /**
3
+ * Resolves the category ID from provided parameters.
4
+ * This function handles cases where either a category path or ID is provided.
5
+ *
6
+ * This function uses the Storefront cache (`cached()`) with a `getById-navigation-trees-${treeId}` key prefix to improve performance.
7
+ * Cached entries are returned if found; otherwise, data is fetched and cached.
8
+ *
9
+ * @param context The RPC context.
10
+ * @param params The parameters for resolving a category ID from provides params.
11
+ * @param params.category The category path.
12
+ * @param params.categoryId The category ID.
13
+ *
14
+ * @returns A Promise resolving to an object with `category` (path) and `categoryId` properties.
12
15
  */
13
16
  export declare function resolveCategoryIdFromParams(context: RpcContext, params: {
14
17
  category?: string;
@@ -20,32 +23,153 @@ export declare function resolveCategoryIdFromParams(context: RpcContext, params:
20
23
  category: string | undefined;
21
24
  categoryId: number | undefined;
22
25
  }>;
23
- export declare const getProductById: (options: FetchProductParams, context: RpcContext) => Promise<Response | Product>;
24
- export declare const getProductsByIds: (options: FetchProductsByIdsParams, context: RpcContext) => Promise<Response | Product[]>;
25
- export declare const getProductsByReferenceKeys: (options: FetchProductsByReferenceKeysParams, context: RpcContext) => Promise<Response | Product[]>;
26
- export declare const getProductsCount: (params: FetchProductsCountParams, context: RpcContext) => Promise<(string[] & ErrorResponse) | {
27
- count: number;
28
- }>;
29
- export declare const fetchAllFiltersForCategory: ({ includedFilters, category }: {
26
+ /**
27
+ * Retrieves a product by its ID.
28
+ *
29
+ * This function uses the Storefront cache (`cached()`) with a `getById-product-${options.id}` key prefix to improve performance.
30
+ * Cached entries are returned if found; otherwise, data is fetched and cached.
31
+ *
32
+ * @param options The options for retrieving a single product by its ID.
33
+ * @param options.id The ID of the product.
34
+ * @param options.with Fields to include in the response.
35
+ * @param options.pricePromotionKey Price promotion key.
36
+ * @param options.includeSellableForFree Whether to include sellable for free products.
37
+ * @param context The RPC context.
38
+ *
39
+ * @returns A Promise resolving to the product data. It will return a
40
+ * `ErrorResponse` alternatively If the product retrieval fails.
41
+ */
42
+ export declare const getProductById: RpcHandler<FetchProductParams, Product>;
43
+ /**
44
+ * Retrieves multiple products by their IDs.
45
+ *
46
+ * This function uses the Storefront cache (`cached()`) with a `getByIds-products` key prefix to improve performance.
47
+ * Cached entries are returned if found; otherwise, data is fetched and cached.
48
+ *
49
+ * @param options The options for retrieving multiple products by their IDs.
50
+ * @param options.ids An array of product IDs.
51
+ * @param options.with Fields to include in the response.
52
+ * @param options.pricePromotionKey Price promotion key.
53
+ * @param context The RPC context.
54
+ *
55
+ * @returns A Promise resolving to an array of product data.
56
+ * It will return an `ErrorResponse` if the product retrieval fails.
57
+ */
58
+ export declare const getProductsByIds: RpcHandler<FetchProductsByIdsParams, Product[]>;
59
+ /**
60
+ * Retrieves products by their reference keys.
61
+ *
62
+ * This function uses the Storefront cache (`cached()`) with a `getByReferenceKeys-products` key prefix to improve performance.
63
+ * Cached entries are returned if found; otherwise, data is fetched and cached.
64
+ *
65
+ * @param options The options for retrieving products.
66
+ * @param options.referenceKeys An array of product reference keys.
67
+ * @param options.with The fields to include in the response.
68
+ * @param options.pricePromotionKey The price promotion key.
69
+ * @param context The RPC context.
70
+ *
71
+ * @returns A Promise that resolves with an array of products.
72
+ * It will return an `ErrorResponse` if the Storefront API request fails.
73
+ */
74
+ export declare const getProductsByReferenceKeys: RpcHandler<FetchProductsByReferenceKeysParams, Product[]>;
75
+ /**
76
+ * Retrieves the count of products matching the provided parameters.
77
+ *
78
+ * This function uses the Storefront cache (`cached()`) with a `products-query` key prefix to improve performance.
79
+ * Cached entries are returned if found; otherwise, data is fetched and cached.
80
+ *
81
+ * @param params The parameters for retrieving the product count.
82
+ * @param params.categoryId ID of the category.
83
+ * @param params.category Path of the category.
84
+ * @param params.includedFilters Filters to include.
85
+ * @param params.where Search criteria.
86
+ * @param params.where.minPrice Minimum price.
87
+ * @param params.where.maxPrice Maximum price.
88
+ * @param params.where.term Search term.
89
+ * @param params.where.attributes Attributes for filtering.
90
+ * @param params.where.whitelistAttributes Whitelisted attributes for filtering.
91
+ * @param params.where.disableFuzziness Whether to disable fuzzy search.
92
+ * @param params.includeSoldOut Whether to include sold out products.
93
+ * @param params.includeSellableForFree Whether to include products sellable for free.
94
+ * @param params.orFiltersOperator Whether to use the OR operator for filters.
95
+ * @param context The RPC context.
96
+ *
97
+ * @returns A Promise that resolves with the product count.
98
+ */
99
+ export declare const getProductsCount: RpcHandler<FetchProductsCountParams, FetchProductsCountResponse>;
100
+ /**
101
+ * Fetches all filters for a given category.
102
+ *
103
+ * This function uses the Storefront cache (`cached()`) with a `filters-for-category-${category.id}` key prefix to improve performance.
104
+ * Cached entries are returned if found; otherwise, data is fetched and cached.
105
+ *
106
+ * @param params The parameters for fetching filters for a category.
107
+ * @param params.includedFilters An array of filter slugs to include.
108
+ * @param params.category Category data.
109
+ * @param context The RPC context.
110
+ *
111
+ * @returns A Promise resolving to an array of filter slugs.
112
+ *
113
+ * @throws Will throw an error if fetching filters fails.
114
+ */
115
+ export declare const fetchAllFiltersForCategory: RpcHandler<{
30
116
  includedFilters?: string[];
31
117
  category: {
32
118
  id?: number;
33
119
  };
34
- }, context: RpcContext) => Promise<string[]>;
35
- export declare const getFilters: (params: FetchFiltersParams, context: RpcContext) => Promise<(string[] & ErrorResponse) | {
36
- filters: FiltersEndpointResponseData;
37
- unfilteredCount: number;
38
- }>;
39
- export declare const getProductsByCategory: (params: FetchProductsByCategoryParams, context: RpcContext) => Promise<(string[] & ErrorResponse) | {
40
- products: Product[];
41
- pagination: {
42
- current: number;
43
- total: number;
44
- perPage: number;
45
- page: number;
46
- first: number;
47
- prev: number;
48
- next: number;
49
- last: number;
50
- };
51
- }>;
120
+ }, string[]>;
121
+ /**
122
+ * Retrieves filters and product count for a given category.
123
+ *
124
+ * This function uses the Storefront cache (`cached()`) with a `get-filters-${categoryId}` and `products-query-category-${categoryId}` key prefix to improve performance.
125
+ * Cached entries are returned if found; otherwise, data is fetched and cached.
126
+ *
127
+ * @param params The parameters for fetching filters.
128
+ * @param params.includedFilters An array of included filters.
129
+ * @param params.where The where clause for filtering.
130
+ * @param params.where.minPrice Minimum price.
131
+ * @param params.where.maxPrice Maximum price.
132
+ * @param params.where.term Search term.
133
+ * @param params.where.attributes Attributes for filtering.
134
+ * @param params.where.whitelistAttributes Whitelisted attributes.
135
+ * @param params.where.disableFuzziness Whether to disable fuzziness.
136
+ * @param params.includeSoldOut Whether to include sold out products.
137
+ * @param params.includeSellableForFree Whether to include products sellable for free.
138
+ * @param params.orFiltersOperator The operator for OR filters.
139
+ * @param context The RPC context.
140
+ *
141
+ * @returns An object containing the filters and unfiltered count.
142
+ */
143
+ export declare const getFilters: RpcHandler<FetchFiltersParams, FetchFiltersResponse>;
144
+ /**
145
+ * Retrieves products by category.
146
+ *
147
+ * This function uses the Storefront cache (`cached()`) with a `products-query-category-${categoryId}` key prefix to improve performance.
148
+ * Cached entries are returned if found; otherwise, data is fetched and cached.
149
+ *
150
+ * @param params The parameters for fetching products.
151
+ * @param params.includedFilters An array of included filters.
152
+ * @param params.cache Cache options.
153
+ * @param params.cache.ttl Time to live for the cache.
154
+ * @param params.cache.cacheKeyPrefix Cache key prefix.
155
+ * @param params.with The 'with' parameter for including additional data.
156
+ * @param params.perPage Number of products per page.
157
+ * @param params.page Page number.
158
+ * @param params.where The where clause for filtering.
159
+ * @param params.where.minPrice Minimum price.
160
+ * @param params.where.maxPrice Maximum price.
161
+ * @param params.where.term Search term.
162
+ * @param params.where.attributes Attributes for filtering.
163
+ * @param params.where.whitelistAttributes Whitelisted attributes.
164
+ * @param params.where.disableFuzziness Whether to disable fuzziness.
165
+ * @param params.sort Sorting criteria.
166
+ * @param params.pricePromotionKey Price promotion key.
167
+ * @param params.includeSellableForFree Whether to include products sellable for free.
168
+ * @param params.includeSoldOut Whether to include sold out products.
169
+ * @param params.orFiltersOperator The operator for OR filters.
170
+ * @param params.trackSearchAnalyticsEvent Whether to track search analytics event.
171
+ * @param context The RPC context.
172
+ *
173
+ * @returns An object containing the products and pagination information.
174
+ */
175
+ export declare const getProductsByCategory: RpcHandler<FetchProductsByCategoryParams, FetchProductsByCategoryResponse>;
@@ -4,7 +4,6 @@ import { MINUTE } from "../../cache/index.mjs";
4
4
  import { unwrap } from "../../utils/response.mjs";
5
5
  import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
6
6
  import { ErrorResponse } from "../../errors/index.mjs";
7
- import { getCampaignKey } from "./campaign.mjs";
8
7
  const MAX_PER_PAGE = 100;
9
8
  const sanitizeAttributesForSAPI = ({
10
9
  attributes,
@@ -25,9 +24,7 @@ export async function resolveCategoryIdFromParams(context, params) {
25
24
  category = params.category;
26
25
  const result = await context.cached(
27
26
  context.sapiClient.categories.getByPath,
28
- {
29
- cacheKeyPrefix: `getByPath-categories-${category}`
30
- }
27
+ { cacheKeyPrefix: `getByPath-categories-${category}` }
31
28
  )(splitAndRemoveEmpty(category));
32
29
  categoryId = result.id;
33
30
  } else {
@@ -37,7 +34,7 @@ export async function resolveCategoryIdFromParams(context, params) {
37
34
  }
38
35
  export const getProductById = async function getProductById2(options, context) {
39
36
  const { sapiClient, cached, withParams } = context;
40
- const campaignKey = await getCampaignKey(context);
37
+ const campaignKey = await context.callRpc?.("getCampaignKey");
41
38
  return await cached(
42
39
  mapSAPIFetchErrorToResponse(sapiClient.products.getById),
43
40
  {
@@ -53,7 +50,7 @@ export const getProductById = async function getProductById2(options, context) {
53
50
  };
54
51
  export const getProductsByIds = async function getProductsByIds2(options, context) {
55
52
  const { sapiClient, cached, withParams } = context;
56
- const campaignKey = await getCampaignKey(context);
53
+ const campaignKey = await context.callRpc?.("getCampaignKey");
57
54
  return await cached(
58
55
  mapSAPIFetchErrorToResponse(sapiClient.products.getByIds),
59
56
  {
@@ -68,7 +65,7 @@ export const getProductsByIds = async function getProductsByIds2(options, contex
68
65
  };
69
66
  export const getProductsByReferenceKeys = async function getProductsByReferenceKeys2(options, context) {
70
67
  const { sapiClient, cached, withParams } = context;
71
- const campaignKey = await getCampaignKey(context);
68
+ const campaignKey = await context.callRpc?.("getCampaignKey");
72
69
  return await cached(
73
70
  mapSAPIFetchErrorToResponse(sapiClient.products.getByReferenceKeys),
74
71
  {
@@ -90,7 +87,7 @@ export const getProductsCount = async function getProductsCount2(params, context
90
87
  orFiltersOperator = void 0
91
88
  } = params;
92
89
  const { cached, sapiClient } = context;
93
- const campaignKey = await getCampaignKey(context);
90
+ const campaignKey = await context.callRpc?.("getCampaignKey");
94
91
  const { categoryId } = await resolveCategoryIdFromParams(context, params);
95
92
  const response = await getSanitizedAttributes(
96
93
  context,
@@ -131,7 +128,7 @@ export const getProductsCount = async function getProductsCount2(params, context
131
128
  };
132
129
  export const fetchAllFiltersForCategory = async function fetchAllFiltersForCategory2({ includedFilters = [], category }, context) {
133
130
  const { cached, sapiClient } = context;
134
- const campaignKey = await getCampaignKey(context);
131
+ const campaignKey = await context.callRpc?.("getCampaignKey");
135
132
  const fetchAndMapFiltersToSlugs = async () => {
136
133
  const filtersFromSAPI = await cached(sapiClient.filters.get)({
137
134
  where: { categoryId: category.id },
@@ -173,7 +170,7 @@ export const getFilters = async function getFilters2(params, context) {
173
170
  orFiltersOperator
174
171
  } = params;
175
172
  const { cached, sapiClient } = context;
176
- const campaignKey = await getCampaignKey(context);
173
+ const campaignKey = await context.callRpc?.("getCampaignKey");
177
174
  const { category, categoryId } = await resolveCategoryIdFromParams(
178
175
  context,
179
176
  params
@@ -253,7 +250,7 @@ export const getProductsByCategory = async function getProductsByCategory2(param
253
250
  trackSearchAnalyticsEvent = void 0
254
251
  } = params;
255
252
  const { cached, sapiClient } = context;
256
- const campaignKey = await getCampaignKey(context);
253
+ const campaignKey = await context.callRpc?.("getCampaignKey");
257
254
  const { category, categoryId } = await resolveCategoryIdFromParams(
258
255
  context,
259
256
  params