@scayle/storefront-core 7.55.0 → 7.57.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,21 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 7.57.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Expose `properties` with option for each category RPC method payload
8
+
9
+ ## 7.56.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Add refresh token logic to customer API client
14
+
15
+ ### Patch Changes
16
+
17
+ - Ensure `user.storefrontAccessToken` is up to date when calling the `getUser` RPC
18
+
3
19
  ## 7.55.0
4
20
 
5
21
  ### Minor Changes
@@ -0,0 +1,7 @@
1
+ # Storefront Core API Clients
2
+
3
+ ## Overview
4
+
5
+ This directory is the home of "mini" API clients. While some SCAYLE APIs provide a TypeScript SDK as an npm package (e.g. SAPI) others do not. When the API is simple enough, we may create a "mini" SDK within `storefront-core`. This way we can provide a TypeScript native abstraction over the API but not suffer the overhead of an additional package to maintain.
6
+
7
+ The SDKs created here should generally be a single file. The goal should be to make them as self-contained as possible, but it is ok if they need to pull a type or utility function from elsewhere in `storefront-core`.
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.CustomerAPIClient = void 0;
7
7
  var _fetch = require("../utils/fetch.cjs");
8
8
  var _httpStatus = require("../constants/httpStatus.cjs");
9
+ var _oauth = require("./oauth.cjs");
9
10
  class CustomerAPIClient {
10
11
  baseURL;
11
12
  context;
@@ -24,26 +25,39 @@ class CustomerAPIClient {
24
25
  } : {})
25
26
  };
26
27
  }
27
- async handleResponse(response) {
28
- if (!response.ok) {
29
- if (response.status === _httpStatus.HttpStatusCode.UNAUTHORIZED && this.context.accessToken) {
30
- this.context.log.debug("Invalid Checkout Token. Deleting session");
31
- await this.context.destroySession();
28
+ async sendRequest(request, retry = true) {
29
+ const response = await request();
30
+ if (response.ok) {
31
+ return await response.json();
32
+ }
33
+ if ((response.status === _httpStatus.HttpStatusCode.UNAUTHORIZED && response.headers.get("WWW-Authenticate")?.includes("invalid_token") || response.status === _httpStatus.HttpStatusCode.FORBIDDEN) && this.context.accessToken && this.context.refreshToken) {
34
+ if (retry) {
35
+ const client = (0, _oauth.getOAuthClient)(this.context);
36
+ const tokens = await client.refreshToken({
37
+ grant_type: "refresh_token",
38
+ refresh_token: this.context.refreshToken
39
+ });
40
+ this.context.updateTokens({
41
+ accessToken: tokens?.access_token,
42
+ refreshToken: tokens?.refresh_token
43
+ });
44
+ return await this.sendRequest(request, false);
32
45
  }
33
- throw new _fetch.FetchError(response);
46
+ this.context.log.debug("Invalid Checkout Token. Deleting session");
47
+ await this.context.destroySession();
34
48
  }
35
- return await response.json();
49
+ throw new _fetch.FetchError(response);
36
50
  }
37
51
  /**
38
52
  * Get the addresses for the current customer
39
53
  */
40
54
  async getAddresses(shopId) {
41
- return await fetch(`${this.baseURL}/api/oauth/customer/addresses`, {
55
+ return await this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/customer/addresses`, {
42
56
  headers: {
43
57
  ...this.headers,
44
58
  "X-Shop-Id": shopId.toString()
45
59
  }
46
- }).then(response => this.handleResponse(response));
60
+ }));
47
61
  }
48
62
  /**
49
63
  * Returns customer data and latest orders.
@@ -51,7 +65,7 @@ class CustomerAPIClient {
51
65
  * @see https://scayle.dev/api/oauth/latest/fetch-authorized-payload
52
66
  */
53
67
  async getMe(shopId, accessToken) {
54
- const response = await fetch(`${this.baseURL}/api/oauth/me`, {
68
+ return await this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/me`, {
55
69
  headers: {
56
70
  ...this.headers,
57
71
  ...(accessToken ? {
@@ -59,20 +73,19 @@ class CustomerAPIClient {
59
73
  } : {}),
60
74
  "X-Shop-Id": shopId.toString()
61
75
  }
62
- });
63
- return this.handleResponse(response);
76
+ }));
64
77
  }
65
78
  /**
66
79
  * Fetch a customer's order
67
80
  * @see https://scayle.dev/api/oauth/latest/fetch-order-by-id
68
81
  */
69
82
  async getOrder(shopId, orderId) {
70
- return await fetch(`${this.baseURL}/api/oauth/customer/order/${orderId}`, {
83
+ return this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/customer/order/${orderId}`, {
71
84
  headers: {
72
85
  ...this.headers,
73
86
  "X-Shop-Id": shopId.toString()
74
87
  }
75
- }).then(response => this.handleResponse(response));
88
+ }));
76
89
  }
77
90
  /**
78
91
  * Update the customer's contact details
@@ -83,7 +96,7 @@ class CustomerAPIClient {
83
96
  email,
84
97
  phone
85
98
  }) {
86
- return await fetch(`${this.baseURL}/api/oauth/customer/contact`, {
99
+ return await this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/customer/contact`, {
87
100
  method: "PUT",
88
101
  headers: {
89
102
  ...this.headers,
@@ -93,20 +106,20 @@ class CustomerAPIClient {
93
106
  email,
94
107
  phone
95
108
  })
96
- }).then(response => this.handleResponse(response));
109
+ }));
97
110
  }
