@scayle/storefront-core 8.9.0 → 8.11.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.
- package/CHANGELOG.md +67 -0
- package/dist/helpers/advancedAttributeHelpers.d.ts +27 -0
- package/dist/helpers/arrayHelpers.d.ts +7 -0
- package/dist/helpers/attributeHelpers.d.ts +32 -0
- package/dist/helpers/basketHelpers.d.ts +7 -0
- package/dist/helpers/categoryHelper.d.ts +38 -0
- package/dist/helpers/filterHelper.d.ts +96 -10
- package/dist/helpers/formHelpers.d.ts +57 -24
- package/dist/helpers/imageHelpers.d.ts +18 -0
- package/dist/helpers/localization.d.ts +6 -4
- package/dist/helpers/objectHelpers.d.ts +7 -0
- package/dist/helpers/orderHelpers.d.ts +31 -16
- package/dist/helpers/productDisruptorHelper.d.ts +43 -0
- package/dist/helpers/productHelpers.d.ts +169 -0
- package/dist/helpers/sanitizationHelpers.d.ts +61 -0
- package/dist/helpers/sortingHelper.d.ts +16 -0
- package/dist/helpers/stringHelpers.d.ts +14 -0
- package/dist/index.d.ts +1 -1
- package/dist/rpc/methods/basket/basket.d.ts +95 -10
- package/dist/rpc/methods/brands.d.ts +26 -0
- package/dist/rpc/methods/campaign.d.ts +8 -4
- package/dist/rpc/methods/categories.d.ts +65 -5
- package/dist/rpc/methods/categories.mjs +2 -1
- package/dist/rpc/methods/cbd.d.ts +10 -0
- package/dist/rpc/methods/checkout/checkout.d.ts +40 -0
- package/dist/rpc/methods/checkout/checkout.mjs +1 -1
- package/dist/rpc/methods/checkout/order.d.ts +12 -0
- package/dist/rpc/methods/checkout/order.mjs +0 -10
- package/dist/rpc/methods/checkout/shopUser.d.ts +20 -0
- package/dist/rpc/methods/checkout/shopUserAddresses.d.ts +7 -0
- package/dist/rpc/methods/navigationTrees.d.ts +27 -0
- package/dist/rpc/methods/oauth/idp.d.ts +24 -0
- package/dist/rpc/methods/products.d.ts +150 -7
- package/dist/rpc/methods/products.mjs +1 -3
- package/dist/rpc/methods/promotion.d.ts +46 -4
- package/dist/rpc/methods/search.d.ts +17 -12
- package/dist/rpc/methods/search.mjs +4 -2
- package/dist/rpc/methods/session.d.ts +71 -0
- package/dist/rpc/methods/session.mjs +13 -13
- package/dist/rpc/methods/shopConfiguration.d.ts +12 -1
- package/dist/rpc/methods/shopConfiguration.mjs +2 -1
- package/dist/rpc/methods/user.d.ts +34 -4
- package/dist/rpc/methods/variants.d.ts +28 -0
- package/dist/rpc/methods/wishlist.d.ts +35 -0
- package/dist/test/factories/user.d.ts +10 -0
- package/dist/types/api/auth.d.ts +67 -0
- package/dist/types/api/context.d.ts +61 -0
- package/dist/types/api/rpc.d.ts +19 -0
- package/dist/types/breadcrumb.d.ts +9 -0
- package/dist/types/promises.d.ts +10 -0
- package/dist/types/sapi/basket.d.ts +26 -1
- package/dist/types/sapi/filter.d.ts +37 -0
- package/dist/types/sapi/navigation.d.ts +16 -4
- package/dist/types/sapi/order.d.ts +137 -242
- package/dist/types/sapi/product.d.ts +85 -0
- package/dist/types/sapi/productFilter.d.ts +14 -0
- package/dist/types/sapi/router.d.ts +3 -0
- package/dist/types/sapi/search.d.ts +19 -0
- package/dist/types/sapi/sorting.d.ts +7 -0
- package/dist/types/sapi/wishlist.d.ts +6 -0
- package/dist/types/user.d.ts +102 -0
- package/package.json +1 -1
|
@@ -1,13 +1,53 @@
|
|
|
1
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
|
+
*/
|
|
2
8
|
interface CheckoutJwtPayload {
|
|
9
|
+
/**
|
|
10
|
+
* The voucher code.
|
|
11
|
+
*/
|
|
3
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
|
+
*/
|
|
4
17
|
customData?: Record<string, unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* The preferred collection point.
|
|
20
|
+
*/
|
|
5
21
|
preferredCollectionPoint?: {
|
|
22
|
+
/**
|
|
23
|
+
* The collection point Id.
|
|
24
|
+
*/
|
|
6
25
|
id: number;
|
|
26
|
+
/**
|
|
27
|
+
* The collection point type.
|
|
28
|
+
*/
|
|
7
29
|
type: string;
|
|
8
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* The selected carrier.
|
|
33
|
+
*/
|
|
9
34
|
carrier?: string;
|
|
10
35
|
}
|
|
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
|
+
*/
|
|
11
51
|
export declare const getCheckoutToken: RpcHandler<CheckoutJwtPayload | undefined, {
|
|
12
52
|
accessToken: string;
|
|
13
53
|
checkoutJwt: string;
|
|
@@ -36,7 +36,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
|
|
|
36
36
|
carrier,
|
|
37
37
|
basketId: context.basketKey,
|
|
38
38
|
campaignKey
|
|
39
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.
|
|
39
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.11.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
|
|
40
40
|
return {
|
|
41
41
|
accessToken: refreshedAccessToken,
|
|
42
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>;
|
|
@@ -21,16 +21,6 @@ export const getOrderById = async function getOrderById2({ orderId }, context) {
|
|
|
21
21
|
"No access token present"
|
|
22
22
|
);
|
|
23
23
|
}
|
|
24
|
-
const isOrderInUserOrderlist = context.user?.orderSummary?.find(
|
|
25
|
-
(order) => order.id === orderId
|
|
26
|
-
);
|
|
27
|
-
if (!isOrderInUserOrderlist) {
|
|
28
|
-
return new ErrorResponse(
|
|
29
|
-
HttpStatusCode.UNAUTHORIZED,
|
|
30
|
-
HttpStatusMessage.UNAUTHORIZED,
|
|
31
|
-
"Order not belonging to current user"
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
24
|
const client = new CustomerAPIClient(context);
|
|
35
25
|
try {
|
|
36
26
|
return await client.getOrder(context.shopId, orderId);
|
|
@@ -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,12 +1,17 @@
|
|
|
1
1
|
import type { FetchFiltersParams, FetchFiltersResponse, FetchProductParams, FetchProductsByCategoryParams, FetchProductsByCategoryResponse, FetchProductsByIdsParams, FetchProductsByReferenceKeysParams, FetchProductsCountParams, FetchProductsCountResponse, Product, RpcContext, RpcHandler } from '../../types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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.
|
|
10
15
|
*/
|
|
11
16
|
export declare function resolveCategoryIdFromParams(context: RpcContext, params: {
|
|
12
17
|
category?: string;
|
|
@@ -18,15 +23,153 @@ export declare function resolveCategoryIdFromParams(context: RpcContext, params:
|
|
|
18
23
|
category: string | undefined;
|
|
19
24
|
categoryId: number | undefined;
|
|
20
25
|
}>;
|
|
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
|
+
*/
|
|
21
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
|
+
*/
|
|
22
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
|
+
*/
|
|
23
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
|
+
*/
|
|
24
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
|
+
*/
|
|
25
115
|
export declare const fetchAllFiltersForCategory: RpcHandler<{
|
|
26
116
|
includedFilters?: string[];
|
|
27
117
|
category: {
|
|
28
118
|
id?: number;
|
|
29
119
|
};
|
|
30
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
|
+
*/
|
|
31
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
|
+
*/
|
|
32
175
|
export declare const getProductsByCategory: RpcHandler<FetchProductsByCategoryParams, FetchProductsByCategoryResponse>;
|
|
@@ -24,9 +24,7 @@ export async function resolveCategoryIdFromParams(context, params) {
|
|
|
24
24
|
category = params.category;
|
|
25
25
|
const result = await context.cached(
|
|
26
26
|
context.sapiClient.categories.getByPath,
|
|
27
|
-
{
|
|
28
|
-
cacheKeyPrefix: `getByPath-categories-${category}`
|
|
29
|
-
}
|
|
27
|
+
{ cacheKeyPrefix: `getByPath-categories-${category}` }
|
|
30
28
|
)(splitAndRemoveEmpty(category));
|
|
31
29
|
categoryId = result.id;
|
|
32
30
|
} else {
|
|
@@ -1,4 +1,46 @@
|
|
|
1
|
-
import type { PromotionsParams, PromotionsResponseData } from '../../types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { PromotionsParams, PromotionsResponseData, RpcContext } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves promotions based on provided parameters.
|
|
4
|
+
*
|
|
5
|
+
* This function uses the Storefront cache (`cached()`) with a `getPromotions` 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 promotions.
|
|
9
|
+
* @param params.pagination Pagination settings.
|
|
10
|
+
* @param params.pagination.page Page number.
|
|
11
|
+
* @param params.pagination.perPage Number of items per page.
|
|
12
|
+
* @param context The RPC context.
|
|
13
|
+
*
|
|
14
|
+
* @returns A Promise that resolves with the promotion data.
|
|
15
|
+
* It will return an `ErrorResponse` if the The Storefront API request fails.
|
|
16
|
+
*/
|
|
17
|
+
export declare const getPromotions: (params: Omit<PromotionsParams, "ids"> | undefined, context: RpcContext) => Promise<Response | PromotionsResponseData>;
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves currently active promotions.
|
|
20
|
+
*
|
|
21
|
+
* This function uses the Storefront cache (`cached()`) with a `getPromotions` 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 promotions.
|
|
25
|
+
* @param params.pagination Pagination settings.
|
|
26
|
+
* @param params.pagination.page Page number.
|
|
27
|
+
* @param params.pagination.perPage Number of items per page.
|
|
28
|
+
* @param context The RPC context.
|
|
29
|
+
*
|
|
30
|
+
* @returns A Promise that resolves with the current promotion data.
|
|
31
|
+
* It will return an `ErrorResponse` if the The Storefront API request fails.
|
|
32
|
+
*/
|
|
33
|
+
export declare const getCurrentPromotions: (params: Omit<PromotionsParams, "ids" | "activeAt"> | undefined, context: RpcContext) => Promise<Response | PromotionsResponseData>;
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves promotions by their IDs.
|
|
36
|
+
*
|
|
37
|
+
* This function uses the Storefront cache (`cached()`) with a `getByIds-promotions` key prefix to improve performance.
|
|
38
|
+
* Cached entries are returned if found; otherwise, data is fetched and cached.
|
|
39
|
+
*
|
|
40
|
+
* @param ids An array of promotion IDs.
|
|
41
|
+
* @param context The RPC context.
|
|
42
|
+
*
|
|
43
|
+
* @returns A Promise that resolves with the promotion data.
|
|
44
|
+
* It will return an `ErrorResponse` if the The Storefront API request fails.
|
|
45
|
+
*/
|
|
46
|
+
export declare const getPromotionsByIds: (ids: string[], context: RpcContext) => Promise<Response | PromotionsResponseData>;
|
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
import type { SearchEntity, SearchV2ResolveEndpointParameters, SearchV2SuggestionsEndpointParameters, SearchV2SuggestionsEndpointResponseData } from '../../types/sapi/search';
|
|
2
|
+
import type { RpcContext } from '../../types';
|
|
2
3
|
/**
|
|
3
4
|
* Fetches search suggestions for a given term.
|
|
4
5
|
*
|
|
5
|
-
* @param option
|
|
6
|
-
* @param option.term
|
|
7
|
-
* @param option.with
|
|
8
|
-
* @param option.categoryId
|
|
9
|
-
* @param context
|
|
6
|
+
* @param option The parameters for the request.
|
|
7
|
+
* @param option.term The term to search for.
|
|
8
|
+
* @param option.with An object describing which data the returned suggestions should contain.
|
|
9
|
+
* @param option.categoryId The category ID to search within.
|
|
10
|
+
* @param context The RPC context.
|
|
10
11
|
*
|
|
11
12
|
* @returns A promise that resolves to a list of search suggestions.
|
|
13
|
+
* It will return an `ErrorResponse` if the request fails.
|
|
12
14
|
*/
|
|
13
|
-
export declare const getSearchSuggestions: ({ term, with: _with, categoryId }: SearchV2SuggestionsEndpointParameters,
|
|
15
|
+
export declare const getSearchSuggestions: ({ term, with: _with, categoryId }: SearchV2SuggestionsEndpointParameters, context: RpcContext) => Promise<Response | SearchV2SuggestionsEndpointResponseData>;
|
|
14
16
|
/**
|
|
15
17
|
* Resolves a search query and returns the resolved entity.
|
|
16
18
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @param option
|
|
21
|
-
* @param
|
|
19
|
+
* This function uses the Storefront cache (`cached()`) with a `resolve-${term}` key prefix to improve performance.
|
|
20
|
+
* Cached entries are returned if found; otherwise, data is fetched and cached.
|
|
21
|
+
*
|
|
22
|
+
* @param option The parameters for the search query.
|
|
23
|
+
* @param option.term The search query to resolve.
|
|
24
|
+
* @param option.with An object describing which data the returned result should contain.
|
|
25
|
+
* @param option.categoryId The category ID for which the search should be performed.
|
|
26
|
+
* @param context The RPC context.
|
|
22
27
|
*
|
|
23
28
|
* @returns A promise that resolves to the resolved entity or null if no entity is found.
|
|
24
29
|
*/
|
|
25
|
-
export declare const resolveSearch: ({ term, with: _with, categoryId }: SearchV2ResolveEndpointParameters,
|
|
30
|
+
export declare const resolveSearch: ({ term, with: _with, categoryId }: SearchV2ResolveEndpointParameters, context: RpcContext) => Promise<SearchEntity | null>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
2
|
-
export const getSearchSuggestions = async function getSearchSuggestions2({ term, with: _with, categoryId },
|
|
2
|
+
export const getSearchSuggestions = async function getSearchSuggestions2({ term, with: _with, categoryId }, context) {
|
|
3
|
+
const { sapiClient, withParams } = context;
|
|
3
4
|
return await mapSAPIFetchErrorToResponse(sapiClient.searchv2.suggestions)(
|
|
4
5
|
term,
|
|
5
6
|
{
|
|
@@ -8,7 +9,8 @@ export const getSearchSuggestions = async function getSearchSuggestions2({ term,
|
|
|
8
9
|
}
|
|
9
10
|
);
|
|
10
11
|
};
|
|
11
|
-
export const resolveSearch = async function resolveSearch2({ term, with: _with, categoryId },
|
|
12
|
+
export const resolveSearch = async function resolveSearch2({ term, with: _with, categoryId }, context) {
|
|
13
|
+
const { cached, sapiClient, withParams } = context;
|
|
12
14
|
const resolvedEntity = await cached(sapiClient.searchv2.resolve, {
|
|
13
15
|
cacheKeyPrefix: `resolve-${term}`
|
|
14
16
|
})(term, {
|
|
@@ -1,20 +1,82 @@
|
|
|
1
1
|
import type { Optional } from 'utility-types';
|
|
2
2
|
import type { GuestRequest, LoginRequest, Oauth, RegisterRequest, RpcContext, RpcContextWithSession, ShopUser, UpdatePasswordByHashRequest } from '../../types';
|
|
3
3
|
import { ErrorResponse } from '../../errors';
|
|
4
|
+
/**
|
|
5
|
+
* Handles the post-login logic, including fetching user data, updating tokens,
|
|
6
|
+
* merging baskets and wishlists, and creating a user-bound session.
|
|
7
|
+
*
|
|
8
|
+
* @param context The RPC context with session information.
|
|
9
|
+
* @param tokens The OAuth tokens.
|
|
10
|
+
*
|
|
11
|
+
* @returns The result of the post login operation. It will return
|
|
12
|
+
* an `ErrorResponse` if fetching the user or merging baskets/wishlists fails.
|
|
13
|
+
*/
|
|
4
14
|
export declare function postLogin(context: RpcContextWithSession, tokens: Oauth): Promise<(ShopUser & ErrorResponse) | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Handles OAuth login requests.
|
|
17
|
+
*
|
|
18
|
+
* @param login The login request data. Includes `email` and `password` keys.
|
|
19
|
+
* @param context The RPC context.
|
|
20
|
+
*
|
|
21
|
+
* @returns A Response object indicating the login status. It will return
|
|
22
|
+
* an `ErrorResponse` if login fails.
|
|
23
|
+
*/
|
|
5
24
|
export declare const oauthLogin: (login: Optional<LoginRequest, "shop_id">, context: RpcContext) => Promise<Response>;
|
|
25
|
+
/**
|
|
26
|
+
* Handles OAuth user registration requests.
|
|
27
|
+
*
|
|
28
|
+
* @param register The registration request data.
|
|
29
|
+
* @param context The RPC context.
|
|
30
|
+
*
|
|
31
|
+
* @returns A Response object indicating the registration status. It will return
|
|
32
|
+
* an `ErrorResponse` if registration fails.
|
|
33
|
+
*/
|
|
6
34
|
export declare const oauthRegister: (register: Optional<RegisterRequest, "shop_id">, context: RpcContext) => Promise<Response>;
|
|
35
|
+
/**
|
|
36
|
+
* Handles OAuth guest login requests.
|
|
37
|
+
*
|
|
38
|
+
* @param guest The guest login request data.
|
|
39
|
+
* @param context The RPC context.
|
|
40
|
+
*
|
|
41
|
+
* @returns A Response object indicating the login status. It will return
|
|
42
|
+
* an `ErrorResponse` if guest login fails.
|
|
43
|
+
*/
|
|
7
44
|
export declare const oauthGuestLogin: (guest: Optional<GuestRequest, "shop_id">, context: RpcContext) => Promise<Response>;
|
|
45
|
+
/**
|
|
46
|
+
* Refreshes the access token using the refresh token.
|
|
47
|
+
*
|
|
48
|
+
* @param context The RPC context.
|
|
49
|
+
*
|
|
50
|
+
* @returns An object indicating the success status of the refresh operation.
|
|
51
|
+
* It will return an `ErrorResponse` if refreshing the token fails.
|
|
52
|
+
*/
|
|
8
53
|
export declare const refreshAccessToken: (context: RpcContext) => Promise<Response | {
|
|
9
54
|
success: true;
|
|
10
55
|
} | {
|
|
11
56
|
success: false;
|
|
12
57
|
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Revokes the current access token and destroys the session.
|
|
60
|
+
*
|
|
61
|
+
* @param context The RPC context.
|
|
62
|
+
*
|
|
63
|
+
* @returns An object indicating the result of the revocation.
|
|
64
|
+
* It will return an `ErrorResponse` if revoking the token fails.
|
|
65
|
+
*/
|
|
13
66
|
export declare const oauthRevokeToken: (context: RpcContext) => Promise<Response | {
|
|
14
67
|
result: true;
|
|
15
68
|
} | {
|
|
16
69
|
result: false;
|
|
17
70
|
}>;
|
|
71
|
+
/**
|
|
72
|
+
* Sends a password reset email to the specified email address.
|
|
73
|
+
*
|
|
74
|
+
* @param email The email address for password reset. Includes email key.
|
|
75
|
+
* @param context The RPC context.
|
|
76
|
+
*
|
|
77
|
+
* @returns An object indicating the success status of the operation.
|
|
78
|
+
* It will return an `ErrorResponse` if sending the password reset email fails.
|
|
79
|
+
*/
|
|
18
80
|
export declare const oauthForgetPassword: ({ email }: {
|
|
19
81
|
email: string;
|
|
20
82
|
}, context: RpcContext) => Promise<Response | {
|
|
@@ -22,4 +84,13 @@ export declare const oauthForgetPassword: ({ email }: {
|
|
|
22
84
|
} | {
|
|
23
85
|
success: false;
|
|
24
86
|
}>;
|
|
87
|
+
/**
|
|
88
|
+
* Updates the password using a password hash.
|
|
89
|
+
*
|
|
90
|
+
* @param passwordHash The password hash data.
|
|
91
|
+
* @param context The RPC context.
|
|
92
|
+
*
|
|
93
|
+
* @returns A Response object indicating the status of the password update.
|
|
94
|
+
* It will return an `ErrorResponse` if updating the password fails.
|
|
95
|
+
*/
|
|
25
96
|
export declare const updatePasswordByHash: (passwordHash: Optional<UpdatePasswordByHashRequest, "shop_id">, context: RpcContext) => Promise<Response>;
|