@scayle/storefront-core 7.58.3 → 7.59.1

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,20 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 7.59.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @scayle/storefront-api@17.4.0
9
+
10
+ ## 7.59.0
11
+
12
+ ### Minor Changes
13
+
14
+ - Add `storefront:afterLogin` and `storefront:afterLogout` hooks to the respective RPC.
15
+
16
+ Add `callHook`, `callHookParallel` and `callHookWith` types to `RpcContext`
17
+
3
18
  ## 7.58.3
4
19
 
5
20
  ### 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(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 && Object.prototype.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; }
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.2"}`).setProtectedHeader({
34
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.59.0"}`).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.2"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
24
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.59.0"}`).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 {};
@@ -14,7 +14,7 @@ interface MemberRole {
14
14
  memberPriority: number;
15
15
  memberRoleSap: string;
16
16
  }
17
- type AuthenticationType = 'password' | string;
17
+ export type AuthenticationType = 'password' | string;
18
18
  interface UserAuthentication {
19
19
  data?: {
20
20
  accessToken?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "7.58.3",
3
+ "version": "7.59.1",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -59,31 +59,32 @@
59
59
  "test:ci": "vitest --run --passWithNoTests --coverage --reporter=default --reporter=junit"
60
60
  },
61
61
  "dependencies": {
62
- "@scayle/storefront-api": "17.3.0",
63
- "crypto-js": "4.2.0",
64
- "jose": "5.5.0",
65
- "radash": "12.1.0",
66
- "slugify": "1.6.6",
67
- "ufo": "1.5.3",
68
- "uncrypto": "0.1.3",
69
- "utility-types": "3.11.0"
62
+ "@scayle/storefront-api": "17.4.0",
63
+ "crypto-js": "^4.2.0",
64
+ "hookable": "^5.5.3",
65
+ "jose": "^5.6.3",
66
+ "radash": "^12.1.0",
67
+ "slugify": "^1.6.6",
68
+ "ufo": "^1.5.3",
69
+ "uncrypto": "^0.1.3",
70
+ "utility-types": "^3.11.0"
70
71
  },
71
72
  "devDependencies": {
72
73
  "@scayle/eslint-config-storefront": "4.2.0",
73
74
  "@types/crypto-js": "4.2.2",
74
- "@types/node": "20.14.9",
75
+ "@types/node": "20.14.10",
75
76
  "@types/webpack-env": "1.18.5",
76
- "@vitest/coverage-v8": "1.6.0",
77
- "dprint": "0.46.3",
78
- "eslint": "9.5.0",
77
+ "@vitest/coverage-v8": "2.0.2",
78
+ "dprint": "0.47.2",
79
+ "eslint": "9.6.0",
79
80
  "eslint-formatter-gitlab": "5.1.0",
80
81
  "publint": "0.2.8",
81
- "rimraf": "5.0.7",
82
+ "rimraf": "6.0.1",
82
83
  "ts-node": "10.9.2",
83
- "typescript": "5.5.2",
84
+ "typescript": "5.5.3",
84
85
  "unbuild": "2.0.0",
85
86
  "unstorage": "1.10.2",
86
- "vitest": "1.6.0"
87
+ "vitest": "2.0.2"
87
88
  },
88
89
  "optionalDependencies": {
89
90
  "redis": "4"