@scayle/storefront-core 7.41.2 → 7.42.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,17 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 7.42.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add `getCategoryByPath` RPC method
8
+
9
+ ## 7.41.3
10
+
11
+ ### Patch Changes
12
+
13
+ - Fix lost session if user refresh is called while not logged in
14
+
3
15
  ## 7.41.2
4
16
 
5
17
  ### Patch Changes
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getRootCategories = exports.getCategoryById = exports.getCategoriesByPath = void 0;
6
+ exports.getRootCategories = exports.getCategoryByPath = exports.getCategoryById = exports.getCategoriesByPath = void 0;
7
7
  var _helpers = require("../../helpers/index.cjs");
8
8
  const getRootCategories = exports.getRootCategories = async function getRootCategories2({
9
9
  children = 1,
@@ -25,6 +25,25 @@ const getRootCategories = exports.getRootCategories = async function getRootCate
25
25
  activeNode: void 0
26
26
  };
27
27
  };
28
+ const getCategoryByPath = exports.getCategoryByPath = async function getCategoryByPath2({
29
+ path,
30
+ children = 1,
31
+ includeHidden
32
+ }, context) {
33
+ const {
34
+ cached,
35
+ bapiClient
36
+ } = context;
37
+ const sanitizedPath = (0, _helpers.splitAndRemoveEmpty)(path);
38
+ return await cached(bapiClient.categories.getByPath, {
39
+ cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
40
+ })(sanitizedPath, {
41
+ with: {
42
+ children
43
+ },
44
+ includeHidden
45
+ });
46
+ };
28
47
  const getCategoriesByPath = exports.getCategoriesByPath = async function getCategoriesByPath2({
29
48
  path,
30
49
  children = 1,
@@ -6,6 +6,11 @@ export declare const getRootCategories: RpcHandler<{
6
6
  categories: Category[];
7
7
  activeNode: undefined;
8
8
  }>;
9
+ export declare const getCategoryByPath: RpcHandler<{
10
+ path: string;
11
+ children?: number;
12
+ includeHidden?: true;
13
+ }, Category | undefined>;
9
14
  export declare const getCategoriesByPath: RpcHandler<{
10
15
  path: string;
11
16
  children?: number;
@@ -11,6 +11,13 @@ export const getRootCategories = async function getRootCategories2({ children =
11
11
  activeNode: void 0
12
12
  };
13
13
  };
14
+ export const getCategoryByPath = async function getCategoryByPath2({ path, children = 1, includeHidden }, context) {
15
+ const { cached, bapiClient } = context;
16
+ const sanitizedPath = splitAndRemoveEmpty(path);
17
+ return await cached(bapiClient.categories.getByPath, {
18
+ cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
19
+ })(sanitizedPath, { with: { children }, includeHidden });
20
+ };
14
21
  export const getCategoriesByPath = async function getCategoriesByPath2({ path, children = 1, includeHidden }, context) {
15
22
  const { cached, bapiClient } = context;
16
23
  if (path === "/") {
@@ -33,24 +33,33 @@ const refreshUser = exports.refreshUser = async function refreshUser2(context) {
33
33
  (0, _types.assertSession)(context);
34
34
  const {
35
35
  accessToken,
36
- shopId
36
+ shopId,
37
+ user
37
38
  } = context;
39
+ if (!accessToken) {
40
+ return {
41
+ user: void 0
42
+ };
43
+ }
44
+ const isLoggedIn = !!user;
38
45
  const client = new _customer.CustomerAPIClient(context);
39
46
  try {
40
- const user = await client.getMe(shopId);
41
- if (!user.authentication) {
42
- user.authentication = {
47
+ const user2 = await client.getMe(shopId);
48
+ if (!user2.authentication) {
49
+ user2.authentication = {
43
50
  type: "idp"
44
51
  };
45
52
  }
46
- user.authentication.storefrontAccessToken = accessToken;
47
- user.loginShopId = shopId;
48
- context.updateUser(user);
53
+ user2.authentication.storefrontAccessToken = accessToken;
54
+ user2.loginShopId = shopId;
55
+ context.updateUser(user2);
49
56
  return {
50
- user
57
+ user: user2
51
58
  };
52
59
  } catch {
53
- await context.destroySession();
60
+ if (isLoggedIn) {
61
+ await context.destroySession();
62
+ }
54
63
  return {
55
64
  user: void 0
56
65
  };
@@ -21,21 +21,27 @@ const fetchUser = async function fetchUser2(payload, context) {
21
21
  };
22
22
  const refreshUser = async function refreshUser2(context) {
23
23
  assertSession(context);
24
- const { accessToken, shopId } = context;
24
+ const { accessToken, shopId, user } = context;
25
+ if (!accessToken) {
26
+ return { user: void 0 };
27
+ }
28
+ const isLoggedIn = !!user;
25
29
  const client = new CustomerAPIClient(context);
26
30
  try {
27
- const user = await client.getMe(shopId);
28
- if (!user.authentication) {
29
- user.authentication = {
31
+ const user2 = await client.getMe(shopId);
32
+ if (!user2.authentication) {
33
+ user2.authentication = {
30
34
  type: "idp"
31
35
  };
32
36
  }
33
- user.authentication.storefrontAccessToken = accessToken;
34
- user.loginShopId = shopId;
35
- context.updateUser(user);
36
- return { user };
37
+ user2.authentication.storefrontAccessToken = accessToken;
38
+ user2.loginShopId = shopId;
39
+ context.updateUser(user2);
40
+ return { user: user2 };
37
41
  } catch {
38
- await context.destroySession();
42
+ if (isLoggedIn) {
43
+ await context.destroySession();
44
+ }
39
45
  return { user: void 0 };
40
46
  }
41
47
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "7.41.2",
3
+ "version": "7.42.0",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -73,7 +73,7 @@
73
73
  "@types/crypto-js": "4.2.2",
74
74
  "@types/node": "20.11.19",
75
75
  "@types/webpack-env": "1.18.4",
76
- "@vitest/coverage-v8": "1.2.2",
76
+ "@vitest/coverage-v8": "1.3.0",
77
77
  "dprint": "0.45.0",
78
78
  "eslint": "8.56.0",
79
79
  "eslint-formatter-gitlab": "5.1.0",
@@ -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.2.2"
86
+ "vitest": "1.3.0"
87
87
  },
88
88
  "optionalDependencies": {
89
89
  "redis": "4"