@scayle/storefront-core 8.4.0 → 8.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/constants/index.d.ts +0 -1
  3. package/dist/constants/index.mjs +0 -1
  4. package/dist/helpers/filterHelper.d.ts +11 -11
  5. package/dist/helpers/sortingHelper.d.ts +22 -23
  6. package/dist/helpers/sortingHelper.mjs +11 -11
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.mjs +6 -0
  9. package/dist/rpc/methods/basket/basket.d.ts +1 -1
  10. package/dist/rpc/methods/basket/basket.mjs +3 -3
  11. package/dist/rpc/methods/checkout/checkout.mjs +1 -1
  12. package/dist/rpc/methods/search.d.ts +22 -0
  13. package/dist/utils/basket.mjs +2 -2
  14. package/dist/utils/user.d.ts +3 -3
  15. package/dist/utils/user.mjs +2 -2
  16. package/package.json +9 -24
  17. package/dist/api/customer.cjs +0 -164
  18. package/dist/api/oauth.cjs +0 -238
  19. package/dist/cache/cache.cjs +0 -1
  20. package/dist/cache/cached.cjs +0 -90
  21. package/dist/cache/index.cjs +0 -27
  22. package/dist/cache/providers/unstorage.cjs +0 -55
  23. package/dist/constants/basket.cjs +0 -26
  24. package/dist/constants/basket.d.ts +0 -24
  25. package/dist/constants/basket.mjs +0 -20
  26. package/dist/constants/cache.cjs +0 -7
  27. package/dist/constants/hash.cjs +0 -11
  28. package/dist/constants/httpStatus.cjs +0 -634
  29. package/dist/constants/index.cjs +0 -93
  30. package/dist/constants/product.cjs +0 -10
  31. package/dist/constants/promotion.cjs +0 -12
  32. package/dist/constants/sorting.cjs +0 -22
  33. package/dist/constants/withParameters.cjs +0 -132
  34. package/dist/errors/errorResponse.cjs +0 -27
  35. package/dist/errors/index.cjs +0 -16
  36. package/dist/helpers/advancedAttributeHelpers.cjs +0 -30
  37. package/dist/helpers/arrayHelpers.cjs +0 -10
  38. package/dist/helpers/attributeHelpers.cjs +0 -24
  39. package/dist/helpers/basketHelpers.cjs +0 -12
  40. package/dist/helpers/categoryHelper.cjs +0 -61
  41. package/dist/helpers/filterHelper.cjs +0 -185
  42. package/dist/helpers/formHelpers.cjs +0 -114
  43. package/dist/helpers/imageHelpers.cjs +0 -20
  44. package/dist/helpers/index.cjs +0 -181
  45. package/dist/helpers/localization.cjs +0 -13
  46. package/dist/helpers/objectHelpers.cjs +0 -19
  47. package/dist/helpers/orderHelpers.cjs +0 -10
  48. package/dist/helpers/product.fixture.cjs +0 -766
  49. package/dist/helpers/productDisruptorHelper.cjs +0 -37
  50. package/dist/helpers/productHelpers.cjs +0 -156
  51. package/dist/helpers/sanitizationHelpers.cjs +0 -35
  52. package/dist/helpers/sortingHelper.cjs +0 -68
  53. package/dist/helpers/stringHelpers.cjs +0 -8
  54. package/dist/index.cjs +0 -100
  55. package/dist/rpc/methods/basket/basket.cjs +0 -270
  56. package/dist/rpc/methods/brands.cjs +0 -33
  57. package/dist/rpc/methods/categories.cjs +0 -129
  58. package/dist/rpc/methods/cbd.cjs +0 -38
  59. package/dist/rpc/methods/checkout/checkout.cjs +0 -48
  60. package/dist/rpc/methods/checkout/index.cjs +0 -49
  61. package/dist/rpc/methods/checkout/order.cjs +0 -42
  62. package/dist/rpc/methods/checkout/shopUser.cjs +0 -110
  63. package/dist/rpc/methods/checkout/shopUserAddresses.cjs +0 -12
  64. package/dist/rpc/methods/index.cjs +0 -225
  65. package/dist/rpc/methods/navigationTrees.cjs +0 -54
  66. package/dist/rpc/methods/oauth/idp.cjs +0 -59
  67. package/dist/rpc/methods/products.cjs +0 -309
  68. package/dist/rpc/methods/promotion.cjs +0 -51
  69. package/dist/rpc/methods/search.cjs +0 -40
  70. package/dist/rpc/methods/session.cjs +0 -257
  71. package/dist/rpc/methods/shopConfiguration.cjs +0 -15
  72. package/dist/rpc/methods/user.cjs +0 -103
  73. package/dist/rpc/methods/variants.cjs +0 -29
  74. package/dist/rpc/methods/wishlist.cjs +0 -104
  75. package/dist/server.cjs +0 -47
  76. package/dist/test/factories/index.cjs +0 -16
  77. package/dist/types/api/auth.cjs +0 -1
  78. package/dist/types/api/context.cjs +0 -15
  79. package/dist/types/api/rpc.cjs +0 -1
  80. package/dist/types/breadcrumb.cjs +0 -1
  81. package/dist/types/index.cjs +0 -267
  82. package/dist/types/promises.cjs +0 -1
  83. package/dist/types/sapi/basket.cjs +0 -1
  84. package/dist/types/sapi/brand.cjs +0 -1
  85. package/dist/types/sapi/campaign.cjs +0 -1
  86. package/dist/types/sapi/category.cjs +0 -1
  87. package/dist/types/sapi/filter.cjs +0 -1
  88. package/dist/types/sapi/navigation.cjs +0 -1
  89. package/dist/types/sapi/order.cjs +0 -1
  90. package/dist/types/sapi/product.cjs +0 -1
  91. package/dist/types/sapi/productFilter.cjs +0 -1
  92. package/dist/types/sapi/promotion.cjs +0 -1
  93. package/dist/types/sapi/redirects.cjs +0 -1
  94. package/dist/types/sapi/router.cjs +0 -1
  95. package/dist/types/sapi/search.cjs +0 -1
  96. package/dist/types/sapi/sorting.cjs +0 -1
  97. package/dist/types/sapi/variant.cjs +0 -1
  98. package/dist/types/sapi/wishlist.cjs +0 -1
  99. package/dist/types/user.cjs +0 -1
  100. package/dist/utils/basket.cjs +0 -14
  101. package/dist/utils/fetch.cjs +0 -19
  102. package/dist/utils/hash.cjs +0 -72
  103. package/dist/utils/index.cjs +0 -49
  104. package/dist/utils/keys.cjs +0 -67
  105. package/dist/utils/log.cjs +0 -93
  106. package/dist/utils/response.cjs +0 -13
  107. package/dist/utils/sapi.cjs +0 -26
  108. package/dist/utils/timeout.cjs +0 -18
  109. package/dist/utils/user.cjs +0 -90
