@scayle/storefront-core 7.58.3 → 7.59.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 +8 -0
- package/dist/helpers/productHelpers.cjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/rpc/methods/checkout/checkout.cjs +1 -1
- package/dist/rpc/methods/checkout/checkout.mjs +1 -1
- package/dist/rpc/methods/session.cjs +12 -0
- package/dist/rpc/methods/session.mjs +12 -0
- package/dist/types/api/context.d.ts +21 -1
- package/dist/types/user.d.ts +1 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @scayle/storefront-core
|
|
2
2
|
|
|
3
|
+
## 7.59.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Add `storefront:afterLogin` and `storefront:afterLogout` hooks to the respective RPC.
|
|
8
|
+
|
|
9
|
+
Add `callHook`, `callHookParallel` and `callHookWith` types to `RpcContext`
|
|
10
|
+
|
|
3
11
|
## 7.58.3
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -11,7 +11,7 @@ var _product = require("../constants/product.cjs");
|
|
|
11
11
|
var _attributeHelpers = require("./attributeHelpers.cjs");
|
|
12
12
|
var _imageHelpers = require("./imageHelpers.cjs");
|
|
13
13
|
var _arrayHelpers = require("./arrayHelpers.cjs");
|
|
14
|
-
function _interopRequireDefault(
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
15
|
const slugify = url => {
|
|
16
16
|
return (0, _slugify.default)(url ?? "", {
|
|
17
17
|
lower: true,
|
package/dist/index.cjs
CHANGED
|
@@ -97,4 +97,4 @@ Object.keys(_types).forEach(function (key) {
|
|
|
97
97
|
});
|
|
98
98
|
var _storefrontApi = require("@scayle/storefront-api");
|
|
99
99
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
100
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u &&
|
|
100
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -31,7 +31,7 @@ const getCheckoutToken = exports.getCheckoutToken = async function getCheckoutTo
|
|
|
31
31
|
carrier,
|
|
32
32
|
basketId: context.basketKey,
|
|
33
33
|
campaignKey: context.campaignKey
|
|
34
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.58.
|
|
34
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.58.3"}`).setProtectedHeader({
|
|
35
35
|
alg: "HS256",
|
|
36
36
|
typ: "JWT"
|
|
37
37
|
}).sign(secret);
|
|
@@ -21,7 +21,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
|
|
|
21
21
|
carrier,
|
|
22
22
|
basketId: context.basketKey,
|
|
23
23
|
campaignKey: context.campaignKey
|
|
24
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.58.
|
|
24
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.58.3"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
|
|
25
25
|
return {
|
|
26
26
|
accessToken: refreshedAccessToken,
|
|
27
27
|
checkoutJwt
|
|
@@ -35,6 +35,12 @@ async function postLogin(context, tokens) {
|
|
|
35
35
|
} = (0, _jose.decodeJwt)(tokens.access_token);
|
|
36
36
|
await Promise.all([(0, _user.mergeBaskets)(context.sessionId, await context.generateBasketKeyForUserId(customerId), _constants.DEFAULT_WITH_LISTING, context), (0, _user.mergeWishlists)(context.sessionId, await context.generateWishlistKeyForUserId(customerId), _constants.DEFAULT_WITH_LISTING, context)]);
|
|
37
37
|
await context.createUserBoundSession();
|
|
38
|
+
await context.callHook?.("storefront:afterLogin", {
|
|
39
|
+
shopId: context.shopId,
|
|
40
|
+
user,
|
|
41
|
+
authenticationType: user.authentication?.type,
|
|
42
|
+
accessToken: tokens.access_token
|
|
43
|
+
}, context);
|
|
38
44
|
}
|
|
39
45
|
const oauthLogin = async (login, context) => {
|
|
40
46
|
(0, _types.assertSession)(context);
|
|
@@ -141,10 +147,16 @@ const oauthRevokeToken = async context => {
|
|
|
141
147
|
if (!accessToken) {
|
|
142
148
|
throw new Error("No app oauth authentication credentials");
|
|
143
149
|
}
|
|
150
|
+
const user = context.user;
|
|
144
151
|
const client = (0, _oauth.getOAuthClient)(context);
|
|
145
152
|
await context.destroySession();
|
|
146
153
|
try {
|
|
147
154
|
await client.revokeToken(context.shopId, accessToken);
|
|
155
|
+
await context.callHook?.("storefront:afterLogout", {
|
|
156
|
+
shopId: context.shopId,
|
|
157
|
+
user,
|
|
158
|
+
authenticationType: user.authentication?.type
|
|
159
|
+
}, context);
|
|
148
160
|
return {
|
|
149
161
|
result: true
|
|
150
162
|
};
|
|
@@ -36,6 +36,12 @@ export async function postLogin(context, tokens) {
|
|
|
36
36
|
)
|
|
37
37
|
]);
|
|
38
38
|
await context.createUserBoundSession();
|
|
39
|
+
await context.callHook?.("storefront:afterLogin", {
|
|
40
|
+
shopId: context.shopId,
|
|
41
|
+
user,
|
|
42
|
+
authenticationType: user.authentication?.type,
|
|
43
|
+
accessToken: tokens.access_token
|
|
44
|
+
}, context);
|
|
39
45
|
}
|
|
40
46
|
export const oauthLogin = async (login, context) => {
|
|
41
47
|
assertSession(context);
|
|
@@ -146,10 +152,16 @@ export const oauthRevokeToken = async (context) => {
|
|
|
146
152
|
if (!accessToken) {
|
|
147
153
|
throw new Error("No app oauth authentication credentials");
|
|
148
154
|
}
|
|
155
|
+
const user = context.user;
|
|
149
156
|
const client = getOAuthClient(context);
|
|
150
157
|
await context.destroySession();
|
|
151
158
|
try {
|
|
152
159
|
await client.revokeToken(context.shopId, accessToken);
|
|
160
|
+
await context.callHook?.("storefront:afterLogout", {
|
|
161
|
+
shopId: context.shopId,
|
|
162
|
+
user,
|
|
163
|
+
authenticationType: user.authentication?.type
|
|
164
|
+
}, context);
|
|
153
165
|
return { result: true };
|
|
154
166
|
} catch (error) {
|
|
155
167
|
const res = convertErrorForRpcCall(error, [
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { StorefrontAPIClient } from '@scayle/storefront-api';
|
|
2
|
+
import type { Hookable } from 'hookable';
|
|
2
3
|
import type { Log } from '../../utils';
|
|
3
4
|
import type { CachedType } from '../../cache/cached';
|
|
4
|
-
import type { ShopUser } from '../user';
|
|
5
|
+
import type { AuthenticationType, ShopUser } from '../user';
|
|
5
6
|
import type { BasketWithOptions, CategoryWith, ProductCategoryWith, ProductWith, SearchV2With, SearchWith, VariantWith, WishlistWithOptions } from '../';
|
|
6
7
|
import type { IDPConfig, OAuthTokens } from './auth';
|
|
7
8
|
export type WithParams = Partial<{
|
|
@@ -43,6 +44,21 @@ export interface ContextWithoutSession {
|
|
|
43
44
|
updateUser: undefined;
|
|
44
45
|
updateTokens: undefined;
|
|
45
46
|
}
|
|
47
|
+
interface LoginInformation {
|
|
48
|
+
shopId: number;
|
|
49
|
+
user: ShopUser;
|
|
50
|
+
authenticationType?: AuthenticationType;
|
|
51
|
+
accessToken: string;
|
|
52
|
+
}
|
|
53
|
+
interface LogoutInformation {
|
|
54
|
+
shopId: number;
|
|
55
|
+
user: ShopUser;
|
|
56
|
+
authenticationType?: AuthenticationType;
|
|
57
|
+
}
|
|
58
|
+
export interface StorefrontHooks {
|
|
59
|
+
'storefront:afterLogin': (loginInfo: LoginInformation, context: RpcContext) => Promise<void> | void;
|
|
60
|
+
'storefront:afterLogout': (logoutInfo: LogoutInformation, context: RpcContext) => Promise<void> | void;
|
|
61
|
+
}
|
|
46
62
|
export type RpcContext = {
|
|
47
63
|
locale: string;
|
|
48
64
|
checkout: {
|
|
@@ -84,6 +100,10 @@ export type RpcContext = {
|
|
|
84
100
|
runtimeConfiguration: RuntimeConfiguration;
|
|
85
101
|
idp?: IDPConfig;
|
|
86
102
|
headers: Headers;
|
|
103
|
+
callHook?: Hookable<StorefrontHooks>['callHook'];
|
|
104
|
+
callHookParallel?: Hookable<StorefrontHooks>['callHookParallel'];
|
|
105
|
+
callHookWith?: Hookable<StorefrontHooks>['callHookWith'];
|
|
87
106
|
} & AdditionalRpcContext & (ContextWithoutSession | ContextWithSession);
|
|
88
107
|
export type RpcContextWithSession = RpcContext & ContextWithSession;
|
|
89
108
|
export declare function assertSession(context: RpcContext): asserts context is RpcContextWithSession;
|
|
109
|
+
export {};
|
package/dist/types/user.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-core",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.59.0",
|
|
4
4
|
"description": "Collection of essential utilities to work with the Storefront API",
|
|
5
5
|
"author": "SCAYLE Commerce Engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -61,7 +61,8 @@
|
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@scayle/storefront-api": "17.3.0",
|
|
63
63
|
"crypto-js": "4.2.0",
|
|
64
|
-
"
|
|
64
|
+
"hookable": "5.5.3",
|
|
65
|
+
"jose": "5.6.2",
|
|
65
66
|
"radash": "12.1.0",
|
|
66
67
|
"slugify": "1.6.6",
|
|
67
68
|
"ufo": "1.5.3",
|
|
@@ -74,13 +75,13 @@
|
|
|
74
75
|
"@types/node": "20.14.9",
|
|
75
76
|
"@types/webpack-env": "1.18.5",
|
|
76
77
|
"@vitest/coverage-v8": "1.6.0",
|
|
77
|
-
"dprint": "0.
|
|
78
|
-
"eslint": "9.
|
|
78
|
+
"dprint": "0.47.0",
|
|
79
|
+
"eslint": "9.6.0",
|
|
79
80
|
"eslint-formatter-gitlab": "5.1.0",
|
|
80
81
|
"publint": "0.2.8",
|
|
81
82
|
"rimraf": "5.0.7",
|
|
82
83
|
"ts-node": "10.9.2",
|
|
83
|
-
"typescript": "5.5.
|
|
84
|
+
"typescript": "5.5.3",
|
|
84
85
|
"unbuild": "2.0.0",
|
|
85
86
|
"unstorage": "1.10.2",
|
|
86
87
|
"vitest": "1.6.0"
|