@salesforce/commerce-sdk-react 2.0.0-nightly-20240620080221 → 2.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.
- package/CHANGELOG.md +8 -4
- package/auth/index.d.ts +3 -0
- package/auth/index.js +9 -8
- package/auth/storage/cookie.js +3 -3
- package/components/ShopperExperience/Component/index.js +4 -4
- package/components/ShopperExperience/Page/index.js +6 -6
- package/components/ShopperExperience/Region/index.js +4 -4
- package/components/ShopperExperience/prop-types.js +1 -1
- package/components/StorefrontPreview/storefront-preview.js +4 -4
- package/components/StorefrontPreview/utils.d.ts +3 -1
- package/components/StorefrontPreview/utils.js +5 -2
- package/constant.d.ts +4 -0
- package/constant.js +7 -1
- package/hooks/ShopperBaskets/cache.js +11 -2
- package/hooks/ShopperBaskets/helpers.d.ts +183 -0
- package/hooks/ShopperBaskets/helpers.js +84 -0
- package/hooks/ShopperBaskets/index.d.ts +1 -0
- package/hooks/ShopperBaskets/index.js +11 -0
- package/hooks/ShopperBaskets/mutation.d.ts +4 -0
- package/hooks/ShopperBaskets/mutation.js +5 -1
- package/hooks/ShopperBaskets/query.js +6 -6
- package/hooks/ShopperContexts/mutation.js +1 -1
- package/hooks/ShopperContexts/query.js +6 -6
- package/hooks/ShopperCustomers/cache.js +2 -2
- package/hooks/ShopperCustomers/mutation.js +1 -1
- package/hooks/ShopperCustomers/query.js +6 -6
- package/hooks/ShopperExperience/query.js +6 -6
- package/hooks/ShopperGiftCertificates/query.js +6 -6
- package/hooks/ShopperLogin/mutation.js +1 -1
- package/hooks/ShopperLogin/query.js +6 -6
- package/hooks/ShopperOrders/cache.js +2 -2
- package/hooks/ShopperOrders/mutation.js +1 -1
- package/hooks/ShopperOrders/query.js +6 -6
- package/hooks/ShopperProducts/query.js +6 -6
- package/hooks/ShopperPromotions/query.js +6 -6
- package/hooks/ShopperSearch/query.js +6 -6
- package/hooks/ShopperSeo/query.js +6 -6
- package/hooks/ShopperStores/query.js +6 -6
- package/hooks/index.js +1 -1
- package/hooks/useAccessToken.js +1 -1
- package/hooks/useAuthContext.js +1 -1
- package/hooks/useAuthHelper.js +1 -1
- package/hooks/useAuthorizationHeader.js +5 -5
- package/hooks/useCommerceApi.js +1 -1
- package/hooks/useConfig.js +1 -1
- package/hooks/useCustomerId.js +1 -1
- package/hooks/useCustomerType.js +1 -1
- package/hooks/useEncUserId.js +1 -1
- package/hooks/useMutation.js +5 -5
- package/hooks/useQuery.js +5 -5
- package/hooks/useUsid.js +1 -1
- package/hooks/utils.js +2 -2
- package/index.js +1 -1
- package/package.json +6 -5
- package/provider.d.ts +3 -0
- package/provider.js +13 -6
- package/types.d.ts +36 -0
- package/types.js +5 -0
- package/utils.js +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
## v2.0.0-
|
|
2
|
-
## v2.0.0-dev (Jun
|
|
3
|
-
## v3.6.0-
|
|
1
|
+
## v2.0.0-preview.0 (Jun 21, 2024)
|
|
2
|
+
## v2.0.0-dev (Jun 21, 2024)
|
|
3
|
+
## v3.6.0-preview.0 (Jun 21, 2024)
|
|
4
|
+
## v2.0.0-dev (Jun 21, 2024)
|
|
5
|
+
## v3.6.0-dev.1 (Jun 21, 2024)
|
|
4
6
|
## v2.0.0-dev (May 21, 2024)
|
|
5
|
-
- Upgrade to commerce-sdk-isomorphic v2.0.0 [#1794](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1794)
|
|
6
7
|
- Add `useCustomQuery` and `useCustomMutation` for SCAPI custom endpoint support [#1793](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1793)
|
|
7
8
|
- Add Shopper Stores hooks [#1788](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1788)
|
|
9
|
+
- Add a helper method to add an item to either new or existing basket [#1677](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1677)
|
|
10
|
+
- Add `updateItemsInBasket` mutation [#1852](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1852)
|
|
11
|
+
- Upgrade to commerce-sdk-isomorphic v2.1.0 [#1852](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1852)
|
|
8
12
|
|
|
9
13
|
## v1.4.2 (Apr 17, 2024)
|
|
10
14
|
- Update SLAS private proxy path [#1752](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1752)
|
package/auth/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { helpers, ShopperLoginTypes, ShopperCustomersTypes } from 'commerce-sdk-isomorphic';
|
|
2
2
|
import { ApiClientConfigParams, Prettify, RemoveStringIndex } from '../hooks/types';
|
|
3
3
|
import { CustomerType } from '../hooks/useCustomerType';
|
|
4
|
+
import { Logger } from '../types';
|
|
4
5
|
type TokenResponse = ShopperLoginTypes.TokenResponse;
|
|
5
6
|
type Helpers = typeof helpers;
|
|
6
7
|
interface AuthConfig extends ApiClientConfigParams {
|
|
@@ -12,6 +13,7 @@ interface AuthConfig extends ApiClientConfigParams {
|
|
|
12
13
|
enablePWAKitPrivateClient?: boolean;
|
|
13
14
|
clientSecret?: string;
|
|
14
15
|
silenceWarnings?: boolean;
|
|
16
|
+
logger: Logger;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* The extended field is not from api response, we manually store the auth type,
|
|
@@ -43,6 +45,7 @@ declare class Auth {
|
|
|
43
45
|
private OCAPISessionsURL;
|
|
44
46
|
private clientSecret;
|
|
45
47
|
private silenceWarnings;
|
|
48
|
+
private logger;
|
|
46
49
|
constructor(config: AuthConfig);
|
|
47
50
|
get(name: AuthDataKeys): string;
|
|
48
51
|
private set;
|
package/auth/index.js
CHANGED
|
@@ -11,11 +11,11 @@ var _utils = require("../utils");
|
|
|
11
11
|
var _constant = require("../constant");
|
|
12
12
|
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; }
|
|
13
13
|
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; }
|
|
14
|
-
function _defineProperty(
|
|
15
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i :
|
|
14
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
16
16
|
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); }
|
|
17
|
-
function asyncGeneratorStep(
|
|
18
|
-
function _asyncToGenerator(
|
|
17
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
18
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } /*
|
|
19
19
|
* Copyright (c) 2023, Salesforce, Inc.
|
|
20
20
|
* All rights reserved.
|
|
21
21
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -120,9 +120,9 @@ const DATA_MAP = {
|
|
|
120
120
|
*/
|
|
121
121
|
class Auth {
|
|
122
122
|
constructor(config) {
|
|
123
|
-
// Special endpoint for injecting SLAS private client secret
|
|
124
|
-
const baseUrl = config.proxy.split(
|
|
125
|
-
const privateClientEndpoint = `${baseUrl}
|
|
123
|
+
// Special endpoint for injecting SLAS private client secret.
|
|
124
|
+
const baseUrl = config.proxy.split(_constant.MOBIFY_PATH)[0];
|
|
125
|
+
const privateClientEndpoint = `${baseUrl}${_constant.SLAS_PRIVATE_PROXY_PATH}`;
|
|
126
126
|
this.client = new _commerceSdkIsomorphic.ShopperLogin({
|
|
127
127
|
proxy: config.enablePWAKitPrivateClient ? privateClientEndpoint : config.proxy,
|
|
128
128
|
parameters: {
|
|
@@ -158,6 +158,7 @@ class Auth {
|
|
|
158
158
|
this.redirectURI = config.redirectURI;
|
|
159
159
|
this.fetchedToken = config.fetchedToken || '';
|
|
160
160
|
this.OCAPISessionsURL = config.OCAPISessionsURL || '';
|
|
161
|
+
this.logger = config.logger;
|
|
161
162
|
|
|
162
163
|
/*
|
|
163
164
|
* There are 2 ways to enable SLAS private client mode.
|
|
@@ -353,7 +354,7 @@ class Auth {
|
|
|
353
354
|
}
|
|
354
355
|
logWarning = msg => {
|
|
355
356
|
if (!this.silenceWarnings) {
|
|
356
|
-
|
|
357
|
+
this.logger.warn(msg);
|
|
357
358
|
}
|
|
358
359
|
};
|
|
359
360
|
|
package/auth/storage/cookie.js
CHANGED
|
@@ -7,11 +7,11 @@ exports.CookieStorage = void 0;
|
|
|
7
7
|
var _jsCookie = _interopRequireDefault(require("js-cookie"));
|
|
8
8
|
var _utils = require("../../utils");
|
|
9
9
|
var _base = require("./base");
|
|
10
|
-
function _interopRequireDefault(
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
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; }
|
|
12
12
|
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; }
|
|
13
|
-
function _defineProperty(
|
|
14
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i :
|
|
13
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
15
15
|
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); } /*
|
|
16
16
|
* Copyright (c) 2023, Salesforce, Inc.
|
|
17
17
|
* All rights reserved.
|
|
@@ -13,10 +13,10 @@ const _excluded = ["data"];
|
|
|
13
13
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
14
14
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
15
15
|
*/
|
|
16
|
-
function _interopRequireDefault(
|
|
17
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (
|
|
18
|
-
function _objectWithoutProperties(
|
|
19
|
-
function _objectWithoutPropertiesLoose(
|
|
16
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
18
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
19
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
|
|
20
20
|
const ComponentNotFound = ({
|
|
21
21
|
typeId
|
|
22
22
|
}) => /*#__PURE__*/_react.default.createElement("div", null, `Component type '${typeId}' not found!`);
|
|
@@ -15,15 +15,15 @@ const _excluded = ["page", "components", "className"];
|
|
|
15
15
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
16
16
|
*/
|
|
17
17
|
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); }
|
|
18
|
-
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 &&
|
|
19
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (
|
|
18
|
+
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 && {}.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; }
|
|
19
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
20
20
|
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; }
|
|
21
21
|
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; }
|
|
22
|
-
function _defineProperty(
|
|
23
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i :
|
|
22
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
23
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
24
24
|
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); }
|
|
25
|
-
function _objectWithoutProperties(
|
|
26
|
-
function _objectWithoutPropertiesLoose(
|
|
25
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
26
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
|
|
27
27
|
// This context will hold the component map as well as any other future context.
|
|
28
28
|
const PageContext = exports.PageContext = /*#__PURE__*/_react.default.createContext(undefined);
|
|
29
29
|
|
|
@@ -15,10 +15,10 @@ const _excluded = ["region", "className"];
|
|
|
15
15
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
16
16
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
17
17
|
*/
|
|
18
|
-
function _interopRequireDefault(
|
|
19
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (
|
|
20
|
-
function _objectWithoutProperties(
|
|
21
|
-
function _objectWithoutPropertiesLoose(
|
|
18
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
20
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
21
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
|
|
22
22
|
/**
|
|
23
23
|
* This PropType represents a `region` object from the ShopperExperience API.
|
|
24
24
|
*/
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.regionPropType = exports.pageType = exports.componentPropType = void 0;
|
|
7
7
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
-
function _interopRequireDefault(
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
/*
|
|
10
10
|
* Copyright (c) 2023, Salesforce, Inc.
|
|
11
11
|
* All rights reserved.
|
|
@@ -10,13 +10,13 @@ var _reactHelmet = require("react-helmet");
|
|
|
10
10
|
var _utils = require("./utils");
|
|
11
11
|
var _reactRouterDom = require("react-router-dom");
|
|
12
12
|
var _hooks = require("../../hooks");
|
|
13
|
-
function _interopRequireDefault(
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
14
|
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); }
|
|
15
|
-
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 &&
|
|
15
|
+
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 && {}.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; }
|
|
16
16
|
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; }
|
|
17
17
|
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; }
|
|
18
|
-
function _defineProperty(
|
|
19
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i :
|
|
18
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
19
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
20
20
|
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); } /*
|
|
21
21
|
* Copyright (c) 2023, Salesforce, Inc.
|
|
22
22
|
* All rights reserved.
|
|
@@ -3,7 +3,9 @@ import { ApiClients } from '../../hooks/types';
|
|
|
3
3
|
* @private
|
|
4
4
|
*/
|
|
5
5
|
export declare const detectStorefrontPreview: () => boolean;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Returns the URL to load the Storefront Preview client script from the parent origin.
|
|
8
|
+
* The client script is served from Runtime Admin and is not a part of the PWA Retail React App bundle.
|
|
7
9
|
* @private
|
|
8
10
|
*/
|
|
9
11
|
export declare const getClientScript: () => string;
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.proxyRequests = exports.getClientScript = exports.detectStorefrontPreview = exports.CustomPropTypes = void 0;
|
|
7
7
|
var _utils = require("../../utils");
|
|
8
|
+
var _constant = require("../../constant");
|
|
8
9
|
/*
|
|
9
10
|
* Copyright (c) 2023, Salesforce, Inc.
|
|
10
11
|
* All rights reserved.
|
|
@@ -20,13 +21,15 @@ const detectStorefrontPreview = () => {
|
|
|
20
21
|
return (0, _utils.isOriginTrusted)(parentOrigin);
|
|
21
22
|
};
|
|
22
23
|
|
|
23
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Returns the URL to load the Storefront Preview client script from the parent origin.
|
|
26
|
+
* The client script is served from Runtime Admin and is not a part of the PWA Retail React App bundle.
|
|
24
27
|
* @private
|
|
25
28
|
*/
|
|
26
29
|
exports.detectStorefrontPreview = detectStorefrontPreview;
|
|
27
30
|
const getClientScript = () => {
|
|
28
31
|
const parentOrigin = (0, _utils.getParentOrigin)() ?? 'https://runtime.commercecloud.com';
|
|
29
|
-
return parentOrigin === _utils.DEVELOPMENT_ORIGIN ? `${parentOrigin}/
|
|
32
|
+
return parentOrigin === _utils.DEVELOPMENT_ORIGIN ? `${parentOrigin}${_constant.LOCAL_BUNDLE_PATH}/static/storefront-preview.js` : `${parentOrigin}/cc/b2c/preview/preview.client.js`;
|
|
30
33
|
};
|
|
31
34
|
|
|
32
35
|
// Custom Prop Types.
|
package/constant.d.ts
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* This list contains domains that can host code in iframe
|
|
3
3
|
*/
|
|
4
4
|
export declare const IFRAME_HOST_ALLOW_LIST: readonly string[];
|
|
5
|
+
export declare const MOBIFY_PATH = "/mobify";
|
|
6
|
+
export declare const PROXY_PATH: string;
|
|
7
|
+
export declare const LOCAL_BUNDLE_PATH: string;
|
|
8
|
+
export declare const SLAS_PRIVATE_PROXY_PATH: string;
|
|
5
9
|
export declare const SLAS_SECRET_WARNING_MSG = "You are potentially exposing SLAS secret on browser. Make sure to keep it safe and secure!";
|
|
6
10
|
export declare const SLAS_SECRET_PLACEHOLDER = "_PLACEHOLDER_PROXY-PWA_KIT_SLAS_CLIENT_SECRET";
|
|
7
11
|
export declare const SLAS_SECRET_OVERRIDE_MSG = "You have enabled PWA Kit Private Client mode which gets the SLAS secret from your environment variable. The SLAS secret you have set in the Auth provider will be ignored.";
|
package/constant.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.SLAS_SECRET_WARNING_MSG = exports.SLAS_SECRET_PLACEHOLDER = exports.SLAS_SECRET_OVERRIDE_MSG = exports.IFRAME_HOST_ALLOW_LIST = void 0;
|
|
6
|
+
exports.SLAS_SECRET_WARNING_MSG = exports.SLAS_SECRET_PLACEHOLDER = exports.SLAS_SECRET_OVERRIDE_MSG = exports.SLAS_PRIVATE_PROXY_PATH = exports.PROXY_PATH = exports.MOBIFY_PATH = exports.LOCAL_BUNDLE_PATH = exports.IFRAME_HOST_ALLOW_LIST = void 0;
|
|
7
7
|
/*
|
|
8
8
|
* Copyright (c) 2023, Salesforce, Inc.
|
|
9
9
|
* All rights reserved.
|
|
@@ -15,6 +15,12 @@ exports.SLAS_SECRET_WARNING_MSG = exports.SLAS_SECRET_PLACEHOLDER = exports.SLAS
|
|
|
15
15
|
* This list contains domains that can host code in iframe
|
|
16
16
|
*/
|
|
17
17
|
const IFRAME_HOST_ALLOW_LIST = exports.IFRAME_HOST_ALLOW_LIST = Object.freeze(['https://runtime.commercecloud.com', 'https://runtime-admin-staging.mobify-storefront.com', 'https://runtime-admin-preview.mobify-storefront.com']);
|
|
18
|
+
|
|
19
|
+
// We hardcode these here since we don't want commerce-sdk-react to have a dependency on pwa-kit-runtime
|
|
20
|
+
const MOBIFY_PATH = exports.MOBIFY_PATH = '/mobify';
|
|
21
|
+
const PROXY_PATH = exports.PROXY_PATH = `${MOBIFY_PATH}/proxy`;
|
|
22
|
+
const LOCAL_BUNDLE_PATH = exports.LOCAL_BUNDLE_PATH = `${MOBIFY_PATH}/bundle/development`;
|
|
23
|
+
const SLAS_PRIVATE_PROXY_PATH = exports.SLAS_PRIVATE_PROXY_PATH = `${MOBIFY_PATH}/slas/private`;
|
|
18
24
|
const SLAS_SECRET_WARNING_MSG = exports.SLAS_SECRET_WARNING_MSG = 'You are potentially exposing SLAS secret on browser. Make sure to keep it safe and secure!';
|
|
19
25
|
const SLAS_SECRET_PLACEHOLDER = exports.SLAS_SECRET_PLACEHOLDER = '_PLACEHOLDER_PROXY-PWA_KIT_SLAS_CLIENT_SECRET';
|
|
20
26
|
const SLAS_SECRET_OVERRIDE_MSG = exports.SLAS_SECRET_OVERRIDE_MSG = 'You have enabled PWA Kit Private Client mode which gets the SLAS secret from your environment variable. The SLAS secret you have set in the Auth provider will be ignored.';
|
|
@@ -8,8 +8,8 @@ var _queryKeyHelpers = require("./queryKeyHelpers");
|
|
|
8
8
|
var _queryKeyHelpers2 = require("../ShopperCustomers/queryKeyHelpers");
|
|
9
9
|
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; }
|
|
10
10
|
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; }
|
|
11
|
-
function _defineProperty(
|
|
12
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i :
|
|
11
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
13
13
|
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
14
|
* Copyright (c) 2023, Salesforce, Inc.
|
|
15
15
|
* All rights reserved.
|
|
@@ -300,6 +300,15 @@ const cacheUpdateMatrix = exports.cacheUpdateMatrix = {
|
|
|
300
300
|
}, ...(customerId ? [updateCustomerBasketsQuery(customerId, parameters, response)] : [])]
|
|
301
301
|
};
|
|
302
302
|
},
|
|
303
|
+
updateItemsInBasket(customerId, {
|
|
304
|
+
parameters
|
|
305
|
+
}, response) {
|
|
306
|
+
return {
|
|
307
|
+
update: [{
|
|
308
|
+
queryKey: _queryKeyHelpers.getBasket.queryKey(parameters)
|
|
309
|
+
}, ...(customerId ? [updateCustomerBasketsQuery(customerId, parameters, response)] : [])]
|
|
310
|
+
};
|
|
311
|
+
},
|
|
303
312
|
updatePaymentInstrumentInBasket(customerId, {
|
|
304
313
|
parameters
|
|
305
314
|
}, response) {
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { ApiClients, Argument } from '../types';
|
|
2
|
+
import { ShopperBasketsTypes } from 'commerce-sdk-isomorphic';
|
|
3
|
+
type Client = ApiClients['shopperBaskets'];
|
|
4
|
+
type Basket = ShopperBasketsTypes.Basket;
|
|
5
|
+
/**
|
|
6
|
+
* This is a helper function for Basket Mutations.
|
|
7
|
+
* useShopperBasketsMutationHelper.addItemToNewOrExistingBasket: is responsible for managing the process of adding an item to a basket.
|
|
8
|
+
* - If a basket already exists, add the item to the basket immediately.
|
|
9
|
+
* - If a basket does not exist, create a new basket using the createBasket mutation
|
|
10
|
+
* and then add the item to the newly created basket using the addItemToBasket mutation.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import useShopperBasketsMutationHelper from '@salesforce/commerce-sdk-react'
|
|
14
|
+
*
|
|
15
|
+
* const Page = () => {
|
|
16
|
+
* const helpers = useShopperBasketsMutationHelper()
|
|
17
|
+
*
|
|
18
|
+
* const addToCart = async () => {
|
|
19
|
+
* const productItems = [{id: 123, quantity: 2}]
|
|
20
|
+
* await basketMutationHelpers.addItemToNewOrExistingBasket(productItems)
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* }
|
|
24
|
+
*/
|
|
25
|
+
export declare function useShopperBasketsMutationHelper(): {
|
|
26
|
+
addItemToNewOrExistingBasket: (productItem: ({
|
|
27
|
+
adjustedTax?: number | undefined;
|
|
28
|
+
basePrice?: number | undefined;
|
|
29
|
+
bonusDiscountLineItemId?: string | undefined;
|
|
30
|
+
bonusProductLineItem?: boolean | undefined;
|
|
31
|
+
bundledProductItems?: (any & {
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
})[] | undefined;
|
|
34
|
+
gift?: boolean | undefined;
|
|
35
|
+
giftMessage?: string | undefined;
|
|
36
|
+
inventoryId?: string | undefined;
|
|
37
|
+
itemId?: string | undefined;
|
|
38
|
+
itemText?: string | undefined;
|
|
39
|
+
optionItems?: ({
|
|
40
|
+
adjustedTax?: number | undefined;
|
|
41
|
+
basePrice?: number | undefined;
|
|
42
|
+
bonusDiscountLineItemId?: string | undefined;
|
|
43
|
+
bonusProductLineItem?: boolean | undefined;
|
|
44
|
+
bundledProductItems?: (any & {
|
|
45
|
+
[key: string]: any;
|
|
46
|
+
})[] | undefined;
|
|
47
|
+
gift?: boolean | undefined;
|
|
48
|
+
giftMessage?: string | undefined;
|
|
49
|
+
inventoryId?: string | undefined;
|
|
50
|
+
itemId?: string | undefined;
|
|
51
|
+
itemText?: string | undefined;
|
|
52
|
+
optionId: string;
|
|
53
|
+
optionItems?: (any & {
|
|
54
|
+
[key: string]: any;
|
|
55
|
+
})[] | undefined;
|
|
56
|
+
optionValueId: string;
|
|
57
|
+
price?: number | undefined;
|
|
58
|
+
priceAdjustments?: ({
|
|
59
|
+
appliedDiscount?: ({
|
|
60
|
+
amount?: number | undefined;
|
|
61
|
+
percentage?: number | undefined;
|
|
62
|
+
priceBookId?: string | undefined;
|
|
63
|
+
type: string;
|
|
64
|
+
} & {
|
|
65
|
+
[key: string]: any;
|
|
66
|
+
}) | undefined;
|
|
67
|
+
couponCode?: string | undefined;
|
|
68
|
+
createdBy?: string | undefined;
|
|
69
|
+
creationDate?: any;
|
|
70
|
+
custom?: boolean | undefined;
|
|
71
|
+
itemText?: string | undefined;
|
|
72
|
+
lastModified?: any;
|
|
73
|
+
manual?: boolean | undefined;
|
|
74
|
+
price?: number | undefined;
|
|
75
|
+
priceAdjustmentId?: string | undefined;
|
|
76
|
+
promotionId?: string | undefined;
|
|
77
|
+
promotionLink?: string | undefined;
|
|
78
|
+
reasonCode?: string | undefined;
|
|
79
|
+
} & {
|
|
80
|
+
[key: string]: any;
|
|
81
|
+
})[] | undefined;
|
|
82
|
+
priceAfterItemDiscount?: number | undefined;
|
|
83
|
+
priceAfterOrderDiscount?: number | undefined;
|
|
84
|
+
productId?: string | undefined;
|
|
85
|
+
productListItem?: {
|
|
86
|
+
id: string;
|
|
87
|
+
priority?: number | undefined;
|
|
88
|
+
productDetailsLink?: {
|
|
89
|
+
productDescription?: string | undefined;
|
|
90
|
+
productId: string;
|
|
91
|
+
productName?: string | undefined;
|
|
92
|
+
title?: string | undefined;
|
|
93
|
+
} | undefined;
|
|
94
|
+
productList?: ({
|
|
95
|
+
description?: string | undefined;
|
|
96
|
+
name?: string | undefined;
|
|
97
|
+
public?: boolean | undefined;
|
|
98
|
+
title?: string | undefined;
|
|
99
|
+
type?: string | undefined;
|
|
100
|
+
} & {
|
|
101
|
+
[key: string]: any;
|
|
102
|
+
}) | undefined;
|
|
103
|
+
public?: boolean | undefined;
|
|
104
|
+
purchasedQuantity?: number | undefined;
|
|
105
|
+
quantity?: number | undefined;
|
|
106
|
+
type?: string | undefined;
|
|
107
|
+
} | undefined;
|
|
108
|
+
productName?: string | undefined;
|
|
109
|
+
quantity?: number | undefined;
|
|
110
|
+
shipmentId?: string | undefined;
|
|
111
|
+
shippingItemId?: string | undefined;
|
|
112
|
+
tax?: number | undefined;
|
|
113
|
+
taxBasis?: number | undefined;
|
|
114
|
+
taxClassId?: string | undefined;
|
|
115
|
+
taxRate?: number | undefined;
|
|
116
|
+
} & {
|
|
117
|
+
[key: string]: any;
|
|
118
|
+
})[] | undefined;
|
|
119
|
+
price?: number | undefined;
|
|
120
|
+
priceAdjustments?: ({
|
|
121
|
+
appliedDiscount?: ({
|
|
122
|
+
amount?: number | undefined;
|
|
123
|
+
percentage?: number | undefined;
|
|
124
|
+
priceBookId?: string | undefined;
|
|
125
|
+
type: string;
|
|
126
|
+
} & {
|
|
127
|
+
[key: string]: any;
|
|
128
|
+
}) | undefined;
|
|
129
|
+
couponCode?: string | undefined;
|
|
130
|
+
createdBy?: string | undefined;
|
|
131
|
+
creationDate?: any;
|
|
132
|
+
custom?: boolean | undefined;
|
|
133
|
+
itemText?: string | undefined;
|
|
134
|
+
lastModified?: any;
|
|
135
|
+
manual?: boolean | undefined;
|
|
136
|
+
price?: number | undefined;
|
|
137
|
+
priceAdjustmentId?: string | undefined;
|
|
138
|
+
promotionId?: string | undefined;
|
|
139
|
+
promotionLink?: string | undefined;
|
|
140
|
+
reasonCode?: string | undefined;
|
|
141
|
+
} & {
|
|
142
|
+
[key: string]: any;
|
|
143
|
+
})[] | undefined;
|
|
144
|
+
priceAfterItemDiscount?: number | undefined;
|
|
145
|
+
priceAfterOrderDiscount?: number | undefined;
|
|
146
|
+
productId?: string | undefined;
|
|
147
|
+
productListItem?: {
|
|
148
|
+
id: string;
|
|
149
|
+
priority?: number | undefined;
|
|
150
|
+
productDetailsLink?: {
|
|
151
|
+
productDescription?: string | undefined;
|
|
152
|
+
productId: string;
|
|
153
|
+
productName?: string | undefined;
|
|
154
|
+
title?: string | undefined;
|
|
155
|
+
} | undefined;
|
|
156
|
+
productList?: ({
|
|
157
|
+
description?: string | undefined;
|
|
158
|
+
name?: string | undefined;
|
|
159
|
+
public?: boolean | undefined;
|
|
160
|
+
title?: string | undefined;
|
|
161
|
+
type?: string | undefined;
|
|
162
|
+
} & {
|
|
163
|
+
[key: string]: any;
|
|
164
|
+
}) | undefined;
|
|
165
|
+
public?: boolean | undefined;
|
|
166
|
+
purchasedQuantity?: number | undefined;
|
|
167
|
+
quantity?: number | undefined;
|
|
168
|
+
type?: string | undefined;
|
|
169
|
+
} | undefined;
|
|
170
|
+
productName?: string | undefined;
|
|
171
|
+
quantity?: number | undefined;
|
|
172
|
+
shipmentId?: string | undefined;
|
|
173
|
+
shippingItemId?: string | undefined;
|
|
174
|
+
tax?: number | undefined;
|
|
175
|
+
taxBasis?: number | undefined;
|
|
176
|
+
taxClassId?: string | undefined;
|
|
177
|
+
taxRate?: number | undefined;
|
|
178
|
+
} & {
|
|
179
|
+
[key: string]: any;
|
|
180
|
+
})[]) => Promise<Basket>;
|
|
181
|
+
};
|
|
182
|
+
export {};
|
|
183
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useShopperBasketsMutationHelper = useShopperBasketsMutationHelper;
|
|
7
|
+
var _index = require("../index");
|
|
8
|
+
var _ShopperCustomers = require("../ShopperCustomers");
|
|
9
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
10
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } /*
|
|
11
|
+
* Copyright (c) 2023, Salesforce, Inc.
|
|
12
|
+
* All rights reserved.
|
|
13
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
14
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* This is a helper function for Basket Mutations.
|
|
18
|
+
* useShopperBasketsMutationHelper.addItemToNewOrExistingBasket: is responsible for managing the process of adding an item to a basket.
|
|
19
|
+
* - If a basket already exists, add the item to the basket immediately.
|
|
20
|
+
* - If a basket does not exist, create a new basket using the createBasket mutation
|
|
21
|
+
* and then add the item to the newly created basket using the addItemToBasket mutation.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* import useShopperBasketsMutationHelper from '@salesforce/commerce-sdk-react'
|
|
25
|
+
*
|
|
26
|
+
* const Page = () => {
|
|
27
|
+
* const helpers = useShopperBasketsMutationHelper()
|
|
28
|
+
*
|
|
29
|
+
* const addToCart = async () => {
|
|
30
|
+
* const productItems = [{id: 123, quantity: 2}]
|
|
31
|
+
* await basketMutationHelpers.addItemToNewOrExistingBasket(productItems)
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* }
|
|
35
|
+
*/
|
|
36
|
+
function useShopperBasketsMutationHelper() {
|
|
37
|
+
const customerId = (0, _index.useCustomerId)();
|
|
38
|
+
const {
|
|
39
|
+
data: basketsData
|
|
40
|
+
} = (0, _ShopperCustomers.useCustomerBaskets)({
|
|
41
|
+
parameters: {
|
|
42
|
+
customerId
|
|
43
|
+
}
|
|
44
|
+
}, {
|
|
45
|
+
enabled: !!customerId
|
|
46
|
+
});
|
|
47
|
+
const createBasket = (0, _index.useShopperBasketsMutation)('createBasket');
|
|
48
|
+
const addItemToBasketMutation = (0, _index.useShopperBasketsMutation)('addItemToBasket');
|
|
49
|
+
return {
|
|
50
|
+
addItemToNewOrExistingBasket: function () {
|
|
51
|
+
var _ref = _asyncToGenerator(function* (productItem) {
|
|
52
|
+
if (basketsData && basketsData.total > 0) {
|
|
53
|
+
// we know that if basketData.total > 0, current basket will always be available
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
55
|
+
const currentBasket = (basketsData === null || basketsData === void 0 ? void 0 : basketsData.baskets) && basketsData.baskets[0];
|
|
56
|
+
return yield addItemToBasketMutation.mutateAsync({
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
58
|
+
parameters: {
|
|
59
|
+
basketId: currentBasket.basketId
|
|
60
|
+
},
|
|
61
|
+
body: productItem
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
const data = yield createBasket.mutateAsync({
|
|
65
|
+
body: {}
|
|
66
|
+
});
|
|
67
|
+
if (!data || !data.basketId) {
|
|
68
|
+
throw Error('Something is wrong. Please try again');
|
|
69
|
+
} else {
|
|
70
|
+
return yield addItemToBasketMutation.mutateAsync({
|
|
71
|
+
parameters: {
|
|
72
|
+
basketId: data.basketId
|
|
73
|
+
},
|
|
74
|
+
body: productItem
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return function addItemToNewOrExistingBasket(_x) {
|
|
80
|
+
return _ref.apply(this, arguments);
|
|
81
|
+
};
|
|
82
|
+
}()
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -24,4 +24,15 @@ Object.keys(_query).forEach(function (key) {
|
|
|
24
24
|
return _query[key];
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
|
+
});
|
|
28
|
+
var _helpers = require("./helpers");
|
|
29
|
+
Object.keys(_helpers).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _helpers[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _helpers[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
27
38
|
});
|
|
@@ -78,6 +78,10 @@ export declare const ShopperBasketsMutations: {
|
|
|
78
78
|
* Updates an item in a basket.
|
|
79
79
|
*/
|
|
80
80
|
readonly UpdateItemInBasket: "updateItemInBasket";
|
|
81
|
+
/**
|
|
82
|
+
* Updates multiple items in a basket.
|
|
83
|
+
*/
|
|
84
|
+
readonly UpdateItemsInBasket: "updateItemsInBasket";
|
|
81
85
|
/**
|
|
82
86
|
* This method allows you to apply external taxation data to an existing basket to be able to pass tax rates and optional values for a specific taxable line item. This endpoint can be called only if external taxation mode was used for basket creation. See POST /baskets for more information.
|
|
83
87
|
*/
|