@scayle/storefront-core 7.26.0 → 7.28.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 +13 -0
- package/dist/api/oauth.cjs +136 -0
- package/dist/api/oauth.d.ts +57 -0
- package/dist/api/oauth.mjs +125 -0
- package/dist/cache/providers/unstorage.cjs +25 -2
- package/dist/cache/providers/unstorage.d.ts +10 -0
- package/dist/cache/providers/unstorage.mjs +25 -2
- package/dist/constants/basket.cjs +2 -3
- package/dist/constants/cache.cjs +1 -2
- package/dist/constants/hash.cjs +2 -3
- package/dist/constants/httpStatus.cjs +3 -5
- package/dist/constants/product.cjs +2 -3
- package/dist/constants/promotion.cjs +4 -7
- package/dist/constants/sorting.cjs +3 -5
- package/dist/constants/withParameters.cjs +7 -13
- package/dist/helpers/product.fixture.cjs +4 -8
- package/dist/index.cjs +2 -2
- package/dist/rpc/methods/basket/basket.cjs +6 -12
- package/dist/rpc/methods/brands.cjs +3 -5
- package/dist/rpc/methods/categories.cjs +4 -7
- package/dist/rpc/methods/cbd.cjs +4 -9
- package/dist/rpc/methods/cbd.mjs +2 -3
- package/dist/rpc/methods/checkout/order.cjs +5 -8
- package/dist/rpc/methods/checkout/order.mjs +3 -4
- package/dist/rpc/methods/checkout/shopUser.cjs +32 -31
- package/dist/rpc/methods/checkout/shopUser.mjs +18 -23
- package/dist/rpc/methods/checkout/shopUserAddresses.cjs +9 -8
- package/dist/rpc/methods/checkout/shopUserAddresses.mjs +7 -4
- package/dist/rpc/methods/navigationTrees.cjs +3 -5
- package/dist/rpc/methods/products.cjs +6 -12
- package/dist/rpc/methods/promotion.cjs +4 -7
- package/dist/rpc/methods/search.cjs +1 -2
- package/dist/rpc/methods/session.cjs +52 -99
- package/dist/rpc/methods/session.d.ts +9 -4
- package/dist/rpc/methods/session.mjs +62 -139
- package/dist/rpc/methods/shopConfiguration.cjs +2 -3
- package/dist/rpc/methods/user.cjs +24 -21
- package/dist/rpc/methods/user.mjs +20 -13
- package/dist/rpc/methods/variants.cjs +2 -3
- package/dist/rpc/methods/wishlist.cjs +5 -9
- package/dist/types/api/auth.d.ts +9 -4
- package/dist/utils/fetch.cjs +19 -0
- package/dist/utils/fetch.d.ts +9 -0
- package/dist/utils/fetch.mjs +12 -0
- package/dist/utils/index.cjs +11 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.mjs +1 -0
- package/package.json +7 -12
- package/dist/utils/rpc.cjs +0 -41
- package/dist/utils/rpc.d.ts +0 -6
- package/dist/utils/rpc.mjs +0 -35
|
@@ -11,7 +11,7 @@ const BAPI_ERROR_NAME = "BAPI ERROR";
|
|
|
11
11
|
function getWithParams(params, context) {
|
|
12
12
|
return params.with ?? context.withParams?.basket ?? _constants.MIN_WITH_PARAMS_BASKET;
|
|
13
13
|
}
|
|
14
|
-
const addItemToBasket = async function addItemToBasket2({
|
|
14
|
+
const addItemToBasket = exports.addItemToBasket = async function addItemToBasket2({
|
|
15
15
|
variantId,
|
|
16
16
|
promotionId,
|
|
17
17
|
quantity,
|
|
@@ -61,8 +61,7 @@ const addItemToBasket = async function addItemToBasket2({
|
|
|
61
61
|
throw new _errors.BAPIError(BAPI_ERROR_NAME, statusCode, message, "addItemToBasket:bapiClient.basket.addOrUpdateItems");
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
|
-
exports.
|
|
65
|
-
const addItemsToBasket = async function addItemsToBasket2(params, context) {
|
|
64
|
+
const addItemsToBasket = exports.addItemsToBasket = async function addItemsToBasket2(params, context) {
|
|
66
65
|
const {
|
|
67
66
|
campaignKey,
|
|
68
67
|
bapiClient,
|
|
@@ -104,8 +103,7 @@ const addItemsToBasket = async function addItemsToBasket2(params, context) {
|
|
|
104
103
|
throw new _errors.BAPIError(BAPI_ERROR_NAME, statusCode, message, "addItemsToBasket:bapiClient.basket.addOrUpdateItems");
|
|
105
104
|
}
|
|
106
105
|
};
|
|
107
|
-
exports.
|
|
108
|
-
const getBasket = async function getBasket2(options, context) {
|
|
106
|
+
const getBasket = exports.getBasket = async function getBasket2(options, context) {
|
|
109
107
|
const {
|
|
110
108
|
bapiClient,
|
|
111
109
|
campaignKey,
|
|
@@ -128,8 +126,7 @@ const getBasket = async function getBasket2(options, context) {
|
|
|
128
126
|
}
|
|
129
127
|
return response.basket;
|
|
130
128
|
};
|
|
131
|
-
exports.
|
|
132
|
-
const removeItemFromBasket = async function removeItemFromBasket2(options, context) {
|
|
129
|
+
const removeItemFromBasket = exports.removeItemFromBasket = async function removeItemFromBasket2(options, context) {
|
|
133
130
|
const {
|
|
134
131
|
bapiClient,
|
|
135
132
|
campaignKey,
|
|
@@ -142,8 +139,7 @@ const removeItemFromBasket = async function removeItemFromBasket2(options, conte
|
|
|
142
139
|
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData
|
|
143
140
|
});
|
|
144
141
|
};
|
|
145
|
-
exports.
|
|
146
|
-
const clearBasket = async function clearBasket2(context) {
|
|
142
|
+
const clearBasket = exports.clearBasket = async function clearBasket2(context) {
|
|
147
143
|
const basket = await getBasket({}, context);
|
|
148
144
|
await Promise.all(basket.items.map(async item => {
|
|
149
145
|
await removeItemFromBasket({
|
|
@@ -153,8 +149,7 @@ const clearBasket = async function clearBasket2(context) {
|
|
|
153
149
|
context.log.debug("The basket has been cleared");
|
|
154
150
|
return true;
|
|
155
151
|
};
|
|
156
|
-
exports.
|
|
157
|
-
const mergeBaskets = async function mergeBaskets2({
|
|
152
|
+
const mergeBaskets = exports.mergeBaskets = async function mergeBaskets2({
|
|
158
153
|
fromBasketKey,
|
|
159
154
|
toBasketKey,
|
|
160
155
|
with: _with
|
|
@@ -164,7 +159,6 @@ const mergeBaskets = async function mergeBaskets2({
|
|
|
164
159
|
}, context);
|
|
165
160
|
return await (0, _user.mergeBaskets)(fromBasketKey, toBasketKey, resolvedWith, context);
|
|
166
161
|
};
|
|
167
|
-
exports.mergeBaskets = mergeBaskets;
|
|
168
162
|
function parseBasketError(response) {
|
|
169
163
|
if (response.type === "failure") {
|
|
170
164
|
const parsedError = {
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getBrands = exports.getBrandById = void 0;
|
|
7
7
|
const MAX_PER_PAGE = 100;
|
|
8
|
-
const getBrands = async function getBrands2({
|
|
8
|
+
const getBrands = exports.getBrands = async function getBrands2({
|
|
9
9
|
pagination
|
|
10
10
|
}, {
|
|
11
11
|
bapiClient,
|
|
@@ -20,8 +20,7 @@ const getBrands = async function getBrands2({
|
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
|
-
exports.
|
|
24
|
-
const getBrandById = async function getBrandById2({
|
|
23
|
+
const getBrandById = exports.getBrandById = async function getBrandById2({
|
|
25
24
|
brandId
|
|
26
25
|
}, {
|
|
27
26
|
bapiClient,
|
|
@@ -30,5 +29,4 @@ const getBrandById = async function getBrandById2({
|
|
|
30
29
|
return await cached(bapiClient.brands.getById, {
|
|
31
30
|
cacheKeyPrefix: `getBrandById-${brandId}`
|
|
32
31
|
})(brandId);
|
|
33
|
-
};
|
|
34
|
-
exports.getBrandById = getBrandById;
|
|
32
|
+
};
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getRootCategories = exports.getCategoryById = exports.getCategoriesByPath = void 0;
|
|
7
7
|
var _helpers = require("../../helpers/index.cjs");
|
|
8
|
-
const getRootCategories = async function getRootCategories2({
|
|
8
|
+
const getRootCategories = exports.getRootCategories = async function getRootCategories2({
|
|
9
9
|
children = 1,
|
|
10
10
|
includeHidden
|
|
11
11
|
}, {
|
|
@@ -25,8 +25,7 @@ const getRootCategories = async function getRootCategories2({
|
|
|
25
25
|
activeNode: void 0
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
|
-
exports.
|
|
29
|
-
const getCategoriesByPath = async function getCategoriesByPath2({
|
|
28
|
+
const getCategoriesByPath = exports.getCategoriesByPath = async function getCategoriesByPath2({
|
|
30
29
|
path,
|
|
31
30
|
children = 1,
|
|
32
31
|
includeHidden
|
|
@@ -79,8 +78,7 @@ const getCategoriesByPath = async function getCategoriesByPath2({
|
|
|
79
78
|
activeNode: result
|
|
80
79
|
};
|
|
81
80
|
};
|
|
82
|
-
exports.
|
|
83
|
-
const getCategoryById = async function getCategoryById2({
|
|
81
|
+
const getCategoryById = exports.getCategoryById = async function getCategoryById2({
|
|
84
82
|
id,
|
|
85
83
|
children = 1,
|
|
86
84
|
includeHidden
|
|
@@ -98,5 +96,4 @@ const getCategoryById = async function getCategoryById2({
|
|
|
98
96
|
},
|
|
99
97
|
includeHidden
|
|
100
98
|
});
|
|
101
|
-
};
|
|
102
|
-
exports.getCategoryById = getCategoryById;
|
|
99
|
+
};
|
package/dist/rpc/methods/cbd.cjs
CHANGED
|
@@ -4,10 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getOrderDataByCbd = void 0;
|
|
7
|
-
var _axios = _interopRequireDefault(require("axios"));
|
|
8
7
|
var _hash = require("../../utils/hash.cjs");
|
|
9
|
-
|
|
10
|
-
const getOrderDataByCbd = async function getOrderDataByCbd2({
|
|
8
|
+
const getOrderDataByCbd = exports.getOrderDataByCbd = async function getOrderDataByCbd2({
|
|
11
9
|
cbdToken
|
|
12
10
|
}, context) {
|
|
13
11
|
if (!cbdToken) {
|
|
@@ -27,9 +25,7 @@ const getOrderDataByCbd = async function getOrderDataByCbd2({
|
|
|
27
25
|
return;
|
|
28
26
|
}
|
|
29
27
|
const accessToken = (0, _hash.encodeBase64)(`${checkoutUsername}:${unescape(checkoutToken)}`);
|
|
30
|
-
const {
|
|
31
|
-
data: orderSuccessData
|
|
32
|
-
} = await _axios.default.get(`${checkoutUrl}/api/v1/orders/${payload.order_id}`, {
|
|
28
|
+
const response = await fetch(`${checkoutUrl}/api/v1/orders/${payload.order_id}`, {
|
|
33
29
|
headers: {
|
|
34
30
|
Accept: "application/json",
|
|
35
31
|
Authorization: `Basic ${accessToken}`,
|
|
@@ -39,7 +35,6 @@ const getOrderDataByCbd = async function getOrderDataByCbd2({
|
|
|
39
35
|
} : {})
|
|
40
36
|
}
|
|
41
37
|
});
|
|
42
|
-
return
|
|
38
|
+
return await response.json();
|
|
43
39
|
}
|
|
44
|
-
};
|
|
45
|
-
exports.getOrderDataByCbd = getOrderDataByCbd;
|
|
40
|
+
};
|
package/dist/rpc/methods/cbd.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
1
|
import { encodeBase64, verifyToken } from "../../utils/hash.mjs";
|
|
3
2
|
export const getOrderDataByCbd = async function getOrderDataByCbd2({ cbdToken }, context) {
|
|
4
3
|
if (!cbdToken) {
|
|
@@ -20,7 +19,7 @@ export const getOrderDataByCbd = async function getOrderDataByCbd2({ cbdToken },
|
|
|
20
19
|
const accessToken = encodeBase64(
|
|
21
20
|
`${checkoutUsername}:${unescape(checkoutToken)}`
|
|
22
21
|
);
|
|
23
|
-
const
|
|
22
|
+
const response = await fetch(
|
|
24
23
|
`${checkoutUrl}/api/v1/orders/${payload.order_id}`,
|
|
25
24
|
{
|
|
26
25
|
headers: {
|
|
@@ -31,6 +30,6 @@ export const getOrderDataByCbd = async function getOrderDataByCbd2({ cbdToken },
|
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
);
|
|
34
|
-
return
|
|
33
|
+
return await response.json();
|
|
35
34
|
}
|
|
36
35
|
};
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getOrderById = void 0;
|
|
7
|
-
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
const getOrderById = async function getOrderById2({
|
|
7
|
+
const getOrderById = exports.getOrderById = async function getOrderById2({
|
|
10
8
|
orderId
|
|
11
9
|
}, context) {
|
|
12
10
|
const accessToken = context.accessToken;
|
|
@@ -28,10 +26,10 @@ const getOrderById = async function getOrderById2({
|
|
|
28
26
|
}
|
|
29
27
|
const orderUrl = `${checkoutUrl}/api/customer/order/${orderId}`;
|
|
30
28
|
try {
|
|
31
|
-
const response = await
|
|
29
|
+
const response = await fetch(orderUrl, {
|
|
32
30
|
headers: {
|
|
33
31
|
Authorization: `Bearer ${accessToken}`,
|
|
34
|
-
"X-Shop-Id": shopId,
|
|
32
|
+
"X-Shop-Id": shopId.toString(),
|
|
35
33
|
Accept: "application/json",
|
|
36
34
|
...(accessHeader ? {
|
|
37
35
|
"X-Access-Header": accessHeader
|
|
@@ -42,7 +40,7 @@ const getOrderById = async function getOrderById2({
|
|
|
42
40
|
throw new Error("Order not found");
|
|
43
41
|
}
|
|
44
42
|
if (response.status === 200) {
|
|
45
|
-
return response.
|
|
43
|
+
return await response.json();
|
|
46
44
|
}
|
|
47
45
|
throw new Error(`Unknown response status: ${response.status}`);
|
|
48
46
|
} catch (error) {
|
|
@@ -51,5 +49,4 @@ const getOrderById = async function getOrderById2({
|
|
|
51
49
|
});
|
|
52
50
|
throw error;
|
|
53
51
|
}
|
|
54
|
-
};
|
|
55
|
-
exports.getOrderById = getOrderById;
|
|
52
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
1
|
export const getOrderById = async function getOrderById2({ orderId }, context) {
|
|
3
2
|
const accessToken = context.accessToken;
|
|
4
3
|
const shopId = context.shopId;
|
|
@@ -21,10 +20,10 @@ export const getOrderById = async function getOrderById2({ orderId }, context) {
|
|
|
21
20
|
}
|
|
22
21
|
const orderUrl = `${checkoutUrl}/api/customer/order/${orderId}`;
|
|
23
22
|
try {
|
|
24
|
-
const response = await
|
|
23
|
+
const response = await fetch(orderUrl, {
|
|
25
24
|
headers: {
|
|
26
25
|
Authorization: `Bearer ${accessToken}`,
|
|
27
|
-
"X-Shop-Id": shopId,
|
|
26
|
+
"X-Shop-Id": shopId.toString(),
|
|
28
27
|
Accept: "application/json",
|
|
29
28
|
...accessHeader ? { "X-Access-Header": accessHeader } : {}
|
|
30
29
|
}
|
|
@@ -33,7 +32,7 @@ export const getOrderById = async function getOrderById2({ orderId }, context) {
|
|
|
33
32
|
throw new Error("Order not found");
|
|
34
33
|
}
|
|
35
34
|
if (response.status === 200) {
|
|
36
|
-
return response.
|
|
35
|
+
return await response.json();
|
|
37
36
|
}
|
|
38
37
|
throw new Error(`Unknown response status: ${response.status}`);
|
|
39
38
|
} catch (error) {
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.updateShopUser = exports.updatePassword = void 0;
|
|
7
|
-
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
const updateShopUser = async function updateShopUser2(payload, context) {
|
|
7
|
+
const updateShopUser = exports.updateShopUser = async function updateShopUser2(payload, context) {
|
|
10
8
|
const shopId = context.shopId;
|
|
11
9
|
const accessHeader = context.checkout.accessHeader;
|
|
12
10
|
const checkoutUrl = context.checkout.url;
|
|
@@ -32,35 +30,39 @@ const updateShopUser = async function updateShopUser2(payload, context) {
|
|
|
32
30
|
const personalUrl = `${checkoutUrl}/api/customer/personal`;
|
|
33
31
|
const headers = {
|
|
34
32
|
Authorization: `Bearer ${context.accessToken}`,
|
|
35
|
-
"X-Shop-Id": shopId,
|
|
33
|
+
"X-Shop-Id": shopId.toString(),
|
|
36
34
|
"Content-Type": "application/json",
|
|
37
35
|
...(accessHeader ? {
|
|
38
36
|
"X-Access-Header": accessHeader
|
|
39
37
|
} : {})
|
|
40
38
|
};
|
|
41
39
|
try {
|
|
42
|
-
const contactResponse = await
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
const contactResponse = await fetch(contactUrl, {
|
|
41
|
+
method: "PATCH",
|
|
42
|
+
headers,
|
|
43
|
+
body: JSON.stringify({
|
|
44
|
+
email: user?.email,
|
|
45
|
+
phone: user?.phone
|
|
46
|
+
})
|
|
47
47
|
});
|
|
48
48
|
if (contactResponse.status === 404) {
|
|
49
49
|
throw new Error("Failed to update user's contact information");
|
|
50
50
|
}
|
|
51
51
|
if (contactResponse.status === 200) {
|
|
52
|
-
const personalResponse = await
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
const personalResponse = await fetch(personalUrl, {
|
|
53
|
+
method: "PATCH",
|
|
54
|
+
headers,
|
|
55
|
+
body: JSON.stringify({
|
|
56
|
+
firstName: user?.firstName,
|
|
57
|
+
lastName: user?.lastName,
|
|
58
|
+
birthDate: user?.birthDate,
|
|
59
|
+
...(user?.gender && {
|
|
60
|
+
gender: user?.gender
|
|
61
|
+
}),
|
|
62
|
+
...(user?.title && {
|
|
63
|
+
title: user?.title
|
|
64
|
+
})
|
|
61
65
|
})
|
|
62
|
-
}, {
|
|
63
|
-
headers
|
|
64
66
|
});
|
|
65
67
|
if (personalResponse.status === 404) {
|
|
66
68
|
throw new Error("Failed to update user's personal information");
|
|
@@ -80,32 +82,32 @@ const updateShopUser = async function updateShopUser2(payload, context) {
|
|
|
80
82
|
user
|
|
81
83
|
};
|
|
82
84
|
};
|
|
83
|
-
exports.
|
|
84
|
-
const updatePassword = async function updatePassword2({
|
|
85
|
+
const updatePassword = exports.updatePassword = async function updatePassword2({
|
|
85
86
|
oldPassword,
|
|
86
87
|
newPassword
|
|
87
88
|
}, context) {
|
|
88
89
|
const shopUser = context.user;
|
|
89
90
|
try {
|
|
90
|
-
const apiResponse = await
|
|
91
|
-
password: oldPassword,
|
|
92
|
-
newPassword
|
|
93
|
-
}, {
|
|
91
|
+
const apiResponse = await fetch(`${context.checkout.url}/api/oauth/customer/password`, {
|
|
94
92
|
headers: {
|
|
95
93
|
Authorization: `Bearer ${context.accessToken}`,
|
|
96
|
-
"X-Shop-Id": context.shopId,
|
|
94
|
+
"X-Shop-Id": context.shopId.toString(),
|
|
97
95
|
"Content-Type": "application/json",
|
|
98
96
|
...(context.checkout.accessHeader ? {
|
|
99
97
|
"X-Access-Header": context.checkout.accessHeader
|
|
100
98
|
} : {})
|
|
101
|
-
}
|
|
99
|
+
},
|
|
100
|
+
body: JSON.stringify({
|
|
101
|
+
password: oldPassword,
|
|
102
|
+
newPassword
|
|
103
|
+
})
|
|
102
104
|
});
|
|
103
105
|
if (apiResponse.status === 200) {
|
|
104
106
|
if (shopUser?.id) {
|
|
105
107
|
await context.destroySessionsForUserId(shopUser.id, [context.sessionId]);
|
|
106
108
|
}
|
|
107
109
|
return {
|
|
108
|
-
user: apiResponse.
|
|
110
|
+
user: await apiResponse.json()
|
|
109
111
|
};
|
|
110
112
|
} else if (apiResponse.status === 401) {
|
|
111
113
|
throw new Error("401 - Failed to update user's password - Unauthorized request");
|
|
@@ -121,5 +123,4 @@ const updatePassword = async function updatePassword2({
|
|
|
121
123
|
return {
|
|
122
124
|
user: shopUser
|
|
123
125
|
};
|
|
124
|
-
};
|
|
125
|
-
exports.updatePassword = updatePassword;
|
|
126
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
1
|
export const updateShopUser = async function updateShopUser2(payload, context) {
|
|
3
2
|
const shopId = context.shopId;
|
|
4
3
|
const accessHeader = context.checkout.accessHeader;
|
|
@@ -25,38 +24,34 @@ export const updateShopUser = async function updateShopUser2(payload, context) {
|
|
|
25
24
|
const personalUrl = `${checkoutUrl}/api/customer/personal`;
|
|
26
25
|
const headers = {
|
|
27
26
|
Authorization: `Bearer ${context.accessToken}`,
|
|
28
|
-
"X-Shop-Id": shopId,
|
|
27
|
+
"X-Shop-Id": shopId.toString(),
|
|
29
28
|
"Content-Type": "application/json",
|
|
30
29
|
...accessHeader ? { "X-Access-Header": accessHeader } : {}
|
|
31
30
|
};
|
|
32
31
|
try {
|
|
33
|
-
const contactResponse = await
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
const contactResponse = await fetch(contactUrl, {
|
|
33
|
+
method: "PATCH",
|
|
34
|
+
headers,
|
|
35
|
+
body: JSON.stringify({
|
|
36
36
|
email: user?.email,
|
|
37
37
|
phone: user?.phone
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
headers
|
|
41
|
-
}
|
|
42
|
-
);
|
|
38
|
+
})
|
|
39
|
+
});
|
|
43
40
|
if (contactResponse.status === 404) {
|
|
44
41
|
throw new Error("Failed to update user's contact information");
|
|
45
42
|
}
|
|
46
43
|
if (contactResponse.status === 200) {
|
|
47
|
-
const personalResponse = await
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
const personalResponse = await fetch(personalUrl, {
|
|
45
|
+
method: "PATCH",
|
|
46
|
+
headers,
|
|
47
|
+
body: JSON.stringify({
|
|
50
48
|
firstName: user?.firstName,
|
|
51
49
|
lastName: user?.lastName,
|
|
52
50
|
birthDate: user?.birthDate,
|
|
53
51
|
...user?.gender && { gender: user?.gender },
|
|
54
52
|
...user?.title && { title: user?.title }
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
headers
|
|
58
|
-
}
|
|
59
|
-
);
|
|
53
|
+
})
|
|
54
|
+
});
|
|
60
55
|
if (personalResponse.status === 404) {
|
|
61
56
|
throw new Error("Failed to update user's personal information");
|
|
62
57
|
}
|
|
@@ -74,23 +69,23 @@ export const updateShopUser = async function updateShopUser2(payload, context) {
|
|
|
74
69
|
export const updatePassword = async function updatePassword2({ oldPassword, newPassword }, context) {
|
|
75
70
|
const shopUser = context.user;
|
|
76
71
|
try {
|
|
77
|
-
const apiResponse = await
|
|
72
|
+
const apiResponse = await fetch(
|
|
78
73
|
`${context.checkout.url}/api/oauth/customer/password`,
|
|
79
|
-
{ password: oldPassword, newPassword },
|
|
80
74
|
{
|
|
81
75
|
headers: {
|
|
82
76
|
Authorization: `Bearer ${context.accessToken}`,
|
|
83
|
-
"X-Shop-Id": context.shopId,
|
|
77
|
+
"X-Shop-Id": context.shopId.toString(),
|
|
84
78
|
"Content-Type": "application/json",
|
|
85
79
|
...context.checkout.accessHeader ? { "X-Access-Header": context.checkout.accessHeader } : {}
|
|
86
|
-
}
|
|
80
|
+
},
|
|
81
|
+
body: JSON.stringify({ password: oldPassword, newPassword })
|
|
87
82
|
}
|
|
88
83
|
);
|
|
89
84
|
if (apiResponse.status === 200) {
|
|
90
85
|
if (shopUser?.id) {
|
|
91
86
|
await context.destroySessionsForUserId(shopUser.id, [context.sessionId]);
|
|
92
87
|
}
|
|
93
|
-
return { user: apiResponse.
|
|
88
|
+
return { user: await apiResponse.json() };
|
|
94
89
|
} else if (apiResponse.status === 401) {
|
|
95
90
|
throw new Error(
|
|
96
91
|
"401 - Failed to update user's password - Unauthorized request"
|
|
@@ -4,22 +4,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getShopUserAddresses = void 0;
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
const getShopUserAddresses = async function getShopUserAddresses2(context) {
|
|
7
|
+
var _fetch = require("../../../utils/fetch.cjs");
|
|
8
|
+
const getShopUserAddresses = exports.getShopUserAddresses = async function getShopUserAddresses2(context) {
|
|
10
9
|
const shopId = context.shopId;
|
|
11
10
|
const accessHeader = context.checkout.accessHeader;
|
|
12
11
|
const checkoutUrl = context.checkout.url;
|
|
13
|
-
const response = await
|
|
12
|
+
const response = await fetch(`${checkoutUrl}/api/oauth/customer/addresses`, {
|
|
14
13
|
headers: {
|
|
15
14
|
Authorization: `Bearer ${context.accessToken}`,
|
|
16
|
-
"X-Shop-Id": shopId,
|
|
15
|
+
"X-Shop-Id": shopId.toString(),
|
|
17
16
|
Accept: "application/json",
|
|
18
17
|
...(accessHeader && {
|
|
19
18
|
"X-Access-Header": accessHeader
|
|
20
19
|
})
|
|
21
20
|
}
|
|
22
21
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
throw new _fetch.FetchError(response);
|
|
24
|
+
}
|
|
25
|
+
return (await response.json()).entities;
|
|
26
|
+
};
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FetchError } from "../../../utils/fetch.mjs";
|
|
2
2
|
const getShopUserAddresses = async function getShopUserAddresses2(context) {
|
|
3
3
|
const shopId = context.shopId;
|
|
4
4
|
const accessHeader = context.checkout.accessHeader;
|
|
5
5
|
const checkoutUrl = context.checkout.url;
|
|
6
|
-
const response = await
|
|
6
|
+
const response = await fetch(
|
|
7
7
|
`${checkoutUrl}/api/oauth/customer/addresses`,
|
|
8
8
|
{
|
|
9
9
|
headers: {
|
|
10
10
|
Authorization: `Bearer ${context.accessToken}`,
|
|
11
|
-
"X-Shop-Id": shopId,
|
|
11
|
+
"X-Shop-Id": shopId.toString(),
|
|
12
12
|
Accept: "application/json",
|
|
13
13
|
...accessHeader && { "X-Access-Header": accessHeader }
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
);
|
|
17
|
-
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
throw new FetchError(response);
|
|
19
|
+
}
|
|
20
|
+
return (await response.json()).entities;
|
|
18
21
|
};
|
|
19
22
|
export { getShopUserAddresses };
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.fetchNavigationTreeById = exports.fetchAllNavigationTrees = void 0;
|
|
7
|
-
const fetchAllNavigationTrees = async function fetchAllNavigationTrees2({
|
|
7
|
+
const fetchAllNavigationTrees = exports.fetchAllNavigationTrees = async function fetchAllNavigationTrees2({
|
|
8
8
|
params
|
|
9
9
|
}, {
|
|
10
10
|
bapiClient: {
|
|
@@ -16,8 +16,7 @@ const fetchAllNavigationTrees = async function fetchAllNavigationTrees2({
|
|
|
16
16
|
cacheKeyPrefix: "getAll-navigation-trees"
|
|
17
17
|
})(params);
|
|
18
18
|
};
|
|
19
|
-
exports.
|
|
20
|
-
const fetchNavigationTreeById = async function fetchNavigationTreeById2({
|
|
19
|
+
const fetchNavigationTreeById = exports.fetchNavigationTreeById = async function fetchNavigationTreeById2({
|
|
21
20
|
treeId,
|
|
22
21
|
params
|
|
23
22
|
}, {
|
|
@@ -29,5 +28,4 @@ const fetchNavigationTreeById = async function fetchNavigationTreeById2({
|
|
|
29
28
|
return await cached(navigation.getById, {
|
|
30
29
|
cacheKeyPrefix: `getById-navigation-trees-${treeId}`
|
|
31
30
|
})(treeId, params);
|
|
32
|
-
};
|
|
33
|
-
exports.fetchNavigationTreeById = fetchNavigationTreeById;
|
|
31
|
+
};
|
|
@@ -7,7 +7,7 @@ exports.getProductsCount = exports.getProductsByIds = exports.getProductsByCateg
|
|
|
7
7
|
var _helpers = require("../../helpers/index.cjs");
|
|
8
8
|
var _constants = require("../../constants/index.cjs");
|
|
9
9
|
const MAX_PER_PAGE = 100;
|
|
10
|
-
const getProductById = async function getProductById2(options, {
|
|
10
|
+
const getProductById = exports.getProductById = async function getProductById2(options, {
|
|
11
11
|
bapiClient,
|
|
12
12
|
cached,
|
|
13
13
|
campaignKey,
|
|
@@ -22,8 +22,7 @@ const getProductById = async function getProductById2(options, {
|
|
|
22
22
|
includeSellableForFree: options.includeSellableForFree
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
|
-
exports.
|
|
26
|
-
const getProductsByIds = async function getProductsByIds2(options, {
|
|
25
|
+
const getProductsByIds = exports.getProductsByIds = async function getProductsByIds2(options, {
|
|
27
26
|
bapiClient,
|
|
28
27
|
cached,
|
|
29
28
|
campaignKey,
|
|
@@ -38,8 +37,7 @@ const getProductsByIds = async function getProductsByIds2(options, {
|
|
|
38
37
|
includeSellableForFree: options.includeSellableForFree
|
|
39
38
|
});
|
|
40
39
|
};
|
|
41
|
-
exports.
|
|
42
|
-
const getProductsByCategory = async function getProductsByCategory2({
|
|
40
|
+
const getProductsByCategory = exports.getProductsByCategory = async function getProductsByCategory2({
|
|
43
41
|
category = "/",
|
|
44
42
|
cache,
|
|
45
43
|
with: _with,
|
|
@@ -106,8 +104,7 @@ const getProductsByCategory = async function getProductsByCategory2({
|
|
|
106
104
|
pagination
|
|
107
105
|
};
|
|
108
106
|
};
|
|
109
|
-
exports.
|
|
110
|
-
const getFilters = async function getFilters2({
|
|
107
|
+
const getFilters = exports.getFilters = async function getFilters2({
|
|
111
108
|
category = "/",
|
|
112
109
|
includedFilters,
|
|
113
110
|
where = void 0,
|
|
@@ -179,8 +176,7 @@ const getFilters = async function getFilters2({
|
|
|
179
176
|
unfilteredCount: productCount?.pagination.total
|
|
180
177
|
};
|
|
181
178
|
};
|
|
182
|
-
exports.
|
|
183
|
-
const fetchAllFiltersForCategory = async function fetchAllFiltersForCategory2({
|
|
179
|
+
const fetchAllFiltersForCategory = exports.fetchAllFiltersForCategory = async function fetchAllFiltersForCategory2({
|
|
184
180
|
includedFilters = [],
|
|
185
181
|
category
|
|
186
182
|
}, {
|
|
@@ -204,8 +200,7 @@ const fetchAllFiltersForCategory = async function fetchAllFiltersForCategory2({
|
|
|
204
200
|
cacheKey: `filters-for-category-${category.slug}`
|
|
205
201
|
})();
|
|
206
202
|
};
|
|
207
|
-
exports.
|
|
208
|
-
const getProductsCount = async function getProductsCount2({
|
|
203
|
+
const getProductsCount = exports.getProductsCount = async function getProductsCount2({
|
|
209
204
|
category = "/",
|
|
210
205
|
categoryId = void 0,
|
|
211
206
|
where = void 0,
|
|
@@ -246,7 +241,6 @@ const getProductsCount = async function getProductsCount2({
|
|
|
246
241
|
count: productCount?.pagination.total
|
|
247
242
|
};
|
|
248
243
|
};
|
|
249
|
-
exports.getProductsCount = getProductsCount;
|
|
250
244
|
const sanitizeAttributesForBAPI = ({
|
|
251
245
|
attributes,
|
|
252
246
|
filterKeys,
|
|
@@ -11,7 +11,7 @@ const setPaginationDefault = pagination => {
|
|
|
11
11
|
perPage: pagination?.perPage || _constants.PROMOTION_PER_PAGE_DEFAULT
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
|
-
const getPromotions = async function getPromotions2(params = {}, context) {
|
|
14
|
+
const getPromotions = exports.getPromotions = async function getPromotions2(params = {}, context) {
|
|
15
15
|
const {
|
|
16
16
|
bapiClient,
|
|
17
17
|
cached
|
|
@@ -23,8 +23,7 @@ const getPromotions = async function getPromotions2(params = {}, context) {
|
|
|
23
23
|
pagination: setPaginationDefault(params.pagination)
|
|
24
24
|
});
|
|
25
25
|
};
|
|
26
|
-
exports.
|
|
27
|
-
const getCurrentPromotions = async function getCurrentPromotions2(params = {}, context) {
|
|
26
|
+
const getCurrentPromotions = exports.getCurrentPromotions = async function getCurrentPromotions2(params = {}, context) {
|
|
28
27
|
const {
|
|
29
28
|
bapiClient,
|
|
30
29
|
cached
|
|
@@ -40,8 +39,7 @@ const getCurrentPromotions = async function getCurrentPromotions2(params = {}, c
|
|
|
40
39
|
pagination: setPaginationDefault(params.pagination)
|
|
41
40
|
});
|
|
42
41
|
};
|
|
43
|
-
exports.
|
|
44
|
-
const getPromotionsByIds = async function getPromotionsByIds2(ids, context) {
|
|
42
|
+
const getPromotionsByIds = exports.getPromotionsByIds = async function getPromotionsByIds2(ids, context) {
|
|
45
43
|
const {
|
|
46
44
|
bapiClient,
|
|
47
45
|
cached
|
|
@@ -49,5 +47,4 @@ const getPromotionsByIds = async function getPromotionsByIds2(ids, context) {
|
|
|
49
47
|
return await cached(bapiClient.promotions.getByIds, {
|
|
50
48
|
cacheKeyPrefix: "getByIds-promotions"
|
|
51
49
|
})(ids);
|
|
52
|
-
};
|
|
53
|
-
exports.getPromotionsByIds = getPromotionsByIds;
|
|
50
|
+
};
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.searchProducts = void 0;
|
|
7
7
|
var _constants = require("../../constants/index.cjs");
|
|
8
8
|
var _stringHelpers = require("../../helpers/stringHelpers.cjs");
|
|
9
|
-
const searchProducts = async function searchProducts2({
|
|
9
|
+
const searchProducts = exports.searchProducts = async function searchProducts2({
|
|
10
10
|
term,
|
|
11
11
|
slug,
|
|
12
12
|
with: _with,
|
|
@@ -25,7 +25,6 @@ const searchProducts = async function searchProducts2({
|
|
|
25
25
|
with: _with ?? withParams?.search ?? _constants.MIN_WITH_PARAMS_SEARCH
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
|
-
exports.searchProducts = searchProducts;
|
|
29
28
|
const getCategoryId = async (cached, bapiClient, slug) => {
|
|
30
29
|
if (!slug) {
|
|
31
30
|
return;
|