@salesforce/commerce-sdk-react 1.0.0-preview.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.
Files changed (143) hide show
  1. package/.eslintrc.js +10 -0
  2. package/CHANGELOG.md +35 -0
  3. package/LICENSE +14 -0
  4. package/README.md +327 -0
  5. package/auth/index.d.ts +220 -0
  6. package/auth/index.js +472 -0
  7. package/auth/storage.d.ts +48 -0
  8. package/auth/storage.js +122 -0
  9. package/components/ShopperExperience/Component/index.d.ts +17 -0
  10. package/components/ShopperExperience/Component/index.js +49 -0
  11. package/components/ShopperExperience/Page/index.d.ts +28 -0
  12. package/components/ShopperExperience/Page/index.js +97 -0
  13. package/components/ShopperExperience/Region/index.d.ts +41 -0
  14. package/components/ShopperExperience/Region/index.js +64 -0
  15. package/components/ShopperExperience/index.d.ts +5 -0
  16. package/components/ShopperExperience/index.js +49 -0
  17. package/components/ShopperExperience/prop-types.d.ts +39 -0
  18. package/components/ShopperExperience/prop-types.js +46 -0
  19. package/components/ShopperExperience/types.d.ts +8 -0
  20. package/components/ShopperExperience/types.js +5 -0
  21. package/components/index.d.ts +2 -0
  22. package/components/index.js +16 -0
  23. package/hooks/ShopperBaskets/cache.d.ts +5 -0
  24. package/hooks/ShopperBaskets/cache.js +351 -0
  25. package/hooks/ShopperBaskets/index.d.ts +3 -0
  26. package/hooks/ShopperBaskets/index.js +27 -0
  27. package/hooks/ShopperBaskets/mutation.d.ts +381 -0
  28. package/hooks/ShopperBaskets/mutation.js +380 -0
  29. package/hooks/ShopperBaskets/query.d.ts +55 -0
  30. package/hooks/ShopperBaskets/query.js +215 -0
  31. package/hooks/ShopperBaskets/queryKeyHelpers.d.ts +72 -0
  32. package/hooks/ShopperBaskets/queryKeyHelpers.js +49 -0
  33. package/hooks/ShopperContexts/cache.d.ts +5 -0
  34. package/hooks/ShopperContexts/cache.js +45 -0
  35. package/hooks/ShopperContexts/index.d.ts +3 -0
  36. package/hooks/ShopperContexts/index.js +27 -0
  37. package/hooks/ShopperContexts/mutation.d.ts +35 -0
  38. package/hooks/ShopperContexts/mutation.js +68 -0
  39. package/hooks/ShopperContexts/query.d.ts +15 -0
  40. package/hooks/ShopperContexts/query.js +59 -0
  41. package/hooks/ShopperContexts/queryKeyHelpers.d.ts +30 -0
  42. package/hooks/ShopperContexts/queryKeyHelpers.js +25 -0
  43. package/hooks/ShopperCustomers/cache.d.ts +5 -0
  44. package/hooks/ShopperCustomers/cache.js +387 -0
  45. package/hooks/ShopperCustomers/index.d.ts +3 -0
  46. package/hooks/ShopperCustomers/index.js +27 -0
  47. package/hooks/ShopperCustomers/mutation.d.ts +163 -0
  48. package/hooks/ShopperCustomers/mutation.js +203 -0
  49. package/hooks/ShopperCustomers/query.d.ts +115 -0
  50. package/hooks/ShopperCustomers/query.js +489 -0
  51. package/hooks/ShopperCustomers/queryKeyHelpers.d.ts +142 -0
  52. package/hooks/ShopperCustomers/queryKeyHelpers.js +91 -0
  53. package/hooks/ShopperExperience/index.d.ts +2 -0
  54. package/hooks/ShopperExperience/index.js +16 -0
  55. package/hooks/ShopperExperience/query.d.ts +31 -0
  56. package/hooks/ShopperExperience/query.js +104 -0
  57. package/hooks/ShopperExperience/queryKeyHelpers.d.ts +38 -0
  58. package/hooks/ShopperExperience/queryKeyHelpers.js +31 -0
  59. package/hooks/ShopperGiftCertificates/index.d.ts +2 -0
  60. package/hooks/ShopperGiftCertificates/index.js +16 -0
  61. package/hooks/ShopperGiftCertificates/query.d.ts +15 -0
  62. package/hooks/ShopperGiftCertificates/query.js +70 -0
  63. package/hooks/ShopperGiftCertificates/queryKeyHelpers.d.ts +29 -0
  64. package/hooks/ShopperGiftCertificates/queryKeyHelpers.js +25 -0
  65. package/hooks/ShopperLogin/cache.d.ts +3 -0
  66. package/hooks/ShopperLogin/cache.js +33 -0
  67. package/hooks/ShopperLogin/index.d.ts +3 -0
  68. package/hooks/ShopperLogin/index.js +27 -0
  69. package/hooks/ShopperLogin/mutation.d.ts +119 -0
  70. package/hooks/ShopperLogin/mutation.js +138 -0
  71. package/hooks/ShopperLogin/query.d.ts +45 -0
  72. package/hooks/ShopperLogin/query.js +176 -0
  73. package/hooks/ShopperLogin/queryKeyHelpers.d.ts +53 -0
  74. package/hooks/ShopperLogin/queryKeyHelpers.js +43 -0
  75. package/hooks/ShopperOrders/cache.d.ts +5 -0
  76. package/hooks/ShopperOrders/cache.js +54 -0
  77. package/hooks/ShopperOrders/index.d.ts +3 -0
  78. package/hooks/ShopperOrders/index.js +27 -0
  79. package/hooks/ShopperOrders/mutation.d.ts +54 -0
  80. package/hooks/ShopperOrders/mutation.js +83 -0
  81. package/hooks/ShopperOrders/query.d.ts +37 -0
  82. package/hooks/ShopperOrders/query.js +139 -0
  83. package/hooks/ShopperOrders/queryKeyHelpers.d.ts +50 -0
  84. package/hooks/ShopperOrders/queryKeyHelpers.js +37 -0
  85. package/hooks/ShopperProducts/index.d.ts +2 -0
  86. package/hooks/ShopperProducts/index.js +16 -0
  87. package/hooks/ShopperProducts/query.d.ts +47 -0
  88. package/hooks/ShopperProducts/query.js +178 -0
  89. package/hooks/ShopperProducts/queryKeyHelpers.d.ts +55 -0
  90. package/hooks/ShopperProducts/queryKeyHelpers.js +43 -0
  91. package/hooks/ShopperPromotions/index.d.ts +2 -0
  92. package/hooks/ShopperPromotions/index.js +16 -0
  93. package/hooks/ShopperPromotions/query.d.ts +29 -0
  94. package/hooks/ShopperPromotions/query.js +102 -0
  95. package/hooks/ShopperPromotions/queryKeyHelpers.d.ts +38 -0
  96. package/hooks/ShopperPromotions/queryKeyHelpers.js +31 -0
  97. package/hooks/ShopperSearch/index.d.ts +2 -0
  98. package/hooks/ShopperSearch/index.js +16 -0
  99. package/hooks/ShopperSearch/query.d.ts +26 -0
  100. package/hooks/ShopperSearch/query.js +99 -0
  101. package/hooks/ShopperSearch/queryKeyHelpers.d.ts +37 -0
  102. package/hooks/ShopperSearch/queryKeyHelpers.js +31 -0
  103. package/hooks/index.d.ts +18 -0
  104. package/hooks/index.js +188 -0
  105. package/hooks/types.d.ts +128 -0
  106. package/hooks/types.js +5 -0
  107. package/hooks/useAccessToken.d.ts +11 -0
  108. package/hooks/useAccessToken.js +43 -0
  109. package/hooks/useAuthContext.d.ts +9 -0
  110. package/hooks/useAuthContext.js +30 -0
  111. package/hooks/useAuthHelper.d.ts +23 -0
  112. package/hooks/useAuthHelper.js +66 -0
  113. package/hooks/useAuthorizationHeader.d.ts +9 -0
  114. package/hooks/useAuthorizationHeader.js +45 -0
  115. package/hooks/useCommerceApi.d.ts +9 -0
  116. package/hooks/useCommerceApi.js +26 -0
  117. package/hooks/useConfig.d.ts +7 -0
  118. package/hooks/useConfig.js +24 -0
  119. package/hooks/useCustomerId.d.ts +7 -0
  120. package/hooks/useCustomerId.js +38 -0
  121. package/hooks/useCustomerType.d.ts +21 -0
  122. package/hooks/useCustomerType.js +43 -0
  123. package/hooks/useEncUserId.d.ts +9 -0
  124. package/hooks/useEncUserId.js +36 -0
  125. package/hooks/useLocalStorage.d.ts +8 -0
  126. package/hooks/useLocalStorage.js +40 -0
  127. package/hooks/useMutation.d.ts +12 -0
  128. package/hooks/useMutation.js +38 -0
  129. package/hooks/useQuery.d.ts +15 -0
  130. package/hooks/useQuery.js +57 -0
  131. package/hooks/useUsid.d.ts +7 -0
  132. package/hooks/useUsid.js +34 -0
  133. package/hooks/utils.d.ts +32 -0
  134. package/hooks/utils.js +125 -0
  135. package/index.d.ts +5 -0
  136. package/index.js +40 -0
  137. package/package.json +88 -0
  138. package/provider.d.ts +36 -0
  139. package/provider.js +124 -0
  140. package/scripts/build-and-release-docs.js +48 -0
  141. package/scripts/version.js +22 -0
  142. package/utils.d.ts +5 -0
  143. package/utils.js +18 -0
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getPublicProductListsBySearchTerm = exports.getPublicProductList = exports.getProductListItem = exports.getExternalProfile = exports.getCustomerProductLists = exports.getCustomerProductListItem = exports.getCustomerProductList = exports.getCustomerPaymentInstrument = exports.getCustomerOrders = exports.getCustomerBaskets = exports.getCustomerAddress = exports.getCustomer = void 0;
7
+ var _utils = require("../utils");
8
+ /*
9
+ * Copyright (c) 2023, Salesforce, Inc.
10
+ * All rights reserved.
11
+ * SPDX-License-Identifier: BSD-3-Clause
12
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
13
+ */
14
+
15
+ // We must use a client with no parameters in order to have required/optional match the API spec
16
+
17
+ // This is defined here, rather than `types.ts`, because it relies on `Client` and `QueryKeys`,
18
+ // and making those generic would add too much complexity.
19
+
20
+ const getExternalProfile = {
21
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'externalId', 'authenticationProviderId', 'siteId']),
22
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/customers/external-profile'],
23
+ queryKey: params => [...getExternalProfile.path(params), getExternalProfile.parameters(params)]
24
+ };
25
+ exports.getExternalProfile = getExternalProfile;
26
+ const getCustomer = {
27
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'customerId', 'siteId']),
28
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/customers/', params.customerId],
29
+ queryKey: params => [...getCustomer.path(params), getCustomer.parameters(params)]
30
+ };
31
+ exports.getCustomer = getCustomer;
32
+ const getCustomerAddress = {
33
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'customerId', 'addressName', 'siteId']),
34
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/customers/', params.customerId, '/addresses/', params.addressName],
35
+ queryKey: params => [...getCustomerAddress.path(params), getCustomerAddress.parameters(params)]
36
+ };
37
+ exports.getCustomerAddress = getCustomerAddress;
38
+ const getCustomerBaskets = {
39
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'customerId', 'siteId']),
40
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/customers/', params.customerId, '/baskets'],
41
+ queryKey: params => [...getCustomerBaskets.path(params), getCustomerBaskets.parameters(params)]
42
+ };
43
+ exports.getCustomerBaskets = getCustomerBaskets;
44
+ const getCustomerOrders = {
45
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'customerId', 'crossSites', 'from', 'until', 'status', 'siteId', 'offset', 'limit']),
46
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/customers/', params.customerId, '/orders'],
47
+ queryKey: params => [...getCustomerOrders.path(params), getCustomerOrders.parameters(params)]
48
+ };
49
+ exports.getCustomerOrders = getCustomerOrders;
50
+ const getCustomerPaymentInstrument = {
51
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'customerId', 'paymentInstrumentId', 'siteId']),
52
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/customers/', params.customerId, '/payment-instruments/', params.paymentInstrumentId],
53
+ queryKey: params => [...getCustomerPaymentInstrument.path(params), getCustomerPaymentInstrument.parameters(params)]
54
+ };
55
+ exports.getCustomerPaymentInstrument = getCustomerPaymentInstrument;
56
+ const getCustomerProductLists = {
57
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'customerId', 'siteId']),
58
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/customers/', params.customerId, '/product-lists'],
59
+ queryKey: params => [...getCustomerProductLists.path(params), getCustomerProductLists.parameters(params)]
60
+ };
61
+ exports.getCustomerProductLists = getCustomerProductLists;
62
+ const getCustomerProductList = {
63
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'customerId', 'listId', 'siteId']),
64
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/customers/', params.customerId, '/product-lists/', params.listId],
65
+ queryKey: params => [...getCustomerProductList.path(params), getCustomerProductList.parameters(params)]
66
+ };
67
+ exports.getCustomerProductList = getCustomerProductList;
68
+ const getCustomerProductListItem = {
69
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'customerId', 'listId', 'itemId', 'siteId']),
70
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/customers/', params.customerId, '/product-lists/', params.listId, '/items/', params.itemId],
71
+ queryKey: params => [...getCustomerProductListItem.path(params), getCustomerProductListItem.parameters(params)]
72
+ };
73
+ exports.getCustomerProductListItem = getCustomerProductListItem;
74
+ const getPublicProductListsBySearchTerm = {
75
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'email', 'firstName', 'lastName', 'siteId']),
76
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/product-lists'],
77
+ queryKey: params => [...getPublicProductListsBySearchTerm.path(params), getPublicProductListsBySearchTerm.parameters(params)]
78
+ };
79
+ exports.getPublicProductListsBySearchTerm = getPublicProductListsBySearchTerm;
80
+ const getPublicProductList = {
81
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'listId', 'siteId']),
82
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/product-lists/', params.listId],
83
+ queryKey: params => [...getPublicProductList.path(params), getPublicProductList.parameters(params)]
84
+ };
85
+ exports.getPublicProductList = getPublicProductList;
86
+ const getProductListItem = {
87
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'listId', 'itemId', 'siteId']),
88
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/product-lists/', params.listId, '/items/', params.itemId],
89
+ queryKey: params => [...getProductListItem.path(params), getProductListItem.parameters(params)]
90
+ };
91
+ exports.getProductListItem = getProductListItem;
@@ -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,31 @@
1
+ import { UseQueryResult } from '@tanstack/react-query';
2
+ import { ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters } from '../types';
3
+ declare type Client = ApiClients['shopperExperience'];
4
+ /**
5
+ * Get Page Designer pages. The results will apply the visibility rules for each page's components, such as personalization or scheduled visibility.
6
+
7
+ Either `categoryId` or `productId` must be given in addition to `aspectTypeId`. Because only a single page-to-product and page-to-category assignment per aspect type can be authored today, the returned results contains one element at most.
8
+
9
+ **Important**: Because this resource uses the GET method, you must not pass sensitive data (payment card information, for example) and must not perform any transactional processes within the server-side scripts that are run for the page and components.
10
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
11
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
12
+ * @returns A TanStack Query query hook with data from the Shopper Experience `getPages` endpoint.
13
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-experience?meta=getPages| Salesforce Developer Center} for more information about the API endpoint.
14
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperexperience.shopperexperience-1.html#getpages | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
15
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
16
+ */
17
+ export declare const usePages: (apiOptions: NullableParameters<Argument<Client['getPages']>>, queryOptions?: ApiQueryOptions<Client['getPages']>) => UseQueryResult<DataType<Client['getPages']>>;
18
+ /**
19
+ * Get a Page Designer page based on a single page ID. The results will apply the visibility rules for the page's components, such as personalization or scheduled visibility.
20
+
21
+ **Important**: Because this resource uses the GET method, you must not pass sensitive data (payment card information, for example) and must not perform any transactional processes within the server-side scripts that are run for the page and components.
22
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
23
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
24
+ * @returns A TanStack Query query hook with data from the Shopper Experience `getPage` endpoint.
25
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-experience?meta=getPage| Salesforce Developer Center} for more information about the API endpoint.
26
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperexperience.shopperexperience-1.html#getpage | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
27
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
28
+ */
29
+ export declare const usePage: (apiOptions: NullableParameters<Argument<Client['getPage']>>, queryOptions?: ApiQueryOptions<Client['getPage']>) => UseQueryResult<DataType<Client['getPage']>>;
30
+ export {};
31
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.usePages = exports.usePage = 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
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ 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
+ 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
+ * Copyright (c) 2023, Salesforce, Inc.
17
+ * All rights reserved.
18
+ * SPDX-License-Identifier: BSD-3-Clause
19
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
20
+ */
21
+ /**
22
+ * Get Page Designer pages. The results will apply the visibility rules for each page's components, such as personalization or scheduled visibility.
23
+
24
+ Either `categoryId` or `productId` must be given in addition to `aspectTypeId`. Because only a single page-to-product and page-to-category assignment per aspect type can be authored today, the returned results contains one element at most.
25
+
26
+ **Important**: Because this resource uses the GET method, you must not pass sensitive data (payment card information, for example) and must not perform any transactional processes within the server-side scripts that are run for the page and components.
27
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
28
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
29
+ * @returns A TanStack Query query hook with data from the Shopper Experience `getPages` endpoint.
30
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-experience?meta=getPages| Salesforce Developer Center} for more information about the API endpoint.
31
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperexperience.shopperexperience-1.html#getpages | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
32
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
33
+ */
34
+ const usePages = (apiOptions, queryOptions = {}) => {
35
+ const {
36
+ shopperExperience: client
37
+ } = (0, _useCommerceApi.default)();
38
+ const methodName = 'getPages';
39
+ const requiredParameters = ['organizationId', 'aspectTypeId', 'siteId'];
40
+
41
+ // Parameters can be set in `apiOptions` or `client.clientConfig`;
42
+ // we must merge them in order to generate the correct query key.
43
+ const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
44
+ const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
45
+ // We don't use `netOptions` here because we manipulate the options in `useQuery`.
46
+ const method = /*#__PURE__*/function () {
47
+ var _ref = _asyncToGenerator(function* (options) {
48
+ return yield client[methodName](options);
49
+ });
50
+ return function method(_x) {
51
+ return _ref.apply(this, arguments);
52
+ };
53
+ }();
54
+
55
+ // For some reason, if we don't explicitly set these generic parameters, the inferred type for
56
+ // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
57
+ return (0, _useQuery.useQuery)(netOptions, queryOptions, {
58
+ method,
59
+ queryKey,
60
+ requiredParameters
61
+ });
62
+ };
63
+ /**
64
+ * Get a Page Designer page based on a single page ID. The results will apply the visibility rules for the page's components, such as personalization or scheduled visibility.
65
+
66
+ **Important**: Because this resource uses the GET method, you must not pass sensitive data (payment card information, for example) and must not perform any transactional processes within the server-side scripts that are run for the page and components.
67
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
68
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
69
+ * @returns A TanStack Query query hook with data from the Shopper Experience `getPage` endpoint.
70
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-experience?meta=getPage| Salesforce Developer Center} for more information about the API endpoint.
71
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperexperience.shopperexperience-1.html#getpage | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
72
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
73
+ */
74
+ exports.usePages = usePages;
75
+ const usePage = (apiOptions, queryOptions = {}) => {
76
+ const {
77
+ shopperExperience: client
78
+ } = (0, _useCommerceApi.default)();
79
+ const methodName = 'getPage';
80
+ const requiredParameters = ['organizationId', 'pageId', 'siteId'];
81
+
82
+ // Parameters can be set in `apiOptions` or `client.clientConfig`;
83
+ // we must merge them in order to generate the correct query key.
84
+ const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
85
+ const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
86
+ // We don't use `netOptions` here because we manipulate the options in `useQuery`.
87
+ const method = /*#__PURE__*/function () {
88
+ var _ref2 = _asyncToGenerator(function* (options) {
89
+ return yield client[methodName](options);
90
+ });
91
+ return function method(_x2) {
92
+ return _ref2.apply(this, arguments);
93
+ };
94
+ }();
95
+
96
+ // For some reason, if we don't explicitly set these generic parameters, the inferred type for
97
+ // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
98
+ return (0, _useQuery.useQuery)(netOptions, queryOptions, {
99
+ method,
100
+ queryKey,
101
+ requiredParameters
102
+ });
103
+ };
104
+ exports.usePage = usePage;
@@ -0,0 +1,38 @@
1
+ import type { ShopperExperience } from 'commerce-sdk-isomorphic';
2
+ import { Argument, ExcludeTail } from '../types';
3
+ declare type Client = ShopperExperience<{
4
+ shortCode: string;
5
+ }>;
6
+ declare type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
+ export declare type QueryKeys = {
8
+ getPages: [
9
+ '/commerce-sdk-react',
10
+ '/organizations/',
11
+ string | undefined,
12
+ '/pages',
13
+ Params<'getPages'>
14
+ ];
15
+ getPage: [
16
+ '/commerce-sdk-react',
17
+ '/organizations/',
18
+ string | undefined,
19
+ '/pages/',
20
+ string | undefined,
21
+ Params<'getPage'>
22
+ ];
23
+ };
24
+ declare type QueryKeyHelper<T extends keyof QueryKeys> = {
25
+ /**
26
+ * Reduces the given parameters (which may have additional, unknown properties) to an object
27
+ * containing *only* the properties required for an endpoint.
28
+ */
29
+ parameters: (params: Params<T>) => Params<T>;
30
+ /** Generates the path component of the query key for an endpoint. */
31
+ path: (params: Params<T>) => ExcludeTail<QueryKeys[T]>;
32
+ /** Generates the full query key for an endpoint. */
33
+ queryKey: (params: Params<T>) => QueryKeys[T];
34
+ };
35
+ export declare const getPages: QueryKeyHelper<'getPages'>;
36
+ export declare const getPage: QueryKeyHelper<'getPage'>;
37
+ export {};
38
+ //# sourceMappingURL=queryKeyHelpers.d.ts.map
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getPages = exports.getPage = void 0;
7
+ var _utils = require("../utils");
8
+ /*
9
+ * Copyright (c) 2023, Salesforce, Inc.
10
+ * All rights reserved.
11
+ * SPDX-License-Identifier: BSD-3-Clause
12
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
13
+ */
14
+
15
+ // We must use a client with no parameters in order to have required/optional match the API spec
16
+
17
+ // This is defined here, rather than `types.ts`, because it relies on `Client` and `QueryKeys`,
18
+ // and making those generic would add too much complexity.
19
+
20
+ const getPages = {
21
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'categoryId', 'productId', 'aspectTypeId', 'aspectAttributes', 'parameters', 'siteId', 'locale']),
22
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/pages'],
23
+ queryKey: params => [...getPages.path(params), getPages.parameters(params)]
24
+ };
25
+ exports.getPages = getPages;
26
+ const getPage = {
27
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'pageId', 'aspectAttributes', 'parameters', 'siteId', 'locale']),
28
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/pages/', params.pageId],
29
+ queryKey: params => [...getPage.path(params), getPage.parameters(params)]
30
+ };
31
+ exports.getPage = getPage;
@@ -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,15 @@
1
+ import { UseQueryResult } from '@tanstack/react-query';
2
+ import { ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters } from '../types';
3
+ declare type Client = ApiClients['shopperGiftCertificates'];
4
+ /**
5
+ * Action to retrieve an existing gift certificate.
6
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
7
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
8
+ * @returns A TanStack Query query hook with data from the Shopper Gift Certificates `getGiftCertificate` endpoint.
9
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-gift-certificates?meta=getGiftCertificate| Salesforce Developer Center} for more information about the API endpoint.
10
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppergiftcertificates.shoppergiftcertificates-1.html#getgiftcertificate | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
11
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
12
+ */
13
+ export declare const useGiftCertificate: (apiOptions: NullableParameters<Argument<Client['getGiftCertificate']>>, queryOptions?: ApiQueryOptions<Client['getGiftCertificate']>) => UseQueryResult<DataType<Client['getGiftCertificate']>>;
14
+ export {};
15
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useGiftCertificate = 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
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ 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; }
15
+ 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; }
16
+ 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; }
17
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
18
+ 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); }
19
+ 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); } }
20
+ 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); }); }; } /*
21
+ * Copyright (c) 2023, Salesforce, Inc.
22
+ * All rights reserved.
23
+ * SPDX-License-Identifier: BSD-3-Clause
24
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
25
+ */
26
+ /**
27
+ * Action to retrieve an existing gift certificate.
28
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
29
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
30
+ * @returns A TanStack Query query hook with data from the Shopper Gift Certificates `getGiftCertificate` endpoint.
31
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-gift-certificates?meta=getGiftCertificate| Salesforce Developer Center} for more information about the API endpoint.
32
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppergiftcertificates.shoppergiftcertificates-1.html#getgiftcertificate | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
33
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
34
+ */
35
+ const useGiftCertificate = (apiOptions, queryOptions = {}) => {
36
+ const {
37
+ shopperGiftCertificates: client
38
+ } = (0, _useCommerceApi.default)();
39
+ const methodName = 'getGiftCertificate';
40
+ const requiredParameters = ['organizationId', 'siteId'];
41
+
42
+ // Parameters can be set in `apiOptions` or `client.clientConfig`;
43
+ // we must merge them in order to generate the correct query key.
44
+ const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
45
+ const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
46
+ // We don't use `netOptions` here because we manipulate the options in `useQuery`.
47
+ const method = /*#__PURE__*/function () {
48
+ var _ref = _asyncToGenerator(function* (options) {
49
+ return yield client[methodName](options);
50
+ });
51
+ return function method(_x) {
52
+ return _ref.apply(this, arguments);
53
+ };
54
+ }();
55
+
56
+ // For some reason, if we don't explicitly set these generic parameters, the inferred type for
57
+ // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
58
+ return (0, _useQuery.useQuery)(netOptions, _objectSpread({
59
+ // !!! This is a violation of our design goal of minimal logic in the indivudal endpoint
60
+ // endpoint hooks. This is because this method is a post method, rather than GET,
61
+ // and its body contains secrets. Setting cacheTime to 0 avoids exposing the secrets in
62
+ // the shared cache.
63
+ cacheTime: 0
64
+ }, queryOptions), {
65
+ method,
66
+ queryKey,
67
+ requiredParameters
68
+ });
69
+ };
70
+ exports.useGiftCertificate = useGiftCertificate;
@@ -0,0 +1,29 @@
1
+ import type { ShopperGiftCertificates } from 'commerce-sdk-isomorphic';
2
+ import { Argument, ExcludeTail } from '../types';
3
+ declare type Client = ShopperGiftCertificates<{
4
+ shortCode: string;
5
+ }>;
6
+ declare type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
+ export declare type QueryKeys = {
8
+ getGiftCertificate: [
9
+ '/commerce-sdk-react',
10
+ '/organizations/',
11
+ string | undefined,
12
+ '/gift-certificate',
13
+ Params<'getGiftCertificate'>
14
+ ];
15
+ };
16
+ declare type QueryKeyHelper<T extends keyof QueryKeys> = {
17
+ /**
18
+ * Reduces the given parameters (which may have additional, unknown properties) to an object
19
+ * containing *only* the properties required for an endpoint.
20
+ */
21
+ parameters: (params: Params<T>) => Params<T>;
22
+ /** Generates the path component of the query key for an endpoint. */
23
+ path: (params: Params<T>) => ExcludeTail<QueryKeys[T]>;
24
+ /** Generates the full query key for an endpoint. */
25
+ queryKey: (params: Params<T>) => QueryKeys[T];
26
+ };
27
+ export declare const getGiftCertificate: QueryKeyHelper<'getGiftCertificate'>;
28
+ export {};
29
+ //# sourceMappingURL=queryKeyHelpers.d.ts.map
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getGiftCertificate = void 0;
7
+ var _utils = require("../utils");
8
+ /*
9
+ * Copyright (c) 2023, Salesforce, Inc.
10
+ * All rights reserved.
11
+ * SPDX-License-Identifier: BSD-3-Clause
12
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
13
+ */
14
+
15
+ // We must use a client with no parameters in order to have required/optional match the API spec
16
+
17
+ // This is defined here, rather than `types.ts`, because it relies on `Client` and `QueryKeys`,
18
+ // and making those generic would add too much complexity.
19
+
20
+ const getGiftCertificate = {
21
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'siteId']),
22
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/gift-certificate'],
23
+ queryKey: params => [...getGiftCertificate.path(params), getGiftCertificate.parameters(params)]
24
+ };
25
+ exports.getGiftCertificate = getGiftCertificate;
@@ -0,0 +1,3 @@
1
+ import { ApiClients, CacheUpdateMatrix } from '../types';
2
+ export declare const cacheUpdateMatrix: CacheUpdateMatrix<ApiClients['shopperLogin']>;
3
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.cacheUpdateMatrix = void 0;
7
+ /*
8
+ * Copyright (c) 2023, 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 noop = () => ({});
15
+ const cacheUpdateMatrix = {
16
+ authorizePasswordlessCustomer: noop,
17
+ logoutCustomer: () => {
18
+ return {
19
+ remove: [{
20
+ queryKey: ['/commerce-sdk-react']
21
+ }]
22
+ };
23
+ },
24
+ getAccessToken: noop,
25
+ getSessionBridgeAccessToken: noop,
26
+ getTrustedSystemAccessToken: noop,
27
+ getTrustedAgentAccessToken: noop,
28
+ resetPassword: noop,
29
+ getPasswordLessAccessToken: noop,
30
+ revokeToken: noop,
31
+ introspectToken: noop
32
+ };
33
+ exports.cacheUpdateMatrix = cacheUpdateMatrix;
@@ -0,0 +1,3 @@
1
+ export * from './mutation';
2
+ export * from './query';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _mutation = require("./mutation");
7
+ Object.keys(_mutation).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _mutation[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _mutation[key];
14
+ }
15
+ });
16
+ });
17
+ var _query = require("./query");
18
+ Object.keys(_query).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _query[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _query[key];
25
+ }
26
+ });
27
+ });