@scayle/storefront-core 8.4.0 → 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.
- package/CHANGELOG.md +16 -0
- package/dist/rpc/methods/checkout/checkout.mjs +1 -1
- package/dist/rpc/methods/search.d.ts +22 -0
- package/package.json +9 -19
- package/dist/api/customer.cjs +0 -164
- package/dist/api/oauth.cjs +0 -238
- package/dist/cache/cache.cjs +0 -1
- package/dist/cache/cached.cjs +0 -90
- package/dist/cache/index.cjs +0 -27
- package/dist/cache/providers/unstorage.cjs +0 -55
- package/dist/constants/basket.cjs +0 -26
- package/dist/constants/cache.cjs +0 -7
- package/dist/constants/hash.cjs +0 -11
- package/dist/constants/httpStatus.cjs +0 -634
- package/dist/constants/index.cjs +0 -93
- package/dist/constants/product.cjs +0 -10
- package/dist/constants/promotion.cjs +0 -12
- package/dist/constants/sorting.cjs +0 -22
- package/dist/constants/withParameters.cjs +0 -132
- package/dist/errors/errorResponse.cjs +0 -27
- package/dist/errors/index.cjs +0 -16
- package/dist/helpers/advancedAttributeHelpers.cjs +0 -30
- package/dist/helpers/arrayHelpers.cjs +0 -10
- package/dist/helpers/attributeHelpers.cjs +0 -24
- package/dist/helpers/basketHelpers.cjs +0 -12
- package/dist/helpers/categoryHelper.cjs +0 -61
- package/dist/helpers/filterHelper.cjs +0 -185
- package/dist/helpers/formHelpers.cjs +0 -114
- package/dist/helpers/imageHelpers.cjs +0 -20
- package/dist/helpers/index.cjs +0 -181
- package/dist/helpers/localization.cjs +0 -13
- package/dist/helpers/objectHelpers.cjs +0 -19
- package/dist/helpers/orderHelpers.cjs +0 -10
- package/dist/helpers/product.fixture.cjs +0 -766
- package/dist/helpers/productDisruptorHelper.cjs +0 -37
- package/dist/helpers/productHelpers.cjs +0 -156
- package/dist/helpers/sanitizationHelpers.cjs +0 -35
- package/dist/helpers/sortingHelper.cjs +0 -68
- package/dist/helpers/stringHelpers.cjs +0 -8
- package/dist/index.cjs +0 -100
- package/dist/rpc/methods/basket/basket.cjs +0 -270
- package/dist/rpc/methods/brands.cjs +0 -33
- package/dist/rpc/methods/categories.cjs +0 -129
- package/dist/rpc/methods/cbd.cjs +0 -38
- package/dist/rpc/methods/checkout/checkout.cjs +0 -48
- package/dist/rpc/methods/checkout/index.cjs +0 -49
- package/dist/rpc/methods/checkout/order.cjs +0 -42
- package/dist/rpc/methods/checkout/shopUser.cjs +0 -110
- package/dist/rpc/methods/checkout/shopUserAddresses.cjs +0 -12
- package/dist/rpc/methods/index.cjs +0 -225
- package/dist/rpc/methods/navigationTrees.cjs +0 -54
- package/dist/rpc/methods/oauth/idp.cjs +0 -59
- package/dist/rpc/methods/products.cjs +0 -309
- package/dist/rpc/methods/promotion.cjs +0 -51
- package/dist/rpc/methods/search.cjs +0 -40
- package/dist/rpc/methods/session.cjs +0 -257
- package/dist/rpc/methods/shopConfiguration.cjs +0 -15
- package/dist/rpc/methods/user.cjs +0 -103
- package/dist/rpc/methods/variants.cjs +0 -29
- package/dist/rpc/methods/wishlist.cjs +0 -104
- package/dist/server.cjs +0 -47
- package/dist/test/factories/index.cjs +0 -16
- package/dist/types/api/auth.cjs +0 -1
- package/dist/types/api/context.cjs +0 -15
- package/dist/types/api/rpc.cjs +0 -1
- package/dist/types/breadcrumb.cjs +0 -1
- package/dist/types/index.cjs +0 -267
- package/dist/types/promises.cjs +0 -1
- package/dist/types/sapi/basket.cjs +0 -1
- package/dist/types/sapi/brand.cjs +0 -1
- package/dist/types/sapi/campaign.cjs +0 -1
- package/dist/types/sapi/category.cjs +0 -1
- package/dist/types/sapi/filter.cjs +0 -1
- package/dist/types/sapi/navigation.cjs +0 -1
- package/dist/types/sapi/order.cjs +0 -1
- package/dist/types/sapi/product.cjs +0 -1
- package/dist/types/sapi/productFilter.cjs +0 -1
- package/dist/types/sapi/promotion.cjs +0 -1
- package/dist/types/sapi/redirects.cjs +0 -1
- package/dist/types/sapi/router.cjs +0 -1
- package/dist/types/sapi/search.cjs +0 -1
- package/dist/types/sapi/sorting.cjs +0 -1
- package/dist/types/sapi/variant.cjs +0 -1
- package/dist/types/sapi/wishlist.cjs +0 -1
- package/dist/types/user.cjs +0 -1
- package/dist/utils/basket.cjs +0 -14
- package/dist/utils/fetch.cjs +0 -19
- package/dist/utils/hash.cjs +0 -72
- package/dist/utils/index.cjs +0 -49
- package/dist/utils/keys.cjs +0 -67
- package/dist/utils/log.cjs +0 -93
- package/dist/utils/response.cjs +0 -13
- package/dist/utils/sapi.cjs +0 -26
- package/dist/utils/timeout.cjs +0 -18
- package/dist/utils/user.cjs +0 -90
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getBrands = exports.getBrandById = void 0;
|
|
7
|
-
var _sapi = require("../../utils/sapi.cjs");
|
|
8
|
-
const MAX_PER_PAGE = 100;
|
|
9
|
-
const getBrands = exports.getBrands = async function getBrands2({
|
|
10
|
-
pagination
|
|
11
|
-
}, {
|
|
12
|
-
sapiClient,
|
|
13
|
-
cached
|
|
14
|
-
}) {
|
|
15
|
-
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.brands.get), {
|
|
16
|
-
cacheKeyPrefix: "getBrands"
|
|
17
|
-
})({
|
|
18
|
-
pagination: {
|
|
19
|
-
page: pagination?.page,
|
|
20
|
-
perPage: pagination?.perPage ? Math.min(pagination.perPage, MAX_PER_PAGE) : void 0
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
const getBrandById = exports.getBrandById = async function getBrandById2({
|
|
25
|
-
brandId
|
|
26
|
-
}, {
|
|
27
|
-
sapiClient,
|
|
28
|
-
cached
|
|
29
|
-
}) {
|
|
30
|
-
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.brands.getById), {
|
|
31
|
-
cacheKeyPrefix: `getBrandById-${brandId}`
|
|
32
|
-
})(brandId);
|
|
33
|
-
};
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getRootCategories = exports.getCategoryByPath = exports.getCategoryById = exports.getCategoriesByPath = void 0;
|
|
7
|
-
var _helpers = require("../../helpers/index.cjs");
|
|
8
|
-
var _sapi = require("../../utils/sapi.cjs");
|
|
9
|
-
const getRootCategories = exports.getRootCategories = async function getRootCategories2({
|
|
10
|
-
children = 1,
|
|
11
|
-
includeHidden,
|
|
12
|
-
properties
|
|
13
|
-
}, {
|
|
14
|
-
cached,
|
|
15
|
-
sapiClient
|
|
16
|
-
}) {
|
|
17
|
-
const result = await cached(sapiClient.categories.getRoots, {
|
|
18
|
-
cacheKeyPrefix: "root-categories"
|
|
19
|
-
})({
|
|
20
|
-
with: {
|
|
21
|
-
children,
|
|
22
|
-
properties
|
|
23
|
-
},
|
|
24
|
-
includeHidden
|
|
25
|
-
});
|
|
26
|
-
return {
|
|
27
|
-
categories: result,
|
|
28
|
-
activeNode: void 0
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
const getCategoryByPath = exports.getCategoryByPath = async function getCategoryByPath2({
|
|
32
|
-
path,
|
|
33
|
-
children = 1,
|
|
34
|
-
includeHidden,
|
|
35
|
-
properties
|
|
36
|
-
}, context) {
|
|
37
|
-
const {
|
|
38
|
-
cached,
|
|
39
|
-
sapiClient
|
|
40
|
-
} = context;
|
|
41
|
-
const sanitizedPath = (0, _helpers.splitAndRemoveEmpty)(path);
|
|
42
|
-
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.categories.getByPath), {
|
|
43
|
-
cacheKeyPrefix: `getByPath-category-${sanitizedPath}`
|
|
44
|
-
})(sanitizedPath, {
|
|
45
|
-
with: {
|
|
46
|
-
children,
|
|
47
|
-
properties
|
|
48
|
-
},
|
|
49
|
-
includeHidden
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
const getCategoriesByPath = exports.getCategoriesByPath = async function getCategoriesByPath2({
|
|
53
|
-
path,
|
|
54
|
-
children = 1,
|
|
55
|
-
includeHidden,
|
|
56
|
-
properties
|
|
57
|
-
}, context) {
|
|
58
|
-
const {
|
|
59
|
-
cached,
|
|
60
|
-
sapiClient
|
|
61
|
-
} = context;
|
|
62
|
-
if (path === "/") {
|
|
63
|
-
return getRootCategories({
|
|
64
|
-
children,
|
|
65
|
-
includeHidden,
|
|
66
|
-
properties
|
|
67
|
-
}, context);
|
|
68
|
-
}
|
|
69
|
-
const sanitizedPath = (0, _helpers.splitAndRemoveEmpty)(path);
|
|
70
|
-
const result = await cached(sapiClient.categories.getByPath, {
|
|
71
|
-
cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
|
|
72
|
-
})(sanitizedPath, {
|
|
73
|
-
with: {
|
|
74
|
-
children,
|
|
75
|
-
properties
|
|
76
|
-
},
|
|
77
|
-
includeHidden
|
|
78
|
-
});
|
|
79
|
-
const rootPath = await Promise.all((result.rootlineIds || []).map(id => {
|
|
80
|
-
return cached(sapiClient.categories.getById, {
|
|
81
|
-
cacheKeyPrefix: `getById-categories-${id}`
|
|
82
|
-
})(id, {
|
|
83
|
-
with: {
|
|
84
|
-
children,
|
|
85
|
-
parents: "all",
|
|
86
|
-
properties
|
|
87
|
-
},
|
|
88
|
-
includeHidden
|
|
89
|
-
});
|
|
90
|
-
}));
|
|
91
|
-
let tree = rootPath[rootPath.length - 1];
|
|
92
|
-
let lastNode = null;
|
|
93
|
-
for (let i = 0; i < rootPath.length; i++) {
|
|
94
|
-
if (lastNode === null) {
|
|
95
|
-
tree = rootPath[i];
|
|
96
|
-
} else if (lastNode.children) {
|
|
97
|
-
const activeElement = lastNode.children?.find(c => c?.id === rootPath[i]?.id);
|
|
98
|
-
if (activeElement) {
|
|
99
|
-
activeElement.children = rootPath[i].children;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
lastNode = rootPath[i];
|
|
103
|
-
}
|
|
104
|
-
return {
|
|
105
|
-
categories: tree,
|
|
106
|
-
activeNode: result
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
const getCategoryById = exports.getCategoryById = async function getCategoryById2({
|
|
110
|
-
id,
|
|
111
|
-
children = 1,
|
|
112
|
-
includeHidden,
|
|
113
|
-
properties
|
|
114
|
-
}, context) {
|
|
115
|
-
const {
|
|
116
|
-
cached,
|
|
117
|
-
sapiClient
|
|
118
|
-
} = context;
|
|
119
|
-
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.categories.getById), {
|
|
120
|
-
cacheKeyPrefix: `getById-categories-${id}`
|
|
121
|
-
})(id, {
|
|
122
|
-
with: {
|
|
123
|
-
children,
|
|
124
|
-
parents: "all",
|
|
125
|
-
properties
|
|
126
|
-
},
|
|
127
|
-
includeHidden
|
|
128
|
-
});
|
|
129
|
-
};
|
package/dist/rpc/methods/cbd.cjs
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getOrderDataByCbd = void 0;
|
|
7
|
-
var _constants = require("../../constants/index.cjs");
|
|
8
|
-
var _errors = require("../../errors/index.cjs");
|
|
9
|
-
var _hash = require("../../utils/hash.cjs");
|
|
10
|
-
const getOrderDataByCbd = exports.getOrderDataByCbd = async function getOrderDataByCbd2({
|
|
11
|
-
cbdToken
|
|
12
|
-
}, context) {
|
|
13
|
-
const payload = await (0, _hash.verifyOrderSuccessToken)(cbdToken, context.checkout.secret);
|
|
14
|
-
if (!payload) {
|
|
15
|
-
context.log.warn("Unable to verify CBD token. Please check that you configured the correct Checkout Secret");
|
|
16
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "Unable to verify CBD token.");
|
|
17
|
-
}
|
|
18
|
-
if (context.checkout.cbdExpiration && Math.floor(Date.now() / 1e3) - payload.issued_at > context.checkout.cbdExpiration) {
|
|
19
|
-
context.log.warn("Attempting to use expired CBD token");
|
|
20
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "The CBD token has expired.");
|
|
21
|
-
}
|
|
22
|
-
const checkoutUrl = context.checkout.url;
|
|
23
|
-
const basicAuth = (0, _hash.encodeBase64)(`${context.checkout.user}:${context.checkout.token}`);
|
|
24
|
-
const response = await fetch(`${checkoutUrl}/api/v1/orders/${payload.order_id}`, {
|
|
25
|
-
headers: {
|
|
26
|
-
Accept: "application/json",
|
|
27
|
-
Authorization: `Basic ${basicAuth}`,
|
|
28
|
-
"X-Shop-Id": context.shopId.toString()
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
if (response.ok) {
|
|
32
|
-
return await response.json();
|
|
33
|
-
}
|
|
34
|
-
context.log.error(`Unexpected status code when fetching order from Checkout API: ${response.status}`);
|
|
35
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.INTERNAL_SERVER_ERROR, _constants.HttpStatusMessage.INTERNAL_SERVER_ERROR, "Unknown error", {
|
|
36
|
-
detail: `Fetching order failed with status code ${response.status}`
|
|
37
|
-
});
|
|
38
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getCheckoutToken = void 0;
|
|
7
|
-
var _jose = require("jose");
|
|
8
|
-
var _types = require("../../../types/index.cjs");
|
|
9
|
-
var _errors = require("../../../errors/index.cjs");
|
|
10
|
-
var _constants = require("../../../constants/index.cjs");
|
|
11
|
-
var _user = require("../user.cjs");
|
|
12
|
-
const getCheckoutToken = exports.getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}, context) {
|
|
13
|
-
if (!(0, _types.hasSession)(context)) {
|
|
14
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
15
|
-
}
|
|
16
|
-
if (!context.accessToken) {
|
|
17
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusMessage.UNAUTHORIZED, "No access token present");
|
|
18
|
-
}
|
|
19
|
-
const refreshedAccessToken = await (0, _user.getAccessToken)({
|
|
20
|
-
forceTokenRefresh: true
|
|
21
|
-
}, context);
|
|
22
|
-
if (refreshedAccessToken instanceof Response) {
|
|
23
|
-
return refreshedAccessToken;
|
|
24
|
-
}
|
|
25
|
-
const secret = new TextEncoder().encode(context.checkout.secret);
|
|
26
|
-
const now = /* @__PURE__ */new Date();
|
|
27
|
-
const {
|
|
28
|
-
voucher,
|
|
29
|
-
customData,
|
|
30
|
-
preferredCollectionPoint,
|
|
31
|
-
carrier
|
|
32
|
-
} = jwtPayload;
|
|
33
|
-
const checkoutJwt = await new _jose.SignJWT({
|
|
34
|
-
voucher,
|
|
35
|
-
customData,
|
|
36
|
-
preferredCollectionPoint,
|
|
37
|
-
carrier,
|
|
38
|
-
basketId: context.basketKey,
|
|
39
|
-
campaignKey: context.campaignKey
|
|
40
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.4.0"}`).setProtectedHeader({
|
|
41
|
-
alg: "HS256",
|
|
42
|
-
typ: "JWT"
|
|
43
|
-
}).sign(secret);
|
|
44
|
-
return {
|
|
45
|
-
accessToken: refreshedAccessToken,
|
|
46
|
-
checkoutJwt
|
|
47
|
-
};
|
|
48
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _order = require("./order.cjs");
|
|
7
|
-
Object.keys(_order).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _order[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _order[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _shopUserAddresses = require("./shopUserAddresses.cjs");
|
|
18
|
-
Object.keys(_shopUserAddresses).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _shopUserAddresses[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _shopUserAddresses[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _shopUser = require("./shopUser.cjs");
|
|
29
|
-
Object.keys(_shopUser).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _shopUser[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _shopUser[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
var _checkout = require("./checkout.cjs");
|
|
40
|
-
Object.keys(_checkout).forEach(function (key) {
|
|
41
|
-
if (key === "default" || key === "__esModule") return;
|
|
42
|
-
if (key in exports && exports[key] === _checkout[key]) return;
|
|
43
|
-
Object.defineProperty(exports, key, {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function () {
|
|
46
|
-
return _checkout[key];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getOrderById = void 0;
|
|
7
|
-
var _errors = require("../../../errors/index.cjs");
|
|
8
|
-
var _fetch = require("../../../utils/fetch.cjs");
|
|
9
|
-
var _customer = require("../../../api/customer.cjs");
|
|
10
|
-
var _httpStatus = require("../../../constants/httpStatus.cjs");
|
|
11
|
-
const getOrderById = exports.getOrderById = async function getOrderById2({
|
|
12
|
-
orderId
|
|
13
|
-
}, context) {
|
|
14
|
-
const accessToken = context.accessToken;
|
|
15
|
-
if (!orderId || isNaN(orderId)) {
|
|
16
|
-
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.NOT_FOUND, _httpStatus.HttpStatusMessage.NOT_FOUND, "No order ID provided");
|
|
17
|
-
}
|
|
18
|
-
if (!accessToken) {
|
|
19
|
-
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.UNAUTHORIZED, _httpStatus.HttpStatusMessage.UNAUTHORIZED, "No access token present");
|
|
20
|
-
}
|
|
21
|
-
const isOrderInUserOrderlist = context.user?.orderSummary?.find(order => order.id === orderId);
|
|
22
|
-
if (!isOrderInUserOrderlist) {
|
|
23
|
-
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.UNAUTHORIZED, _httpStatus.HttpStatusMessage.UNAUTHORIZED, "Order not belonging to current user");
|
|
24
|
-
}
|
|
25
|
-
const client = new _customer.CustomerAPIClient(context);
|
|
26
|
-
try {
|
|
27
|
-
return await client.getOrder(context.shopId, orderId);
|
|
28
|
-
} catch (error) {
|
|
29
|
-
if (error instanceof _fetch.FetchError) {
|
|
30
|
-
if (error.response.status === _httpStatus.HttpStatusCode.NOT_FOUND) {
|
|
31
|
-
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.NOT_FOUND, _httpStatus.HttpStatusMessage.NOT_FOUND, "Order not found");
|
|
32
|
-
}
|
|
33
|
-
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.INTERNAL_SERVER_ERROR, _httpStatus.HttpStatusMessage.INTERNAL_SERVER_ERROR, "Unknown error", {
|
|
34
|
-
detail: `Fetching order "${orderId}" failed with status code ${error.response.status}`
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
context.log.error("Error while fetching order details", {
|
|
38
|
-
error
|
|
39
|
-
});
|
|
40
|
-
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.INTERNAL_SERVER_ERROR, _httpStatus.HttpStatusMessage.INTERNAL_SERVER_ERROR, "Unknown error");
|
|
41
|
-
}
|
|
42
|
-
};
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.updateShopUser = exports.updatePassword = void 0;
|
|
7
|
-
var _errors = require("../../../errors/index.cjs");
|
|
8
|
-
var _customer = require("../../../api/customer.cjs");
|
|
9
|
-
var _oauth = require("../../../api/oauth.cjs");
|
|
10
|
-
var _fetch = require("../../../utils/fetch.cjs");
|
|
11
|
-
var _httpStatus = require("../../../constants/httpStatus.cjs");
|
|
12
|
-
const updateShopUser = exports.updateShopUser = async function updateShopUser2(payload, context) {
|
|
13
|
-
const shopId = context.shopId;
|
|
14
|
-
const updatedUser = {
|
|
15
|
-
email: payload.email,
|
|
16
|
-
phone: payload.phone,
|
|
17
|
-
firstName: payload.firstName,
|
|
18
|
-
lastName: payload.lastName,
|
|
19
|
-
birthDate: payload.birthDate,
|
|
20
|
-
gender: payload.gender,
|
|
21
|
-
title: payload.title
|
|
22
|
-
};
|
|
23
|
-
if (!context.user) {
|
|
24
|
-
const message = "Unauthorized request: Missing access token";
|
|
25
|
-
context.log.error(message);
|
|
26
|
-
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.UNAUTHORIZED, _httpStatus.HttpStatusMessage.UNAUTHORIZED, "No access token present");
|
|
27
|
-
}
|
|
28
|
-
const user = {
|
|
29
|
-
...context.user,
|
|
30
|
-
...updatedUser
|
|
31
|
-
};
|
|
32
|
-
const client = new _customer.CustomerAPIClient(context);
|
|
33
|
-
try {
|
|
34
|
-
await Promise.all([client.updateContactInfo(shopId, {
|
|
35
|
-
email: user.email,
|
|
36
|
-
phone: user.phone
|
|
37
|
-
}), client.updatePersonalInfo(shopId, {
|
|
38
|
-
firstName: user?.firstName,
|
|
39
|
-
lastName: user?.lastName,
|
|
40
|
-
birthDate: user?.birthDate,
|
|
41
|
-
...(user?.gender && {
|
|
42
|
-
gender: user?.gender
|
|
43
|
-
}),
|
|
44
|
-
...(user?.title && {
|
|
45
|
-
title: user?.title
|
|
46
|
-
})
|
|
47
|
-
})]);
|
|
48
|
-
context.updateUser(user);
|
|
49
|
-
return {
|
|
50
|
-
user
|
|
51
|
-
};
|
|
52
|
-
} catch (error) {
|
|
53
|
-
context.log.error("Error while updating user information", error);
|
|
54
|
-
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.INTERNAL_SERVER_ERROR, _httpStatus.HttpStatusMessage.INTERNAL_SERVER_ERROR, "Error while updating user information");
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const updatePassword = exports.updatePassword = async function updatePassword2({
|
|
58
|
-
oldPassword,
|
|
59
|
-
newPassword
|
|
60
|
-
}, context) {
|
|
61
|
-
const shopUser = context.user;
|
|
62
|
-
const oauthEnabled = context.oauth?.apiHost && context.oauth?.clientId && context.oauth?.clientSecret;
|
|
63
|
-
try {
|
|
64
|
-
if (oauthEnabled) {
|
|
65
|
-
const client2 = (0, _oauth.getOAuthClient)(context);
|
|
66
|
-
if (!context.accessToken) {
|
|
67
|
-
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.UNAUTHORIZED, _httpStatus.HttpStatusMessage.UNAUTHORIZED, "No access token present");
|
|
68
|
-
}
|
|
69
|
-
await client2.updatePassword({
|
|
70
|
-
password: oldPassword,
|
|
71
|
-
new_password: newPassword
|
|
72
|
-
}, context.accessToken);
|
|
73
|
-
return {
|
|
74
|
-
user: shopUser
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
const client = new _customer.CustomerAPIClient(context);
|
|
78
|
-
const user = await client.updatePassword(context.shopId, {
|
|
79
|
-
password: oldPassword,
|
|
80
|
-
newPassword
|
|
81
|
-
});
|
|
82
|
-
if (shopUser?.id) {
|
|
83
|
-
await context.destroySessionsForUserId(shopUser.id, [context.sessionId]);
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
user
|
|
87
|
-
};
|
|
88
|
-
} catch (error) {
|
|
89
|
-
if (!(error instanceof _fetch.FetchError)) {
|
|
90
|
-
context.log.error("Error while updating user's password", error);
|
|
91
|
-
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.INTERNAL_SERVER_ERROR, _httpStatus.HttpStatusMessage.INTERNAL_SERVER_ERROR, "Error while updating user's password");
|
|
92
|
-
}
|
|
93
|
-
if (error.response.status === _httpStatus.HttpStatusCode.UNAUTHORIZED) {
|
|
94
|
-
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.UNAUTHORIZED, _httpStatus.HttpStatusMessage.UNAUTHORIZED, "Failed to update user's password", {
|
|
95
|
-
detail: "Unauthorized request"
|
|
96
|
-
});
|
|
97
|
-
} else if (error.response.status === _httpStatus.HttpStatusCode.FORBIDDEN) {
|
|
98
|
-
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.FORBIDDEN, _httpStatus.HttpStatusMessage.FORBIDDEN, "Failed to update user's password", {
|
|
99
|
-
detail: "Invalid auth"
|
|
100
|
-
});
|
|
101
|
-
} else if (error.response.status === _httpStatus.HttpStatusCode.NOT_FOUND) {
|
|
102
|
-
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.NOT_FOUND, _httpStatus.HttpStatusMessage.NOT_FOUND, "Failed to update user's password", {
|
|
103
|
-
detail: "User not found"
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
user: shopUser
|
|
109
|
-
};
|
|
110
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getShopUserAddresses = void 0;
|
|
7
|
-
var _customer = require("../../../api/customer.cjs");
|
|
8
|
-
const getShopUserAddresses = exports.getShopUserAddresses = async function getShopUserAddresses2(context) {
|
|
9
|
-
const shopId = context.shopId;
|
|
10
|
-
const client = new _customer.CustomerAPIClient(context);
|
|
11
|
-
return (await client.getAddresses(shopId)).entities;
|
|
12
|
-
};
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
getProductById: true,
|
|
8
|
-
getProductsByIds: true,
|
|
9
|
-
getProductsByReferenceKeys: true,
|
|
10
|
-
getProductsCount: true,
|
|
11
|
-
fetchAllFiltersForCategory: true,
|
|
12
|
-
getFilters: true,
|
|
13
|
-
getProductsByCategory: true
|
|
14
|
-
};
|
|
15
|
-
Object.defineProperty(exports, "fetchAllFiltersForCategory", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function () {
|
|
18
|
-
return _products.fetchAllFiltersForCategory;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(exports, "getFilters", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _products.getFilters;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
Object.defineProperty(exports, "getProductById", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function () {
|
|
30
|
-
return _products.getProductById;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
Object.defineProperty(exports, "getProductsByCategory", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
get: function () {
|
|
36
|
-
return _products.getProductsByCategory;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
Object.defineProperty(exports, "getProductsByIds", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
get: function () {
|
|
42
|
-
return _products.getProductsByIds;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
Object.defineProperty(exports, "getProductsByReferenceKeys", {
|
|
46
|
-
enumerable: true,
|
|
47
|
-
get: function () {
|
|
48
|
-
return _products.getProductsByReferenceKeys;
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
Object.defineProperty(exports, "getProductsCount", {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
get: function () {
|
|
54
|
-
return _products.getProductsCount;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
var _basket = require("./basket/basket.cjs");
|
|
58
|
-
Object.keys(_basket).forEach(function (key) {
|
|
59
|
-
if (key === "default" || key === "__esModule") return;
|
|
60
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
61
|
-
if (key in exports && exports[key] === _basket[key]) return;
|
|
62
|
-
Object.defineProperty(exports, key, {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
get: function () {
|
|
65
|
-
return _basket[key];
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
var _brands = require("./brands.cjs");
|
|
70
|
-
Object.keys(_brands).forEach(function (key) {
|
|
71
|
-
if (key === "default" || key === "__esModule") return;
|
|
72
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
73
|
-
if (key in exports && exports[key] === _brands[key]) return;
|
|
74
|
-
Object.defineProperty(exports, key, {
|
|
75
|
-
enumerable: true,
|
|
76
|
-
get: function () {
|
|
77
|
-
return _brands[key];
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
var _categories = require("./categories.cjs");
|
|
82
|
-
Object.keys(_categories).forEach(function (key) {
|
|
83
|
-
if (key === "default" || key === "__esModule") return;
|
|
84
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
85
|
-
if (key in exports && exports[key] === _categories[key]) return;
|
|
86
|
-
Object.defineProperty(exports, key, {
|
|
87
|
-
enumerable: true,
|
|
88
|
-
get: function () {
|
|
89
|
-
return _categories[key];
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
var _cbd = require("./cbd.cjs");
|
|
94
|
-
Object.keys(_cbd).forEach(function (key) {
|
|
95
|
-
if (key === "default" || key === "__esModule") return;
|
|
96
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
97
|
-
if (key in exports && exports[key] === _cbd[key]) return;
|
|
98
|
-
Object.defineProperty(exports, key, {
|
|
99
|
-
enumerable: true,
|
|
100
|
-
get: function () {
|
|
101
|
-
return _cbd[key];
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
var _products = require("./products.cjs");
|
|
106
|
-
var _search = require("./search.cjs");
|
|
107
|
-
Object.keys(_search).forEach(function (key) {
|
|
108
|
-
if (key === "default" || key === "__esModule") return;
|
|
109
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
110
|
-
if (key in exports && exports[key] === _search[key]) return;
|
|
111
|
-
Object.defineProperty(exports, key, {
|
|
112
|
-
enumerable: true,
|
|
113
|
-
get: function () {
|
|
114
|
-
return _search[key];
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
var _shopConfiguration = require("./shopConfiguration.cjs");
|
|
119
|
-
Object.keys(_shopConfiguration).forEach(function (key) {
|
|
120
|
-
if (key === "default" || key === "__esModule") return;
|
|
121
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
122
|
-
if (key in exports && exports[key] === _shopConfiguration[key]) return;
|
|
123
|
-
Object.defineProperty(exports, key, {
|
|
124
|
-
enumerable: true,
|
|
125
|
-
get: function () {
|
|
126
|
-
return _shopConfiguration[key];
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
var _user = require("./user.cjs");
|
|
131
|
-
Object.keys(_user).forEach(function (key) {
|
|
132
|
-
if (key === "default" || key === "__esModule") return;
|
|
133
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
134
|
-
if (key in exports && exports[key] === _user[key]) return;
|
|
135
|
-
Object.defineProperty(exports, key, {
|
|
136
|
-
enumerable: true,
|
|
137
|
-
get: function () {
|
|
138
|
-
return _user[key];
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
var _wishlist = require("./wishlist.cjs");
|
|
143
|
-
Object.keys(_wishlist).forEach(function (key) {
|
|
144
|
-
if (key === "default" || key === "__esModule") return;
|
|
145
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
146
|
-
if (key in exports && exports[key] === _wishlist[key]) return;
|
|
147
|
-
Object.defineProperty(exports, key, {
|
|
148
|
-
enumerable: true,
|
|
149
|
-
get: function () {
|
|
150
|
-
return _wishlist[key];
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
var _checkout = require("./checkout/index.cjs");
|
|
155
|
-
Object.keys(_checkout).forEach(function (key) {
|
|
156
|
-
if (key === "default" || key === "__esModule") return;
|
|
157
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
158
|
-
if (key in exports && exports[key] === _checkout[key]) return;
|
|
159
|
-
Object.defineProperty(exports, key, {
|
|
160
|
-
enumerable: true,
|
|
161
|
-
get: function () {
|
|
162
|
-
return _checkout[key];
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
var _variants = require("./variants.cjs");
|
|
167
|
-
Object.keys(_variants).forEach(function (key) {
|
|
168
|
-
if (key === "default" || key === "__esModule") return;
|
|
169
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
170
|
-
if (key in exports && exports[key] === _variants[key]) return;
|
|
171
|
-
Object.defineProperty(exports, key, {
|
|
172
|
-
enumerable: true,
|
|
173
|
-
get: function () {
|
|
174
|
-
return _variants[key];
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
var _navigationTrees = require("./navigationTrees.cjs");
|
|
179
|
-
Object.keys(_navigationTrees).forEach(function (key) {
|
|
180
|
-
if (key === "default" || key === "__esModule") return;
|
|
181
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
182
|
-
if (key in exports && exports[key] === _navigationTrees[key]) return;
|
|
183
|
-
Object.defineProperty(exports, key, {
|
|
184
|
-
enumerable: true,
|
|
185
|
-
get: function () {
|
|
186
|
-
return _navigationTrees[key];
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
var _session = require("./session.cjs");
|
|
191
|
-
Object.keys(_session).forEach(function (key) {
|
|
192
|
-
if (key === "default" || key === "__esModule") return;
|
|
193
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
194
|
-
if (key in exports && exports[key] === _session[key]) return;
|
|
195
|
-
Object.defineProperty(exports, key, {
|
|
196
|
-
enumerable: true,
|
|
197
|
-
get: function () {
|
|
198
|
-
return _session[key];
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
var _promotion = require("./promotion.cjs");
|
|
203
|
-
Object.keys(_promotion).forEach(function (key) {
|
|
204
|
-
if (key === "default" || key === "__esModule") return;
|
|
205
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
206
|
-
if (key in exports && exports[key] === _promotion[key]) return;
|
|
207
|
-
Object.defineProperty(exports, key, {
|
|
208
|
-
enumerable: true,
|
|
209
|
-
get: function () {
|
|
210
|
-
return _promotion[key];
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
var _idp = require("./oauth/idp.cjs");
|
|
215
|
-
Object.keys(_idp).forEach(function (key) {
|
|
216
|
-
if (key === "default" || key === "__esModule") return;
|
|
217
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
218
|
-
if (key in exports && exports[key] === _idp[key]) return;
|
|
219
|
-
Object.defineProperty(exports, key, {
|
|
220
|
-
enumerable: true,
|
|
221
|
-
get: function () {
|
|
222
|
-
return _idp[key];
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
});
|