@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,215 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useTaxesFromBasket = exports.useShippingMethodsForShipment = exports.usePriceBooksForBasket = exports.usePaymentMethodsForBasket = exports.useBasket = 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
+ * Gets a basket.
23
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
24
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
25
+ * @returns A TanStack Query query hook with data from the Shopper Baskets `getBasket` endpoint.
26
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-baskets?meta=getBasket| Salesforce Developer Center} for more information about the API endpoint.
27
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperbaskets.shopperbaskets-1.html#getbasket | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
28
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
29
+ */
30
+ const useBasket = (apiOptions, queryOptions = {}) => {
31
+ const {
32
+ shopperBaskets: client
33
+ } = (0, _useCommerceApi.default)();
34
+ const methodName = 'getBasket';
35
+ const requiredParameters = ['organizationId', 'basketId', 'siteId'];
36
+
37
+ // Parameters can be set in `apiOptions` or `client.clientConfig`;
38
+ // we must merge them in order to generate the correct query key.
39
+ const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
40
+ const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
41
+ // We don't use `netOptions` here because we manipulate the options in `useQuery`.
42
+ const method = /*#__PURE__*/function () {
43
+ var _ref = _asyncToGenerator(function* (options) {
44
+ return yield client[methodName](options);
45
+ });
46
+ return function method(_x) {
47
+ return _ref.apply(this, arguments);
48
+ };
49
+ }();
50
+
51
+ // For some reason, if we don't explicitly set these generic parameters, the inferred type for
52
+ // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
53
+ return (0, _useQuery.useQuery)(netOptions, queryOptions, {
54
+ method,
55
+ queryKey,
56
+ requiredParameters
57
+ });
58
+ };
59
+ /**
60
+ * Gets applicable payment methods for an existing basket considering the open payment amount only.
61
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
62
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
63
+ * @returns A TanStack Query query hook with data from the Shopper Baskets `getPaymentMethodsForBasket` endpoint.
64
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-baskets?meta=getPaymentMethodsForBasket| Salesforce Developer Center} for more information about the API endpoint.
65
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperbaskets.shopperbaskets-1.html#getpaymentmethodsforbasket | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
66
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
67
+ */
68
+ exports.useBasket = useBasket;
69
+ const usePaymentMethodsForBasket = (apiOptions, queryOptions = {}) => {
70
+ const {
71
+ shopperBaskets: client
72
+ } = (0, _useCommerceApi.default)();
73
+ const methodName = 'getPaymentMethodsForBasket';
74
+ const requiredParameters = ['organizationId', 'basketId', 'siteId'];
75
+
76
+ // Parameters can be set in `apiOptions` or `client.clientConfig`;
77
+ // we must merge them in order to generate the correct query key.
78
+ const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
79
+ const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
80
+ // We don't use `netOptions` here because we manipulate the options in `useQuery`.
81
+ const method = /*#__PURE__*/function () {
82
+ var _ref2 = _asyncToGenerator(function* (options) {
83
+ return yield client[methodName](options);
84
+ });
85
+ return function method(_x2) {
86
+ return _ref2.apply(this, arguments);
87
+ };
88
+ }();
89
+
90
+ // For some reason, if we don't explicitly set these generic parameters, the inferred type for
91
+ // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
92
+ return (0, _useQuery.useQuery)(netOptions, queryOptions, {
93
+ method,
94
+ queryKey,
95
+ requiredParameters
96
+ });
97
+ };
98
+ /**
99
+ * Gets applicable price books for an existing basket.
100
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
101
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
102
+ * @returns A TanStack Query query hook with data from the Shopper Baskets `getPriceBooksForBasket` endpoint.
103
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-baskets?meta=getPriceBooksForBasket| Salesforce Developer Center} for more information about the API endpoint.
104
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperbaskets.shopperbaskets-1.html#getpricebooksforbasket | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
105
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
106
+ */
107
+ exports.usePaymentMethodsForBasket = usePaymentMethodsForBasket;
108
+ const usePriceBooksForBasket = (apiOptions, queryOptions = {}) => {
109
+ const {
110
+ shopperBaskets: client
111
+ } = (0, _useCommerceApi.default)();
112
+ const methodName = 'getPriceBooksForBasket';
113
+ const requiredParameters = ['organizationId', 'basketId', 'siteId'];
114
+
115
+ // Parameters can be set in `apiOptions` or `client.clientConfig`;
116
+ // we must merge them in order to generate the correct query key.
117
+ const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
118
+ const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
119
+ // We don't use `netOptions` here because we manipulate the options in `useQuery`.
120
+ const method = /*#__PURE__*/function () {
121
+ var _ref3 = _asyncToGenerator(function* (options) {
122
+ return yield client[methodName](options);
123
+ });
124
+ return function method(_x3) {
125
+ return _ref3.apply(this, arguments);
126
+ };
127
+ }();
128
+
129
+ // For some reason, if we don't explicitly set these generic parameters, the inferred type for
130
+ // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
131
+ return (0, _useQuery.useQuery)(netOptions, queryOptions, {
132
+ method,
133
+ queryKey,
134
+ requiredParameters
135
+ });
136
+ };
137
+ /**
138
+ * Gets the applicable shipping methods for a certain shipment of a basket.
139
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
140
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
141
+ * @returns A TanStack Query query hook with data from the Shopper Baskets `getShippingMethodsForShipment` endpoint.
142
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-baskets?meta=getShippingMethodsForShipment| Salesforce Developer Center} for more information about the API endpoint.
143
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperbaskets.shopperbaskets-1.html#getshippingmethodsforshipment | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
144
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
145
+ */
146
+ exports.usePriceBooksForBasket = usePriceBooksForBasket;
147
+ const useShippingMethodsForShipment = (apiOptions, queryOptions = {}) => {
148
+ const {
149
+ shopperBaskets: client
150
+ } = (0, _useCommerceApi.default)();
151
+ const methodName = 'getShippingMethodsForShipment';
152
+ const requiredParameters = ['organizationId', 'basketId', 'shipmentId', 'siteId'];
153
+
154
+ // Parameters can be set in `apiOptions` or `client.clientConfig`;
155
+ // we must merge them in order to generate the correct query key.
156
+ const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
157
+ const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
158
+ // We don't use `netOptions` here because we manipulate the options in `useQuery`.
159
+ const method = /*#__PURE__*/function () {
160
+ var _ref4 = _asyncToGenerator(function* (options) {
161
+ return yield client[methodName](options);
162
+ });
163
+ return function method(_x4) {
164
+ return _ref4.apply(this, arguments);
165
+ };
166
+ }();
167
+
168
+ // For some reason, if we don't explicitly set these generic parameters, the inferred type for
169
+ // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
170
+ return (0, _useQuery.useQuery)(netOptions, queryOptions, {
171
+ method,
172
+ queryKey,
173
+ requiredParameters
174
+ });
175
+ };
176
+ /**
177
+ * This method gives you the external taxation data set by the PUT taxes API. This endpoint can be called only if external taxation mode was used for basket creation. See POST /baskets for more information.
178
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
179
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
180
+ * @returns A TanStack Query query hook with data from the Shopper Baskets `getTaxesFromBasket` endpoint.
181
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-baskets?meta=getTaxesFromBasket| Salesforce Developer Center} for more information about the API endpoint.
182
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperbaskets.shopperbaskets-1.html#gettaxesfrombasket | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
183
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
184
+ */
185
+ exports.useShippingMethodsForShipment = useShippingMethodsForShipment;
186
+ const useTaxesFromBasket = (apiOptions, queryOptions = {}) => {
187
+ const {
188
+ shopperBaskets: client
189
+ } = (0, _useCommerceApi.default)();
190
+ const methodName = 'getTaxesFromBasket';
191
+ const requiredParameters = ['organizationId', 'basketId', 'siteId'];
192
+
193
+ // Parameters can be set in `apiOptions` or `client.clientConfig`;
194
+ // we must merge them in order to generate the correct query key.
195
+ const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
196
+ const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
197
+ // We don't use `netOptions` here because we manipulate the options in `useQuery`.
198
+ const method = /*#__PURE__*/function () {
199
+ var _ref5 = _asyncToGenerator(function* (options) {
200
+ return yield client[methodName](options);
201
+ });
202
+ return function method(_x5) {
203
+ return _ref5.apply(this, arguments);
204
+ };
205
+ }();
206
+
207
+ // For some reason, if we don't explicitly set these generic parameters, the inferred type for
208
+ // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
209
+ return (0, _useQuery.useQuery)(netOptions, queryOptions, {
210
+ method,
211
+ queryKey,
212
+ requiredParameters
213
+ });
214
+ };
215
+ exports.useTaxesFromBasket = useTaxesFromBasket;
@@ -0,0 +1,72 @@
1
+ import type { ShopperBaskets } from 'commerce-sdk-isomorphic';
2
+ import { Argument, ExcludeTail } from '../types';
3
+ declare type Client = ShopperBaskets<{
4
+ shortCode: string;
5
+ }>;
6
+ declare type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
+ export declare type QueryKeys = {
8
+ getBasket: [
9
+ '/commerce-sdk-react',
10
+ '/organizations/',
11
+ string | undefined,
12
+ '/baskets/',
13
+ string | undefined,
14
+ Params<'getBasket'>
15
+ ];
16
+ getPaymentMethodsForBasket: [
17
+ '/commerce-sdk-react',
18
+ '/organizations/',
19
+ string | undefined,
20
+ '/baskets/',
21
+ string | undefined,
22
+ '/payment-methods',
23
+ Params<'getPaymentMethodsForBasket'>
24
+ ];
25
+ getPriceBooksForBasket: [
26
+ '/commerce-sdk-react',
27
+ '/organizations/',
28
+ string | undefined,
29
+ '/baskets/',
30
+ string | undefined,
31
+ '/price-books',
32
+ Params<'getPriceBooksForBasket'>
33
+ ];
34
+ getShippingMethodsForShipment: [
35
+ '/commerce-sdk-react',
36
+ '/organizations/',
37
+ string | undefined,
38
+ '/baskets/',
39
+ string | undefined,
40
+ '/shipments/',
41
+ string | undefined,
42
+ '/shipping-methods',
43
+ Params<'getShippingMethodsForShipment'>
44
+ ];
45
+ getTaxesFromBasket: [
46
+ '/commerce-sdk-react',
47
+ '/organizations/',
48
+ string | undefined,
49
+ '/baskets/',
50
+ string | undefined,
51
+ '/taxes',
52
+ Params<'getTaxesFromBasket'>
53
+ ];
54
+ };
55
+ declare type QueryKeyHelper<T extends keyof QueryKeys> = {
56
+ /**
57
+ * Reduces the given parameters (which may have additional, unknown properties) to an object
58
+ * containing *only* the properties required for an endpoint.
59
+ */
60
+ parameters: (params: Params<T>) => Params<T>;
61
+ /** Generates the path component of the query key for an endpoint. */
62
+ path: (params: Params<T>) => ExcludeTail<QueryKeys[T]>;
63
+ /** Generates the full query key for an endpoint. */
64
+ queryKey: (params: Params<T>) => QueryKeys[T];
65
+ };
66
+ export declare const getBasket: QueryKeyHelper<'getBasket'>;
67
+ export declare const getPaymentMethodsForBasket: QueryKeyHelper<'getPaymentMethodsForBasket'>;
68
+ export declare const getPriceBooksForBasket: QueryKeyHelper<'getPriceBooksForBasket'>;
69
+ export declare const getShippingMethodsForShipment: QueryKeyHelper<'getShippingMethodsForShipment'>;
70
+ export declare const getTaxesFromBasket: QueryKeyHelper<'getTaxesFromBasket'>;
71
+ export {};
72
+ //# sourceMappingURL=queryKeyHelpers.d.ts.map
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getTaxesFromBasket = exports.getShippingMethodsForShipment = exports.getPriceBooksForBasket = exports.getPaymentMethodsForBasket = exports.getBasket = 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 getBasket = {
21
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'basketId', 'siteId', 'locale']),
22
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/baskets/', params.basketId],
23
+ queryKey: params => [...getBasket.path(params), getBasket.parameters(params)]
24
+ };
25
+ exports.getBasket = getBasket;
26
+ const getPaymentMethodsForBasket = {
27
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'basketId', 'siteId', 'locale']),
28
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/baskets/', params.basketId, '/payment-methods'],
29
+ queryKey: params => [...getPaymentMethodsForBasket.path(params), getPaymentMethodsForBasket.parameters(params)]
30
+ };
31
+ exports.getPaymentMethodsForBasket = getPaymentMethodsForBasket;
32
+ const getPriceBooksForBasket = {
33
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'basketId', 'siteId']),
34
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/baskets/', params.basketId, '/price-books'],
35
+ queryKey: params => [...getPriceBooksForBasket.path(params), getPriceBooksForBasket.parameters(params)]
36
+ };
37
+ exports.getPriceBooksForBasket = getPriceBooksForBasket;
38
+ const getShippingMethodsForShipment = {
39
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'basketId', 'shipmentId', 'siteId', 'locale']),
40
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/baskets/', params.basketId, '/shipments/', params.shipmentId, '/shipping-methods'],
41
+ queryKey: params => [...getShippingMethodsForShipment.path(params), getShippingMethodsForShipment.parameters(params)]
42
+ };
43
+ exports.getShippingMethodsForShipment = getShippingMethodsForShipment;
44
+ const getTaxesFromBasket = {
45
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'basketId', 'siteId']),
46
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/baskets/', params.basketId, '/taxes'],
47
+ queryKey: params => [...getTaxesFromBasket.path(params), getTaxesFromBasket.parameters(params)]
48
+ };
49
+ exports.getTaxesFromBasket = getTaxesFromBasket;
@@ -0,0 +1,5 @@
1
+ import { ApiClients, CacheUpdateMatrix } from '../types';
2
+ declare type Client = ApiClients['shopperContexts'];
3
+ export declare const cacheUpdateMatrix: CacheUpdateMatrix<Client>;
4
+ export {};
5
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.cacheUpdateMatrix = void 0;
7
+ var _queryKeyHelpers = require("./queryKeyHelpers");
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
+ // TODO: Complete cache invalidation https://gus.lightning.force.com/lightning/_classic/%2Fa07EE00001NoYplYAF
16
+ const cacheUpdateMatrix = {
17
+ createShopperContext(customerId, {
18
+ parameters
19
+ }) {
20
+ return {
21
+ invalidate: [{
22
+ queryKey: _queryKeyHelpers.getShopperContext.queryKey(parameters)
23
+ }]
24
+ };
25
+ },
26
+ updateShopperContext(_customerId, {
27
+ parameters
28
+ }) {
29
+ return {
30
+ update: [{
31
+ queryKey: _queryKeyHelpers.getShopperContext.queryKey(parameters)
32
+ }]
33
+ };
34
+ },
35
+ deleteShopperContext(_customerId, {
36
+ parameters
37
+ }) {
38
+ return {
39
+ remove: [{
40
+ queryKey: _queryKeyHelpers.getShopperContext.queryKey(parameters)
41
+ }]
42
+ };
43
+ }
44
+ };
45
+ 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
+ });
@@ -0,0 +1,35 @@
1
+ import { ApiClients, Argument, DataType } from '../types';
2
+ import { UseMutationResult } from '@tanstack/react-query';
3
+ declare type Client = ApiClients['shopperContexts'];
4
+ /** Mutations available for Shopper Contexts. */
5
+ export declare const ShopperContextsMutations: {
6
+ /**
7
+ * Creates the shopper's context based on shopperJWT.
8
+ * @returns A TanStack Query mutation hook for interacting with the Shopper Contexts `createShopperContext` endpoint.
9
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-contexts?meta=createShopperContext| Salesforce Developer Center} for more information about the API endpoint.
10
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercontexts.shoppercontexts-1.html#createshoppercontext | `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/useMutation | TanStack Query `useMutation` reference} for more information about the return value.
12
+ */
13
+ readonly CreateShopperContext: "createShopperContext";
14
+ /**
15
+ * Gets the shopper's context based on the shopperJWT.
16
+ * @returns A TanStack Query mutation hook for interacting with the Shopper Contexts `deleteShopperContext` endpoint.
17
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-contexts?meta=deleteShopperContext| Salesforce Developer Center} for more information about the API endpoint.
18
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercontexts.shoppercontexts-1.html#deleteshoppercontext | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
19
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useMutation | TanStack Query `useMutation` reference} for more information about the return value.
20
+ */
21
+ readonly DeleteShopperContext: "deleteShopperContext";
22
+ /**
23
+ * Updates the shopper's context based on the Shopper JWT. If the shopper context exists, it's updated with the patch body. If a customer qualifier or an `effectiveDateTime` is already present in the existing shopper context, its value is replaced by the corresponding value from the patch body. If a customer qualifers' value is set to `null` it's deleted from existing shopper context. If `effectiveDateTime` value is set to set to an empty string (\"\"), it's deleted from existing shopper context. If `effectiveDateTime` value is set to `null` it's ignored. If an `effectiveDateTime` or customer qualifiiers' value is new, it's added to the existing Shopper context.
24
+ * @returns A TanStack Query mutation hook for interacting with the Shopper Contexts `updateShopperContext` endpoint.
25
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-contexts?meta=updateShopperContext| Salesforce Developer Center} for more information about the API endpoint.
26
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercontexts.shoppercontexts-1.html#updateshoppercontext | `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/useMutation | TanStack Query `useMutation` reference} for more information about the return value.
28
+ */
29
+ readonly UpdateShopperContext: "updateShopperContext";
30
+ };
31
+ /** Mutation for Shopper Contexts. */
32
+ export declare type ShopperContextsMutation = (typeof ShopperContextsMutations)[keyof typeof ShopperContextsMutations];
33
+ export declare function useShopperContextsMutation<Mutation extends ShopperContextsMutation>(mutation: Mutation): UseMutationResult<DataType<Client[Mutation]>, unknown, Argument<Client[Mutation]>>;
34
+ export {};
35
+ //# sourceMappingURL=mutation.d.ts.map
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ShopperContextsMutations = void 0;
7
+ exports.useShopperContextsMutation = useShopperContextsMutation;
8
+ var _useMutation = require("../useMutation");
9
+ var _utils = require("../utils");
10
+ var _useCommerceApi = _interopRequireDefault(require("../useCommerceApi"));
11
+ var _cache = require("./cache");
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ /*
14
+ * Copyright (c) 2023, Salesforce, Inc.
15
+ * All rights reserved.
16
+ * SPDX-License-Identifier: BSD-3-Clause
17
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
18
+ */
19
+
20
+ /** Mutations available for Shopper Contexts. */
21
+ const ShopperContextsMutations = {
22
+ /**
23
+ * Creates the shopper's context based on shopperJWT.
24
+ * @returns A TanStack Query mutation hook for interacting with the Shopper Contexts `createShopperContext` endpoint.
25
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-contexts?meta=createShopperContext| Salesforce Developer Center} for more information about the API endpoint.
26
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercontexts.shoppercontexts-1.html#createshoppercontext | `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/useMutation | TanStack Query `useMutation` reference} for more information about the return value.
28
+ */
29
+ CreateShopperContext: 'createShopperContext',
30
+ /**
31
+ * Gets the shopper's context based on the shopperJWT.
32
+ * @returns A TanStack Query mutation hook for interacting with the Shopper Contexts `deleteShopperContext` endpoint.
33
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-contexts?meta=deleteShopperContext| Salesforce Developer Center} for more information about the API endpoint.
34
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercontexts.shoppercontexts-1.html#deleteshoppercontext | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
35
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useMutation | TanStack Query `useMutation` reference} for more information about the return value.
36
+ */
37
+ DeleteShopperContext: 'deleteShopperContext',
38
+ /**
39
+ * Updates the shopper's context based on the Shopper JWT. If the shopper context exists, it's updated with the patch body. If a customer qualifier or an `effectiveDateTime` is already present in the existing shopper context, its value is replaced by the corresponding value from the patch body. If a customer qualifers' value is set to `null` it's deleted from existing shopper context. If `effectiveDateTime` value is set to set to an empty string (\"\"), it's deleted from existing shopper context. If `effectiveDateTime` value is set to `null` it's ignored. If an `effectiveDateTime` or customer qualifiiers' value is new, it's added to the existing Shopper context.
40
+ * @returns A TanStack Query mutation hook for interacting with the Shopper Contexts `updateShopperContext` endpoint.
41
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-contexts?meta=updateShopperContext| Salesforce Developer Center} for more information about the API endpoint.
42
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercontexts.shoppercontexts-1.html#updateshoppercontext | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
43
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useMutation | TanStack Query `useMutation` reference} for more information about the return value.
44
+ */
45
+ UpdateShopperContext: 'updateShopperContext'
46
+ };
47
+
48
+ /** Mutation for Shopper Contexts. */
49
+ exports.ShopperContextsMutations = ShopperContextsMutations;
50
+ function useShopperContextsMutation(mutation) {
51
+ const getCacheUpdates = _cache.cacheUpdateMatrix[mutation];
52
+ // TODO: Remove this check when all mutations are implemented.
53
+ if (!getCacheUpdates) throw new _utils.NotImplementedError(`The '${mutation}' mutation`);
54
+
55
+ // The `Options` and `Data` types for each mutation are similar, but distinct, and the union
56
+ // type generated from `Client[Mutation]` seems to be too complex for TypeScript to handle.
57
+ // I'm not sure if there's a way to avoid the type assertions in here for the methods that
58
+ // use them. However, I'm fairly confident that they are safe to do, as they seem to be simply
59
+ // re-asserting what we already have.
60
+ const {
61
+ shopperContexts: client
62
+ } = (0, _useCommerceApi.default)();
63
+ return (0, _useMutation.useMutation)({
64
+ client,
65
+ method: opts => client[mutation](opts),
66
+ getCacheUpdates: getCacheUpdates
67
+ });
68
+ }
@@ -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['shopperContexts'];
4
+ /**
5
+ * Gets the shopper's context based on the shopperJWT. ******** This API is currently a work in progress, and not available to use yet. ********
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 Contexts `getShopperContext` endpoint.
9
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-contexts?meta=getShopperContext| Salesforce Developer Center} for more information about the API endpoint.
10
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercontexts.shoppercontexts-1.html#getshoppercontext | `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 useShopperContext: (apiOptions: NullableParameters<Argument<Client['getShopperContext']>>, queryOptions?: ApiQueryOptions<Client['getShopperContext']>) => UseQueryResult<DataType<Client['getShopperContext']>>;
14
+ export {};
15
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useShopperContext = 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
+ * Gets the shopper's context based on the shopperJWT. ******** This API is currently a work in progress, and not available to use yet. ********
23
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
24
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
25
+ * @returns A TanStack Query query hook with data from the Shopper Contexts `getShopperContext` endpoint.
26
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-contexts?meta=getShopperContext| Salesforce Developer Center} for more information about the API endpoint.
27
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercontexts.shoppercontexts-1.html#getshoppercontext | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
28
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
29
+ */
30
+ const useShopperContext = (apiOptions, queryOptions = {}) => {
31
+ const {
32
+ shopperContexts: client
33
+ } = (0, _useCommerceApi.default)();
34
+ const methodName = 'getShopperContext';
35
+ const requiredParameters = ['organizationId', 'usid'];
36
+
37
+ // Parameters can be set in `apiOptions` or `client.clientConfig`;
38
+ // we must merge them in order to generate the correct query key.
39
+ const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
40
+ const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
41
+ // We don't use `netOptions` here because we manipulate the options in `useQuery`.
42
+ const method = /*#__PURE__*/function () {
43
+ var _ref = _asyncToGenerator(function* (options) {
44
+ return yield client[methodName](options);
45
+ });
46
+ return function method(_x) {
47
+ return _ref.apply(this, arguments);
48
+ };
49
+ }();
50
+
51
+ // For some reason, if we don't explicitly set these generic parameters, the inferred type for
52
+ // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
53
+ return (0, _useQuery.useQuery)(netOptions, queryOptions, {
54
+ method,
55
+ queryKey,
56
+ requiredParameters
57
+ });
58
+ };
59
+ exports.useShopperContext = useShopperContext;