@salesforce/commerce-sdk-react 1.3.0 → 1.4.0-dev

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/auth/index.d.ts +0 -2
  3. package/auth/index.js +2 -5
  4. package/hooks/ShopperBaskets/paramKeys.d.ts +9 -0
  5. package/hooks/ShopperBaskets/paramKeys.js +25 -0
  6. package/hooks/ShopperBaskets/query.js +36 -5
  7. package/hooks/ShopperBaskets/queryKeyHelpers.d.ts +0 -5
  8. package/hooks/ShopperBaskets/queryKeyHelpers.js +22 -10
  9. package/hooks/ShopperContexts/paramKeys.d.ts +5 -0
  10. package/hooks/ShopperContexts/paramKeys.js +17 -0
  11. package/hooks/ShopperContexts/query.js +13 -1
  12. package/hooks/ShopperContexts/queryKeyHelpers.d.ts +0 -5
  13. package/hooks/ShopperContexts/queryKeyHelpers.js +6 -2
  14. package/hooks/ShopperCustomers/cache.js +7 -2
  15. package/hooks/ShopperCustomers/paramKeys.d.ts +26 -0
  16. package/hooks/ShopperCustomers/paramKeys.js +44 -0
  17. package/hooks/ShopperCustomers/query.js +73 -16
  18. package/hooks/ShopperCustomers/queryKeyHelpers.d.ts +0 -6
  19. package/hooks/ShopperCustomers/queryKeyHelpers.js +58 -28
  20. package/hooks/ShopperExperience/paramKeys.d.ts +6 -0
  21. package/hooks/ShopperExperience/paramKeys.js +19 -0
  22. package/hooks/ShopperExperience/query.js +18 -2
  23. package/hooks/ShopperExperience/queryKeyHelpers.d.ts +0 -5
  24. package/hooks/ShopperExperience/queryKeyHelpers.js +10 -4
  25. package/hooks/ShopperGiftCertificates/paramKeys.d.ts +5 -0
  26. package/hooks/ShopperGiftCertificates/paramKeys.js +17 -0
  27. package/hooks/ShopperGiftCertificates/query.js +8 -1
  28. package/hooks/ShopperGiftCertificates/queryKeyHelpers.d.ts +0 -5
  29. package/hooks/ShopperGiftCertificates/queryKeyHelpers.js +6 -2
  30. package/hooks/ShopperLogin/paramKeys.d.ts +7 -0
  31. package/hooks/ShopperLogin/paramKeys.js +21 -0
  32. package/hooks/ShopperLogin/query.js +24 -3
  33. package/hooks/ShopperLogin/queryKeyHelpers.d.ts +0 -5
  34. package/hooks/ShopperLogin/queryKeyHelpers.js +14 -6
  35. package/hooks/ShopperOrders/paramKeys.d.ts +7 -0
  36. package/hooks/ShopperOrders/paramKeys.js +21 -0
  37. package/hooks/ShopperOrders/query.js +24 -3
  38. package/hooks/ShopperOrders/queryKeyHelpers.d.ts +0 -5
  39. package/hooks/ShopperOrders/queryKeyHelpers.js +14 -6
  40. package/hooks/ShopperProducts/paramKeys.d.ts +8 -0
  41. package/hooks/ShopperProducts/paramKeys.js +23 -0
  42. package/hooks/ShopperProducts/query.js +30 -4
  43. package/hooks/ShopperProducts/queryKeyHelpers.d.ts +0 -5
  44. package/hooks/ShopperProducts/queryKeyHelpers.js +18 -8
  45. package/hooks/ShopperPromotions/paramKeys.d.ts +6 -0
  46. package/hooks/ShopperPromotions/paramKeys.js +19 -0
  47. package/hooks/ShopperPromotions/query.js +18 -2
  48. package/hooks/ShopperPromotions/queryKeyHelpers.d.ts +0 -5
  49. package/hooks/ShopperPromotions/queryKeyHelpers.js +10 -4
  50. package/hooks/ShopperSearch/paramKeys.d.ts +6 -0
  51. package/hooks/ShopperSearch/paramKeys.js +18 -0
  52. package/hooks/ShopperSearch/query.js +16 -2
  53. package/hooks/ShopperSearch/queryKeyHelpers.d.ts +0 -5
  54. package/hooks/ShopperSearch/queryKeyHelpers.js +10 -4
  55. package/hooks/ShopperSeo/index.d.ts +2 -0
  56. package/hooks/ShopperSeo/index.js +16 -0
  57. package/hooks/ShopperSeo/paramKeys.d.ts +5 -0
  58. package/hooks/ShopperSeo/paramKeys.js +17 -0
  59. package/hooks/ShopperSeo/query.d.ts +20 -0
  60. package/hooks/ShopperSeo/query.js +74 -0
  61. package/hooks/ShopperSeo/queryKeyHelpers.d.ts +24 -0
  62. package/hooks/ShopperSeo/queryKeyHelpers.js +28 -0
  63. package/hooks/index.d.ts +1 -0
  64. package/hooks/index.js +12 -0
  65. package/hooks/types.d.ts +2 -1
  66. package/hooks/useLocalStorage.d.ts +0 -1
  67. package/hooks/useLocalStorage.js +30 -20
  68. package/hooks/utils.d.ts +2 -0
  69. package/hooks/utils.js +11 -2
  70. package/package.json +5 -5
  71. package/provider.js +2 -1
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getPromotionsForCampaign = exports.getPromotions = void 0;
7
7
  var _utils = require("../utils");
