@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.
- package/CHANGELOG.md +85 -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 +3 -1
- package/dist/rpc/methods/basket/basket.d.ts +95 -10
- package/dist/rpc/methods/basket/basket.mjs +4 -5
- 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 +42 -3
- package/dist/rpc/methods/checkout/checkout.mjs +2 -3
- package/dist/rpc/methods/checkout/order.d.ts +12 -0
- 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 +160 -36
- package/dist/rpc/methods/products.mjs +8 -11
- 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 +30 -2
- package/dist/rpc/methods/variants.mjs +1 -2
- package/dist/rpc/methods/wishlist.d.ts +42 -7
- package/dist/rpc/methods/wishlist.mjs +3 -4
- 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 +82 -1
- 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/dist/utils/campaign.d.ts +25 -10
- package/package.json +4 -4
|
@@ -1,10 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the row index for an item given its overall index and pagination options.
|
|
3
|
+
*
|
|
4
|
+
* @param index The overall index of the item.
|
|
5
|
+
* @param options Pagination options. Defaults to 2 columns, page 1, and 24 items per page.
|
|
6
|
+
* @param options.columns
|
|
7
|
+
* @param options.page
|
|
8
|
+
* @param options.perPage
|
|
9
|
+
*
|
|
10
|
+
* @returns The calculated row index.
|
|
11
|
+
*
|
|
12
|
+
* @deprecated Row Disruption and associated functionality should be handled within the Storefront project itself.
|
|
13
|
+
*/
|
|
1
14
|
export declare const getRowByIndex: (index: number, options?: {
|
|
2
15
|
columns: number;
|
|
3
16
|
page: number;
|
|
4
17
|
perPage: number;
|
|
5
18
|
}) => number;
|
|
19
|
+
/**
|
|
20
|
+
* Filters disruptors for a specific row.
|
|
21
|
+
*
|
|
22
|
+
* @param row The row number.
|
|
23
|
+
* @param disruptors An array of disruptor objects.
|
|
24
|
+
*
|
|
25
|
+
* @returns An array of disruptors belonging to the specified row.
|
|
26
|
+
*
|
|
27
|
+
* @deprecated Row Disruption and associated functionality should be handled within the Storefront project itself.
|
|
28
|
+
*/
|
|
6
29
|
export declare const getDisruptorsForRow: (row: number, disruptors: {
|
|
7
30
|
insert_in_row: string;
|
|
8
31
|
}[]) => object[];
|
|
32
|
+
/**
|
|
33
|
+
* Checks if the given index is the first index of a row.
|
|
34
|
+
*
|
|
35
|
+
* @param index The index to check.
|
|
36
|
+
* @param columns The number of columns.
|
|
37
|
+
*
|
|
38
|
+
* @returns True if the index is the first of a row, false otherwise.
|
|
39
|
+
*
|
|
40
|
+
* @deprecated Row Disruption and associated functionality should be handled within the Storefront project itself.
|
|
41
|
+
*/
|
|
9
42
|
export declare const isFirstIndexOfRow: (index: number, columns: number) => boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Checks if a disruptor exists at a specific row.
|
|
45
|
+
*
|
|
46
|
+
* @param row The row number.
|
|
47
|
+
* @param disruptorRows An array of disruptor row numbers as strings.
|
|
48
|
+
*
|
|
49
|
+
* @returns True if a disruptor exists at the specified row, false otherwise.
|
|
50
|
+
*
|
|
51
|
+
* @deprecated Row Disruption and associated functionality should be handled within the Storefront project itself.
|
|
52
|
+
*/
|
|
10
53
|
export declare const hasDisruptorAtRow: (row: number, disruptorRows: string[]) => boolean;
|
|
@@ -3,9 +3,37 @@ import type { ProductSibling } from '../types/sapi/product';
|
|
|
3
3
|
interface Route {
|
|
4
4
|
path?: string;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Generates a slug from a given URL string.
|
|
8
|
+
*
|
|
9
|
+
* @param url The URL string to slugify.
|
|
10
|
+
*
|
|
11
|
+
* @returns The slugified string.
|
|
12
|
+
*/
|
|
6
13
|
export declare const slugify: (url: string | undefined) => string;
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves the price of a variant.
|
|
16
|
+
*
|
|
17
|
+
* @param variant The variant object.
|
|
18
|
+
*
|
|
19
|
+
* @returns The variant price.
|
|
20
|
+
*/
|
|
7
21
|
export declare const getPrice: (variant: Variant) => VariantPrice;
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves the original price of a variant price.
|
|
24
|
+
*
|
|
25
|
+
* @param price The variant price object.
|
|
26
|
+
*
|
|
27
|
+
* @returns The original price.
|
|
28
|
+
*/
|
|
8
29
|
export declare const getOriginalPrice: (price: VariantPrice) => number;
|
|
30
|
+
/**
|
|
31
|
+
* Calculates the total applied reductions from a price object.
|
|
32
|
+
*
|
|
33
|
+
* @param price The price object containing applied reductions.
|
|
34
|
+
*
|
|
35
|
+
* @returns The total applied reductions.
|
|
36
|
+
*/
|
|
9
37
|
export declare const getTotalAppliedReductions: (price: {
|
|
10
38
|
appliedReductions: {
|
|
11
39
|
amount: {
|
|
@@ -17,21 +45,162 @@ export declare const getTotalAppliedReductions: (price: {
|
|
|
17
45
|
absoluteWithTax: number;
|
|
18
46
|
relative: number;
|
|
19
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* Gets the lowest price from a list of variants.
|
|
50
|
+
*
|
|
51
|
+
* @param variants An array of variants.
|
|
52
|
+
*
|
|
53
|
+
* @returns The lowest variant price.
|
|
54
|
+
*/
|
|
20
55
|
export declare const getLowestPrice: (variants: Variant[]) => VariantPrice;
|
|
56
|
+
/**
|
|
57
|
+
* Filters applied reductions by a specific category.
|
|
58
|
+
*
|
|
59
|
+
* @param price The price object.
|
|
60
|
+
* @param category The category to filter by.
|
|
61
|
+
*
|
|
62
|
+
* @returns An array of applied reductions matching the category.
|
|
63
|
+
*/
|
|
21
64
|
export declare const getAppliedReductionsByCategory: (price: VariantPrice | BasketItemPrice, category: AppliedReduction["category"]) => AppliedReduction[];
|
|
65
|
+
/**
|
|
66
|
+
* Retrieves the size from a variant.
|
|
67
|
+
*
|
|
68
|
+
* @param variant The variant object.
|
|
69
|
+
* @param attributeName The name of the size attribute. Defaults to 'shopSize'.
|
|
70
|
+
*
|
|
71
|
+
* @returns The size value.
|
|
72
|
+
*/
|
|
22
73
|
export declare const getSizeFromVariant: (variant: Variant, attributeName?: string) => Value | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Retrieves the size from a specific variant within a product.
|
|
76
|
+
*
|
|
77
|
+
* @param product The product object.
|
|
78
|
+
* @param variantId The ID of the variant.
|
|
79
|
+
*
|
|
80
|
+
* @returns The size value, or null if not found.
|
|
81
|
+
*/
|
|
23
82
|
export declare const getSizeFromSpecificVariant: (product: Product, variantId?: number) => Value | null | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Retrieves a specific variant from a list of variants.
|
|
85
|
+
*
|
|
86
|
+
* @param variants An array of variants.
|
|
87
|
+
* @param id The ID of the variant to retrieve.
|
|
88
|
+
*
|
|
89
|
+
* @returns The variant object if found, otherwise undefined.
|
|
90
|
+
*/
|
|
24
91
|
export declare const getVariant: (variants: Variant[], id: number) => Variant | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Retrieves all unique sizes from a list of variant attributes.
|
|
94
|
+
*
|
|
95
|
+
* @param variantsAttributes An array of variants.
|
|
96
|
+
* @param attributeName The name of the size attribute. Defaults to 'shopSize'.
|
|
97
|
+
*
|
|
98
|
+
* @returns An array of unique size values.
|
|
99
|
+
*/
|
|
25
100
|
export declare const getAllSizesFromVariants: (variantsAttributes: Variant[], attributeName?: string) => any[];
|
|
101
|
+
/**
|
|
102
|
+
* Retrieves product siblings including the product itself.
|
|
103
|
+
* Filters out inactive siblings.
|
|
104
|
+
*
|
|
105
|
+
* @param product The product object. If null or undefined, returns an empty array.
|
|
106
|
+
* @param colorAttributeName The name of the attribute representing the product's color.
|
|
107
|
+
* Defaults to 'colorDetail'. This attribute is used to extract color information
|
|
108
|
+
* for each sibling using `getAttributeValueTuples`.
|
|
109
|
+
*
|
|
110
|
+
* @returns An array of simplified product sibling objects. Each object has the following structure:
|
|
111
|
+
* - `id`: The ID of the product sibling.
|
|
112
|
+
* - `image`: The URL of the product's bust image, front view. Retrieved using `getImageFromList`.
|
|
113
|
+
* If no suitable image is found, this field may be null.
|
|
114
|
+
* - `colors`: An array of color values extracted from the attribute specified by `colorAttributeName`.
|
|
115
|
+
* This is the result of calling `getAttributeValueTuples` with the product's attributes and `colorAttributeName`.
|
|
116
|
+
* If the attribute is not found, this will be an empty array.
|
|
117
|
+
*/
|
|
26
118
|
export declare const getProductSiblings: (product?: Product | null, colorAttributeName?: string) => ProductSibling[];
|
|
119
|
+
/**
|
|
120
|
+
* Retrieves the colors of a product.
|
|
121
|
+
*
|
|
122
|
+
* @param product The product object.
|
|
123
|
+
* @param colorAttributeName The name of the color attribute. Defaults to 'colorDetail'.
|
|
124
|
+
*
|
|
125
|
+
* @returns An array of product color labels.
|
|
126
|
+
*/
|
|
27
127
|
export declare const getProductColors: (product: Product, colorAttributeName?: string) => string[];
|
|
128
|
+
/**
|
|
129
|
+
* Retrieves a variant by its size.
|
|
130
|
+
*
|
|
131
|
+
* @param variants An array of variants.
|
|
132
|
+
* @param size The size value to search for.
|
|
133
|
+
* @param sizeAttributeName The name of the size attribute. Defaults to 'shopSize'.
|
|
134
|
+
*
|
|
135
|
+
* @returns The variant object if found, otherwise undefined.
|
|
136
|
+
*/
|
|
28
137
|
export declare const getVariantBySize: (variants: Variant[], size: Value, sizeAttributeName?: string) => Variant | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* Checks if a variant is in stock.
|
|
140
|
+
*
|
|
141
|
+
* @param variant The variant object.
|
|
142
|
+
*
|
|
143
|
+
* @returns True if the variant is in stock or sellable when out-of-stock, false otherwise.
|
|
144
|
+
*/
|
|
29
145
|
export declare const isInStock: (variant: Variant) => boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Checks if a variant with a specific size is in stock.
|
|
148
|
+
*
|
|
149
|
+
* @param variants An array of variants.
|
|
150
|
+
* @param size The size value to check.
|
|
151
|
+
* @param sizeAttributeName The name of the size attribute. Defaults to 'shopSize'.
|
|
152
|
+
*
|
|
153
|
+
* @returns True if the variant is in stock, false otherwise.
|
|
154
|
+
*/
|
|
30
155
|
export declare const isVariantInStock: (variants: Variant[], size: Value, sizeAttributeName?: string) => boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Retrieves an attribute value from a product.
|
|
158
|
+
*
|
|
159
|
+
* @param product The product object.
|
|
160
|
+
* @param key The attribute key.
|
|
161
|
+
*
|
|
162
|
+
* @returns The attribute value.
|
|
163
|
+
*/
|
|
31
164
|
export declare const getAttribute: (product: Product, key: string) => any;
|
|
165
|
+
/**
|
|
166
|
+
* Generates the product path based on product name and id
|
|
167
|
+
*
|
|
168
|
+
* @param product The product object
|
|
169
|
+
*
|
|
170
|
+
* @returns The product path as string
|
|
171
|
+
*/
|
|
32
172
|
export declare const getProductPath: (product: Product) => string;
|
|
173
|
+
/**
|
|
174
|
+
* Retrieves categories matching a given route from a product.
|
|
175
|
+
*
|
|
176
|
+
* @param product The product object
|
|
177
|
+
* @param route The route object containing path information.
|
|
178
|
+
*
|
|
179
|
+
* @returns An array of categories.
|
|
180
|
+
*/
|
|
33
181
|
export declare const getCategoriesByRoute: (product: Product | null, route: Route | null) => import("@scayle/storefront-api").ProductCategory[];
|
|
182
|
+
/**
|
|
183
|
+
* Retrieves the latest/deepest category from product categories
|
|
184
|
+
*
|
|
185
|
+
* @param categories List of product categories
|
|
186
|
+
*
|
|
187
|
+
* @returns The latest category object or undefined
|
|
188
|
+
*/
|
|
34
189
|
export declare const getLatestCategory: (categories?: Product["categories"]) => import("@scayle/storefront-api").ProductCategory | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* Retrieves colors from a product and its siblings
|
|
192
|
+
*
|
|
193
|
+
* @param product The product data.
|
|
194
|
+
* @param colorAttributeName The name of the color attribute (default: 'colorDetail').
|
|
195
|
+
*
|
|
196
|
+
* @returns An array of color values.
|
|
197
|
+
*/
|
|
35
198
|
export declare const getProductAndSiblingsColors: (product: Product, colorAttributeName?: string) => Value[];
|
|
199
|
+
/**
|
|
200
|
+
* Extracts unique crossselling values from variants' advanced attributes.
|
|
201
|
+
*
|
|
202
|
+
* @param variants An array of variants.
|
|
203
|
+
* @returns An array of unique crossselling values (strings or numbers).
|
|
204
|
+
*/
|
|
36
205
|
export declare const getVariantCrosssellingValues: (variants: Variant[] | undefined) => (string | number)[];
|
|
37
206
|
export {};
|
|
@@ -1,4 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes the shop locale segment from a given path.
|
|
3
|
+
*
|
|
4
|
+
* @param locale The locale to remove (case-insensitive).
|
|
5
|
+
* @param path The path string.
|
|
6
|
+
* @param splitter The path separator. Defaults to '/'.
|
|
7
|
+
*
|
|
8
|
+
* @returns The path with the locale segment removed.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* stripShopLocaleFromPath('en', '/en/products') // '/products'
|
|
13
|
+
* stripShopLocaleFromPath('de', '/de/category/shoes') // '/category/shoes'
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
1
16
|
export declare const stripShopLocaleFromPath: (locale: string, path: string, splitter?: string) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Purifies a sensitive value by masking characters. Optionally shows the first and last characters.
|
|
19
|
+
*
|
|
20
|
+
* @param value The sensitive value to purify.
|
|
21
|
+
* @param showFirstAndLastChar Whether to show the first and last characters. Defaults to `false`.
|
|
22
|
+
*
|
|
23
|
+
* @returns The purified value.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* purifySensitiveValue("secret") // "********"
|
|
28
|
+
* purifySensitiveValue("secret", true) // "s****t"
|
|
29
|
+
* purifySensitiveValue("ab", true) // "ab" (doesn't mask if less than 3 characters)
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
2
32
|
export declare const purifySensitiveValue: (value: string, showFirstAndLastChar?: boolean) => string;
|
|
33
|
+
/**
|
|
34
|
+
* Purifies sensitive data from an object by masking values associated with blacklisted keys.
|
|
35
|
+
* Handles nested objects recursively.
|
|
36
|
+
*
|
|
37
|
+
* @param data The object containing potentially sensitive data.
|
|
38
|
+
* @param blacklistedKeys An array of keys to mask. Defaults to `['password']`.
|
|
39
|
+
* @param showFirstAndLastChar Whether to show the first and last characters of sensitive values. Defaults to `false`.
|
|
40
|
+
*
|
|
41
|
+
* @returns A new object with sensitive data purified.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const data = { name: "John", password: "mysecret", address: { street: "123 Main St", zip: "12345" } }
|
|
46
|
+
*
|
|
47
|
+
* const purified = purifySensitiveData(data) // { name: "John", password: "********", address: { street: "123 Main St", zip: "12345" } }
|
|
48
|
+
* const purifiedWithFirstLast = purifySensitiveData(data, ['password', 'zip'], true) // { name: "John", password: "m****t", address: { street: "123 Main St", zip: "1****5" } }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
3
51
|
export declare const purifySensitiveData: (data?: Record<string, any>, blacklistedKeys?: string[], showFirstAndLastChar?: boolean) => Record<string, any>;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a Headers object from a record, filtering out undefined values.
|
|
54
|
+
*
|
|
55
|
+
* @param headers A partial record of header key-value pairs. Undefined values are ignored.
|
|
56
|
+
*
|
|
57
|
+
* @returns A new `Headers` object.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const headers = createAndPurifyHeaders({ 'Content-Type': 'application/json', Authorization: undefined })
|
|
62
|
+
* // headers now contains only the 'Content-Type' header
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
4
65
|
export declare const createAndPurifyHeaders: (headers: Partial<Record<string, string | undefined>>) => Headers;
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import type { Query, SortingValueKey } from '../index';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves a subset of sorting values based on the provided keys.
|
|
4
|
+
* Filters out invalid keys and returns an object mapping valid keys to their sorting configurations.
|
|
5
|
+
*
|
|
6
|
+
* @param options An array of sorting value keys to include in the result. Defaults to all available keys.
|
|
7
|
+
*
|
|
8
|
+
* @returns An object mapping valid sorting keys to their configurations.
|
|
9
|
+
*/
|
|
2
10
|
export declare const getSortingValues: (options?: Array<SortingValueKey>) => {
|
|
3
11
|
[k: string]: {
|
|
4
12
|
by: "price";
|
|
@@ -31,6 +39,14 @@ export declare const getSortingValues: (options?: Array<SortingValueKey>) => {
|
|
|
31
39
|
query: "reduction-asc";
|
|
32
40
|
};
|
|
33
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves the sorting configuration based on the provided query.
|
|
44
|
+
*
|
|
45
|
+
* @param query The sort query parameter.
|
|
46
|
+
* @param defaultSort The default sorting key to use if the query is not recognized. Defaults to 'dateNewest'.
|
|
47
|
+
*
|
|
48
|
+
* @returns The sorting configuration object corresponding to the query or the default sort.
|
|
49
|
+
*/
|
|
34
50
|
export declare const getSortByValue: (query: Query, defaultSort?: SortingValueKey) => {
|
|
35
51
|
by: "price";
|
|
36
52
|
direction: "desc";
|
|
@@ -1,2 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits a string by a separator and removes any empty strings from the resulting array.
|
|
3
|
+
*
|
|
4
|
+
* @param value The string to split.
|
|
5
|
+
* @param separator The separator to use. Defaults to '/'.
|
|
6
|
+
* @returns An array of non-empty strings.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* splitAndRemoveEmpty("a/b/c") // ["a", "b", "c"]
|
|
11
|
+
* splitAndRemoveEmpty("a//b/c", "/") // ["a", "b", "c"]
|
|
12
|
+
* splitAndRemoveEmpty("a/b//", "/") // ["a", "b"]
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
1
15
|
declare const splitAndRemoveEmpty: (value: string, separator?: string) => string[];
|
|
2
16
|
export { splitAndRemoveEmpty };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as rpcMethods from './rpc/methods';
|
|
2
|
+
import type { RpcContext } from './types';
|
|
2
3
|
export { rpcMethods };
|
|
3
4
|
export * from './errors';
|
|
4
5
|
export * from './utils';
|
|
@@ -39,7 +40,7 @@ export type RpcMethods = {
|
|
|
39
40
|
* added RPC methods from the SCAYLE Storefront application.
|
|
40
41
|
*
|
|
41
42
|
* @see https://github.com/microsoft/TypeScript/pull/42149#issuecomment-865385560
|
|
42
|
-
*
|
|
43
|
+
*
|
|
43
44
|
* Without this workaround, the signature to `rpcCall` looks something like
|
|
44
45
|
* `rpcCall(m: 'addItemToBasket' | 'addItemToWishlist'...)`.
|
|
45
46
|
* But we need it to look like `rpcCall(m: RpcMethodName)` in order to include
|
|
@@ -65,4 +66,5 @@ export type RpcMethodParameters<N extends RpcMethodName> = Parameters<RpcMethod<
|
|
|
65
66
|
* @template N The name of the RPC method.
|
|
66
67
|
*/
|
|
67
68
|
export type RpcMethodReturnType<N extends RpcMethodName> = ReturnType<RpcMethod<N>>;
|
|
69
|
+
export type RpcMethodCall = <N extends RpcMethodName, P extends RpcMethodParameters<N>, TResult extends Exclude<Awaited<RpcMethodReturnType<N>>, Response>>(...args: P extends RpcContext ? [N] : [N, P]) => TResult;
|
|
68
70
|
export { ExistingItemHandling, AddToBasketFailureKind, UpdateBasketItemFailureKind, AddToWishlistFailureKind, PromotionEffectType, FilterTypes, APISortOption, APISortOrder, type ProductSortConfig, } from '@scayle/storefront-api';
|
|
@@ -2,6 +2,24 @@ import { ExistingItemHandling } from '@scayle/storefront-api';
|
|
|
2
2
|
import type { AddOrUpdateItemError, UpdateBasketItemQuantity } from '@scayle/storefront-api';
|
|
3
3
|
import { ErrorResponse } from '../../../errors';
|
|
4
4
|
import type { AddOrUpdateItemType, BasketResponseData, BasketWithOptions, Product, RpcContext, Variant } from '../../../types';
|
|
5
|
+
/**
|
|
6
|
+
* Adds an item to the basket.
|
|
7
|
+
*
|
|
8
|
+
* @param params The parameters for adding a single item to a basket.
|
|
9
|
+
* @param params.variantId The ID of the variant to add.
|
|
10
|
+
* @param params.promotionId The ID of the promotion.
|
|
11
|
+
* @param params.quantity The quantity of the item to add.
|
|
12
|
+
* @param params.displayData Display data for the item.
|
|
13
|
+
* @param params.customData Custom data for the item.
|
|
14
|
+
* @param params.existingItemHandling How to handle existing items, default to `'AddQuantityToExisting'`.
|
|
15
|
+
* @param params.itemGroup The item group.
|
|
16
|
+
* @param params.with withParams for basket.
|
|
17
|
+
* @param params.orderCustomData Custom data for order.
|
|
18
|
+
* @param context The RPC context.
|
|
19
|
+
*
|
|
20
|
+
* @returns The updated basket, potentially with errors. It will return
|
|
21
|
+
* an `ErrorResponse` if no session is found or adding to basket fails.
|
|
22
|
+
*/
|
|
5
23
|
export declare const addItemToBasket: ({ variantId, promotionId, quantity, displayData, customData, existingItemHandling, itemGroup, with: _with, orderCustomData, }: AddOrUpdateItemType & {
|
|
6
24
|
existingItemHandling?: ExistingItemHandling;
|
|
7
25
|
with?: BasketWithOptions;
|
|
@@ -13,6 +31,19 @@ export declare const addItemToBasket: ({ variantId, promotionId, quantity, displ
|
|
|
13
31
|
basket: BasketResponseData<Product, Variant>;
|
|
14
32
|
errors: AddOrUpdateItemError[];
|
|
15
33
|
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Adds multiple items to the basket.
|
|
36
|
+
*
|
|
37
|
+
* @param params The parameters for adding multiple items to a basket.
|
|
38
|
+
* @param params.items An array of items to add.
|
|
39
|
+
* @param params.existingItemHandling How to handle existing items.
|
|
40
|
+
* @param params.with withParams for basket.
|
|
41
|
+
* @param params.orderCustomData Order custom data.
|
|
42
|
+
* @param context The RPC context.
|
|
43
|
+
*
|
|
44
|
+
* @returns The updated basket, potentially with errors. It will return
|
|
45
|
+
* an `ErrorResponse` if no session is found or adding to basket fails.
|
|
46
|
+
*/
|
|
16
47
|
export declare const addItemsToBasket: (params: {
|
|
17
48
|
items: AddOrUpdateItemType[];
|
|
18
49
|
existingItemHandling: ExistingItemHandling;
|
|
@@ -25,11 +56,33 @@ export declare const addItemsToBasket: (params: {
|
|
|
25
56
|
basket: BasketResponseData<Product, Variant>;
|
|
26
57
|
errors: AddOrUpdateItemError[];
|
|
27
58
|
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Retrieves the current basket.
|
|
61
|
+
*
|
|
62
|
+
* @param options The options for retrieving the basket.
|
|
63
|
+
* @param options.orderCustomData Custom data for the order.
|
|
64
|
+
* @param context The RPC context.
|
|
65
|
+
*
|
|
66
|
+
* @returns The basket data. It will return an `ErrorResponse` alternatively
|
|
67
|
+
* if no session is found or retrieving the basket fails.
|
|
68
|
+
*/
|
|
28
69
|
export declare const getBasket: (options: (BasketWithOptions & {
|
|
29
70
|
orderCustomData?: Record<string, unknown>;
|
|
30
71
|
}) | undefined, context: RpcContext) => Promise<ErrorResponse | {
|
|
31
72
|
basket: BasketResponseData<Product, Variant>;
|
|
32
73
|
}>;
|
|
74
|
+
/**
|
|
75
|
+
* Removes an item from the basket.
|
|
76
|
+
*
|
|
77
|
+
* @param options The options for removing the item.
|
|
78
|
+
* @param options.itemKey The key of the item to remove.
|
|
79
|
+
* @param options.with withParams for basket.
|
|
80
|
+
* @param options.orderCustomData Custom data for the order.
|
|
81
|
+
* @param context The RPC context.
|
|
82
|
+
*
|
|
83
|
+
* @returns The updated basket. It will return an `ErrorResponse` alternatively
|
|
84
|
+
* if no session is found or removing the item fails.
|
|
85
|
+
*/
|
|
33
86
|
export declare const removeItemFromBasket: (options: {
|
|
34
87
|
itemKey: string;
|
|
35
88
|
with?: BasketWithOptions;
|
|
@@ -37,7 +90,27 @@ export declare const removeItemFromBasket: (options: {
|
|
|
37
90
|
}, context: RpcContext) => Promise<ErrorResponse | {
|
|
38
91
|
basket: BasketResponseData<Product, Variant>;
|
|
39
92
|
}>;
|
|
93
|
+
/**
|
|
94
|
+
* Clears the basket, removing all items.
|
|
95
|
+
*
|
|
96
|
+
* @param context The RPC context.
|
|
97
|
+
*
|
|
98
|
+
* @returns True if the basket was cleared successfully. It will return
|
|
99
|
+
* an `ErrorResponse` alternatively iIf an error occurs during basket clearing.
|
|
100
|
+
*/
|
|
40
101
|
export declare const clearBasket: (context: RpcContext) => Promise<true | ErrorResponse>;
|
|
102
|
+
/**
|
|
103
|
+
* Merges two baskets.
|
|
104
|
+
*
|
|
105
|
+
* @param params The parameters for merging baskets.
|
|
106
|
+
* @param params.fromBasketKey The key of the source basket.
|
|
107
|
+
* @param params.toBasketKey The key of the target basket.
|
|
108
|
+
* @param params.with withParams for basket.
|
|
109
|
+
* @param params.orderCustomData Custom data for the order.
|
|
110
|
+
* @param context The RPC context.
|
|
111
|
+
*
|
|
112
|
+
* @returns The new merged basket as result of the merge operation.
|
|
113
|
+
*/
|
|
41
114
|
export declare const mergeBaskets: ({ fromBasketKey, toBasketKey, with: _with, orderCustomData }: {
|
|
42
115
|
fromBasketKey: string;
|
|
43
116
|
toBasketKey: string;
|
|
@@ -56,29 +129,41 @@ export declare const mergeBaskets: ({ fromBasketKey, toBasketKey, with: _with, o
|
|
|
56
129
|
readonly errors: AddOrUpdateItemError[];
|
|
57
130
|
} | undefined>;
|
|
58
131
|
/**
|
|
59
|
-
*
|
|
132
|
+
* Type defining an object containing properties of a basket item than should be
|
|
133
|
+
* applied to the basket item during the update.
|
|
60
134
|
*/
|
|
61
135
|
export type BasketItemUpdateData = Partial<Omit<UpdateBasketItemQuantity, 'basketKey' | 'itemKey' | 'with' | 'quantity'>> & {
|
|
62
136
|
quantity: number;
|
|
63
137
|
};
|
|
138
|
+
/**
|
|
139
|
+
* Interface defining parameters for `UpdateBasketItemRequest`.
|
|
140
|
+
*/
|
|
64
141
|
export interface UpdateBasketItemRequestParameter {
|
|
65
|
-
/**
|
|
142
|
+
/**
|
|
143
|
+
* The key of the item to be updated.
|
|
144
|
+
*/
|
|
66
145
|
basketItemKey: string;
|
|
67
|
-
/**
|
|
146
|
+
/**
|
|
147
|
+
* The update data that should be applied to the basket item.
|
|
148
|
+
*/
|
|
68
149
|
update: BasketItemUpdateData;
|
|
69
|
-
/**
|
|
150
|
+
/**
|
|
151
|
+
* An object describing which data the returned basket should contain.
|
|
152
|
+
*/
|
|
70
153
|
with?: BasketWithOptions;
|
|
71
154
|
}
|
|
72
155
|
/**
|
|
73
156
|
* Applies the provided update data to a specific item in a basket.
|
|
74
157
|
*
|
|
75
|
-
* @param params
|
|
76
|
-
* @param params.basketItemKey
|
|
77
|
-
* @param params.update
|
|
78
|
-
* @param params.with
|
|
79
|
-
* @param context
|
|
158
|
+
* @param params The parameters for updating a basket item.
|
|
159
|
+
* @param params.basketItemKey The key of the item to be updated.
|
|
160
|
+
* @param params.update The update data that should be applied to the basket item.
|
|
161
|
+
* @param params.with An object describing which data the returned basket should contain.
|
|
162
|
+
* @param context The RPC context.
|
|
80
163
|
*
|
|
81
|
-
* @returns A promise that resolves with the updated basket.
|
|
164
|
+
* @returns A promise that resolves with the updated basket.
|
|
165
|
+
* In case of an error the, the failure kind will be resolved.
|
|
166
|
+
* It will return an `ErrorResponse` if no session is found or update operation fails.
|
|
82
167
|
*/
|
|
83
168
|
export declare const updateBasketItem: ({ basketItemKey, update, with: _with }: UpdateBasketItemRequestParameter, context: RpcContext) => Promise<ErrorResponse | {
|
|
84
169
|
basket: BasketResponseData<Product, Variant>;
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
import { mergeBaskets as mergeBasketFunction } from "../../../utils/user.mjs";
|
|
10
10
|
import { unwrap } from "../../../utils/response.mjs";
|
|
11
11
|
import { wasAddedWithReducedQuantity } from "../../../utils/index.mjs";
|
|
12
|
-
import { getCampaignKey } from "../campaign.mjs";
|
|
13
12
|
const SAPI_ERROR_NAME = "SAPI ERROR";
|
|
14
13
|
function getWithParams(params, context) {
|
|
15
14
|
return params.with ?? context.withParams?.basket ?? MIN_WITH_PARAMS_BASKET;
|
|
@@ -33,7 +32,7 @@ export const addItemToBasket = async function addItemToBasket2({
|
|
|
33
32
|
);
|
|
34
33
|
}
|
|
35
34
|
const { sapiClient, basketKey } = context;
|
|
36
|
-
const campaignKey = await getCampaignKey
|
|
35
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
37
36
|
const resolvedWith = getWithParams(
|
|
38
37
|
{ with: _with },
|
|
39
38
|
context
|
|
@@ -94,7 +93,7 @@ export const addItemsToBasket = async function addItemsToBasket2(params, context
|
|
|
94
93
|
);
|
|
95
94
|
}
|
|
96
95
|
const { sapiClient, basketKey } = context;
|
|
97
|
-
const campaignKey = await getCampaignKey
|
|
96
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
98
97
|
const resolvedWith = getWithParams(params, context);
|
|
99
98
|
const itemsToBeAddedOrUpdated = params.items.map((item) => ({
|
|
100
99
|
variantId: item.variantId,
|
|
@@ -155,7 +154,7 @@ export const getBasket = async function getBasket2(options, context) {
|
|
|
155
154
|
);
|
|
156
155
|
}
|
|
157
156
|
const { sapiClient, basketKey } = context;
|
|
158
|
-
const campaignKey = await getCampaignKey
|
|
157
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
159
158
|
const resolvedWith = getWithParams(
|
|
160
159
|
{ with: options },
|
|
161
160
|
context
|
|
@@ -188,7 +187,7 @@ export const removeItemFromBasket = async function removeItemFromBasket2(options
|
|
|
188
187
|
);
|
|
189
188
|
}
|
|
190
189
|
const { sapiClient, basketKey } = context;
|
|
191
|
-
const campaignKey = await getCampaignKey
|
|
190
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
192
191
|
const resolvedWith = getWithParams(options, context);
|
|
193
192
|
const basket = await sapiClient.basket.deleteItem(
|
|
194
193
|
basketKey,
|
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
import type { Brand, BrandsEndpointRequestParameters, BrandsEndpointResponseData } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves a list of brands.
|
|
4
|
+
*
|
|
5
|
+
* This function uses the Storefront cache (`cached()`) with a `getBrands` 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 brands.
|
|
9
|
+
* @param params.pagination The pagination settings.
|
|
10
|
+
* @param params.pagination.page The desired page number.
|
|
11
|
+
* @param params.pagination.perPage The number of brands per page (optional, capped at `MAX_PER_PAGE`).
|
|
12
|
+
* @param context The RPC context.
|
|
13
|
+
*
|
|
14
|
+
* @returns The list of brands. It will return an `ErrorResponse` if the request fails.
|
|
15
|
+
*/
|
|
2
16
|
export declare const getBrands: ({ pagination }: BrandsEndpointRequestParameters, { sapiClient, cached }: import("../../types").RpcContext) => Promise<Response | BrandsEndpointResponseData>;
|
|
17
|
+
/**
|
|
18
|
+
* Retrieves a brand by its ID.
|
|
19
|
+
*
|
|
20
|
+
* This function uses the Storefront cache (`cached()`) with a `getBrandById-${brandId}` key prefix to improve performance.
|
|
21
|
+
* Cached entries are returned if found; otherwise, data is fetched and cached.
|
|
22
|
+
*
|
|
23
|
+
* @param params The parameters for retrieving a brand by its ID.
|
|
24
|
+
* @param params.brandId The ID of the brand to retrieve.
|
|
25
|
+
* @param context The RPC context.
|
|
26
|
+
*
|
|
27
|
+
* @returns The brand. It will return an `ErrorResponse` alternatively If the request fails.
|
|
28
|
+
*/
|
|
3
29
|
export declare const getBrandById: ({ brandId }: {
|
|
4
30
|
brandId: number;
|
|
5
31
|
}, { sapiClient, cached }: import("../../types").RpcContext) => Promise<Response | Brand>;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type { RpcContext } from '../../types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* Retrieves the active campaign key.
|
|
4
|
+
*
|
|
5
|
+
* This RPC method retrieves the key for the earliest active campaign. It first checks the `context`
|
|
6
|
+
* for an existing `campaignKey`. If not present, it fetches active campaigns from the SAPI
|
|
7
|
+
* `list-campaigns` endpoint using the `sapiClient`, caching the result for 5 minutes.
|
|
6
8
|
*
|
|
7
|
-
* Uses SAPI's list-campaigns endpoint
|
|
8
9
|
* @see https://scayle.dev/en/api-guides/storefront-api/resources/campaigns/list-campaigns
|
|
9
10
|
*
|
|
11
|
+
* This function uses the Storefront cache (`cached()`) with a `get-campaignKey` key prefix to improve performance.
|
|
12
|
+
* Cached entries are returned if found; otherwise, data is fetched and cached.
|
|
13
|
+
*
|
|
10
14
|
* @param context The RPC Context
|
|
11
15
|
* @returns The current active campaign key.
|
|
12
16
|
*/
|