@scayle/storefront-core 7.25.1 → 7.27.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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 7.27.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Introduce gzip-based compression for unstorage cache interface
8
+ - Upgrade package `@aboutyou/backbone`to `v15.14.3`
9
+
10
+ ## 7.26.0
11
+
12
+ ### Minor Changes
13
+
14
+ - Don't return oauth tokens from RPC methods
15
+
3
16
  ## 7.25.1
4
17
 
5
18
  ### Patch Changes
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.UnstorageCache = void 0;
7
+ var _compression = require("../../utils/compression.cjs");
7
8
  class UnstorageCache {
8
9
  storage;
9
10
  prefix;
@@ -16,7 +17,7 @@ class UnstorageCache {
16
17
  if (value === null) {
17
18
  return null;
18
19
  }
19
- return value;
20
+ return typeof value === "string" ? this.deserialize(value) : value;
20
21
  }
21
22
  async has(key) {
22
23
  return await this.storage.hasItem(this.getKey(key));
@@ -37,7 +38,8 @@ class UnstorageCache {
37
38
  await Promise.all(keys.map(k => this.storage.removeItem(k)));
38
39
  }
39
40
  async set(key, value, ttl, tags = []) {
40
- await this.storage.setItem(this.getKey(key), value, {
41
+ const _value = await this.serialize(value);
42
+ await this.storage.setItem(this.getKey(key), _value, {
41
43
  ttl
42
44
  });
43
45
  await Promise.all(tags.map(tag => this.addKeyToTag(tag, this.getKey(key))));
@@ -51,5 +53,26 @@ class UnstorageCache {
51
53
  getKey(key) {
52
54
  return [this.prefix, key].join(":");
53
55
  }
56
+ /**
57
+ * First iteration copied from `packages/storefront-core/src/cache/providers/redis.ts`
58
+ * @param value String to be deserialized and decompressed
59
+ */
60
+ async deserialize(value) {
61
+ try {
62
+ const data = await (0, _compression.decompress)(value);
63
+ return JSON.parse(data);
64
+ } catch (error) {
65
+ console.warn("UnstorageCache: Unable to decompress data", error);
66
+ return value;
67
+ }
68
+ }
69
+ /**
70
+ * First iteration copied from `packages/storefront-core/src/cache/providers/redis.ts`
71
+ * @param value String to be deserialized and decompressed
72
+ */
73
+ async serialize(value) {
74
+ const data = JSON.stringify(value);
75
+ return await (0, _compression.compress)(data);
76
+ }
54
77
  }
55
78
  exports.UnstorageCache = UnstorageCache;
@@ -13,4 +13,14 @@ export declare class UnstorageCache implements CacheInterface {
13
13
  set(key: string, value: any, ttl: number, tags?: string[]): Promise<void>;
14
14
  private addKeyToTag;
15
15
  private getKey;
16
+ /**
17
+ * First iteration copied from `packages/storefront-core/src/cache/providers/redis.ts`
18
+ * @param value String to be deserialized and decompressed
19
+ */
20
+ private deserialize;
21
+ /**
22
+ * First iteration copied from `packages/storefront-core/src/cache/providers/redis.ts`
23
+ * @param value String to be deserialized and decompressed
24
+ */
25
+ private serialize;
16
26
  }
@@ -1,3 +1,4 @@
1
+ import { compress, decompress } from "../../utils/compression.mjs";
1
2
  export class UnstorageCache {
2
3
  storage;
3
4
  prefix;
@@ -10,7 +11,7 @@ export class UnstorageCache {
10
11
  if (value === null) {
11
12
  return null;
12
13
  }
13
- return value;
14
+ return typeof value === "string" ? this.deserialize(value) : value;
14
15
  }
15
16
  async has(key) {
16
17
  return await this.storage.hasItem(this.getKey(key));
@@ -31,7 +32,8 @@ export class UnstorageCache {
31
32
  await Promise.all(keys.map((k) => this.storage.removeItem(k)));
32
33
  }
33
34
  async set(key, value, ttl, tags = []) {
34
- await this.storage.setItem(this.getKey(key), value, {
35
+ const _value = await this.serialize(value);
36
+ await this.storage.setItem(this.getKey(key), _value, {
35
37
  ttl
36
38
  });
37
39
  await Promise.all(
@@ -47,4 +49,25 @@ export class UnstorageCache {
47
49
  getKey(key) {
48
50
  return [this.prefix, key].join(":");
49
51
  }
52
+ /**
53
+ * First iteration copied from `packages/storefront-core/src/cache/providers/redis.ts`
54
+ * @param value String to be deserialized and decompressed
55
+ */
56
+ async deserialize(value) {
57
+ try {
58
+ const data = await decompress(value);
59
+ return JSON.parse(data);
60
+ } catch (error) {
61
+ console.warn("UnstorageCache: Unable to decompress data", error);
62
+ return value;
63
+ }
64
+ }
65
+ /**
66
+ * First iteration copied from `packages/storefront-core/src/cache/providers/redis.ts`
67
+ * @param value String to be deserialized and decompressed
68
+ */
69
+ async serialize(value) {
70
+ const data = JSON.stringify(value);
71
+ return await compress(data);
72
+ }
50
73
  }
@@ -4,10 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ExistingItemHandling = void 0;
7
- const ExistingItemHandling = {
7
+ const ExistingItemHandling = exports.ExistingItemHandling = {
8
8
  KeepExisting: 0,
9
9
  AddQuantityToExisting: 1,
10
10
  ReplaceExisting: 2,
11
11
  ReplaceExistingWithCombinedQuantity: 3
12
- };
13
- exports.ExistingItemHandling = ExistingItemHandling;
12
+ };
@@ -4,5 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.CACHE_TIMEOUT = void 0;
7
- const CACHE_TIMEOUT = 500;
8
- exports.CACHE_TIMEOUT = CACHE_TIMEOUT;
7
+ const CACHE_TIMEOUT = exports.CACHE_TIMEOUT = 500;
@@ -4,8 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.HashAlgorithm = void 0;
7
- const HashAlgorithm = {
7
+ const HashAlgorithm = exports.HashAlgorithm = {
8
8
  MD5: "md5",
9
9
  SHA256: "sha256"
10
- };
11
- exports.HashAlgorithm = HashAlgorithm;
10
+ };
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.HttpStatusMessage = exports.HttpStatusCode = void 0;
7
- const HttpStatusCode = {
7
+ const HttpStatusCode = exports.HttpStatusCode = {
8
8
  /**
9
9
  * The server has received the request headers and the client should proceed to send the request body
10
10
  * (in the case of a request for which a body needs to be sent; for example, a POST request).
@@ -318,8 +318,7 @@ const HttpStatusCode = {
318
318
  */
319
319
  NETWORK_AUTHENTICATION_REQUIRED: 511
320
320
  };
321
- exports.HttpStatusCode = HttpStatusCode;
322
- const HttpStatusMessage = {
321
+ const HttpStatusMessage = exports.HttpStatusMessage = {
323
322
  /**
324
323
  * The server has received the request headers and the client should proceed to send the request body
325
324
  * (in the case of a request for which a body needs to be sent; for example, a POST request).
@@ -632,5 +631,4 @@ const HttpStatusMessage = {
632
631
  * to require agreement to Terms of Service before granting full Internet access via a Wi-Fi hotspot).
633
632
  */
634
633
  NETWORK_AUTHENTICATION_REQUIRED: "NETWORK AUTHENTICATION REQUIRED"
635
- };
636
- exports.HttpStatusMessage = HttpStatusMessage;
634
+ };
@@ -4,8 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ProductImageType = void 0;
7
- const ProductImageType = {
7
+ const ProductImageType = exports.ProductImageType = {
8
8
  MODEL: "model",
9
9
  BUST: "bust"
10
- };
11
- exports.ProductImageType = ProductImageType;
10
+ };
@@ -4,12 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.PromotionEffectType = exports.PROMOTION_PER_PAGE_DEFAULT = exports.PROMOTION_PAGE_DEFAULT = void 0;
7
- const PROMOTION_PAGE_DEFAULT = 1;
8
- exports.PROMOTION_PAGE_DEFAULT = PROMOTION_PAGE_DEFAULT;
9
- const PROMOTION_PER_PAGE_DEFAULT = 100;
10
- exports.PROMOTION_PER_PAGE_DEFAULT = PROMOTION_PER_PAGE_DEFAULT;
11
- const PromotionEffectType = {
7
+ const PROMOTION_PAGE_DEFAULT = exports.PROMOTION_PAGE_DEFAULT = 1;
8
+ const PROMOTION_PER_PAGE_DEFAULT = exports.PROMOTION_PER_PAGE_DEFAULT = 100;
9
+ const PromotionEffectType = exports.PromotionEffectType = {
12
10
  AUTOMATIC_DISCOUNT: "automatic_discount",
13
11
  BUY_X_GET_Y: "buy_x_get_y"
14
- };
15
- exports.PromotionEffectType = PromotionEffectType;
12
+ };
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.SortQuery = exports.SortName = void 0;
7
- const SortName = {
7
+ const SortName = exports.SortName = {
8
8
  TOPSELLER: "topseller",
9
9
  DATE_NEWEST: "date_newest",
10
10
  PRICE_DESC: "price_desc",
@@ -12,13 +12,11 @@ const SortName = {
12
12
  REDUCTION_DESC: "reduction_desc",
13
13
  REDUCTION_ASC: "reduction_asc"
14
14
  };
15
- exports.SortName = SortName;
16
- const SortQuery = {
15
+ const SortQuery = exports.SortQuery = {
17
16
  TOPSELLER: "topseller",
18
17
  DATE_NEWEST: "date-newest",
19
18
  PRICE_DESC: "price-desc",
20
19
  PRICE_ASC: "price-asc",
21
20
  REDUCTION_DESC: "reduction-desc",
22
21
  REDUCTION_ASC: "reduction-asc"
23
- };
24
- exports.SortQuery = SortQuery;
22
+ };
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.MIN_WITH_PARAMS_WISHLIST = exports.MIN_WITH_PARAMS_VARIANT = exports.MIN_WITH_PARAMS_SEARCH = exports.MIN_WITH_PARAMS_PRODUCT = exports.MIN_WITH_PARAMS_BASKET = exports.DEFAULT_WITH_LISTING = void 0;
7
- const DEFAULT_WITH_LISTING = {
7
+ const DEFAULT_WITH_LISTING = exports.DEFAULT_WITH_LISTING = {
8
8
  items: {
9
9
  product: {
10
10
  attributes: "all",
@@ -24,8 +24,7 @@ const DEFAULT_WITH_LISTING = {
24
24
  }
25
25
  }
26
26
  };
27
- exports.DEFAULT_WITH_LISTING = DEFAULT_WITH_LISTING;
28
- const MIN_WITH_PARAMS_SEARCH = {
27
+ const MIN_WITH_PARAMS_SEARCH = exports.MIN_WITH_PARAMS_SEARCH = {
29
28
  products: {
30
29
  attributes: {
31
30
  withKey: ["brand", "color", "colorDetail", "name"]
@@ -40,8 +39,7 @@ const MIN_WITH_PARAMS_SEARCH = {
40
39
  }
41
40
  }
42
41
  };
43
- exports.MIN_WITH_PARAMS_SEARCH = MIN_WITH_PARAMS_SEARCH;
44
- const MIN_WITH_PARAMS_PRODUCT = {
42
+ const MIN_WITH_PARAMS_PRODUCT = exports.MIN_WITH_PARAMS_PRODUCT = {
45
43
  attributes: {
46
44
  withKey: ["color", "brand", "name", "material", "careSymbol"]
47
45
  },
@@ -69,8 +67,7 @@ const MIN_WITH_PARAMS_PRODUCT = {
69
67
  }
70
68
  }
71
69
  };
72
- exports.MIN_WITH_PARAMS_PRODUCT = MIN_WITH_PARAMS_PRODUCT;
73
- const MIN_WITH_PARAMS_BASKET = {
70
+ const MIN_WITH_PARAMS_BASKET = exports.MIN_WITH_PARAMS_BASKET = {
74
71
  items: {
75
72
  product: {
76
73
  attributes: {
@@ -99,8 +96,7 @@ const MIN_WITH_PARAMS_BASKET = {
99
96
  }
100
97
  }
101
98
  };
102
- exports.MIN_WITH_PARAMS_BASKET = MIN_WITH_PARAMS_BASKET;
103
- const MIN_WITH_PARAMS_WISHLIST = {
99
+ const MIN_WITH_PARAMS_WISHLIST = exports.MIN_WITH_PARAMS_WISHLIST = {
104
100
  items: {
105
101
  product: {
106
102
  attributes: {
@@ -129,10 +125,8 @@ const MIN_WITH_PARAMS_WISHLIST = {
129
125
  }
130
126
  }
131
127
  };
132
- exports.MIN_WITH_PARAMS_WISHLIST = MIN_WITH_PARAMS_WISHLIST;
133
- const MIN_WITH_PARAMS_VARIANT = {
128
+ const MIN_WITH_PARAMS_VARIANT = exports.MIN_WITH_PARAMS_VARIANT = {
134
129
  attributes: {
135
130
  withKey: ["size", "shopSize", "vendorSize"]
136
131
  }
137
- };
138
- exports.MIN_WITH_PARAMS_VARIANT = MIN_WITH_PARAMS_VARIANT;
132
+ };
@@ -7,7 +7,7 @@ exports.productFromEDT = exports.product = exports.priceFixtureWithReductions =
7
7
  const BILD_HINTERGRUND_LABEL = "Bild Hintergrund";
8
8
  const CREATED_AT = "2022-04-26T15:04:56+00:00";
9
9
  const WOMEN_CLOTHING_CATEGORY_URL = "/women/kleidung";
10
- const product = {
10
+ const product = exports.product = {
11
11
  id: 6,
12
12
  isActive: true,
13
13
  isSoldOut: false,
@@ -178,8 +178,7 @@ const product = {
178
178
  categoryProperties: []
179
179
  }]]
180
180
  };
181
- exports.product = product;
182
- const productFromEDT = {
181
+ const productFromEDT = exports.productFromEDT = {
183
182
  id: 5703863,
184
183
  isActive: true,
185
184
  isSoldOut: false,
@@ -763,8 +762,5 @@ const productFromEDT = {
763
762
  categoryProperties: []
764
763
  }]]
765
764
  };
766
- exports.productFromEDT = productFromEDT;
767
- const priceFixture = product.variants[0].price;
768
- exports.priceFixture = priceFixture;
769
- const priceFixtureWithReductions = productFromEDT.variants[0].price;
770
- exports.priceFixtureWithReductions = priceFixtureWithReductions;
765
+ const priceFixture = exports.priceFixture = product.variants[0].price;
766
+ const priceFixtureWithReductions = exports.priceFixtureWithReductions = productFromEDT.variants[0].price;
package/dist/index.cjs CHANGED
@@ -81,5 +81,5 @@ Object.keys(_types).forEach(function (key) {
81
81
  }
82
82
  });
83
83
  });
84
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
85
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
84
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
85
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -11,7 +11,7 @@ const BAPI_ERROR_NAME = "BAPI ERROR";
11
11
  function getWithParams(params, context) {
12
12
  return params.with ?? context.withParams?.basket ?? _constants.MIN_WITH_PARAMS_BASKET;
13
13
  }
14
- const addItemToBasket = async function addItemToBasket2({
14
+ const addItemToBasket = exports.addItemToBasket = async function addItemToBasket2({
15
15
  variantId,
16
16
  promotionId,
17
17
  quantity,
@@ -61,8 +61,7 @@ const addItemToBasket = async function addItemToBasket2({
61
61
  throw new _errors.BAPIError(BAPI_ERROR_NAME, statusCode, message, "addItemToBasket:bapiClient.basket.addOrUpdateItems");
62
62
  }
63
63
  };
64
- exports.addItemToBasket = addItemToBasket;
65
- const addItemsToBasket = async function addItemsToBasket2(params, context) {
64
+ const addItemsToBasket = exports.addItemsToBasket = async function addItemsToBasket2(params, context) {
66
65
  const {
67
66
  campaignKey,
68
67
  bapiClient,
@@ -104,8 +103,7 @@ const addItemsToBasket = async function addItemsToBasket2(params, context) {
104
103
  throw new _errors.BAPIError(BAPI_ERROR_NAME, statusCode, message, "addItemsToBasket:bapiClient.basket.addOrUpdateItems");
105
104
  }
106
105
  };
107
- exports.addItemsToBasket = addItemsToBasket;
108
- const getBasket = async function getBasket2(options, context) {
106
+ const getBasket = exports.getBasket = async function getBasket2(options, context) {
109
107
  const {
110
108
  bapiClient,
111
109
  campaignKey,
@@ -128,8 +126,7 @@ const getBasket = async function getBasket2(options, context) {
128
126
  }
129
127
  return response.basket;
130
128
  };
131
- exports.getBasket = getBasket;
132
- const removeItemFromBasket = async function removeItemFromBasket2(options, context) {
129
+ const removeItemFromBasket = exports.removeItemFromBasket = async function removeItemFromBasket2(options, context) {
133
130
  const {
134
131
  bapiClient,
135
132
  campaignKey,
@@ -142,8 +139,7 @@ const removeItemFromBasket = async function removeItemFromBasket2(options, conte
142
139
  includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData
143
140
  });
144
141
  };
145
- exports.removeItemFromBasket = removeItemFromBasket;
146
- const clearBasket = async function clearBasket2(context) {
142
+ const clearBasket = exports.clearBasket = async function clearBasket2(context) {
147
143
  const basket = await getBasket({}, context);
148
144
  await Promise.all(basket.items.map(async item => {
149
145
  await removeItemFromBasket({
@@ -153,8 +149,7 @@ const clearBasket = async function clearBasket2(context) {
153
149
  context.log.debug("The basket has been cleared");
154
150
  return true;
155
151
  };
156
- exports.clearBasket = clearBasket;
157
- const mergeBaskets = async function mergeBaskets2({
152
+ const mergeBaskets = exports.mergeBaskets = async function mergeBaskets2({
158
153
  fromBasketKey,
159
154
  toBasketKey,
160
155
  with: _with
@@ -164,7 +159,6 @@ const mergeBaskets = async function mergeBaskets2({
164
159
  }, context);
165
160
  return await (0, _user.mergeBaskets)(fromBasketKey, toBasketKey, resolvedWith, context);
166
161
  };
167
- exports.mergeBaskets = mergeBaskets;
168
162
  function parseBasketError(response) {
169
163
  if (response.type === "failure") {
170
164
  const parsedError = {
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getBrands = exports.getBrandById = void 0;
7
7
  const MAX_PER_PAGE = 100;
8
- const getBrands = async function getBrands2({
8
+ const getBrands = exports.getBrands = async function getBrands2({
9
9
  pagination
10
10
  }, {
11
11
  bapiClient,
@@ -20,8 +20,7 @@ const getBrands = async function getBrands2({
20
20
  }
21
21
  });
22
22
  };
23
- exports.getBrands = getBrands;
24
- const getBrandById = async function getBrandById2({
23
+ const getBrandById = exports.getBrandById = async function getBrandById2({
25
24
  brandId
26
25
  }, {
27
26
  bapiClient,
@@ -30,5 +29,4 @@ const getBrandById = async function getBrandById2({
30
29
  return await cached(bapiClient.brands.getById, {
31
30
  cacheKeyPrefix: `getBrandById-${brandId}`
32
31
  })(brandId);
33
- };
34
- exports.getBrandById = getBrandById;
32
+ };
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getRootCategories = exports.getCategoryById = exports.getCategoriesByPath = void 0;
7
7
  var _helpers = require("../../helpers/index.cjs");
8
- const getRootCategories = async function getRootCategories2({
8
+ const getRootCategories = exports.getRootCategories = async function getRootCategories2({
9
9
  children = 1,
10
10
  includeHidden
11
11
  }, {
@@ -25,8 +25,7 @@ const getRootCategories = async function getRootCategories2({
25
25
  activeNode: void 0
26
26
  };
27
27
  };
28
- exports.getRootCategories = getRootCategories;
29
- const getCategoriesByPath = async function getCategoriesByPath2({
28
+ const getCategoriesByPath = exports.getCategoriesByPath = async function getCategoriesByPath2({
30
29
  path,
31
30
  children = 1,
32
31
  includeHidden
@@ -79,8 +78,7 @@ const getCategoriesByPath = async function getCategoriesByPath2({
79
78
  activeNode: result
80
79
  };
81
80
  };
82
- exports.getCategoriesByPath = getCategoriesByPath;
83
- const getCategoryById = async function getCategoryById2({
81
+ const getCategoryById = exports.getCategoryById = async function getCategoryById2({
84
82
  id,
85
83
  children = 1,
86
84
  includeHidden
@@ -98,5 +96,4 @@ const getCategoryById = async function getCategoryById2({
98
96
  },
99
97
  includeHidden
100
98
  });
101
- };
102
- exports.getCategoryById = getCategoryById;
99
+ };
@@ -7,7 +7,7 @@ exports.getOrderDataByCbd = void 0;
7
7
  var _axios = _interopRequireDefault(require("axios"));
8
8
  var _hash = require("../../utils/hash.cjs");
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- const getOrderDataByCbd = async function getOrderDataByCbd2({
10
+ const getOrderDataByCbd = exports.getOrderDataByCbd = async function getOrderDataByCbd2({
11
11
  cbdToken
12
12
  }, context) {
13
13
  if (!cbdToken) {
@@ -41,5 +41,4 @@ const getOrderDataByCbd = async function getOrderDataByCbd2({
41
41
  });
42
42
  return orderSuccessData;
43
43
  }
44
- };
45
- exports.getOrderDataByCbd = getOrderDataByCbd;
44
+ };
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getOrderById = void 0;
7
7
  var _axios = _interopRequireDefault(require("axios"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- const getOrderById = async function getOrderById2({
9
+ const getOrderById = exports.getOrderById = async function getOrderById2({
10
10
  orderId
11
11
  }, context) {
12
12
  const accessToken = context.accessToken;
@@ -51,5 +51,4 @@ const getOrderById = async function getOrderById2({
51
51
  });
52
52
  throw error;
53
53
  }
54
- };
55
- exports.getOrderById = getOrderById;
54
+ };
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.updateShopUser = exports.updatePassword = void 0;
7
7
  var _axios = _interopRequireDefault(require("axios"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- const updateShopUser = async function updateShopUser2(payload, context) {
9
+ const updateShopUser = exports.updateShopUser = async function updateShopUser2(payload, context) {
10
10
  const shopId = context.shopId;
11
11
  const accessHeader = context.checkout.accessHeader;
12
12
  const checkoutUrl = context.checkout.url;
@@ -80,8 +80,7 @@ const updateShopUser = async function updateShopUser2(payload, context) {
80
80
  user
81
81
  };
82
82
  };
83
- exports.updateShopUser = updateShopUser;
84
- const updatePassword = async function updatePassword2({
83
+ const updatePassword = exports.updatePassword = async function updatePassword2({
85
84
  oldPassword,
86
85
  newPassword
87
86
  }, context) {
@@ -121,5 +120,4 @@ const updatePassword = async function updatePassword2({
121
120
  return {
122
121
  user: shopUser
123
122
  };
124
- };
125
- exports.updatePassword = updatePassword;
123
+ };
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getShopUserAddresses = void 0;
7
7
  var _axios = _interopRequireDefault(require("axios"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- const getShopUserAddresses = async function getShopUserAddresses2(context) {
9
+ const getShopUserAddresses = exports.getShopUserAddresses = async function getShopUserAddresses2(context) {
10
10
  const shopId = context.shopId;
11
11
  const accessHeader = context.checkout.accessHeader;
12
12
  const checkoutUrl = context.checkout.url;
@@ -21,5 +21,4 @@ const getShopUserAddresses = async function getShopUserAddresses2(context) {
21
21
  }
22
22
  });
23
23
  return response.data.entities;
24
- };
25
- exports.getShopUserAddresses = getShopUserAddresses;
24
+ };
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.fetchNavigationTreeById = exports.fetchAllNavigationTrees = void 0;
7
- const fetchAllNavigationTrees = async function fetchAllNavigationTrees2({
7
+ const fetchAllNavigationTrees = exports.fetchAllNavigationTrees = async function fetchAllNavigationTrees2({
8
8
  params
9
9
  }, {
10
10
  bapiClient: {
@@ -16,8 +16,7 @@ const fetchAllNavigationTrees = async function fetchAllNavigationTrees2({
16
16
  cacheKeyPrefix: "getAll-navigation-trees"
17
17
  })(params);
18
18
  };
19
- exports.fetchAllNavigationTrees = fetchAllNavigationTrees;
20
- const fetchNavigationTreeById = async function fetchNavigationTreeById2({
19
+ const fetchNavigationTreeById = exports.fetchNavigationTreeById = async function fetchNavigationTreeById2({
21
20
  treeId,
22
21
  params
23
22
  }, {
@@ -29,5 +28,4 @@ const fetchNavigationTreeById = async function fetchNavigationTreeById2({
29
28
  return await cached(navigation.getById, {
30
29
  cacheKeyPrefix: `getById-navigation-trees-${treeId}`
31
30
  })(treeId, params);
32
- };
33
- exports.fetchNavigationTreeById = fetchNavigationTreeById;
31
+ };
@@ -7,7 +7,7 @@ exports.getProductsCount = exports.getProductsByIds = exports.getProductsByCateg
7
7
  var _helpers = require("../../helpers/index.cjs");
8
8
  var _constants = require("../../constants/index.cjs");
9
9
  const MAX_PER_PAGE = 100;
10
- const getProductById = async function getProductById2(options, {
10
+ const getProductById = exports.getProductById = async function getProductById2(options, {
11
11
  bapiClient,
12
12
  cached,
13
13
  campaignKey,
@@ -22,8 +22,7 @@ const getProductById = async function getProductById2(options, {
22
22
  includeSellableForFree: options.includeSellableForFree
23
23
  });
24
24
  };
25
- exports.getProductById = getProductById;
26
- const getProductsByIds = async function getProductsByIds2(options, {
25
+ const getProductsByIds = exports.getProductsByIds = async function getProductsByIds2(options, {
27
26
  bapiClient,
28
27
  cached,
29
28
  campaignKey,
@@ -38,8 +37,7 @@ const getProductsByIds = async function getProductsByIds2(options, {
38
37
  includeSellableForFree: options.includeSellableForFree
39
38
  });
40
39
  };
41
- exports.getProductsByIds = getProductsByIds;
42
- const getProductsByCategory = async function getProductsByCategory2({
40
+ const getProductsByCategory = exports.getProductsByCategory = async function getProductsByCategory2({
43
41
  category = "/",
44
42
  cache,
45
43
  with: _with,
@@ -106,8 +104,7 @@ const getProductsByCategory = async function getProductsByCategory2({
106
104
  pagination
107
105
  };
108
106
  };
109
- exports.getProductsByCategory = getProductsByCategory;
110
- const getFilters = async function getFilters2({
107
+ const getFilters = exports.getFilters = async function getFilters2({
111
108
  category = "/",
112
109
  includedFilters,
113
110
  where = void 0,
@@ -179,8 +176,7 @@ const getFilters = async function getFilters2({
179
176
  unfilteredCount: productCount?.pagination.total
180
177
  };
181
178
  };
182
- exports.getFilters = getFilters;
183
- const fetchAllFiltersForCategory = async function fetchAllFiltersForCategory2({
179
+ const fetchAllFiltersForCategory = exports.fetchAllFiltersForCategory = async function fetchAllFiltersForCategory2({
184
180
  includedFilters = [],
185
181
  category
186
182
  }, {
@@ -204,8 +200,7 @@ const fetchAllFiltersForCategory = async function fetchAllFiltersForCategory2({
204
200
  cacheKey: `filters-for-category-${category.slug}`
205
201
  })();
206
202
  };
207
- exports.fetchAllFiltersForCategory = fetchAllFiltersForCategory;
208
- const getProductsCount = async function getProductsCount2({
203
+ const getProductsCount = exports.getProductsCount = async function getProductsCount2({
209
204
  category = "/",
210
205
  categoryId = void 0,
211
206
  where = void 0,
@@ -246,7 +241,6 @@ const getProductsCount = async function getProductsCount2({
246
241
  count: productCount?.pagination.total
247
242
  };
248
243
  };
249
- exports.getProductsCount = getProductsCount;
250
244
  const sanitizeAttributesForBAPI = ({
251
245
  attributes,
252
246
  filterKeys,
@@ -11,7 +11,7 @@ const setPaginationDefault = pagination => {
11
11
  perPage: pagination?.perPage || _constants.PROMOTION_PER_PAGE_DEFAULT
12
12
  };
13
13
  };
14
- const getPromotions = async function getPromotions2(params = {}, context) {
14
+ const getPromotions = exports.getPromotions = async function getPromotions2(params = {}, context) {
15
15
  const {
16
16
  bapiClient,
17
17
  cached
@@ -23,8 +23,7 @@ const getPromotions = async function getPromotions2(params = {}, context) {
23
23
  pagination: setPaginationDefault(params.pagination)
24
24
  });
25
25
  };
26
- exports.getPromotions = getPromotions;
27
- const getCurrentPromotions = async function getCurrentPromotions2(params = {}, context) {
26
+ const getCurrentPromotions = exports.getCurrentPromotions = async function getCurrentPromotions2(params = {}, context) {
28
27
  const {
29
28
  bapiClient,
30
29
  cached
@@ -40,8 +39,7 @@ const getCurrentPromotions = async function getCurrentPromotions2(params = {}, c
40
39
  pagination: setPaginationDefault(params.pagination)
41
40
  });
42
41
  };
43
- exports.getCurrentPromotions = getCurrentPromotions;
44
- const getPromotionsByIds = async function getPromotionsByIds2(ids, context) {
42
+ const getPromotionsByIds = exports.getPromotionsByIds = async function getPromotionsByIds2(ids, context) {
45
43
  const {
46
44
  bapiClient,
47
45
  cached
@@ -49,5 +47,4 @@ const getPromotionsByIds = async function getPromotionsByIds2(ids, context) {
49
47
  return await cached(bapiClient.promotions.getByIds, {
50
48
  cacheKeyPrefix: "getByIds-promotions"
51
49
  })(ids);
52
- };
53
- exports.getPromotionsByIds = getPromotionsByIds;
50
+ };
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.searchProducts = void 0;
7
7
  var _constants = require("../../constants/index.cjs");
8
8
  var _stringHelpers = require("../../helpers/stringHelpers.cjs");
9
- const searchProducts = async function searchProducts2({
9
+ const searchProducts = exports.searchProducts = async function searchProducts2({
10
10
  term,
11
11
  slug,
12
12
  with: _with,
@@ -25,7 +25,6 @@ const searchProducts = async function searchProducts2({
25
25
  with: _with ?? withParams?.search ?? _constants.MIN_WITH_PARAMS_SEARCH
26
26
  });
27
27
  };
28
- exports.searchProducts = searchProducts;
29
28
  const getCategoryId = async (cached, bapiClient, slug) => {
30
29
  if (!slug) {
31
30
  return;
@@ -26,7 +26,7 @@ function getOAuthSettings(context) {
26
26
  throw new MissingCredentialsError();
27
27
  }
28
28
  const BASIC_AUTH_HASH = (0, _hash.encodeBase64)(`${clientId}:${clientSecret}`);
29
- const axiosInstance2 = _axios.default.create({
29
+ const axiosInstance = _axios.default.create({
30
30
  baseURL: `${apiHost}/v1`,
31
31
  headers: {
32
32
  Authorization: `Basic ${BASIC_AUTH_HASH}`
@@ -36,7 +36,7 @@ function getOAuthSettings(context) {
36
36
  clientId,
37
37
  clientSecret,
38
38
  apiHost,
39
- axiosInstance: axiosInstance2
39
+ axiosInstance
40
40
  };
41
41
  }
42
42
  const saveUserOnSession = async (accessToken, context) => {
@@ -54,13 +54,13 @@ const saveUserOnSession = async (accessToken, context) => {
54
54
  const oauthLogin = async (login, context) => {
55
55
  const shopId = context.shopId;
56
56
  const {
57
- axiosInstance: axiosInstance2
57
+ axiosInstance
58
58
  } = getOAuthSettings(context);
59
59
  if (!login.email || !login.password) {
60
60
  throw new Error("Login or password are missing, seems like validation has failed");
61
61
  }
62
62
  try {
63
- const response = await axiosInstance2.post("/auth/login", {
63
+ const response = await axiosInstance.post("/auth/login", {
64
64
  ...login,
65
65
  shop_id: shopId
66
66
  });
@@ -74,27 +74,21 @@ const oauthLogin = async (login, context) => {
74
74
  } = (0, _jose.decodeJwt)(response.data.access_token);
75
75
  await Promise.all([(0, _user.mergeBaskets)(context.sessionId, await context.generateBasketKeyForUserId(customerId), _constants.DEFAULT_WITH_LISTING, context), (0, _user.mergeWishlists)(context.sessionId, await context.generateWishlistKeyForUserId(customerId), _constants.DEFAULT_WITH_LISTING, context)]);
76
76
  await context.createUserBoundSession();
77
- return {
78
- oauth: response.data
79
- };
80
77
  } catch (error) {
81
78
  const err = (0, _rpc.convertErrorForRpcCall)(error, [_constants.HttpStatusCode.INTERNAL_SERVER_ERROR, _constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusCode.NOT_FOUND]);
82
79
  if (err) {
83
80
  throw err;
84
81
  }
85
- return {
86
- oauth: null
87
- };
88
82
  }
89
83
  };
90
84
  exports.oauthLogin = oauthLogin;
91
85
  const oauthRegister = async (register, context) => {
92
86
  const shopId = context.shopId;
93
87
  const {
94
- axiosInstance: axiosInstance2
88
+ axiosInstance
95
89
  } = getOAuthSettings(context);
96
90
  try {
97
- const response = await axiosInstance2.post("/auth/register", {
91
+ const response = await axiosInstance.post("/auth/register", {
98
92
  ...register,
99
93
  shop_id: shopId
100
94
  });
@@ -108,27 +102,21 @@ const oauthRegister = async (register, context) => {
108
102
  } = (0, _jose.decodeJwt)(response.data.access_token);
109
103
  await Promise.all([(0, _user.mergeBaskets)(context.sessionId, await context.generateBasketKeyForUserId(customerId), _constants.DEFAULT_WITH_LISTING, context), (0, _user.mergeWishlists)(context.sessionId, await context.generateWishlistKeyForUserId(customerId), _constants.DEFAULT_WITH_LISTING, context)]);
110
104
  await context.createUserBoundSession();
111
- return {
112
- oauth: response.data
113
- };
114
105
  } catch (error) {
115
106
  const err = (0, _rpc.convertErrorForRpcCall)(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusCode.CONFLICT]);
116
107
  if (err) {
117
108
  throw err;
118
109
  }
119
- return {
120
- oauth: null
121
- };
122
110
  }
123
111
  };
124
112
  exports.oauthRegister = oauthRegister;
125
113
  const oauthGuestLogin = async (guest, context) => {
126
114
  const shopId = context.shopId;
127
115
  const {
128
- axiosInstance: axiosInstance2
116
+ axiosInstance
129
117
  } = getOAuthSettings(context);
130
118
  try {
131
- const response = await axiosInstance2.post("/auth/login/guest", {
119
+ const response = await axiosInstance.post("/auth/login/guest", {
132
120
  ...guest,
133
121
  shop_id: shopId
134
122
  });
@@ -142,44 +130,39 @@ const oauthGuestLogin = async (guest, context) => {
142
130
  } = (0, _jose.decodeJwt)(response.data.access_token);
143
131
  await Promise.all([(0, _user.mergeBaskets)(context.sessionId, await context.generateBasketKeyForUserId(customerId), _constants.DEFAULT_WITH_LISTING, context), (0, _user.mergeWishlists)(context.sessionId, await context.generateWishlistKeyForUserId(customerId), _constants.DEFAULT_WITH_LISTING, context)]);
144
132
  await context.createUserBoundSession();
145
- return {
146
- oauth: response.data
147
- };
148
133
  } catch (error) {
149
134
  const err = (0, _rpc.convertErrorForRpcCall)(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusCode.CONFLICT]);
150
135
  if (err) {
151
136
  throw err;
152
137
  }
153
- return {
154
- oauth: null
155
- };
156
138
  }
157
139
  };
158
140
  exports.oauthGuestLogin = oauthGuestLogin;
159
141
  const refreshAccessToken = async context => {
160
142
  const refreshToken = context.refreshToken;
161
143
  const {
162
- axiosInstance: axiosInstance2
144
+ axiosInstance
163
145
  } = getOAuthSettings(context);
164
146
  if (!refreshToken) {
165
147
  throw new Error("No app refresh token provided");
166
148
  }
167
149
  try {
168
- const response = await axiosInstance2.post("/oauth/token", {
150
+ const response = await axiosInstance.post("/oauth/token", {
169
151
  grant_type: "refresh_token",
170
152
  refresh_token: refreshToken
171
153
  });
172
154
  context.updateTokens({
173
- accessToken: response.data.access_token,
174
- refreshToken: response.data.refresh_token
155
+ accessToken: response.data?.access_token,
156
+ refreshToken: response.data?.refresh_token
175
157
  });
176
- return response.data;
158
+ return {
159
+ success: !!response.data
160
+ };
177
161
  } catch (error) {
178
162
  const err = (0, _rpc.convertErrorForRpcCall)(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED]);
179
163
  if (err) {
180
164
  throw err;
181
165
  }
182
- return null;
183
166
  }
184
167
  };
185
168
  exports.refreshAccessToken = refreshAccessToken;
@@ -189,6 +172,9 @@ const oauthRevokeToken = async context => {
189
172
  throw new Error("No app oauth authentication credentials");
190
173
  }
191
174
  const decodedAccessToken = (0, _jose.decodeJwt)(accessToken);
175
+ const {
176
+ axiosInstance
177
+ } = getOAuthSettings(context);
192
178
  await context.destroySession();
193
179
  try {
194
180
  await axiosInstance.delete(`/oauth/tokens/${decodedAccessToken.jti}`, {
@@ -215,7 +201,7 @@ const oauthForgetPassword = async ({
215
201
  }, context) => {
216
202
  const shopId = context.shopId;
217
203
  const {
218
- axiosInstance: axiosInstance2
204
+ axiosInstance
219
205
  } = getOAuthSettings(context);
220
206
  try {
221
207
  const resetUrl = new URL(context.auth.resetPasswordUrl);
@@ -224,7 +210,7 @@ const oauthForgetPassword = async ({
224
210
  } else {
225
211
  resetUrl.searchParams.set("hash", "{hash}");
226
212
  }
227
- await axiosInstance2.post("/auth/password/send-reset-email", {
213
+ await axiosInstance.post("/auth/password/send-reset-email", {
228
214
  email,
229
215
  reset_url: decodeURI(resetUrl.toString()),
230
216
  shop_id: shopId
@@ -246,10 +232,10 @@ exports.oauthForgetPassword = oauthForgetPassword;
246
232
  const updatePasswordByHash = async (passwordHash, context) => {
247
233
  const shopId = context.shopId;
248
234
  const {
249
- axiosInstance: axiosInstance2
235
+ axiosInstance
250
236
  } = getOAuthSettings(context);
251
237
  try {
252
- const response = await axiosInstance2.put("/auth/password/update-by-hash", {
238
+ const response = await axiosInstance.put("/auth/password/update-by-hash", {
253
239
  ...passwordHash,
254
240
  shop_id: shopId
255
241
  });
@@ -258,17 +244,11 @@ const updatePasswordByHash = async (passwordHash, context) => {
258
244
  refreshToken: response.data.refresh_token
259
245
  });
260
246
  await context.createUserBoundSession();
261
- return {
262
- oauth: response.data
263
- };
264
247
  } catch (error) {
265
248
  const err = (0, _rpc.convertErrorForRpcCall)(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusCode.NOT_ACCEPTABLE]);
266
249
  if (err) {
267
250
  throw err;
268
251
  }
269
- return {
270
- oauth: null
271
- };
272
252
  }
273
253
  };
274
254
  exports.updatePasswordByHash = updatePasswordByHash;
@@ -1,20 +1,14 @@
1
- import { GuestRequest, LoginRequest, Oauth, RegisterRequest, RpcHandler, SendResetPasswordEmailRequest, UpdatePasswordByHashRequest } from '../../types';
2
- export declare const oauthLogin: RpcHandler<LoginRequest, {
3
- oauth: Oauth | null;
4
- }>;
5
- export declare const oauthRegister: RpcHandler<RegisterRequest, {
6
- oauth: Oauth | null;
7
- }>;
8
- export declare const oauthGuestLogin: RpcHandler<GuestRequest, {
9
- oauth: Oauth | null;
1
+ import { GuestRequest, LoginRequest, ParamRpcHandler, RegisterRequest, RpcHandler, SendResetPasswordEmailRequest, UpdatePasswordByHashRequest } from '../../types';
2
+ export declare const oauthLogin: ParamRpcHandler<LoginRequest, undefined>;
3
+ export declare const oauthRegister: ParamRpcHandler<RegisterRequest, undefined>;
4
+ export declare const oauthGuestLogin: ParamRpcHandler<GuestRequest, undefined>;
5
+ export declare const refreshAccessToken: RpcHandler<{
6
+ success: boolean;
10
7
  }>;
11
- export declare const refreshAccessToken: RpcHandler<Oauth | null>;
12
8
  export declare const oauthRevokeToken: RpcHandler<{
13
9
  result: boolean;
14
10
  }>;
15
11
  export declare const oauthForgetPassword: RpcHandler<SendResetPasswordEmailRequest, {
16
12
  success: boolean;
17
13
  }>;
18
- export declare const updatePasswordByHash: RpcHandler<UpdatePasswordByHashRequest, {
19
- oauth: Oauth | null;
20
- }>;
14
+ export declare const updatePasswordByHash: ParamRpcHandler<UpdatePasswordByHashRequest, undefined>;
@@ -19,7 +19,7 @@ function getOAuthSettings(context) {
19
19
  throw new MissingCredentialsError();
20
20
  }
21
21
  const BASIC_AUTH_HASH = encodeBase64(`${clientId}:${clientSecret}`);
22
- const axiosInstance2 = axios.create({
22
+ const axiosInstance = axios.create({
23
23
  baseURL: `${apiHost}/v1`,
24
24
  headers: {
25
25
  Authorization: `Basic ${BASIC_AUTH_HASH}`
@@ -29,7 +29,7 @@ function getOAuthSettings(context) {
29
29
  clientId,
30
30
  clientSecret,
31
31
  apiHost,
32
- axiosInstance: axiosInstance2
32
+ axiosInstance
33
33
  };
34
34
  }
35
35
  const saveUserOnSession = async (accessToken, context) => {
@@ -46,14 +46,14 @@ const saveUserOnSession = async (accessToken, context) => {
46
46
  };
47
47
  export const oauthLogin = async (login, context) => {
48
48
  const shopId = context.shopId;
49
- const { axiosInstance: axiosInstance2 } = getOAuthSettings(context);
49
+ const { axiosInstance } = getOAuthSettings(context);
50
50
  if (!login.email || !login.password) {
51
51
  throw new Error(
52
52
  "Login or password are missing, seems like validation has failed"
53
53
  );
54
54
  }
55
55
  try {
56
- const response = await axiosInstance2.post(
56
+ const response = await axiosInstance.post(
57
57
  "/auth/login",
58
58
  {
59
59
  ...login,
@@ -81,9 +81,6 @@ export const oauthLogin = async (login, context) => {
81
81
  )
82
82
  ]);
83
83
  await context.createUserBoundSession();
84
- return {
85
- oauth: response.data
86
- };
87
84
  } catch (error) {
88
85
  const err = convertErrorForRpcCall(error, [
89
86
  HttpStatusCode.INTERNAL_SERVER_ERROR,
@@ -94,14 +91,13 @@ export const oauthLogin = async (login, context) => {
94
91
  if (err) {
95
92
  throw err;
96
93
  }
97
- return { oauth: null };
98
94
  }
99
95
  };
100
96
  export const oauthRegister = async (register, context) => {
101
97
  const shopId = context.shopId;
102
- const { axiosInstance: axiosInstance2 } = getOAuthSettings(context);
98
+ const { axiosInstance } = getOAuthSettings(context);
103
99
  try {
104
- const response = await axiosInstance2.post(
100
+ const response = await axiosInstance.post(
105
101
  "/auth/register",
106
102
  {
107
103
  ...register,
@@ -129,9 +125,6 @@ export const oauthRegister = async (register, context) => {
129
125
  )
130
126
  ]);
131
127
  await context.createUserBoundSession();
132
- return {
133
- oauth: response.data
134
- };
135
128
  } catch (error) {
136
129
  const err = convertErrorForRpcCall(error, [
137
130
  HttpStatusCode.BAD_REQUEST,
@@ -141,14 +134,13 @@ export const oauthRegister = async (register, context) => {
141
134
  if (err) {
142
135
  throw err;
143
136
  }
144
- return { oauth: null };
145
137
  }
146
138
  };
147
139
  export const oauthGuestLogin = async (guest, context) => {
148
140
  const shopId = context.shopId;
149
- const { axiosInstance: axiosInstance2 } = getOAuthSettings(context);
141
+ const { axiosInstance } = getOAuthSettings(context);
150
142
  try {
151
- const response = await axiosInstance2.post(
143
+ const response = await axiosInstance.post(
152
144
  "/auth/login/guest",
153
145
  {
154
146
  ...guest,
@@ -176,9 +168,6 @@ export const oauthGuestLogin = async (guest, context) => {
176
168
  )
177
169
  ]);
178
170
  await context.createUserBoundSession();
179
- return {
180
- oauth: response.data
181
- };
182
171
  } catch (error) {
183
172
  const err = convertErrorForRpcCall(error, [
184
173
  HttpStatusCode.BAD_REQUEST,
@@ -188,17 +177,16 @@ export const oauthGuestLogin = async (guest, context) => {
188
177
  if (err) {
189
178
  throw err;
190
179
  }
191
- return { oauth: null };
192
180
  }
193
181
  };
194
182
  export const refreshAccessToken = async (context) => {
195
183
  const refreshToken = context.refreshToken;
196
- const { axiosInstance: axiosInstance2 } = getOAuthSettings(context);
184
+ const { axiosInstance } = getOAuthSettings(context);
197
185
  if (!refreshToken) {
198
186
  throw new Error("No app refresh token provided");
199
187
  }
200
188
  try {
201
- const response = await axiosInstance2.post(
189
+ const response = await axiosInstance.post(
202
190
  "/oauth/token",
203
191
  {
204
192
  grant_type: "refresh_token",
@@ -206,10 +194,10 @@ export const refreshAccessToken = async (context) => {
206
194
  }
207
195
  );
208
196
  context.updateTokens({
209
- accessToken: response.data.access_token,
210
- refreshToken: response.data.refresh_token
197
+ accessToken: response.data?.access_token,
198
+ refreshToken: response.data?.refresh_token
211
199
  });
212
- return response.data;
200
+ return { success: !!response.data };
213
201
  } catch (error) {
214
202
  const err = convertErrorForRpcCall(error, [
215
203
  HttpStatusCode.BAD_REQUEST,
@@ -218,7 +206,6 @@ export const refreshAccessToken = async (context) => {
218
206
  if (err) {
219
207
  throw err;
220
208
  }
221
- return null;
222
209
  }
223
210
  };
224
211
  export const oauthRevokeToken = async (context) => {
@@ -227,6 +214,7 @@ export const oauthRevokeToken = async (context) => {
227
214
  throw new Error("No app oauth authentication credentials");
228
215
  }
229
216
  const decodedAccessToken = decodeJwt(accessToken);
217
+ const { axiosInstance } = getOAuthSettings(context);
230
218
  await context.destroySession();
231
219
  try {
232
220
  await axiosInstance.delete(`/oauth/tokens/${decodedAccessToken.jti}`, {
@@ -249,7 +237,7 @@ export const oauthRevokeToken = async (context) => {
249
237
  };
250
238
  export const oauthForgetPassword = async ({ email }, context) => {
251
239
  const shopId = context.shopId;
252
- const { axiosInstance: axiosInstance2 } = getOAuthSettings(context);
240
+ const { axiosInstance } = getOAuthSettings(context);
253
241
  try {
254
242
  const resetUrl = new URL(context.auth.resetPasswordUrl);
255
243
  if (!resetUrl.searchParams.has("hash")) {
@@ -257,7 +245,7 @@ export const oauthForgetPassword = async ({ email }, context) => {
257
245
  } else {
258
246
  resetUrl.searchParams.set("hash", "{hash}");
259
247
  }
260
- await axiosInstance2.post("/auth/password/send-reset-email", {
248
+ await axiosInstance.post("/auth/password/send-reset-email", {
261
249
  email,
262
250
  reset_url: decodeURI(resetUrl.toString()),
263
251
  shop_id: shopId
@@ -278,9 +266,9 @@ export const oauthForgetPassword = async ({ email }, context) => {
278
266
  };
279
267
  export const updatePasswordByHash = async (passwordHash, context) => {
280
268
  const shopId = context.shopId;
281
- const { axiosInstance: axiosInstance2 } = getOAuthSettings(context);
269
+ const { axiosInstance } = getOAuthSettings(context);
282
270
  try {
283
- const response = await axiosInstance2.put(
271
+ const response = await axiosInstance.put(
284
272
  "/auth/password/update-by-hash",
285
273
  {
286
274
  ...passwordHash,
@@ -292,9 +280,6 @@ export const updatePasswordByHash = async (passwordHash, context) => {
292
280
  refreshToken: response.data.refresh_token
293
281
  });
294
282
  await context.createUserBoundSession();
295
- return {
296
- oauth: response.data
297
- };
298
283
  } catch (error) {
299
284
  const err = convertErrorForRpcCall(error, [
300
285
  HttpStatusCode.BAD_REQUEST,
@@ -304,6 +289,5 @@ export const updatePasswordByHash = async (passwordHash, context) => {
304
289
  if (err) {
305
290
  throw err;
306
291
  }
307
- return { oauth: null };
308
292
  }
309
293
  };
@@ -4,12 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getShopConfiguration = void 0;
7
- const getShopConfiguration = async function getShopConfiguration2({
7
+ const getShopConfiguration = exports.getShopConfiguration = async function getShopConfiguration2({
8
8
  cached,
9
9
  bapiClient
10
10
  }) {
11
11
  return await cached(bapiClient.shopConfiguration.get, {
12
12
  cacheKeyPrefix: "get-shopConfigurations"
13
13
  })();
14
- };
15
- exports.getShopConfiguration = getShopConfiguration;
14
+ };
@@ -7,13 +7,12 @@ exports.refreshUser = exports.getUser = exports.fetchUser = void 0;
7
7
  var _axios = _interopRequireDefault(require("axios"));
8
8
  var _httpStatus = require("../../constants/httpStatus.cjs");
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- const getUser = function getUser2(context) {
10
+ const getUser = exports.getUser = function getUser2(context) {
11
11
  return {
12
12
  user: context.user
13
13
  };
14
14
  };
15
- exports.getUser = getUser;
16
- const fetchUser = async function fetchUser2(payload, options) {
15
+ const fetchUser = exports.fetchUser = async function fetchUser2(payload, options) {
17
16
  const {
18
17
  accessToken
19
18
  } = payload;
@@ -43,8 +42,7 @@ const fetchUser = async function fetchUser2(payload, options) {
43
42
  }
44
43
  };
45
44
  };
46
- exports.fetchUser = fetchUser;
47
- const refreshUser = async function refreshUser2(context) {
45
+ const refreshUser = exports.refreshUser = async function refreshUser2(context) {
48
46
  const {
49
47
  accessToken,
50
48
  checkout,
@@ -85,5 +83,4 @@ const refreshUser = async function refreshUser2(context) {
85
83
  return {
86
84
  user: void 0
87
85
  };
88
- };
89
- exports.refreshUser = refreshUser;
86
+ };
@@ -7,7 +7,7 @@ exports.getVariantById = void 0;
7
7
  const defaultWith = {
8
8
  attributes: "all"
9
9
  };
10
- const getVariantById = async function getVariantById2({
10
+ const getVariantById = exports.getVariantById = async function getVariantById2({
11
11
  ids,
12
12
  include = defaultWith,
13
13
  pricePromotionKey = "default"
@@ -25,5 +25,4 @@ const getVariantById = async function getVariantById2({
25
25
  campaignKey,
26
26
  pricePromotionKey
27
27
  } : void 0);
28
- };
29
- exports.getVariantById = getVariantById;
28
+ };
@@ -9,7 +9,7 @@ var _constants = require("../../constants/index.cjs");
9
9
  function getWithParams(params, context) {
10
10
  return params.with ?? context.withParams?.basket ?? _constants.MIN_WITH_PARAMS_WISHLIST;
11
11
  }
12
- const addItemToWishlist = async function addItemToWishlist2(options, context) {
12
+ const addItemToWishlist = exports.addItemToWishlist = async function addItemToWishlist2(options, context) {
13
13
  const {
14
14
  bapiClient,
15
15
  campaignKey,
@@ -44,8 +44,7 @@ const addItemToWishlist = async function addItemToWishlist2(options, context) {
44
44
  throw new _errors.BAPIError("BAPI ERROR", code, message, "bapiClient.wishlist.addItem");
45
45
  }
46
46
  };
47
- exports.addItemToWishlist = addItemToWishlist;
48
- const getWishlist = async function getWishlist2(options, context) {
47
+ const getWishlist = exports.getWishlist = async function getWishlist2(options, context) {
49
48
  const {
50
49
  bapiClient,
51
50
  campaignKey
@@ -59,8 +58,7 @@ const getWishlist = async function getWishlist2(options, context) {
59
58
  pricePromotionKey: resolvedWith?.pricePromotionKey ?? ""
60
59
  });
61
60
  };
62
- exports.getWishlist = getWishlist;
63
- const removeItemFromWishlist = async function removeItemFromWishlist2(options, context) {
61
+ const removeItemFromWishlist = exports.removeItemFromWishlist = async function removeItemFromWishlist2(options, context) {
64
62
  const {
65
63
  bapiClient,
66
64
  campaignKey,
@@ -72,8 +70,7 @@ const removeItemFromWishlist = async function removeItemFromWishlist2(options, c
72
70
  campaignKey
73
71
  });
74
72
  };
75
- exports.removeItemFromWishlist = removeItemFromWishlist;
76
- const clearWishlist = async function clearWishlist2(context) {
73
+ const clearWishlist = exports.clearWishlist = async function clearWishlist2(context) {
77
74
  const wishlist = await getWishlist({}, context);
78
75
  await Promise.all(wishlist.items.map(async item => {
79
76
  await removeItemFromWishlist({
@@ -81,5 +78,4 @@ const clearWishlist = async function clearWishlist2(context) {
81
78
  }, context);
82
79
  }));
83
80
  return await getWishlist({}, context);
84
- };
85
- exports.clearWishlist = clearWishlist;
81
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "7.25.1",
3
+ "version": "7.27.0",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -56,11 +56,11 @@
56
56
  "test:ci": "jest --passWithNoTests --runInBand --coverage --reporters=default --reporters=jest-junit"
57
57
  },
58
58
  "peerDependencies": {
59
- "@aboutyou/backbone": "15.14.1",
59
+ "@aboutyou/backbone": "15.14.3",
60
60
  "axios": "^0.21.1 || ^0.27.0"
61
61
  },
62
62
  "dependencies": {
63
- "@aboutyou/backbone": "15.14.1",
63
+ "@aboutyou/backbone": "15.14.3",
64
64
  "crypto-js": "4.2.0",
65
65
  "jose": "^4.14.4",
66
66
  "radash": "^11.0.0",
@@ -73,13 +73,13 @@
73
73
  "devDependencies": {
74
74
  "@scayle/eslint-config-storefront": "3.2.5",
75
75
  "@scayle/prettier-config-storefront": "2.0.2",
76
- "@types/crypto-js": "4.1.3",
77
- "@types/jest": "29.5.8",
78
- "@types/node": "20.9.0",
76
+ "@types/crypto-js": "4.2.1",
77
+ "@types/jest": "29.5.10",
78
+ "@types/node": "20.9.4",
79
79
  "@types/webpack-env": "1.18.4",
80
80
  "unbuild": "2.0.0",
81
81
  "axios": "0.27.2",
82
- "eslint": "8.53.0",
82
+ "eslint": "8.54.0",
83
83
  "eslint-formatter-gitlab": "5.1.0",
84
84
  "jest": "29.7.0",
85
85
  "jest-junit": "16.0.0",