@scayle/storefront-core 8.54.0 → 8.56.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 CHANGED
@@ -1,5 +1,34 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 8.56.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added support for custom session data in the RPC context type definitions.
8
+
9
+ The `ContextWithSession` interface now includes a `sessionCustomData` property (which may be `undefined`) to read custom session data and an `updateSessionCustomData` method to update it.
10
+ The `ContextWithoutSession` interface has been updated accordingly to maintain type consistency.
11
+ The `SessionCustomData` interface can be augmented using TypeScript module augmentation to provide type safety for custom session properties.
12
+
13
+ ### Patch Changes
14
+
15
+ **Dependencies**
16
+
17
+ - Updated dependency to @scayle/storefront-api@18.19.0
18
+ - Updated dependency to @scayle/unstorage-scayle-kv-driver@2.0.9
19
+
20
+ ## 8.55.0
21
+
22
+ ### Minor Changes
23
+
24
+ - Updated the type of the `removeItemFromBasket` RPC to accurately reflect that error responses can be returned if removing an item from the basket fails (these error responses were already being returned before; only the type was updated). Additionally, the `clearBasket` RPC now removes items sequentially to avoid conflicts between basket updates and returns an error response if any items in the basket could not be removed.
25
+
26
+ ### Patch Changes
27
+
28
+ **Dependencies**
29
+
30
+ - Updated dependency to @scayle/storefront-api@18.19.0
31
+
3
32
  ## 8.54.0
4
33
 
5
34
  ### Minor Changes
@@ -86,12 +86,12 @@ export declare const removeItemFromBasket: RpcHandler<{
86
86
  basket: BasketResponseData<Product, Variant>;
87
87
  }>;
88
88
  /**
89
- * Clears the basket, removing all items.
89
+ * Clears the basket, by removing all items sequentially.
90
90
  *
91
91
  * @param context The RPC context.
92
92
  *
93
93
  * @returns True if the basket was cleared successfully. It will return
94
- * an `ErrorResponse` alternatively iIf an error occurs during basket clearing.
94
+ * an `ErrorResponse` alternatively if an error occurs during basket clearing.
95
95
  */
96
96
  export declare const clearBasket: RpcHandler<boolean>;
97
97
  /**
@@ -213,7 +213,7 @@ export const removeItemFromBasket = defineRpcHandler(async (options, context) =>
213
213
  const campaignKey = await context.callRpc?.("getCampaignKey");
214
214
  const _orderCustomData = await context.callRpc?.("getOrderCustomData");
215
215
  const resolvedWith = getWithParams(options, context);
216
- const basket = await sapiClient.basket.deleteItem(
216
+ const response = await sapiClient.basket.deleteItem(
217
217
  basketKey,
218
218
  options.itemKey,
219
219
  {
@@ -227,7 +227,14 @@ export const removeItemFromBasket = defineRpcHandler(async (options, context) =>
227
227
  customerToken: getValidatedAccessToken(context.accessToken) ?? void 0
228
228
  }
229
229
  );
230
- return { basket };
230
+ if ("code" in response) {
231
+ return new ErrorResponse(
232
+ response.code,
233
+ SAPI_ERROR_NAME,
234
+ response.message
235
+ );
236
+ }
237
+ return { basket: response };
231
238
  });
232
239
  export const clearBasket = defineRpcHandler(
233
240
  async (context) => {
@@ -236,12 +243,15 @@ export const clearBasket = defineRpcHandler(
236
243
  return getBasketResponse;
237
244
  }
238
245
  const { basket } = await unwrap(getBasketResponse);
239
- await Promise.all(
240
- basket.items.map(async (item) => {
241
- await removeItemFromBasket({ itemKey: item.key }, context);
242
- })
243
- );
244
- context.log.debug("The basket has been cleared");
246
+ for (const item of basket.items) {
247
+ const response = await removeItemFromBasket(
248
+ { itemKey: item.key },
249
+ context
250
+ );
251
+ if (response instanceof ErrorResponse) {
252
+ return response;
253
+ }
254
+ }
245
255
  return true;
246
256
  }
247
257
  );
@@ -40,7 +40,7 @@ export const getCheckoutToken = defineRpcHandler(async (jwtPayload = {}, context
40
40
  ...customData,
41
41
  ...orderCustomData
42
42
  }
43
- }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.54.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
43
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.56.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
44
44
  return {
45
45
  accessToken: refreshedAccessToken,
46
46
  checkoutJwt
@@ -27,7 +27,7 @@ export interface RuntimeConfiguration {
27
27
  }
28
28
  /**
29
29
  * Additional context information for RPC calls.
30
- * AThis interface can be augmented to extend the `RpcContext` type and
30
+ * This interface can be augmented to extend the `RpcContext` type and
31
31
  * allows to adding custom properties to the RPC context.
32
32
  *
33
33
  * @example
@@ -42,6 +42,22 @@ export interface RuntimeConfiguration {
42
42
  */
