@scayle/storefront-core 7.51.0 → 7.52.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,19 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 7.52.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add `getCheckoutToken` RPC, which provides access token and checkout JWT needed by the checkout web component.
8
+
9
+ ## 7.51.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Update ShopConfiguration types
14
+ - Updated dependencies
15
+ - @scayle/storefront-api@17.1.0
16
+
3
17
  ## 7.51.0
4
18
 
5
19
  ### Minor Changes
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getCheckoutToken = void 0;
7
+ var _jose = require("jose");
8
+ const getCheckoutToken = exports.getCheckoutToken = async function getCheckoutToken2(jwtPayload, context) {
9
+ if (!context.accessToken) {
10
+ throw new Error("No access token present");
11
+ }
12
+ const secret = new TextEncoder().encode(context.checkout.secret);
13
+ const now = /* @__PURE__ */new Date();
14
+ const {
15
+ voucher,
16
+ customData,
17
+ preferredCollectionPoint,
18
+ carrier
19
+ } = jwtPayload || {};
20
+ const checkoutJwt = await new _jose.SignJWT({
21
+ voucher,
22
+ customData,
23
+ preferredCollectionPoint,
24
+ carrier,
25
+ basketId: context.basketKey,
26
+ campaignKey: context.campaignKey
27
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.51.1"}`).setProtectedHeader({
28
+ alg: "HS256",
29
+ typ: "JWT"
30
+ }).sign(secret);
31
+ return {
32
+ accessToken: context.accessToken,
33
+ checkoutJwt
34
+ };
35
+ };
@@ -0,0 +1,15 @@
1
+ import type { RpcContext } from '../../../types';
2
+ interface CheckoutJwtPayload {
3
+ voucher?: string;
4
+ customData?: Record<string, unknown>;
5
+ preferredCollectionPoint?: {
6
+ id: number;
7
+ type: string;
8
+ };
9
+ carrier?: string;
10
+ }
11
+ export declare const getCheckoutToken: (jwtPayload: CheckoutJwtPayload | undefined, context: RpcContext) => Promise<{
12
+ accessToken: string;
13
+ checkoutJwt: string;
14
+ }>;
15
+ export {};
@@ -0,0 +1,21 @@
1
+ import { SignJWT } from "jose";
2
+ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload, context) {
3
+ if (!context.accessToken) {
4
+ throw new Error("No access token present");
5
+ }
6
+ const secret = new TextEncoder().encode(context.checkout.secret);
7
+ const now = /* @__PURE__ */ new Date();
8
+ const { voucher, customData, preferredCollectionPoint, carrier } = jwtPayload || {};
9
+ const checkoutJwt = await new SignJWT({
10
+ voucher,
11
+ customData,
12
+ preferredCollectionPoint,
13
+ carrier,
14
+ basketId: context.basketKey,
15
+ campaignKey: context.campaignKey
16
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.51.1"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
17
+ return {
18
+ accessToken: context.accessToken,
19
+ checkoutJwt
20
+ };
21
+ };
@@ -35,4 +35,15 @@ Object.keys(_shopUser).forEach(function (key) {
35
35
  return _shopUser[key];
36
36
  }
37
37
  });
38
+ });
39
+ var _checkout = require("./checkout.cjs");
40
+ Object.keys(_checkout).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _checkout[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _checkout[key];
47
+ }
48
+ });
38
49
  });
@@ -1,3 +1,4 @@
1
1
  export * from './order';
2
2
  export * from './shopUserAddresses';
3
3
  export * from './shopUser';
4
+ export * from './checkout';
@@ -1,3 +1,4 @@
1
1
  export * from "./order.mjs";
2
2
  export * from "./shopUserAddresses.mjs";
3
3
  export * from "./shopUser.mjs";
4
+ export * from "./checkout.mjs";
@@ -1,4 +1,4 @@
1
- import type { ShopConfigurationResponseData } from '@scayle/storefront-api';
1
+ import type { ShopConfiguration } from '@scayle/storefront-api';
2
2
  import type { RpcContext } from '../../types';
3
- declare const getShopConfiguration: ({ cached, bapiClient }: RpcContext) => Promise<ShopConfigurationResponseData>;
3
+ declare const getShopConfiguration: ({ cached, bapiClient }: RpcContext) => Promise<ShopConfiguration>;
4
4
  export { getShopConfiguration };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "7.51.0",
3
+ "version": "7.52.0",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -59,7 +59,7 @@
59
59
  "test:ci": "vitest --run --passWithNoTests --coverage --reporter=default --reporter=junit"
60
60
  },
61
61
  "dependencies": {
62
- "@scayle/storefront-api": "17.0.1",
62
+ "@scayle/storefront-api": "17.1.0",
63
63
  "crypto-js": "4.2.0",
64
64
  "jose": "5.3.0",
65
65
  "radash": "12.1.0",
@@ -75,9 +75,9 @@
75
75
  "@types/webpack-env": "1.18.5",
76
76
  "@vitest/coverage-v8": "1.6.0",
77
77
  "dprint": "0.45.1",
78
- "eslint": "9.2.0",
78
+ "eslint": "9.3.0",
79
79
  "eslint-formatter-gitlab": "5.1.0",
80
- "publint": "0.2.7",
80
+ "publint": "0.2.8",
81
81
  "rimraf": "5.0.7",
82
82
  "ts-node": "10.9.2",
83
83
  "typescript": "5.4.5",