@salesforce/commerce-sdk-react 3.1.0 → 3.1.1-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 +52 -77
- package/README.md +1 -129
- package/auth/index.d.ts +14 -120
- package/auth/index.js +106 -422
- package/auth/storage/cookie.js +3 -4
- package/components/ShopperExperience/Component/index.js +2 -2
- package/components/ShopperExperience/Page/index.js +2 -2
- package/components/ShopperExperience/Region/index.js +2 -2
- package/constant.d.ts +0 -15
- package/constant.js +2 -20
- package/hooks/ShopperLogin/cache.js +0 -2
- package/hooks/ShopperLogin/mutation.d.ts +0 -10
- package/hooks/ShopperLogin/mutation.js +0 -10
- package/hooks/index.d.ts +0 -2
- package/hooks/index.js +0 -16
- package/hooks/useMutation.d.ts +1 -11
- package/hooks/useMutation.js +29 -37
- package/package.json +5 -5
- package/provider.d.ts +1 -3
- package/provider.js +21 -33
- package/hooks/useDNT.d.ts +0 -17
- package/hooks/useDNT.js +0 -42
- package/hooks/useTrustedAgent.d.ts +0 -24
- package/hooks/useTrustedAgent.js +0 -185
package/auth/storage/cookie.js
CHANGED
|
@@ -7,7 +7,6 @@ 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
|
-
var _constant = require("../../constant");
|
|
11
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
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; }
|
|
13
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; }
|
|
@@ -34,11 +33,11 @@ class CookieStorage extends _base.BaseStorage {
|
|
|
34
33
|
super(options);
|
|
35
34
|
}
|
|
36
35
|
set(key, value, options) {
|
|
37
|
-
const suffixedKey =
|
|
36
|
+
const suffixedKey = this.getSuffixedKey(key);
|
|
38
37
|
_jsCookie.default.set(suffixedKey, value, _objectSpread(_objectSpread({}, (0, _utils.getDefaultCookieAttributes)()), options));
|
|
39
38
|
}
|
|
40
39
|
get(key) {
|
|
41
|
-
const suffixedKey =
|
|
40
|
+
const suffixedKey = this.getSuffixedKey(key);
|
|
42
41
|
let value = _jsCookie.default.get(suffixedKey) || '';
|
|
43
42
|
if (value) {
|
|
44
43
|
// Some values, like the access token, may be split
|
|
@@ -55,7 +54,7 @@ class CookieStorage extends _base.BaseStorage {
|
|
|
55
54
|
return value;
|
|
56
55
|
}
|
|
57
56
|
delete(key, options) {
|
|
58
|
-
const suffixedKey =
|
|
57
|
+
const suffixedKey = this.getSuffixedKey(key);
|
|
59
58
|
_jsCookie.default.remove(suffixedKey, _objectSpread(_objectSpread({}, (0, _utils.getDefaultCookieAttributes)()), options));
|
|
60
59
|
|
|
61
60
|
// Some values, like the access token, may be split
|
|
@@ -15,8 +15,8 @@ const _excluded = ["data"];
|
|
|
15
15
|
*/
|
|
16
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
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
|
|
19
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.
|
|
18
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.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.includes(n)) 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!`);
|
|
@@ -22,8 +22,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
22
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
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(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var
|
|
26
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.
|
|
25
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.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.includes(n)) 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
|
|
|
@@ -17,8 +17,8 @@ const _excluded = ["region", "className"];
|
|
|
17
17
|
*/
|
|
18
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
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
|
|
21
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.
|
|
20
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.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.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
22
22
|
/**
|
|
23
23
|
* This PropType represents a `region` object from the ShopperExperience API.
|
|
24
24
|
*/
|
package/constant.d.ts
CHANGED
|
@@ -9,19 +9,4 @@ export declare const SLAS_PRIVATE_PROXY_PATH: string;
|
|
|
9
9
|
export declare const SLAS_SECRET_WARNING_MSG = "You are potentially exposing SLAS secret on browser. Make sure to keep it safe and secure!";
|
|
10
10
|
export declare const SLAS_SECRET_PLACEHOLDER = "_PLACEHOLDER_PROXY-PWA_KIT_SLAS_CLIENT_SECRET";
|
|
11
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.";
|
|
12
|
-
export declare const SLAS_REFRESH_TOKEN_COOKIE_TTL_OVERRIDE_MSG = "You are attempting to use an invalid refresh token TTL value.";
|
|
13
|
-
export declare const DNT_COOKIE_NAME: "dw_dnt";
|
|
14
|
-
export declare const DWSID_COOKIE_NAME = "dwsid";
|
|
15
|
-
export declare const EXCLUDE_COOKIE_SUFFIX: string[];
|
|
16
|
-
/**
|
|
17
|
-
* For Hybrid Setups only!
|
|
18
|
-
* Unlike SCAPI/OCAPI, ECOM creates baskets in app-server cache initially and move the basket object
|
|
19
|
-
* to the db later based on basket state. In a hybrid storefront, storefront requests might be
|
|
20
|
-
* routed to different appservers, if the basket object is still in appserver cache, you will start
|
|
21
|
-
* seeing inconsistencies in basket state. To avoid this, if you have a dwsid cookie, you must send
|
|
22
|
-
* the value of the dwsid cookie with each SCAPI/OCAPI request in a hybrid storefront to maintain appserver affinity.
|
|
23
|
-
*
|
|
24
|
-
* Use the header key below to send dwsid value with SCAPI/OCAPI requests.
|
|
25
|
-
*/
|
|
26
|
-
export declare const SERVER_AFFINITY_HEADER_KEY = "sfdc_dwsid";
|
|
27
12
|
//# sourceMappingURL=constant.d.ts.map
|
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.
|
|
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.
|
|
@@ -23,22 +23,4 @@ const LOCAL_BUNDLE_PATH = exports.LOCAL_BUNDLE_PATH = `${MOBIFY_PATH}/bundle/dev
|
|
|
23
23
|
const SLAS_PRIVATE_PROXY_PATH = exports.SLAS_PRIVATE_PROXY_PATH = `${MOBIFY_PATH}/slas/private`;
|
|
24
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!';
|
|
25
25
|
const SLAS_SECRET_PLACEHOLDER = exports.SLAS_SECRET_PLACEHOLDER = '_PLACEHOLDER_PROXY-PWA_KIT_SLAS_CLIENT_SECRET';
|
|
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.';
|
|
27
|
-
const SLAS_REFRESH_TOKEN_COOKIE_TTL_OVERRIDE_MSG = exports.SLAS_REFRESH_TOKEN_COOKIE_TTL_OVERRIDE_MSG = 'You are attempting to use an invalid refresh token TTL value.';
|
|
28
|
-
const DNT_COOKIE_NAME = exports.DNT_COOKIE_NAME = 'dw_dnt';
|
|
29
|
-
const DWSID_COOKIE_NAME = exports.DWSID_COOKIE_NAME = 'dwsid';
|
|
30
|
-
// commerce-sdk-react namespaces cookies with siteID as suffixes to allow multisite setups.
|
|
31
|
-
// However some cookies are set and used outside of PWA Kit and must not be modified with suffixes.
|
|
32
|
-
const EXCLUDE_COOKIE_SUFFIX = exports.EXCLUDE_COOKIE_SUFFIX = [DWSID_COOKIE_NAME, DNT_COOKIE_NAME];
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* For Hybrid Setups only!
|
|
36
|
-
* Unlike SCAPI/OCAPI, ECOM creates baskets in app-server cache initially and move the basket object
|
|
37
|
-
* to the db later based on basket state. In a hybrid storefront, storefront requests might be
|
|
38
|
-
* routed to different appservers, if the basket object is still in appserver cache, you will start
|
|
39
|
-
* seeing inconsistencies in basket state. To avoid this, if you have a dwsid cookie, you must send
|
|
40
|
-
* the value of the dwsid cookie with each SCAPI/OCAPI request in a hybrid storefront to maintain appserver affinity.
|
|
41
|
-
*
|
|
42
|
-
* Use the header key below to send dwsid value with SCAPI/OCAPI requests.
|
|
43
|
-
*/
|
|
44
|
-
const SERVER_AFFINITY_HEADER_KEY = exports.SERVER_AFFINITY_HEADER_KEY = 'sfdc_dwsid';
|
|
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.';
|
|
@@ -21,12 +21,10 @@ const cacheUpdateMatrix = exports.cacheUpdateMatrix = {
|
|
|
21
21
|
}]
|
|
22
22
|
};
|
|
23
23
|
},
|
|
24
|
-
authorizeCustomer: noop,
|
|
25
24
|
getAccessToken: noop,
|
|
26
25
|
getSessionBridgeAccessToken: noop,
|
|
27
26
|
getTrustedSystemAccessToken: noop,
|
|
28
27
|
getTrustedAgentAccessToken: noop,
|
|
29
|
-
getPasswordResetToken: noop,
|
|
30
28
|
resetPassword: noop,
|
|
31
29
|
getPasswordLessAccessToken: noop,
|
|
32
30
|
revokeToken: noop,
|
|
@@ -22,11 +22,6 @@ Required parameters: `refresh token`, `channel_id`, and `client`.
|
|
|
22
22
|
* @returns A TanStack Query mutation hook for interacting with the Shopper Login `logoutCustomer` endpoint.
|
|
23
23
|
*/
|
|
24
24
|
readonly LogoutCustomer: "logoutCustomer";
|
|
25
|
-
/**
|
|
26
|
-
* Get an authorization code after authenticating a user against an identity provider (IDP). This is the first step of the OAuth 2.1 authorization code flow, where a user can log in via federation to the IDP configured for the client. After successfully logging in, the user gets an authorization code via a redirect URI.
|
|
27
|
-
* @returns A TanStack Query mutation hook for interacting with the Shopper Login `authorizeCustomer` endpoint.
|
|
28
|
-
*/
|
|
29
|
-
readonly AuthorizeCustomer: "authorizeCustomer";
|
|
30
25
|
/**
|
|
31
26
|
* Get the shopper or guest JWT access token and a refresh token. This is the second step of the OAuth 2.1 authorization code flow.
|
|
32
27
|
* @returns A TanStack Query mutation hook for interacting with the Shopper Login `getAccessToken` endpoint.
|
|
@@ -59,11 +54,6 @@ The value of the `_sfdc_client_auth` header must be a Base64-encoded string. The
|
|
|
59
54
|
* @returns A TanStack Query mutation hook for interacting with the Shopper Login `getTrustedAgentAccessToken` endpoint.
|
|
60
55
|
*/
|
|
61
56
|
readonly GetTrustedAgentAccessToken: "getTrustedAgentAccessToken";
|
|
62
|
-
/**
|
|
63
|
-
* Request a reset password token
|
|
64
|
-
* @returns A TanStack Query mutation hook for interacting with the Shopper Login `getPasswordResetToken` endpoint.
|
|
65
|
-
*/
|
|
66
|
-
readonly GetPasswordResetToken: "getPasswordResetToken";
|
|
67
57
|
/**
|
|
68
58
|
* Creates a new password
|
|
69
59
|
* @returns A TanStack Query mutation hook for interacting with the Shopper Login `resetPassword` endpoint.
|
|
@@ -36,11 +36,6 @@ const ShopperLoginMutations = exports.ShopperLoginMutations = {
|
|
|
36
36
|
* @returns A TanStack Query mutation hook for interacting with the Shopper Login `logoutCustomer` endpoint.
|
|
37
37
|
*/
|
|
38
38
|
LogoutCustomer: 'logoutCustomer',
|
|
39
|
-
/**
|
|
40
|
-
* Get an authorization code after authenticating a user against an identity provider (IDP). This is the first step of the OAuth 2.1 authorization code flow, where a user can log in via federation to the IDP configured for the client. After successfully logging in, the user gets an authorization code via a redirect URI.
|
|
41
|
-
* @returns A TanStack Query mutation hook for interacting with the Shopper Login `authorizeCustomer` endpoint.
|
|
42
|
-
*/
|
|
43
|
-
AuthorizeCustomer: 'authorizeCustomer',
|
|
44
39
|
/**
|
|
45
40
|
* Get the shopper or guest JWT access token and a refresh token. This is the second step of the OAuth 2.1 authorization code flow.
|
|
46
41
|
* @returns A TanStack Query mutation hook for interacting with the Shopper Login `getAccessToken` endpoint.
|
|
@@ -67,11 +62,6 @@ const ShopperLoginMutations = exports.ShopperLoginMutations = {
|
|
|
67
62
|
* @returns A TanStack Query mutation hook for interacting with the Shopper Login `getTrustedAgentAccessToken` endpoint.
|
|
68
63
|
*/
|
|
69
64
|
GetTrustedAgentAccessToken: 'getTrustedAgentAccessToken',
|
|
70
|
-
/**
|
|
71
|
-
* Request a reset password token
|
|
72
|
-
* @returns A TanStack Query mutation hook for interacting with the Shopper Login `getPasswordResetToken` endpoint.
|
|
73
|
-
*/
|
|
74
|
-
GetPasswordResetToken: 'getPasswordResetToken',
|
|
75
65
|
/**
|
|
76
66
|
* Creates a new password
|
|
77
67
|
* @returns A TanStack Query mutation hook for interacting with the Shopper Login `resetPassword` endpoint.
|
package/hooks/index.d.ts
CHANGED
|
@@ -17,9 +17,7 @@ export { default as useEncUserId } from './useEncUserId';
|
|
|
17
17
|
export { default as useUsid } from './useUsid';
|
|
18
18
|
export { default as useCustomerId } from './useCustomerId';
|
|
19
19
|
export { default as useCustomerType } from './useCustomerType';
|
|
20
|
-
export { default as useTrustedAgent } from './useTrustedAgent';
|
|
21
20
|
export { default as useConfig } from './useConfig';
|
|
22
|
-
export { default as useDNT } from './useDNT';
|
|
23
21
|
export { useCustomQuery } from './useQuery';
|
|
24
22
|
export { useCustomMutation } from './useMutation';
|
|
25
23
|
//# sourceMappingURL=index.d.ts.map
|
package/hooks/index.js
CHANGED
|
@@ -10,9 +10,7 @@ var _exportNames = {
|
|
|
10
10
|
useUsid: true,
|
|
11
11
|
useCustomerId: true,
|
|
12
12
|
useCustomerType: true,
|
|
13
|
-
useTrustedAgent: true,
|
|
14
13
|
useConfig: true,
|
|
15
|
-
useDNT: true,
|
|
16
14
|
useCustomQuery: true,
|
|
17
15
|
useCustomMutation: true
|
|
18
16
|
};
|
|
@@ -58,24 +56,12 @@ Object.defineProperty(exports, "useCustomerType", {
|
|
|
58
56
|
return _useCustomerType.default;
|
|
59
57
|
}
|
|
60
58
|
});
|
|
61
|
-
Object.defineProperty(exports, "useDNT", {
|
|
62
|
-
enumerable: true,
|
|
63
|
-
get: function () {
|
|
64
|
-
return _useDNT.default;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
59
|
Object.defineProperty(exports, "useEncUserId", {
|
|
68
60
|
enumerable: true,
|
|
69
61
|
get: function () {
|
|
70
62
|
return _useEncUserId.default;
|
|
71
63
|
}
|
|
72
64
|
});
|
|
73
|
-
Object.defineProperty(exports, "useTrustedAgent", {
|
|
74
|
-
enumerable: true,
|
|
75
|
-
get: function () {
|
|
76
|
-
return _useTrustedAgent.default;
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
65
|
Object.defineProperty(exports, "useUsid", {
|
|
80
66
|
enumerable: true,
|
|
81
67
|
get: function () {
|
|
@@ -244,9 +230,7 @@ var _useEncUserId = _interopRequireDefault(require("./useEncUserId"));
|
|
|
244
230
|
var _useUsid = _interopRequireDefault(require("./useUsid"));
|
|
245
231
|
var _useCustomerId = _interopRequireDefault(require("./useCustomerId"));
|
|
246
232
|
var _useCustomerType = _interopRequireDefault(require("./useCustomerType"));
|
|
247
|
-
var _useTrustedAgent = _interopRequireDefault(require("./useTrustedAgent"));
|
|
248
233
|
var _useConfig = _interopRequireDefault(require("./useConfig"));
|
|
249
|
-
var _useDNT = _interopRequireDefault(require("./useDNT"));
|
|
250
234
|
var _useQuery = require("./useQuery");
|
|
251
235
|
var _useMutation = require("./useMutation");
|
|
252
236
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
package/hooks/useMutation.d.ts
CHANGED
|
@@ -10,15 +10,6 @@ export declare const useMutation: <Client extends ApiClient, Options extends Api
|
|
|
10
10
|
method: ApiMethod<Options, Data>;
|
|
11
11
|
getCacheUpdates: CacheUpdateGetter<Required<ApiOptions<NonNullable<Client["clientConfig"]["parameters"] & Options["parameters"]>, unknown extends Options["body"] ? never : Options["body"], NonNullable<Client["clientConfig"]["headers"] & Options["headers"]>>>, Data>;
|
|
12
12
|
}) => import("@tanstack/react-query").UseMutationResult<Data, unknown, Options, unknown>;
|
|
13
|
-
type TMutationVariables = {
|
|
14
|
-
body?: unknown;
|
|
15
|
-
parameters?: {
|
|
16
|
-
[key: string]: string | number | boolean | string[] | number[];
|
|
17
|
-
};
|
|
18
|
-
headers?: {
|
|
19
|
-
[key: string]: string;
|
|
20
|
-
};
|
|
21
|
-
} | void;
|
|
22
13
|
/**
|
|
23
14
|
* A hook for SCAPI custom endpoint mutations.
|
|
24
15
|
*
|
|
@@ -29,6 +20,5 @@ type TMutationVariables = {
|
|
|
29
20
|
* @param mutationOptions - Options passed through to @tanstack/react-query
|
|
30
21
|
* @returns A TanStack Query mutation hook with data from the custom API endpoint.
|
|
31
22
|
*/
|
|
32
|
-
export declare const useCustomMutation:
|
|
33
|
-
export {};
|
|
23
|
+
export declare const useCustomMutation: (apiOptions: OptionalCustomEndpointClientConfig, mutationOptions?: UseMutationOptions) => import("@tanstack/react-query").UseMutationResult<unknown, unknown, void, unknown>;
|
|
34
24
|
//# sourceMappingURL=useMutation.d.ts.map
|
package/hooks/useMutation.js
CHANGED
|
@@ -43,7 +43,7 @@ const useMutation = hookConfig => {
|
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
45
|
};
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
/**
|
|
48
48
|
* A hook for SCAPI custom endpoint mutations.
|
|
49
49
|
*
|
|
@@ -54,44 +54,36 @@ exports.useMutation = useMutation;
|
|
|
54
54
|
* @param mutationOptions - Options passed through to @tanstack/react-query
|
|
55
55
|
* @returns A TanStack Query mutation hook with data from the custom API endpoint.
|
|
56
56
|
*/
|
|
57
|
+
exports.useMutation = useMutation;
|
|
57
58
|
const useCustomMutation = (apiOptions, mutationOptions) => {
|
|
59
|
+
const config = (0, _useConfig.default)();
|
|
58
60
|
const auth = (0, _useAuthContext.default)();
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
} : {}), args !== null && args !== void 0 && args.parameters ? {
|
|
85
|
-
parameters: args.parameters
|
|
86
|
-
} : {}),
|
|
87
|
-
clientConfig: _objectSpread(_objectSpread({}, globalClientConfig), apiOptions.clientConfig || {})
|
|
88
|
-
}));
|
|
89
|
-
});
|
|
90
|
-
return function (_x) {
|
|
91
|
-
return _ref.apply(this, arguments);
|
|
92
|
-
};
|
|
93
|
-
}();
|
|
61
|
+
const callCustomEndpointWithAuth = options => {
|
|
62
|
+
return /*#__PURE__*/_asyncToGenerator(function* () {
|
|
63
|
+
var _options$options;
|
|
64
|
+
const clientConfig = options.clientConfig || {};
|
|
65
|
+
const clientHeaders = config.headers || {};
|
|
66
|
+
const {
|
|
67
|
+
access_token
|
|
68
|
+
} = yield auth.ready();
|
|
69
|
+
return yield _commerceSdkIsomorphic.helpers.callCustomEndpoint(_objectSpread(_objectSpread({}, options), {}, {
|
|
70
|
+
options: _objectSpread(_objectSpread({}, options.options), {}, {
|
|
71
|
+
headers: _objectSpread(_objectSpread({
|
|
72
|
+
Authorization: `Bearer ${access_token}`
|
|
73
|
+
}, clientHeaders), (_options$options = options.options) === null || _options$options === void 0 ? void 0 : _options$options.headers)
|
|
74
|
+
}),
|
|
75
|
+
clientConfig: _objectSpread({
|
|
76
|
+
parameters: {
|
|
77
|
+
clientId: config.clientId,
|
|
78
|
+
siteId: config.siteId,
|
|
79
|
+
organizationId: config.organizationId,
|
|
80
|
+
shortCode: config.organizationId
|
|
81
|
+
},
|
|
82
|
+
proxy: config.proxy
|
|
83
|
+
}, clientConfig)
|
|
84
|
+
}));
|
|
85
|
+
});
|
|
94
86
|
};
|
|
95
|
-
return (0, _reactQuery.useMutation)(
|
|
87
|
+
return (0, _reactQuery.useMutation)(callCustomEndpointWithAuth(apiOptions), mutationOptions);
|
|
96
88
|
};
|
|
97
89
|
exports.useCustomMutation = useCustomMutation;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/commerce-sdk-react",
|
|
3
|
-
"version": "3.1.0",
|
|
3
|
+
"version": "3.1.1-preview.0",
|
|
4
4
|
"description": "A library that provides react hooks for fetching data from Commerce Cloud",
|
|
5
5
|
"homepage": "https://github.com/SalesforceCommerceCloud/pwa-kit/tree/develop/packages/ecom-react-hooks#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
"version": "node ./scripts/version.js"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"commerce-sdk-isomorphic": "^3.
|
|
43
|
+
"commerce-sdk-isomorphic": "^3.0.0",
|
|
44
44
|
"js-cookie": "^3.0.1",
|
|
45
45
|
"jwt-decode": "^4.0.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@salesforce/pwa-kit-dev": "
|
|
48
|
+
"@salesforce/pwa-kit-dev": "4.0.0-extensibility-preview.0",
|
|
49
49
|
"@tanstack/react-query": "^4.28.0",
|
|
50
50
|
"@testing-library/jest-dom": "^5.16.5",
|
|
51
51
|
"@testing-library/react": "^14.0.0",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@types/react-helmet": "~6.1.6",
|
|
61
61
|
"@types/react-router-dom": "~5.3.3",
|
|
62
62
|
"cross-env": "^5.2.1",
|
|
63
|
-
"internal-lib-build": "
|
|
63
|
+
"internal-lib-build": "4.0.0-extensibility-preview.0",
|
|
64
64
|
"jsonwebtoken": "^9.0.0",
|
|
65
65
|
"nock": "^13.3.0",
|
|
66
66
|
"nodemon": "^2.0.22",
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
"publishConfig": {
|
|
91
91
|
"directory": "dist"
|
|
92
92
|
},
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "16a2673cbdb9b22e3071435e8afbc2e89b2e37da"
|
|
94
94
|
}
|
package/provider.d.ts
CHANGED
|
@@ -12,13 +12,11 @@ export interface CommerceApiProviderProps extends ApiClientConfigParams {
|
|
|
12
12
|
fetchOptions?: ShopperBasketsTypes.FetchOptions;
|
|
13
13
|
headers?: Record<string, string>;
|
|
14
14
|
fetchedToken?: string;
|
|
15
|
+
OCAPISessionsURL?: string;
|
|
15
16
|
enablePWAKitPrivateClient?: boolean;
|
|
16
17
|
clientSecret?: string;
|
|
17
18
|
silenceWarnings?: boolean;
|
|
18
19
|
logger?: Logger;
|
|
19
|
-
defaultDnt?: boolean;
|
|
20
|
-
refreshTokenRegisteredCookieTTL?: number;
|
|
21
|
-
refreshTokenGuestCookieTTL?: number;
|
|
22
20
|
}
|
|
23
21
|
/**
|
|
24
22
|
* @internal
|
package/provider.js
CHANGED
|
@@ -92,44 +92,18 @@ const CommerceApiProvider = props => {
|
|
|
92
92
|
locale,
|
|
93
93
|
currency,
|
|
94
94
|
fetchedToken,
|
|
95
|
+
OCAPISessionsURL,
|
|
95
96
|
enablePWAKitPrivateClient,
|
|
96
97
|
clientSecret,
|
|
97
98
|
silenceWarnings,
|
|
98
|
-
logger
|
|
99
|
-
defaultDnt,
|
|
100
|
-
refreshTokenRegisteredCookieTTL,
|
|
101
|
-
refreshTokenGuestCookieTTL
|
|
99
|
+
logger
|
|
102
100
|
} = props;
|
|
103
101
|
|
|
104
102
|
// Set the logger based on provided configuration, or default to the console object if no logger is provided
|
|
105
103
|
const configLogger = logger || console;
|
|
106
|
-
const auth = (0, _react.useMemo)(() => {
|
|
107
|
-
return new _auth.default({
|
|
108
|
-
clientId,
|
|
109
|
-
organizationId,
|
|
110
|
-
shortCode,
|
|
111
|
-
siteId,
|
|
112
|
-
proxy,
|
|
113
|
-
redirectURI,
|
|
114
|
-
fetchOptions,
|
|
115
|
-
fetchedToken,
|
|
116
|
-
enablePWAKitPrivateClient,
|
|
117
|
-
clientSecret,
|
|
118
|
-
silenceWarnings,
|
|
119
|
-
logger: configLogger,
|
|
120
|
-
defaultDnt,
|
|
121
|
-
refreshTokenRegisteredCookieTTL,
|
|
122
|
-
refreshTokenGuestCookieTTL
|
|
123
|
-
});
|
|
124
|
-
}, [clientId, organizationId, shortCode, siteId, proxy, redirectURI, fetchOptions, fetchedToken, enablePWAKitPrivateClient, clientSecret, silenceWarnings, configLogger, refreshTokenRegisteredCookieTTL, refreshTokenGuestCookieTTL]);
|
|
125
|
-
const dwsid = auth.get(_constant.DWSID_COOKIE_NAME);
|
|
126
|
-
const serverAffinityHeader = {};
|
|
127
|
-
if (dwsid) {
|
|
128
|
-
serverAffinityHeader[_constant.SERVER_AFFINITY_HEADER_KEY] = dwsid;
|
|
129
|
-
}
|
|
130
104
|
const config = {
|
|
131
105
|
proxy,
|
|
132
|
-
headers
|
|
106
|
+
headers,
|
|
133
107
|
parameters: {
|
|
134
108
|
clientId,
|
|
135
109
|
organizationId,
|
|
@@ -161,6 +135,23 @@ const CommerceApiProvider = props => {
|
|
|
161
135
|
shopperStores: new _commerceSdkIsomorphic.ShopperStores(config)
|
|
162
136
|
};
|
|
163
137
|
}, [clientId, organizationId, shortCode, siteId, proxy, fetchOptions, locale, currency, headers === null || headers === void 0 ? void 0 : headers['correlation-id']]);
|
|
138
|
+
const auth = (0, _react.useMemo)(() => {
|
|
139
|
+
return new _auth.default({
|
|
140
|
+
clientId,
|
|
141
|
+
organizationId,
|
|
142
|
+
shortCode,
|
|
143
|
+
siteId,
|
|
144
|
+
proxy,
|
|
145
|
+
redirectURI,
|
|
146
|
+
fetchOptions,
|
|
147
|
+
fetchedToken,
|
|
148
|
+
OCAPISessionsURL,
|
|
149
|
+
enablePWAKitPrivateClient,
|
|
150
|
+
clientSecret,
|
|
151
|
+
silenceWarnings,
|
|
152
|
+
logger: configLogger
|
|
153
|
+
});
|
|
154
|
+
}, [clientId, organizationId, shortCode, siteId, proxy, redirectURI, fetchOptions, fetchedToken, OCAPISessionsURL, enablePWAKitPrivateClient, clientSecret, silenceWarnings, configLogger]);
|
|
164
155
|
|
|
165
156
|
// Initialize the session
|
|
166
157
|
(0, _react.useEffect)(() => void auth.ready(), [auth]);
|
|
@@ -177,10 +168,7 @@ const CommerceApiProvider = props => {
|
|
|
177
168
|
locale,
|
|
178
169
|
currency,
|
|
179
170
|
silenceWarnings,
|
|
180
|
-
logger: configLogger
|
|
181
|
-
defaultDnt,
|
|
182
|
-
refreshTokenRegisteredCookieTTL,
|
|
183
|
-
refreshTokenGuestCookieTTL
|
|
171
|
+
logger: configLogger
|
|
184
172
|
}
|
|
185
173
|
}, /*#__PURE__*/_react.default.createElement(CommerceApiContext.Provider, {
|
|
186
174
|
value: apiClients
|
package/hooks/useDNT.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
interface useDntReturn {
|
|
2
|
-
dntStatus: boolean | undefined;
|
|
3
|
-
updateDNT: (preference: boolean | null) => Promise<void>;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Hook that returns
|
|
7
|
-
* dntStatus - a boolean indicating the current DNT preference
|
|
8
|
-
* updateDNT - a function that takes a DNT preference and creates the dw_dnt
|
|
9
|
-
* cookie and reauthroizes with SLAS
|
|
10
|
-
*
|
|
11
|
-
* @group Helpers
|
|
12
|
-
* @category DNT
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
declare const useDNT: () => useDntReturn;
|
|
16
|
-
export default useDNT;
|
|
17
|
-
//# sourceMappingURL=useDNT.d.ts.map
|
package/hooks/useDNT.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _useAuthContext = _interopRequireDefault(require("./useAuthContext"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
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) 2024, salesforce.com, 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
|
-
* Hook that returns
|
|
18
|
-
* dntStatus - a boolean indicating the current DNT preference
|
|
19
|
-
* updateDNT - a function that takes a DNT preference and creates the dw_dnt
|
|
20
|
-
* cookie and reauthroizes with SLAS
|
|
21
|
-
*
|
|
22
|
-
* @group Helpers
|
|
23
|
-
* @category DNT
|
|
24
|
-
*
|
|
25
|
-
*/
|
|
26
|
-
const useDNT = () => {
|
|
27
|
-
const auth = (0, _useAuthContext.default)();
|
|
28
|
-
const dntStatus = auth.getDnt();
|
|
29
|
-
const updateDNT = /*#__PURE__*/function () {
|
|
30
|
-
var _ref = _asyncToGenerator(function* (preference) {
|
|
31
|
-
yield auth.setDnt(preference);
|
|
32
|
-
});
|
|
33
|
-
return function updateDNT(_x) {
|
|
34
|
-
return _ref.apply(this, arguments);
|
|
35
|
-
};
|
|
36
|
-
}();
|
|
37
|
-
return {
|
|
38
|
-
dntStatus,
|
|
39
|
-
updateDNT
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
var _default = exports.default = useDNT;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { ShopperLoginTypes } from 'commerce-sdk-isomorphic';
|
|
2
|
-
type TokenResponse = ShopperLoginTypes.TokenResponse;
|
|
3
|
-
type UseTrustedAgent = {
|
|
4
|
-
isAgent: boolean;
|
|
5
|
-
agentId: string | null;
|
|
6
|
-
loginId: string | null;
|
|
7
|
-
login: (loginId?: string, usid?: string) => Promise<TokenResponse>;
|
|
8
|
-
logout: () => Promise<TokenResponse>;
|
|
9
|
-
};
|
|
10
|
-
export declare const createTrustedAgentPopup: (url: string, isRefresh?: boolean, timeoutMinutes?: number, refreshTimeoutFocusMinutes?: number) => Promise<{
|
|
11
|
-
code: string;
|
|
12
|
-
state: string;
|
|
13
|
-
}>;
|
|
14
|
-
/**
|
|
15
|
-
* A hook to return trusted agent state.
|
|
16
|
-
*
|
|
17
|
-
* @group Helpers
|
|
18
|
-
* @category Shopper Authentication
|
|
19
|
-
* @experimental
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
declare const useTrustedAgent: () => UseTrustedAgent;
|
|
23
|
-
export default useTrustedAgent;
|
|
24
|
-
//# sourceMappingURL=useTrustedAgent.d.ts.map
|