@scayle/storefront-core 8.17.0 → 8.18.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 +18 -0
- package/dist/cache/cached.d.ts +1 -1
- package/dist/cache/cached.mjs +1 -1
- package/dist/helpers/advancedAttributeHelpers.d.ts +1 -3
- package/dist/helpers/arrayHelpers.d.ts +12 -3
- package/dist/helpers/attributeHelpers.d.ts +4 -4
- package/dist/helpers/basketHelpers.d.ts +1 -1
- package/dist/helpers/filterHelper.d.ts +5 -34
- package/dist/helpers/orderHelpers.d.ts +2 -2
- package/dist/helpers/productHelpers.d.ts +5 -5
- package/dist/helpers/productHelpers.mjs +6 -0
- package/dist/helpers/sortingHelper.d.ts +4 -63
- package/dist/rpc/methods/basket/basket.d.ts +15 -33
- package/dist/rpc/methods/brands.d.ts +4 -4
- package/dist/rpc/methods/brands.mjs +6 -3
- package/dist/rpc/methods/campaign.mjs +1 -1
- package/dist/rpc/methods/categories.d.ts +11 -14
- package/dist/rpc/methods/cbd.d.ts +3 -4
- package/dist/rpc/methods/checkout/checkout.mjs +1 -1
- package/dist/rpc/methods/checkout/order.d.ts +3 -4
- package/dist/rpc/methods/checkout/shopUser.d.ts +4 -5
- package/dist/rpc/methods/checkout/shopUserAddresses.d.ts +2 -2
- package/dist/rpc/methods/navigationTrees.d.ts +4 -5
- package/dist/rpc/methods/oauth/idp.d.ts +5 -8
- package/dist/rpc/methods/products.d.ts +2 -2
- package/dist/rpc/methods/promotion.d.ts +4 -4
- package/dist/rpc/methods/search.d.ts +4 -4
- package/dist/rpc/methods/session.d.ts +13 -19
- package/dist/rpc/methods/shopConfiguration.d.ts +2 -2
- package/dist/rpc/methods/user.d.ts +8 -11
- package/dist/rpc/methods/user.mjs +4 -1
- package/dist/test/factories/user.d.ts +1 -1
- package/dist/utils/hash.d.ts +1 -1
- package/dist/utils/log.d.ts +1 -1
- package/dist/utils/timeout.d.ts +1 -1
- package/dist/utils/user.d.ts +3 -13
- package/package.json +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @scayle/storefront-core
|
|
2
2
|
|
|
3
|
+
## 8.18.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Update RPC methods to use explicit typing. This is an internal change to enable Typescript's `isolatedDeclarations` option. It will not impact regular usage of RPC methods, however if you are importing one of the functions directly, the explicit rather than inferred type will be used.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
**Dependencies**
|
|
12
|
+
|
|
13
|
+
- Updated dependency to @scayle/storefront-api@18.2.2
|
|
14
|
+
|
|
15
|
+
## 8.17.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Ensure that the `getAttribute` helper function can handle multi-value attributes.
|
|
20
|
+
|
|
3
21
|
## 8.17.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
package/dist/cache/cached.d.ts
CHANGED
package/dist/cache/cached.mjs
CHANGED
|
@@ -6,9 +6,7 @@ import type { FieldSet, GroupSet } from '../types';
|
|
|
6
6
|
*
|
|
7
7
|
* @returns An array of flattened objects.
|
|
8
8
|
*/
|
|
9
|
-
export declare const flattenFieldSet: (fieldSet: FieldSet) =>
|
|
10
|
-
[key: string]: string | number | null | undefined;
|
|
11
|
-
}[][];
|
|
9
|
+
export declare const flattenFieldSet: (fieldSet: FieldSet) => FieldSet;
|
|
12
10
|
interface FlattenedMaterialComposition {
|
|
13
11
|
materialGroupName?: string;
|
|
14
12
|
values: {
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursive helper type to extract the innermost non-array element types from T.
|
|
3
|
+
* Handles nested arrays and unions of arrays/non-arrays.
|
|
4
|
+
*/
|
|
5
|
+
type FlattenElement<T> = T extends ReadonlyArray<infer U> ? FlattenElement<U> : T;
|
|
1
6
|
/**
|
|
2
7
|
* Flattens an array of arrays with unknown depth into a single-level array.
|
|
3
8
|
*
|
|
4
|
-
* @
|
|
9
|
+
* @template T The type of the potentially nested array. Must extend `readonly unknown[]`.
|
|
10
|
+
*
|
|
11
|
+
* @param array The array to flatten.
|
|
5
12
|
*
|
|
6
|
-
* @returns
|
|
13
|
+
* @returns A new, single-level array containing all the innermost elements
|
|
14
|
+
* extracted from the input array. The element type is inferred recursively.
|
|
7
15
|
*/
|
|
8
|
-
export declare const flattenDeep: <T extends unknown
|
|
16
|
+
export declare const flattenDeep: <T extends ReadonlyArray<unknown>>(array: T) => FlattenElement<T>[];
|
|
17
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Attributes } from '@scayle/storefront-api';
|
|
1
|
+
import type { Attributes, Value } from '@scayle/storefront-api';
|
|
2
2
|
/**
|
|
3
3
|
* Retrieves the first attribute value for a given attribute name from a set of attributes.
|
|
4
4
|
*
|
|
@@ -7,7 +7,7 @@ import type { Attributes } from '@scayle/storefront-api';
|
|
|
7
7
|
*
|
|
8
8
|
* @returns The first attribute value, or undefined if not found.
|
|
9
9
|
*/
|
|
10
|
-
export declare const getFirstAttributeValue: (attributes: Attributes | undefined, attributeName: string) =>
|
|
10
|
+
export declare const getFirstAttributeValue: (attributes: Attributes | undefined, attributeName: string) => Value | undefined;
|
|
11
11
|
/**
|
|
12
12
|
* Retrieves the value or label of the first attribute value for a given attribute name.
|
|
13
13
|
*
|
|
@@ -25,7 +25,7 @@ export declare const getAttributeValue: (attributes: Attributes | undefined, att
|
|
|
25
25
|
*
|
|
26
26
|
* @returns An array of attribute values, or an empty array if not found.
|
|
27
27
|
*/
|
|
28
|
-
export declare const getAttributeValueTuples: (attributes: Attributes | undefined, attributeName: string) =>
|
|
28
|
+
export declare const getAttributeValueTuples: (attributes: Attributes | undefined, attributeName: string) => Value[];
|
|
29
29
|
/**
|
|
30
30
|
* Retrieves the first attribute value for multiple attribute names.
|
|
31
31
|
*
|
|
@@ -34,4 +34,4 @@ export declare const getAttributeValueTuples: (attributes: Attributes | undefine
|
|
|
34
34
|
*
|
|
35
35
|
* @returns An array of attribute values, filtered to remove any null or undefined values.
|
|
36
36
|
*/
|
|
37
|
-
export declare const getManyAttributeValueTuples: (attributes: Attributes | undefined, attributeNames: string[]) =>
|
|
37
|
+
export declare const getManyAttributeValueTuples: (attributes: Attributes | undefined, attributeNames: string[]) => Value[];
|
|
@@ -6,4 +6,4 @@ import type { BasketPackageInformation } from '@scayle/storefront-api';
|
|
|
6
6
|
*
|
|
7
7
|
* @returns A tuple containing the earliest and latest delivery dates, or null if no dates are found.
|
|
8
8
|
*/
|
|
9
|
-
export declare const getShippingDates: (packages: BasketPackageInformation[]) =>
|
|
9
|
+
export declare const getShippingDates: (packages: BasketPackageInformation[]) => [string | null, string | null];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CentAmount, ProductSearchQuery } from '@scayle/storefront-api';
|
|
2
|
-
import type { ProductFilter } from '../types';
|
|
2
|
+
import type { ProductFilter, SortValue } from '../types';
|
|
3
3
|
export interface TransformedFilter {
|
|
4
4
|
key: string;
|
|
5
5
|
displayName: string;
|
|
@@ -50,7 +50,7 @@ export declare const groupFilterableValuesByKey: (filters: ProductFilter[], filt
|
|
|
50
50
|
*/
|
|
51
51
|
export declare const transformStateToFilters: (state: {
|
|
52
52
|
[key: string]: TransformedFilter[];
|
|
53
|
-
}) => any
|
|
53
|
+
}) => Record<string, any>;
|
|
54
54
|
/**
|
|
55
55
|
* Merges an array of filters into a single filter object.
|
|
56
56
|
*
|
|
@@ -67,7 +67,7 @@ export declare const mergeFilters: (filters: TransformedFilter[]) => Record<stri
|
|
|
67
67
|
*
|
|
68
68
|
* @returns True if the filter is active, false otherwise.
|
|
69
69
|
*/
|
|
70
|
-
export declare const isFilterActive: (filters: Record<string, any>, filterToCheck: TransformedFilter) =>
|
|
70
|
+
export declare const isFilterActive: (filters: Record<string, any>, filterToCheck: TransformedFilter) => boolean;
|
|
71
71
|
/**
|
|
72
72
|
* Gets the active filters from a set of filters.
|
|
73
73
|
*
|
|
@@ -100,36 +100,7 @@ export declare const transformMinAndMaxPriceToFilter: (prices: (CentAmount | und
|
|
|
100
100
|
*
|
|
101
101
|
* @returns The transformed sort value.
|
|
102
102
|
*/
|
|
103
|
-
export declare const transformSortToFilter: (sort: string) =>
|
|
104
|
-
by: "price";
|
|
105
|
-
direction: "desc";
|
|
106
|
-
name: "topseller";
|
|
107
|
-
query: "topseller";
|
|
108
|
-
} | {
|
|
109
|
-
by: "new";
|
|
110
|
-
name: "date_newest";
|
|
111
|
-
query: "date-newest";
|
|
112
|
-
} | {
|
|
113
|
-
by: "price";
|
|
114
|
-
direction: "desc";
|
|
115
|
-
name: "price_desc";
|
|
116
|
-
query: "price-desc";
|
|
117
|
-
} | {
|
|
118
|
-
by: "price";
|
|
119
|
-
direction: "asc";
|
|
120
|
-
name: "price_asc";
|
|
121
|
-
query: "price-asc";
|
|
122
|
-
} | {
|
|
123
|
-
by: "reduction";
|
|
124
|
-
direction: "desc";
|
|
125
|
-
name: "reduction_desc";
|
|
126
|
-
query: "reduction-desc";
|
|
127
|
-
} | {
|
|
128
|
-
by: "reduction";
|
|
129
|
-
direction: "asc";
|
|
130
|
-
name: "reduction_asc";
|
|
131
|
-
query: "reduction-asc";
|
|
132
|
-
};
|
|
103
|
+
export declare const transformSortToFilter: (sort: string) => SortValue;
|
|
133
104
|
/**
|
|
134
105
|
* Gets grouped filterable values by keys.
|
|
135
106
|
*
|
|
@@ -151,7 +122,7 @@ export declare const getGroupedFilterableValues: (keys: Array<string>, filterabl
|
|
|
151
122
|
*
|
|
152
123
|
* @returns The min or max price value.
|
|
153
124
|
*/
|
|
154
|
-
export declare const getFilterablePriceValue: (filterableValues: Record<string, any>, key?: "min" | "max") =>
|
|
125
|
+
export declare const getFilterablePriceValue: (filterableValues: Record<string, any>, key?: "min" | "max") => CentAmount;
|
|
155
126
|
export type SerializedFilter = Record<string, string>;
|
|
156
127
|
export type Filter = Record<string, string | number | (string | number | null)[]>;
|
|
157
128
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Order } from '../types';
|
|
1
|
+
import type { Order, OrderItem } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Retrieves unique items from an order based on variant ID.
|
|
4
4
|
*
|
|
@@ -8,7 +8,7 @@ import type { Order } from '../types';
|
|
|
8
8
|
*
|
|
9
9
|
* @deprecated getting unique items from order should be handled within the Storefront project itself.
|
|
10
10
|
*/
|
|
11
|
-
export declare const getUniqueItemsFromOrder: <P, V>(order: Order<P, V>) =>
|
|
11
|
+
export declare const getUniqueItemsFromOrder: <P, V>(order: Order<P, V>) => OrderItem<P, V>[] | undefined;
|
|
12
12
|
/**
|
|
13
13
|
* Gets the quantity of a specific item in an order based on its variant ID.
|
|
14
14
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AppliedReduction, BasketItemPrice, Product, Value, Variant, VariantPrice } from '@scayle/storefront-api';
|
|
1
|
+
import type { AppliedReduction, BasketItemPrice, Product, ProductCategory, Value, Variant, VariantPrice } from '@scayle/storefront-api';
|
|
2
2
|
import type { ProductSibling } from '../types/sapi/product';
|
|
3
3
|
interface Route {
|
|
4
4
|
path?: string;
|
|
@@ -97,7 +97,7 @@ export declare const getVariant: (variants: Variant[], id: number) => Variant |
|
|
|
97
97
|
*
|
|
98
98
|
* @returns An array of unique size values.
|
|
99
99
|
*/
|
|
100
|
-
export declare const getAllSizesFromVariants: (variantsAttributes: Variant[], attributeName?: string) =>
|
|
100
|
+
export declare const getAllSizesFromVariants: (variantsAttributes: Variant[], attributeName?: string) => Value[];
|
|
101
101
|
/**
|
|
102
102
|
* Retrieves product siblings including the product itself.
|
|
103
103
|
* Filters out inactive siblings.
|
|
@@ -161,7 +161,7 @@ export declare const isVariantInStock: (variants: Variant[], size: Value, sizeAt
|
|
|
161
161
|
*
|
|
162
162
|
* @returns The attribute value.
|
|
163
163
|
*/
|
|
164
|
-
export declare const getAttribute: (product: Product, key: string) =>
|
|
164
|
+
export declare const getAttribute: (product: Product, key: string) => string | undefined;
|
|
165
165
|
/**
|
|
166
166
|
* Generates the product path based on product name and id
|
|
167
167
|
*
|
|
@@ -178,7 +178,7 @@ export declare const getProductPath: (product: Product) => string;
|
|
|
178
178
|
*
|
|
179
179
|
* @returns An array of categories.
|
|
180
180
|
*/
|
|
181
|
-
export declare const getCategoriesByRoute: (product: Product | null, route: Route | null) =>
|
|
181
|
+
export declare const getCategoriesByRoute: (product: Product | null, route: Route | null) => ProductCategory[];
|
|
182
182
|
/**
|
|
183
183
|
* Retrieves the latest/deepest category from product categories
|
|
184
184
|
*
|
|
@@ -186,7 +186,7 @@ export declare const getCategoriesByRoute: (product: Product | null, route: Rout
|
|
|
186
186
|
*
|
|
187
187
|
* @returns The latest category object or undefined
|
|
188
188
|
*/
|
|
189
|
-
export declare const getLatestCategory: (categories?: Product["categories"]) =>
|
|
189
|
+
export declare const getLatestCategory: (categories?: Product["categories"]) => ProductCategory | undefined;
|
|
190
190
|
/**
|
|
191
191
|
* Retrieves colors from a product and its siblings
|
|
192
192
|
*
|
|
@@ -92,6 +92,12 @@ export const isVariantInStock = (variants, size, sizeAttributeName = "shopSize")
|
|
|
92
92
|
};
|
|
93
93
|
export const getAttribute = (product, key) => {
|
|
94
94
|
const values = product.attributes?.[key]?.values;
|
|
95
|
+
if (!values) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (Array.isArray(values)) {
|
|
99
|
+
return values[0]?.value ?? values[0]?.label;
|
|
100
|
+
}
|
|
95
101
|
return values?.value ?? values?.label;
|
|
96
102
|
};
|
|
97
103
|
export const getProductPath = (product) => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Query
|
|
1
|
+
import type { Query } from '../index';
|
|
2
|
+
import type { SortingValueKey, SortValue } from '../types/sapi/sorting';
|
|
2
3
|
/**
|
|
3
4
|
* Retrieves a subset of sorting values based on the provided keys.
|
|
4
5
|
* Filters out invalid keys and returns an object mapping valid keys to their sorting configurations.
|
|
@@ -7,38 +8,7 @@ import type { Query, SortingValueKey } from '../index';
|
|
|
7
8
|
*
|
|
8
9
|
* @returns An object mapping valid sorting keys to their configurations.
|
|
9
10
|
*/
|
|
10
|
-
export declare const getSortingValues: (options?:
|
|
11
|
-
[k: string]: {
|
|
12
|
-
by: "price";
|
|
13
|
-
direction: "desc";
|
|
14
|
-
name: "topseller";
|
|
15
|
-
query: "topseller";
|
|
16
|
-
} | {
|
|
17
|
-
by: "new";
|
|
18
|
-
name: "date_newest";
|
|
19
|
-
query: "date-newest";
|
|
20
|
-
} | {
|
|
21
|
-
by: "price";
|
|
22
|
-
direction: "desc";
|
|
23
|
-
name: "price_desc";
|
|
24
|
-
query: "price-desc";
|
|
25
|
-
} | {
|
|
26
|
-
by: "price";
|
|
27
|
-
direction: "asc";
|
|
28
|
-
name: "price_asc";
|
|
29
|
-
query: "price-asc";
|
|
30
|
-
} | {
|
|
31
|
-
by: "reduction";
|
|
32
|
-
direction: "desc";
|
|
33
|
-
name: "reduction_desc";
|
|
34
|
-
query: "reduction-desc";
|
|
35
|
-
} | {
|
|
36
|
-
by: "reduction";
|
|
37
|
-
direction: "asc";
|
|
38
|
-
name: "reduction_asc";
|
|
39
|
-
query: "reduction-asc";
|
|
40
|
-
};
|
|
41
|
-
};
|
|
11
|
+
export declare const getSortingValues: (options?: SortingValueKey[]) => Record<SortingValueKey, SortValue>;
|
|
42
12
|
/**
|
|
43
13
|
* Retrieves the sorting configuration based on the provided query.
|
|
44
14
|
*
|
|
@@ -47,33 +17,4 @@ export declare const getSortingValues: (options?: Array<SortingValueKey>) => {
|
|
|
47
17
|
*
|
|
48
18
|
* @returns The sorting configuration object corresponding to the query or the default sort.
|
|
49
19
|
*/
|
|
50
|
-
export declare const getSortByValue: (query: Query, defaultSort?: SortingValueKey) =>
|
|
51
|
-
by: "price";
|
|
52
|
-
direction: "desc";
|
|
53
|
-
name: "topseller";
|
|
54
|
-
query: "topseller";
|
|
55
|
-
} | {
|
|
56
|
-
by: "new";
|
|
57
|
-
name: "date_newest";
|
|
58
|
-
query: "date-newest";
|
|
59
|
-
} | {
|
|
60
|
-
by: "price";
|
|
61
|
-
direction: "desc";
|
|
62
|
-
name: "price_desc";
|
|
63
|
-
query: "price-desc";
|
|
64
|
-
} | {
|
|
65
|
-
by: "price";
|
|
66
|
-
direction: "asc";
|
|
67
|
-
name: "price_asc";
|
|
68
|
-
query: "price-asc";
|
|
69
|
-
} | {
|
|
70
|
-
by: "reduction";
|
|
71
|
-
direction: "desc";
|
|
72
|
-
name: "reduction_desc";
|
|
73
|
-
query: "reduction-desc";
|
|
74
|
-
} | {
|
|
75
|
-
by: "reduction";
|
|
76
|
-
direction: "asc";
|
|
77
|
-
name: "reduction_asc";
|
|
78
|
-
query: "reduction-asc";
|
|
79
|
-
};
|
|
20
|
+
export declare const getSortByValue: (query: Query, defaultSort?: SortingValueKey) => SortValue;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ExistingItemHandling } from '@scayle/storefront-api';
|
|
2
2
|
import type { AddOrUpdateItemError, UpdateBasketItemQuantity } from '@scayle/storefront-api';
|
|
3
|
-
import {
|
|
4
|
-
import type { AddOrUpdateItemType, BasketResponseData, BasketWithOptions, Product, RpcContext, Variant } from '../../../types';
|
|
3
|
+
import type { AddOrUpdateItemType, BasketResponseData, BasketWithOptions, Product, RpcHandler, Variant } from '../../../types';
|
|
5
4
|
/**
|
|
6
5
|
* Adds an item to the basket.
|
|
7
6
|
*
|
|
@@ -20,16 +19,13 @@ import type { AddOrUpdateItemType, BasketResponseData, BasketWithOptions, Produc
|
|
|
20
19
|
* @returns The updated basket, potentially with errors. It will return
|
|
21
20
|
* an `ErrorResponse` if no session is found or adding to basket fails.
|
|
22
21
|
*/
|
|
23
|
-
export declare const addItemToBasket:
|
|
22
|
+
export declare const addItemToBasket: RpcHandler<AddOrUpdateItemType & {
|
|
24
23
|
existingItemHandling?: ExistingItemHandling;
|
|
25
24
|
with?: BasketWithOptions;
|
|
26
25
|
orderCustomData?: Record<string, unknown>;
|
|
27
|
-
},
|
|
26
|
+
}, {
|
|
28
27
|
basket: BasketResponseData<Product, Variant>;
|
|
29
|
-
errors?:
|
|
30
|
-
} | {
|
|
31
|
-
basket: BasketResponseData<Product, Variant>;
|
|
32
|
-
errors: AddOrUpdateItemError[];
|
|
28
|
+
errors?: AddOrUpdateItemError[];
|
|
33
29
|
}>;
|
|
34
30
|
/**
|
|
35
31
|
* Adds multiple items to the basket.
|
|
@@ -44,17 +40,14 @@ export declare const addItemToBasket: ({ variantId, promotionId, quantity, displ
|
|
|
44
40
|
* @returns The updated basket, potentially with errors. It will return
|
|
45
41
|
* an `ErrorResponse` if no session is found or adding to basket fails.
|
|
46
42
|
*/
|
|
47
|
-
export declare const addItemsToBasket:
|
|
43
|
+
export declare const addItemsToBasket: RpcHandler<{
|
|
48
44
|
items: AddOrUpdateItemType[];
|
|
49
45
|
existingItemHandling: ExistingItemHandling;
|
|
50
46
|
with?: BasketWithOptions;
|
|
51
47
|
orderCustomData?: Record<string, unknown>;
|
|
52
|
-
},
|
|
53
|
-
basket: BasketResponseData<Product, Variant>;
|
|
54
|
-
errors?: undefined;
|
|
55
|
-
} | {
|
|
48
|
+
}, {
|
|
56
49
|
basket: BasketResponseData<Product, Variant>;
|
|
57
|
-
errors
|
|
50
|
+
errors?: AddOrUpdateItemError[];
|
|
58
51
|
}>;
|
|
59
52
|
/**
|
|
60
53
|
* Retrieves the current basket.
|
|
@@ -66,9 +59,9 @@ export declare const addItemsToBasket: (params: {
|
|
|
66
59
|
* @returns The basket data. It will return an `ErrorResponse` alternatively
|
|
67
60
|
* if no session is found or retrieving the basket fails.
|
|
68
61
|
*/
|
|
69
|
-
export declare const getBasket:
|
|
62
|
+
export declare const getBasket: RpcHandler<BasketWithOptions & {
|
|
70
63
|
orderCustomData?: Record<string, unknown>;
|
|
71
|
-
}
|
|
64
|
+
} | undefined, {
|
|
72
65
|
basket: BasketResponseData<Product, Variant>;
|
|
73
66
|
}>;
|
|
74
67
|
/**
|
|
@@ -83,11 +76,11 @@ export declare const getBasket: (options: (BasketWithOptions & {
|
|
|
83
76
|
* @returns The updated basket. It will return an `ErrorResponse` alternatively
|
|
84
77
|
* if no session is found or removing the item fails.
|
|
85
78
|
*/
|
|
86
|
-
export declare const removeItemFromBasket:
|
|
79
|
+
export declare const removeItemFromBasket: RpcHandler<{
|
|
87
80
|
itemKey: string;
|
|
88
81
|
with?: BasketWithOptions;
|
|
89
82
|
orderCustomData?: Record<string, unknown>;
|
|
90
|
-
},
|
|
83
|
+
}, {
|
|
91
84
|
basket: BasketResponseData<Product, Variant>;
|
|
92
85
|
}>;
|
|
93
86
|
/**
|
|
@@ -98,7 +91,7 @@ export declare const removeItemFromBasket: (options: {
|
|
|
98
91
|
* @returns True if the basket was cleared successfully. It will return
|
|
99
92
|
* an `ErrorResponse` alternatively iIf an error occurs during basket clearing.
|
|
100
93
|
*/
|
|
101
|
-
export declare const clearBasket:
|
|
94
|
+
export declare const clearBasket: RpcHandler<boolean>;
|
|
102
95
|
/**
|
|
103
96
|
* Merges two baskets.
|
|
104
97
|
*
|
|
@@ -111,23 +104,12 @@ export declare const clearBasket: (context: RpcContext) => Promise<true | ErrorR
|
|
|
111
104
|
*
|
|
112
105
|
* @returns The new merged basket as result of the merge operation.
|
|
113
106
|
*/
|
|
114
|
-
export declare const mergeBaskets:
|
|
107
|
+
export declare const mergeBaskets: RpcHandler<{
|
|
115
108
|
fromBasketKey: string;
|
|
116
109
|
toBasketKey: string;
|
|
117
110
|
with?: BasketWithOptions;
|
|
118
111
|
orderCustomData?: Record<string, unknown>;
|
|
119
|
-
},
|
|
120
|
-
type: "failure";
|
|
121
|
-
statusCode: number;
|
|
122
|
-
basket: BasketResponseData<Product, Variant>;
|
|
123
|
-
} | {
|
|
124
|
-
readonly type: "success";
|
|
125
|
-
readonly basket: BasketResponseData<Product, Variant>;
|
|
126
|
-
} | {
|
|
127
|
-
readonly type: "failure";
|
|
128
|
-
readonly basket: BasketResponseData<Product, Variant>;
|
|
129
|
-
readonly errors: AddOrUpdateItemError[];
|
|
130
|
-
} | undefined>;
|
|
112
|
+
}, any>;
|
|
131
113
|
/**
|
|
132
114
|
* Type defining an object containing properties of a basket item than should be
|
|
133
115
|
* applied to the basket item during the update.
|
|
@@ -165,6 +147,6 @@ export interface UpdateBasketItemRequestParameter {
|
|
|
165
147
|
* In case of an error the, the failure kind will be resolved.
|
|
166
148
|
* It will return an `ErrorResponse` if no session is found or update operation fails.
|
|
167
149
|
*/
|
|
168
|
-
export declare const updateBasketItem:
|
|
150
|
+
export declare const updateBasketItem: RpcHandler<UpdateBasketItemRequestParameter, {
|
|
169
151
|
basket: BasketResponseData<Product, Variant>;
|
|
170
152
|
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Brand, BrandsEndpointRequestParameters, BrandsEndpointResponseData } from '../../types';
|
|
1
|
+
import type { Brand, BrandsEndpointRequestParameters, BrandsEndpointResponseData, RpcHandler } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* Retrieves a list of brands.
|
|
4
4
|
*
|
|
@@ -13,7 +13,7 @@ import type { Brand, BrandsEndpointRequestParameters, BrandsEndpointResponseData
|
|
|
13
13
|
*
|
|
14
14
|
* @returns The list of brands. It will return an `ErrorResponse` if the request fails.
|
|
15
15
|
*/
|
|
16
|
-
export declare const getBrands:
|
|
16
|
+
export declare const getBrands: RpcHandler<BrandsEndpointRequestParameters, BrandsEndpointResponseData>;
|
|
17
17
|
/**
|
|
18
18
|
* Retrieves a brand by its ID.
|
|
19
19
|
*
|
|
@@ -26,6 +26,6 @@ export declare const getBrands: ({ pagination }: BrandsEndpointRequestParameters
|
|
|
26
26
|
*
|
|
27
27
|
* @returns The brand. It will return an `ErrorResponse` alternatively If the request fails.
|
|
28
28
|
*/
|
|
29
|
-
export declare const getBrandById:
|
|
29
|
+
export declare const getBrandById: RpcHandler<{
|
|
30
30
|
brandId: number;
|
|
31
|
-
},
|
|
31
|
+
}, Brand>;
|
|
@@ -11,7 +11,10 @@ export const getBrands = async function getBrands2({ pagination }, { sapiClient,
|
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
13
|
export const getBrandById = async function getBrandById2({ brandId }, { sapiClient, cached }) {
|
|
14
|
-
return await cached(
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
return await cached(
|
|
15
|
+
mapSAPIFetchErrorToResponse(sapiClient.brands.getById),
|
|
16
|
+
{
|
|
17
|
+
cacheKeyPrefix: `getBrandById-${brandId}`
|
|
18
|
+
}
|
|
19
|
+
)(brandId);
|
|
17
20
|
};
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
sortCampaignsByDateAscending,
|
|
4
4
|
isCampaignActive
|
|
5
5
|
} from "../../utils/campaign.mjs";
|
|
6
|
-
export const getCampaignKey = async (context)
|
|
6
|
+
export const getCampaignKey = async function getCampaignKey2(context) {
|
|
7
7
|
if (context.campaignKey) {
|
|
8
8
|
return context.campaignKey;
|
|
9
9
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Category, ProductCategoryPropertyWith,
|
|
1
|
+
import type { Category, ProductCategoryPropertyWith, RpcHandler } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* Retrieves the root categories.
|
|
4
4
|
*
|
|
@@ -13,11 +13,11 @@ import type { Category, ProductCategoryPropertyWith, RpcContext } from '../../ty
|
|
|
13
13
|
*
|
|
14
14
|
* @returns The root categories and the active node (undefined).
|
|
15
15
|
*/
|
|
16
|
-
export declare const getRootCategories:
|
|
16
|
+
export declare const getRootCategories: RpcHandler<{
|
|
17
17
|
children?: number;
|
|
18
18
|
includeHidden?: true;
|
|
19
19
|
properties?: ProductCategoryPropertyWith;
|
|
20
|
-
},
|
|
20
|
+
}, {
|
|
21
21
|
categories: Category[];
|
|
22
22
|
activeNode: undefined;
|
|
23
23
|
}>;
|
|
@@ -37,12 +37,12 @@ export declare const getRootCategories: ({ children, includeHidden, properties }
|
|
|
37
37
|
* @returns The category or undefined if not found.
|
|
38
38
|
* It will return an `ErrorResponse` if an error occurs during the API call.
|
|
39
39
|
*/
|
|
40
|
-
export declare const getCategoryByPath:
|
|
40
|
+
export declare const getCategoryByPath: RpcHandler<{
|
|
41
41
|
path: string;
|
|
42
42
|
children?: number;
|
|
43
43
|
includeHidden?: true;
|
|
44
44
|
properties?: ProductCategoryPropertyWith;
|
|
45
|
-
},
|
|
45
|
+
}, Category | undefined>;
|
|
46
46
|
/**
|
|
47
47
|
* Retrieves categories by path.
|
|
48
48
|
*
|
|
@@ -58,17 +58,14 @@ export declare const getCategoryByPath: ({ path, children, includeHidden, proper
|
|
|
58
58
|
*
|
|
59
59
|
* @returns The categories data.
|
|
60
60
|
*/
|
|
61
|
-
export declare const getCategoriesByPath:
|
|
61
|
+
export declare const getCategoriesByPath: RpcHandler<{
|
|
62
62
|
path: string;
|
|
63
63
|
children?: number;
|
|
64
64
|
includeHidden?: true;
|
|
65
65
|
properties?: ProductCategoryPropertyWith;
|
|
66
|
-
},
|
|
67
|
-
categories: Category[];
|
|
68
|
-
activeNode
|
|
69
|
-
} | {
|
|
70
|
-
categories: Category;
|
|
71
|
-
activeNode: Category;
|
|
66
|
+
}, {
|
|
67
|
+
categories: Category[] | Category;
|
|
68
|
+
activeNode?: Category;
|
|
72
69
|
}>;
|
|
73
70
|
/**
|
|
74
71
|
* Retrieves a category by ID.
|
|
@@ -85,9 +82,9 @@ export declare const getCategoriesByPath: ({ path, children, includeHidden, prop
|
|
|
85
82
|
*
|
|
86
83
|
* @returns The category. It will return an `ErrorResponse` if category retrieval fails.
|
|
87
84
|
*/
|
|
88
|
-
export declare const getCategoryById:
|
|
85
|
+
export declare const getCategoryById: RpcHandler<{
|
|
89
86
|
id: number;
|
|
90
87
|
children?: number;
|
|
91
88
|
includeHidden?: true;
|
|
92
89
|
properties?: ProductCategoryPropertyWith;
|
|
93
|
-
},
|
|
90
|
+
}, Category>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Order, RpcContext } from '../../types';
|
|
1
|
+
import type { Order, RpcHandler } from '../../types';
|
|
3
2
|
/**
|
|
4
3
|
* Retrieves order data using a CBD token.
|
|
5
4
|
*
|
|
@@ -10,6 +9,6 @@ import type { Order, RpcContext } from '../../types';
|
|
|
10
9
|
* @returns The order data. It will return an `ErrorResponse` alternatively if
|
|
11
10
|
* the CBD token is invalid, expired, or if an error occurs during the order retrieval.
|
|
12
11
|
*/
|
|
13
|
-
export declare const getOrderDataByCbd:
|
|
12
|
+
export declare const getOrderDataByCbd: RpcHandler<{
|
|
14
13
|
cbdToken: string;
|
|
15
|
-
},
|
|
14
|
+
}, Order>;
|
|
@@ -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.18.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
|
|
40
40
|
return {
|
|
41
41
|
accessToken: refreshedAccessToken,
|
|
42
42
|
checkoutJwt
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Order } from '../../../types';
|
|
1
|
+
import type { Order, RpcHandler } from '../../../types';
|
|
3
2
|
/**
|
|
4
3
|
* Retrieves an order by its ID.
|
|
5
4
|
*
|
|
@@ -12,6 +11,6 @@ import type { Order } from '../../../types';
|
|
|
12
11
|
* the order does not belong to the current user, the order is not found,
|
|
13
12
|
* or an unknown error occurs.
|
|
14
13
|
*/
|
|
15
|
-
export declare const getOrderById:
|
|
14
|
+
export declare const getOrderById: RpcHandler<{
|
|
16
15
|
orderId: number;
|
|
17
|
-
},
|
|
16
|
+
}, Order>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { ShopUser, UpdatePasswordParams } from '../../../types';
|
|
1
|
+
import type { RpcHandler, ShopUser, UpdatePasswordParams } from '../../../types';
|
|
3
2
|
/**
|
|
4
3
|
* Updates the shop user.
|
|
5
4
|
*
|
|
@@ -9,7 +8,7 @@ import type { ShopUser, UpdatePasswordParams } from '../../../types';
|
|
|
9
8
|
* @returns The updated user. It will return an `ErrorResponse` alternatively
|
|
10
9
|
* if updating user information fails.
|
|
11
10
|
*/
|
|
12
|
-
export declare const updateShopUser:
|
|
11
|
+
export declare const updateShopUser: RpcHandler<Partial<ShopUser>, {
|
|
13
12
|
user: ShopUser;
|
|
14
13
|
}>;
|
|
15
14
|
/**
|
|
@@ -23,6 +22,6 @@ export declare const updateShopUser: (payload: Partial<ShopUser>, context: impor
|
|
|
23
22
|
* @returns The user object (or undefined if an error occurs and shopUser is undefined).
|
|
24
23
|
* It will return an `ErrorResponse` if updating the password fails.
|
|
25
24
|
*/
|
|
26
|
-
export declare const updatePassword:
|
|
27
|
-
user
|
|
25
|
+
export declare const updatePassword: RpcHandler<UpdatePasswordParams, {
|
|
26
|
+
user?: ShopUser;
|
|
28
27
|
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ShopUserAddress } from '../../../types';
|
|
1
|
+
import type { RpcHandler, ShopUserAddress } from '../../../types';
|
|
2
2
|
/**
|
|
3
3
|
* Retrieves the shop user addresses.
|
|
4
4
|
*
|
|
@@ -6,5 +6,5 @@ import type { ShopUserAddress } from '../../../types';
|
|
|
6
6
|
*
|
|
7
7
|
* @returns The shop user addresses.
|
|
8
8
|
*/
|
|
9
|
-
declare const getShopUserAddresses:
|
|
9
|
+
declare const getShopUserAddresses: RpcHandler<ShopUserAddress[]>;
|
|
10
10
|
export { getShopUserAddresses };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { NavigationAllEndpointResponseData, NavigationTree } from '@scayle/storefront-api';
|
|
2
|
-
import type { FetchNavigationTreeByIdParams, FetchNavigationTreeByNameParams, FetchNavigationTreesParams } from '../../types';
|
|
3
|
-
import { ErrorResponse } from '../../errors';
|
|
2
|
+
import type { FetchNavigationTreeByIdParams, FetchNavigationTreeByNameParams, FetchNavigationTreesParams, RpcHandler } from '../../types';
|
|
4
3
|
/**
|
|
5
4
|
* Fetches all navigation trees.
|
|
6
5
|
*
|
|
@@ -14,7 +13,7 @@ import { ErrorResponse } from '../../errors';
|
|
|
14
13
|
* @returns The navigation trees data. It will return an `ErrorResponse`
|
|
15
14
|
* if an error occurs during fetching.
|
|
16
15
|
*/
|
|
17
|
-
export declare const fetchAllNavigationTrees:
|
|
16
|
+
export declare const fetchAllNavigationTrees: RpcHandler<FetchNavigationTreesParams, NavigationAllEndpointResponseData>;
|
|
18
17
|
/**
|
|
19
18
|
* Fetches a navigation tree by its ID.
|
|
20
19
|
*
|
|
@@ -29,5 +28,5 @@ export declare const fetchAllNavigationTrees: ({ params }: FetchNavigationTreesP
|
|
|
29
28
|
* @returns The navigation tree data. It will return an `ErrorResponse`
|
|
30
29
|
* if an error occurs during fetching.
|
|
31
30
|
*/
|
|
32
|
-
export declare const fetchNavigationTreeById:
|
|
33
|
-
export declare const fetchNavigationTreeByName:
|
|
31
|
+
export declare const fetchNavigationTreeById: RpcHandler<FetchNavigationTreeByIdParams, NavigationTree>;
|
|
32
|
+
export declare const fetchNavigationTreeByName: RpcHandler<FetchNavigationTreeByNameParams, NavigationTree>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { RpcContext } from '../../../types';
|
|
1
|
+
import type { RpcHandler } from '../../../types';
|
|
3
2
|
/**
|
|
4
3
|
* Retrieves external IDP redirect URLs.
|
|
5
4
|
*
|
|
@@ -13,11 +12,9 @@ import type { RpcContext } from '../../../types';
|
|
|
13
12
|
* or an ErrorResponse if an error occurs. It will return an `ErrorResponse`
|
|
14
13
|
* if JWT signing fails or another unexpected error occurs.
|
|
15
14
|
*/
|
|
16
|
-
export declare const getExternalIdpRedirect:
|
|
15
|
+
export declare const getExternalIdpRedirect: RpcHandler<{
|
|
17
16
|
queryParams?: Record<string, string>;
|
|
18
|
-
},
|
|
19
|
-
[k: string]: string;
|
|
20
|
-
}>;
|
|
17
|
+
}, Record<string, string>>;
|
|
21
18
|
/**
|
|
22
19
|
* Handles the IDP login callback.
|
|
23
20
|
*
|
|
@@ -29,8 +26,8 @@ export declare const getExternalIdpRedirect: ({ queryParams }: {
|
|
|
29
26
|
*
|
|
30
27
|
* @returns A success message, or an `ErrorResponse` an error during login occurs.
|
|
31
28
|
*/
|
|
32
|
-
export declare const handleIDPLoginCallback:
|
|
29
|
+
export declare const handleIDPLoginCallback: RpcHandler<{
|
|
33
30
|
code: string;
|
|
34
|
-
},
|
|
31
|
+
}, {
|
|
35
32
|
message: string;
|
|
36
33
|
}>;
|
|
@@ -20,8 +20,8 @@ export declare function resolveCategoryIdFromParams(context: RpcContext, params:
|
|
|
20
20
|
categoryId: number;
|
|
21
21
|
category?: undefined;
|
|
22
22
|
}): Promise<{
|
|
23
|
-
category
|
|
24
|
-
categoryId
|
|
23
|
+
category?: string;
|
|
24
|
+
categoryId?: number;
|
|
25
25
|
}>;
|
|
26
26
|
/**
|
|
27
27
|
* Retrieves a product by its ID.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PromotionsParams,
|
|
1
|
+
import type { PromotionsParams, PromotionsResponseData, RpcHandler } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* Retrieves promotions based on provided parameters.
|
|
4
4
|
*
|
|
@@ -14,7 +14,7 @@ import type { PromotionsParams, RpcContext } from '../../types';
|
|
|
14
14
|
* @returns A Promise that resolves with the promotion data.
|
|
15
15
|
* It will return an `ErrorResponse` if the The Storefront API request fails.
|
|
16
16
|
*/
|
|
17
|
-
export declare const getPromotions:
|
|
17
|
+
export declare const getPromotions: RpcHandler<Omit<PromotionsParams, 'ids'>, PromotionsResponseData>;
|
|
18
18
|
/**
|
|
19
19
|
* Retrieves currently active promotions.
|
|
20
20
|
*
|
|
@@ -30,7 +30,7 @@ export declare const getPromotions: (params: Omit<PromotionsParams, "ids"> | und
|
|
|
30
30
|
* @returns A Promise that resolves with the current promotion data.
|
|
31
31
|
* It will return an `ErrorResponse` if the The Storefront API request fails.
|
|
32
32
|
*/
|
|
33
|
-
export declare const getCurrentPromotions:
|
|
33
|
+
export declare const getCurrentPromotions: RpcHandler<Omit<PromotionsParams, 'ids' | 'activeAt'>, PromotionsResponseData>;
|
|
34
34
|
/**
|
|
35
35
|
* Retrieves promotions by their IDs.
|
|
36
36
|
*
|
|
@@ -43,4 +43,4 @@ export declare const getCurrentPromotions: (params: Omit<PromotionsParams, "ids"
|
|
|
43
43
|
* @returns A Promise that resolves with the promotion data.
|
|
44
44
|
* It will return an `ErrorResponse` if the The Storefront API request fails.
|
|
45
45
|
*/
|
|
46
|
-
export declare const getPromotionsByIds:
|
|
46
|
+
export declare const getPromotionsByIds: RpcHandler<string[], PromotionsResponseData>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { SearchV2ResolveEndpointParameters, SearchV2ResolveEndpointResponseData, SearchV2SuggestionsEndpointParameters, SearchV2SuggestionsEndpointResponseData } from '../../types/sapi/search';
|
|
2
|
+
import type { RpcHandler } from '../../types';
|
|
3
3
|
/**
|
|
4
4
|
* Fetches search suggestions for a given term.
|
|
5
5
|
*
|
|
@@ -12,7 +12,7 @@ import type { RpcContext } from '../../types';
|
|
|
12
12
|
* @returns A promise that resolves to a list of search suggestions.
|
|
13
13
|
* It will return an `ErrorResponse` if the request fails.
|
|
14
14
|
*/
|
|
15
|
-
export declare const getSearchSuggestions:
|
|
15
|
+
export declare const getSearchSuggestions: RpcHandler<SearchV2SuggestionsEndpointParameters, SearchV2SuggestionsEndpointResponseData>;
|
|
16
16
|
/**
|
|
17
17
|
* Resolves a search query and returns the resolved entity.
|
|
18
18
|
*
|
|
@@ -27,4 +27,4 @@ export declare const getSearchSuggestions: ({ term, with: _with, categoryId }: S
|
|
|
27
27
|
*
|
|
28
28
|
* @returns A promise that resolves to the resolved entity or null if no entity is found.
|
|
29
29
|
*/
|
|
30
|
-
export declare const resolveSearch:
|
|
30
|
+
export declare const resolveSearch: RpcHandler<SearchV2ResolveEndpointParameters, Promise<SearchV2ResolveEndpointResponseData | null>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Optional } from 'utility-types';
|
|
2
|
-
import type { GuestRequest, LoginRequest, Oauth,
|
|
2
|
+
import type { GuestRequest, LoginRequest, Oauth, ParamRpcHandler, RegisterRequest, RpcContextWithSession, RpcHandler, UpdatePasswordByHashRequest } from '../../types';
|
|
3
3
|
import { ErrorResponse } from '../../errors';
|
|
4
4
|
/**
|
|
5
5
|
* Handles the post-login logic, including fetching user data, updating tokens,
|
|
@@ -11,7 +11,7 @@ import { ErrorResponse } from '../../errors';
|
|
|
11
11
|
* @returns The result of the post login operation. It will return
|
|
12
12
|
* an `ErrorResponse` if fetching the user or merging baskets/wishlists fails.
|
|
13
13
|
*/
|
|
14
|
-
export declare function postLogin(context: RpcContextWithSession, tokens: Oauth): Promise<
|
|
14
|
+
export declare function postLogin(context: RpcContextWithSession, tokens: Oauth): Promise<ErrorResponse | undefined>;
|
|
15
15
|
/**
|
|
16
16
|
* Handles OAuth login requests.
|
|
17
17
|
*
|
|
@@ -21,7 +21,7 @@ export declare function postLogin(context: RpcContextWithSession, tokens: Oauth)
|
|
|
21
21
|
* @returns A Response object indicating the login status. It will return
|
|
22
22
|
* an `ErrorResponse` if login fails.
|
|
23
23
|
*/
|
|
24
|
-
export declare const oauthLogin:
|
|
24
|
+
export declare const oauthLogin: ParamRpcHandler<Optional<LoginRequest, 'shop_id'>, undefined>;
|
|
25
25
|
/**
|
|
26
26
|
* Handles OAuth user registration requests.
|
|
27
27
|
*
|
|
@@ -31,7 +31,7 @@ export declare const oauthLogin: (login: Optional<LoginRequest, "shop_id">, cont
|
|
|
31
31
|
* @returns A Response object indicating the registration status. It will return
|
|
32
32
|
* an `ErrorResponse` if registration fails.
|
|
33
33
|
*/
|
|
34
|
-
export declare const oauthRegister:
|
|
34
|
+
export declare const oauthRegister: ParamRpcHandler<Optional<RegisterRequest, 'shop_id'>, undefined>;
|
|
35
35
|
/**
|
|
36
36
|
* Handles OAuth guest login requests.
|
|
37
37
|
*
|
|
@@ -41,7 +41,7 @@ export declare const oauthRegister: (register: Optional<RegisterRequest, "shop_i
|
|
|
41
41
|
* @returns A Response object indicating the login status. It will return
|
|
42
42
|
* an `ErrorResponse` if guest login fails.
|
|
43
43
|
*/
|
|
44
|
-
export declare const oauthGuestLogin:
|
|
44
|
+
export declare const oauthGuestLogin: ParamRpcHandler<Optional<GuestRequest, 'shop_id'>, undefined>;
|
|
45
45
|
/**
|
|
46
46
|
* Refreshes the access token using the refresh token.
|
|
47
47
|
*
|
|
@@ -50,10 +50,8 @@ export declare const oauthGuestLogin: (guest: Optional<GuestRequest, "shop_id">,
|
|
|
50
50
|
* @returns An object indicating the success status of the refresh operation.
|
|
51
51
|
* It will return an `ErrorResponse` if refreshing the token fails.
|
|
52
52
|
*/
|
|
53
|
-
export declare const refreshAccessToken:
|
|
54
|
-
success:
|
|
55
|
-
} | {
|
|
56
|
-
success: false;
|
|
53
|
+
export declare const refreshAccessToken: RpcHandler<{
|
|
54
|
+
success: boolean;
|
|
57
55
|
}>;
|
|
58
56
|
/**
|
|
59
57
|
* Revokes the current access token and destroys the session.
|
|
@@ -63,10 +61,8 @@ export declare const refreshAccessToken: (context: RpcContext) => Promise<Respon
|
|
|
63
61
|
* @returns An object indicating the result of the revocation.
|
|
64
62
|
* It will return an `ErrorResponse` if revoking the token fails.
|
|
65
63
|
*/
|
|
66
|
-
export declare const oauthRevokeToken:
|
|
67
|
-
result:
|
|
68
|
-
} | {
|
|
69
|
-
result: false;
|
|
64
|
+
export declare const oauthRevokeToken: RpcHandler<{
|
|
65
|
+
result: boolean;
|
|
70
66
|
}>;
|
|
71
67
|
/**
|
|
72
68
|
* Sends a password reset email to the specified email address.
|
|
@@ -77,12 +73,10 @@ export declare const oauthRevokeToken: (context: RpcContext) => Promise<Response
|
|
|
77
73
|
* @returns An object indicating the success status of the operation.
|
|
78
74
|
* It will return an `ErrorResponse` if sending the password reset email fails.
|
|
79
75
|
*/
|
|
80
|
-
export declare const oauthForgetPassword:
|
|
76
|
+
export declare const oauthForgetPassword: RpcHandler<{
|
|
81
77
|
email: string;
|
|
82
|
-
},
|
|
83
|
-
success:
|
|
84
|
-
} | {
|
|
85
|
-
success: false;
|
|
78
|
+
}, {
|
|
79
|
+
success: boolean;
|
|
86
80
|
}>;
|
|
87
81
|
/**
|
|
88
82
|
* Updates the password using a password hash.
|
|
@@ -93,4 +87,4 @@ export declare const oauthForgetPassword: ({ email }: {
|
|
|
93
87
|
* @returns A Response object indicating the status of the password update.
|
|
94
88
|
* It will return an `ErrorResponse` if updating the password fails.
|
|
95
89
|
*/
|
|
96
|
-
export declare const updatePasswordByHash:
|
|
90
|
+
export declare const updatePasswordByHash: ParamRpcHandler<Optional<UpdatePasswordByHashRequest, 'shop_id'>, undefined>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ShopConfiguration } from '@scayle/storefront-api';
|
|
2
|
-
import type {
|
|
2
|
+
import type { RpcHandler } from '../../types';
|
|
3
3
|
/**
|
|
4
4
|
* Retrieves the shop configuration.
|
|
5
5
|
*
|
|
@@ -11,5 +11,5 @@ import type { RpcContext } from '../../types';
|
|
|
11
11
|
* @returns The shop configuration. It will return an `ErrorResponse` alternatively
|
|
12
12
|
* if the Storefront API request fails.
|
|
13
13
|
*/
|
|
14
|
-
declare const getShopConfiguration:
|
|
14
|
+
declare const getShopConfiguration: RpcHandler<ShopConfiguration>;
|
|
15
15
|
export { getShopConfiguration };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { RpcContext, ShopUser } from '../../types';
|
|
2
|
-
import { ErrorResponse } from '../../errors';
|
|
1
|
+
import type { RpcContext, RpcHandler, ShopUser } from '../../types';
|
|
3
2
|
/**
|
|
4
3
|
* Retrieves the user from the context.
|
|
5
4
|
*
|
|
@@ -7,9 +6,9 @@ import { ErrorResponse } from '../../errors';
|
|
|
7
6
|
*
|
|
8
7
|
* @returns An object containing the user object, or undefined if not logged in.
|
|
9
8
|
*/
|
|
10
|
-
declare const getUser:
|
|
11
|
-
user
|
|
12
|
-
}
|
|
9
|
+
declare const getUser: RpcHandler<{
|
|
10
|
+
user?: ShopUser;
|
|
11
|
+
}>;
|
|
13
12
|
/**
|
|
14
13
|
* Fetches user data using the provided access token.
|
|
15
14
|
*
|
|
@@ -32,10 +31,8 @@ declare const fetchUser: ({ accessToken }: {
|
|
|
32
31
|
* @returns An object containing the user object, or undefined if session is destroyed.
|
|
33
32
|
* It will return an `ErrorResponse` if no session is found or other errors occur.
|
|
34
33
|
*/
|
|
35
|
-
declare const refreshUser:
|
|
36
|
-
user
|
|
37
|
-
} | {
|
|
38
|
-
user: ShopUser;
|
|
34
|
+
declare const refreshUser: RpcHandler<{
|
|
35
|
+
user?: ShopUser;
|
|
39
36
|
}>;
|
|
40
37
|
/**
|
|
41
38
|
* Retrieves or refreshes the access token.
|
|
@@ -47,7 +44,7 @@ declare const refreshUser: (context: RpcContext) => Promise<ErrorResponse | {
|
|
|
47
44
|
* @returns The access token. It will return an `ErrorResponse` alternatively
|
|
48
45
|
* if no session, access token, or refresh token is found.
|
|
49
46
|
*/
|
|
50
|
-
declare const getAccessToken:
|
|
47
|
+
declare const getAccessToken: RpcHandler<{
|
|
51
48
|
forceTokenRefresh?: boolean;
|
|
52
|
-
}
|
|
49
|
+
}, string>;
|
|
53
50
|
export { getUser, fetchUser, refreshUser, getAccessToken };
|
|
@@ -42,7 +42,10 @@ const refreshUser = async function refreshUser2(context) {
|
|
|
42
42
|
return { user: void 0 };
|
|
43
43
|
}
|
|
44
44
|
try {
|
|
45
|
-
const user = await fetchUser
|
|
45
|
+
const user = await context.callRpc?.("fetchUser", { accessToken });
|
|
46
|
+
if (!user) {
|
|
47
|
+
return { user: void 0 };
|
|
48
|
+
}
|
|
46
49
|
context.updateUser(user);
|
|
47
50
|
return { user };
|
|
48
51
|
} catch {
|
|
@@ -10,4 +10,4 @@ import type { ShopUser } from '../../types';
|
|
|
10
10
|
* const multipleUsers = userFactory.buildList(5) // Generates an array of 5 ShopUser objects.
|
|
11
11
|
* ```
|
|
12
12
|
*/
|
|
13
|
-
export declare const userFactory: Factory<ShopUser
|
|
13
|
+
export declare const userFactory: Factory<ShopUser>;
|
package/dist/utils/hash.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @throws {Error} If SFC is built without MD5 support (SFC_OMIT_MD5 environment variable is set).
|
|
12
12
|
*/
|
|
13
|
-
export declare const md5: (value: string) => Promise<
|
|
13
|
+
export declare const md5: (value: string) => Promise<string>;
|
|
14
14
|
/**
|
|
15
15
|
* Calculates the SHA256 hash of a string.
|
|
16
16
|
*
|
package/dist/utils/log.d.ts
CHANGED
|
@@ -95,7 +95,7 @@ export declare class Log {
|
|
|
95
95
|
*
|
|
96
96
|
* @returns A Promise that resolves with the result of the timed function.
|
|
97
97
|
*/
|
|
98
|
-
time(message: string, func: () =>
|
|
98
|
+
time<T = any>(message: string, func: () => T): Promise<T>;
|
|
99
99
|
/**
|
|
100
100
|
* Attaches the log instance to a request object.
|
|
101
101
|
* This is typically used in server middleware.
|
package/dist/utils/timeout.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @returns A Promise that resolves after the specified delay.
|
|
7
7
|
*/
|
|
8
|
-
export declare const wait: (ms: number) => Promise<
|
|
8
|
+
export declare const wait: (ms: number) => Promise<void>;
|
|
9
9
|
/**
|
|
10
10
|
* Wraps a promise with a timeout. Rejects the promise if it doesn't resolve within the given time.
|
|
11
11
|
*
|
package/dist/utils/user.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BasketResponse, AddManyItemsBasketResponse } from '@scayle/storefront-api';
|
|
2
|
+
import type { BasketWithOptions, Product, RpcContext, Variant } from '../types';
|
|
2
3
|
/**
|
|
3
4
|
* Merges two baskets. Adds the items from the `fromBasketKey` basket to the `toBasketKey` basket
|
|
4
5
|
* and then clears the `fromBasketKey` basket. Handles existing items by adding quantities.
|
|
@@ -12,18 +13,7 @@ import type { BasketWithOptions, RpcContext } from '../types';
|
|
|
12
13
|
*/
|
|
13
14
|
export declare const mergeBaskets: (fromBasketKey: string, toBasketKey: string, withOptions: BasketWithOptions & {
|
|
14
15
|
orderCustomData?: Record<string, unknown>;
|
|
15
|
-
}, context: RpcContext) => Promise<
|
|
16
|
-
type: "failure";
|
|
17
|
-
statusCode: number;
|
|
18
|
-
basket: import("@scayle/storefront-api").BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>;
|
|
19
|
-
} | {
|
|
20
|
-
readonly type: "success";
|
|
21
|
-
readonly basket: import("@scayle/storefront-api").BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>;
|
|
22
|
-
} | {
|
|
23
|
-
readonly type: "failure";
|
|
24
|
-
readonly basket: import("@scayle/storefront-api").BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>;
|
|
25
|
-
readonly errors: import("@scayle/storefront-api").AddOrUpdateItemError[];
|
|
26
|
-
} | undefined>;
|
|
16
|
+
}, context: RpcContext) => Promise<BasketResponse<Product, Variant> | AddManyItemsBasketResponse<Product, Variant> | undefined>;
|
|
27
17
|
/**
|
|
28
18
|
* Merges two wishlists. Adds the items from the `fromWishlistKey` wishlist to the `toWishlistKey` wishlist
|
|
29
19
|
* and then clears the `fromWishlistKey` wishlist.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-core",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.18.0",
|
|
4
4
|
"description": "Collection of essential utilities to work with the Storefront API",
|
|
5
5
|
"author": "SCAYLE Commerce Engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"fishery": "^2.2.3"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@scayle/storefront-api": "18.2.
|
|
66
|
+
"@scayle/storefront-api": "18.2.2",
|
|
67
67
|
"@scayle/unstorage-scayle-kv-driver": "0.1.1",
|
|
68
68
|
"crypto-js": "^4.2.0",
|
|
69
69
|
"hookable": "^5.5.3",
|
|
@@ -80,14 +80,17 @@
|
|
|
80
80
|
"@types/webpack-env": "1.18.8",
|
|
81
81
|
"@vitest/coverage-v8": "2.1.9",
|
|
82
82
|
"dprint": "0.49.1",
|
|
83
|
-
"eslint": "9.
|
|
83
|
+
"eslint": "9.24.0",
|
|
84
84
|
"eslint-formatter-gitlab": "5.1.0",
|
|
85
85
|
"fishery": "2.2.3",
|
|
86
86
|
"publint": "0.2.12",
|
|
87
87
|
"rimraf": "6.0.1",
|
|
88
|
-
"typescript": "5.8.
|
|
88
|
+
"typescript": "5.8.3",
|
|
89
89
|
"unbuild": "3.5.0",
|
|
90
90
|
"unstorage": "1.15.0",
|
|
91
91
|
"vitest": "2.1.9"
|
|
92
|
+
},
|
|
93
|
+
"volta": {
|
|
94
|
+
"node": "22.14.0"
|
|
92
95
|
}
|
|
93
96
|
}
|