@scayle/storefront-core 8.36.0 → 8.38.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,22 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 8.38.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Refined the `ContextWithoutSession` type to accurately represent actual data: `wishlistKey`, `basketKey`, and `sessionId` are now typed as `string` instead of `undefined`, since even logged-out users have these values set.
8
+ - Made `getCheckoutToken` callable by logged-in and not logged-in users. When called by a not logged-in user, the RPC returns only the `checkoutJWT`. For logged-in users, it continues to return both the `checkoutJWT` and a refreshed `accessToken` as before.
9
+
10
+ ## 8.37.0
11
+
12
+ ### Minor Changes
13
+
14
+ - The `where` parameter for the `getProductsByCategory` and `getProductsCount` RPCs was extended to include the previously missing options `sellableAt`, `hasCampaignReduction`, and `containsSearch`.
15
+
16
+ ### Patch Changes
17
+
18
+ - Added missing export of the RPC `getCampaign`
19
+
3
20
  ## 8.36.0
4
21
 
5
22
  ### Minor Changes
@@ -49,7 +49,7 @@ interface CheckoutJwtPayload {
49
49
  * It will return an `ErrorResponse` if no session is found, no access token is present.
50
50
  */
51
51
  export declare const getCheckoutToken: RpcHandler<CheckoutJwtPayload | undefined, {
52
- accessToken: string;
52
+ accessToken: string | undefined;
53
53
  checkoutJwt: string;
54
54
  }>;
55
55
  export {};
@@ -12,19 +12,15 @@ export const getCheckoutToken = defineRpcHandler(async (jwtPayload = {}, context
12
12
  "No Session found"
13
13
  );
14
14
  }
15
- if (!context.accessToken) {
16
- return new ErrorResponse(
17
- HttpStatusCode.UNAUTHORIZED,
18
- HttpStatusMessage.UNAUTHORIZED,
19
- "No access token present"
15
+ let refreshedAccessToken;
16
+ if (context.accessToken) {
17
+ refreshedAccessToken = await getAccessToken(
18
+ { forceTokenRefresh: true },
19
+ context
20
20
  );
21
- }
22
- const refreshedAccessToken = await getAccessToken(
23
- { forceTokenRefresh: true },
24
- context
25
- );
26
- if (refreshedAccessToken instanceof Response) {
27
- return refreshedAccessToken;
21
+ if (refreshedAccessToken instanceof Response) {
22
+ return refreshedAccessToken;
23
+ }
28
24
  }
29
25
  const secret = new TextEncoder().encode(context.checkout.secret);
30
26
  const now = /* @__PURE__ */ new Date();
@@ -37,7 +33,7 @@ export const getCheckoutToken = defineRpcHandler(async (jwtPayload = {}, context
37
33
  carrier,
38
34
  basketId: context.basketKey,
39
35
  campaignKey
40
- }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.36.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
36
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.38.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
41
37
  return {
42
38
  accessToken: refreshedAccessToken,
43
39
  checkoutJwt
@@ -1,7 +1,7 @@
1
1
  export * from './basket/basket';
2
2
  export * from './brands';
3
3
  export * from './categories';
4
- export { getCampaignKey } from './campaign';
4
+ export * from './campaign';
5
5
  export * from './cbd';
6
6
  export { getProductById, getProductsByIds, getProductsByReferenceKeys, getProductsCount, fetchAllFiltersForCategory, getFilters, getProductsByCategory, } from './products';
7
7
  export * from './search';
@@ -1,7 +1,7 @@
1
1
  export * from "./basket/basket.mjs";
2
2
  export * from "./brands.mjs";
3
3
  export * from "./categories.mjs";
4
- export { getCampaignKey } from "./campaign.mjs";
4
+ export * from "./campaign.mjs";
5
5
  export * from "./cbd.mjs";
6
6
  export {
7
7
  getProductById,
@@ -89,10 +89,11 @@ export const getProductsCount = async function getProductsCount2(params, context
89
89
  const { cached, sapiClient } = context;
90
90
  const campaignKey = await context.callRpc?.("getCampaignKey");
91
91
  const { categoryId } = await resolveCategoryIdFromParams(context, params);
92
+ const { attributes, whitelistAttributes, ...filter } = where || {};
92
93
  const response = await getSanitizedAttributes(
93
94
  context,
94
95
  categoryId,
95
- where?.attributes || [],
96
+ attributes || [],
96
97
  includedFilters
97
98
  );
98
99
  if (response instanceof ErrorResponse) {
@@ -104,17 +105,12 @@ export const getProductsCount = async function getProductsCount2(params, context
104
105
  cacheKeyPrefix: "products-query"
105
106
  })({
106
107
  where: {
108
+ ...filter,
107
109
  categoryId,
108
- minPrice: where?.minPrice,
109
- maxPrice: where?.maxPrice,
110
- minReduction: where?.minReduction,
111
- maxReduction: where?.maxReduction,
112
- term: where?.term,
113
110
  attributes: [
114
111
  ...sanitizedAttributes,
115
- ...where?.whitelistAttributes || []
116
- ],
117
- disableFuzziness: where?.disableFuzziness
112
+ ...whitelistAttributes || []
113
+ ]
118
114
  },
119
115
  pagination: {
120
116
  perPage: 1
@@ -177,10 +173,11 @@ export const getFilters = async function getFilters2(params, context) {
177
173
  context,
178
174
  params
179
175
  );
176
+ const { attributes, whitelistAttributes, ...filter } = where || {};
180
177
  const response = await getSanitizedAttributes(
181
178
  context,
182
179
  categoryId,
183
- where?.attributes || [],
180
+ attributes || [],
184
181
  includedFilters
185
182
  );
186
183
  if (response instanceof ErrorResponse) {
@@ -192,15 +189,11 @@ export const getFilters = async function getFilters2(params, context) {
192
189
  cacheKeyPrefix: `get-filters-${categoryId}`
193
190
  })({
194
191
  where: {
192
+ ...filter,
195
193
  categoryId,
196
- minPrice: where?.minPrice,
197
- maxPrice: where?.maxPrice,
198
- minReduction: where?.minReduction,
199
- maxReduction: where?.maxReduction,
200
- term: where?.term,
201
194
  attributes: [
202
195
  ...sanitizedAttributes,
203
- ...where?.whitelistAttributes || []
196
+ ...whitelistAttributes || []
204
197
  ]
205
198
  },
206
199
  includeSoldOut,
@@ -214,17 +207,12 @@ export const getFilters = async function getFilters2(params, context) {
214
207
  cacheKeyPrefix: `products-query-category-${category === "/" ? "root" : categoryId}`
215
208
  })({
216
209
  where: {
210
+ ...filter,
217
211
  categoryId,
218
- minPrice: where?.minPrice,
219
- maxPrice: where?.maxPrice,
220
- minReduction: where?.minReduction,
221
- maxReduction: where?.maxReduction,
222
- term: where?.term,
223
212
  attributes: [
224
213
  ...sanitizedAttributes,
225
- ...where?.whitelistAttributes || []
226
- ],
227
- disableFuzziness: where?.disableFuzziness
214
+ ...whitelistAttributes || []
215
+ ]
228
216
  },
229
217
  pagination: {
230
218
  perPage: 1
@@ -261,10 +249,11 @@ export const getProductsByCategory = async function getProductsByCategory2(param
261
249
  context,
262
250
  params
263
251
  );
252
+ const { attributes, whitelistAttributes, ...filter } = where || {};
264
253
  const response = await getSanitizedAttributes(
265
254
  context,
266
255
  categoryId,
267
- where?.attributes || [],
256
+ attributes || [],
268
257
  includedFilters
269
258
  );
270
259
  if (response instanceof ErrorResponse) {
@@ -280,17 +269,12 @@ export const getProductsByCategory = async function getProductsByCategory2(param
280
269
  }
281
270
  )({
282
271
  where: {
272
+ ...filter,
283
273
  categoryId,
284
- minPrice: where?.minPrice,
285
- maxPrice: where?.maxPrice,
286
- minReduction: where?.minReduction,
287
- maxReduction: where?.maxReduction,
288
- term: where?.term,
289
274
  attributes: [
290
275
  ...sanitizedAttributes,
291
- ...where?.whitelistAttributes || []
292
- ],
293
- disableFuzziness: where?.disableFuzziness
276
+ ...whitelistAttributes || []
277
+ ]
294
278
  },
295
279
  pagination: {
296
280
  perPage: Math.min(perPage, MAX_PER_PAGE),
@@ -61,9 +61,9 @@ export interface ContextWithSession {
61
61
  * Context interface without session information.
62
62
  */
63
63
  export interface ContextWithoutSession {
64
- wishlistKey: undefined;
65
- basketKey: undefined;
66
- sessionId: undefined;
64
+ wishlistKey: string;
65
+ basketKey: string;
66
+ sessionId: string;
67
67
  user: undefined;
68
68
  accessToken: undefined;
69
69
  refreshToken: undefined;
@@ -90,6 +90,9 @@ export interface FetchProductsByReferenceKeysParams {
90
90
  with?: ProductWith;
91
91
  pricePromotionKey?: string;
92
92
  }
93
+ export type ProductWhere = Partial<Omit<ProductSearchQuery, 'categoryId'> & {
94
+ whitelistAttributes?: ProductSearchQuery['attributes'];
95
+ }>;
93
96
  /**
94
97
  * Parameters for fetching products by category.
95
98
  */
@@ -101,16 +104,7 @@ export type FetchProductsByCategoryParams = {
101
104
  perPage?: number;
102
105
  page?: number;
103
106
  /** Search query parameters. */
104
- where?: {
105
- term?: ProductSearchQuery['term'];
106
- minPrice?: ProductSearchQuery['minPrice'];
107
- maxPrice?: ProductSearchQuery['maxPrice'];
108
- minReduction?: ProductSearchQuery['minReduction'];
109
- maxReduction?: ProductSearchQuery['maxReduction'];
110
- attributes?: ProductSearchQuery['attributes'];
111
- disableFuzziness?: ProductSearchQuery['disableFuzziness'];
112
- whitelistAttributes?: ProductSearchQuery['attributes'];
113
- };
107
+ where?: ProductWhere;
114
108
  /** Sort parameters. */
115
109
  sort?: FilterParams['sort'];
116
110
  pricePromotionKey?: string;
@@ -145,16 +139,7 @@ export interface FetchProductsByCategoryResponse {
145
139
  */
146
140
  export type FetchProductsCountParams = {
147
141
  /** Search query parameters. */
148
- where?: {
149
- term?: ProductSearchQuery['term'];
150
- minPrice?: ProductSearchQuery['minPrice'];
151
- maxPrice?: ProductSearchQuery['maxPrice'];
152
- minReduction?: ProductSearchQuery['minReduction'];
153
- maxReduction?: ProductSearchQuery['maxReduction'];
154
- attributes?: ProductSearchQuery['attributes'];
155
- disableFuzziness?: ProductSearchQuery['disableFuzziness'];
156
- whitelistAttributes?: ProductSearchQuery['attributes'];
157
- };
142
+ where?: ProductWhere;
158
143
  includedFilters?: Array<string>;
159
144
  includeSoldOut?: boolean;
160
145
  includeSellableForFree?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "8.36.0",
3
+ "version": "8.38.0",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -74,7 +74,7 @@
74
74
  "unbuild": "3.5.0",
75
75
  "unstorage": "1.16.0",
76
76
  "vitest": "3.2.4",
77
- "@scayle/eslint-config-storefront": "4.6.1"
77
+ "@scayle/eslint-config-storefront": "4.7.0"
78
78
  },
79
79
  "volta": {
80
80
  "node": "22.17.1"