@scayle/storefront-core 8.19.1 → 8.20.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,26 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 8.20.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Re-exported `BasketKey` and `ApplicablePromotion` from `@scayle/storefront-api`
8
+
9
+ **Dependencies**
10
+
11
+ - Updated dependency to @scayle/storefront-api@18.3.0
12
+
13
+ ## 8.20.0
14
+
15
+ ### Minor Changes
16
+
17
+ - Include additional client information to Auth API requests to improve security.
18
+ - Add `originalIp` to the RPCContext which represents the IP address of the request without considering the `x-forwarded-for` header.
19
+
20
+ ### Patch Changes
21
+
22
+ - **\[Basket\]** Pass `campaignKey` to SAPI when updating an basket item using the `updateBasketItem` RPC.
23
+
3
24
  ## 8.19.1
4
25
 
5
26
  ### Patch Changes
@@ -25,11 +25,32 @@ export function getOAuthClient(context) {
25
25
  }
26
26
  const { clientId, clientSecret, apiHost } = context.oauth;
27
27
  const accessHeader = context.internalAccessHeader;
28
+ const requestHeaders = context.headers;
29
+ const host = requestHeaders.get("host");
30
+ const userAgent = requestHeaders.get("user-agent");
31
+ const contentType = requestHeaders.get("content-type");
32
+ const ip = context.originalIp;
33
+ const additionalHeaders = {};
34
+ if (ip) {
35
+ additionalHeaders["x-original-client-ip"] = ip;
36
+ }
37
+ if (userAgent) {
38
+ additionalHeaders["x-original-user-agent"] = userAgent;
39
+ }
40
+ if (host) {
41
+ additionalHeaders["x-original-host"] = host;
42
+ }
43
+ if (contentType) {
44
+ additionalHeaders["x-original-content-type"] = contentType;
45
+ }
46
+ if (accessHeader) {
47
+ additionalHeaders["x-internal-access"] = accessHeader;
48
+ }
28
49
  return new OAuthClient({
29
50
  clientId,
30
51
  clientSecret,
31
52
  apiHost,
32
- additionalHeaders: accessHeader ? { "x-internal-access": accessHeader } : {}
53
+ additionalHeaders
33
54
  }, context.log);
34
55
  }
35
56
  export class OAuthClient {
@@ -241,11 +241,12 @@ export const updateBasketItem = async function updateBasketItem2({ basketItemKey
241
241
  context
242
242
  );
243
243
  const { quantity, ...updateParams } = update;
244
+ const campaignKey = update.campaignKey ?? await context.callRpc?.("getCampaignKey");
244
245
  const result = await sapiClient.basket.updateItem(
245
246
  basketKey,
246
247
  basketItemKey,
247
248
  quantity,
248
- { ...updateParams, with: resolvedWith }
249
+ { ...updateParams, campaignKey, with: resolvedWith }
249
250
  );
250
251
  if (result.type === "success") {
251
252
  return { basket: result.basket };
@@ -36,7 +36,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
36
36
  carrier,
37
37
  basketId: context.basketKey,
38
38
  campaignKey
39
- }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.19.1"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
39
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.20.1"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
40
40
  return {
41
41
  accessToken: refreshedAccessToken,
42
42
  checkoutJwt
@@ -150,6 +150,7 @@ export type RpcContext = {
150
150
  generateWishlistKeyForUserId: (userId: string) => Promise<string>;
151
151
  routerBasePath?: string;
152
152
  ip?: string | undefined;
153
+ originalIp?: string;
153
154
  log: Log;
154
155
  auth: {
155
156
  resetPasswordUrl?: string;
@@ -1,4 +1,4 @@
1
- import type { BasketItemDisplayData, BasketItemDisplayDataKey, BasketResponse, BasketResponseData, BasketWith, BasketItemDisplayDataItem, CreateBasketItemParameters, ItemGroup } from '@scayle/storefront-api';
1
+ import type { BasketKey, ApplicablePromotion, BasketItemDisplayData, BasketItemDisplayDataItem, BasketItemDisplayDataKey, BasketResponse, BasketResponseData, BasketWith, CreateBasketItemParameters, ItemGroup } from '@scayle/storefront-api';
2
2
  /**
3
3
  * Represents custom data for a basket item. Corresponds to the `customData` property
4
4
  * of `CreateBasketItemParameters`.
@@ -45,4 +45,4 @@ export interface UseBasketParams {
45
45
  /** Data to include with the basket. */
46
46
  with: BasketWithOptions;
47
47
  }
48
- export type { BasketItemDisplayData, BasketItemDisplayDataItem, BasketResponseData, BasketWith, BasketResponse, ItemGroup, };
48
+ export type { BasketKey, ApplicablePromotion, BasketItemDisplayData, BasketItemDisplayDataItem, BasketResponseData, BasketWith, BasketResponse, ItemGroup, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "8.19.1",
3
+ "version": "8.20.1",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -52,7 +52,8 @@
52
52
  "typecheck": "tsc --noEmit -p tsconfig.json",
53
53
  "format": "dprint check",
54
54
  "format:fix": "dprint fmt",
55
- "lint": "eslint . --format gitlab",
55
+ "lint": "eslint .",
56
+ "lint:ci": "eslint . --format gitlab",
56
57
  "lint:fix": "eslint . --fix",
57
58
  "package:lint": "publint",
58
59
  "test:watch": "vitest --passWithNoTests",
@@ -63,7 +64,7 @@
63
64
  "fishery": "^2.2.3"
64
65
  },
65
66
  "dependencies": {
66
- "@scayle/storefront-api": "18.2.2",
67
+ "@scayle/storefront-api": "18.3.0",
67
68
  "@scayle/unstorage-scayle-kv-driver": "0.1.1",
68
69
  "crypto-js": "^4.2.0",
69
70
  "hookable": "^5.5.3",