@salesforce/commerce-sdk-react 3.2.0-preview.0 → 3.2.0-preview.3

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 CHANGED
@@ -1,14 +1,17 @@
1
- ## v3.2.0-preview.0 (Feb 03, 2025)
2
- ## v3.2.0-dev (Feb 03, 2025)
3
- ## v3.9.0-preview.0 (Feb 03, 2025)
1
+ ## v4.0.0-extensibility-preview.3 (Dec 13, 2024)
2
+ ## v3.1.1-preview.3 (Dec 13, 2024)
3
+ ## v3.1.1-preview.3 (Dec 13, 2024)
4
+ ## v3.1.1-preview.2 (Dec 09, 2024)
5
+ ## v3.1.1-preview.1 (Dec 09, 2024)
6
+ ## v4.0.0-extensibility-preview.2 (Dec 09, 2024)
7
+ ## v3.1.1-preview.1 (Dec 09, 2024)
8
+ ## v3.1.1-preview.0 (Dec 02, 2024)
4
9
  ## v3.2.0-dev (Oct 29, 2024)
5
10
  - Allow cookies for ShopperLogin API [#2190](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2190
6
11
  - Fix refresh token TTL warning from firing when override is not provided [#2114](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2114)
7
- - Readme updates for private clients [#2212](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2212)
12
+
8
13
  - Update CacheUpdateMatrix for mergeBasket mutation [#2138](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2092)
9
14
  - Clear auth state if session has been invalidated by a password change [#2092](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2092)
10
- - DNT interface improvement [#2203](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2203)
11
- - Support Node 22 [#2218](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2218)
12
15
 
13
16
  ## v3.1.0 (Oct 28, 2024)
14
17
 
package/README.md CHANGED
@@ -43,7 +43,7 @@ In practice, we recommend:
43
43
  npm install @salesforce/commerce-sdk-react @tanstack/react-query
44
44
  ```
45
45
 
46
- ## ⚡️ Quickstart (PWA Kit v3.0+)
46
+ ## ⚡️ Quickstart (PWA Kit v2.3.0+)
47
47
 
48
48
  To integrate this library with your PWA Kit application you can use the `CommerceApiProvider` directly assuming that you use the `withReactQuery` higher order component to wrap your `AppConfig` component. Below is a snippet of how this is accomplished.
49
49
 
@@ -54,10 +54,6 @@ import {CommerceApiProvider} from '@salesforce/commerce-sdk-react'
54
54
  import {withReactQuery} from '@salesforce/pwa-kit-react-sdk/ssr/universal/components/with-react-query'
55
55
 
56
56
  const AppConfig = ({children}) => {
57
- const headers = {
58
- 'correlation-id': correlationId
59
- }
60
-
61
57
  return (
62
58
  <CommerceApiProvider
63
59
  clientId="12345678-1234-1234-1234-123412341234"
@@ -68,11 +64,6 @@ const AppConfig = ({children}) => {
68
64
  shortCode="12345678"
69
65
  locale="en-US"
70
66
  currency="USD"
71
- headers={headers}
72
- // Uncomment 'enablePWAKitPrivateClient' to use SLAS private client login flows.
73
- // Make sure to also enable useSLASPrivateClient in ssr.js when enabling this setting.
74
- // enablePWAKitPrivateClient={true}
75
- logger={createLogger({packageName: 'commerce-sdk-react'})}
76
67
  >
77
68
  {children}
78
69
  </CommerceApiProvider>
@@ -134,10 +125,68 @@ export default App
134
125
 
135
126
  _💡 This section assumes you have read and completed the [Authorization for Shopper APIs](https://developer.salesforce.com/docs/commerce/commerce-api/guide/authorization-for-shopper-apis.html) guide._
136
127
 
137
- To help reduce boilerplate code for managing shopper authentication, by default, this library automatically initializes shopper session and manages the tokens for developers. Commerce-sdk-react supports both the [SLAS Public Client login flow](https://developer.salesforce.com/docs/commerce/commerce-api/guide/slas-public-client.html) and [SLAS Private Client login flow](https://developer.salesforce.com/docs/commerce/commerce-api/guide/slas-private-client.html). Authorization using a private client is supported in PWA Kit 3.5 and later, and is the recommended authorization workflow.
128
+ To help reduce boilerplate code for managing shopper authentication, by default, this library automatically initializes shopper session and manages the tokens for developers. Currently, the library supports the [Public Client login flow](https://developer.salesforce.com/docs/commerce/commerce-api/guide/slas-public-client.html).
129
+
130
+ Commerce-react-sdk supports both public and private flow of the [Authorization for Shopper APIs](https://developer.salesforce.com/docs/commerce/commerce-api/guide/authorization-for-shopper-apis.html) guide._
131
+ You can choose to use either public or private slas to login. By default, public flow is enabled.
132
+
133
+ #### How private SLAS works
134
+ This section assumes you read and understand how [private SLAS](https://developer.salesforce.com/docs/commerce/commerce-api/guide/slas-private-client.html) flow works
135
+
136
+ To enable private slas flow, you need to pass your secret into the CommercerProvider via clientSecret prop.
137
+ **Note** You should only use private slas if you know you can secure your secret since commercer-sdk-react runs isomorphically.
138
+
139
+ ```js
140
+ // app/components/_app-config/index.jsx
141
+
142
+ import {CommerceApiProvider} from '@salesforce/commerce-sdk-react'
143
+ import {withReactQuery} from '@salesforce/pwa-kit-react-sdk/ssr/universal/components/with-react-query'
144
+
145
+ const AppConfig = ({children}) => {
146
+ return (
147
+ <CommerceApiProvider
148
+ clientId="12345678-1234-1234-1234-123412341234"
149
+ organizationId="f_ecom_aaaa_001"
150
+ proxy="localhost:3000/mobify/proxy/api"
151
+ redirectURI="localhost:3000/callback"
152
+ siteId="RefArch"
153
+ shortCode="12345678"
154
+ locale="en-US"
155
+ currency="USD"
156
+ clientSecret="<your-slas-private-secret>"
157
+ >
158
+ {children}
159
+ </CommerceApiProvider>
160
+ )
161
+ }
162
+ ```
163
+ #### Disable slas private warnings
164
+ By default, a warning as below will be displayed on client side to remind developers to always keep their secret safe and secured.
165
+ ```js
166
+ 'You are potentially exposing SLAS secret on browser. Make sure to keep it safe and secure!'
167
+ ```
168
+ You can disable this warning by using CommerceProvider prop `silenceWarnings`
138
169
 
139
- #### Using a private SLAS client
140
- To enable a private client, see [Use a SLAS Private Client](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/use-a-slas-private-client.html).
170
+ ```js
171
+ const AppConfig = ({children}) => {
172
+ return (
173
+ <CommerceApiProvider
174
+ clientId="12345678-1234-1234-1234-123412341234"
175
+ organizationId="f_ecom_aaaa_001"
176
+ proxy="localhost:3000/mobify/proxy/api"
177
+ redirectURI="localhost:3000/callback"
178
+ siteId="RefArch"
179
+ shortCode="12345678"
180
+ locale="en-US"
181
+ currency="USD"
182
+ clientSecret="<your-slas-private-secret>"
183
+ silenceWarnings={true}
184
+ >
185
+ {children}
186
+ </CommerceApiProvider>
187
+ )
188
+ }
189
+ ```
141
190
 
142
191
  ### Shopper Session Initialization
143
192
 
package/auth/index.d.ts CHANGED
@@ -30,9 +30,6 @@ export type AuthData = Prettify<RemoveStringIndex<TokenResponse> & {
30
30
  }>;
31
31
  /** A shopper could be guest or registered, so we store the refresh tokens individually. */
32
32
  type AuthDataKeys = Exclude<keyof AuthData, 'refresh_token'> | 'refresh_token_guest' | 'refresh_token_registered' | 'access_token_sfra' | typeof DNT_COOKIE_NAME | typeof DWSID_COOKIE_NAME;
33
- type DntOptions = {
34
- includeDefaults: boolean;
35
- };
36
33
  export declare const DEFAULT_SLAS_REFRESH_TOKEN_REGISTERED_TTL: number;
37
34
  export declare const DEFAULT_SLAS_REFRESH_TOKEN_GUEST_TTL: number;
38
35
  /**
@@ -61,20 +58,7 @@ declare class Auth {
61
58
  get(name: AuthDataKeys): string;
62
59
  private set;
63
60
  private delete;
64
- /**
65
- * Return the value of the DNT cookie or undefined if it is not set.
66
- * The DNT cookie being undefined means that there is a necessity to
67
- * get the user's input for consent tracking, but not that there is no
68
- * DNT value to apply to analytics layers. DNT value will default to
69
- * a certain value and this is reflected by effectiveDnt.
70
- *
71
- * If the cookie value is invalid, then it will be deleted in this function.
72
- *
73
- * If includeDefaults is true, then even if the cookie is not defined,
74
- * defaultDnt will be returned, if it exists. If defaultDnt is not defined, then
75
- * the SDK Default will return (false)
76
- */
77
- getDnt(options?: DntOptions): boolean | undefined;
61
+ getDnt(): boolean | undefined;
78
62
  setDnt(preference: boolean | null): Promise<void>;
79
63
  private clearStorage;
80
64
  /**
@@ -85,6 +69,11 @@ declare class Auth {
85
69
  * Used to validate JWT token expiration.
86
70
  */
87
71
  private isTokenExpired;
72
+ /**
73
+ * Gets the Do-Not-Track (DNT) preference from the `dw_dnt` cookie.
74
+ * If user has set their DNT preference, read the cookie, if not, use the default DNT pref. If the default DNT pref has not been set, default to false.
75
+ */
76
+ private getDntPreference;
88
77
  /**
89
78
  * Returns the SLAS access token or an empty string if the access token
90
79
  * is not found in local store or if SFRA wants PWA to trigger refresh token login.
package/auth/index.js CHANGED
@@ -232,22 +232,9 @@ class Auth {
232
232
  const storage = this.stores[storageType];
233
233
  storage.delete(key);
234
234
  }
235
-
236
- /**
237
- * Return the value of the DNT cookie or undefined if it is not set.
238
- * The DNT cookie being undefined means that there is a necessity to
239
- * get the user's input for consent tracking, but not that there is no
240
- * DNT value to apply to analytics layers. DNT value will default to
241
- * a certain value and this is reflected by effectiveDnt.
242
- *
243
- * If the cookie value is invalid, then it will be deleted in this function.
244
- *
245
- * If includeDefaults is true, then even if the cookie is not defined,
246
- * defaultDnt will be returned, if it exists. If defaultDnt is not defined, then
247
- * the SDK Default will return (false)
248
- */
249
- getDnt(options) {
235
+ getDnt() {
250
236
  const dntCookieVal = this.get(_constant.DNT_COOKIE_NAME);
237
+ // Only '1' or '0' are valid, and invalid values, lack of cookie, or value conflict with token must be an undefined DNT
251
238
  let dntCookieStatus = undefined;
252
239
  const accessToken = this.getAccessToken();
253
240
  let isInSync = true;
@@ -262,19 +249,6 @@ class Auth {
262
249
  } else {
263
250
  dntCookieStatus = Boolean(Number(dntCookieVal));
264
251
  }
265
- if (options !== null && options !== void 0 && options.includeDefaults) {
266
- const defaultDnt = this.defaultDnt;
267
- let effectiveDnt;
268
- const dntCookie = dntCookieVal === '1' ? true : dntCookieVal === '0' ? false : undefined;
269
- if (dntCookie !== undefined) {
270
- effectiveDnt = dntCookie;
271
- } else {
272
- // If the cookie is not set, read the defaultDnt preference.
273
- // If defaultDnt doesn't exist, default to false, following SLAS default for dnt
274
- effectiveDnt = defaultDnt !== undefined ? defaultDnt : false;
275
- }
276
- return effectiveDnt;
277
- }
278
252
  return dntCookieStatus;
279
253
  }
280
254
  setDnt(preference) {
@@ -354,6 +328,21 @@ class Auth {
354
328
  return validTimeSeconds <= tokenAgeSeconds;
355
329
  }
356
330
 
331
+ /**
332
+ * Gets the Do-Not-Track (DNT) preference from the `dw_dnt` cookie.
333
+ * If user has set their DNT preference, read the cookie, if not, use the default DNT pref. If the default DNT pref has not been set, default to false.
334
+ */
335
+ getDntPreference(dw_dnt, defaultDnt) {
336
+ let dntPref;
337
+ // Read `dw_dnt` cookie
338
+ const dntCookie = dw_dnt === '1' ? true : dw_dnt === '0' ? false : undefined;
339
+ dntPref = dntCookie;
340
+
341
+ // If the cookie is not set, read the default DNT preference.
342
+ if (dntCookie === undefined) dntPref = defaultDnt !== undefined ? defaultDnt : undefined;
343
+ return dntPref;
344
+ }
345
+
357
346
  /**
358
347
  * Returns the SLAS access token or an empty string if the access token
359
348
  * is not found in local store or if SFRA wants PWA to trigger refresh token login.
@@ -494,18 +483,17 @@ class Auth {
494
483
  refreshAccessToken() {
495
484
  var _this2 = this;
496
485
  return _asyncToGenerator(function* () {
497
- const dntPref = _this2.getDnt({
498
- includeDefaults: true
499
- });
486
+ const dntPref = _this2.getDntPreference(_this2.get(_constant.DNT_COOKIE_NAME), _this2.defaultDnt);
500
487
  const refreshTokenRegistered = _this2.get('refresh_token_registered');
501
488
  const refreshTokenGuest = _this2.get('refresh_token_guest');
502
489
  const refreshToken = refreshTokenRegistered || refreshTokenGuest;
503
490
  if (refreshToken) {
504
491
  try {
505
- return yield _this2.queueRequest(() => _commerceSdkIsomorphic.helpers.refreshAccessToken(_this2.client, {
506
- refreshToken,
492
+ return yield _this2.queueRequest(() => _commerceSdkIsomorphic.helpers.refreshAccessToken(_this2.client, _objectSpread({
493
+ refreshToken
494
+ }, dntPref !== undefined && {
507
495
  dnt: dntPref
508
- }, {
496
+ }), {
509
497
  clientSecret: _this2.clientSecret
510
498
  }), !!refreshTokenGuest);
511
499
  } catch (error) {
@@ -565,7 +553,7 @@ class Auth {
565
553
  var _this3 = this;
566
554
  return _asyncToGenerator(function* () {
567
555
  const queue = _this3.pendingToken ?? Promise.resolve();
568
- _this3.pendingToken = queue.then( /*#__PURE__*/_asyncToGenerator(function* () {
556
+ _this3.pendingToken = queue.then(/*#__PURE__*/_asyncToGenerator(function* () {
569
557
  const token = yield fn();
570
558
  _this3.handleTokenResponse(token, isGuest);
571
559
  // Q: Why don't we just return token? Why re-construct the same object again?
@@ -682,21 +670,20 @@ class Auth {
682
670
  _this6.logWarning(_constant.SLAS_SECRET_WARNING_MSG);
683
671
  }
684
672
  const usid = _this6.get('usid');
685
- const dntPref = _this6.getDnt({
686
- includeDefaults: true
687
- });
673
+ const dntPref = _this6.getDntPreference(_this6.get(_constant.DNT_COOKIE_NAME), _this6.defaultDnt);
688
674
  const isGuest = true;
689
- const guestPrivateArgs = [_this6.client, _objectSpread({
675
+ const guestPrivateArgs = [_this6.client, _objectSpread(_objectSpread({}, dntPref !== undefined && {
690
676
  dnt: dntPref
691
- }, usid && {
677
+ }), usid && {
692
678
  usid
693
679
  }), {
694
680
  clientSecret: _this6.clientSecret
695
681
  }];
696
- const guestPublicArgs = [_this6.client, _objectSpread({
697
- redirectURI: _this6.redirectURI,
682
+ const guestPublicArgs = [_this6.client, _objectSpread(_objectSpread({
683
+ redirectURI: _this6.redirectURI
684
+ }, dntPref !== undefined && {
698
685
  dnt: dntPref
699
- }, usid && {
686
+ }), usid && {
700
687
  usid
701
688
  })];
702
689
  const callback = _this6.clientSecret ? () => _commerceSdkIsomorphic.helpers.loginGuestUserPrivate(...guestPrivateArgs) : () => _commerceSdkIsomorphic.helpers.loginGuestUser(...guestPublicArgs);
@@ -761,16 +748,15 @@ class Auth {
761
748
  }
762
749
  const redirectURI = _this8.redirectURI;
763
750
  const usid = _this8.get('usid');
764
- const dntPref = _this8.getDnt({
765
- includeDefaults: true
766
- });
751
+ const dntPref = _this8.getDntPreference(_this8.get(_constant.DNT_COOKIE_NAME), _this8.defaultDnt);
767
752
  const isGuest = false;
768
753
  const token = yield _commerceSdkIsomorphic.helpers.loginRegisteredUserB2C(_this8.client, _objectSpread(_objectSpread({}, credentials), {}, {
769
754
  clientSecret: _this8.clientSecret
770
- }), _objectSpread({
771
- redirectURI,
755
+ }), _objectSpread(_objectSpread({
756
+ redirectURI
757
+ }, dntPref !== undefined && {
772
758
  dnt: dntPref
773
- }, usid && {
759
+ }), usid && {
774
760
  usid
775
761
  }));
776
762
  _this8.handleTokenResponse(token, isGuest);
@@ -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 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; }
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 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; }
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 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; }
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
  */
@@ -42,7 +42,7 @@ const useAuthorizationHeader = method => {
42
42
  headers: _objectSpread({
43
43
  Authorization: `Bearer ${access_token}`
44
44
  }, options.headers)
45
- })).catch( /*#__PURE__*/function () {
45
+ })).catch(/*#__PURE__*/function () {
46
46
  var _ref2 = _asyncToGenerator(function* (error) {
47
47
  const {
48
48
  access_token
package/hooks/useDNT.d.ts CHANGED
@@ -1,26 +1,16 @@
1
1
  interface useDntReturn {
2
- selectedDnt: boolean | undefined;
3
2
  dntStatus: boolean | undefined;
4
- effectiveDnt: boolean | undefined;
5
3
  updateDNT: (preference: boolean | null) => Promise<void>;
6
- updateDnt: (preference: boolean | null) => Promise<void>;
7
4
  }
8
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
+ *
9
11
  * @group Helpers
10
12
  * @category DNT
11
13
  *
12
- * @returns {Object} - The returned object containing DNT states and function to update preference
13
- * @property {boolean} selectedDnt - DNT user preference. Used to determine
14
- * if the consent tracking form should be rendered
15
- * @property {boolean} effectiveDnt - effective DNT value to apply to
16
- * analytics layers. Takes defaultDnt into account when selectedDnt is undefined.
17
- * If defaultDnt is undefined as well, then SDK default is used.
18
- * @property {function} updateDnt - takes a DNT choice and creates the dw_dnt
19
- * cookie and reauthorizes with SLAS
20
- * @property {function} updateDNT - @deprecated Deprecated since version 3.1.0. Use updateDnt instead.
21
- * @property {boolean} dntStatus - @deprecated Deprecated since version 3.1.0. Use selectedDnt instead.
22
- *
23
- *
24
14
  */
25
15
  declare const useDNT: () => useDntReturn;
26
16
  export default useDNT;
package/hooks/useDNT.js CHANGED
@@ -14,44 +14,29 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
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
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
+ *
17
22
  * @group Helpers
18
23
  * @category DNT
19
24
  *
20
- * @returns {Object} - The returned object containing DNT states and function to update preference
21
- * @property {boolean} selectedDnt - DNT user preference. Used to determine
22
- * if the consent tracking form should be rendered
23
- * @property {boolean} effectiveDnt - effective DNT value to apply to
24
- * analytics layers. Takes defaultDnt into account when selectedDnt is undefined.
25
- * If defaultDnt is undefined as well, then SDK default is used.
26
- * @property {function} updateDnt - takes a DNT choice and creates the dw_dnt
27
- * cookie and reauthorizes with SLAS
28
- * @property {function} updateDNT - @deprecated Deprecated since version 3.1.0. Use updateDnt instead.
29
- * @property {boolean} dntStatus - @deprecated Deprecated since version 3.1.0. Use selectedDnt instead.
30
- *
31
- *
32
25
  */
33
26
  const useDNT = () => {
34
27
  const auth = (0, _useAuthContext.default)();
35
- const selectedDnt = auth.getDnt();
36
- const effectiveDnt = auth.getDnt({
37
- includeDefaults: true
38
- });
39
- const updateDnt = /*#__PURE__*/function () {
28
+ const dntStatus = auth.getDnt();
29
+ const updateDNT = /*#__PURE__*/function () {
40
30
  var _ref = _asyncToGenerator(function* (preference) {
41
31
  yield auth.setDnt(preference);
42
32
  });
43
- return function updateDnt(_x) {
33
+ return function updateDNT(_x) {
44
34
  return _ref.apply(this, arguments);
45
35
  };
46
36
  }();
47
- const updateDNT = updateDnt;
48
- const dntStatus = selectedDnt;
49
37
  return {
50
- selectedDnt,
51
- effectiveDnt,
52
38
  dntStatus,
53
- updateDNT,
54
- updateDnt
39
+ updateDNT
55
40
  };
56
41
  };
57
42
  var _default = exports.default = useDNT;
@@ -61,7 +61,7 @@ const useCustomMutation = (apiOptions, mutationOptions) => {
61
61
  const {
62
62
  access_token
63
63
  } = yield auth.ready();
64
- return yield _commerceSdkIsomorphic.helpers.callCustomEndpoint((0, _helpers.generateCustomEndpointOptions)(apiOptions, globalConfig, access_token, args)).catch( /*#__PURE__*/function () {
64
+ return yield _commerceSdkIsomorphic.helpers.callCustomEndpoint((0, _helpers.generateCustomEndpointOptions)(apiOptions, globalConfig, access_token, args)).catch(/*#__PURE__*/function () {
65
65
  var _ref2 = _asyncToGenerator(function* (error) {
66
66
  const {
67
67
  access_token
package/hooks/useQuery.js CHANGED
@@ -86,7 +86,7 @@ const useCustomQuery = (apiOptions, queryOptions) => {
86
86
  access_token
87
87
  } = yield auth.ready();
88
88
  const customEndpointOptions = (0, _helpers.generateCustomEndpointOptions)(options, config, access_token);
89
- return yield _commerceSdkIsomorphic.helpers.callCustomEndpoint(customEndpointOptions).catch( /*#__PURE__*/function () {
89
+ return yield _commerceSdkIsomorphic.helpers.callCustomEndpoint(customEndpointOptions).catch(/*#__PURE__*/function () {
90
90
  var _ref3 = _asyncToGenerator(function* (error) {
91
91
  const {
92
92
  access_token
@@ -127,7 +127,7 @@ const useTrustedAgent = () => {
127
127
  const authorizeTrustedAgent = (0, _reactQuery.useMutation)(auth.authorizeTrustedAgent.bind(auth));
128
128
  const loginTrustedAgent = (0, _reactQuery.useMutation)(auth.loginTrustedAgent.bind(auth));
129
129
  const logoutTrustedAgent = (0, _reactQuery.useMutation)(auth.logout.bind(auth));
130
- const login = (0, _react.useCallback)( /*#__PURE__*/function () {
130
+ const login = (0, _react.useCallback)(/*#__PURE__*/function () {
131
131
  var _ref2 = _asyncToGenerator(function* (loginId, usid, refresh = false) {
132
132
  if (!(0, _utils.onClient)()) {
133
133
  throw new Error('Something went wrong, this client side method is invoked on the server.');
@@ -154,7 +154,7 @@ const useTrustedAgent = () => {
154
154
  return _ref2.apply(this, arguments);
155
155
  };
156
156
  }(), [auth]);
157
- const logout = (0, _react.useCallback)( /*#__PURE__*/_asyncToGenerator(function* () {
157
+ const logout = (0, _react.useCallback)(/*#__PURE__*/_asyncToGenerator(function* () {
158
158
  return yield logoutTrustedAgent.mutateAsync();
159
159
  }), [auth]);
160
160
  (0, _react.useEffect)(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/commerce-sdk-react",
3
- "version": "3.2.0-preview.0",
3
+ "version": "3.2.0-preview.3",
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": {
@@ -45,7 +45,7 @@
45
45
  "jwt-decode": "^4.0.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@salesforce/pwa-kit-dev": "3.9.0-preview.0",
48
+ "@salesforce/pwa-kit-dev": "4.0.0-extensibility-preview.3",
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": "3.9.0-preview.0",
63
+ "internal-lib-build": "4.0.0-extensibility-preview.3",
64
64
  "jsonwebtoken": "^9.0.0",
65
65
  "nock": "^13.3.0",
66
66
  "nodemon": "^2.0.22",
@@ -84,11 +84,11 @@
84
84
  "react-router-dom": "^5.3.4"
85
85
  },
86
86
  "engines": {
87
- "node": "^16.11.0 || ^18.0.0 || ^20.0.0 || ^22.0.0",
88
- "npm": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0"
87
+ "node": "^16.11.0 || ^18.0.0 || ^20.0.0",
88
+ "npm": "^8.0.0 || ^9.0.0 || ^10.0.0"
89
89
  },
90
90
  "publishConfig": {
91
91
  "directory": "dist"
92
92
  },
93
- "gitHead": "f31e6088a7e99fbe8c61d80722433811ed0e998e"
93
+ "gitHead": "904de01e826117febeea952e034478349e16ea4d"
94
94
  }