98
111
  /**
99
112
  * Update the customer's personal details
100
113
  */
101
114
  async updatePersonalInfo(shopId, payload) {
102
- return await fetch(`${this.baseURL}/api/oauth/customer/personal`, {
115
+ return await this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/customer/personal`, {
103
116
  method: "PUT",
104
117
  headers: {
105
118
  ...this.headers,
106
119
  "X-Shop-Id": shopId.toString()
107
120
  },
108
121
  body: JSON.stringify(payload)
109
- }).then(response => this.handleResponse(response));
122
+ }));
110
123
  }
111
124
  /**
112
125
  * Update the customer's password
@@ -117,7 +130,7 @@ class CustomerAPIClient {
117
130
  password,
118
131
  newPassword
119
132
  }) {
120
- return await fetch(`${this.baseURL}/api/oauth/customer/password`, {
133
+ return await this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/customer/password`, {
121
134
  method: "PUT",
122
135
  headers: {
123
136
  ...this.headers,
@@ -127,7 +140,7 @@ class CustomerAPIClient {
127
140
  password,
128
141
  newPassword
129
142
  })
130
- }).then(response => this.handleResponse(response));
143
+ }));
131
144
  }
132
145
  }
133
146
  exports.CustomerAPIClient = CustomerAPIClient;
