@scayle/storefront-core 8.37.0 → 8.38.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,12 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 8.38.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Refined the `ContextWithoutSession` type to accurately represent actual data: `wishlistKey`, `basketKey`, and `sessionId` are now typed as `string` instead of `undefined`, since even logged-out users have these values set.
8
+ - Made `getCheckoutToken` callable by logged-in and not logged-in users. When called by a not logged-in user, the RPC returns only the `checkoutJWT`. For logged-in users, it continues to return both the `checkoutJWT` and a refreshed `accessToken` as before.
9
+
3
10
  ## 8.37.0
4
11
 
5
12
  ### Minor Changes
@@ -49,7 +49,7 @@ interface CheckoutJwtPayload {
49
49
  * It will return an `ErrorResponse` if no session is found, no access token is present.
50
50
  */
51
51
  export declare const getCheckoutToken: RpcHandler<CheckoutJwtPayload | undefined, {
52
- accessToken: string;
52
+ accessToken: string | undefined;
53
53
  checkoutJwt: string;
54
54
  }>;
55
55
  export {};
@@ -12,19 +12,15 @@ export const getCheckoutToken = defineRpcHandler(async (jwtPayload = {}, context
12
12
  "No Session found"
13
13
  );
14
14
  }
15
- if (!context.accessToken) {
16
- return new ErrorResponse(
17
- HttpStatusCode.UNAUTHORIZED,
18
- HttpStatusMessage.UNAUTHORIZED,
19
- "No access token present"
15
+ let refreshedAccessToken;
16
+ if (context.accessToken) {
17
+ refreshedAccessToken = await getAccessToken(
18
+ { forceTokenRefresh: true },
19
+ context
20
20
  );
21
- }
22
- const refreshedAccessToken = await getAccessToken(
23
- { forceTokenRefresh: true },
24
- context
25
- );
26
- if (refreshedAccessToken instanceof Response) {
27
- return refreshedAccessToken;
21
+ if (refreshedAccessToken instanceof Response) {
22
+ return refreshedAccessToken;
23
+ }
28
24
  }
29
25
  const secret = new TextEncoder().encode(context.checkout.secret);
30
26
  const now = /* @__PURE__ */ new Date();
@@ -37,7 +33,7 @@ export const getCheckoutToken = defineRpcHandler(async (jwtPayload = {}, context
37
33
  carrier,
38
34
  basketId: context.basketKey,
39
35
  campaignKey
40
- }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.37.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
36
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.38.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
41
37
  return {
42
38
  accessToken: refreshedAccessToken,
43
39
  checkoutJwt
@@ -61,9 +61,9 @@ export interface ContextWithSession {
61
61
  * Context interface without session information.
62
62
  */
63
63
  export interface ContextWithoutSession {
64
- wishlistKey: undefined;
65
- basketKey: undefined;
66
- sessionId: undefined;
64
+ wishlistKey: string;
65
+ basketKey: string;
66
+ sessionId: string;
67
67
  user: undefined;
68
68
  accessToken: undefined;
69
69
  refreshToken: undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "8.37.0",
3
+ "version": "8.38.0",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -74,7 +74,7 @@
74
74
  "unbuild": "3.5.0",
75
75
  "unstorage": "1.16.0",
76
76
  "vitest": "3.2.4",
77
- "@scayle/eslint-config-storefront": "4.6.1"
77
+ "@scayle/eslint-config-storefront": "4.7.0"
78
78
  },
79
79
  "volta": {
80
80
  "node": "22.17.1"