@scayle/storefront-core 7.51.1 → 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 +6 -0
- package/dist/rpc/methods/checkout/checkout.cjs +35 -0
- package/dist/rpc/methods/checkout/checkout.d.ts +15 -0
- package/dist/rpc/methods/checkout/checkout.mjs +21 -0
- package/dist/rpc/methods/checkout/index.cjs +11 -0
- package/dist/rpc/methods/checkout/index.d.ts +1 -0
- package/dist/rpc/methods/checkout/index.mjs +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -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
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-core",
|
|
3
|
-
"version": "7.
|
|
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",
|
|
@@ -75,7 +75,7 @@
|
|
|
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.
|
|
78
|
+
"eslint": "9.3.0",
|
|
79
79
|
"eslint-formatter-gitlab": "5.1.0",
|
|
80
80
|
"publint": "0.2.8",
|
|
81
81
|
"rimraf": "5.0.7",
|