@scayle/storefront-core 8.61.0 → 8.61.2
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-V7.md +1 -11
- package/CHANGELOG.md +100 -103
- package/dist/api/customer.mjs +1 -3
- package/dist/api/oauth.mjs +9 -6
- package/dist/cache/providers/unstorage.mjs +1 -3
- package/dist/constants/withParameters.mjs +2 -16
- package/dist/helpers/attributeHelpers.mjs +3 -1
- package/dist/helpers/filterHelper.mjs +11 -8
- package/dist/helpers/productHelpers.mjs +1 -3
- package/dist/helpers/sanitizationHelpers.mjs +1 -4
- package/dist/helpers/sortingHelper.mjs +1 -3
- package/dist/rpc/methods/basket/basket.d.ts +2 -2
- package/dist/rpc/methods/basket/basket.mjs +334 -321
- package/dist/rpc/methods/brands.mjs +26 -20
- package/dist/rpc/methods/campaign.mjs +32 -23
- package/dist/rpc/methods/categories.mjs +156 -135
- package/dist/rpc/methods/cbd.mjs +52 -49
- package/dist/rpc/methods/checkout/checkout.mjs +42 -39
- package/dist/rpc/methods/checkout/order.mjs +46 -40
- package/dist/rpc/methods/checkout/shopUser.mjs +112 -106
- package/dist/rpc/methods/navigationTrees.mjs +50 -32
- package/dist/rpc/methods/oauth/idp.mjs +64 -55
- package/dist/rpc/methods/products.mjs +224 -212
- package/dist/rpc/methods/promotion.mjs +46 -31
- package/dist/rpc/methods/search.mjs +26 -20
- package/dist/rpc/methods/session.mjs +289 -260
- package/dist/rpc/methods/shopConfiguration.mjs +12 -9
- package/dist/rpc/methods/user.mjs +87 -78
- package/dist/rpc/methods/variants.mjs +17 -14
- package/dist/rpc/methods/wishlist.mjs +71 -62
- package/dist/utils/hash.mjs +2 -7
- package/dist/utils/sapi.mjs +10 -7
- package/package.json +4 -4
|
@@ -21,221 +21,232 @@ const SAPI_ERROR_NAME = "SAPI ERROR";
|
|
|
21
21
|
function getWithParams(params, context) {
|
|
22
22
|
return params.with ?? context.withParams?.basket ?? MIN_WITH_PARAMS_BASKET;
|
|
23
23
|
}
|
|
24
|
-
export const addItemToBasket = defineRpcHandler(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
24
|
+
export const addItemToBasket = defineRpcHandler(
|
|
25
|
+
async ({
|
|
26
|
+
variantId,
|
|
27
|
+
promotionId,
|
|
28
|
+
promotions,
|
|
29
|
+
quantity,
|
|
30
|
+
displayData,
|
|
31
|
+
customData,
|
|
32
|
+
existingItemHandling = ExistingItemHandling.ADD_QUANTITY_TO_EXISTING,
|
|
33
|
+
itemGroup,
|
|
34
|
+
with: _with,
|
|
35
|
+
orderCustomData
|
|
36
|
+
}, context) => {
|
|
37
|
+
if (!hasSession(context)) {
|
|
38
|
+
return new ErrorResponse(
|
|
39
|
+
HttpStatusCode.BAD_REQUEST,
|
|
40
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
41
|
+
"No Session found"
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
const { sapiClient, basketKey } = context;
|
|
45
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
46
|
+
const _orderCustomData = await context.callRpc?.("getOrderCustomData");
|
|
47
|
+
const resolvedWith = getWithParams(
|
|
48
|
+
{ with: _with },
|
|
49
|
+
context
|
|
41
50
|
);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
campaignKey,
|
|
60
|
-
displayData,
|
|
61
|
-
pricePromotionKey: resolvedWith?.pricePromotionKey || "",
|
|
62
|
-
customData,
|
|
63
|
-
itemGroup,
|
|
64
|
-
with: resolvedWith,
|
|
65
|
-
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData
|
|
51
|
+
const result = await sapiClient.basket.addOrUpdateItems(
|
|
52
|
+
basketKey,
|
|
53
|
+
[
|
|
54
|
+
{
|
|
55
|
+
variantId,
|
|
56
|
+
quantity,
|
|
57
|
+
params: {
|
|
58
|
+
promotionId: promotionId ?? void 0,
|
|
59
|
+
promotions: promotions ?? void 0,
|
|
60
|
+
campaignKey,
|
|
61
|
+
displayData,
|
|
62
|
+
pricePromotionKey: resolvedWith?.pricePromotionKey || "",
|
|
63
|
+
customData,
|
|
64
|
+
itemGroup,
|
|
65
|
+
with: resolvedWith,
|
|
66
|
+
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData
|
|
67
|
+
}
|
|
66
68
|
}
|
|
67
|
-
|
|
68
|
-
],
|
|
69
|
-
{
|
|
70
|
-
skipAvailabilityCheck: false,
|
|
71
|
-
orderCustomData: mergeOrderCustomData(_orderCustomData, orderCustomData),
|
|
72
|
-
customerToken: getValidatedAccessToken(context.accessToken) ?? void 0
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
existingItemHandling
|
|
76
|
-
}
|
|
77
|
-
);
|
|
78
|
-
if (result.type === "success") {
|
|
79
|
-
return { basket: result.basket };
|
|
80
|
-
} else if (result.type === "failure" && wasAddedWithReducedQuantity(result.errors)) {
|
|
81
|
-
return {
|
|
82
|
-
basket: result.basket,
|
|
83
|
-
errors: result.errors
|
|
84
|
-
};
|
|
85
|
-
} else {
|
|
86
|
-
const { message, statusCode } = parseBasketError(result);
|
|
87
|
-
context.log.error("Adding item to basket failed", { message, statusCode });
|
|
88
|
-
return new ErrorResponse(
|
|
89
|
-
HttpStatusCode.BAD_REQUEST,
|
|
90
|
-
SAPI_ERROR_NAME,
|
|
91
|
-
"Adding item to basket failed",
|
|
69
|
+
],
|
|
92
70
|
{
|
|
93
|
-
|
|
94
|
-
|
|
71
|
+
skipAvailabilityCheck: false,
|
|
72
|
+
orderCustomData: mergeOrderCustomData(
|
|
73
|
+
_orderCustomData,
|
|
74
|
+
orderCustomData
|
|
75
|
+
),
|
|
76
|
+
customerToken: getValidatedAccessToken(context.accessToken) ?? void 0
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
existingItemHandling
|
|
95
80
|
}
|
|
96
81
|
);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
promotions: item.promotions ?? void 0,
|
|
117
|
-
campaignKey,
|
|
118
|
-
displayData: item.displayData,
|
|
119
|
-
pricePromotionKey: resolvedWith?.pricePromotionKey || "",
|
|
120
|
-
customData: item.customData,
|
|
121
|
-
with: resolvedWith,
|
|
122
|
-
includeItemsWithoutProductData: item.includeItemsWithoutProductData ?? resolvedWith?.includeItemsWithoutProductData,
|
|
123
|
-
itemGroup: item.itemGroup ?? void 0
|
|
82
|
+
if (result.type === "success") {
|
|
83
|
+
return { basket: result.basket };
|
|
84
|
+
} else if (result.type === "failure" && wasAddedWithReducedQuantity(result.errors)) {
|
|
85
|
+
return {
|
|
86
|
+
basket: result.basket,
|
|
87
|
+
errors: result.errors
|
|
88
|
+
};
|
|
89
|
+
} else {
|
|
90
|
+
const { message, statusCode } = parseBasketError(result);
|
|
91
|
+
context.log.error("Adding item to basket failed", { message, statusCode });
|
|
92
|
+
return new ErrorResponse(
|
|
93
|
+
HttpStatusCode.BAD_REQUEST,
|
|
94
|
+
SAPI_ERROR_NAME,
|
|
95
|
+
"Adding item to basket failed",
|
|
96
|
+
{
|
|
97
|
+
detail: message,
|
|
98
|
+
errors: result.errors
|
|
99
|
+
}
|
|
100
|
+
);
|
|
124
101
|
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
)
|
|
136
|
-
customerToken: getValidatedAccessToken(context.accessToken) ?? void 0
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
existingItemHandling: params.existingItemHandling || ExistingItemHandling.ADD_QUANTITY_TO_EXISTING
|
|
102
|
+
},
|
|
103
|
+
{ method: "PUT" }
|
|
104
|
+
);
|
|
105
|
+
export const addItemsToBasket = defineRpcHandler(
|
|
106
|
+
async (params, context) => {
|
|
107
|
+
if (!hasSession(context)) {
|
|
108
|
+
return new ErrorResponse(
|
|
109
|
+
HttpStatusCode.BAD_REQUEST,
|
|
110
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
111
|
+
"No Session found"
|
|
112
|
+
);
|
|
140
113
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
"Adding one or more items to basket failed",
|
|
159
|
-
{
|
|
160
|
-
detail: message,
|
|
161
|
-
errors: result.errors
|
|
114
|
+
const { sapiClient, basketKey } = context;
|
|
115
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
116
|
+
const _orderCustomData = await context.callRpc?.("getOrderCustomData");
|
|
117
|
+
const resolvedWith = getWithParams(params, context);
|
|
118
|
+
const itemsToBeAddedOrUpdated = params.items.map((item) => ({
|
|
119
|
+
variantId: item.variantId,
|
|
120
|
+
quantity: item.quantity,
|
|
121
|
+
params: {
|
|
122
|
+
promotionId: item.promotionId ?? void 0,
|
|
123
|
+
promotions: item.promotions ?? void 0,
|
|
124
|
+
campaignKey,
|
|
125
|
+
displayData: item.displayData,
|
|
126
|
+
pricePromotionKey: resolvedWith?.pricePromotionKey || "",
|
|
127
|
+
customData: item.customData,
|
|
128
|
+
with: resolvedWith,
|
|
129
|
+
includeItemsWithoutProductData: item.includeItemsWithoutProductData ?? resolvedWith?.includeItemsWithoutProductData,
|
|
130
|
+
itemGroup: item.itemGroup ?? void 0
|
|
162
131
|
}
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const _orderCustomData = await context.callRpc?.("getOrderCustomData");
|
|
177
|
-
const resolvedWith = getWithParams(
|
|
178
|
-
{ with: options },
|
|
179
|
-
context
|
|
180
|
-
);
|
|
181
|
-
const response = await sapiClient.basket.get(basketKey, {
|
|
182
|
-
with: resolvedWith,
|
|
183
|
-
campaignKey,
|
|
184
|
-
includeItemsWithoutProductData: resolvedWith.includeItemsWithoutProductData,
|
|
185
|
-
orderCustomData: mergeOrderCustomData(
|
|
186
|
-
_orderCustomData,
|
|
187
|
-
options?.orderCustomData
|
|
188
|
-
),
|
|
189
|
-
customerToken: getValidatedAccessToken(context.accessToken) ?? void 0
|
|
190
|
-
});
|
|
191
|
-
if (response.type === "failure") {
|
|
192
|
-
const { statusCode, message } = parseBasketError(response);
|
|
193
|
-
return new ErrorResponse(
|
|
194
|
-
statusCode,
|
|
195
|
-
SAPI_ERROR_NAME,
|
|
196
|
-
"Adding item to basket failed",
|
|
132
|
+
}));
|
|
133
|
+
const result = await sapiClient.basket.addOrUpdateItems(
|
|
134
|
+
basketKey,
|
|
135
|
+
itemsToBeAddedOrUpdated,
|
|
136
|
+
{
|
|
137
|
+
skipAvailabilityCheck: false,
|
|
138
|
+
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData,
|
|
139
|
+
orderCustomData: mergeOrderCustomData(
|
|
140
|
+
_orderCustomData,
|
|
141
|
+
params.orderCustomData
|
|
142
|
+
),
|
|
143
|
+
customerToken: getValidatedAccessToken(context.accessToken) ?? void 0
|
|
144
|
+
},
|
|
197
145
|
{
|
|
198
|
-
|
|
146
|
+
existingItemHandling: params.existingItemHandling || ExistingItemHandling.ADD_QUANTITY_TO_EXISTING
|
|
199
147
|
}
|
|
200
148
|
);
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
149
|
+
if (result.type === "success") {
|
|
150
|
+
return { basket: result.basket };
|
|
151
|
+
} else if (result.type === "failure" && wasAddedWithReducedQuantity(result.errors)) {
|
|
152
|
+
return {
|
|
153
|
+
basket: result.basket,
|
|
154
|
+
errors: result.errors
|
|
155
|
+
};
|
|
156
|
+
} else {
|
|
157
|
+
const { statusCode, message } = parseBasketError(result);
|
|
158
|
+
context.log.error("Adding one or more items to basket failed", {
|
|
159
|
+
statusCode,
|
|
160
|
+
message
|
|
161
|
+
});
|
|
162
|
+
return new ErrorResponse(
|
|
163
|
+
HttpStatusCode.BAD_REQUEST,
|
|
164
|
+
SAPI_ERROR_NAME,
|
|
165
|
+
"Adding one or more items to basket failed",
|
|
166
|
+
{
|
|
167
|
+
detail: message,
|
|
168
|
+
errors: result.errors
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
{ method: "PUT" }
|
|
174
|
+
);
|
|
175
|
+
export const getBasket = defineRpcHandler(
|
|
176
|
+
async (options, context) => {
|
|
177
|
+
if (!hasSession(context)) {
|
|
178
|
+
return new ErrorResponse(
|
|
179
|
+
HttpStatusCode.BAD_REQUEST,
|
|
180
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
181
|
+
"No Session found"
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
const { sapiClient, basketKey } = context;
|
|
185
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
186
|
+
const _orderCustomData = await context.callRpc?.("getOrderCustomData");
|
|
187
|
+
const resolvedWith = getWithParams(
|
|
188
|
+
{ with: options },
|
|
189
|
+
context
|
|
210
190
|
);
|
|
211
|
-
|
|
212
|
-
const { sapiClient, basketKey } = context;
|
|
213
|
-
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
214
|
-
const _orderCustomData = await context.callRpc?.("getOrderCustomData");
|
|
215
|
-
const resolvedWith = getWithParams(options, context);
|
|
216
|
-
const response = await sapiClient.basket.deleteItem(
|
|
217
|
-
basketKey,
|
|
218
|
-
options.itemKey,
|
|
219
|
-
{
|
|
191
|
+
const response = await sapiClient.basket.get(basketKey, {
|
|
220
192
|
with: resolvedWith,
|
|
221
193
|
campaignKey,
|
|
222
|
-
includeItemsWithoutProductData: resolvedWith
|
|
194
|
+
includeItemsWithoutProductData: resolvedWith.includeItemsWithoutProductData,
|
|
223
195
|
orderCustomData: mergeOrderCustomData(
|
|
224
196
|
_orderCustomData,
|
|
225
|
-
options
|
|
197
|
+
options?.orderCustomData
|
|
226
198
|
),
|
|
227
199
|
customerToken: getValidatedAccessToken(context.accessToken) ?? void 0
|
|
200
|
+
});
|
|
201
|
+
if (response.type === "failure") {
|
|
202
|
+
const { statusCode, message } = parseBasketError(response);
|
|
203
|
+
return new ErrorResponse(
|
|
204
|
+
statusCode,
|
|
205
|
+
SAPI_ERROR_NAME,
|
|
206
|
+
"Adding item to basket failed",
|
|
207
|
+
{
|
|
208
|
+
detail: message
|
|
209
|
+
}
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
return { basket: response.basket };
|
|
213
|
+
},
|
|
214
|
+
{ method: "POST" }
|
|
215
|
+
);
|
|
216
|
+
export const removeItemFromBasket = defineRpcHandler(
|
|
217
|
+
async (options, context) => {
|
|
218
|
+
if (!hasSession(context)) {
|
|
219
|
+
return new ErrorResponse(
|
|
220
|
+
HttpStatusCode.BAD_REQUEST,
|
|
221
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
222
|
+
"No Session found"
|
|
223
|
+
);
|
|
228
224
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
225
|
+
const { sapiClient, basketKey } = context;
|
|
226
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
227
|
+
const _orderCustomData = await context.callRpc?.("getOrderCustomData");
|
|
228
|
+
const resolvedWith = getWithParams(options, context);
|
|
229
|
+
const response = await sapiClient.basket.deleteItem(
|
|
230
|
+
basketKey,
|
|
231
|
+
options.itemKey,
|
|
232
|
+
{
|
|
233
|
+
with: resolvedWith,
|
|
234
|
+
campaignKey,
|
|
235
|
+
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData,
|
|
236
|
+
orderCustomData: mergeOrderCustomData(
|
|
237
|
+
_orderCustomData,
|
|
238
|
+
options.orderCustomData
|
|
239
|
+
),
|
|
240
|
+
customerToken: getValidatedAccessToken(context.accessToken) ?? void 0
|
|
241
|
+
}
|
|
235
242
|
);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
243
|
+
if ("code" in response) {
|
|
244
|
+
return new ErrorResponse(response.code, SAPI_ERROR_NAME, response.message);
|
|
245
|
+
}
|
|
246
|
+
return { basket: response };
|
|
247
|
+
},
|
|
248
|
+
{ method: "DELETE" }
|
|
249
|
+
);
|
|
239
250
|
export const clearBasket = defineRpcHandler(
|
|
240
251
|
async (context) => {
|
|
241
252
|
const getBasketResponse = await getBasket({}, context);
|
|
@@ -256,150 +267,152 @@ export const clearBasket = defineRpcHandler(
|
|
|
256
267
|
},
|
|
257
268
|
{ method: "DELETE" }
|
|
258
269
|
);
|
|
259
|
-
export const mergeBaskets = defineRpcHandler(
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const _orderCustomData = await context.callRpc?.("getOrderCustomData");
|
|
265
|
-
return await mergeBasketFunction(
|
|
266
|
-
fromBasketKey,
|
|
267
|
-
toBasketKey,
|
|
268
|
-
{
|
|
269
|
-
...resolvedWith,
|
|
270
|
-
orderCustomData: mergeOrderCustomData(_orderCustomData, orderCustomData)
|
|
271
|
-
},
|
|
272
|
-
context
|
|
273
|
-
);
|
|
274
|
-
}, { method: "POST" });
|
|
275
|
-
export const updateBasketItem = defineRpcHandler(async ({ basketItemKey, update, with: _with, orderCustomData }, context) => {
|
|
276
|
-
if (!hasSession(context)) {
|
|
277
|
-
return new ErrorResponse(
|
|
278
|
-
HttpStatusCode.BAD_REQUEST,
|
|
279
|
-
HttpStatusMessage.BAD_REQUEST,
|
|
280
|
-
"No Session found"
|
|
270
|
+
export const mergeBaskets = defineRpcHandler(
|
|
271
|
+
async ({ fromBasketKey, toBasketKey, with: _with, orderCustomData }, context) => {
|
|
272
|
+
const resolvedWith = getWithParams(
|
|
273
|
+
{ with: _with },
|
|
274
|
+
context
|
|
281
275
|
);
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
276
|
+
const _orderCustomData = await context.callRpc?.("getOrderCustomData");
|
|
277
|
+
return await mergeBasketFunction(
|
|
278
|
+
fromBasketKey,
|
|
279
|
+
toBasketKey,
|
|
280
|
+
{
|
|
281
|
+
...resolvedWith,
|
|
282
|
+
orderCustomData: mergeOrderCustomData(
|
|
283
|
+
_orderCustomData,
|
|
284
|
+
orderCustomData
|
|
285
|
+
)
|
|
286
|
+
},
|
|
287
|
+
context
|
|
288
|
+
);
|
|
289
|
+
},
|
|
290
|
+
{ method: "POST" }
|
|
291
|
+
);
|
|
292
|
+
export const updateBasketItem = defineRpcHandler(
|
|
293
|
+
async ({ basketItemKey, update, with: _with, orderCustomData }, context) => {
|
|
294
|
+
if (!hasSession(context)) {
|
|
295
|
+
return new ErrorResponse(
|
|
296
|
+
HttpStatusCode.BAD_REQUEST,
|
|
297
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
298
|
+
"No Session found"
|
|
299
|
+
);
|
|
301
300
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
context.
|
|
307
|
-
|
|
301
|
+
const { basketKey, sapiClient } = context;
|
|
302
|
+
const resolvedWith = getWithParams({ with: _with }, context);
|
|
303
|
+
const { quantity, ...updateParams } = update;
|
|
304
|
+
const campaignKey = update.campaignKey ?? await context.callRpc?.("getCampaignKey");
|
|
305
|
+
const _orderCustomData = await context.callRpc?.("getOrderCustomData");
|
|
306
|
+
const result = await sapiClient.basket.updateItem(
|
|
308
307
|
basketKey,
|
|
309
308
|
basketItemKey,
|
|
310
|
-
|
|
311
|
-
});
|
|
312
|
-
return new ErrorResponse(
|
|
313
|
-
HttpStatusCode.BAD_REQUEST,
|
|
314
|
-
SAPI_ERROR_NAME,
|
|
315
|
-
"Updating basket item failed",
|
|
309
|
+
quantity,
|
|
316
310
|
{
|
|
317
|
-
|
|
311
|
+
...updateParams,
|
|
312
|
+
campaignKey,
|
|
313
|
+
with: resolvedWith,
|
|
314
|
+
orderCustomData: mergeOrderCustomData(
|
|
315
|
+
_orderCustomData,
|
|
316
|
+
orderCustomData
|
|
317
|
+
),
|
|
318
|
+
customerToken: getValidatedAccessToken(context.accessToken) ?? void 0
|
|
318
319
|
}
|
|
319
320
|
);
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
321
|
+
if (result.type === "success") {
|
|
322
|
+
return { basket: result.basket };
|
|
323
|
+
} else {
|
|
324
|
+
context.log.error("Updating basket item failed", {
|
|
325
|
+
kind: result.kind,
|
|
326
|
+
basketKey,
|
|
327
|
+
basketItemKey,
|
|
328
|
+
update
|
|
329
|
+
});
|
|
330
|
+
return new ErrorResponse(
|
|
331
|
+
HttpStatusCode.BAD_REQUEST,
|
|
332
|
+
SAPI_ERROR_NAME,
|
|
333
|
+
"Updating basket item failed",
|
|
334
|
+
{
|
|
335
|
+
failureKind: result.kind
|
|
336
|
+
}
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
{ method: "PUT" }
|
|
341
|
+
);
|
|
342
|
+
export const getApplicablePromotionsByCode = defineRpcHandler(
|
|
343
|
+
async ({ promotionCode, with: _with }, context) => {
|
|
344
|
+
if (!hasSession(context)) {
|
|
345
|
+
return new ErrorResponse(
|
|
346
|
+
HttpStatusCode.BAD_REQUEST,
|
|
347
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
348
|
+
"No Session found"
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
const { basketKey, sapiClient } = context;
|
|
352
|
+
const resolvedWith = getWithParams({ with: _with }, context);
|
|
353
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
354
|
+
const orderCustomData = await context.callRpc?.("getOrderCustomData");
|
|
355
|
+
const result = await mapSAPIFetchErrorToResponse(
|
|
356
|
+
sapiClient.basket.getApplicablePromotionsByCode
|
|
357
|
+
)(basketKey, promotionCode, {
|
|
343
358
|
campaignKey,
|
|
344
359
|
with: resolvedWith,
|
|
345
360
|
orderCustomData,
|
|
346
361
|
customerToken: getValidatedAccessToken(context.accessToken) ?? void 0
|
|
347
|
-
}
|
|
348
|
-
);
|
|
349
|
-
if (result instanceof Response || result.type === "failure") {
|
|
350
|
-
context.log.info("Getting applicable promotion codes failed", {
|
|
351
|
-
basketKey,
|
|
352
|
-
promotionCode
|
|
353
362
|
});
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
sapiClient
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
{
|
|
363
|
+
if (result instanceof Response || result.type === "failure") {
|
|
364
|
+
context.log.info("Getting applicable promotion codes failed", {
|
|
365
|
+
basketKey,
|
|
366
|
+
promotionCode
|
|
367
|
+
});
|
|
368
|
+
return new ErrorResponse(
|
|
369
|
+
HttpStatusCode.BAD_REQUEST,
|
|
370
|
+
SAPI_ERROR_NAME,
|
|
371
|
+
"Getting applicable promotion codes failed"
|
|
372
|
+
);
|
|
373
|
+
} else {
|
|
374
|
+
return { basket: result.basket };
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
{ method: "POST" }
|
|
378
|
+
);
|
|
379
|
+
export const updatePromotions = defineRpcHandler(
|
|
380
|
+
async (params, context) => {
|
|
381
|
+
if (!hasSession(context)) {
|
|
382
|
+
return new ErrorResponse(
|
|
383
|
+
HttpStatusCode.BAD_REQUEST,
|
|
384
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
385
|
+
"No Session found"
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
const { basketKey, sapiClient } = context;
|
|
389
|
+
const campaignKey = params.campaignKey ?? await context.callRpc?.("getCampaignKey");
|
|
390
|
+
const orderCustomData = await context.callRpc?.("getOrderCustomData");
|
|
391
|
+
const resolvedWith = getWithParams({ with: params.with }, context);
|
|
392
|
+
const result = await mapSAPIFetchErrorToResponse(
|
|
393
|
+
sapiClient.basket.bulkUpdatePromotions
|
|
394
|
+
)(basketKey, {
|
|
383
395
|
...params,
|
|
384
396
|
campaignKey,
|
|
385
397
|
with: resolvedWith,
|
|
386
398
|
orderCustomData,
|
|
387
399
|
customerToken: getValidatedAccessToken(context.accessToken) ?? void 0
|
|
388
|
-
}
|
|
389
|
-
);
|
|
390
|
-
if (result instanceof Response || result.type === "failure") {
|
|
391
|
-
context.log.info("Bulk updating promotions failed", {
|
|
392
|
-
basketKey,
|
|
393
|
-
items: params.items
|
|
394
400
|
});
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
401
|
+
if (result instanceof Response || result.type === "failure") {
|
|
402
|
+
context.log.info("Bulk updating promotions failed", {
|
|
403
|
+
basketKey,
|
|
404
|
+
items: params.items
|
|
405
|
+
});
|
|
406
|
+
return new ErrorResponse(
|
|
407
|
+
HttpStatusCode.BAD_REQUEST,
|
|
408
|
+
SAPI_ERROR_NAME,
|
|
409
|
+
"Bulk updating promotions failed"
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
return { basket: result.basket };
|
|
413
|
+
},
|
|
414
|
+
{ method: "PUT" }
|
|
415
|
+
);
|
|
403
416
|
function parseBasketError(response) {
|
|
404
417
|
const parsedError = {
|
|
405
418
|
message: "",
|