package/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 8.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Reexport `ExistingItemHandling`,`AddToBasketFailureKind`,`UpdateBasketItemFailureKind`,`AddToWishlistFailureKind`,`PromotionEffectType` and `FilterTypes` from `@scayle/storefront-api`, instead of redefining them in `@scayle/storefront-core`
8
+ - Remove `package.json` and `server` exports.
9
+ - The CommonJS export format will be removed in this version. All exports are provided through ES Modules (`import`/`export`) exclusively
10
+
11
+ This change will primarily affect users who are currently using the CommonJS format of this package. To update your code, you should replace `require` statements with `import` statements and update your build tooling if necessary.
12
+
13
+ ```TypeScript
14
+ const { ... } = require('@scayle/storefront-core');
15
+
16
+ // will become
17
+
18
+ import { ... } from '@scayle/storefront-core';
19
+ ```
20
+
21
+ ### Patch Changes
22
+
23
+ **Dependencies**
24
+
25
+ - Updated dependency to @scayle/storefront-api@18.0.0
26
+
27
+ ## 8.5.0
28
+
29
+ ### Minor Changes
30
+
31
+ - The CommonJS export format will be removed in this version. All exports are provided through ES Modules (`import`/`export`) exclusively
32
+
33
+ This change will primarily affect users who are currently using the CommonJS format of this package. To update your code, you should replace `require` statements with `import` statements and update your build tooling if necessary.
34
+
35
+ ```TypeScript
36
+ const { ... } = require('@scayle/storefront-core');
37
+
38
+ // will become
39
+
40
+ import { ... } from '@scayle/storefront-core';
41
+ ```
42
+
3
43
  ## 8.4.0
