@scayle/storefront-core 8.3.2 → 8.5.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 (101) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/api/customer.d.ts +19 -13
  3. package/dist/api/customer.mjs +16 -10
  4. package/dist/api/oauth.d.ts +45 -11
  5. package/dist/api/oauth.mjs +43 -10
  6. package/dist/rpc/methods/checkout/checkout.mjs +1 -1
  7. package/dist/rpc/methods/search.d.ts +22 -0
  8. package/dist/types/user.d.ts +1 -1
  9. package/package.json +9 -19
  10. package/dist/api/customer.cjs +0 -158
  11. package/dist/api/oauth.cjs +0 -205
  12. package/dist/cache/cache.cjs +0 -1
  13. package/dist/cache/cached.cjs +0 -90
  14. package/dist/cache/index.cjs +0 -27
  15. package/dist/cache/providers/unstorage.cjs +0 -55
  16. package/dist/constants/basket.cjs +0 -26
  17. package/dist/constants/cache.cjs +0 -7
  18. package/dist/constants/hash.cjs +0 -11
  19. package/dist/constants/httpStatus.cjs +0 -634
  20. package/dist/constants/index.cjs +0 -93
  21. package/dist/constants/product.cjs +0 -10
  22. package/dist/constants/promotion.cjs +0 -12
  23. package/dist/constants/sorting.cjs +0 -22
  24. package/dist/constants/withParameters.cjs +0 -132
  25. package/dist/errors/errorResponse.cjs +0 -27
  26. package/dist/errors/index.cjs +0 -16
  27. package/dist/helpers/advancedAttributeHelpers.cjs +0 -30
  28. package/dist/helpers/arrayHelpers.cjs +0 -10
  29. package/dist/helpers/attributeHelpers.cjs +0 -24
  30. package/dist/helpers/basketHelpers.cjs +0 -12
  31. package/dist/helpers/categoryHelper.cjs +0 -61
  32. package/dist/helpers/filterHelper.cjs +0 -185
  33. package/dist/helpers/formHelpers.cjs +0 -114
  34. package/dist/helpers/imageHelpers.cjs +0 -20
  35. package/dist/helpers/index.cjs +0 -181
  36. package/dist/helpers/localization.cjs +0 -13
  37. package/dist/helpers/objectHelpers.cjs +0 -19
  38. package/dist/helpers/orderHelpers.cjs +0 -10
  39. package/dist/helpers/product.fixture.cjs +0 -766
  40. package/dist/helpers/productDisruptorHelper.cjs +0 -37
  41. package/dist/helpers/productHelpers.cjs +0 -156
  42. package/dist/helpers/sanitizationHelpers.cjs +0 -35
  43. package/dist/helpers/sortingHelper.cjs +0 -68
  44. package/dist/helpers/stringHelpers.cjs +0 -8
  45. package/dist/index.cjs +0 -100
  46. package/dist/rpc/methods/basket/basket.cjs +0 -270
  47. package/dist/rpc/methods/brands.cjs +0 -33
  48. package/dist/rpc/methods/categories.cjs +0 -129
  49. package/dist/rpc/methods/cbd.cjs +0 -38
  50. package/dist/rpc/methods/checkout/checkout.cjs +0 -48
  51. package/dist/rpc/methods/checkout/index.cjs +0 -49
  52. package/dist/rpc/methods/checkout/order.cjs +0 -42
  53. package/dist/rpc/methods/checkout/shopUser.cjs +0 -110
  54. package/dist/rpc/methods/checkout/shopUserAddresses.cjs +0 -12
  55. package/dist/rpc/methods/index.cjs +0 -225
  56. package/dist/rpc/methods/navigationTrees.cjs +0 -54
  57. package/dist/rpc/methods/oauth/idp.cjs +0 -59
  58. package/dist/rpc/methods/products.cjs +0 -309
  59. package/dist/rpc/methods/promotion.cjs +0 -51
  60. package/dist/rpc/methods/search.cjs +0 -40
  61. package/dist/rpc/methods/session.cjs +0 -257
  62. package/dist/rpc/methods/shopConfiguration.cjs +0 -15
  63. package/dist/rpc/methods/user.cjs +0 -103
  64. package/dist/rpc/methods/variants.cjs +0 -29
  65. package/dist/rpc/methods/wishlist.cjs +0 -104
  66. package/dist/server.cjs +0 -47
  67. package/dist/test/factories/index.cjs +0 -16
  68. package/dist/types/api/auth.cjs +0 -1
  69. package/dist/types/api/context.cjs +0 -15
  70. package/dist/types/api/rpc.cjs +0 -1
  71. package/dist/types/breadcrumb.cjs +0 -1
  72. package/dist/types/index.cjs +0 -267
  73. package/dist/types/promises.cjs +0 -1
  74. package/dist/types/sapi/basket.cjs +0 -1
  75. package/dist/types/sapi/brand.cjs +0 -1
  76. package/dist/types/sapi/campaign.cjs +0 -1
  77. package/dist/types/sapi/category.cjs +0 -1
  78. package/dist/types/sapi/filter.cjs +0 -1
  79. package/dist/types/sapi/navigation.cjs +0 -1
  80. package/dist/types/sapi/order.cjs +0 -1
  81. package/dist/types/sapi/product.cjs +0 -1
  82. package/dist/types/sapi/productFilter.cjs +0 -1
  83. package/dist/types/sapi/promotion.cjs +0 -1
  84. package/dist/types/sapi/redirects.cjs +0 -1
  85. package/dist/types/sapi/router.cjs +0 -1
  86. package/dist/types/sapi/search.cjs +0 -1
  87. package/dist/types/sapi/sorting.cjs +0 -1
  88. package/dist/types/sapi/variant.cjs +0 -1
  89. package/dist/types/sapi/wishlist.cjs +0 -1
  90. package/dist/types/user.cjs +0 -1
  91. package/dist/utils/basket.cjs +0 -14
  92. package/dist/utils/fetch.cjs +0 -19
  93. package/dist/utils/hash.cjs +0 -72
  94. package/dist/utils/index.cjs +0 -49
  95. package/dist/utils/keys.cjs +0 -67
  96. package/dist/utils/log.cjs +0 -93
  97. package/dist/utils/response.cjs +0 -13
  98. package/dist/utils/sapi.cjs +0 -26
  99. package/dist/utils/timeout.cjs +0 -18
  100. package/dist/utils/user.cjs +0 -90
  101. /package/dist/api/{README.md → INFO.md} +0 -0
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isFirstIndexOfRow = exports.hasDisruptorAtRow = exports.getRowByIndex = exports.getDisruptorsForRow = void 0;
7
- const getRowByIndex = (index, options = {
8
- columns: 2,
9
- page: 1,
10
- perPage: 24
11
- }) => {
12
- const {
13
- columns,
14
- page,
15
- perPage
16
- } = options;
17
- const adjustedIndex = index + (page - 1) * perPage;
18
- return Math.floor(adjustedIndex / columns);
19
- };
20
- exports.getRowByIndex = getRowByIndex;
21
- const getDisruptorsForRow = (row, disruptors) => {
22
- return disruptors.reduce((c, v, _) => {
23
- if (v.insert_in_row === row.toString()) {
24
- c.push(v);
25
- }
26
- return c;
27
- }, []);
28
- };
29
- exports.getDisruptorsForRow = getDisruptorsForRow;
30
- const isFirstIndexOfRow = (index, columns) => {
31
- return index % columns === 0;
32
- };
33
- exports.isFirstIndexOfRow = isFirstIndexOfRow;
34
- const hasDisruptorAtRow = (row, disruptorRows) => {
35
- return disruptorRows.includes(row.toString());
36
- };
37
- exports.hasDisruptorAtRow = hasDisruptorAtRow;
@@ -1,156 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.slugify = exports.isVariantInStock = exports.isInStock = exports.getVariantCrosssellingValues = exports.getVariantBySize = exports.getVariant = exports.getTotalAppliedReductions = exports.getSizeFromVariant = exports.getSizeFromSpecificVariant = exports.getProductSiblings = exports.getProductPath = exports.getProductColors = exports.getProductAndSiblingsColors = exports.getPrice = exports.getOriginalPrice = exports.getLowestPrice = exports.getLatestCategory = exports.getCategoriesByRoute = exports.getAttribute = exports.getAppliedReductionsByCategory = exports.getAllSizesFromVariants = void 0;
7
- var _storefrontApi = require("@scayle/storefront-api");
8
- var _slugify = _interopRequireDefault(require("slugify"));
9
- var _product = require("../constants/product.cjs");
10
- var _attributeHelpers = require("./attributeHelpers.cjs");
11
- var _imageHelpers = require("./imageHelpers.cjs");
12
- var _arrayHelpers = require("./arrayHelpers.cjs");
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
- const slugify = url => {
15
- return (0, _slugify.default)(url ?? "", {
16
- lower: true,
17
- remove: /[*+~.()'"!:@/#?]/g
18
- });
19
- };
20
- exports.slugify = slugify;
21
- const getPrice = variant => variant.price;
22
- exports.getPrice = getPrice;
23
- const getOriginalPrice = price => {
24
- return price.appliedReductions.length > 0 ? price.appliedReductions[0].amount.absoluteWithTax + price.withTax : price.withTax;
25
- };
26
- exports.getOriginalPrice = getOriginalPrice;
27
- const getTotalAppliedReductions = price => {
28
- const total = {
29
- absoluteWithTax: 0,
30
- relative: 0
31
- };
32
- if (price) {
33
- price.appliedReductions.forEach(reduction => {
34
- total.absoluteWithTax += reduction.amount.absoluteWithTax;
35
- total.relative += reduction.amount.relative;
36
- });
37
- }
38
- return total;
39
- };
40
- exports.getTotalAppliedReductions = getTotalAppliedReductions;
41
- const getLowestPrice = variants => {
42
- return variants.reduce((m, x) => m.price.withoutTax < x.price.withoutTax ? m : x).price;
43
- };
44
- exports.getLowestPrice = getLowestPrice;
45
- const getAppliedReductionsByCategory = (price, category) => {
46
- return price.appliedReductions.filter(reduction => {
47
- return reduction.category === category;
48
- });
49
- };
50
- exports.getAppliedReductionsByCategory = getAppliedReductionsByCategory;
51
- const getSizeFromVariant = (variant, attributeName = "shopSize") => (0, _storefrontApi.getFirstAttributeValue)(variant.attributes, attributeName);
52
- exports.getSizeFromVariant = getSizeFromVariant;
53
- const getSizeFromSpecificVariant = (product, variantId) => {
54
- if (!product.variants) {
55
- return null;
56
- }
57
- const variant = product.variants?.find(item => item.id === variantId);
58
- return getSizeFromVariant(variant || product.variants[0]);
59
- };
60
- exports.getSizeFromSpecificVariant = getSizeFromSpecificVariant;
61
- const getVariant = (variants, id) => {
62
- return variants?.find(variant => variant.id === id);
63
- };
64
- exports.getVariant = getVariant;
65
- const getAllSizesFromVariants = (variantsAttributes, attributeName = "shopSize") => {
66
- const array = variantsAttributes.map(variant => (0, _storefrontApi.getFirstAttributeValue)(variant.attributes, attributeName)).filter(Boolean);
67
- return [...new Map(array.map(item => [item?.id ?? item, item])).values()];
68
- };
69
- exports.getAllSizesFromVariants = getAllSizesFromVariants;
70
- const getProductSiblings = (product, colorAttributeName = "colorDetail") => {
71
- if (!product) {
72
- return [];
73
- }
74
- const items = [product];
75
- product.siblings?.forEach(item => {
76
- if (!item.isActive) {
77
- return;
78
- }
79
- items.push(item);
80
- });
81
- return items.map(item => ({
82
- id: item.id,
83
- image: (0, _imageHelpers.getImageFromList)(item.images, _product.ProductImageType.BUST, "front"),
84
- colors: (0, _attributeHelpers.getAttributeValueTuples)(item.attributes, colorAttributeName)
85
- }));
86
- };
87
- exports.getProductSiblings = getProductSiblings;
88
- const getProductColors = (product, colorAttributeName = "colorDetail") => {
89
- return (0, _attributeHelpers.getAttributeValueTuples)(product.attributes, colorAttributeName).map(color => color.label);
90
- };
91
- exports.getProductColors = getProductColors;
92
- const getVariantBySize = (variants, size, sizeAttributeName = "shopSize") => {
93
- return variants?.find(variant => (0, _attributeHelpers.getAttributeValue)(variant.attributes, sizeAttributeName) === size.value);
94
- };
95
- exports.getVariantBySize = getVariantBySize;
96
- const isInStock = variant => {
97
- return variant.stock.quantity > 0 || variant.stock.isSellableWithoutStock === true;
98
- };
99
- exports.isInStock = isInStock;
100
- const isVariantInStock = (variants, size, sizeAttributeName = "shopSize") => {
101
- const variant = variants?.find(variant2 => getSizeFromVariant(variant2, sizeAttributeName)?.value === size.value);
102
- if (!variant) {
103
- return false;
104
- }
105
- return isInStock(variant);
106
- };
107
- exports.isVariantInStock = isVariantInStock;
108
- const getAttribute = (product, key) => {
109
- const values = product.attributes?.[key]?.values;
110
- return values?.value ?? values?.label;
111
- };
112
- exports.getAttribute = getAttribute;
113
- const getProductPath = product => {
114
- const name = (0, _attributeHelpers.getAttributeValue)(product.attributes, "name");
115
- return `/product/${slugify(name)}-${product.id}`;
116
- };
117
- exports.getProductPath = getProductPath;
118
- const getCategoriesByRoute = (product, route) => {
119
- if (!product) {
120
- return [];
121
- }
122
- const item = product?.categories?.find(categories => {
123
- return categories.some(entry => entry.categoryUrl === route?.path);
124
- });
125
- if (item) {
126
- return item;
127
- }
128
- return product.categories?.[product.categories?.length - 1] || [];
129
- };
130
- exports.getCategoriesByRoute = getCategoriesByRoute;
131
- const getLatestCategory = categories => {
132
- if (!categories || categories.length === 0) {
133
- return;
134
- }
135
- const categoriesLength = categories.length;
136
- const latestSubset = categories[categoriesLength - 1];
137
- return latestSubset[latestSubset.length - 1];
138
- };
139
- exports.getLatestCategory = getLatestCategory;
140
- const getProductAndSiblingsColors = (product, colorAttributeName = "colorDetail") => {
141
- const productColor = (0, _storefrontApi.getFirstAttributeValue)(product.attributes, colorAttributeName);
142
- const siblingsColors = (product.siblings ?? []).filter(sibling => sibling.isActive).map(sibling => (0, _storefrontApi.getFirstAttributeValue)(sibling.attributes, colorAttributeName));
143
- return [productColor, ...siblingsColors].filter(color => !!color);
144
- };
145
- exports.getProductAndSiblingsColors = getProductAndSiblingsColors;
146
- const getVariantCrosssellingValues = variants => {
147
- if (!variants?.length) {
148
- return [];
149
- }
150
- const crossellings = variants.map(variant => variant.advancedAttributes?.variantCrosssellings).filter(Boolean);
151
- const uniqueCrossellings = [...new Map(crossellings.map(item => [item?.id ?? item, item])).values()];
152
- const values = uniqueCrossellings.map(r => r?.values);
153
- const fieldSets = (0, _arrayHelpers.flattenDeep)(values).map(r => r?.fieldSet);
154
- return (0, _arrayHelpers.flattenDeep)(fieldSets).map(r => r?.value).filter(it => !!it);
155
- };
156
- exports.getVariantCrosssellingValues = getVariantCrosssellingValues;
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.stripShopLocaleFromPath = exports.purifySensitiveValue = exports.purifySensitiveData = exports.createAndPurifyHeaders = void 0;
7
- const SANITIZATION_MASK = "********";
8
- const regex = /(?<!^).(?!$)/g;
9
- const stripShopLocaleFromPath = (locale, path, splitter = "/") => path.split(splitter).filter(segment => segment.toLowerCase() !== locale.toLowerCase()).join("/");
10
- exports.stripShopLocaleFromPath = stripShopLocaleFromPath;
11
- const purifySensitiveValue = (value, showFirstAndLastChar = false) => {
12
- return showFirstAndLastChar && value.length > 2 ? value.replace(regex, "*") : SANITIZATION_MASK;
13
- };
14
- exports.purifySensitiveValue = purifySensitiveValue;
15
- const purifySensitiveData = (data = {}, blacklistedKeys = ["password"], showFirstAndLastChar = false) => {
16
- return Object.entries(data).reduce((purifiedPayload, [key, value]) => {
17
- if (!!value && value.constructor === Object) {
18
- purifiedPayload[key] = purifySensitiveData(value, blacklistedKeys);
19
- return purifiedPayload;
20
- }
21
- const isSensitiveData = blacklistedKeys.some(excludedKey => key.includes(excludedKey));
22
- if (isSensitiveData && value) {
23
- purifiedPayload[key] = purifySensitiveValue(value, showFirstAndLastChar);
24
- } else {
25
- purifiedPayload[key] = value;
26
- }
27
- return purifiedPayload;
28
- }, {});
29
- };
30
- exports.purifySensitiveData = purifySensitiveData;
31
- const createAndPurifyHeaders = headers => {
32
- const sanitizedHeaders = Object.fromEntries(Object.entries(headers).filter(([_, value]) => value !== void 0));
33
- return new Headers(sanitizedHeaders);
34
- };
35
- exports.createAndPurifyHeaders = createAndPurifyHeaders;
@@ -1,68 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getSortingValues = exports.getSortByValue = void 0;
7
- var _storefrontApi = require("@scayle/storefront-api");
8
- var _sorting = require("../constants/sorting.cjs");
9
- const SORTING_VALUES = {
10
- topSeller: {
11
- by: _storefrontApi.APISortOption.Price,
12
- direction: _storefrontApi.APISortOrder.Descending,
13
- name: _sorting.SortName.TOPSELLER,
14
- query: _sorting.SortQuery.TOPSELLER
15
- },
16
- dateNewest: {
17
- by: _storefrontApi.APISortOption.DateAdded,
18
- name: _sorting.SortName.DATE_NEWEST,
19
- query: _sorting.SortQuery.DATE_NEWEST
20
- },
21
- priceDesc: {
22
- by: _storefrontApi.APISortOption.Price,
23
- direction: _storefrontApi.APISortOrder.Descending,
24
- name: _sorting.SortName.PRICE_DESC,
25
- query: _sorting.SortQuery.PRICE_DESC
26
- },
27
- priceAsc: {
28
- by: _storefrontApi.APISortOption.Price,
29
- direction: _storefrontApi.APISortOrder.Ascending,
30
- name: _sorting.SortName.PRICE_ASC,
31
- query: _sorting.SortQuery.PRICE_ASC
32
- },
33
- reductionDesc: {
34
- by: _storefrontApi.APISortOption.Reduction,
35
- direction: _storefrontApi.APISortOrder.Descending,
36
- name: _sorting.SortName.REDUCTION_DESC,
37
- query: _sorting.SortQuery.REDUCTION_DESC
38
- },
39
- reductionAsc: {
40
- by: _storefrontApi.APISortOption.Reduction,
41
- direction: _storefrontApi.APISortOrder.Ascending,
42
- name: _sorting.SortName.REDUCTION_ASC,
43
- query: _sorting.SortQuery.REDUCTION_ASC
44
- }
45
- };
46
- const getSortingValues = (options = ["topSeller", "dateNewest", "priceDesc", "priceAsc", "reductionDesc", "reductionAsc"]) => {
47
- return Object.fromEntries(options.filter(key => key in SORTING_VALUES).map(key => [key, SORTING_VALUES[key]]));
48
- };
49
- exports.getSortingValues = getSortingValues;
50
- const getSortByValue = (query, defaultSort) => {
51
- switch (query) {
52
- case _sorting.SortQuery.PRICE_DESC:
53
- return SORTING_VALUES.priceDesc;
54
- case _sorting.SortQuery.PRICE_ASC:
55
- return SORTING_VALUES.priceAsc;
56
- case _sorting.SortQuery.REDUCTION_DESC:
57
- return SORTING_VALUES.reductionDesc;
58
- case _sorting.SortQuery.REDUCTION_ASC:
59
- return SORTING_VALUES.reductionAsc;
60
- case _sorting.SortQuery.TOPSELLER:
61
- return SORTING_VALUES.topSeller;
62
- case _sorting.SortQuery.DATE_NEWEST:
63
- return SORTING_VALUES.dateNewest;
64
- default:
65
- return SORTING_VALUES[defaultSort || "dateNewest"];
66
- }
67
- };
68
- exports.getSortByValue = getSortByValue;
@@ -1,8 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.splitAndRemoveEmpty = void 0;
7
- const splitAndRemoveEmpty = (value, separator = "/") => value.split(separator).filter(string => string !== "");
8
- exports.splitAndRemoveEmpty = splitAndRemoveEmpty;
package/dist/index.cjs DELETED
@@ -1,100 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- rpcMethods: true,
8
- APISortOption: true,
9
- APISortOrder: true
10
- };
11
- Object.defineProperty(exports, "APISortOption", {
12
- enumerable: true,
13
- get: function () {
14
- return _storefrontApi.APISortOption;
15
- }
16
- });
17
- Object.defineProperty(exports, "APISortOrder", {
18
- enumerable: true,
19
- get: function () {
20
- return _storefrontApi.APISortOrder;
21
- }
22
- });
23
- exports.rpcMethods = void 0;
24
- var rpcMethods = _interopRequireWildcard(require("./rpc/methods/index.cjs"));
25
- exports.rpcMethods = rpcMethods;
26
- var _errors = require("./errors/index.cjs");
27
- Object.keys(_errors).forEach(function (key) {
28
- if (key === "default" || key === "__esModule") return;
29
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
30
- if (key in exports && exports[key] === _errors[key]) return;
31
- Object.defineProperty(exports, key, {
32
- enumerable: true,
33
- get: function () {
34
- return _errors[key];
35
- }
36
- });
37
- });
38
- var _utils = require("./utils/index.cjs");
39
- Object.keys(_utils).forEach(function (key) {
40
- if (key === "default" || key === "__esModule") return;
41
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
42
- if (key in exports && exports[key] === _utils[key]) return;
43
- Object.defineProperty(exports, key, {
44
- enumerable: true,
45
- get: function () {
46
- return _utils[key];
47
- }
48
- });
49
- });
50
- var _constants = require("./constants/index.cjs");
51
- Object.keys(_constants).forEach(function (key) {
52
- if (key === "default" || key === "__esModule") return;
53
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
54
- if (key in exports && exports[key] === _constants[key]) return;
55
- Object.defineProperty(exports, key, {
56
- enumerable: true,
57
- get: function () {
58
- return _constants[key];
59
- }
60
- });
61
- });
62
- var _cache = require("./cache/index.cjs");
63
- Object.keys(_cache).forEach(function (key) {
64
- if (key === "default" || key === "__esModule") return;
65
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
66
- if (key in exports && exports[key] === _cache[key]) return;
67
- Object.defineProperty(exports, key, {
68
- enumerable: true,
69
- get: function () {
70
- return _cache[key];
71
- }
72
- });
73
- });
74
- var _helpers = require("./helpers/index.cjs");
75
- Object.keys(_helpers).forEach(function (key) {
76
- if (key === "default" || key === "__esModule") return;
77
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
78
- if (key in exports && exports[key] === _helpers[key]) return;
79
- Object.defineProperty(exports, key, {
80
- enumerable: true,
81
- get: function () {
82
- return _helpers[key];
83
- }
84
- });
85
- });
86
- var _types = require("./types/index.cjs");
87
- Object.keys(_types).forEach(function (key) {
88
- if (key === "default" || key === "__esModule") return;
89
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
90
- if (key in exports && exports[key] === _types[key]) return;
91
- Object.defineProperty(exports, key, {
92
- enumerable: true,
93
- get: function () {
94
- return _types[key];
95
- }
96
- });
97
- });
98
- var _storefrontApi = require("@scayle/storefront-api");
99
- 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); }
100
- 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 && {}.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; }
@@ -1,270 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.updateBasketItem = exports.removeItemFromBasket = exports.mergeBaskets = exports.getBasket = exports.clearBasket = exports.addItemsToBasket = exports.addItemToBasket = void 0;
7
- var _errors = require("../../../errors/index.cjs");
8
- var _types = require("../../../types/index.cjs");
9
- var _constants = require("../../../constants/index.cjs");
10
- var _user = require("../../../utils/user.cjs");
11
- var _response = require("../../../utils/response.cjs");
12
- var _utils = require("../../../utils/index.cjs");
13
- const SAPI_ERROR_NAME = "SAPI ERROR";
14
- function getWithParams(params, context) {
15
- return params.with ?? context.withParams?.basket ?? _constants.MIN_WITH_PARAMS_BASKET;
16
- }
17
- const addItemToBasket = exports.addItemToBasket = async function addItemToBasket2({
18
- variantId,
19
- promotionId,
20
- quantity,
21
- displayData,
22
- customData,
23
- existingItemHandling = _constants.ExistingItemHandling.AddQuantityToExisting,
24
- itemGroup,
25
- with: _with,
26
- orderCustomData
27
- }, context) {
28
- if (!(0, _types.hasSession)(context)) {
29
- return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
30
- }
31
- const {
32
- campaignKey,
33
- sapiClient,
34
- basketKey
35
- } = context;
36
- const resolvedWith = getWithParams({
37
- with: _with
38
- }, context);
39
- const result = await sapiClient.basket.addOrUpdateItems(basketKey, [{
40
- variantId,
41
- quantity,
42
- params: {
43
- promotionId: promotionId ?? void 0,
44
- campaignKey,
45
- displayData,
46
- pricePromotionKey: resolvedWith?.pricePromotionKey || "",
47
- customData,
48
- itemGroup,
49
- with: resolvedWith,
50
- includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData
51
- }
52
- }], {
53
- skipAvailabilityCheck: false,
54
- orderCustomData
55
- }, {
56
- existingItemHandling
57
- });
58
- if (result.type === "success") {
59
- return {
60
- basket: result.basket
61
- };
62
- } else if (result.type === "failure" && (0, _utils.wasAddedWithReducedQuantity)(result.errors)) {
63
- return {
64
- basket: result.basket,
65
- errors: result.errors
66
- };
67
- } else {
68
- const {
69
- message,
70
- statusCode
71
- } = parseBasketError(result);
72
- context.log.error("Adding item to basket failed", {
73
- message,
74
- statusCode
75
- });
76
- return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, SAPI_ERROR_NAME, "Adding item to basket failed", {
77
- detail: message,
78
- errors: result.errors
79
- });
80
- }
81
- };
82
- const addItemsToBasket = exports.addItemsToBasket = async function addItemsToBasket2(params, context) {
83
- if (!(0, _types.hasSession)(context)) {
84
- return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
85
- }
86
- const {
87
- campaignKey,
88
- sapiClient,
89
- basketKey
90
- } = context;
91
- const resolvedWith = getWithParams(params, context);
92
- const itemsToBeAddedOrUpdated = params.items.map(item => ({
93
- variantId: item.variantId,
94
- quantity: item.quantity,
95
- params: {
96
- promotionId: item.promotionId ?? void 0,
97
- campaignKey,
98
- displayData: item.displayData,
99
- pricePromotionKey: resolvedWith?.pricePromotionKey || "",
100
- customData: item.customData,
101
- with: resolvedWith,
102
- includeItemsWithoutProductData: item.includeItemsWithoutProductData ?? resolvedWith?.includeItemsWithoutProductData,
103
- itemGroup: item.itemGroup ?? void 0
104
- }
105
- }));
106
- const result = await sapiClient.basket.addOrUpdateItems(basketKey, itemsToBeAddedOrUpdated, {
107
- skipAvailabilityCheck: false,
108
- includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData,
109
- orderCustomData: params.orderCustomData
110
- }, {
111
- existingItemHandling: params.existingItemHandling || _constants.ExistingItemHandling.AddQuantityToExisting
112
- });
113
- if (result.type === "success") {
114
- return {
115
- basket: result.basket
116
- };
117
- } else if (result.type === "failure" && (0, _utils.wasAddedWithReducedQuantity)(result.errors)) {
118
- return {
119
- basket: result.basket,
120
- errors: result.errors
121
- };
122
- } else {
123
- const {
124
- statusCode,
125
- message
126
- } = parseBasketError(result);
127
- context.log.error("Adding one or more items to basket failed", {
128
- statusCode,
129
- message
130
- });
131
- return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, SAPI_ERROR_NAME, "Adding one or more items to basket failed", {
132
- detail: message,
133
- errors: result.errors
134
- });
135
- }
136
- };
137
- const getBasket = exports.getBasket = async function getBasket2(options, context) {
138
- if (!(0, _types.hasSession)(context)) {
139
- return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
140
- }
141
- const {
142
- sapiClient,
143
- campaignKey,
144
- basketKey
145
- } = context;
146
- const resolvedWith = getWithParams({
147
- with: options
148
- }, context);
149
- const response = await sapiClient.basket.get(basketKey, {
150
- with: resolvedWith,
151
- campaignKey,
152
- includeItemsWithoutProductData: resolvedWith.includeItemsWithoutProductData,
153
- orderCustomData: options?.orderCustomData
154
- });
155
- if (response.type === "failure") {
156
- const {
157
- statusCode,
158
- message
159
- } = parseBasketError(response);
160
- return new _errors.ErrorResponse(statusCode, SAPI_ERROR_NAME, "Adding item to basket failed", {
161
- detail: message
162
- });
163
- }
164
- return {
165
- basket: response.basket
166
- };
167
- };
168
- const removeItemFromBasket = exports.removeItemFromBasket = async function removeItemFromBasket2(options, context) {
169
- if (!(0, _types.hasSession)(context)) {
170
- return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
171
- }
172
- const {
173
- sapiClient,
174
- campaignKey,
175
- basketKey
176
- } = context;
177
- const resolvedWith = getWithParams(options, context);
178
- const basket = await sapiClient.basket.deleteItem(basketKey, options.itemKey, {
179
- with: resolvedWith,
180
- campaignKey,
181
- includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData,
182
- orderCustomData: options.orderCustomData
183
- });
184
- return {
185
- basket
186
- };
187
- };
188
- const clearBasket = exports.clearBasket = async function clearBasket2(context) {
189
- const getBasketResponse = await getBasket({}, context);
190
- if (getBasketResponse instanceof _errors.ErrorResponse) {
191
- return getBasketResponse;
192
- }
193
- const {
194
- basket
195
- } = await (0, _response.unwrap)(getBasketResponse);
196
- await Promise.all(basket.items.map(async item => {
197
- await removeItemFromBasket({
198
- itemKey: item.key
199
- }, context);
200
- }));
201
- context.log.debug("The basket has been cleared");
202
- return true;
203
- };
204
- const mergeBaskets = exports.mergeBaskets = async function mergeBaskets2({
205
- fromBasketKey,
206
- toBasketKey,
207
- with: _with,
208
- orderCustomData
209
- }, context) {
210
- const resolvedWith = getWithParams({
211
- with: _with
212
- }, context);
213
- return await (0, _user.mergeBaskets)(fromBasketKey, toBasketKey, {
214
- ...resolvedWith,
215
- orderCustomData
216
- }, context);
217
- };
218
- const updateBasketItem = exports.updateBasketItem = async function updateBasketItem2({
219
- basketItemKey,
220
- update,
221
- with: _with
222
- }, context) {
223
- if (!(0, _types.hasSession)(context)) {
224
- return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
225
- }
226
- const {
227
- basketKey,
228
- sapiClient
229
- } = context;
230
- const resolvedWith = getWithParams({
231
- with: _with
232
- }, context);
233
- const {
234
- quantity,
235
- ...updateParams
236
- } = update;
237
- const result = await sapiClient.basket.updateItem(basketKey, basketItemKey, quantity, {
238
- ...updateParams,
239
- with: resolvedWith
240
- });
241
- if (result.type === "success") {
242
- return {
243
- basket: result.basket
244
- };
245
- } else {
246
- context.log.error("Updating basket item failed", {
247
- kind: result.kind,
248
- basketKey,
249
- basketItemKey,
250
- update
251
- });
252
- return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, SAPI_ERROR_NAME, "Updating basket item failed", {
253
- failureKind: result.kind
254
- });
255
- }
256
- };
257
- function parseBasketError(response) {
258
- const parsedError = {
259
- message: "",
260
- statusCode: 500
261
- };
262
- if ("statusCode" in response) {
263
- parsedError.statusCode = response.statusCode;
264
- } else {
265
- const [error] = response.errors;
266
- parsedError.message = response.errors?.map(error2 => `${error2.operation !== "delete" ? `${error2.kind}:` : ""}${error2.operation}:${error2.variantId} - ${error2.message}`).join(" | ");
267
- parsedError.statusCode = error.statusCode;
268
- }
269
- return parsedError;
270
- }