@scayle/storefront-core 7.42.1 → 7.44.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,18 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 7.44.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Expose the `loginWithIDP` function from the `useSession` composable.
8
+ - Changes the signature of `handleIDPLoginCallback` to receive an object with the code inside instead of just the code for improved logging behavior.
9
+
10
+ ## 7.43.0
11
+
12
+ ### Minor Changes
13
+
14
+ - Add `createAndPurifyHeaders` sanitization helper
15
+
3
16
  ## 7.42.1
4
17
 
5
18
  ### Patch Changes
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.stripShopLocaleFromPath = exports.purifySensitiveData = void 0;
6
+ exports.stripShopLocaleFromPath = exports.purifySensitiveData = exports.createAndPurifyHeaders = void 0;
7
7
  var _radash = require("radash");
8
8
  const SANITIZATION_MASK = "********";
9
9
  const stripShopLocaleFromPath = (locale, path, splitter = "/") => path.split(splitter).filter(segment => segment.toLowerCase() !== locale.toLowerCase()).join("/");
@@ -19,4 +19,9 @@ const purifySensitiveData = (data = {}, blacklistedKeys = ["password"]) => {
19
19
  return purifiedPayload;
20
20
  }, {});
21
21
  };
22
- exports.purifySensitiveData = purifySensitiveData;
22
+ exports.purifySensitiveData = purifySensitiveData;
23
+ const createAndPurifyHeaders = headers => {
24
+ const sanitizedHeaders = (0, _radash.shake)(headers);
25
+ return new Headers(sanitizedHeaders);
26
+ };
27
+ exports.createAndPurifyHeaders = createAndPurifyHeaders;
@@ -1,2 +1,3 @@
1
1
  export declare const stripShopLocaleFromPath: (locale: string, path: string, splitter?: string) => string;
2
2
  export declare const purifySensitiveData: (data?: Record<string, any>, blacklistedKeys?: string[]) => Record<string, any>;
3
+ export declare const createAndPurifyHeaders: (headers: Partial<Record<string, string | undefined>>) => Headers;
@@ -1,4 +1,4 @@
1
- import { isObject } from "radash";
1
+ import { isObject, shake } from "radash";
2
2
  const SANITIZATION_MASK = "********";
3
3
  export const stripShopLocaleFromPath = (locale, path, splitter = "/") => path.split(splitter).filter((segment) => segment.toLowerCase() !== locale.toLowerCase()).join("/");
4
4
  export const purifySensitiveData = (data = {}, blacklistedKeys = ["password"]) => {
@@ -17,3 +17,7 @@ export const purifySensitiveData = (data = {}, blacklistedKeys = ["password"]) =
17
17
  {}
18
18
  );
19
19
  };
20
+ export const createAndPurifyHeaders = (headers) => {
21
+ const sanitizedHeaders = shake(headers);
22
+ return new Headers(sanitizedHeaders);
23
+ };
@@ -7,12 +7,13 @@ exports.handleIDPLoginCallback = exports.getExternalIdpRedirect = void 0;
7
7
  var _jose = require("jose");
8
8
  var _types = require("../../../types/index.cjs");
9
9
  var _oauth = require("../../../api/oauth.cjs");
10
+ var _user = require("../user.cjs");
10
11
  const getExternalIdpRedirect = exports.getExternalIdpRedirect = async function getExternalIdpRedirect2(context) {
11
12
  const shopId = context.shopId.toString();
12
13
  const OAuthClient = (0, _oauth.getOAuthClient)(context);
13
14
  const checkoutSecret = context.checkout.secret;
14
15
  if (!context.idp?.enabled) {
15
- throw new Error("IDP disabled");
16
+ return {};
16
17
  }
17
18
  const IDPKeys = context.idp.idpKeys;
18
19
  const IDPRedirectURL = context.idp.idpRedirectURL;
@@ -39,7 +40,9 @@ const getExternalIdpRedirect = exports.getExternalIdpRedirect = async function g
39
40
  }));
40
41
  return Object.fromEntries(results);
41
42
  };
