@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,178 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useProducts = exports.useProduct = exports.useCategory = exports.useCategories = 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
+ * Allows access to multiple products by a single request. Only products that are online and assigned to a site catalog are returned. The maximum number of productIDs that can be requested are 24. Along with product details, the availability, product options, images, price, promotions, and variations for the valid products will be included, as appropriate.
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 Products `getProducts` endpoint.
26
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-products?meta=getProducts| Salesforce Developer Center} for more information about the API endpoint.
27
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperproducts.shopperproducts-1.html#getproducts | `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 useProducts = (apiOptions, queryOptions = {}) => {
31
+ const {
32
+ shopperProducts: client
33
+ } = (0, _useCommerceApi.default)();
34
+ const methodName = 'getProducts';
35
+ const requiredParameters = ['organizationId', 'ids', '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
+ * Allows access to product details for a single product ID. Only products that are online and assigned to a site catalog are returned. Along with product details, the availability, images, price, bundled_products, set_products, recommedations, product options, variations, and promotions for the products will be included, as appropriate.
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 Products `getProduct` endpoint.
64
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-products?meta=getProduct| Salesforce Developer Center} for more information about the API endpoint.
65
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperproducts.shopperproducts-1.html#getproduct | `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.useProducts = useProducts;
69
+ const useProduct = (apiOptions, queryOptions = {}) => {
70
+ const {
71
+ shopperProducts: client
72
+ } = (0, _useCommerceApi.default)();
73
+ const methodName = 'getProduct';
74
+ const requiredParameters = ['organizationId', 'id', '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
+ * When you use the URL template, the server returns multiple categories (a result object of category documents). You can use this template as a convenient way of obtaining multiple categories in a single request, instead of issuing separate requests for each category. You can specify up to 50 multiple IDs. You must enclose the list of IDs in parentheses. If a category identifier contains parenthesis or the separator sign, you must URL encode the character. The server only returns online categories.
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 Products `getCategories` endpoint.
103
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-products?meta=getCategories| Salesforce Developer Center} for more information about the API endpoint.
104
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperproducts.shopperproducts-1.html#getcategories | `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.useProduct = useProduct;
108
+ const useCategories = (apiOptions, queryOptions = {}) => {
109
+ const {
110
+ shopperProducts: client
111
+ } = (0, _useCommerceApi.default)();
112
+ const methodName = 'getCategories';
113
+ const requiredParameters = ['organizationId', 'ids', '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
+ * When you use the URL template below, the server returns a category identified by its ID; by default, the server
139
+ also returns the first level of subcategories, but you can specify another level by setting the levels
140
+ parameter. The server only returns online categories.
141
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
142
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
143
+ * @returns A TanStack Query query hook with data from the Shopper Products `getCategory` endpoint.
144
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-products?meta=getCategory| Salesforce Developer Center} for more information about the API endpoint.
145
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperproducts.shopperproducts-1.html#getcategory | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
146
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
147
+ */
148
+ exports.useCategories = useCategories;
149
+ const useCategory = (apiOptions, queryOptions = {}) => {
150
+ const {
151
+ shopperProducts: client
152
+ } = (0, _useCommerceApi.default)();
153
+ const methodName = 'getCategory';
154
+ const requiredParameters = ['organizationId', 'id', 'siteId'];
155
+
156
+ // Parameters can be set in `apiOptions` or `client.clientConfig`;
157
+ // we must merge them in order to generate the correct query key.
158
+ const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
159
+ const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
160
+ // We don't use `netOptions` here because we manipulate the options in `useQuery`.
161
+ const method = /*#__PURE__*/function () {
162
+ var _ref4 = _asyncToGenerator(function* (options) {
163
+ return yield client[methodName](options);
164
+ });
165
+ return function method(_x4) {
166
+ return _ref4.apply(this, arguments);
167
+ };
168
+ }();
169
+
170
+ // For some reason, if we don't explicitly set these generic parameters, the inferred type for
171
+ // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
172
+ return (0, _useQuery.useQuery)(netOptions, queryOptions, {
173
+ method,
174
+ queryKey,
175
+ requiredParameters
176
+ });
177
+ };
178
+ exports.useCategory = useCategory;
@@ -0,0 +1,55 @@
1
+ import type { ShopperProducts } from 'commerce-sdk-isomorphic';
2
+ import { Argument, ExcludeTail } from '../types';
3
+ declare type Client = ShopperProducts<{
4
+ shortCode: string;
5
+ }>;
6
+ declare type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
+ export declare type QueryKeys = {
8
+ getProducts: [
9
+ '/commerce-sdk-react',
10
+ '/organizations/',
11
+ string | undefined,
12
+ '/products',
13
+ Params<'getProducts'>
14
+ ];
15
+ getProduct: [
16
+ '/commerce-sdk-react',
17
+ '/organizations/',
18
+ string | undefined,
19
+ '/products/',
20
+ string | undefined,
21
+ Params<'getProduct'>
22
+ ];
23
+ getCategories: [
24
+ '/commerce-sdk-react',
25
+ '/organizations/',
26
+ string | undefined,
27
+ '/categories',
28
+ Params<'getCategories'>
29
+ ];
30
+ getCategory: [
31
+ '/commerce-sdk-react',
32
+ '/organizations/',
33
+ string | undefined,
34
+ '/categories/',
35
+ string | undefined,
36
+ Params<'getCategory'>
37
+ ];
38
+ };
39
+ declare type QueryKeyHelper<T extends keyof QueryKeys> = {
40
+ /**
41
+ * Reduces the given parameters (which may have additional, unknown properties) to an object
42
+ * containing *only* the properties required for an endpoint.
43
+ */
44
+ parameters: (params: Params<T>) => Params<T>;
45
+ /** Generates the path component of the query key for an endpoint. */
46
+ path: (params: Params<T>) => ExcludeTail<QueryKeys[T]>;
47
+ /** Generates the full query key for an endpoint. */
48
+ queryKey: (params: Params<T>) => QueryKeys[T];
49
+ };
50
+ export declare const getProducts: QueryKeyHelper<'getProducts'>;
51
+ export declare const getProduct: QueryKeyHelper<'getProduct'>;
52
+ export declare const getCategories: QueryKeyHelper<'getCategories'>;
53
+ export declare const getCategory: QueryKeyHelper<'getCategory'>;
54
+ export {};
55
+ //# sourceMappingURL=queryKeyHelpers.d.ts.map
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getProducts = exports.getProduct = exports.getCategory = exports.getCategories = 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 getProducts = {
21
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'ids', 'inventoryIds', 'currency', 'expand', 'locale', 'allImages', 'perPricebook', 'siteId']),
22
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/products'],
23
+ queryKey: params => [...getProducts.path(params), getProducts.parameters(params)]
24
+ };
25
+ exports.getProducts = getProducts;
26
+ const getProduct = {
27
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'id', 'inventoryIds', 'currency', 'expand', 'locale', 'allImages', 'perPricebook', 'siteId']),
28
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/products/', params.id],
29
+ queryKey: params => [...getProduct.path(params), getProduct.parameters(params)]
30
+ };
31
+ exports.getProduct = getProduct;
32
+ const getCategories = {
33
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'ids', 'levels', 'locale', 'siteId']),
34
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/categories'],
35
+ queryKey: params => [...getCategories.path(params), getCategories.parameters(params)]
36
+ };
37
+ exports.getCategories = getCategories;
38
+ const getCategory = {
39
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'id', 'levels', 'locale', 'siteId']),
40
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/categories/', params.id],
41
+ queryKey: params => [...getCategory.path(params), getCategory.parameters(params)]
42
+ };
43
+ exports.getCategory = getCategory;
@@ -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,29 @@
1
+ import { UseQueryResult } from '@tanstack/react-query';
2
+ import { ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters } from '../types';
3
+ declare type Client = ApiClients['shopperPromotions'];
4
+ /**
5
+ * Returns an array of enabled promotions for a list of specified IDs. In the request URL, you can specify up to 50 IDs. If you specify an ID that contains either parentheses or the separator characters, you must URL encode these characters. Each request returns only enabled promotions as the server does not consider promotion qualifiers or schedules.
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 Promotions `getPromotions` endpoint.
9
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-promotions?meta=getPromotions| Salesforce Developer Center} for more information about the API endpoint.
10
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperpromotions.shopperpromotions-1.html#getpromotions | `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 usePromotions: (apiOptions: NullableParameters<Argument<Client['getPromotions']>>, queryOptions?: ApiQueryOptions<Client['getPromotions']>) => UseQueryResult<DataType<Client['getPromotions']>>;
14
+ /**
15
+ * Handles get promotion by filter criteria. Returns an array of enabled promotions matching the specified filter
16
+ criteria. In the request URL, you must provide a campaign_id parameter, and you can optionally specify a date
17
+ range by providing start_date and end_date parameters. Both parameters are required to specify a date range, as
18
+ omitting one causes the server to return a MissingParameterException fault. Each request returns only enabled
19
+ promotions, since the server does not consider promotion qualifiers or schedules.
20
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
21
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
22
+ * @returns A TanStack Query query hook with data from the Shopper Promotions `getPromotionsForCampaign` endpoint.
23
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-promotions?meta=getPromotionsForCampaign| Salesforce Developer Center} for more information about the API endpoint.
24
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperpromotions.shopperpromotions-1.html#getpromotionsforcampaign | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
25
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
26
+ */
27
+ export declare const usePromotionsForCampaign: (apiOptions: NullableParameters<Argument<Client['getPromotionsForCampaign']>>, queryOptions?: ApiQueryOptions<Client['getPromotionsForCampaign']>) => UseQueryResult<DataType<Client['getPromotionsForCampaign']>>;
28
+ export {};
29
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.usePromotionsForCampaign = exports.usePromotions = 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
+ * Returns an array of enabled promotions for a list of specified IDs. In the request URL, you can specify up to 50 IDs. If you specify an ID that contains either parentheses or the separator characters, you must URL encode these characters. Each request returns only enabled promotions as the server does not consider promotion qualifiers or schedules.
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 Promotions `getPromotions` endpoint.
26
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-promotions?meta=getPromotions| Salesforce Developer Center} for more information about the API endpoint.
27
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperpromotions.shopperpromotions-1.html#getpromotions | `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 usePromotions = (apiOptions, queryOptions = {}) => {
31
+ const {
32
+ shopperPromotions: client
33
+ } = (0, _useCommerceApi.default)();
34
+ const methodName = 'getPromotions';
35
+ const requiredParameters = ['organizationId', 'siteId', 'ids'];
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
+ * Handles get promotion by filter criteria. Returns an array of enabled promotions matching the specified filter
61
+ criteria. In the request URL, you must provide a campaign_id parameter, and you can optionally specify a date
62
+ range by providing start_date and end_date parameters. Both parameters are required to specify a date range, as
63
+ omitting one causes the server to return a MissingParameterException fault. Each request returns only enabled
64
+ promotions, since the server does not consider promotion qualifiers or schedules.
65
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
66
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
67
+ * @returns A TanStack Query query hook with data from the Shopper Promotions `getPromotionsForCampaign` endpoint.
68
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-promotions?meta=getPromotionsForCampaign| Salesforce Developer Center} for more information about the API endpoint.
69
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperpromotions.shopperpromotions-1.html#getpromotionsforcampaign | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
70
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
71
+ */
72
+ exports.usePromotions = usePromotions;
73
+ const usePromotionsForCampaign = (apiOptions, queryOptions = {}) => {
74
+ const {
75
+ shopperPromotions: client
76
+ } = (0, _useCommerceApi.default)();
77
+ const methodName = 'getPromotionsForCampaign';
78
+ const requiredParameters = ['organizationId', 'campaignId', 'siteId'];
79
+
80
+ // Parameters can be set in `apiOptions` or `client.clientConfig`;
81
+ // we must merge them in order to generate the correct query key.
82
+ const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
83
+ const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
84
+ // We don't use `netOptions` here because we manipulate the options in `useQuery`.
85
+ const method = /*#__PURE__*/function () {
86
+ var _ref2 = _asyncToGenerator(function* (options) {
87
+ return yield client[methodName](options);
88
+ });
89
+ return function method(_x2) {
90
+ return _ref2.apply(this, arguments);
91
+ };
92
+ }();
93
+
94
+ // For some reason, if we don't explicitly set these generic parameters, the inferred type for
95
+ // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
96
+ return (0, _useQuery.useQuery)(netOptions, queryOptions, {
97
+ method,
98
+ queryKey,
99
+ requiredParameters
100
+ });
101
+ };
102
+ exports.usePromotionsForCampaign = usePromotionsForCampaign;
@@ -0,0 +1,38 @@
1
+ import type { ShopperPromotions } from 'commerce-sdk-isomorphic';
2
+ import { Argument, ExcludeTail } from '../types';
3
+ declare type Client = ShopperPromotions<{
4
+ shortCode: string;
5
+ }>;
6
+ declare type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
+ export declare type QueryKeys = {
8
+ getPromotions: [
9
+ '/commerce-sdk-react',
10
+ '/organizations/',
11
+ string | undefined,
12
+ '/promotions',
13
+ Params<'getPromotions'>
14
+ ];
15
+ getPromotionsForCampaign: [
16
+ '/commerce-sdk-react',
17
+ '/organizations/',
18
+ string | undefined,
19
+ '/promotions/campaigns/',
20
+ string | undefined,
21
+ Params<'getPromotionsForCampaign'>
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 getPromotions: QueryKeyHelper<'getPromotions'>;
36
+ export declare const getPromotionsForCampaign: QueryKeyHelper<'getPromotionsForCampaign'>;
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.getPromotionsForCampaign = exports.getPromotions = 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 getPromotions = {
21
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'siteId', 'ids', 'locale']),
22
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/promotions'],
23
+ queryKey: params => [...getPromotions.path(params), getPromotions.parameters(params)]
24
+ };
25
+ exports.getPromotions = getPromotions;
26
+ const getPromotionsForCampaign = {
27
+ parameters: params => (0, _utils.pick)(params, ['organizationId', 'campaignId', 'siteId', 'startDate', 'endDate', 'currency']),
28
+ path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/promotions/campaigns/', params.campaignId],
29
+ queryKey: params => [...getPromotionsForCampaign.path(params), getPromotionsForCampaign.parameters(params)]
30
+ };
31
+ exports.getPromotionsForCampaign = getPromotionsForCampaign;
@@ -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,26 @@
1
+ import { UseQueryResult } from '@tanstack/react-query';
2
+ import { ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters } from '../types';
3
+ declare type Client = ApiClients['shopperSearch'];
4
+ /**
5
+ * Provides keyword and refinement search functionality for products. Only returns the product ID, link, and name in
6
+ the product search hit. The search result contains only products that are online and assigned to site catalog.
7
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
8
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
9
+ * @returns A TanStack Query query hook with data from the Shopper Search `productSearch` endpoint.
10
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-search?meta=productSearch| Salesforce Developer Center} for more information about the API endpoint.
11
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppersearch.shoppersearch-1.html#productsearch | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
12
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
13
+ */
14
+ export declare const useProductSearch: (apiOptions: NullableParameters<Argument<Client['productSearch']>>, queryOptions?: ApiQueryOptions<Client['productSearch']>) => UseQueryResult<DataType<Client['productSearch']>>;
15
+ /**
16
+ * Provides keyword search functionality for products, categories, and brands suggestions. Returns suggested products, suggested categories, and suggested brands for the given search phrase.
17
+ * @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
18
+ * @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
19
+ * @returns A TanStack Query query hook with data from the Shopper Search `getSearchSuggestions` endpoint.
20
+ * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-search?meta=getSearchSuggestions| Salesforce Developer Center} for more information about the API endpoint.
21
+ * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppersearch.shoppersearch-1.html#getsearchsuggestions | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
22
+ * @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
23
+ */
24
+ export declare const useSearchSuggestions: (apiOptions: NullableParameters<Argument<Client['getSearchSuggestions']>>, queryOptions?: ApiQueryOptions<Client['getSearchSuggestions']>) => UseQueryResult<DataType<Client['getSearchSuggestions']>>;
25
+ export {};
26
+ //# sourceMappingURL=query.d.ts.map