@scayle/storefront-core 8.2.1 → 8.3.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 +14 -0
- package/dist/rpc/methods/basket/basket.cjs +40 -1
- package/dist/rpc/methods/basket/basket.d.ts +29 -1
- package/dist/rpc/methods/basket/basket.mjs +39 -0
- package/dist/rpc/methods/checkout/checkout.cjs +1 -1
- package/dist/rpc/methods/checkout/checkout.mjs +1 -1
- package/dist/rpc/methods/search.d.ts +1 -1
- package/dist/utils/user.d.ts +3 -3
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @scayle/storefront-core
|
|
2
2
|
|
|
3
|
+
## 8.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [Basket] Add support to update existing basket items using the `updateBasketItem` RPC.
|
|
8
|
+
|
|
9
|
+
## 8.2.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
**Dependencies**
|
|
14
|
+
|
|
15
|
+
- Updated dependency to @scayle/storefront-api@17.17.0
|
|
16
|
+
|
|
3
17
|
## 8.2.1
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.removeItemFromBasket = exports.mergeBaskets = exports.getBasket = exports.clearBasket = exports.addItemsToBasket = exports.addItemToBasket = void 0;
|
|
6
|
+
exports.updateBasketItem = exports.removeItemFromBasket = exports.mergeBaskets = exports.getBasket = exports.clearBasket = exports.addItemsToBasket = exports.addItemToBasket = void 0;
|
|
7
7
|
var _errors = require("../../../errors/index.cjs");
|
|
8
8
|
var _types = require("../../../types/index.cjs");
|
|
9
9
|
var _constants = require("../../../constants/index.cjs");
|
|
@@ -215,6 +215,45 @@ const mergeBaskets = exports.mergeBaskets = async function mergeBaskets2({
|
|
|
215
215
|
orderCustomData
|
|
216
216
|
}, context);
|
|
217
217
|
};
|
|
218
|
+
const updateBasketItem = exports.updateBasketItem = async function updateBasketItem2({
|
|
219
|
+
basketItemKey,
|
|
220
|
+
update,
|
|
221
|
+
with: _with
|
|
222
|
+
}, context) {
|
|
223
|
+
if (!(0, _types.hasSession)(context)) {
|
|
224
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
225
|
+
}
|
|
226
|
+
const {
|
|
227
|
+
basketKey,
|
|
228
|
+
sapiClient
|
|
229
|
+
} = context;
|
|
230
|
+
const resolvedWith = getWithParams({
|
|
231
|
+
with: _with
|
|
232
|
+
}, context);
|
|
233
|
+
const {
|
|
234
|
+
quantity,
|
|
235
|
+
...updateParams
|
|
236
|
+
} = update;
|
|
237
|
+
const result = await sapiClient.basket.updateItem(basketKey, basketItemKey, quantity, {
|
|
238
|
+
...updateParams,
|
|
239
|
+
with: resolvedWith
|
|
240
|
+
});
|
|
241
|
+
if (result.type === "success") {
|
|
242
|
+
return {
|
|
243
|
+
basket: result.basket
|
|
244
|
+
};
|
|
245
|
+
} else {
|
|
246
|
+
context.log.error("Updating basket item failed", {
|
|
247
|
+
kind: result.kind,
|
|
248
|
+
basketKey,
|
|
249
|
+
basketItemKey,
|
|
250
|
+
update
|
|
251
|
+
});
|
|
252
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, SAPI_ERROR_NAME, "Updating basket item failed", {
|
|
253
|
+
failureKind: result.kind
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
};
|
|
218
257
|
function parseBasketError(response) {
|
|
219
258
|
const parsedError = {
|
|
220
259
|
message: "",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AddOrUpdateItemError } from '@scayle/storefront-api';
|
|
1
|
+
import type { AddOrUpdateItemError, UpdateBasketItemQuantity } from '@scayle/storefront-api';
|
|
2
2
|
import { ErrorResponse } from '../../../errors';
|
|
3
3
|
import type { AddOrUpdateItemType, BasketResponseData, BasketWithOptions, Product, RpcContext, Variant } from '../../../types';
|
|
4
4
|
import { ExistingItemHandling } from '../../../constants';
|
|
@@ -55,3 +55,31 @@ export declare const mergeBaskets: ({ fromBasketKey, toBasketKey, with: _with, o
|
|
|
55
55
|
readonly basket: BasketResponseData<Product, Variant>;
|
|
56
56
|
readonly errors: AddOrUpdateItemError[];
|
|
57
57
|
} | undefined>;
|
|
58
|
+
/**
|
|
59
|
+
* An object containing properties of a basket item than should be applied to the basket item during the update.
|
|
60
|
+
*/
|
|
61
|
+
export type BasketItemUpdateData = Partial<Omit<UpdateBasketItemQuantity, 'basketKey' | 'itemKey' | 'with' | 'quantity'>> & {
|
|
62
|
+
quantity: number;
|
|
63
|
+
};
|
|
64
|
+
export interface UpdateBasketItemRequestParameter {
|
|
65
|
+
/** key of the item to be updated. */
|
|
66
|
+
basketItemKey: string;
|
|
67
|
+
/** The update data that should be applied to the basket item- */
|
|
68
|
+
update: BasketItemUpdateData;
|
|
69
|
+
/** An object describing which data the returned basket should contain. */
|
|
70
|
+
with?: BasketWithOptions;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Applies the provided update data to a specific item in a basket.
|
|
74
|
+
*
|
|
75
|
+
* @param params - The request parameters.
|
|
76
|
+
* @param params.basketItemKey - The key of the item to be updated.
|
|
77
|
+
* @param params.update - The update data that should be applied to the basket item.
|
|
78
|
+
* @param params.with - An object describing which data the returned basket should contain.
|
|
79
|
+
* @param context - The rpc context associated with the request.
|
|
80
|
+
*
|
|
81
|
+
* @returns A promise that resolves with the updated basket. In case of an error the, the failure kind will be resolved.
|
|
82
|
+
*/
|
|
83
|
+
export declare const updateBasketItem: ({ basketItemKey, update, with: _with }: UpdateBasketItemRequestParameter, context: RpcContext) => Promise<ErrorResponse | {
|
|
84
|
+
basket: BasketResponseData<Product, Variant>;
|
|
85
|
+
}>;
|
|
@@ -223,6 +223,45 @@ export const mergeBaskets = async function mergeBaskets2({ fromBasketKey, toBask
|
|
|
223
223
|
context
|
|
224
224
|
);
|
|
225
225
|
};
|
|
226
|
+
export const updateBasketItem = async function updateBasketItem2({ basketItemKey, update, with: _with }, context) {
|
|
227
|
+
if (!hasSession(context)) {
|
|
228
|
+
return new ErrorResponse(
|
|
229
|
+
HttpStatusCode.BAD_REQUEST,
|
|
230
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
231
|
+
"No Session found"
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
const { basketKey, sapiClient } = context;
|
|
235
|
+
const resolvedWith = getWithParams(
|
|
236
|
+
{ with: _with },
|
|
237
|
+
context
|
|
238
|
+
);
|
|
239
|
+
const { quantity, ...updateParams } = update;
|
|
240
|
+
const result = await sapiClient.basket.updateItem(
|
|
241
|
+
basketKey,
|
|
242
|
+
basketItemKey,
|
|
243
|
+
quantity,
|
|
244
|
+
{ ...updateParams, with: resolvedWith }
|
|
245
|
+
);
|
|
246
|
+
if (result.type === "success") {
|
|
247
|
+
return { basket: result.basket };
|
|
248
|
+
} else {
|
|
249
|
+
context.log.error("Updating basket item failed", {
|
|
250
|
+
kind: result.kind,
|
|
251
|
+
basketKey,
|
|
252
|
+
basketItemKey,
|
|
253
|
+
update
|
|
254
|
+
});
|
|
255
|
+
return new ErrorResponse(
|
|
256
|
+
HttpStatusCode.BAD_REQUEST,
|
|
257
|
+
SAPI_ERROR_NAME,
|
|
258
|
+
"Updating basket item failed",
|
|
259
|
+
{
|
|
260
|
+
failureKind: result.kind
|
|
261
|
+
}
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
226
265
|
function parseBasketError(response) {
|
|
227
266
|
const parsedError = {
|
|
228
267
|
message: "",
|
|
@@ -37,7 +37,7 @@ const getCheckoutToken = exports.getCheckoutToken = async function getCheckoutTo
|
|
|
37
37
|
carrier,
|
|
38
38
|
basketId: context.basketKey,
|
|
39
39
|
campaignKey: context.campaignKey
|
|
40
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.
|
|
40
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.3.0"}`).setProtectedHeader({
|
|
41
41
|
alg: "HS256",
|
|
42
42
|
typ: "JWT"
|
|
43
43
|
}).sign(secret);
|
|
@@ -35,7 +35,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
|
|
|
35
35
|
carrier,
|
|
36
36
|
basketId: context.basketKey,
|
|
37
37
|
campaignKey: context.campaignKey
|
|
38
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.
|
|
38
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.3.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
|
|
39
39
|
return {
|
|
40
40
|
accessToken: refreshedAccessToken,
|
|
41
41
|
checkoutJwt
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { SearchV2ResolveEndpointParameters, SearchV2SuggestionsEndpointParameters, SearchV2SuggestionsEndpointResponseData } from '../../types/sapi/search';
|
|
2
2
|
export declare const getSearchSuggestions: ({ term, with: _with, categoryId }: SearchV2SuggestionsEndpointParameters, { sapiClient, withParams }: import("../../types").RpcContext) => Promise<Response | SearchV2SuggestionsEndpointResponseData>;
|
|
3
|
-
export declare const resolveSearch: ({ term, with: _with, categoryId }: SearchV2ResolveEndpointParameters, { cached, sapiClient, withParams }: import("../../types").RpcContext) => Promise<import("@scayle/storefront-api/dist/shared/storefront-api.
|
|
3
|
+
export declare const resolveSearch: ({ term, with: _with, categoryId }: SearchV2ResolveEndpointParameters, { cached, sapiClient, withParams }: import("../../types").RpcContext) => Promise<import("@scayle/storefront-api/dist/shared/storefront-api.DUu2u41G").S | null>;
|
package/dist/utils/user.d.ts
CHANGED
|
@@ -4,13 +4,13 @@ export declare const mergeBaskets: (fromBasketKey: string, toBasketKey: string,
|
|
|
4
4
|
}, context: RpcContext) => Promise<{
|
|
5
5
|
type: "failure";
|
|
6
6
|
statusCode: number;
|
|
7
|
-
basket: import("@scayle/storefront-api/dist/shared/storefront-api.
|
|
7
|
+
basket: import("@scayle/storefront-api/dist/shared/storefront-api.DUu2u41G").f<import("@scayle/storefront-api/dist/shared/storefront-api.DUu2u41G").a, import("@scayle/storefront-api/dist/shared/storefront-api.DUu2u41G").V>;
|
|
8
8
|
} | {
|
|
9
9
|
readonly type: "success";
|
|
10
|
-
readonly basket: import("@scayle/storefront-api/dist/shared/storefront-api.
|
|
10
|
+
readonly basket: import("@scayle/storefront-api/dist/shared/storefront-api.DUu2u41G").f<import("@scayle/storefront-api/dist/shared/storefront-api.DUu2u41G").a, import("@scayle/storefront-api/dist/shared/storefront-api.DUu2u41G").V>;
|
|
11
11
|
} | {
|
|
12
12
|
readonly type: "failure";
|
|
13
|
-
readonly basket: import("@scayle/storefront-api/dist/shared/storefront-api.
|
|
13
|
+
readonly basket: import("@scayle/storefront-api/dist/shared/storefront-api.DUu2u41G").f<import("@scayle/storefront-api/dist/shared/storefront-api.DUu2u41G").a, import("@scayle/storefront-api/dist/shared/storefront-api.DUu2u41G").V>;
|
|
14
14
|
readonly errors: import("@scayle/storefront-api").AddOrUpdateItemError[];
|
|
15
15
|
} | undefined>;
|
|
16
16
|
export declare const mergeWishlists: (fromWishlistKey: string, toWishlistKey: string, withOptions: BasketWithOptions, context: RpcContext) => Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-core",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.3.0",
|
|
4
4
|
"description": "Collection of essential utilities to work with the Storefront API",
|
|
5
5
|
"author": "SCAYLE Commerce Engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"test:ci": "vitest --run --passWithNoTests --coverage --reporter=default --reporter=junit --outputFile=./coverage/junit.xml"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@scayle/storefront-api": "17.
|
|
74
|
+
"@scayle/storefront-api": "17.17.0",
|
|
75
75
|
"crypto-js": "^4.2.0",
|
|
76
76
|
"hookable": "^5.5.3",
|
|
77
77
|
"jose": "^5.6.3",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@scayle/eslint-config-storefront": "4.4.1",
|
|
85
85
|
"@types/crypto-js": "4.2.2",
|
|
86
|
-
"@types/node": "22.10.
|
|
86
|
+
"@types/node": "22.10.9",
|
|
87
87
|
"@types/webpack-env": "1.18.5",
|
|
88
88
|
"@vitest/coverage-v8": "2.1.8",
|
|
89
89
|
"dprint": "0.48.0",
|