@salesforce/commerce-sdk-react 1.0.0 → 1.0.1-preview.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,8 +1,14 @@
1
+ ## v1.0.1 (Jul 26, 2023)
2
+
3
+ - Updated the expiry of the guest refresh token cookie to 30 days, to match the actual [duration of the token](https://developer.salesforce.com/docs/commerce/commerce-api/guide/slas.html?q=refresh+token#access-tokens-and-refresh-tokens). [#1342](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1342)
4
+ - Fix potential security vulnerability in `semver` dependency [#1358](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1358)
5
+ - Fix request headers to be the intended headers, rather than parameters [#1377](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1377)
6
+
1
7
  ## v1.0.0 (Jun 15, 2023)
2
8
 
3
- - First public release of package on npm under `@salesforce/commerce-sdk-react`
4
- - Add missing cache invalidation for contexts/customers/login/order [#1073](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1073)
5
- - Upgrade React 18, React DOM 18, @types/react@18, @types/react-dom@v18 Testing library 14 [#1166](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1166)
9
+ - First public release of package on npm under `@salesforce/commerce-sdk-react`
10
+ - Add missing cache invalidation for contexts/customers/login/order [#1073](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1073)
11
+ - Upgrade React 18, React DOM 18, @types/react@18, @types/react-dom@v18 Testing library 14 [#1166](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1166)
6
12
 
7
13
  ## Older Versions Without Namespace
8
14
 
@@ -10,28 +16,28 @@ The older versions below were published without the `@salesforce` namespace.
10
16
 
11
17
  ## v2.7.1 (May 11, 2023)
12
18
 
13
- - Re-generate lock files and fix hook lib tests [#1186](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1186)
14
- - Add additional properties to ShopperLogin test types [#1185](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1185)
15
- - Add missing cache invalidation for contexts/customers/login/order [#1073](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1073)
16
- - Fix Shopper Baskets Test case [#1082](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1082)
17
- - Implement remaining Shopper Baskets cache logic [#1070](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1070)
18
- - Decode pre-fetched token and save auth data in storage [#1052](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1052)
19
- - Allow query hook parameters to be null. [#1046](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1046)
20
- - Implement updateCustomerPassword as no-op. [#1031](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1031)
19
+ - Re-generate lock files and fix hook lib tests [#1186](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1186)
20
+ - Add additional properties to ShopperLogin test types [#1185](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1185)
21
+ - Add missing cache invalidation for contexts/customers/login/order [#1073](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1073)
22
+ - Fix Shopper Baskets Test case [#1082](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1082)
23
+ - Implement remaining Shopper Baskets cache logic [#1070](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1070)
24
+ - Decode pre-fetched token and save auth data in storage [#1052](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1052)
25
+ - Allow query hook parameters to be null. [#1046](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1046)
26
+ - Implement updateCustomerPassword as no-op. [#1031](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1031)
21
27
 
22
28
  ## v2.7.0 (Mar 03, 2023)
23
29
 
24
- - Add Page/Region/Component components for shopper experience/page designer page rendering [#963](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/963)
25
- - Namespace `Auth` storage keys with site identifier to allow multi-site support [#911](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/911)
26
- - Add Shopper Experience `usePage` and `usePages` hooks[#958](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/958)
30
+ - Add Page/Region/Component components for shopper experience/page designer page rendering [#963](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/963)
31
+ - Namespace `Auth` storage keys with site identifier to allow multi-site support [#911](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/911)
32
+ - Add Shopper Experience `usePage` and `usePages` hooks[#958](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/958)
27
33
 
28
34
  ## v2.6.0 (Jan 25, 2023)
29
35
 
30
36
  ## v2.5.0 (Jan 05, 2023)
31
37
 
32
- - Exclude test files in package file to avoid publishing them [#856](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/856)
33
- - Pass in 'headers' and 'rawResponse' options to mutation hooks [#845](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/845)
34
- - Commerce hooks: basket mutations [#834](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/834)
35
- - Remove overriding of params in mutation hooks [#859](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/859)
38
+ - Exclude test files in package file to avoid publishing them [#856](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/856)
39
+ - Pass in 'headers' and 'rawResponse' options to mutation hooks [#845](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/845)
40
+ - Commerce hooks: basket mutations [#834](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/834)
41
+ - Remove overriding of params in mutation hooks [#859](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/859)
36
42
 
37
43
  ## v2.4.0 (Dec 01, 2022)
package/auth/index.d.ts CHANGED
@@ -35,7 +35,8 @@ declare class Auth {
35
35
  private shopperCustomersClient;
36
36
  private redirectURI;
37
37
  private pendingToken;
38
- private REFRESH_TOKEN_EXPIRATION_DAYS;
38
+ private REFRESH_TOKEN_EXPIRATION_DAYS_REGISTERED;
39
+ private REFRESH_TOKEN_EXPIRATION_DAYS_GUEST;
39
40
  private stores;
40
41
  private fetchedToken;
41
42
  private OCAPISessionsURL;
package/auth/index.js CHANGED
@@ -115,7 +115,8 @@ const DATA_MAP = {
115
115
  * @Internal
116
116
  */
117
117
  class Auth {
118
- REFRESH_TOKEN_EXPIRATION_DAYS = 90;
118
+ REFRESH_TOKEN_EXPIRATION_DAYS_REGISTERED = 90;
119
+ REFRESH_TOKEN_EXPIRATION_DAYS_GUEST = 30;
119
120
  constructor(config) {
120
121
  this.client = new _commerceSdkIsomorphic.ShopperLogin({
121
122
  proxy: config.proxy,
@@ -265,11 +266,12 @@ class Auth {
265
266
  this.set('customer_type', isGuest ? 'guest' : 'registered');
266
267
  const refreshTokenKey = isGuest ? 'refresh_token_guest' : 'refresh_token_registered';
267
268
  const refreshTokenCopyKey = isGuest ? 'refresh_token_guest_copy' : 'refresh_token_registered_copy';
269
+ const refreshTokenExpiry = isGuest ? this.REFRESH_TOKEN_EXPIRATION_DAYS_GUEST : this.REFRESH_TOKEN_EXPIRATION_DAYS_REGISTERED;
268
270
  this.set(refreshTokenKey, res.refresh_token, {
269
- expires: this.REFRESH_TOKEN_EXPIRATION_DAYS
271
+ expires: refreshTokenExpiry
270
272
  });
271
273
  this.set(refreshTokenCopyKey, res.refresh_token, {
272
- expires: this.REFRESH_TOKEN_EXPIRATION_DAYS
274
+ expires: refreshTokenExpiry
273
275
  });
274
276
  }
275
277
 
package/auth/storage.js CHANGED
@@ -5,13 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.MemoryStorage = exports.LocalStorage = exports.CookieStorage = exports.BaseStorage = void 0;
7
7
  var _jsCookie = _interopRequireDefault(require("js-cookie"));
8
+ var _utils = require("../utils");
8
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
10
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
10
11
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
11
12
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
13
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
13
14
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /*
14
- * Copyright (c) 2022, Salesforce, Inc.
15
+ * Copyright (c) 2023, Salesforce, Inc.
15
16
  * All rights reserved.
16
17
  * SPDX-License-Identifier: BSD-3-Clause
17
18
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
@@ -44,9 +45,12 @@ class CookieStorage extends BaseStorage {
44
45
  }
45
46
  set(key, value, options) {
46
47
  const suffixedKey = this.getSuffixedKey(key);
47
- _jsCookie.default.set(suffixedKey, value, _objectSpread(_objectSpread({}, options), {}, {
48
- secure: true
49
- }));
48
+ _jsCookie.default.set(suffixedKey, value, _objectSpread({
49
+ // Deployed sites will always be HTTPS, but the local dev server is served over HTTP.
50
+ // Ideally, this would be `secure: true`, because Chrome and Firefox both treat
51
+ // localhost as a Secure context. But Safari doesn't, so here we are.
52
+ secure: !(0, _utils.onClient)() || window.location.protocol === 'https:'
53
+ }, options));
50
54
  }
51
55
  get(key) {
52
56
  const suffixedKey = this.getSuffixedKey(key);
@@ -38,9 +38,11 @@ const updateCustomerBasketsQuery = (customerId, parameters, response) => {
38
38
  })),
39
39
  updater: oldData => {
40
40
  var _oldData$baskets;
41
- // do not update if response basket is not part of existing customer baskets
42
- if (!(oldData !== null && oldData !== void 0 && (_oldData$baskets = oldData.baskets) !== null && _oldData$baskets !== void 0 && _oldData$baskets.some(basket => basket.basketId === parameters.basketId))) {
43
- return undefined;
41
+ if (!(oldData !== null && oldData !== void 0 && (_oldData$baskets = oldData.baskets) !== null && _oldData$baskets !== void 0 && _oldData$baskets.length)) {
42
+ return {
43
+ baskets: [response],
44
+ total: 1
45
+ };
44
46
  }
45
47
  const updatedBaskets = oldData.baskets.map(basket => basket.basketId === parameters.basketId ? response : basket);
46
48
  return _objectSpread(_objectSpread({}, oldData), {}, {
package/hooks/utils.js CHANGED
@@ -74,7 +74,7 @@ const mergeOptions = (client, options) => {
74
74
  body: options.body
75
75
  } : {}), {}, {
76
76
  parameters: _objectSpread(_objectSpread({}, client.clientConfig.parameters), options.parameters ? omitNullable(options.parameters) : {}),
77
- headers: _objectSpread(_objectSpread({}, client.clientConfig.parameters), options.parameters)
77
+ headers: _objectSpread(_objectSpread({}, client.clientConfig.headers), options.headers)
78
78
  });
79
79
  return merged;
80
80
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/commerce-sdk-react",
3
- "version": "1.0.0",
3
+ "version": "1.0.1-preview.1",
4
4
  "description": "A library that provides react hooks for fetching data from Commerce Cloud",
5
5
  "homepage": "https://github.com/SalesforceCommerceCloud/pwa-kit/tree/develop/packages/ecom-react-hooks#readme",
6
6
  "bugs": {
@@ -47,7 +47,7 @@
47
47
  "typedoc-plugin-missing-exports": "^2.0.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@salesforce/pwa-kit-dev": "3.0.0",
50
+ "@salesforce/pwa-kit-dev": "3.1.0-preview.5",
51
51
  "@tanstack/react-query": "^4.28.0",
52
52
  "@testing-library/jest-dom": "^5.16.5",
53
53
  "@testing-library/react": "^14.0.0",
@@ -59,17 +59,17 @@
59
59
  "@types/react-dom": "^18.2.1",
60
60
  "@types/react-helmet": "^6.1.6",
61
61
  "cross-env": "^5.2.1",
62
- "internal-lib-build": "3.0.0",
62
+ "internal-lib-build": "3.1.0-preview.5",
63
63
  "jsonwebtoken": "^9.0.0",
64
64
  "nock": "^13.3.0",
65
65
  "nodemon": "^2.0.22",
66
66
  "react": "^18.2.0",
67
67
  "react-dom": "^18.2.0",
68
68
  "react-helmet": "^6.1.0",
69
- "semver": "^7.3.8",
69
+ "semver": "^7.5.2",
70
70
  "shelljs": "^0.8.5",
71
71
  "typedoc": "^0.24.7",
72
- "typescript": "^4.8.3"
72
+ "typescript": "4.9.5"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "@tanstack/react-query": "^4.28.0",
@@ -86,5 +86,5 @@
86
86
  "publishConfig": {
87
87
  "directory": "dist"
88
88
  },
89
- "gitHead": "d48df913cc9b8b3a30c56593caea31c9f33f361c"
89
+ "gitHead": "dac0446923988299709a35c535f0a37645927fd2"
90
90
  }