8
+ var _paramKeys = _interopRequireDefault(require("./paramKeys"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
10
  /*
9
11
  * Copyright (c) 2023, Salesforce, Inc.
10
12
  * All rights reserved.
@@ -18,12 +20,16 @@ var _utils = require("../utils");
18
20
  // and making those generic would add too much complexity.
19
21
 
20
22
  const getPromotions = exports.getPromotions = {
21
- parameters: params => (0, _utils.pick)(params, ['organizationId', 'siteId', 'ids', 'locale']),
22
23
  path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/promotions'],
23
- queryKey: params => [...getPromotions.path(params), getPromotions.parameters(params)]
24
+ queryKey: params => {
25
+ const paramKeys = [..._paramKeys.default['getPromotions'], ...(0, _utils.getCustomKeys)(params)];
26
+ return [...getPromotions.path(params), (0, _utils.pick)(params, paramKeys)];
27
+ }
24
28
  };
25
29
  const getPromotionsForCampaign = exports.getPromotionsForCampaign = {
26
- parameters: params => (0, _utils.pick)(params, ['organizationId', 'campaignId', 'siteId', 'startDate', 'endDate', 'currency']),
27
30
  path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/promotions/campaigns/', params.campaignId],
28
- queryKey: params => [...getPromotionsForCampaign.path(params), getPromotionsForCampaign.parameters(params)]
31
+ queryKey: params => {
32
+ const paramKeys = [..._paramKeys.default['getPromotionsForCampaign'], ...(0, _utils.getCustomKeys)(params)];
33
+ return [...getPromotionsForCampaign.path(params), (0, _utils.pick)(params, paramKeys)];
34
+ }
29
35
  };
@@ -0,0 +1,6 @@
1
+ declare const _default: {
2
+ productSearch: readonly ["organizationId", "siteId", "q", "refine", "sort", "currency", "locale", "expand", "offset", "limit"];
3
+ getSearchSuggestions: readonly ["organizationId", "siteId", "q", "limit", "currency", "locale"];
4
+ };
5
+ export default _default;
6
+ //# sourceMappingURL=paramKeys.d.ts.map
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ /*
8
+ * Copyright (c) 2024, Salesforce, Inc.
9
+ * All rights reserved.
10
+ * SPDX-License-Identifier: BSD-3-Clause
11
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
12
+ */
13
+ const productSearch = ['organizationId', 'siteId', 'q', 'refine', 'sort', 'currency', 'locale', 'expand', 'offset', 'limit'];
14
+ const getSearchSuggestions = ['organizationId', 'siteId', 'q', 'limit', 'currency', 'locale'];
15
+ var _default = exports.default = {
16
+ productSearch,
17
+ getSearchSuggestions
18
+ };
@@ -8,9 +8,15 @@ var _useCommerceApi = _interopRequireDefault(require("../useCommerceApi"));
8
8
  var _useQuery = require("../useQuery");
9
9
  var _utils = require("../utils");
10
10
  var queryKeyHelpers = _interopRequireWildcard(require("./queryKeyHelpers"));
11
+ var _paramKeys = _interopRequireDefault(require("./paramKeys"));
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 && Object.prototype.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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ 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; }
16
+ 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; }
17
+ 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; }
18
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
19
+ 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
20
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
15
21
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } /*
16
22
  * Copyright (c) 2023, Salesforce, Inc.
@@ -42,6 +48,8 @@ const useProductSearch = (apiOptions, queryOptions = {}) => {
42
48
  // Parameters can be set in `apiOptions` or `client.clientConfig`;
43
49
  // we must merge them in order to generate the correct query key.
44
50
  const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
51
+ const paramKeys = [..._paramKeys.default[methodName], ...(0, _utils.getCustomKeys)(netOptions.parameters)];
52
+ const parameters = (0, _utils.pick)(netOptions.parameters, paramKeys);
45
53
  const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
46
54
  // We don't use `netOptions` here because we manipulate the options in `useQuery`.
47
55
  const method = /*#__PURE__*/function () {
@@ -55,7 +63,9 @@ const useProductSearch = (apiOptions, queryOptions = {}) => {
55
63
 
56
64
  // For some reason, if we don't explicitly set these generic parameters, the inferred type for
57
65
  // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
58
- return (0, _useQuery.useQuery)(netOptions, queryOptions, {
66
+ return (0, _useQuery.useQuery)(_objectSpread(_objectSpread({}, netOptions), {}, {
67
+ parameters
68
+ }), queryOptions, {
59
69
  method,
60
70
  queryKey,
61
71
  requiredParameters
@@ -85,6 +95,8 @@ const useSearchSuggestions = (apiOptions, queryOptions = {}) => {
85
95
  // Parameters can be set in `apiOptions` or `client.clientConfig`;
86
96
  // we must merge them in order to generate the correct query key.
87
97
  const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
98
+ const paramKeys = [..._paramKeys.default[methodName], ...(0, _utils.getCustomKeys)(netOptions.parameters)];
99
+ const parameters = (0, _utils.pick)(netOptions.parameters, paramKeys);
88
100
  const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
89
101
  // We don't use `netOptions` here because we manipulate the options in `useQuery`.
90
102
  const method = /*#__PURE__*/function () {
@@ -98,7 +110,9 @@ const useSearchSuggestions = (apiOptions, queryOptions = {}) => {
98
110
 
99
111
  // For some reason, if we don't explicitly set these generic parameters, the inferred type for
100
112
  // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
101
- return (0, _useQuery.useQuery)(netOptions, queryOptions, {
113
+ return (0, _useQuery.useQuery)(_objectSpread(_objectSpread({}, netOptions), {}, {
114
+ parameters
115
+ }), queryOptions, {
102
116
  method,
103
117
  queryKey,
104
118
  requiredParameters
@@ -21,11 +21,6 @@ export type QueryKeys = {
21
21
  ];
22
22
  };
23
23
  type QueryKeyHelper<T extends keyof QueryKeys> = {
24
- /**
25
- * Reduces the given parameters (which may have additional, unknown properties) to an object
26
- * containing *only* the properties required for an endpoint.
27
- */
28
- parameters: (params: Params<T>) => Params<T>;
29
24
  /** Generates the path component of the query key for an endpoint. */
30
25
  path: (params: Params<T>) => ExcludeTail<QueryKeys[T]>;
31
26
  /** Generates the full query key for an endpoint. */
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.productSearch = exports.getSearchSuggestions = void 0;
7
7
  var _utils = require("../utils");
8
+ var _paramKeys = _interopRequireDefault(require("./paramKeys"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
10
  /*
9
11
  * Copyright (c) 2023, Salesforce, Inc.
10
12
  * All rights reserved.
@@ -18,12 +20,16 @@ var _utils = require("../utils");
18
20
  // and making those generic would add too much complexity.
19
21
 
20
22
  const productSearch = exports.productSearch = {
21
- parameters: params => (0, _utils.pick)(params, ['organizationId', 'siteId', 'q', 'refine', 'sort', 'currency', 'locale', 'expand', 'offset', 'limit']),
22
23
  path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/product-search'],
23
- queryKey: params => [...productSearch.path(params), productSearch.parameters(params)]
24
+ queryKey: params => {
25
+ const paramKeys = [..._paramKeys.default['productSearch'], ...(0, _utils.getCustomKeys)(params)];
26
+ return [...productSearch.path(params), (0, _utils.pick)(params, paramKeys)];
27
+ }
24
28
  };
25
29
  const getSearchSuggestions = exports.getSearchSuggestions = {
26
- parameters: params => (0, _utils.pick)(params, ['organizationId', 'siteId', 'q', 'limit', 'currency', 'locale']),
27
30
  path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/search-suggestions'],
28
- queryKey: params => [...getSearchSuggestions.path(params), getSearchSuggestions.parameters(params)]
31
+ queryKey: params => {
32
+ const paramKeys = [..._paramKeys.default['getSearchSuggestions'], ...(0, _utils.getCustomKeys)(params)];
33
+ return [...getSearchSuggestions.path(params), (0, _utils.pick)(params, paramKeys)];
34
+ }
29
35
  };
@@ -0,0 +1,2 @@
1
+ export * from './query';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _query = require("./query");
7
+ Object.keys(_query).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _query[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _query[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ getUrlMapping: readonly ["organizationId", "urlSegment", "siteId", "locale"];
3
+ };
4
+ export default _default;
5
+ //# sourceMappingURL=paramKeys.d.ts.map
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ /*
8
+ * Copyright (c) 2024, Salesforce, Inc.
9
+ * All rights reserved.
10
+ * SPDX-License-Identifier: BSD-3-Clause
11
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
12
+ */
13
+
14
+ const getUrlMapping = ['organizationId', 'urlSegment', 'siteId', 'locale'];
15
+ var _default = exports.default = {
16
+ getUrlMapping
17
+ };
@@ -0,0 +1,20 @@
1
+ import { UseQueryResult } from '@tanstack/react-query';
2
+ import { ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters } from '../types';
3
+ type Client = ApiClients['shopperSeo'];
4
+ /**
5
+ * Gets URL mapping information for a URL that a shopper clicked or typed in.
6
+ *
7
+ * The mapping information is based on URL rules and redirects set up in Business Manager.
8
+ * For more information about prerequisites and sample usage, see [URL Resolution](https://developer.salesforce.com/docs/commerce/commerce-api/guide/url-resolution.html). You can customize the behavior of this endpoint by using hooks.
9
+ * @group ShopperSeo
10
+ * @category Query
11
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
12
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
13
+ * @returns A TanStack Query query hook with data from the Shopper Seo `getUrlMapping` endpoint.
14
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-seo?meta=getUrlMapping| Salesforce Developer Center} for more information about the API endpoint.
15
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperseo.shopperseo-1.html#geturlmapping | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
16
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
17
+ */
18
+ export declare const useUrlMapping: (apiOptions: NullableParameters<Argument<Client['getUrlMapping']>>, queryOptions?: ApiQueryOptions<Client['getUrlMapping']>) => UseQueryResult<DataType<Client['getUrlMapping']>>;
19
+ export {};
20
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useUrlMapping = void 0;
7
+ var _useCommerceApi = _interopRequireDefault(require("../useCommerceApi"));
8
+ var _useQuery = require("../useQuery");
9
+ var _utils = require("../utils");
10
+ var queryKeyHelpers = _interopRequireWildcard(require("./queryKeyHelpers"));
11
+ var _paramKeys = _interopRequireDefault(require("./paramKeys"));
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); }
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 && Object.prototype.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; }
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ 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; }
16
+ 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; }
17
+ 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; }
18
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
19
+ 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); }
20
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
21
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } /*
22
+ * Copyright (c) 2024, Salesforce, Inc.
23
+ * All rights reserved.
24
+ * SPDX-License-Identifier: BSD-3-Clause
25
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
26
+ */
27
+ /**
28
+ * Gets URL mapping information for a URL that a shopper clicked or typed in.
29
+ *
30
+ * The mapping information is based on URL rules and redirects set up in Business Manager.
31
+ * For more information about prerequisites and sample usage, see [URL Resolution](https://developer.salesforce.com/docs/commerce/commerce-api/guide/url-resolution.html). You can customize the behavior of this endpoint by using hooks.
32
+ * @group ShopperSeo
33
+ * @category Query
34
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
35
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
36
+ * @returns A TanStack Query query hook with data from the Shopper Seo `getUrlMapping` endpoint.
37
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-seo?meta=getUrlMapping| Salesforce Developer Center} for more information about the API endpoint.
38
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperseo.shopperseo-1.html#geturlmapping | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
39
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
40
+ */
41
+ const useUrlMapping = (apiOptions, queryOptions = {}) => {
42
+ const {
43
+ shopperSeo: client
44
+ } = (0, _useCommerceApi.default)();
45
+ const methodName = 'getUrlMapping';
46
+ const requiredParameters = ['organizationId', 'siteId'];
47
+
48
+ // Parameters can be set in `apiOptions` or `client.clientConfig`;
49
+ // we must merge them in order to generate the correct query key.
50
+ const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
51
+ const paramKeys = [..._paramKeys.default[methodName], ...(0, _utils.getCustomKeys)(netOptions.parameters)];
52
+ const parameters = (0, _utils.pick)(netOptions.parameters, paramKeys);
53
+ const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
54
+ // We don't use `netOptions` here because we manipulate the options in `useQuery`.
55
+ const method = /*#__PURE__*/function () {
56
+ var _ref = _asyncToGenerator(function* (options) {
57
+ return yield client[methodName](options);
58
+ });
59
+ return function method(_x) {
60
+ return _ref.apply(this, arguments);
61
+ };
62
+ }();
63
+
64
+ // For some reason, if we don't explicitly set these generic parameters, the inferred type for
65
+ // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
66
+ return (0, _useQuery.useQuery)(_objectSpread(_objectSpread({}, netOptions), {}, {
67
+ parameters
68
+ }), queryOptions, {
69
+ method,
70
+ queryKey,
71
+ requiredParameters
72
+ });
73
+ };
74
+ exports.useUrlMapping = useUrlMapping;
@@ -0,0 +1,24 @@
1
+ import type { ShopperSeo } from 'commerce-sdk-isomorphic';
2
+ import { Argument, ExcludeTail } from '../types';
3
+ type Client = ShopperSeo<{
4
+ shortCode: string;
5
+ }>;
6
+ type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
+ export type QueryKeys = {
8
+ getUrlMapping: [
9
+ '/commerce-sdk-react',
10
+ '/organizations/',
11
+ string | undefined,
12
+ '/url-mapping',
13
+ Params<'getUrlMapping'>
14
+ ];
15
+ };
16
+ type QueryKeyHelper<T extends keyof QueryKeys> = {
17
+ /** Generates the path component of the query key for an endpoint. */
18
+ path: (params: Params<T>) => ExcludeTail<QueryKeys[T]>;
19
+ /** Generates the full query key for an endpoint. */
20
+ queryKey: (params: Params<T>) => QueryKeys[T];
21
+ };
22
+ export declare const getUrlMapping: QueryKeyHelper<'getUrlMapping'>;
23
+ export {};
24
+ //# sourceMappingURL=queryKeyHelpers.d.ts.map
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getUrlMapping = void 0;
7
+ var _utils = require("../utils");
8
+ var _paramKeys = _interopRequireDefault(require("./paramKeys"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ /*
11
+ * Copyright (c) 2024, Salesforce, Inc.
12
+ * All rights reserved.
13
+ * SPDX-License-Identifier: BSD-3-Clause
14
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
15
+ */
16
+
17
+ // We must use a client with no parameters in order to have required/optional match the API spec
18
+
19
+ // This is defined here, rather than `types.ts`, because it relies on `Client` and `QueryKeys`,
20
+ // and making those generic would add too much complexity.
21
+
22
+ const getUrlMapping = exports.getUrlMapping = {
23
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/url-mapping'],
24
+ queryKey: params => {
25
+ const paramKeys = [..._paramKeys.default['getUrlMapping'], ...(0, _utils.getCustomKeys)(params)];
26
+ return [...getUrlMapping.path(params), (0, _utils.pick)(params, paramKeys)];
27
+ }
28
+ };
package/hooks/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export * from './ShopperOrders';
8
8
  export * from './ShopperProducts';
9
9
  export * from './ShopperPromotions';
10
10
  export * from './ShopperSearch';
11
+ export * from './ShopperSeo';
11
12
  export * from './useAuthHelper';
12
13
  export { default as useAccessToken } from './useAccessToken';
13
14
  export { default as useCommerceApi } from './useCommerceApi';
package/hooks/index.js CHANGED
@@ -167,6 +167,18 @@ Object.keys(_ShopperSearch).forEach(function (key) {
167
167
  }
168
168
  });
169
169
  });
170
+ var _ShopperSeo = require("./ShopperSeo");
171
+ Object.keys(_ShopperSeo).forEach(function (key) {
172
+ if (key === "default" || key === "__esModule") return;
173
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
174
+ if (key in exports && exports[key] === _ShopperSeo[key]) return;
175
+ Object.defineProperty(exports, key, {
176
+ enumerable: true,
177
+ get: function () {
178
+ return _ShopperSeo[key];
179
+ }
180
+ });
181
+ });
170
182
  var _useAuthHelper = require("./useAuthHelper");
171
183
  Object.keys(_useAuthHelper).forEach(function (key) {
172
184
  if (key === "default" || key === "__esModule") return;
package/hooks/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { InvalidateQueryFilters, QueryFilters, Updater, UseQueryOptions } from '@tanstack/react-query';
2
- import { ShopperBaskets, ShopperContexts, ShopperCustomers, ShopperExperience, ShopperGiftCertificates, ShopperLogin, ShopperOrders, ShopperProducts, ShopperPromotions, ShopperSearch } from 'commerce-sdk-isomorphic';
2
+ import { ShopperBaskets, ShopperContexts, ShopperCustomers, ShopperExperience, ShopperGiftCertificates, ShopperLogin, ShopperOrders, ShopperProducts, ShopperPromotions, ShopperSearch, ShopperSeo } from 'commerce-sdk-isomorphic';
3
3
  /** Makes a type easier to read. */
4
4
  export type Prettify<T extends object> = NonNullable<Pick<T, keyof T>>;
5
5
  /**
@@ -55,6 +55,7 @@ export interface ApiClients {
55
55
  shopperProducts: ShopperProducts<ApiClientConfigParams>;
56
56
  shopperPromotions: ShopperPromotions<ApiClientConfigParams>;
57
57
  shopperSearch: ShopperSearch<ApiClientConfigParams>;
58
+ shopperSeo: ShopperSeo<ApiClientConfigParams>;
58
59
  }
59
60
  export type ApiClient = ApiClients[keyof ApiClients];
60
61
  /**
@@ -1,7 +1,6 @@
1
1
  type Value = string | null;
2
2
  /**
3
3
  * @internal
4
- *
5
4
  */
6
5
  declare function useLocalStorage(key: string): Value;
7
6
  export default useLocalStorage;
@@ -14,27 +14,37 @@ var _react = require("react");
14
14
 
15
15
  /**
16
16
  * @internal
17
- *
17
+ */
18
+ const readValue = key => {
19
+ // TODO: Use detectLocalStorageAvailable when app can better handle clients without storage
20
+ if (typeof window === 'undefined') {
21
+ return null;
22
+ }
23
+ return window.localStorage.getItem(key);
24
+ };
25
+
26
+ /**
27
+ * @internal
28
+ */
29
+ const subscribeToLocalStorage = callback => {
30
+ window.addEventListener('storage', callback);
31
+ return () => window.removeEventListener('storage', callback);
32
+ };
33
+
34
+ /**
35
+ * @internal
36
+ */
37
+ const getLocalStorageServerSnapshot = () => {
38
+ // local storage is not available on the server
39
+ return null;
40
+ };
41
+
42
+ /**
43
+ * @internal
18
44
  */
19
45
  function useLocalStorage(key) {
20
- const readValue = () => {
21
- // TODO: Use detectLocalStorageAvailable when app can better handle clients without storage
22
- if (typeof window === 'undefined') {
23
- return null;
24
- }
25
- return window.localStorage.getItem(key);
26
- };
27
- const [storedValue, setStoredValue] = (0, _react.useState)(readValue);
28
- const handleStorageChange = event => {
29
- if (event.key !== key) {
30
- return;
31
- }
32
- setStoredValue(readValue());
33
- };
34
- (0, _react.useEffect)(() => {
35
- window.addEventListener('storage', handleStorageChange);
36
- return () => window.removeEventListener('storage', handleStorageChange);
37
- }, []);
38
- return storedValue;
46
+ const getLocalStorageSnapshot = () => readValue(key);
47
+ const store = (0, _react.useSyncExternalStore)(subscribeToLocalStorage, getLocalStorageSnapshot, getLocalStorageServerSnapshot);
48
+ return store;
39
49
  }
40
50
  var _default = exports.default = useLocalStorage;
package/hooks/utils.d.ts CHANGED
@@ -29,4 +29,6 @@ export declare const omitNullableParameters: <T extends {
29
29
  }>(obj: T) => OmitNullableParameters<T>;
30
30
  /** Simple deep clone utility */
31
31
  export declare const clone: <T>(val: T) => T;
32
+ /** get a list of custom key starting with c_**/
33
+ export declare const getCustomKeys: <T extends object>(obj: T) => `c_${string}`[];
32
34
  //# sourceMappingURL=utils.d.ts.map
package/hooks/utils.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.updateCache = exports.pick = exports.pathStartsWith = exports.omitNullableParameters = exports.omitNullable = exports.mergeOptions = exports.isObject = exports.hasAllKeys = exports.clone = exports.and = exports.NotImplementedError = void 0;
6
+ exports.updateCache = exports.pick = exports.pathStartsWith = exports.omitNullableParameters = exports.omitNullable = exports.mergeOptions = exports.isObject = exports.hasAllKeys = exports.getCustomKeys = exports.clone = exports.and = exports.NotImplementedError = void 0;
7
7
  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; }
8
8
  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; }
9
9
  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; }
@@ -122,4 +122,13 @@ const clone = val => {
122
122
  const entries = Object.entries(val).map(([k, v]) => [k, clone(v)]);
123
123
  return Object.fromEntries(entries);
124
124
  };
125
- exports.clone = clone;
125
+
126
+ /** get a list of custom key starting with c_**/
127
+ exports.clone = clone;
128
+ const getCustomKeys = obj => {
129
+ if (typeof obj !== 'object' || obj === null) {
130
+ throw new Error('Invalid input. Expecting an object as an input.');
131
+ }
132
+ return Object.keys(obj).filter(key => key.startsWith('c_'));
133
+ };
134
+ exports.getCustomKeys = getCustomKeys;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/commerce-sdk-react",
3
- "version": "1.3.0",
3
+ "version": "1.4.0-dev",
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": {
@@ -40,12 +40,12 @@
40
40
  "version": "node ./scripts/version.js"
41
41
  },
42
42
  "dependencies": {
43
- "commerce-sdk-isomorphic": "^1.10.4",
43
+ "commerce-sdk-isomorphic": "^1.12.0",
44
44
  "js-cookie": "^3.0.1",
45
45
  "jwt-decode": "^4.0.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@salesforce/pwa-kit-dev": "3.4.0",
48
+ "@salesforce/pwa-kit-dev": "3.5.0-alpha.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",
@@ -59,7 +59,7 @@
59
59
  "@types/react-helmet": "~6.1.6",
60
60
  "@types/react-router-dom": "~5.3.3",
61
61
  "cross-env": "^5.2.1",
62
- "internal-lib-build": "3.4.0",
62
+ "internal-lib-build": "3.5.0-alpha.0",
63
63
  "jsonwebtoken": "^9.0.0",
64
64
  "nock": "^13.3.0",
65
65
  "nodemon": "^2.0.22",
@@ -89,5 +89,5 @@
89
89
  "publishConfig": {
90
90
  "directory": "dist"
91
91
  },
92
- "gitHead": "acb019e60609a5e5ef11ba40aedfa94beee4e515"
92
+ "gitHead": "0edd6b2ea26b9c23502755b6ccc7316a538a4c7a"
93
93
  }
package/provider.js CHANGED
@@ -105,7 +105,8 @@ const CommerceApiProvider = props => {
105
105
  shopperOrders: new _commerceSdkIsomorphic.ShopperOrders(config),
106
106
  shopperProducts: new _commerceSdkIsomorphic.ShopperProducts(config),
107
107
  shopperPromotions: new _commerceSdkIsomorphic.ShopperPromotions(config),
108
- shopperSearch: new _commerceSdkIsomorphic.ShopperSearch(config)
108
+ shopperSearch: new _commerceSdkIsomorphic.ShopperSearch(config),
109
+ shopperSeo: new _commerceSdkIsomorphic.ShopperSeo(config)
109
110
  };
110
111
  }, [clientId, organizationId, shortCode, siteId, proxy, fetchOptions, locale, currency, headers === null || headers === void 0 ? void 0 : headers['correlation-id']]);
111
112
  const auth = (0, _react.useMemo)(() => {