@salesforce/commerce-sdk-react 2.0.0-preview.1 → 2.0.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,3 +1,9 @@
1
+ ## v2.0.1 (Jul 08, 2024)
2
+ - Fix private slas proxy config for commerce api in provider [#1883](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1883)
3
+ - Fix `useCustomQuery` error handling [#1883](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1883)
4
+ - Fix `updateCustomer` squashing existing data [#1883](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1883)
5
+ - Fix `transferBasket` updating the wrong customer basket [#1887](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1887)
6
+
1
7
  ## v2.0.0 (Jun 25, 2024)
2
8
  - Add `useCustomQuery` and `useCustomMutation` for SCAPI custom endpoint support [#1793](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1793)
3
9
  - Add Shopper Stores hooks [#1788](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1788)
@@ -240,9 +240,11 @@ const cacheUpdateMatrix = exports.cacheUpdateMatrix = {
240
240
  transferBasket(customerId, {
241
241
  parameters
242
242
  }, response) {
243
+ var _response$customerInf;
243
244
  const {
244
245
  basketId
245
246
  } = response;
247
+ const transferedTo = response === null || response === void 0 ? void 0 : (_response$customerInf = response.customerInfo) === null || _response$customerInf === void 0 ? void 0 : _response$customerInf.customerId;
246
248
  return {
247
249
  // TODO: Convert invalidate to an update that removes the matching basket
248
250
  invalidate: [...(customerId && !basketId ? [invalidateCustomerBasketsQuery(customerId, parameters)] : [])],
@@ -250,7 +252,7 @@ const cacheUpdateMatrix = exports.cacheUpdateMatrix = {
250
252
  queryKey: _queryKeyHelpers.getBasket.queryKey(_objectSpread(_objectSpread({}, parameters), {}, {
251
253
  basketId
252
254
  }))
253
- }, ...(customerId && basketId ? [updateCustomerBasketsQuery(customerId, _objectSpread(_objectSpread({}, parameters), {}, {
255
+ }, ...(transferedTo && basketId ? [updateCustomerBasketsQuery(transferedTo, _objectSpread(_objectSpread({}, parameters), {}, {
254
256
  basketId
255
257
  }), response)] : [])]
256
258
  };
@@ -268,7 +268,7 @@ const cacheUpdateMatrix = exports.cacheUpdateMatrix = {
268
268
  resetPassword: noop,
269
269
  updateCustomer(customerId, {
270
270
  parameters
271
- }) {
271
+ }, response) {
272
272
  // When we update a customer, we don't know what data has changed, so we must invalidate all
273
273
  // derivative endpoints. They conveniently all start with the same path as `getCustomer`,
274
274
  // but we do NOT want to invalidate `getCustomer` itself, we want to _update_ it. (Ideally,
@@ -283,7 +283,13 @@ const cacheUpdateMatrix = exports.cacheUpdateMatrix = {
283
283
  const predicate = (0, _utils.and)((0, _utils.pathStartsWith)(path), isNotGetCustomer);
284
284
  return {
285
285
  update: [{
286
- queryKey: _queryKeyHelpers.getCustomer.queryKey(parameters)
286
+ queryKey: _queryKeyHelpers.getCustomer.queryKey(parameters),
287
+ updater: createUpdateFunction(customer => {
288
+ // The `updateCustomer` endpoint does not return exhaustive customer data. It
289
+ // is missing data for `addresses` and `paymentInstruments`, to name a few. Here
290
+ // we ensure that any customer data we have is preserved.
291
+ return _objectSpread(_objectSpread({}, customer), response);
292
+ })
287
293
  }],
288
294
  invalidate: [{
289
295
  predicate
package/hooks/useQuery.js CHANGED
@@ -93,7 +93,7 @@ const useCustomQuery = (apiOptions, queryOptions) => {
93
93
  Authorization: `Bearer ${access_token}`
94
94
  }, clientHeaders), (_options$options2 = options.options) === null || _options$options2 === void 0 ? void 0 : _options$options2.headers)
95
95
  }, options.options),
96
- clientConfig: _objectSpread({
96
+ clientConfig: _objectSpread(_objectSpread({
97
97
  parameters: {
98
98
  clientId: config.clientId,
99
99
  siteId: config.siteId,
@@ -101,7 +101,9 @@ const useCustomQuery = (apiOptions, queryOptions) => {
101
101
  shortCode: config.organizationId
102
102
  },
103
103
  proxy: config.proxy
104
- }, clientConfig)
104
+ }, clientConfig), {}, {
105
+ throwOnBadResponse: true
106
+ })
105
107
  }));
106
108
  });
107
109
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/commerce-sdk-react",
3
- "version": "2.0.0-preview.1",
3
+ "version": "2.0.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": {
@@ -45,7 +45,7 @@
45
45
  "jwt-decode": "^4.0.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@salesforce/pwa-kit-dev": "3.6.0-preview.1",
48
+ "@salesforce/pwa-kit-dev": "3.6.0",
49
49
  "@tanstack/react-query": "^4.28.0",
50
50
  "@testing-library/jest-dom": "^5.16.5",
51
51
  "@testing-library/react": "^14.0.0",
@@ -60,7 +60,7 @@
60
60
  "@types/react-helmet": "~6.1.6",
61
61
  "@types/react-router-dom": "~5.3.3",
62
62
  "cross-env": "^5.2.1",
63
- "internal-lib-build": "3.6.0-preview.1",
63
+ "internal-lib-build": "3.6.0",
64
64
  "jsonwebtoken": "^9.0.0",
65
65
  "nock": "^13.3.0",
66
66
  "nodemon": "^2.0.22",
@@ -90,5 +90,5 @@
90
90
  "publishConfig": {
91
91
  "directory": "dist"
92
92
  },
93
- "gitHead": "9c4f0ecc797e8e62c3b5a52a1586d3f80bc7e060"
93
+ "gitHead": "eb6bc596bbce102309014335bb9072f305c425f2"
94
94
  }
package/provider.js CHANGED
@@ -7,16 +7,20 @@ exports.default = exports.ConfigContext = exports.CommerceApiContext = exports.A
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _commerceSdkIsomorphic = require("commerce-sdk-isomorphic");
9
9
  var _auth = _interopRequireDefault(require("./auth"));
10
+ var _constant = require("./constant");
10
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
12
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
13
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
- /*
14
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
15
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
17
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
18
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*
14
19
  * Copyright (c) 2022, salesforce.com, inc.
15
20
  * All rights reserved.
16
21
  * SPDX-License-Identifier: BSD-3-Clause
17
22
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
18
23
  */
19
-
20
24
  /**
21
25
  * @internal
22
26
  */
@@ -111,6 +115,8 @@ const CommerceApiProvider = props => {
111
115
  throwOnBadResponse: true,
112
116
  fetchOptions
113
117
  };
118
+ const baseUrl = config.proxy.split(_constant.MOBIFY_PATH)[0];
119
+ const privateClientEndpoint = `${baseUrl}${_constant.SLAS_PRIVATE_PROXY_PATH}`;
114
120
  const apiClients = (0, _react.useMemo)(() => {
115
121
  return {
116
122
  shopperBaskets: new _commerceSdkIsomorphic.ShopperBaskets(config),
@@ -118,7 +124,9 @@ const CommerceApiProvider = props => {
118
124
  shopperCustomers: new _commerceSdkIsomorphic.ShopperCustomers(config),
119
125
  shopperExperience: new _commerceSdkIsomorphic.ShopperExperience(config),
120
126
  shopperGiftCertificates: new _commerceSdkIsomorphic.ShopperGiftCertificates(config),
121
- shopperLogin: new _commerceSdkIsomorphic.ShopperLogin(config),
127
+ shopperLogin: new _commerceSdkIsomorphic.ShopperLogin(_objectSpread(_objectSpread({}, config), {}, {
128
+ proxy: enablePWAKitPrivateClient ? privateClientEndpoint : config.proxy
129
+ })),
122
130
  shopperOrders: new _commerceSdkIsomorphic.ShopperOrders(config),
123
131
  shopperProducts: new _commerceSdkIsomorphic.ShopperProducts(config),
124
132
  shopperPromotions: new _commerceSdkIsomorphic.ShopperPromotions(config),