@salesforce/commerce-sdk-react 1.3.0 → 1.4.0-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -1
- package/auth/index.d.ts +0 -2
- package/auth/index.js +2 -5
- package/hooks/ShopperBaskets/paramKeys.d.ts +9 -0
- package/hooks/ShopperBaskets/paramKeys.js +25 -0
- package/hooks/ShopperBaskets/query.js +36 -5
- package/hooks/ShopperBaskets/queryKeyHelpers.d.ts +0 -5
- package/hooks/ShopperBaskets/queryKeyHelpers.js +22 -10
- package/hooks/ShopperContexts/paramKeys.d.ts +5 -0
- package/hooks/ShopperContexts/paramKeys.js +17 -0
- package/hooks/ShopperContexts/query.js +13 -1
- package/hooks/ShopperContexts/queryKeyHelpers.d.ts +0 -5
- package/hooks/ShopperContexts/queryKeyHelpers.js +6 -2
- package/hooks/ShopperCustomers/cache.js +7 -2
- package/hooks/ShopperCustomers/paramKeys.d.ts +26 -0
- package/hooks/ShopperCustomers/paramKeys.js +44 -0
- package/hooks/ShopperCustomers/query.js +73 -16
- package/hooks/ShopperCustomers/queryKeyHelpers.d.ts +0 -6
- package/hooks/ShopperCustomers/queryKeyHelpers.js +58 -28
- package/hooks/ShopperExperience/paramKeys.d.ts +6 -0
- package/hooks/ShopperExperience/paramKeys.js +19 -0
- package/hooks/ShopperExperience/query.js +18 -2
- package/hooks/ShopperExperience/queryKeyHelpers.d.ts +0 -5
- package/hooks/ShopperExperience/queryKeyHelpers.js +10 -4
- package/hooks/ShopperGiftCertificates/paramKeys.d.ts +5 -0
- package/hooks/ShopperGiftCertificates/paramKeys.js +17 -0
- package/hooks/ShopperGiftCertificates/query.js +8 -1
- package/hooks/ShopperGiftCertificates/queryKeyHelpers.d.ts +0 -5
- package/hooks/ShopperGiftCertificates/queryKeyHelpers.js +6 -2
- package/hooks/ShopperLogin/paramKeys.d.ts +7 -0
- package/hooks/ShopperLogin/paramKeys.js +21 -0
- package/hooks/ShopperLogin/query.js +24 -3
- package/hooks/ShopperLogin/queryKeyHelpers.d.ts +0 -5
- package/hooks/ShopperLogin/queryKeyHelpers.js +14 -6
- package/hooks/ShopperOrders/paramKeys.d.ts +7 -0
- package/hooks/ShopperOrders/paramKeys.js +21 -0
- package/hooks/ShopperOrders/query.js +24 -3
- package/hooks/ShopperOrders/queryKeyHelpers.d.ts +0 -5
- package/hooks/ShopperOrders/queryKeyHelpers.js +14 -6
- package/hooks/ShopperProducts/paramKeys.d.ts +8 -0
- package/hooks/ShopperProducts/paramKeys.js +23 -0
- package/hooks/ShopperProducts/query.js +30 -4
- package/hooks/ShopperProducts/queryKeyHelpers.d.ts +0 -5
- package/hooks/ShopperProducts/queryKeyHelpers.js +18 -8
- package/hooks/ShopperPromotions/paramKeys.d.ts +6 -0
- package/hooks/ShopperPromotions/paramKeys.js +19 -0
- package/hooks/ShopperPromotions/query.js +18 -2
- package/hooks/ShopperPromotions/queryKeyHelpers.d.ts +0 -5
- package/hooks/ShopperPromotions/queryKeyHelpers.js +10 -4
- package/hooks/ShopperSearch/paramKeys.d.ts +6 -0
- package/hooks/ShopperSearch/paramKeys.js +18 -0
- package/hooks/ShopperSearch/query.js +16 -2
- package/hooks/ShopperSearch/queryKeyHelpers.d.ts +0 -5
- package/hooks/ShopperSearch/queryKeyHelpers.js +10 -4
- package/hooks/ShopperSeo/index.d.ts +2 -0
- package/hooks/ShopperSeo/index.js +16 -0
- package/hooks/ShopperSeo/paramKeys.d.ts +5 -0
- package/hooks/ShopperSeo/paramKeys.js +17 -0
- package/hooks/ShopperSeo/query.d.ts +20 -0
- package/hooks/ShopperSeo/query.js +74 -0
- package/hooks/ShopperSeo/queryKeyHelpers.d.ts +24 -0
- package/hooks/ShopperSeo/queryKeyHelpers.js +28 -0
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +12 -0
- package/hooks/types.d.ts +2 -1
- package/hooks/useLocalStorage.d.ts +0 -1
- package/hooks/useLocalStorage.js +30 -20
- package/hooks/utils.d.ts +2 -0
- package/hooks/utils.js +11 -2
- package/package.json +5 -5
- package/provider.js +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
## v1.4.0-dev (Mar 26, 2024)
|
|
2
|
+
## v3.5.0-alpha.0 (Mar 26, 2024)
|
|
3
|
+
## v1.4.0-dev (Jan 22, 2024)
|
|
4
|
+
- Fix invalid query params warnings and allow custom query [#1655](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1655)
|
|
5
|
+
- Fix cannot read properties of undefined (reading 'unshift') [#1689](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1689)
|
|
6
|
+
- Add Shopper SEO hook [#1688](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1688)
|
|
7
|
+
- Update useLocalStorage implementation to be more responsive [#1703](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1703)
|
|
8
|
+
|
|
1
9
|
## v1.3.0 (Jan 19, 2024)
|
|
2
10
|
|
|
3
11
|
- Add support for node 20 [#1612](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1612)
|
|
4
|
-
- Fix bug when running in an iframe [#1629](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1629)
|
|
5
12
|
|
|
6
13
|
## v1.2.0 (Dec 08, 2023)
|
|
7
14
|
|
package/auth/index.d.ts
CHANGED
|
@@ -35,8 +35,6 @@ declare class Auth {
|
|
|
35
35
|
private shopperCustomersClient;
|
|
36
36
|
private redirectURI;
|
|
37
37
|
private pendingToken;
|
|
38
|
-
private REFRESH_TOKEN_EXPIRATION_DAYS_REGISTERED;
|
|
39
|
-
private REFRESH_TOKEN_EXPIRATION_DAYS_GUEST;
|
|
40
38
|
private stores;
|
|
41
39
|
private fetchedToken;
|
|
42
40
|
private OCAPISessionsURL;
|
package/auth/index.js
CHANGED
|
@@ -120,8 +120,6 @@ const DATA_MAP = {
|
|
|
120
120
|
* @Internal
|
|
121
121
|
*/
|
|
122
122
|
class Auth {
|
|
123
|
-
REFRESH_TOKEN_EXPIRATION_DAYS_REGISTERED = 90;
|
|
124
|
-
REFRESH_TOKEN_EXPIRATION_DAYS_GUEST = 30;
|
|
125
123
|
constructor(config) {
|
|
126
124
|
this.client = new _commerceSdkIsomorphic.ShopperLogin({
|
|
127
125
|
proxy: config.proxy,
|
|
@@ -264,12 +262,11 @@ class Auth {
|
|
|
264
262
|
this.set('customer_type', isGuest ? 'guest' : 'registered');
|
|
265
263
|
const refreshTokenKey = isGuest ? 'refresh_token_guest' : 'refresh_token_registered';
|
|
266
264
|
const refreshTokenCopyKey = isGuest ? 'refresh_token_guest_copy' : 'refresh_token_registered_copy';
|
|
267
|
-
const refreshTokenExpiry = isGuest ? this.REFRESH_TOKEN_EXPIRATION_DAYS_GUEST : this.REFRESH_TOKEN_EXPIRATION_DAYS_REGISTERED;
|
|
268
265
|
this.set(refreshTokenKey, res.refresh_token, {
|
|
269
|
-
expires:
|
|
266
|
+
expires: res.refresh_token_expires_in
|
|
270
267
|
});
|
|
271
268
|
this.set(refreshTokenCopyKey, res.refresh_token, {
|
|
272
|
-
expires:
|
|
269
|
+
expires: res.refresh_token_expires_in
|
|
273
270
|
});
|
|
274
271
|
}
|
|
275
272
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
getBasket: readonly ["organizationId", "basketId", "siteId", "locale"];
|
|
3
|
+
getPaymentMethodsForBasket: readonly ["organizationId", "basketId", "siteId", "locale"];
|
|
4
|
+
getPriceBooksForBasket: readonly ["organizationId", "basketId", "siteId"];
|
|
5
|
+
getShippingMethodsForShipment: readonly ["organizationId", "basketId", "shipmentId", "siteId", "locale"];
|
|
6
|
+
getTaxesFromBasket: readonly ["organizationId", "basketId", "siteId"];
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
|
9
|
+
//# sourceMappingURL=paramKeys.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (c) 2024, Salesforce, Inc.
|
|
9
|
+
* All rights reserved.
|
|
10
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
11
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const getBasket = ['organizationId', 'basketId', 'siteId', 'locale'];
|
|
15
|
+
const getPaymentMethodsForBasket = ['organizationId', 'basketId', 'siteId', 'locale'];
|
|
16
|
+
const getPriceBooksForBasket = ['organizationId', 'basketId', 'siteId'];
|
|
17
|
+
const getShippingMethodsForShipment = ['organizationId', 'basketId', 'shipmentId', 'siteId', 'locale'];
|
|
18
|
+
const getTaxesFromBasket = ['organizationId', 'basketId', 'siteId'];
|
|
19
|
+
var _default = exports.default = {
|
|
20
|
+
getBasket,
|
|
21
|
+
getPaymentMethodsForBasket,
|
|
22
|
+
getPriceBooksForBasket,
|
|
23
|
+
getShippingMethodsForShipment,
|
|
24
|
+
getTaxesFromBasket
|
|
25
|
+
};
|
|
@@ -8,9 +8,15 @@ var _useCommerceApi = _interopRequireDefault(require("../useCommerceApi"));
|
|
|
8
8
|
var _useQuery = require("../useQuery");
|
|
9
9
|
var _utils = require("../utils");
|
|
10
10
|
var queryKeyHelpers = _interopRequireWildcard(require("./queryKeyHelpers"));
|
|
11
|
+
var _paramKeys = _interopRequireDefault(require("./paramKeys"));
|
|
11
12
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
13
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
18
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
19
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
14
20
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
15
21
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } /*
|
|
16
22
|
* Copyright (c) 2023, Salesforce, Inc.
|
|
@@ -39,6 +45,9 @@ const useBasket = (apiOptions, queryOptions = {}) => {
|
|
|
39
45
|
// Parameters can be set in `apiOptions` or `client.clientConfig`;
|
|
40
46
|
// we must merge them in order to generate the correct query key.
|
|
41
47
|
const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
|
|
48
|
+
// get param keys for the api from netOptions
|
|
49
|
+
const paramKeys = [..._paramKeys.default[methodName], ...(0, _utils.getCustomKeys)(netOptions.parameters)];
|
|
50
|
+
const parameters = (0, _utils.pick)(netOptions.parameters, paramKeys);
|
|
42
51
|
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
|
|
43
52
|
// We don't use `netOptions` here because we manipulate the options in `useQuery`.
|
|
44
53
|
const method = /*#__PURE__*/function () {
|
|
@@ -52,7 +61,9 @@ const useBasket = (apiOptions, queryOptions = {}) => {
|
|
|
52
61
|
|
|
53
62
|
// For some reason, if we don't explicitly set these generic parameters, the inferred type for
|
|
54
63
|
// `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
|
|
55
|
-
return (0, _useQuery.useQuery)(netOptions,
|
|
64
|
+
return (0, _useQuery.useQuery)(_objectSpread(_objectSpread({}, netOptions), {}, {
|
|
65
|
+
parameters
|
|
66
|
+
}), queryOptions, {
|
|
56
67
|
method,
|
|
57
68
|
queryKey,
|
|
58
69
|
requiredParameters
|
|
@@ -80,6 +91,9 @@ const usePaymentMethodsForBasket = (apiOptions, queryOptions = {}) => {
|
|
|
80
91
|
// Parameters can be set in `apiOptions` or `client.clientConfig`;
|
|
81
92
|
// we must merge them in order to generate the correct query key.
|
|
82
93
|
const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
|
|
94
|
+
// get param keys for the api from netOptions
|
|
95
|
+
const paramKeys = [..._paramKeys.default[methodName], ...(0, _utils.getCustomKeys)(netOptions.parameters)];
|
|
96
|
+
const parameters = (0, _utils.pick)(netOptions.parameters, paramKeys);
|
|
83
97
|
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
|
|
84
98
|
// We don't use `netOptions` here because we manipulate the options in `useQuery`.
|
|
85
99
|
const method = /*#__PURE__*/function () {
|
|
@@ -93,7 +107,9 @@ const usePaymentMethodsForBasket = (apiOptions, queryOptions = {}) => {
|
|
|
93
107
|
|
|
94
108
|
// For some reason, if we don't explicitly set these generic parameters, the inferred type for
|
|
95
109
|
// `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
|
|
96
|
-
return (0, _useQuery.useQuery)(netOptions,
|
|
110
|
+
return (0, _useQuery.useQuery)(_objectSpread(_objectSpread({}, netOptions), {}, {
|
|
111
|
+
parameters
|
|
112
|
+
}), queryOptions, {
|
|
97
113
|
method,
|
|
98
114
|
queryKey,
|
|
99
115
|
requiredParameters
|
|
@@ -121,6 +137,9 @@ const usePriceBooksForBasket = (apiOptions, queryOptions = {}) => {
|
|
|
121
137
|
// Parameters can be set in `apiOptions` or `client.clientConfig`;
|
|
122
138
|
// we must merge them in order to generate the correct query key.
|
|
123
139
|
const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
|
|
140
|
+
// get param keys for the api from netOptions
|
|
141
|
+
const paramKeys = [..._paramKeys.default[methodName], ...(0, _utils.getCustomKeys)(netOptions.parameters)];
|
|
142
|
+
const parameters = (0, _utils.pick)(netOptions.parameters, paramKeys);
|
|
124
143
|
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
|
|
125
144
|
// We don't use `netOptions` here because we manipulate the options in `useQuery`.
|
|
126
145
|
const method = /*#__PURE__*/function () {
|
|
@@ -134,7 +153,9 @@ const usePriceBooksForBasket = (apiOptions, queryOptions = {}) => {
|
|
|
134
153
|
|
|
135
154
|
// For some reason, if we don't explicitly set these generic parameters, the inferred type for
|
|
136
155
|
// `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
|
|
137
|
-
return (0, _useQuery.useQuery)(netOptions,
|
|
156
|
+
return (0, _useQuery.useQuery)(_objectSpread(_objectSpread({}, netOptions), {}, {
|
|
157
|
+
parameters
|
|
158
|
+
}), queryOptions, {
|
|
138
159
|
method,
|
|
139
160
|
queryKey,
|
|
140
161
|
requiredParameters
|
|
@@ -162,6 +183,9 @@ const useShippingMethodsForShipment = (apiOptions, queryOptions = {}) => {
|
|
|
162
183
|
// Parameters can be set in `apiOptions` or `client.clientConfig`;
|
|
163
184
|
// we must merge them in order to generate the correct query key.
|
|
164
185
|
const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
|
|
186
|
+
// get param keys for the api from netOptions
|
|
187
|
+
const paramKeys = [..._paramKeys.default[methodName], ...(0, _utils.getCustomKeys)(netOptions.parameters)];
|
|
188
|
+
const parameters = (0, _utils.pick)(netOptions.parameters, paramKeys);
|
|
165
189
|
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
|
|
166
190
|
// We don't use `netOptions` here because we manipulate the options in `useQuery`.
|
|
167
191
|
const method = /*#__PURE__*/function () {
|
|
@@ -175,7 +199,9 @@ const useShippingMethodsForShipment = (apiOptions, queryOptions = {}) => {
|
|
|
175
199
|
|
|
176
200
|
// For some reason, if we don't explicitly set these generic parameters, the inferred type for
|
|
177
201
|
// `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
|
|
178
|
-
return (0, _useQuery.useQuery)(netOptions,
|
|
202
|
+
return (0, _useQuery.useQuery)(_objectSpread(_objectSpread({}, netOptions), {}, {
|
|
203
|
+
parameters
|
|
204
|
+
}), queryOptions, {
|
|
179
205
|
method,
|
|
180
206
|
queryKey,
|
|
181
207
|
requiredParameters
|
|
@@ -203,6 +229,9 @@ const useTaxesFromBasket = (apiOptions, queryOptions = {}) => {
|
|
|
203
229
|
// Parameters can be set in `apiOptions` or `client.clientConfig`;
|
|
204
230
|
// we must merge them in order to generate the correct query key.
|
|
205
231
|
const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
|
|
232
|
+
// get param keys for the api from netOptions
|
|
233
|
+
const paramKeys = [..._paramKeys.default[methodName], ...(0, _utils.getCustomKeys)(netOptions.parameters)];
|
|
234
|
+
const parameters = (0, _utils.pick)(netOptions.parameters, paramKeys);
|
|
206
235
|
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
|
|
207
236
|
// We don't use `netOptions` here because we manipulate the options in `useQuery`.
|
|
208
237
|
const method = /*#__PURE__*/function () {
|
|
@@ -216,7 +245,9 @@ const useTaxesFromBasket = (apiOptions, queryOptions = {}) => {
|
|
|
216
245
|
|
|
217
246
|
// For some reason, if we don't explicitly set these generic parameters, the inferred type for
|
|
218
247
|
// `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
|
|
219
|
-
return (0, _useQuery.useQuery)(netOptions,
|
|
248
|
+
return (0, _useQuery.useQuery)(_objectSpread(_objectSpread({}, netOptions), {}, {
|
|
249
|
+
parameters
|
|
250
|
+
}), queryOptions, {
|
|
220
251
|
method,
|
|
221
252
|
queryKey,
|
|
222
253
|
requiredParameters
|
|
@@ -53,11 +53,6 @@ export type QueryKeys = {
|
|
|
53
53
|
];
|
|
54
54
|
};
|
|
55
55
|
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
56
|
/** Generates the path component of the query key for an endpoint. */
|
|
62
57
|
path: (params: Params<T>) => ExcludeTail<QueryKeys[T]>;
|
|
63
58
|
/** Generates the full query key for an endpoint. */
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getTaxesFromBasket = exports.getShippingMethodsForShipment = exports.getPriceBooksForBasket = exports.getPaymentMethodsForBasket = exports.getBasket = void 0;
|
|
7
7
|
var _utils = require("../utils");
|
|
8
|
+
var _paramKeys = _interopRequireDefault(require("../ShopperBaskets/paramKeys"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
10
|
/*
|
|
9
11
|
* Copyright (c) 2023, Salesforce, Inc.
|
|
10
12
|
* All rights reserved.
|
|
@@ -18,27 +20,37 @@ var _utils = require("../utils");
|
|
|
18
20
|
// and making those generic would add too much complexity.
|
|
19
21
|
|
|
20
22
|
const getBasket = exports.getBasket = {
|
|
21
|
-
parameters: params => (0, _utils.pick)(params, ['organizationId', 'basketId', 'siteId', 'locale']),
|
|
22
23
|
path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/baskets/', params.basketId],
|
|
23
|
-
queryKey: params =>
|
|
24
|
+
queryKey: params => {
|
|
25
|
+
const paramKeys = [..._paramKeys.default['getBasket'], ...(0, _utils.getCustomKeys)(params)];
|
|
26
|
+
return [...getBasket.path(params), (0, _utils.pick)(params, paramKeys)];
|
|
27
|
+
}
|
|
24
28
|
};
|
|
25
29
|
const getPaymentMethodsForBasket = exports.getPaymentMethodsForBasket = {
|
|
26
|
-
parameters: params => (0, _utils.pick)(params, ['organizationId', 'basketId', 'siteId', 'locale']),
|
|
27
30
|
path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/baskets/', params.basketId, '/payment-methods'],
|
|
28
|
-
queryKey: params =>
|
|
31
|
+
queryKey: params => {
|
|
32
|
+
const paramKeys = [..._paramKeys.default['getPaymentMethodsForBasket'], ...(0, _utils.getCustomKeys)(params)];
|
|
33
|
+
return [...getPaymentMethodsForBasket.path(params), (0, _utils.pick)(params, paramKeys)];
|
|
34
|
+
}
|
|
29
35
|
};
|
|
30
36
|
const getPriceBooksForBasket = exports.getPriceBooksForBasket = {
|
|
31
|
-
parameters: params => (0, _utils.pick)(params, ['organizationId', 'basketId', 'siteId']),
|
|
32
37
|
path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/baskets/', params.basketId, '/price-books'],
|
|
33
|
-
queryKey: params =>
|
|
38
|
+
queryKey: params => {
|
|
39
|
+
const paramKeys = [..._paramKeys.default['getPriceBooksForBasket'], ...(0, _utils.getCustomKeys)(params)];
|
|
40
|
+
return [...getPriceBooksForBasket.path(params), (0, _utils.pick)(params, paramKeys)];
|
|
41
|
+
}
|
|
34
42
|
};
|
|
35
43
|
const getShippingMethodsForShipment = exports.getShippingMethodsForShipment = {
|
|
36
|
-
parameters: params => (0, _utils.pick)(params, ['organizationId', 'basketId', 'shipmentId', 'siteId', 'locale']),
|
|
37
44
|
path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/baskets/', params.basketId, '/shipments/', params.shipmentId, '/shipping-methods'],
|
|
38
|
-
queryKey: params =>
|
|
45
|
+
queryKey: params => {
|
|
46
|
+
const paramKeys = [..._paramKeys.default['getShippingMethodsForShipment'], ...(0, _utils.getCustomKeys)(params)];
|
|
47
|
+
return [...getShippingMethodsForShipment.path(params), (0, _utils.pick)(params, paramKeys)];
|
|
48
|
+
}
|
|
39
49
|
};
|
|
40
50
|
const getTaxesFromBasket = exports.getTaxesFromBasket = {
|
|
41
|
-
parameters: params => (0, _utils.pick)(params, ['organizationId', 'basketId', 'siteId']),
|
|
42
51
|
path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/baskets/', params.basketId, '/taxes'],
|
|
43
|
-
queryKey: params =>
|
|
52
|
+
queryKey: params => {
|
|
53
|
+
const paramKeys = [..._paramKeys.default['getTaxesFromBasket'], ...(0, _utils.getCustomKeys)(params)];
|
|
54
|
+
return [...getTaxesFromBasket.path(params), (0, _utils.pick)(params, paramKeys)];
|
|
55
|
+
}
|
|
44
56
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (c) 2024, Salesforce, Inc.
|
|
9
|
+
* All rights reserved.
|
|
10
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
11
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const getShopperContext = ['organizationId', 'usid'];
|
|
15
|
+
var _default = exports.default = {
|
|
16
|
+
getShopperContext
|
|
17
|
+
};
|
|
@@ -8,9 +8,15 @@ var _useCommerceApi = _interopRequireDefault(require("../useCommerceApi"));
|
|
|
8
8
|
var _useQuery = require("../useQuery");
|
|
9
9
|
var _utils = require("../utils");
|
|
10
10
|
var queryKeyHelpers = _interopRequireWildcard(require("./queryKeyHelpers"));
|
|
11
|
+
var _paramKeys = _interopRequireDefault(require("./paramKeys"));
|
|
11
12
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
13
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
18
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
19
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
14
20
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
15
21
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } /*
|
|
16
22
|
* Copyright (c) 2023, Salesforce, Inc.
|
|
@@ -39,6 +45,10 @@ const useShopperContext = (apiOptions, queryOptions = {}) => {
|
|
|
39
45
|
// Parameters can be set in `apiOptions` or `client.clientConfig`;
|
|
40
46
|
// we must merge them in order to generate the correct query key.
|
|
41
47
|
const netOptions = (0, _utils.omitNullableParameters)((0, _utils.mergeOptions)(client, apiOptions));
|
|
48
|
+
|
|
49
|
+
// get param keys for the api from netOptions
|
|
50
|
+
const paramKeys = [..._paramKeys.default[methodName], ...(0, _utils.getCustomKeys)(netOptions.parameters)];
|
|
51
|
+
const parameters = (0, _utils.pick)(netOptions.parameters, paramKeys);
|
|
42
52
|
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters);
|
|
43
53
|
// We don't use `netOptions` here because we manipulate the options in `useQuery`.
|
|
44
54
|
const method = /*#__PURE__*/function () {
|
|
@@ -52,7 +62,9 @@ const useShopperContext = (apiOptions, queryOptions = {}) => {
|
|
|
52
62
|
|
|
53
63
|
// For some reason, if we don't explicitly set these generic parameters, the inferred type for
|
|
54
64
|
// `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
|
|
55
|
-
return (0, _useQuery.useQuery)(netOptions,
|
|
65
|
+
return (0, _useQuery.useQuery)(_objectSpread(_objectSpread({}, netOptions), {}, {
|
|
66
|
+
parameters
|
|
67
|
+
}), queryOptions, {
|
|
56
68
|
method,
|
|
57
69
|
queryKey,
|
|
58
70
|
requiredParameters
|
|
@@ -15,11 +15,6 @@ export type QueryKeys = {
|
|
|
15
15
|
];
|
|
16
16
|
};
|
|
17
17
|
type QueryKeyHelper<T extends keyof QueryKeys> = {
|
|
18
|
-
/**
|
|
19
|
-
* Reduces the given parameters (which may have additional, unknown properties) to an object
|
|
20
|
-
* containing *only* the properties required for an endpoint.
|
|
21
|
-
*/
|
|
22
|
-
parameters: (params: Params<T>) => Params<T>;
|
|
23
18
|
/** Generates the path component of the query key for an endpoint. */
|
|
24
19
|
path: (params: Params<T>) => ExcludeTail<QueryKeys[T]>;
|
|
25
20
|
/** Generates the full query key for an endpoint. */
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getShopperContext = void 0;
|
|
7
7
|
var _utils = require("../utils");
|
|
8
|
+
var _paramKeys = _interopRequireDefault(require("./paramKeys"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
10
|
/*
|
|
9
11
|
* Copyright (c) 2023, Salesforce, Inc.
|
|
10
12
|
* All rights reserved.
|
|
@@ -18,7 +20,9 @@ var _utils = require("../utils");
|
|
|
18
20
|
// and making those generic would add too much complexity.
|
|
19
21
|
|
|
20
22
|
const getShopperContext = exports.getShopperContext = {
|
|
21
|
-
parameters: params => (0, _utils.pick)(params, ['organizationId', 'usid']),
|
|
22
23
|
path: params => ['/commerce-sdk-react', '/organizations/', params.organizationId, '/shopper-context/', params.usid],
|
|
23
|
-
queryKey: params =>
|
|
24
|
+
queryKey: params => {
|
|
25
|
+
const paramKeys = [..._paramKeys.default['getShopperContext'], ...(0, _utils.getCustomKeys)(params)];
|
|
26
|
+
return [...getShopperContext.path(params), (0, _utils.pick)(params, paramKeys)];
|
|
27
|
+
}
|
|
24
28
|
};
|
|
@@ -79,8 +79,13 @@ const cacheUpdateMatrix = exports.cacheUpdateMatrix = {
|
|
|
79
79
|
update: [{
|
|
80
80
|
queryKey: _queryKeyHelpers.getCustomerProductLists.queryKey(parameters),
|
|
81
81
|
updater: createUpdateFunction(result => {
|
|
82
|
-
//
|
|
83
|
-
result.data
|
|
82
|
+
// if a user has no product list, data will not present in the response.
|
|
83
|
+
if (!result.data) {
|
|
84
|
+
result.data = [response];
|
|
85
|
+
} else {
|
|
86
|
+
// Add new list to front of the lists.
|
|
87
|
+
result.data.unshift(response);
|
|
88
|
+
}
|
|
84
89
|
result.limit++;
|
|
85
90
|
result.total++;
|
|
86
91
|
return result;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const getCustomer: readonly ["organizationId", "customerId", "siteId"];
|
|
2
|
+
export declare const getCustomerAddress: readonly ["organizationId", "customerId", "addressName", "siteId"];
|
|
3
|
+
export declare const getCustomerBaskets: readonly ["organizationId", "customerId", "siteId"];
|
|
4
|
+
export declare const getCustomerOrders: readonly ["organizationId", "customerId", "crossSites", "from", "until", "status", "siteId", "offset", "limit"];
|
|
5
|
+
export declare const getCustomerPaymentInstrument: readonly ["organizationId", "customerId", "paymentInstrumentId", "siteId"];
|
|
6
|
+
export declare const getCustomerProductLists: readonly ["organizationId", "customerId", "siteId"];
|
|
7
|
+
export declare const getCustomerProductList: readonly ["organizationId", "customerId", "listId", "siteId"];
|
|
8
|
+
export declare const getCustomerProductListItem: readonly ["organizationId", "customerId", "listId", "itemId", "siteId"];
|
|
9
|
+
export declare const getPublicProductListsBySearchTerm: readonly ["organizationId", "email", "firstName", "lastName", "siteId"];
|
|
10
|
+
export declare const getPublicProductList: readonly ["organizationId", "listId", "siteId"];
|
|
11
|
+
export declare const getProductListItem: readonly ["organizationId", "listId", "itemId", "siteId"];
|
|
12
|
+
declare const _default: {
|
|
13
|
+
getCustomer: readonly ["organizationId", "customerId", "siteId"];
|
|
14
|
+
getCustomerAddress: readonly ["organizationId", "customerId", "addressName", "siteId"];
|
|
15
|
+
getCustomerBaskets: readonly ["organizationId", "customerId", "siteId"];
|
|
16
|
+
getCustomerOrders: readonly ["organizationId", "customerId", "crossSites", "from", "until", "status", "siteId", "offset", "limit"];
|
|
17
|
+
getCustomerPaymentInstrument: readonly ["organizationId", "customerId", "paymentInstrumentId", "siteId"];
|
|
18
|
+
getCustomerProductList: readonly ["organizationId", "customerId", "listId", "siteId"];
|
|
19
|
+
getCustomerProductLists: readonly ["organizationId", "customerId", "siteId"];
|
|
20
|
+
getCustomerProductListItem: readonly ["organizationId", "customerId", "listId", "itemId", "siteId"];
|
|
21
|
+
getPublicProductListsBySearchTerm: readonly ["organizationId", "email", "firstName", "lastName", "siteId"];
|
|
22
|
+
getPublicProductList: readonly ["organizationId", "listId", "siteId"];
|
|
23
|
+
getProductListItem: readonly ["organizationId", "listId", "itemId", "siteId"];
|
|
24
|
+
};
|
|
25
|
+
export default _default;
|
|
26
|
+
//# sourceMappingURL=paramKeys.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getPublicProductListsBySearchTerm = exports.getPublicProductList = exports.getProductListItem = exports.getCustomerProductLists = exports.getCustomerProductListItem = exports.getCustomerProductList = exports.getCustomerPaymentInstrument = exports.getCustomerOrders = exports.getCustomerBaskets = exports.getCustomerAddress = exports.getCustomer = exports.default = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (c) 2024, Salesforce, Inc.
|
|
9
|
+
* All rights reserved.
|
|
10
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
11
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
12
|
+
*/
|
|
13
|
+
const getCustomer = exports.getCustomer = ['organizationId', 'customerId', 'siteId'];
|
|
14
|
+
const getCustomerAddress = exports.getCustomerAddress = ['organizationId', 'customerId', 'addressName', 'siteId'];
|
|
15
|
+
const getCustomerBaskets = exports.getCustomerBaskets = ['organizationId', 'customerId', 'siteId'];
|
|
16
|
+
const getCustomerOrders = exports.getCustomerOrders = ['organizationId', 'customerId', 'crossSites', 'from', 'until', 'status', 'siteId', 'offset', 'limit'];
|
|
17
|
+
const getCustomerPaymentInstrument = exports.getCustomerPaymentInstrument = ['organizationId', 'customerId', 'paymentInstrumentId', 'siteId'];
|
|
18
|
+
const getCustomerProductLists = exports.getCustomerProductLists = ['organizationId', 'customerId', 'siteId'];
|
|
19
|
+
const getCustomerProductList = exports.getCustomerProductList = ['organizationId', 'customerId', 'listId', 'siteId'];
|
|
20
|
+
const getCustomerProductListItem = exports.getCustomerProductListItem = ['organizationId', 'customerId', 'listId', 'itemId', 'siteId'];
|
|
21
|
+
const getPublicProductListsBySearchTerm = exports.getPublicProductListsBySearchTerm = ['organizationId', 'email', 'firstName', 'lastName', 'siteId'];
|
|
22
|
+
const getPublicProductList = exports.getPublicProductList = ['organizationId', 'listId', 'siteId'];
|
|
23
|
+
const getProductListItem = exports.getProductListItem = ['organizationId', 'listId', 'itemId', 'siteId'];
|
|
24
|
+
// TODO: Re-implement (and update description from RAML spec) when the endpoint exits closed beta.
|
|
25
|
+
// export const getExternalProfile = [
|
|
26
|
+
// 'organizationId',
|
|
27
|
+
// 'externalId',
|
|
28
|
+
// 'authenticationProviderId',
|
|
29
|
+
// 'siteId'
|
|
30
|
+
// ] as const
|
|
31
|
+
var _default = exports.default = {
|
|
32
|
+
getCustomer,
|
|
33
|
+
getCustomerAddress,
|
|
34
|
+
getCustomerBaskets,
|
|
35
|
+
getCustomerOrders,
|
|
36
|
+
getCustomerPaymentInstrument,
|
|
37
|
+
getCustomerProductList,
|
|
38
|
+
getCustomerProductLists,
|
|
39
|
+
getCustomerProductListItem,
|
|
40
|
+
getPublicProductListsBySearchTerm,
|
|
41
|
+
getPublicProductList,
|
|
42
|
+
getProductListItem
|
|
43
|
+
// getExternalProfile
|
|
44
|
+
};
|