@@ -39,7 +39,7 @@ export declare class CustomerAPIClient {
39
39
  context: RpcContext;
40
40
  constructor(context: RpcContext);
41
41
  get headers(): HeadersInit;
42
- handleResponse<BodyType>(response: Response): Promise<BodyType>;
42
+ sendRequest<BodyType>(request: () => Promise<Response>, retry?: boolean): Promise<BodyType>;
43
43
  /**
44
44
  * Get the addresses for the current customer
45
45
  */
@@ -1,5 +1,6 @@
1
1
  import { FetchError } from "../utils/fetch.mjs";
2
2
  import { HttpStatusCode } from "../constants/httpStatus.mjs";
3
+ import { getOAuthClient } from "./oauth.mjs";
3
4
  export class CustomerAPIClient {
4
5
  baseURL;
5
6
  context;
@@ -16,27 +17,42 @@ export class CustomerAPIClient {
16
17
  ...accessHeader ? { "X-Access-Header": accessHeader } : {}
17
18
  };
18
19
  }
19
- async handleResponse(response) {
20
- if (!response.ok) {
21
- if (response.status === HttpStatusCode.UNAUTHORIZED && this.context.accessToken) {
22
- this.context.log.debug("Invalid Checkout Token. Deleting session");
23
- await this.context.destroySession();
20
+ async sendRequest(request, retry = true) {
21
+ const response = await request();
22
+ if (response.ok) {
23
+ return await response.json();
24
+ }
25
+ if ((response.status === HttpStatusCode.UNAUTHORIZED && response.headers.get("WWW-Authenticate")?.includes(
26
+ "invalid_token"
27
+ ) || response.status === HttpStatusCode.FORBIDDEN) && this.context.accessToken && this.context.refreshToken) {
28
+ if (retry) {
29
+ const client = getOAuthClient(this.context);
30
+ const tokens = await client.refreshToken({
31
+ grant_type: "refresh_token",
32
+ refresh_token: this.context.refreshToken
33
+ });
34
+ this.context.updateTokens({
35
+ accessToken: tokens?.access_token,
36
+ refreshToken: tokens?.refresh_token
37
+ });
38
+ return await this.sendRequest(request, false);
24
39
  }
25
- throw new FetchError(response);
40
+ this.context.log.debug("Invalid Checkout Token. Deleting session");
41
+ await this.context.destroySession();
26
42
  }
27
- return await response.json();
43
+ throw new FetchError(response);
28
44
  }
29
45
  /**
30
46
  * Get the addresses for the current customer
31
47
  */
32
48
  async getAddresses(shopId) {
33
- return await fetch(`${this.baseURL}/api/oauth/customer/addresses`, {
34
- headers: {
35
- ...this.headers,
36
- "X-Shop-Id": shopId.toString()
37
- }
38
- }).then(
39
- (response) => this.handleResponse(response)
49
+ return await this.sendRequest(
50
+ () => fetch(`${this.baseURL}/api/oauth/customer/addresses`, {
51
+ headers: {
52
+ ...this.headers,
53
+ "X-Shop-Id": shopId.toString()
54
+ }
55
+ })
40
56
  );
41
57
  }
42
58
  /**
@@ -45,26 +61,29 @@ export class CustomerAPIClient {
45
61
  * @see https://scayle.dev/api/oauth/latest/fetch-authorized-payload
46
62
  */
47
63
  async getMe(shopId, accessToken) {
48
- const response = await fetch(`${this.baseURL}/api/oauth/me`, {
49
- headers: {
50
- ...this.headers,
51
- ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
52
- "X-Shop-Id": shopId.toString()
53
- }
54
- });
55
- return this.handleResponse(response);
64
+ return await this.sendRequest(
65
+ () => fetch(`${this.baseURL}/api/oauth/me`, {
66
+ headers: {
67
+ ...this.headers,
68
+ ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
69
+ "X-Shop-Id": shopId.toString()
70
+ }
71
+ })
72
+ );
56
73
  }
57
74
  /**
58
75
  * Fetch a customer's order
59
76
  * @see https://scayle.dev/api/oauth/latest/fetch-order-by-id
60
77
  */
61
78
  async getOrder(shopId, orderId) {
62
- return await fetch(`${this.baseURL}/api/oauth/customer/order/${orderId}`, {
63
- headers: {
64
- ...this.headers,
65
- "X-Shop-Id": shopId.toString()
66
- }
67
- }).then((response) => this.handleResponse(response));
79
+ return this.sendRequest(
80
+ () => fetch(`${this.baseURL}/api/oauth/customer/order/${orderId}`, {
81
+ headers: {
82
+ ...this.headers,
83
+ "X-Shop-Id": shopId.toString()
84
+ }
85
+ })
86
+ );
68
87
  }
69
88
  /**
70
89
  * Update the customer's contact details
@@ -72,30 +91,34 @@ export class CustomerAPIClient {
72
91
  * @see https://scayle.dev/api/oauth/latest/put-customer-contact
73
92
  */
74
93
  async updateContactInfo(shopId, { email, phone }) {
75
- return await fetch(`${this.baseURL}/api/oauth/customer/contact`, {
76
- method: "PUT",
77
- headers: {
78
- ...this.headers,
79
- "X-Shop-Id": shopId.toString()
80
- },
81
- body: JSON.stringify({
82
- email,
83
- phone
94
+ return await this.sendRequest(
95
+ () => fetch(`${this.baseURL}/api/oauth/customer/contact`, {
96
+ method: "PUT",
97
+ headers: {
98
+ ...this.headers,
99
+ "X-Shop-Id": shopId.toString()
100
+ },
101
+ body: JSON.stringify({
102
+ email,
103
+ phone
104
+ })
84
105
  })
85
- }).then((response) => this.handleResponse(response));
106
+ );
86
107
  }
87
108
  /**
88
109
  * Update the customer's personal details
89
110
  */
90
111
  async updatePersonalInfo(shopId, payload) {
91
- return await fetch(`${this.baseURL}/api/oauth/customer/personal`, {
92
- method: "PUT",
93
- headers: {
94
- ...this.headers,
95
- "X-Shop-Id": shopId.toString()
96
- },
97
- body: JSON.stringify(payload)
98
- }).then((response) => this.handleResponse(response));
112
+ return await this.sendRequest(
113
+ () => fetch(`${this.baseURL}/api/oauth/customer/personal`, {
114
+ method: "PUT",
115
+ headers: {
116
+ ...this.headers,
117
+ "X-Shop-Id": shopId.toString()
118
+ },
119
+ body: JSON.stringify(payload)
120
+ })
121
+ );
99
122
  }
100
123
  /**
101
124
  * Update the customer's password
@@ -103,13 +126,15 @@ export class CustomerAPIClient {
103
126
  * @see https://scayle.dev/api/oauth/latest/put-customer-password
104
127
  */
105
128
  async updatePassword(shopId, { password, newPassword }) {
106
- return await fetch(`${this.baseURL}/api/oauth/customer/password`, {
107
- method: "PUT",
108
- headers: {
109
- ...this.headers,
110
- "X-Shop-Id": shopId.toString()
111
- },
112
- body: JSON.stringify({ password, newPassword })
113
- }).then((response) => this.handleResponse(response));
129
+ return await this.sendRequest(
130
+ () => fetch(`${this.baseURL}/api/oauth/customer/password`, {
131
+ method: "PUT",
132
+ headers: {
133
+ ...this.headers,
134
+ "X-Shop-Id": shopId.toString()
135
+ },
136
+ body: JSON.stringify({ password, newPassword })
137
+ })
138
+ );
114
139
  }
115
140
  }
@@ -7,7 +7,8 @@ exports.getRootCategories = exports.getCategoryByPath = exports.getCategoryById
7
7
  var _helpers = require("../../helpers/index.cjs");
8
8
  const getRootCategories = exports.getRootCategories = async function getRootCategories2({
9
9
  children = 1,
10
- includeHidden
10
+ includeHidden,
11
+ properties
11
12
  }, {
12
13
  cached,
13
14
  bapiClient
@@ -16,7 +17,8 @@ const getRootCategories = exports.getRootCategories = async function getRootCate
16
17
  cacheKeyPrefix: "root-categories"
17
18
  })({
18
19
  with: {
19
- children
20
+ children,
21
+ properties
20
22
  },
21
23
  includeHidden
22
24
  });
@@ -28,7 +30,8 @@ const getRootCategories = exports.getRootCategories = async function getRootCate
28
30
  const getCategoryByPath = exports.getCategoryByPath = async function getCategoryByPath2({
29
31
  path,
30
32
  children = 1,
31
- includeHidden
33
+ includeHidden,
34
+ properties
32
35
  }, context) {
33
36
  const {
34
37
  cached,
@@ -39,7 +42,8 @@ const getCategoryByPath = exports.getCategoryByPath = async function getCategory
39
42
  cacheKeyPrefix: `getByPath-category-${sanitizedPath}`
40
43
  })(sanitizedPath, {
41
44
  with: {
42
- children
45
+ children,
46
+ properties
43
47
  },
44
48
  includeHidden
45
49
  });
@@ -47,7 +51,8 @@ const getCategoryByPath = exports.getCategoryByPath = async function getCategory
47
51
  const getCategoriesByPath = exports.getCategoriesByPath = async function getCategoriesByPath2({
48
52
  path,
49
53
  children = 1,
50
- includeHidden
54
+ includeHidden,
55
+ properties
51
56
  }, context) {
52
57
  const {
53
58
  cached,
@@ -56,7 +61,8 @@ const getCategoriesByPath = exports.getCategoriesByPath = async function getCate
56
61
  if (path === "/") {
57
62
  return getRootCategories({
58
63
  children,
59
- includeHidden
64
+ includeHidden,
65
+ properties
60
66
  }, context);
61
67
  }
62
68
  const sanitizedPath = (0, _helpers.splitAndRemoveEmpty)(path);
@@ -64,7 +70,8 @@ const getCategoriesByPath = exports.getCategoriesByPath = async function getCate
64
70
  cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
65
71
  })(sanitizedPath, {
66
72
  with: {
67
- children
73
+ children,
74
+ properties
68
75
  },
69
76
  includeHidden
70
77
  });
@@ -74,7 +81,8 @@ const getCategoriesByPath = exports.getCategoriesByPath = async function getCate
74
81
  })(id, {
75
82
  with: {
76
83
  children,
77
- parents: "all"
84
+ parents: "all",
85
+ properties
78
86
  },
79
87
  includeHidden
80
88
  });
@@ -100,7 +108,8 @@ const getCategoriesByPath = exports.getCategoriesByPath = async function getCate
100
108
  const getCategoryById = exports.getCategoryById = async function getCategoryById2({
101
109
  id,
102
110
  children = 1,
103
- includeHidden
111
+ includeHidden,
112
+ properties
104
113
  }, context) {
105
114
  const {
106
115
  cached,
@@ -111,7 +120,8 @@ const getCategoryById = exports.getCategoryById = async function getCategoryById
111
120
  })(id, {
112
121
  with: {
113
122
  children,
114
- parents: "all"
123
+ parents: "all",
124
+ properties
115
125
  },
116
126
  includeHidden
117
127
  });
@@ -1,20 +1,23 @@
1
- import type { Category } from '../../types';
2
- export declare const getRootCategories: ({ children, includeHidden }: {
1
+ import type { Category, ProductCategoryPropertyWith } from '../../types';
2
+ export declare const getRootCategories: ({ children, includeHidden, properties }: {
3
3
  children?: number | undefined;
4
4
  includeHidden?: true | undefined;
5
+ properties?: ProductCategoryPropertyWith | undefined;
5
6
  }, { cached, bapiClient }: import("../../types").RpcContext) => Promise<{
6
7
  categories: Category[];
7
8
  activeNode: undefined;
8
9
  }>;
9
- export declare const getCategoryByPath: ({ path, children, includeHidden }: {
10
+ export declare const getCategoryByPath: ({ path, children, includeHidden, properties }: {
10
11
  path: string;
11
12
  children?: number | undefined;
12
13
  includeHidden?: true | undefined;
14
+ properties?: ProductCategoryPropertyWith | undefined;
13
15
  }, context: import("../../types").RpcContext) => Promise<Category>;
14
- export declare const getCategoriesByPath: ({ path, children, includeHidden }: {
16
+ export declare const getCategoriesByPath: ({ path, children, includeHidden, properties }: {
15
17
  path: string;
16
18
  children?: number | undefined;
17
19
  includeHidden?: true | undefined;
20
+ properties?: ProductCategoryPropertyWith | undefined;
18
21
  }, context: import("../../types").RpcContext) => Promise<{
19
22
  categories: Category[];
20
23
  activeNode: undefined;
@@ -22,8 +25,9 @@ export declare const getCategoriesByPath: ({ path, children, includeHidden }: {
22
25
  categories: Category;
23
26
  activeNode: Category;
24
27
  }>;
25
- export declare const getCategoryById: ({ id, children, includeHidden }: {
28
+ export declare const getCategoryById: ({ id, children, includeHidden, properties }: {
26
29
  id: number;
27
30
  children?: number | undefined;
28
31
  includeHidden?: true | undefined;
32
+ properties?: ProductCategoryPropertyWith | undefined;
29
33
  }, context: import("../../types").RpcContext) => Promise<Category>;
@@ -1,9 +1,9 @@
1
1
  import { splitAndRemoveEmpty } from "../../helpers/index.mjs";
2
- export const getRootCategories = async function getRootCategories2({ children = 1, includeHidden }, { cached, bapiClient }) {
2
+ export const getRootCategories = async function getRootCategories2({ children = 1, includeHidden, properties }, { cached, bapiClient }) {
3
3
  const result = await cached(bapiClient.categories.getRoots, {
4
4
  cacheKeyPrefix: "root-categories"
5
5
  })({
6
- with: { children },
6
+ with: { children, properties },
7
7
  includeHidden
8
8
  });
9
9
  return {
@@ -11,22 +11,25 @@ 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) {
14
+ export const getCategoryByPath = async function getCategoryByPath2({ path, children = 1, includeHidden, properties }, context) {
15
15
  const { cached, bapiClient } = context;
16
16
  const sanitizedPath = splitAndRemoveEmpty(path);
17
17
  return await cached(bapiClient.categories.getByPath, {
18
18
  cacheKeyPrefix: `getByPath-category-${sanitizedPath}`
19
- })(sanitizedPath, { with: { children }, includeHidden });
19
+ })(sanitizedPath, { with: { children, properties }, includeHidden });
20
20
  };
21
- export const getCategoriesByPath = async function getCategoriesByPath2({ path, children = 1, includeHidden }, context) {
21
+ export const getCategoriesByPath = async function getCategoriesByPath2({ path, children = 1, includeHidden, properties }, context) {
22
22
  const { cached, bapiClient } = context;
23
23
  if (path === "/") {
24
- return getRootCategories({ children, includeHidden }, context);
24
+ return getRootCategories({ children, includeHidden, properties }, context);
25
25
  }
26
26
  const sanitizedPath = splitAndRemoveEmpty(path);
27
27
  const result = await cached(bapiClient.categories.getByPath, {
28
28
  cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
29
- })(sanitizedPath, { with: { children }, includeHidden });
29
+ })(sanitizedPath, {
30
+ with: { children, properties },
31
+ includeHidden
32
+ });
30
33
  const rootPath = await Promise.all(
31
34
  (result.rootlineIds || []).map((id) => {
32
35
  return cached(bapiClient.categories.getById, {
@@ -34,7 +37,8 @@ export const getCategoriesByPath = async function getCategoriesByPath2({ path, c
34
37
  })(id, {
35
38
  with: {
36
39
  children,
37
- parents: "all"
40
+ parents: "all",
41
+ properties
38
42
  },
39
43
  includeHidden
40
44
  });
@@ -57,14 +61,15 @@ export const getCategoriesByPath = async function getCategoriesByPath2({ path, c
57
61
  }
58
62
  return { categories: tree, activeNode: result };
59
63
  };
60
- export const getCategoryById = async function getCategoryById2({ id, children = 1, includeHidden }, context) {
64
+ export const getCategoryById = async function getCategoryById2({ id, children = 1, includeHidden, properties }, context) {
61
65
  const { cached, bapiClient } = context;
62
66
  return await cached(bapiClient.categories.getById, {
63
67
  cacheKeyPrefix: `getById-categories-${id}`
64
68
  })(id, {
65
69
  with: {
66
70
  children,
67
- parents: "all"
71
+ parents: "all",
72
+ properties
68
73
  },
69
74
  includeHidden
70
75
  });
@@ -24,7 +24,7 @@ const getCheckoutToken = exports.getCheckoutToken = async function getCheckoutTo
24
24
  carrier,
25
25
  basketId: context.basketKey,
26
26
  campaignKey: context.campaignKey
27
- }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.54.0"}`).setProtectedHeader({
27
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.56.0"}`).setProtectedHeader({
28
28
  alg: "HS256",
29
29
  typ: "JWT"
30
30
  }).sign(secret);
@@ -13,7 +13,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload, con
13
13
  carrier,
14
14
  basketId: context.basketKey,
15
15
  campaignKey: context.campaignKey
16
- }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.54.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
16
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.56.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
17
17
  return {
18
18
  accessToken: context.accessToken,
19
19
  checkoutJwt
@@ -7,8 +7,20 @@ exports.refreshUser = exports.getUser = exports.fetchUser = void 0;
7
7
  var _types = require("../../types/index.cjs");
8
8
  var _customer = require("../../api/customer.cjs");
9
9
  const getUser = exports.getUser = function getUser2(context) {
10
+ const {
11
+ user,
12
+ accessToken,
13
+ shopId
14
+ } = context;
15
+ if (user) {
16
+ user.authentication = user.authentication ?? {
17
+ type: "idp"
18
+ };
19
+ user.authentication.storefrontAccessToken = accessToken;
20
+ user.loginShopId = shopId;
21
+ }
10
22
  return {
11
- user: context.user
23
+ user
12
24
  };
13
25
  };
14
26
  const fetchUser = exports.fetchUser = async function fetchUser2(payload, context) {
@@ -1,8 +1,16 @@
1
1
  import { assertSession } from "../../types/index.mjs";
2
2
  import { CustomerAPIClient } from "../../api/customer.mjs";
3
3
  const getUser = function getUser2(context) {
4
+ const { user, accessToken, shopId } = context;
5
+ if (user) {
6
+ user.authentication = user.authentication ?? {
7
+ type: "idp"
8
+ };
9
+ user.authentication.storefrontAccessToken = accessToken;
10
+ user.loginShopId = shopId;
11
+ }
4
12
  return {
5
- user: context.user
13
+ user
6
14
  };
7
15
  };
8
16
  const fetchUser = async function fetchUser2(payload, context) {
@@ -1,2 +1,2 @@
1
- import type { Category, ProductCategory, ProductCategoryWith } from '@scayle/storefront-api';
2
- export type { ProductCategoryWith, ProductCategory, Category };
1
+ import type { Category, ProductCategory, ProductCategoryPropertyWith, ProductCategoryWith } from '@scayle/storefront-api';
2
+ export type { ProductCategoryWith, ProductCategory, ProductCategoryPropertyWith, Category, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "7.55.0",
3
+ "version": "7.57.0",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -71,11 +71,11 @@
71
71
  "devDependencies": {
72
72
  "@scayle/eslint-config-storefront": "4.2.0",
73
73
  "@types/crypto-js": "4.2.2",
74
- "@types/node": "20.14.1",
74
+ "@types/node": "20.14.2",
75
75
  "@types/webpack-env": "1.18.5",
76
76
  "@vitest/coverage-v8": "1.6.0",
77
- "dprint": "0.46.1",
78
- "eslint": "9.4.0",
77
+ "dprint": "0.46.2",
78
+ "eslint": "9.5.0",
79
79
  "eslint-formatter-gitlab": "5.1.0",
80
80
  "publint": "0.2.8",
81
81
  "rimraf": "5.0.7",