4
44
 
5
45
  ### Minor Changes
@@ -1,6 +1,5 @@
1
1
  export * from './withParameters';
2
2
  export * from './cache';
3
- export * from './basket';
4
3
  export * from './httpStatus';
5
4
  export * from './sorting';
6
5
  export * from './product';
@@ -1,6 +1,5 @@
1
1
  export * from "./withParameters.mjs";
2
2
  export * from "./cache.mjs";
3
- export * from "./basket.mjs";
4
3
  export * from "./httpStatus.mjs";
5
4
  export * from "./sorting.mjs";
6
5
  export * from "./product.mjs";
@@ -36,32 +36,32 @@ export declare const getActiveFilters: (filters: Record<string, any>, activeFilt
36
36
  export declare const groupFiltersByKey: (filters: TransformedFilter[]) => [string, TransformedFilter[]][];
37
37
  export declare const transformMinAndMaxPriceToFilter: (prices: (CentAmount | undefined)[]) => any;
38
38
  export declare const transformSortToFilter: (sort: string) => {
39
- by: import("@scayle/storefront-api").APISortOption;
40
- direction: import("@scayle/storefront-api").APISortOrder;
39
+ by: "price";
40
+ direction: "desc";
41
41
  name: "topseller";
42
42
  query: "topseller";
43
43
  } | {
44
- by: import("@scayle/storefront-api").APISortOption;
44
+ by: "new";
45
45
  name: "date_newest";
46
46
  query: "date-newest";
47
47
  } | {
48
- by: import("@scayle/storefront-api").APISortOption;
49
- direction: import("@scayle/storefront-api").APISortOrder;
48
+ by: "price";
49
+ direction: "desc";
50
50
  name: "price_desc";
51
51
  query: "price-desc";
52
52
  } | {
53
- by: import("@scayle/storefront-api").APISortOption;
54
- direction: import("@scayle/storefront-api").APISortOrder;
53
+ by: "price";
54
+ direction: "asc";
55
55
  name: "price_asc";
56
56
  query: "price-asc";
57
57
  } | {
58
- by: import("@scayle/storefront-api").APISortOption;
59
- direction: import("@scayle/storefront-api").APISortOrder;
58
+ by: "reduction";
59
+ direction: "desc";
60
60
  name: "reduction_desc";
61
61
  query: "reduction-desc";
62
62
  } | {
63
- by: import("@scayle/storefront-api").APISortOption;
64
- direction: import("@scayle/storefront-api").APISortOrder;
63
+ by: "reduction";
64
+ direction: "asc";
65
65
  name: "reduction_asc";
66
66
  query: "reduction-asc";
67
67
  };
@@ -1,64 +1,63 @@
1
- import { APISortOption, APISortOrder } from '@scayle/storefront-api';
2
1
  import type { Query, SortingValueKey } from '../index';
3
2
  export declare const getSortingValues: (options?: Array<SortingValueKey>) => {
4
3
  [k: string]: {
5
- by: APISortOption;
6
- direction: APISortOrder;
4
+ by: "price";
5
+ direction: "desc";
7
6
  name: "topseller";
8
7
  query: "topseller";
9
8
  } | {
10
- by: APISortOption;
9
+ by: "new";
11
10
  name: "date_newest";
12
11
  query: "date-newest";
13
12
  } | {
14
- by: APISortOption;
15
- direction: APISortOrder;
13
+ by: "price";
14
+ direction: "desc";
16
15
  name: "price_desc";
17
16
  query: "price-desc";
18
17
  } | {
19
- by: APISortOption;
20
- direction: APISortOrder;
18
+ by: "price";
19
+ direction: "asc";
21
20
  name: "price_asc";
22
21
  query: "price-asc";
23
22
  } | {
24
- by: APISortOption;
25
- direction: APISortOrder;
23
+ by: "reduction";
24
+ direction: "desc";
26
25
  name: "reduction_desc";
27
26
  query: "reduction-desc";
28
27
  } | {
29
- by: APISortOption;
30
- direction: APISortOrder;
28
+ by: "reduction";
29
+ direction: "asc";
31
30
  name: "reduction_asc";
32
31
  query: "reduction-asc";
33
32
  };
34
33
  };
35
34
  export declare const getSortByValue: (query: Query, defaultSort?: SortingValueKey) => {
36
- by: APISortOption;
37
- direction: APISortOrder;
35
+ by: "price";
36
+ direction: "desc";
38
37
  name: "topseller";
39
38
  query: "topseller";
40
39
  } | {
41
- by: APISortOption;
40
+ by: "new";
42
41
  name: "date_newest";
43
42
  query: "date-newest";
44
43
  } | {
45
- by: APISortOption;
46
- direction: APISortOrder;
44
+ by: "price";
45
+ direction: "desc";
47
46
  name: "price_desc";
48
47
  query: "price-desc";
49
48
  } | {
50
- by: APISortOption;
51
- direction: APISortOrder;
49
+ by: "price";
50
+ direction: "asc";
52
51
  name: "price_asc";
53
52
  query: "price-asc";
54
53
  } | {
55
- by: APISortOption;
56
- direction: APISortOrder;
54
+ by: "reduction";
55
+ direction: "desc";
57
56
  name: "reduction_desc";
58
57
  query: "reduction-desc";
59
58
  } | {
60
- by: APISortOption;
61
- direction: APISortOrder;
59
+ by: "reduction";
60
+ direction: "asc";
62
61
  name: "reduction_asc";
63
62
  query: "reduction-asc";
64
63
  };
@@ -2,37 +2,37 @@ import { APISortOption, APISortOrder } from "@scayle/storefront-api";
2
2
  import { SortName, SortQuery } from "../constants/sorting.mjs";
3
3
  const SORTING_VALUES = {
4
4
  topSeller: {
5
- by: APISortOption.Price,
6
- direction: APISortOrder.Descending,
5
+ by: APISortOption.PRICE,
6
+ direction: APISortOrder.DESCENDING,
7
7
  name: SortName.TOPSELLER,
8
8
  query: SortQuery.TOPSELLER
9
9
  },
10
10
  dateNewest: {
11
- by: APISortOption.DateAdded,
11
+ by: APISortOption.DATE_ADDED,
12
12
  name: SortName.DATE_NEWEST,
13
13
  query: SortQuery.DATE_NEWEST
14
14
  },
15
15
  priceDesc: {
16
- by: APISortOption.Price,
17
- direction: APISortOrder.Descending,
16
+ by: APISortOption.PRICE,
17
+ direction: APISortOrder.DESCENDING,
18
18
  name: SortName.PRICE_DESC,
19
19
  query: SortQuery.PRICE_DESC
20
20
  },
21
21
  priceAsc: {
22
- by: APISortOption.Price,
23
- direction: APISortOrder.Ascending,
22
+ by: APISortOption.PRICE,
23
+ direction: APISortOrder.ASCENDING,
24
24
  name: SortName.PRICE_ASC,
25
25
  query: SortQuery.PRICE_ASC
26
26
  },
27
27
  reductionDesc: {
28
- by: APISortOption.Reduction,
29
- direction: APISortOrder.Descending,
28
+ by: APISortOption.REDUCTION,
29
+ direction: APISortOrder.DESCENDING,
30
30
  name: SortName.REDUCTION_DESC,
31
31
  query: SortQuery.REDUCTION_DESC
32
32
  },
33
33
  reductionAsc: {
34
- by: APISortOption.Reduction,
35
- direction: APISortOrder.Ascending,
34
+ by: APISortOption.REDUCTION,
35
+ direction: APISortOrder.ASCENDING,
36
36
  name: SortName.REDUCTION_ASC,
37
37
  query: SortQuery.REDUCTION_ASC
38
38
  }
package/dist/index.d.ts CHANGED
@@ -17,4 +17,4 @@ export type RpcMethodName = Resolve<keyof RpcMethods>;
17
17
  export type RpcMethod<N extends RpcMethodName> = RpcMethods[N];
18
18
  export type RpcMethodParameters<N extends RpcMethodName> = Parameters<RpcMethod<N>>[0];
19
19
  export type RpcMethodReturnType<N extends RpcMethodName> = ReturnType<RpcMethod<N>>;
20
- export { APISortOption, APISortOrder, type ProductSortConfig, } from '@scayle/storefront-api';
20
+ export { ExistingItemHandling, AddToBasketFailureKind, UpdateBasketItemFailureKind, AddToWishlistFailureKind, PromotionEffectType, FilterTypes, APISortOption, APISortOrder, type ProductSortConfig, } from '@scayle/storefront-api';
package/dist/index.mjs CHANGED
@@ -7,6 +7,12 @@ export * from "./cache/index.mjs";
7
7
  export * from "./helpers/index.mjs";
8
8
  export * from "./types/index.mjs";
9
9
  export {
10
+ ExistingItemHandling,
11
+ AddToBasketFailureKind,
12
+ UpdateBasketItemFailureKind,
13
+ AddToWishlistFailureKind,
14
+ PromotionEffectType,
15
+ FilterTypes,
10
16
  APISortOption,
11
17
  APISortOrder
12
18
  } from "@scayle/storefront-api";
@@ -1,7 +1,7 @@
1
+ import { ExistingItemHandling } from '@scayle/storefront-api';
1
2
  import type { AddOrUpdateItemError, UpdateBasketItemQuantity } from '@scayle/storefront-api';
2
3
  import { ErrorResponse } from '../../../errors';
3
4
  import type { AddOrUpdateItemType, BasketResponseData, BasketWithOptions, Product, RpcContext, Variant } from '../../../types';
4
- import { ExistingItemHandling } from '../../../constants';
5
5
  export declare const addItemToBasket: ({ variantId, promotionId, quantity, displayData, customData, existingItemHandling, itemGroup, with: _with, orderCustomData, }: AddOrUpdateItemType & {
6
6
  existingItemHandling?: ExistingItemHandling;
7
7
  with?: BasketWithOptions;
@@ -1,7 +1,7 @@
1
+ import { ExistingItemHandling } from "@scayle/storefront-api";
1
2
  import { ErrorResponse } from "../../../errors/index.mjs";
2
3
  import { hasSession } from "../../../types/index.mjs";
3
4
  import {
4
- ExistingItemHandling,
5
5
  HttpStatusCode,
6
6
  HttpStatusMessage,
7
7
  MIN_WITH_PARAMS_BASKET
@@ -19,7 +19,7 @@ export const addItemToBasket = async function addItemToBasket2({
19
19
  quantity,
20
20
  displayData,
21
21
  customData,
22
- existingItemHandling = ExistingItemHandling.AddQuantityToExisting,
22
+ existingItemHandling = ExistingItemHandling.ADD_QUANTITY_TO_EXISTING,
23
23
  itemGroup,
24
24
  with: _with,
25
25
  orderCustomData
@@ -116,7 +116,7 @@ export const addItemsToBasket = async function addItemsToBasket2(params, context
116
116
  orderCustomData: params.orderCustomData
117
117
  },
118
118
  {
119
- existingItemHandling: params.existingItemHandling || ExistingItemHandling.AddQuantityToExisting
119
+ existingItemHandling: params.existingItemHandling || ExistingItemHandling.ADD_QUANTITY_TO_EXISTING
120
120
  }
121
121
  );
122
122
  if (result.type === "success") {
@@ -35,7 +35,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
35
35
  carrier,
36
36
  basketId: context.basketKey,
37
37
  campaignKey: context.campaignKey
38
- }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.4.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
38
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.6.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
39
39
  return {
40
40
  accessToken: refreshedAccessToken,
41
41
  checkoutJwt
@@ -1,3 +1,25 @@
1
1
  import type { SearchEntity, SearchV2ResolveEndpointParameters, SearchV2SuggestionsEndpointParameters, SearchV2SuggestionsEndpointResponseData } from '../../types/sapi/search';
2
+ /**
3
+ * Fetches search suggestions for a given term.
4
+ *
5
+ * @param option - The parameters for the request.
6
+ * @param option.term - The term to search for.
7
+ * @param option.with - An object describing which data the returned suggestions should contain.
8
+ * @param option.categoryId - The category ID to search within.
9
+ * @param context - The rpc context associated with the request.
10
+ *
11
+ * @returns A promise that resolves to a list of search suggestions.
12
+ */
2
13
  export declare const getSearchSuggestions: ({ term, with: _with, categoryId }: SearchV2SuggestionsEndpointParameters, { sapiClient, withParams }: import("../../types").RpcContext) => Promise<Response | SearchV2SuggestionsEndpointResponseData>;
14
+ /**
15
+ * Resolves a search query and returns the resolved entity.
16
+ *
17
+ * @param option - The parameters for the search query.
18
+ * @param option.term - The search query to resolve.
19
+ * @param option.with - An object describing which data the returned result should contain.
20
+ * @param option.categoryId - The category ID for which the search should be performed.
21
+ * @param context - The rpc context associated with the request.
22
+ *
23
+ * @returns A promise that resolves to the resolved entity or null if no entity is found.
24
+ */
3
25
  export declare const resolveSearch: ({ term, with: _with, categoryId }: SearchV2ResolveEndpointParameters, { cached, sapiClient, withParams }: import("../../types").RpcContext) => Promise<SearchEntity | null>;
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  AddToBasketFailureKind,
3
3
  UpdateBasketItemFailureKind
4
- } from "../constants/index.mjs";
4
+ } from "@scayle/storefront-api";
5
5
  export const wasAddedWithReducedQuantity = (errors) => {
6
6
  if (!errors) {
7
7
  return false;
8
8
  }
9
9
  return errors.every(
10
- (error) => error.operation === "add" && error.kind === AddToBasketFailureKind.ItemAddedWithReducedQuantity || error.operation === "update" && error.kind === UpdateBasketItemFailureKind.ItemAddedWithReducedQuantity
10
+ (error) => error.operation === "add" && error.kind === AddToBasketFailureKind.ITEM_ADDED_WITH_REDUCED_QUANTITY || error.operation === "update" && error.kind === UpdateBasketItemFailureKind.ITEM_ADDED_WITH_REDUCED_QUANTITY
11
11
  );
12
12
  };
@@ -4,13 +4,13 @@ export declare const mergeBaskets: (fromBasketKey: string, toBasketKey: string,
4
4
  }, context: RpcContext) => Promise<{
5
5
  type: "failure";
6
6
  statusCode: number;
7
- basket: import("@scayle/storefront-api/dist/shared/storefront-api.B70Ru0Qh").f<import("@scayle/storefront-api/dist/shared/storefront-api.B70Ru0Qh").a, import("@scayle/storefront-api/dist/shared/storefront-api.B70Ru0Qh").d>;
7
+ basket: import("@scayle/storefront-api").BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>;
8
8
  } | {
9
9
  readonly type: "success";
10
- readonly basket: import("@scayle/storefront-api/dist/shared/storefront-api.B70Ru0Qh").f<import("@scayle/storefront-api/dist/shared/storefront-api.B70Ru0Qh").a, import("@scayle/storefront-api/dist/shared/storefront-api.B70Ru0Qh").d>;
10
+ readonly basket: import("@scayle/storefront-api").BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>;
11
11
  } | {
12
12
  readonly type: "failure";
13
- readonly basket: import("@scayle/storefront-api/dist/shared/storefront-api.B70Ru0Qh").f<import("@scayle/storefront-api/dist/shared/storefront-api.B70Ru0Qh").a, import("@scayle/storefront-api/dist/shared/storefront-api.B70Ru0Qh").d>;
13
+ readonly basket: import("@scayle/storefront-api").BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>;
14
14
  readonly errors: import("@scayle/storefront-api").AddOrUpdateItemError[];
15
15
  } | undefined>;
16
16
  export declare const mergeWishlists: (fromWishlistKey: string, toWishlistKey: string, withOptions: BasketWithOptions, context: RpcContext) => Promise<void>;
@@ -1,4 +1,4 @@
1
- import { ExistingItemHandling } from "../constants/index.mjs";
1
+ import { ExistingItemHandling } from "@scayle/storefront-api";
2
2
  export const mergeBaskets = async (fromBasketKey, toBasketKey, withOptions, context) => {
3
3
  const { sapiClient, campaignKey } = context;
4
4
  const fromOriginBasket = await sapiClient.basket.get(fromBasketKey, {
@@ -33,7 +33,7 @@ export const mergeBaskets = async (fromBasketKey, toBasketKey, withOptions, cont
33
33
  orderCustomData: withOptions.orderCustomData
34
34
  },
35
35
  {
36
- existingItemHandling: ExistingItemHandling.AddQuantityToExisting
36
+ existingItemHandling: ExistingItemHandling.ADD_QUANTITY_TO_EXISTING
37
37
  }
38
38
  );
39
39
  fromBasket.items.map(async (item) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "8.4.0",
3
+ "version": "8.6.0",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -11,39 +11,24 @@
11
11
  "website": "https://scayle.dev/en/storefront-guide/developer-guide/getting-started/about-storefront",
12
12
  "sideEffects": false,
13
13
  "exports": {
14
- "./package.json": "./package.json",
15
14
  ".": {
16
15
  "types": "./dist/index.d.ts",
17
- "import": "./dist/index.mjs",
18
- "require": "./dist/index.cjs",
19
- "default": "./dist/index.cjs"
20
- },
21
- "./server": {
22
- "types": "./dist/server.d.ts",
23
- "import": "./dist/server.mjs",
24
- "require": "./dist/server.cjs",
25
- "default": "./dist/server.cjs"
16
+ "default": "./dist/index.mjs"
26
17
  },
27
18
  "./dist/test/factories": {
28
19
  "types": "./dist/test/factories/index.d.ts",
29
- "import": "./dist/test/factories/index.mjs",
30
- "require": "./dist/test/factories/index.cjs",
31
- "default": "./dist/test/factories/index.cjs"
20
+ "default": "./dist/test/factories/index.mjs"
32
21
  },
33
22
  "./test/factories": {
34
23
  "types": "./dist/test/factories/index.d.ts",
35
- "import": "./dist/test/factories/index.mjs",
36
- "require": "./dist/test/factories/index.cjs",
37
- "default": "./dist/test/factories/index.cjs"
24
+ "default": "./dist/test/factories/index.mjs"
38
25
  },
39
26
  "./dist/*": {
40
27
  "types": "./dist/*.d.ts",
41
- "import": "./dist/*.mjs",
42
- "require": "./dist/*.cjs",
43
- "default": "./dist/*.cjs"
28
+ "default": "./dist/*.mjs"
44
29
  }
45
30
  },
46
- "main": "./dist/index.cjs",
31
+ "main": "./dist/index.mjs",
47
32
  "module": "./dist/index.mjs",
48
33
  "types": "./dist/index.d.ts",
49
34
  "files": [
@@ -71,7 +56,7 @@
71
56
  "test:ci": "vitest --run --passWithNoTests --coverage --reporter=default --reporter=junit --outputFile=./coverage/junit.xml"
72
57
  },
73
58
  "dependencies": {
74
- "@scayle/storefront-api": "17.18.0",
59
+ "@scayle/storefront-api": "18.0.0",
75
60
  "crypto-js": "^4.2.0",
76
61
  "hookable": "^5.5.3",
77
62
  "jose": "^5.6.3",
@@ -83,11 +68,11 @@
83
68
  "devDependencies": {
84
69
  "@scayle/eslint-config-storefront": "4.4.1",
85
70
  "@types/crypto-js": "4.2.2",
86
- "@types/node": "22.13.1",
71
+ "@types/node": "22.13.2",
87
72
  "@types/webpack-env": "1.18.8",
88
73
  "@vitest/coverage-v8": "2.1.9",
89
74
  "dprint": "0.49.0",
90
- "eslint": "9.19.0",
75
+ "eslint": "9.20.1",
91
76
  "eslint-formatter-gitlab": "5.1.0",
92
77
  "publint": "0.2.12",
93
78
  "rimraf": "6.0.1",
@@ -1,164 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CustomerAPIClient = void 0;
7
- var _fetch = require("../utils/fetch.cjs");
8
- var _httpStatus = require("../constants/httpStatus.cjs");
9
- var _oauth = require("./oauth.cjs");
10
- class CustomerAPIClient {
11
- baseURL;
12
- context;
13
- additionalHeaders;
14
- constructor(context) {
15
- this.baseURL = context.checkout.url;
16
- this.context = context;
17
- this.additionalHeaders = context.internalAccessHeader ? {
18
- "x-internal-access": context.internalAccessHeader
19
- } : {};
20
- }
21
- get headers() {
22
- return {
23
- Authorization: `Bearer ${this.context.accessToken}`,
24
- Accept: "application/json",
25
- "Content-Type": "application/json",
26
- ...this.additionalHeaders
27
- };
28
- }
29
- async sendRequest(request, retry = true) {
30
- const response = await request();
31
- if (response.ok) {
32
- return await response.json();
33
- }
34
- if ((response.status === _httpStatus.HttpStatusCode.UNAUTHORIZED && response.headers.get("WWW-Authenticate")?.includes("invalid_token") || response.status === _httpStatus.HttpStatusCode.FORBIDDEN) && this.context.accessToken && this.context.refreshToken) {
35
- if (retry) {
36
- const client = (0, _oauth.getOAuthClient)(this.context);
37
- try {
38
- const tokens = await client.refreshToken({
39
- grant_type: "refresh_token",
40
- refresh_token: this.context.refreshToken
41
- });
42
- this.context.updateTokens({
43
- accessToken: tokens?.access_token,
44
- refreshToken: tokens?.refresh_token
45
- });
46
- } catch (e) {
47
- if (e instanceof _fetch.FetchError && e.response.status === _httpStatus.HttpStatusCode.UNAUTHORIZED) {
48
- this.context.log.debug("Failed to refresh Checkout Token due to invalid refresh token. Deleting session");
49
- await this.context.destroySession();
50
- } else {
51
- this.context.log.debug("Failed to refresh Checkout Token for unknown reason.");
52
- }
53
- throw new _fetch.FetchError(response);
54
- }
55
- return await this.sendRequest(request, false);
56
- } else {
57
- this.context.log.debug("Invalid Checkout Token. Deleting session");
58
- await this.context.destroySession();
59
- }
60
- }
61
- throw new _fetch.FetchError(response);
62
- }
63
- /**
64
- * Get the addresses for the current customer.
65
- *
66
- * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/address/list-addresses
67
- */
68
- async getAddresses(shopId) {
69
- return await this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/customer/addresses`, {
70
- headers: {
71
- ...this.headers,
72
- "X-Shop-Id": shopId.toString()
73
- }
74
- }));
75
- }
76
- /**
77
- * Returns customer data and latest orders.
78
- * When not logged in, it will return `undefined`.
79
- *
80
- * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/get-customer
81
- */
82
- async getMe(shopId, accessToken) {
83
- return await this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/me`, {
84
- headers: {
85
- ...this.headers,
86
- ...(accessToken ? {
87
- Authorization: `Bearer ${accessToken}`
88
- } : {}),
89
- "X-Shop-Id": shopId.toString()
90
- }
91
- }));
92
- }
93
- /**
94
- * Retrieve a customer's order.
95
- *
96
- * @see https://scayle.dev/en/api-guides/customer-account-api/resources/order/get-order
97
- */
98
- async getOrder(shopId, orderId) {
99
- return this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/customer/order/${orderId}`, {
100
- headers: {
101
- ...this.headers,
102
- "X-Shop-Id": shopId.toString()
103
- }
104
- }));
105
- }
106
- /**
107
- * Update contact details of a customer.
108
- *
109
- * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-contact-details
110
- */
111
- async updateContactInfo(shopId, {
112
- email,
113
- phone
114
- }) {
115
- return await this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/customer/contact`, {
116
- method: "PUT",
117
- headers: {
118
- ...this.headers,
119
- "X-Shop-Id": shopId.toString()
120
- },
121
- body: JSON.stringify({
122
- email,
123
- phone
124
- })
125
- }));
126
- }
127
- /**
128
- * Update customer personal data.
129
- *
130
- * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-personal-data
131
- */
132
- async updatePersonalInfo(shopId, payload) {
133
- return await this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/customer/personal`, {
134
- method: "PUT",
135
- headers: {
136
- ...this.headers,
137
- "X-Shop-Id": shopId.toString()
138
- },
139
- body: JSON.stringify(payload)
140
- }));
141
- }
142
- /**
143
- * Update customer password.
144
- *
145
- * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-password
146
- */
147
- async updatePassword(shopId, {
148
- password,
149
- newPassword
150
- }) {
151
- return await this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/customer/password`, {
152
- method: "PUT",
153
- headers: {
154
- ...this.headers,
155
- "X-Shop-Id": shopId.toString()
156
- },
157
- body: JSON.stringify({
158
- password,
159
- newPassword
160
- })
161
- }));
162
- }
163
- }
164
- exports.CustomerAPIClient = CustomerAPIClient;