42
- const handleIDPLoginCallback = exports.handleIDPLoginCallback = async function handleIDPLoginCallback2(code, context) {
43
+ const handleIDPLoginCallback = exports.handleIDPLoginCallback = async function handleIDPLoginCallback2({
44
+ code
45
+ }, context) {
43
46
  (0, _types.assertSession)(context);
44
47
  const OAuthClient = (0, _oauth.getOAuthClient)(context);
45
48
  const {
@@ -50,6 +53,7 @@ const handleIDPLoginCallback = exports.handleIDPLoginCallback = async function h
50
53
  accessToken,
51
54
  refreshToken
52
55
  });
56
+ await (0, _user.refreshUser)(context);
53
57
  return {
54
58
  message: "success"
55
59
  };
@@ -2,6 +2,8 @@ import type { RpcContext } from '../../../types';
2
2
  export declare const getExternalIdpRedirect: (context: RpcContext) => Promise<{
3
3
  [k: string]: string;
4
4
  }>;
5
- export declare const handleIDPLoginCallback: (code: string, context: RpcContext) => Promise<{
5
+ export declare const handleIDPLoginCallback: ({ code }: {
6
+ code: string;
7
+ }, context: RpcContext) => Promise<{
6
8
  message: string;
7
9
  }>;
@@ -1,12 +1,13 @@
1
1
  import { SignJWT } from "jose";
2
2
  import { assertSession } from "../../../types/index.mjs";
3
3
  import { getOAuthClient } from "../../../api/oauth.mjs";
4
+ import { refreshUser } from "../user.mjs";
4
5
  export const getExternalIdpRedirect = async function getExternalIdpRedirect2(context) {
5
6
  const shopId = context.shopId.toString();
6
7
  const OAuthClient = getOAuthClient(context);
7
8
  const checkoutSecret = context.checkout.secret;
8
9
  if (!context.idp?.enabled) {
9
- throw new Error("IDP disabled");
10
+ return {};
10
11
  }
11
12
  const IDPKeys = context.idp.idpKeys;
12
13
  const IDPRedirectURL = context.idp.idpRedirectURL;
@@ -35,7 +36,7 @@ export const getExternalIdpRedirect = async function getExternalIdpRedirect2(con
35
36
  );
36
37
  return Object.fromEntries(results);
37
38
  };
38
- export const handleIDPLoginCallback = async function handleIDPLoginCallback2(code, context) {
39
+ export const handleIDPLoginCallback = async function handleIDPLoginCallback2({ code }, context) {
39
40
  assertSession(context);
40
41
  const OAuthClient = getOAuthClient(context);
41
42
  const { access_token: accessToken, refresh_token: refreshToken } = await OAuthClient.generateToken(code);
@@ -43,6 +44,7 @@ export const handleIDPLoginCallback = async function handleIDPLoginCallback2(cod
43
44
  accessToken,
44
45
  refreshToken
45
46
  });
47
+ await refreshUser(context);
46
48
  return {
47
49
  message: "success"
48
50
  };
@@ -76,6 +76,7 @@ export type RpcContext = {
76
76
  };
77
77
  runtimeConfiguration: RuntimeConfiguration;
78
78
  idp?: IDPConfig;
79
+ headers: Headers;
79
80
  } & (ContextNoSession | ContextWithSession);
80
81
  export type RpcContextWithSession = RpcContext & {
81
82
  sessionId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "7.42.1",
3
+ "version": "7.44.0",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -62,7 +62,7 @@
62
62
  "@aboutyou/backbone": "16.1.2",
63
63
  "crypto-js": "4.2.0",
64
64
  "jose": "5.2.2",
65
- "radash": "11.0.0",
65
+ "radash": "12.0.0",
66
66
  "slugify": "1.6.6",
67
67
  "ufo": "1.4.0",
68
68
  "uncrypto": "0.1.3",
@@ -71,11 +71,11 @@
71
71
  "devDependencies": {
72
72
  "@scayle/eslint-config-storefront": "3.2.6",
73
73
  "@types/crypto-js": "4.2.2",
74
- "@types/node": "20.11.19",
74
+ "@types/node": "20.11.24",
75
75
  "@types/webpack-env": "1.18.4",
76
- "@vitest/coverage-v8": "1.3.0",
76
+ "@vitest/coverage-v8": "1.3.1",
77
77
  "dprint": "0.45.0",
78
- "eslint": "8.56.0",
78
+ "eslint": "8.57.0",
79
79
  "eslint-formatter-gitlab": "5.1.0",
80
80
  "publint": "0.2.7",
81
81
  "rimraf": "5.0.5",
@@ -83,7 +83,7 @@
83
83
  "typescript": "5.3.3",
84
84
  "unbuild": "2.0.0",
85
85
  "unstorage": "1.10.1",
86
- "vitest": "1.3.0"
86
+ "vitest": "1.3.1"
87
87
  },
88
88
  "optionalDependencies": {
89
89
  "redis": "4"