@scayle/storefront-core 7.22.1
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 +480 -0
- package/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/bapi/init.cjs +30 -0
- package/dist/bapi/init.d.ts +14 -0
- package/dist/bapi/init.mjs +23 -0
- package/dist/cache/cache.cjs +1 -0
- package/dist/cache/cache.d.ts +8 -0
- package/dist/cache/cache.mjs +0 -0
- package/dist/cache/cached.cjs +89 -0
- package/dist/cache/cached.d.ts +24 -0
- package/dist/cache/cached.mjs +92 -0
- package/dist/cache/index.cjs +38 -0
- package/dist/cache/index.d.ts +3 -0
- package/dist/cache/index.mjs +3 -0
- package/dist/cache/providers/redis.cjs +94 -0
- package/dist/cache/providers/redis.d.ts +28 -0
- package/dist/cache/providers/redis.mjs +86 -0
- package/dist/cache/providers/unstorage.cjs +54 -0
- package/dist/cache/providers/unstorage.d.ts +16 -0
- package/dist/cache/providers/unstorage.mjs +49 -0
- package/dist/cache/types.cjs +11 -0
- package/dist/cache/types.d.ts +6 -0
- package/dist/cache/types.mjs +4 -0
- package/dist/constants/basket.cjs +13 -0
- package/dist/constants/basket.d.ts +8 -0
- package/dist/constants/basket.mjs +6 -0
- package/dist/constants/cache.cjs +8 -0
- package/dist/constants/cache.d.ts +1 -0
- package/dist/constants/cache.mjs +1 -0
- package/dist/constants/hash.cjs +11 -0
- package/dist/constants/hash.d.ts +6 -0
- package/dist/constants/hash.mjs +4 -0
- package/dist/constants/httpStatus.cjs +636 -0
- package/dist/constants/httpStatus.d.ts +632 -0
- package/dist/constants/httpStatus.mjs +629 -0
- package/dist/constants/index.cjs +93 -0
- package/dist/constants/index.d.ts +8 -0
- package/dist/constants/index.mjs +8 -0
- package/dist/constants/product.cjs +11 -0
- package/dist/constants/product.d.ts +6 -0
- package/dist/constants/product.mjs +4 -0
- package/dist/constants/promotion.cjs +10 -0
- package/dist/constants/promotion.d.ts +2 -0
- package/dist/constants/promotion.mjs +2 -0
- package/dist/constants/sorting.cjs +24 -0
- package/dist/constants/sorting.d.ts +20 -0
- package/dist/constants/sorting.mjs +17 -0
- package/dist/constants/withParameters.cjs +138 -0
- package/dist/constants/withParameters.d.ts +30 -0
- package/dist/constants/withParameters.mjs +132 -0
- package/dist/errors/BAPIError.cjs +16 -0
- package/dist/errors/BAPIError.d.ts +6 -0
- package/dist/errors/BAPIError.mjs +9 -0
- package/dist/errors/baseError.cjs +17 -0
- package/dist/errors/baseError.d.ts +5 -0
- package/dist/errors/baseError.mjs +10 -0
- package/dist/errors/index.cjs +27 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.mjs +2 -0
- package/dist/helpers/advancedAttributeHelpers.cjs +26 -0
- package/dist/helpers/advancedAttributeHelpers.d.ts +12 -0
- package/dist/helpers/advancedAttributeHelpers.mjs +21 -0
- package/dist/helpers/arrayHelpers.cjs +10 -0
- package/dist/helpers/arrayHelpers.d.ts +1 -0
- package/dist/helpers/arrayHelpers.mjs +3 -0
- package/dist/helpers/attributeHelpers.cjs +24 -0
- package/dist/helpers/attributeHelpers.d.ts +5 -0
- package/dist/helpers/attributeHelpers.mjs +17 -0
- package/dist/helpers/autobind.cjs +44 -0
- package/dist/helpers/autobind.d.ts +39 -0
- package/dist/helpers/autobind.mjs +35 -0
- package/dist/helpers/basketHelpers.cjs +12 -0
- package/dist/helpers/basketHelpers.d.ts +2 -0
- package/dist/helpers/basketHelpers.mjs +5 -0
- package/dist/helpers/categoryHelper.cjs +61 -0
- package/dist/helpers/categoryHelper.d.ts +7 -0
- package/dist/helpers/categoryHelper.mjs +44 -0
- package/dist/helpers/filterHelper.cjs +156 -0
- package/dist/helpers/filterHelper.d.ts +82 -0
- package/dist/helpers/filterHelper.mjs +147 -0
- package/dist/helpers/formHelpers.cjs +114 -0
- package/dist/helpers/formHelpers.d.ts +48 -0
- package/dist/helpers/formHelpers.mjs +106 -0
- package/dist/helpers/imageHelpers.cjs +20 -0
- package/dist/helpers/imageHelpers.d.ts +4 -0
- package/dist/helpers/imageHelpers.mjs +14 -0
- package/dist/helpers/index.cjs +192 -0
- package/dist/helpers/index.d.ts +17 -0
- package/dist/helpers/index.mjs +17 -0
- package/dist/helpers/localization.cjs +13 -0
- package/dist/helpers/localization.d.ts +7 -0
- package/dist/helpers/localization.mjs +6 -0
- package/dist/helpers/objectHelpers.cjs +19 -0
- package/dist/helpers/objectHelpers.d.ts +1 -0
- package/dist/helpers/objectHelpers.mjs +6 -0
- package/dist/helpers/orderHelpers.cjs +10 -0
- package/dist/helpers/orderHelpers.d.ts +67 -0
- package/dist/helpers/orderHelpers.mjs +4 -0
- package/dist/helpers/product.fixture.cjs +770 -0
- package/dist/helpers/product.fixture.d.ts +415 -0
- package/dist/helpers/product.fixture.mjs +838 -0
- package/dist/helpers/productDisruptorHelper.cjs +37 -0
- package/dist/helpers/productDisruptorHelper.d.ts +10 -0
- package/dist/helpers/productDisruptorHelper.mjs +23 -0
- package/dist/helpers/productHelpers.cjs +188 -0
- package/dist/helpers/productHelpers.d.ts +41 -0
- package/dist/helpers/productHelpers.mjs +170 -0
- package/dist/helpers/sanitizationHelpers.cjs +15 -0
- package/dist/helpers/sanitizationHelpers.d.ts +2 -0
- package/dist/helpers/sanitizationHelpers.mjs +6 -0
- package/dist/helpers/sortingHelper.cjs +67 -0
- package/dist/helpers/sortingHelper.d.ts +69 -0
- package/dist/helpers/sortingHelper.mjs +66 -0
- package/dist/helpers/stringHelpers.cjs +8 -0
- package/dist/helpers/stringHelpers.d.ts +2 -0
- package/dist/helpers/stringHelpers.mjs +2 -0
- package/dist/index.cjs +85 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.mjs +8 -0
- package/dist/rpc/methods/basket/basket.cjs +183 -0
- package/dist/rpc/methods/basket/basket.d.ts +23 -0
- package/dist/rpc/methods/basket/basket.mjs +181 -0
- package/dist/rpc/methods/brands.cjs +34 -0
- package/dist/rpc/methods/brands.d.ts +5 -0
- package/dist/rpc/methods/brands.mjs +16 -0
- package/dist/rpc/methods/categories.cjs +102 -0
- package/dist/rpc/methods/categories.d.ts +21 -0
- package/dist/rpc/methods/categories.mjs +64 -0
- package/dist/rpc/methods/cbd.cjs +45 -0
- package/dist/rpc/methods/cbd.d.ts +4 -0
- package/dist/rpc/methods/cbd.mjs +36 -0
- package/dist/rpc/methods/checkout/index.cjs +38 -0
- package/dist/rpc/methods/checkout/index.d.ts +3 -0
- package/dist/rpc/methods/checkout/index.mjs +3 -0
- package/dist/rpc/methods/checkout/order.cjs +55 -0
- package/dist/rpc/methods/checkout/order.d.ts +4 -0
- package/dist/rpc/methods/checkout/order.mjs +43 -0
- package/dist/rpc/methods/checkout/shopUser.cjs +126 -0
- package/dist/rpc/methods/checkout/shopUser.d.ts +7 -0
- package/dist/rpc/methods/checkout/shopUser.mjs +109 -0
- package/dist/rpc/methods/checkout/shopUserAddresses.cjs +25 -0
- package/dist/rpc/methods/checkout/shopUserAddresses.d.ts +3 -0
- package/dist/rpc/methods/checkout/shopUserAddresses.mjs +19 -0
- package/dist/rpc/methods/index.cjs +159 -0
- package/dist/rpc/methods/index.d.ts +14 -0
- package/dist/rpc/methods/index.mjs +14 -0
- package/dist/rpc/methods/navigationTrees.cjs +33 -0
- package/dist/rpc/methods/navigationTrees.d.ts +5 -0
- package/dist/rpc/methods/navigationTrees.mjs +10 -0
- package/dist/rpc/methods/products.cjs +261 -0
- package/dist/rpc/methods/products.d.ts +13 -0
- package/dist/rpc/methods/products.mjs +217 -0
- package/dist/rpc/methods/promotion.cjs +53 -0
- package/dist/rpc/methods/promotion.d.ts +4 -0
- package/dist/rpc/methods/promotion.mjs +38 -0
- package/dist/rpc/methods/search.cjs +38 -0
- package/dist/rpc/methods/search.d.ts +10 -0
- package/dist/rpc/methods/search.mjs +22 -0
- package/dist/rpc/methods/session.cjs +274 -0
- package/dist/rpc/methods/session.d.ts +20 -0
- package/dist/rpc/methods/session.mjs +309 -0
- package/dist/rpc/methods/shopConfiguration.cjs +15 -0
- package/dist/rpc/methods/shopConfiguration.d.ts +4 -0
- package/dist/rpc/methods/shopConfiguration.mjs +6 -0
- package/dist/rpc/methods/user.cjs +89 -0
- package/dist/rpc/methods/user.d.ts +20 -0
- package/dist/rpc/methods/user.mjs +56 -0
- package/dist/rpc/methods/variants.cjs +29 -0
- package/dist/rpc/methods/variants.d.ts +8 -0
- package/dist/rpc/methods/variants.mjs +12 -0
- package/dist/rpc/methods/wishlist.cjs +85 -0
- package/dist/rpc/methods/wishlist.d.ts +13 -0
- package/dist/rpc/methods/wishlist.mjs +61 -0
- package/dist/server.cjs +39 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.mjs +4 -0
- package/dist/types/api/auth.cjs +1 -0
- package/dist/types/api/auth.d.ts +63 -0
- package/dist/types/api/auth.mjs +0 -0
- package/dist/types/api/context.cjs +1 -0
- package/dist/types/api/context.d.ts +61 -0
- package/dist/types/api/context.mjs +0 -0
- package/dist/types/api/rpc.cjs +1 -0
- package/dist/types/api/rpc.d.ts +4 -0
- package/dist/types/api/rpc.mjs +0 -0
- package/dist/types/bapi/basket.cjs +1 -0
- package/dist/types/bapi/basket.d.ts +25 -0
- package/dist/types/bapi/basket.mjs +0 -0
- package/dist/types/bapi/brand.cjs +1 -0
- package/dist/types/bapi/brand.d.ts +2 -0
- package/dist/types/bapi/brand.mjs +0 -0
- package/dist/types/bapi/category.cjs +1 -0
- package/dist/types/bapi/category.d.ts +6 -0
- package/dist/types/bapi/category.mjs +0 -0
- package/dist/types/bapi/filter.cjs +1 -0
- package/dist/types/bapi/filter.d.ts +49 -0
- package/dist/types/bapi/filter.mjs +0 -0
- package/dist/types/bapi/navigation.cjs +1 -0
- package/dist/types/bapi/navigation.d.ts +10 -0
- package/dist/types/bapi/navigation.mjs +0 -0
- package/dist/types/bapi/order.cjs +1 -0
- package/dist/types/bapi/order.d.ts +554 -0
- package/dist/types/bapi/order.mjs +0 -0
- package/dist/types/bapi/pagination.cjs +1 -0
- package/dist/types/bapi/pagination.d.ts +13 -0
- package/dist/types/bapi/pagination.mjs +0 -0
- package/dist/types/bapi/product.cjs +1 -0
- package/dist/types/bapi/product.d.ts +84 -0
- package/dist/types/bapi/product.mjs +0 -0
- package/dist/types/bapi/productFilter.cjs +1 -0
- package/dist/types/bapi/productFilter.d.ts +7 -0
- package/dist/types/bapi/productFilter.mjs +0 -0
- package/dist/types/bapi/promotion.cjs +1 -0
- package/dist/types/bapi/promotion.d.ts +2 -0
- package/dist/types/bapi/promotion.mjs +0 -0
- package/dist/types/bapi/redirects.cjs +1 -0
- package/dist/types/bapi/redirects.d.ts +1 -0
- package/dist/types/bapi/redirects.mjs +0 -0
- package/dist/types/bapi/router.cjs +1 -0
- package/dist/types/bapi/router.d.ts +1 -0
- package/dist/types/bapi/router.mjs +0 -0
- package/dist/types/bapi/search.cjs +1 -0
- package/dist/types/bapi/search.d.ts +21 -0
- package/dist/types/bapi/search.mjs +0 -0
- package/dist/types/bapi/sorting.cjs +5 -0
- package/dist/types/bapi/sorting.d.ts +10 -0
- package/dist/types/bapi/sorting.mjs +1 -0
- package/dist/types/bapi/wishlist.cjs +1 -0
- package/dist/types/bapi/wishlist.d.ts +9 -0
- package/dist/types/bapi/wishlist.mjs +0 -0
- package/dist/types/breadcrumb.cjs +1 -0
- package/dist/types/breadcrumb.d.ts +4 -0
- package/dist/types/breadcrumb.mjs +0 -0
- package/dist/types/index.cjs +236 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/index.mjs +21 -0
- package/dist/types/promises.cjs +1 -0
- package/dist/types/promises.d.ts +2 -0
- package/dist/types/promises.mjs +0 -0
- package/dist/types/user.cjs +1 -0
- package/dist/types/user.d.ts +100 -0
- package/dist/types/user.mjs +0 -0
- package/dist/utils/compression.cjs +24 -0
- package/dist/utils/compression.d.ts +2 -0
- package/dist/utils/compression.mjs +16 -0
- package/dist/utils/hash.cjs +68 -0
- package/dist/utils/hash.d.ts +8 -0
- package/dist/utils/hash.mjs +61 -0
- package/dist/utils/index.cjs +27 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.mjs +2 -0
- package/dist/utils/keys.cjs +67 -0
- package/dist/utils/keys.d.ts +24 -0
- package/dist/utils/keys.mjs +56 -0
- package/dist/utils/log.cjs +93 -0
- package/dist/utils/log.d.ts +43 -0
- package/dist/utils/log.mjs +75 -0
- package/dist/utils/rpc.cjs +41 -0
- package/dist/utils/rpc.d.ts +6 -0
- package/dist/utils/rpc.mjs +35 -0
- package/dist/utils/timeout.cjs +17 -0
- package/dist/utils/timeout.d.ts +2 -0
- package/dist/utils/timeout.mjs +9 -0
- package/dist/utils/user.cjs +75 -0
- package/dist/utils/user.d.ts +14 -0
- package/dist/utils/user.mjs +65 -0
- package/package.json +97 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { APISortOption, APISortOrder } from "@aboutyou/backbone";
|
|
2
|
+
import { pick } from "radash";
|
|
3
|
+
import { SortName, SortQuery } from "../constants/sorting.mjs";
|
|
4
|
+
const SORTING_VALUES = {
|
|
5
|
+
topSeller: {
|
|
6
|
+
by: APISortOption.Price,
|
|
7
|
+
direction: APISortOrder.Descending,
|
|
8
|
+
name: SortName.TOPSELLER,
|
|
9
|
+
query: SortQuery.TOPSELLER
|
|
10
|
+
},
|
|
11
|
+
dateNewest: {
|
|
12
|
+
by: APISortOption.DateAdded,
|
|
13
|
+
name: SortName.DATE_NEWEST,
|
|
14
|
+
query: SortQuery.DATE_NEWEST
|
|
15
|
+
},
|
|
16
|
+
priceDesc: {
|
|
17
|
+
by: APISortOption.Price,
|
|
18
|
+
direction: APISortOrder.Descending,
|
|
19
|
+
name: SortName.PRICE_DESC,
|
|
20
|
+
query: SortQuery.PRICE_DESC
|
|
21
|
+
},
|
|
22
|
+
priceAsc: {
|
|
23
|
+
by: APISortOption.Price,
|
|
24
|
+
direction: APISortOrder.Ascending,
|
|
25
|
+
name: SortName.PRICE_ASC,
|
|
26
|
+
query: SortQuery.PRICE_ASC
|
|
27
|
+
},
|
|
28
|
+
reductionDesc: {
|
|
29
|
+
by: APISortOption.Reduction,
|
|
30
|
+
direction: APISortOrder.Descending,
|
|
31
|
+
name: SortName.REDUCTION_DESC,
|
|
32
|
+
query: SortQuery.REDUCTION_DESC
|
|
33
|
+
},
|
|
34
|
+
reductionAsc: {
|
|
35
|
+
by: APISortOption.Reduction,
|
|
36
|
+
direction: APISortOrder.Ascending,
|
|
37
|
+
name: SortName.REDUCTION_ASC,
|
|
38
|
+
query: SortQuery.REDUCTION_ASC
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
export const getSortingValues = (options = [
|
|
42
|
+
"topSeller",
|
|
43
|
+
"dateNewest",
|
|
44
|
+
"priceDesc",
|
|
45
|
+
"priceAsc",
|
|
46
|
+
"reductionDesc",
|
|
47
|
+
"reductionAsc"
|
|
48
|
+
]) => pick(SORTING_VALUES, options);
|
|
49
|
+
export const getSortByValue = (query, defaultSort) => {
|
|
50
|
+
switch (query) {
|
|
51
|
+
case SortQuery.PRICE_DESC:
|
|
52
|
+
return SORTING_VALUES.priceDesc;
|
|
53
|
+
case SortQuery.PRICE_ASC:
|
|
54
|
+
return SORTING_VALUES.priceAsc;
|
|
55
|
+
case SortQuery.REDUCTION_DESC:
|
|
56
|
+
return SORTING_VALUES.reductionDesc;
|
|
57
|
+
case SortQuery.REDUCTION_ASC:
|
|
58
|
+
return SORTING_VALUES.reductionAsc;
|
|
59
|
+
case SortQuery.TOPSELLER:
|
|
60
|
+
return SORTING_VALUES.topSeller;
|
|
61
|
+
case SortQuery.DATE_NEWEST:
|
|
62
|
+
return SORTING_VALUES.dateNewest;
|
|
63
|
+
default:
|
|
64
|
+
return SORTING_VALUES[defaultSort || "dateNewest"];
|
|
65
|
+
}
|
|
66
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
rpcMethods: true
|
|
8
|
+
};
|
|
9
|
+
exports.rpcMethods = void 0;
|
|
10
|
+
var rpcMethods = _interopRequireWildcard(require("./rpc/methods/index.cjs"));
|
|
11
|
+
exports.rpcMethods = rpcMethods;
|
|
12
|
+
var _errors = require("./errors/index.cjs");
|
|
13
|
+
Object.keys(_errors).forEach(function (key) {
|
|
14
|
+
if (key === "default" || key === "__esModule") return;
|
|
15
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
16
|
+
if (key in exports && exports[key] === _errors[key]) return;
|
|
17
|
+
Object.defineProperty(exports, key, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () {
|
|
20
|
+
return _errors[key];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
var _utils = require("./utils/index.cjs");
|
|
25
|
+
Object.keys(_utils).forEach(function (key) {
|
|
26
|
+
if (key === "default" || key === "__esModule") return;
|
|
27
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
28
|
+
if (key in exports && exports[key] === _utils[key]) return;
|
|
29
|
+
Object.defineProperty(exports, key, {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () {
|
|
32
|
+
return _utils[key];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
var _constants = require("./constants/index.cjs");
|
|
37
|
+
Object.keys(_constants).forEach(function (key) {
|
|
38
|
+
if (key === "default" || key === "__esModule") return;
|
|
39
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
40
|
+
if (key in exports && exports[key] === _constants[key]) return;
|
|
41
|
+
Object.defineProperty(exports, key, {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function () {
|
|
44
|
+
return _constants[key];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
var _cache = require("./cache/index.cjs");
|
|
49
|
+
Object.keys(_cache).forEach(function (key) {
|
|
50
|
+
if (key === "default" || key === "__esModule") return;
|
|
51
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
52
|
+
if (key in exports && exports[key] === _cache[key]) return;
|
|
53
|
+
Object.defineProperty(exports, key, {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
get: function () {
|
|
56
|
+
return _cache[key];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
var _helpers = require("./helpers/index.cjs");
|
|
61
|
+
Object.keys(_helpers).forEach(function (key) {
|
|
62
|
+
if (key === "default" || key === "__esModule") return;
|
|
63
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
64
|
+
if (key in exports && exports[key] === _helpers[key]) return;
|
|
65
|
+
Object.defineProperty(exports, key, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function () {
|
|
68
|
+
return _helpers[key];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
var _types = require("./types/index.cjs");
|
|
73
|
+
Object.keys(_types).forEach(function (key) {
|
|
74
|
+
if (key === "default" || key === "__esModule") return;
|
|
75
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
76
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
77
|
+
Object.defineProperty(exports, key, {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function () {
|
|
80
|
+
return _types[key];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
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; }
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as rpcMethods from './rpc/methods';
|
|
2
|
+
export { rpcMethods };
|
|
3
|
+
export * from './errors';
|
|
4
|
+
export * from './utils';
|
|
5
|
+
export * from './constants';
|
|
6
|
+
export * from './cache';
|
|
7
|
+
export * from './helpers';
|
|
8
|
+
export * from './types';
|
|
9
|
+
type RpcMethodsCore = typeof rpcMethods;
|
|
10
|
+
export interface RpcMethodsStorefrontInternal {
|
|
11
|
+
}
|
|
12
|
+
export type RpcMethods = {
|
|
13
|
+
[Key in keyof RpcMethodsCore | keyof RpcMethodsStorefrontInternal]: Key extends keyof RpcMethodsStorefrontInternal ? RpcMethodsStorefrontInternal[Key] : Key extends keyof RpcMethodsCore ? RpcMethodsCore[Key] : never;
|
|
14
|
+
};
|
|
15
|
+
type Resolve<T> = T extends T ? T : never;
|
|
16
|
+
export type RpcMethodName = Resolve<keyof RpcMethods>;
|
|
17
|
+
export type RpcMethod<N extends RpcMethodName> = RpcMethods[N];
|
|
18
|
+
export type RpcMethodParameters<N extends RpcMethodName> = Parameters<RpcMethod<N>>[0];
|
|
19
|
+
export type RpcMethodReturnType<N extends RpcMethodName> = ReturnType<RpcMethod<N>>;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as rpcMethods from "./rpc/methods/index.mjs";
|
|
2
|
+
export { rpcMethods };
|
|
3
|
+
export * from "./errors/index.mjs";
|
|
4
|
+
export * from "./utils/index.mjs";
|
|
5
|
+
export * from "./constants/index.mjs";
|
|
6
|
+
export * from "./cache/index.mjs";
|
|
7
|
+
export * from "./helpers/index.mjs";
|
|
8
|
+
export * from "./types/index.mjs";
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.removeItemFromBasket = exports.mergeBaskets = exports.getBasket = exports.clearBasket = exports.addItemsToBasket = exports.addItemToBasket = void 0;
|
|
7
|
+
var _errors = require("../../../errors/index.cjs");
|
|
8
|
+
var _constants = require("../../../constants/index.cjs");
|
|
9
|
+
var _user = require("../../../utils/user.cjs");
|
|
10
|
+
const BAPI_ERROR_NAME = "BAPI ERROR";
|
|
11
|
+
function getWithParams(params, context) {
|
|
12
|
+
return params.with ?? context.withParams?.basket ?? _constants.MIN_WITH_PARAMS_BASKET;
|
|
13
|
+
}
|
|
14
|
+
const addItemToBasket = async function addItemToBasket2({
|
|
15
|
+
variantId,
|
|
16
|
+
promotionId,
|
|
17
|
+
quantity,
|
|
18
|
+
displayData,
|
|
19
|
+
customData,
|
|
20
|
+
existingItemHandling = _constants.ExistingItemHandling.AddQuantityToExisting,
|
|
21
|
+
itemGroup,
|
|
22
|
+
with: _with
|
|
23
|
+
}, context) {
|
|
24
|
+
const {
|
|
25
|
+
campaignKey,
|
|
26
|
+
bapiClient,
|
|
27
|
+
basketKey
|
|
28
|
+
} = context;
|
|
29
|
+
const resolvedWith = getWithParams({
|
|
30
|
+
with: _with
|
|
31
|
+
}, context);
|
|
32
|
+
const result = await bapiClient.basket.addOrUpdateItems(basketKey, [{
|
|
33
|
+
variantId,
|
|
34
|
+
quantity,
|
|
35
|
+
params: {
|
|
36
|
+
promotionId,
|
|
37
|
+
campaignKey,
|
|
38
|
+
displayData,
|
|
39
|
+
pricePromotionKey: resolvedWith?.pricePromotionKey || "",
|
|
40
|
+
customData,
|
|
41
|
+
itemGroup,
|
|
42
|
+
with: resolvedWith,
|
|
43
|
+
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData
|
|
44
|
+
}
|
|
45
|
+
}], {
|
|
46
|
+
skipAvailabilityCheck: false
|
|
47
|
+
}, {
|
|
48
|
+
existingItemHandling
|
|
49
|
+
});
|
|
50
|
+
if (result.type === "success") {
|
|
51
|
+
return result.basket;
|
|
52
|
+
} else {
|
|
53
|
+
const {
|
|
54
|
+
message,
|
|
55
|
+
statusCode
|
|
56
|
+
} = parseBasketError(result);
|
|
57
|
+
context.log.error("Adding item to basket failed", {
|
|
58
|
+
message,
|
|
59
|
+
statusCode
|
|
60
|
+
});
|
|
61
|
+
throw new _errors.BAPIError(BAPI_ERROR_NAME, statusCode, message, "addItemToBasket:bapiClient.basket.addOrUpdateItems");
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
exports.addItemToBasket = addItemToBasket;
|
|
65
|
+
const addItemsToBasket = async function addItemsToBasket2(params, context) {
|
|
66
|
+
const {
|
|
67
|
+
campaignKey,
|
|
68
|
+
bapiClient,
|
|
69
|
+
basketKey
|
|
70
|
+
} = context;
|
|
71
|
+
const resolvedWith = getWithParams(params, context);
|
|
72
|
+
const itemsToBeAddedOrUpdated = params.items.map(item => ({
|
|
73
|
+
variantId: item.variantId,
|
|
74
|
+
quantity: item.quantity,
|
|
75
|
+
params: {
|
|
76
|
+
promotionId: item.promotionId,
|
|
77
|
+
campaignKey,
|
|
78
|
+
displayData: item.displayData,
|
|
79
|
+
pricePromotionKey: resolvedWith?.pricePromotionKey || "",
|
|
80
|
+
customData: item.customData,
|
|
81
|
+
with: resolvedWith,
|
|
82
|
+
includeItemsWithoutProductData: item.includeItemsWithoutProductData ?? resolvedWith?.includeItemsWithoutProductData,
|
|
83
|
+
itemGroup: item.itemGroup ?? void 0
|
|
84
|
+
}
|
|
85
|
+
}));
|
|
86
|
+
const result = await bapiClient.basket.addOrUpdateItems(basketKey, itemsToBeAddedOrUpdated, {
|
|
87
|
+
skipAvailabilityCheck: false,
|
|
88
|
+
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData
|
|
89
|
+
}, {
|
|
90
|
+
existingItemHandling: params.existingItemHandling || _constants.ExistingItemHandling.AddQuantityToExisting,
|
|
91
|
+
considerItemGroupForUniqueness: Boolean(params.considerItemGroupForUniqueness ?? null)
|
|
92
|
+
});
|
|
93
|
+
if (result.type === "success") {
|
|
94
|
+
return result.basket;
|
|
95
|
+
} else {
|
|
96
|
+
const {
|
|
97
|
+
statusCode,
|
|
98
|
+
message
|
|
99
|
+
} = parseBasketError(result);
|
|
100
|
+
context.log.error("Adding one or more items to basket failed", {
|
|
101
|
+
statusCode,
|
|
102
|
+
message
|
|
103
|
+
});
|
|
104
|
+
throw new _errors.BAPIError(BAPI_ERROR_NAME, statusCode, message, "addItemsToBasket:bapiClient.basket.addOrUpdateItems");
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
exports.addItemsToBasket = addItemsToBasket;
|
|
108
|
+
const getBasket = async function getBasket2(options, context) {
|
|
109
|
+
const {
|
|
110
|
+
bapiClient,
|
|
111
|
+
campaignKey,
|
|
112
|
+
basketKey
|
|
113
|
+
} = context;
|
|
114
|
+
const resolvedWith = getWithParams({
|
|
115
|
+
with: options
|
|
116
|
+
}, context);
|
|
117
|
+
const response = await bapiClient.basket.get(basketKey, {
|
|
118
|
+
with: resolvedWith,
|
|
119
|
+
campaignKey,
|
|
120
|
+
includeItemsWithoutProductData: resolvedWith.includeItemsWithoutProductData
|
|
121
|
+
});
|
|
122
|
+
if (response.type === "failure") {
|
|
123
|
+
const {
|
|
124
|
+
statusCode,
|
|
125
|
+
message
|
|
126
|
+
} = parseBasketError(response);
|
|
127
|
+
throw new _errors.BAPIError(BAPI_ERROR_NAME, statusCode, message, "bapiClient.basket.get");
|
|
128
|
+
}
|
|
129
|
+
return response.basket;
|
|
130
|
+
};
|
|
131
|
+
exports.getBasket = getBasket;
|
|
132
|
+
const removeItemFromBasket = async function removeItemFromBasket2(options, context) {
|
|
133
|
+
const {
|
|
134
|
+
bapiClient,
|
|
135
|
+
campaignKey,
|
|
136
|
+
basketKey
|
|
137
|
+
} = context;
|
|
138
|
+
const resolvedWith = getWithParams(options, context);
|
|
139
|
+
return await bapiClient.basket.deleteItem(basketKey, options.itemKey, {
|
|
140
|
+
with: resolvedWith,
|
|
141
|
+
campaignKey,
|
|
142
|
+
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
exports.removeItemFromBasket = removeItemFromBasket;
|
|
146
|
+
const clearBasket = async function clearBasket2(context) {
|
|
147
|
+
const basket = await getBasket({}, context);
|
|
148
|
+
await Promise.all(basket.items.map(async item => {
|
|
149
|
+
await removeItemFromBasket({
|
|
150
|
+
itemKey: item.key
|
|
151
|
+
}, context);
|
|
152
|
+
}));
|
|
153
|
+
context.log.debug("The basket has been cleared");
|
|
154
|
+
return true;
|
|
155
|
+
};
|
|
156
|
+
exports.clearBasket = clearBasket;
|
|
157
|
+
const mergeBaskets = async function mergeBaskets2({
|
|
158
|
+
fromBasketKey,
|
|
159
|
+
toBasketKey,
|
|
160
|
+
with: _with
|
|
161
|
+
}, context) {
|
|
162
|
+
const resolvedWith = getWithParams({
|
|
163
|
+
with: _with
|
|
164
|
+
}, context);
|
|
165
|
+
return await (0, _user.mergeBaskets)(fromBasketKey, toBasketKey, resolvedWith, context);
|
|
166
|
+
};
|
|
167
|
+
exports.mergeBaskets = mergeBaskets;
|
|
168
|
+
function parseBasketError(response) {
|
|
169
|
+
if (response.type === "failure") {
|
|
170
|
+
const parsedError = {
|
|
171
|
+
message: "",
|
|
172
|
+
statusCode: 500
|
|
173
|
+
};
|
|
174
|
+
if ("statusCode" in response) {
|
|
175
|
+
parsedError.statusCode = response.statusCode;
|
|
176
|
+
} else {
|
|
177
|
+
const [error] = response.errors;
|
|
178
|
+
parsedError.message = response.errors?.map(error2 => `${error2.operation !== "delete" ? error2.kind + ":" : ""}${error2.operation}:${error2.variantId} - ${error2.message}`).join(" | ");
|
|
179
|
+
parsedError.statusCode = error.statusCode;
|
|
180
|
+
}
|
|
181
|
+
return parsedError;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AddOrUpdateItemType, BasketResponseData, BasketWithOptions, Product, Variant, RpcHandler } from '../../../types';
|
|
2
|
+
import { ExistingItemHandling } from '../../../constants';
|
|
3
|
+
export declare const addItemToBasket: RpcHandler<AddOrUpdateItemType & {
|
|
4
|
+
existingItemHandling?: ExistingItemHandling;
|
|
5
|
+
with?: BasketWithOptions;
|
|
6
|
+
}, BasketResponseData<Product, Variant>>;
|
|
7
|
+
export declare const addItemsToBasket: RpcHandler<{
|
|
8
|
+
items: AddOrUpdateItemType[];
|
|
9
|
+
existingItemHandling: ExistingItemHandling;
|
|
10
|
+
with?: BasketWithOptions;
|
|
11
|
+
considerItemGroupForUniqueness?: boolean;
|
|
12
|
+
}, BasketResponseData<Product, Variant>>;
|
|
13
|
+
export declare const getBasket: RpcHandler<BasketWithOptions | undefined, BasketResponseData<Product, Variant>>;
|
|
14
|
+
export declare const removeItemFromBasket: RpcHandler<{
|
|
15
|
+
itemKey: string;
|
|
16
|
+
with?: BasketWithOptions;
|
|
17
|
+
}, BasketResponseData<Product, Variant>>;
|
|
18
|
+
export declare const clearBasket: RpcHandler<boolean>;
|
|
19
|
+
export declare const mergeBaskets: RpcHandler<{
|
|
20
|
+
fromBasketKey: string;
|
|
21
|
+
toBasketKey: string;
|
|
22
|
+
with?: BasketWithOptions;
|
|
23
|
+
}, any>;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { BAPIError } from "../../../errors/index.mjs";
|
|
2
|
+
import {
|
|
3
|
+
ExistingItemHandling,
|
|
4
|
+
MIN_WITH_PARAMS_BASKET
|
|
5
|
+
} from "../../../constants/index.mjs";
|
|
6
|
+
import { mergeBaskets as mergeBasketFunction } from "../../../utils/user.mjs";
|
|
7
|
+
const BAPI_ERROR_NAME = "BAPI ERROR";
|
|
8
|
+
function getWithParams(params, context) {
|
|
9
|
+
return params.with ?? context.withParams?.basket ?? MIN_WITH_PARAMS_BASKET;
|
|
10
|
+
}
|
|
11
|
+
export const addItemToBasket = async function addItemToBasket2({
|
|
12
|
+
variantId,
|
|
13
|
+
promotionId,
|
|
14
|
+
quantity,
|
|
15
|
+
displayData,
|
|
16
|
+
customData,
|
|
17
|
+
existingItemHandling = ExistingItemHandling.AddQuantityToExisting,
|
|
18
|
+
itemGroup,
|
|
19
|
+
with: _with
|
|
20
|
+
}, context) {
|
|
21
|
+
const { campaignKey, bapiClient, basketKey } = context;
|
|
22
|
+
const resolvedWith = getWithParams(
|
|
23
|
+
{ with: _with },
|
|
24
|
+
context
|
|
25
|
+
);
|
|
26
|
+
const result = await bapiClient.basket.addOrUpdateItems(
|
|
27
|
+
basketKey,
|
|
28
|
+
[
|
|
29
|
+
{
|
|
30
|
+
variantId,
|
|
31
|
+
quantity,
|
|
32
|
+
params: {
|
|
33
|
+
promotionId,
|
|
34
|
+
campaignKey,
|
|
35
|
+
displayData,
|
|
36
|
+
pricePromotionKey: resolvedWith?.pricePromotionKey || "",
|
|
37
|
+
customData,
|
|
38
|
+
itemGroup,
|
|
39
|
+
with: resolvedWith,
|
|
40
|
+
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
{
|
|
45
|
+
skipAvailabilityCheck: false
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
existingItemHandling
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
if (result.type === "success") {
|
|
52
|
+
return result.basket;
|
|
53
|
+
} else {
|
|
54
|
+
const { message, statusCode } = parseBasketError(result);
|
|
55
|
+
context.log.error("Adding item to basket failed", { message, statusCode });
|
|
56
|
+
throw new BAPIError(
|
|
57
|
+
BAPI_ERROR_NAME,
|
|
58
|
+
statusCode,
|
|
59
|
+
message,
|
|
60
|
+
"addItemToBasket:bapiClient.basket.addOrUpdateItems"
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
export const addItemsToBasket = async function addItemsToBasket2(params, context) {
|
|
65
|
+
const { campaignKey, bapiClient, basketKey } = context;
|
|
66
|
+
const resolvedWith = getWithParams(params, context);
|
|
67
|
+
const itemsToBeAddedOrUpdated = params.items.map((item) => ({
|
|
68
|
+
variantId: item.variantId,
|
|
69
|
+
quantity: item.quantity,
|
|
70
|
+
params: {
|
|
71
|
+
promotionId: item.promotionId,
|
|
72
|
+
campaignKey,
|
|
73
|
+
displayData: item.displayData,
|
|
74
|
+
pricePromotionKey: resolvedWith?.pricePromotionKey || "",
|
|
75
|
+
customData: item.customData,
|
|
76
|
+
with: resolvedWith,
|
|
77
|
+
includeItemsWithoutProductData: item.includeItemsWithoutProductData ?? resolvedWith?.includeItemsWithoutProductData,
|
|
78
|
+
itemGroup: item.itemGroup ?? void 0
|
|
79
|
+
}
|
|
80
|
+
}));
|
|
81
|
+
const result = await bapiClient.basket.addOrUpdateItems(
|
|
82
|
+
basketKey,
|
|
83
|
+
itemsToBeAddedOrUpdated,
|
|
84
|
+
{
|
|
85
|
+
skipAvailabilityCheck: false,
|
|
86
|
+
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
existingItemHandling: params.existingItemHandling || ExistingItemHandling.AddQuantityToExisting,
|
|
90
|
+
considerItemGroupForUniqueness: Boolean(
|
|
91
|
+
params.considerItemGroupForUniqueness ?? null
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
if (result.type === "success") {
|
|
96
|
+
return result.basket;
|
|
97
|
+
} else {
|
|
98
|
+
const { statusCode, message } = parseBasketError(result);
|
|
99
|
+
context.log.error("Adding one or more items to basket failed", {
|
|
100
|
+
statusCode,
|
|
101
|
+
message
|
|
102
|
+
});
|
|
103
|
+
throw new BAPIError(
|
|
104
|
+
BAPI_ERROR_NAME,
|
|
105
|
+
statusCode,
|
|
106
|
+
message,
|
|
107
|
+
"addItemsToBasket:bapiClient.basket.addOrUpdateItems"
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
export const getBasket = async function getBasket2(options, context) {
|
|
112
|
+
const { bapiClient, campaignKey, basketKey } = context;
|
|
113
|
+
const resolvedWith = getWithParams(
|
|
114
|
+
{ with: options },
|
|
115
|
+
context
|
|
116
|
+
);
|
|
117
|
+
const response = await bapiClient.basket.get(basketKey, {
|
|
118
|
+
with: resolvedWith,
|
|
119
|
+
campaignKey,
|
|
120
|
+
includeItemsWithoutProductData: resolvedWith.includeItemsWithoutProductData
|
|
121
|
+
});
|
|
122
|
+
if (response.type === "failure") {
|
|
123
|
+
const { statusCode, message } = parseBasketError(response);
|
|
124
|
+
throw new BAPIError(
|
|
125
|
+
BAPI_ERROR_NAME,
|
|
126
|
+
statusCode,
|
|
127
|
+
message,
|
|
128
|
+
"bapiClient.basket.get"
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
return response.basket;
|
|
132
|
+
};
|
|
133
|
+
export const removeItemFromBasket = async function removeItemFromBasket2(options, context) {
|
|
134
|
+
const { bapiClient, campaignKey, basketKey } = context;
|
|
135
|
+
const resolvedWith = getWithParams(options, context);
|
|
136
|
+
return await bapiClient.basket.deleteItem(basketKey, options.itemKey, {
|
|
137
|
+
with: resolvedWith,
|
|
138
|
+
campaignKey,
|
|
139
|
+
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
export const clearBasket = async function clearBasket2(context) {
|
|
143
|
+
const basket = await getBasket({}, context);
|
|
144
|
+
await Promise.all(
|
|
145
|
+
basket.items.map(async (item) => {
|
|
146
|
+
await removeItemFromBasket({ itemKey: item.key }, context);
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
context.log.debug("The basket has been cleared");
|
|
150
|
+
return true;
|
|
151
|
+
};
|
|
152
|
+
export const mergeBaskets = async function mergeBaskets2({ fromBasketKey, toBasketKey, with: _with }, context) {
|
|
153
|
+
const resolvedWith = getWithParams(
|
|
154
|
+
{ with: _with },
|
|
155
|
+
context
|
|
156
|
+
);
|
|
157
|
+
return await mergeBasketFunction(
|
|
158
|
+
fromBasketKey,
|
|
159
|
+
toBasketKey,
|
|
160
|
+
resolvedWith,
|
|
161
|
+
context
|
|
162
|
+
);
|
|
163
|
+
};
|
|
164
|
+
function parseBasketError(response) {
|
|
165
|
+
if (response.type === "failure") {
|
|
166
|
+
const parsedError = {
|
|
167
|
+
message: "",
|
|
168
|
+
statusCode: 500
|
|
169
|
+
};
|
|
170
|
+
if ("statusCode" in response) {
|
|
171
|
+
parsedError.statusCode = response.statusCode;
|
|
172
|
+
} else {
|
|
173
|
+
const [error] = response.errors;
|
|
174
|
+
parsedError.message = response.errors?.map(
|
|
175
|
+
(error2) => `${error2.operation !== "delete" ? error2.kind + ":" : ""}${error2.operation}:${error2.variantId} - ${error2.message}`
|
|
176
|
+
).join(" | ");
|
|
177
|
+
parsedError.statusCode = error.statusCode;
|
|
178
|
+
}
|
|
179
|
+
return parsedError;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getBrands = exports.getBrandById = void 0;
|
|
7
|
+
const MAX_PER_PAGE = 100;
|
|
8
|
+
const getBrands = async function getBrands2({
|
|
9
|
+
pagination
|
|
10
|
+
}, {
|
|
11
|
+
bapiClient,
|
|
12
|
+
cached
|
|
13
|
+
}) {
|
|
14
|
+
return await cached(bapiClient.brands.get, {
|
|
15
|
+
cacheKeyPrefix: "getBrands"
|
|
16
|
+
})({
|
|
17
|
+
pagination: {
|
|
18
|
+
page: pagination?.page,
|
|
19
|
+
perPage: pagination?.perPage ? Math.min(pagination.perPage, MAX_PER_PAGE) : void 0
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
exports.getBrands = getBrands;
|
|
24
|
+
const getBrandById = async function getBrandById2({
|
|
25
|
+
brandId
|
|
26
|
+
}, {
|
|
27
|
+
bapiClient,
|
|
28
|
+
cached
|
|
29
|
+
}) {
|
|
30
|
+
return await cached(bapiClient.brands.getById, {
|
|
31
|
+
cacheKeyPrefix: `getBrandById-${brandId}`
|
|
32
|
+
})(brandId);
|
|
33
|
+
};
|
|
34
|
+
exports.getBrandById = getBrandById;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Brand, BrandsEndpointRequestParameters, BrandsEndpointResponseData, RpcHandler } from '../../types';
|
|
2
|
+
export declare const getBrands: RpcHandler<BrandsEndpointRequestParameters, BrandsEndpointResponseData>;
|
|
3
|
+
export declare const getBrandById: RpcHandler<{
|
|
4
|
+
brandId: number;
|
|
5
|
+
}, Brand>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const MAX_PER_PAGE = 100;
|
|
2
|
+
export const getBrands = async function getBrands2({ pagination }, { bapiClient, cached }) {
|
|
3
|
+
return await cached(bapiClient.brands.get, {
|
|
4
|
+
cacheKeyPrefix: "getBrands"
|
|
5
|
+
})({
|
|
6
|
+
pagination: {
|
|
7
|
+
page: pagination?.page,
|
|
8
|
+
perPage: pagination?.perPage ? Math.min(pagination.perPage, MAX_PER_PAGE) : void 0
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export const getBrandById = async function getBrandById2({ brandId }, { bapiClient, cached }) {
|
|
13
|
+
return await cached(bapiClient.brands.getById, {
|
|
14
|
+
cacheKeyPrefix: `getBrandById-${brandId}`
|
|
15
|
+
})(brandId);
|
|
16
|
+
};
|