@salesforce/commerce-sdk-react 1.3.0 → 1.4.0-gpt-nightly-20240315030539
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 +6 -1
- package/auth/index.d.ts +0 -2
- package/auth/index.js +2 -5
- package/components/ShopperExperience/Component/index.d.ts +1 -0
- package/components/ShopperExperience/Component/index.js +46 -5
- package/components/ShopperExperience/Page/index.d.ts +4 -0
- package/components/ShopperExperience/Page/index.js +14 -3
- package/components/ShopperExperience/Region/index.js +1 -1
- 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/utils.d.ts +2 -0
- package/hooks/utils.js +11 -2
- package/package.json +7 -6
- package/provider.js +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
## v1.4.0-gpt-nightly-20240315030539 (Mar 15, 2024)
|
|
2
|
+
## v1.4.0-dev (Jan 22, 2024)
|
|
3
|
+
- Fix invalid query params warnings and allow custom query [#1655](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1655)
|
|
4
|
+
- Fix cannot read properties of undefined (reading 'unshift') [#1689](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1689)
|
|
5
|
+
- Add Shopper SEO hook [#1688](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1688)
|
|
6
|
+
|
|
1
7
|
## v1.3.0 (Jan 19, 2024)
|
|
2
8
|
|
|
3
9
|
- 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
10
|
|
|
6
11
|
## v1.2.0 (Dec 08, 2023)
|
|
7
12
|
|
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
|
|
|
@@ -2,6 +2,7 @@ import { Component as ComponentType } from '../types';
|
|
|
2
2
|
type ComponentProps = {
|
|
3
3
|
component: ComponentType;
|
|
4
4
|
};
|
|
5
|
+
export declare const REQUIRED_EGPT_JSX_COMPONENTS: string[];
|
|
5
6
|
/**
|
|
6
7
|
* This component will render a page designer page given its serialized data object.
|
|
7
8
|
*
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.Component = void 0;
|
|
7
|
-
var _react =
|
|
6
|
+
exports.default = exports.REQUIRED_EGPT_JSX_COMPONENTS = exports.Component = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _Page = require("../Page");
|
|
9
|
+
var _reactJsxParser = _interopRequireDefault(require("react-jsx-parser"));
|
|
9
10
|
const _excluded = ["data"];
|
|
10
11
|
/*
|
|
11
12
|
* Copyright (c) 2023, Salesforce, Inc.
|
|
@@ -14,12 +15,21 @@ const _excluded = ["data"];
|
|
|
14
15
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
15
16
|
*/
|
|
16
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
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); }
|
|
19
|
+
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; }
|
|
17
20
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
18
21
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
19
22
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
20
23
|
const ComponentNotFound = ({
|
|
21
24
|
typeId
|
|
22
25
|
}) => /*#__PURE__*/_react.default.createElement("div", null, `Component type '${typeId}' not found!`);
|
|
26
|
+
|
|
27
|
+
// The main use case for the JSX parser is to leverage eGPT Generative Components
|
|
28
|
+
// from page designer. At the moment, only Chakra UI components are supported. There isn't
|
|
29
|
+
// a good place to put this list of required components, so we'll just put it here for now.
|
|
30
|
+
// In the future, we need to have a place to share the list.
|
|
31
|
+
const REQUIRED_EGPT_JSX_COMPONENTS = exports.REQUIRED_EGPT_JSX_COMPONENTS = ['Accordion', 'AccordionButton', 'AccordionIcon', 'AccordionItem', 'AccordionPanel', 'Alert', 'AlertDialog', 'AlertDialogBody', 'AlertDialogContent', 'AlertDialogFooter', 'AlertDialogHeader', 'AlertDialogOverlay', 'AlertIcon', 'AlertTitle', 'AspectRatio', 'Badge', 'Box', 'Breadcrumb', 'BreadcrumbItem', 'BreadcrumbLink', 'Button', 'ButtonGroup', 'Center', 'ChakraProvider', 'Checkbox', 'CloseButton', 'Container', 'Divider', 'Drawer', 'DrawerBody', 'DrawerCloseButton', 'DrawerContent', 'DrawerFooter', 'DrawerHeader', 'DrawerOverlay', 'Fade', 'Flex', 'FormControl', 'FormErrorMessage', 'FormLabel', 'Grid', 'GridItem', 'HStack', 'Heading', 'Icon', 'IconButton', 'Image', 'Img', 'Input', 'InputGroup', 'InputLeftElement', 'InputRightElement', 'Link', 'List', 'ListItem', 'Modal', 'ModalBody', 'ModalCloseButton', 'ModalContent', 'ModalFooter', 'ModalHeader', 'ModalOverlay', 'Popover', 'PopoverArrow', 'PopoverBody', 'PopoverCloseButton', 'PopoverContent', 'PopoverFooter', 'PopoverHeader', 'PopoverTrigger', 'Portal', 'Radio', 'RadioGroup', 'Select', 'SimpleGrid', 'Skeleton', 'Spacer', 'Spinner', 'Stack', 'StackDivider', 'StylesProvider', 'Text', 'Tooltip', 'VStack', 'Wrap', 'WrapItem'];
|
|
32
|
+
|
|
23
33
|
/**
|
|
24
34
|
* This component will render a page designer page given its serialized data object.
|
|
25
35
|
*
|
|
@@ -31,18 +41,49 @@ const Component = ({
|
|
|
31
41
|
component
|
|
32
42
|
}) => {
|
|
33
43
|
const pageContext = (0, _Page.usePageContext)();
|
|
34
|
-
const
|
|
44
|
+
const {
|
|
45
|
+
jsxParserComponents
|
|
46
|
+
} = pageContext;
|
|
35
47
|
const {
|
|
36
48
|
data
|
|
37
49
|
} = component,
|
|
38
50
|
rest = _objectWithoutProperties(component, _excluded);
|
|
51
|
+
const {
|
|
52
|
+
code
|
|
53
|
+
} = data || {};
|
|
54
|
+
const isEinsteinAssistedComponent = !!code;
|
|
55
|
+
let instance = /*#__PURE__*/_react.default.createElement(ComponentNotFound, _extends({}, rest, data));
|
|
56
|
+
(0, _react.useEffect)(() => {
|
|
57
|
+
if (isEinsteinAssistedComponent) {
|
|
58
|
+
const missingJsxComponents = REQUIRED_EGPT_JSX_COMPONENTS.filter(required => {
|
|
59
|
+
return !(jsxParserComponents !== null && jsxParserComponents !== void 0 && jsxParserComponents[required]);
|
|
60
|
+
});
|
|
61
|
+
Boolean(missingJsxComponents.length) && console.error('[Page Designer Einstein Assisted Component] - The following component implementation are missing: ', missingJsxComponents.join(', ') + '.\n', 'You must ensure the "jsxParserComponents" prop of the <Page/> component includes these components, otherwise the component may fail to render.');
|
|
62
|
+
}
|
|
63
|
+
}, [code === null || code === void 0 ? void 0 : code.code]);
|
|
64
|
+
if (isEinsteinAssistedComponent) {
|
|
65
|
+
// TODO: this is a workaround for the fact that
|
|
66
|
+
// 'react-jsx-parser' still uses React@16 typings
|
|
67
|
+
// we need to cast it to the newer React typings
|
|
68
|
+
const JsxParserComponent = _reactJsxParser.default;
|
|
69
|
+
instance = /*#__PURE__*/_react.default.createElement(JsxParserComponent, _extends({
|
|
70
|
+
components: pageContext.jsxParserComponents
|
|
71
|
+
// TODO: make component data structure more clear
|
|
72
|
+
// from the PD custom editor, let's not have "code.code"
|
|
73
|
+
,
|
|
74
|
+
jsx: code.code
|
|
75
|
+
}, rest, data));
|
|
76
|
+
} else if (pageContext !== null && pageContext !== void 0 && pageContext.components[component.typeId]) {
|
|
77
|
+
const ComponentClass = pageContext === null || pageContext === void 0 ? void 0 : pageContext.components[component.typeId];
|
|
78
|
+
instance = /*#__PURE__*/_react.default.createElement(ComponentClass, _extends({}, rest, data));
|
|
79
|
+
}
|
|
39
80
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
40
81
|
id: component.id,
|
|
41
82
|
className: "component"
|
|
42
83
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
43
84
|
className: "container"
|
|
44
|
-
},
|
|
85
|
+
}, instance));
|
|
45
86
|
};
|
|
46
87
|
exports.Component = Component;
|
|
47
|
-
Component.displayName = 'Component';
|
|
88
|
+
Component.displayName = '[Page Designer] Component';
|
|
48
89
|
var _default = exports.default = Component;
|
|
@@ -3,12 +3,15 @@ import type { Component as ComponentType, Page as PageType } from '../types';
|
|
|
3
3
|
type ComponentMap = {
|
|
4
4
|
[typeId: string]: React.ComponentType<ComponentType & unknown>;
|
|
5
5
|
};
|
|
6
|
+
type JsxParserComponents = Record<string, ComponentType>;
|
|
6
7
|
interface PageProps extends React.ComponentProps<'div'> {
|
|
7
8
|
page: PageType;
|
|
8
9
|
components: ComponentMap;
|
|
10
|
+
jsxParserComponents?: JsxParserComponents;
|
|
9
11
|
}
|
|
10
12
|
type PageContextValue = {
|
|
11
13
|
components: ComponentMap;
|
|
14
|
+
jsxParserComponents?: JsxParserComponents;
|
|
12
15
|
};
|
|
13
16
|
export declare const PageContext: React.Context<PageContextValue | undefined>;
|
|
14
17
|
export declare const usePageContext: () => PageContextValue;
|
|
@@ -18,6 +21,7 @@ export declare const usePageContext: () => PageContextValue;
|
|
|
18
21
|
* @param {PageProps} props
|
|
19
22
|
* @param {Page} props.region - The page designer page data representation.
|
|
20
23
|
* @param {ComponentMap} props.components - A mapping of typeId's to react components representing the type.
|
|
24
|
+
* @param {JsxParserComponents} [props.jsxParserComponents] - An array of react components that the jsx parser can use, optional.
|
|
21
25
|
* @returns {React.ReactElement} - Page component.
|
|
22
26
|
*/
|
|
23
27
|
export declare const Page: {
|
|
@@ -7,7 +7,7 @@ exports.usePageContext = exports.default = exports.PageContext = exports.Page =
|
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _reactHelmet = require("react-helmet");
|
|
9
9
|
var _Region = require("../Region");
|
|
10
|
-
const _excluded = ["page", "components", "className"];
|
|
10
|
+
const _excluded = ["page", "components", "jsxParserComponents", "className"];
|
|
11
11
|
/*
|
|
12
12
|
* Copyright (c) 2023, Salesforce, Inc.
|
|
13
13
|
* All rights reserved.
|
|
@@ -44,6 +44,7 @@ const usePageContext = () => {
|
|
|
44
44
|
* @param {PageProps} props
|
|
45
45
|
* @param {Page} props.region - The page designer page data representation.
|
|
46
46
|
* @param {ComponentMap} props.components - A mapping of typeId's to react components representing the type.
|
|
47
|
+
* @param {JsxParserComponents} [props.jsxParserComponents] - An array of react components that the jsx parser can use, optional.
|
|
47
48
|
* @returns {React.ReactElement} - Page component.
|
|
48
49
|
*/
|
|
49
50
|
exports.usePageContext = usePageContext;
|
|
@@ -51,11 +52,13 @@ const Page = props => {
|
|
|
51
52
|
const {
|
|
52
53
|
page,
|
|
53
54
|
components,
|
|
55
|
+
jsxParserComponents,
|
|
54
56
|
className = ''
|
|
55
57
|
} = props,
|
|
56
58
|
rest = _objectWithoutProperties(props, _excluded);
|
|
57
59
|
const [contextValue, setContextValue] = (0, _react.useState)({
|
|
58
|
-
components
|
|
60
|
+
components,
|
|
61
|
+
jsxParserComponents
|
|
59
62
|
});
|
|
60
63
|
const {
|
|
61
64
|
id,
|
|
@@ -72,6 +75,14 @@ const Page = props => {
|
|
|
72
75
|
components
|
|
73
76
|
}));
|
|
74
77
|
}, [components]);
|
|
78
|
+
(0, _react.useEffect)(() => {
|
|
79
|
+
if (!jsxParserComponents) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
setContextValue(_objectSpread(_objectSpread({}, contextValue), {}, {
|
|
83
|
+
jsxParserComponents
|
|
84
|
+
}));
|
|
85
|
+
}, [jsxParserComponents]);
|
|
75
86
|
return /*#__PURE__*/_react.default.createElement(PageContext.Provider, {
|
|
76
87
|
value: contextValue
|
|
77
88
|
}, /*#__PURE__*/_react.default.createElement(_reactHelmet.Helmet, null, pageTitle && /*#__PURE__*/_react.default.createElement("title", null, pageTitle), pageDescription && /*#__PURE__*/_react.default.createElement("meta", {
|
|
@@ -91,5 +102,5 @@ const Page = props => {
|
|
|
91
102
|
})))));
|
|
92
103
|
};
|
|
93
104
|
exports.Page = Page;
|
|
94
|
-
Page.displayName = 'Page';
|
|
105
|
+
Page.displayName = '[Page Designer] Page';
|
|
95
106
|
var _default = exports.default = Page;
|
|
@@ -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
|