43
43
  export interface AdditionalRpcContext {
44
44
  }
45
+ /**
46
+ * Interface for custom session data.
47
+ * This interface can be augmented to extend the `RpcContextWithSession` type and
48
+ * allows to adding custom data properties to the session on the RPC context.
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * declare module '@scayle/storefront-core' {
53
+ * interface SessionCustomData {
54
+ * myCustomData: string
55
+ * }
56
+ * }
57
+ * ```
58
+ */
59
+ export interface SessionCustomData {
60
+ }
45
61
  /**
46
62
  * Context interface with session information.
47
63
  */
@@ -52,8 +68,10 @@ export interface ContextWithSession {
52
68
  user: ShopUser | undefined;
53
69
  accessToken: string | undefined;
54
70
  refreshToken: string | undefined;
71
+ sessionCustomData: SessionCustomData | undefined;
55
72
  destroySession: () => Promise<void>;
56
73
  createUserBoundSession: () => Promise<void>;
74
+ updateSessionCustomData: (updatedCustomData: SessionCustomData) => Promise<void>;
57
75
  updateUser: (user: ShopUser) => void;
58
76
  updateTokens: (tokens: OAuthTokens) => void;
59
77
  }
@@ -67,9 +85,11 @@ export interface ContextWithoutSession {
67
85
  user: undefined;
68
86
  accessToken: undefined;
69
87
  refreshToken: undefined;
88
+ sessionCustomData: undefined;
70
89
  destroySession: undefined;
71
90
  createUserBoundSession: undefined;
72
91
  updateUser: undefined;
92
+ updateSessionCustomData: undefined;
73
93
  updateTokens: undefined;
74
94
  }
75
95
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "8.54.0",
3
+ "version": "8.56.0",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -48,16 +48,16 @@
48
48
  "ufo": "^1.5.3",
49
49
  "uncrypto": "^0.1.3",
50
50
  "utility-types": "^3.11.0",
51
- "@scayle/unstorage-scayle-kv-driver": "2.0.9",
52
- "@scayle/storefront-api": "18.18.1"
51
+ "@scayle/storefront-api": "18.19.0",
52
+ "@scayle/unstorage-scayle-kv-driver": "2.0.9"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/crypto-js": "4.2.2",
56
56
  "@types/node": "22.19.1",
57
57
  "@types/webpack-env": "1.18.8",
58
- "@vitest/coverage-v8": "4.0.14",
58
+ "@vitest/coverage-v8": "4.0.15",
59
59
  "dprint": "0.50.2",
60
- "eslint-formatter-gitlab": "6.0.1",
60
+ "eslint-formatter-gitlab": "7.0.0",
61
61
  "eslint": "9.39.1",
62
62
  "fishery": "2.3.1",
63
63
  "publint": "0.3.15",
@@ -65,9 +65,9 @@
65
65
  "typescript": "5.9.3",
66
66
  "unbuild": "3.6.1",
67
67
  "unstorage": "1.17.3",
68
- "vitest": "4.0.14",
69
- "@scayle/vitest-config-storefront": "1.0.0",
70
- "@scayle/eslint-config-storefront": "4.7.15"
68
+ "vitest": "4.0.15",
69
+ "@scayle/eslint-config-storefront": "4.7.16",
70
+ "@scayle/vitest-config-storefront": "1.0.0"
71
71
  },
72
72
  "volta": {
73
73
  "node": "22.21.1"