@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 CHANGED
@@ -1,29 +1,10 @@
1
- ## v3.1.0 (Oct 28, 2024)
2
-
3
- - [Server Affinity] Attach dwsid to SCAPI request headers [#2090](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2090)
4
- - Add the `authorizeCustomer` and `getPasswordResetToken` to the `ShopperLoginMutations` [#2056](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2056)
5
- - Add useDNT hook to commerce-sdk-react and put DNT in auth [#2067](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2067/files)
6
- - Add Trusted Agent on Behalf of (TAOB) support for SLAS APIs [#2077](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2077)
7
- - Add optional `refreshTokenRegisteredCookieTTL` and `refreshTokenGuestCookieTTL` to Commerce API config [#2077](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2077)
8
- - Improve refresh token error logging [#2028](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2028)
9
- - Remove ocapi session-bridging on phased launches [#2011](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2011)
10
- - Add `defaultDnt` to support setting the dnt flag for SLAS. Upgrade `commerce-sdk-isomorphic` to v3.1.1 [#1979](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1979)
11
- - Update logout helper to work for guest users [#1997](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1997)
12
- - Update `useCustomMutation` hook to accept request body as a parameter to the mutate function [#2030](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2030)
13
- - Simplify `useCustomMutation` hook implementation [#2034](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2034)
14
- - Documentation for `useCustomMutation` hook along with new dynamic `body` param option [#2042](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2042)
15
-
16
- ## v3.0.1 (Sep 04, 2024)
17
-
18
- - Fixed an issue where the `expires` attribute in cookies, ensuring it uses seconds instead of days. [#1994](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1994)
1
+ ## v3.1.1-preview.0 (Dec 02, 2024)
19
2
 
20
3
  ## v3.0.0 (Aug 07, 2024)
21
-
22
- - Add `meta.displayName` to queries. It can be used to identify queries in performance metrics or logs. [#1895](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1895)
23
- - Upgrade to commerce-sdk-isomorphic v3.0.0 [#1914](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1914)
4
+ - Add `meta.displayName` to queries. It can be used to identify queries in performance metrics or logs. [#1895](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1895)
5
+ - Upgrade to commerce-sdk-isomorphic v3.0.0 [#1914](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1914)
24
6
 
25
7
  ### :warning: Planned API Changes :warning:
26
-
27
8
  #### Shopper Context
28
9
 
29
10
  Starting July 31st 2024, all endpoints in the Shopper context API will require the `siteId` parameter for new customers. This field is marked as optional for backward compatibility and will be changed to mandatory tentatively by January 2025. You can read more about the planned change [here](https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-context?meta=Summary) in the notes section.
@@ -32,79 +13,73 @@ Starting July 31st 2024, all endpoints in the Shopper context API will require t
32
13
 
33
14
  SLAS will soon require new tenants to pass `channel_id` as an argument for retrieving guest access tokens. You can read more about the planned change [here](https://developer.salesforce.com/docs/commerce/commerce-api/guide/slas.html#guest-tokens).
34
15
 
35
- Please be aware that existing tenants are on a temporary allow list and will see no immediate disruption to service. We do ask that all users seek to adhere to the `channel_id` requirement before the end of August to enhance your security posture before the holiday peak season.
16
+ Please be aware that existing tenants are on a temporary allow list and will see no immediate disruption to service. We do ask that all users seek to adhere to the `channel_id` requirement before the end of August to enhance your security posture before the holiday peak season.
36
17
 
37
18
  In practice, we recommend:
38
-
39
- - For customers using the SLAS helpers with a private client, it is recommended to upgrade to `v3.0.0` of the `commerce-sdk-react`.
19
+ - For customers using the SLAS helpers with a private client, it is recommended to upgrade to `v3.0.0` of the `commerce-sdk-react`.
40
20
 
41
21
  ## v2.0.2 (Jul 12, 2024)
42
-
43
- - Updated StorefrontPreview component to make siteId available [#1874](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1874)
22
+ - Updated StorefrontPreview component to make siteId available [#1874](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1874)
44
23
 
45
24
  ## v2.0.1 (Jul 08, 2024)
46
-
47
- - Fix private slas proxy config for commerce api in provider [#1883](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1883)
48
- - Fix `useCustomQuery` error handling [#1883](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1883)
49
- - Fix `updateCustomer` squashing existing data [#1883](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1883)
50
- - Fix `transferBasket` updating the wrong customer basket [#1887](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1887)
25
+ - Fix private slas proxy config for commerce api in provider [#1883](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1883)
26
+ - Fix `useCustomQuery` error handling [#1883](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1883)
27
+ - Fix `updateCustomer` squashing existing data [#1883](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1883)
28
+ - Fix `transferBasket` updating the wrong customer basket [#1887](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1887)
51
29
 
52
30
  ## v2.0.0 (Jun 25, 2024)
53
-
54
- - Add `useCustomQuery` and `useCustomMutation` for SCAPI custom endpoint support [#1793](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1793)
55
- - Add Shopper Stores hooks [#1788](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1788)
56
- - Add a helper method to add an item to either new or existing basket [#1677](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1677)
57
- - Add `updateItemsInBasket` mutation [#1852](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1852)
58
- - Upgrade to commerce-sdk-isomorphic v2.1.0 [#1852](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1852)
31
+ - Add `useCustomQuery` and `useCustomMutation` for SCAPI custom endpoint support [#1793](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1793)
32
+ - Add Shopper Stores hooks [#1788](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1788)
33
+ - Add a helper method to add an item to either new or existing basket [#1677](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1677)
34
+ - Add `updateItemsInBasket` mutation [#1852](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1852)
35
+ - Upgrade to commerce-sdk-isomorphic v2.1.0 [#1852](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1852)
59
36
 
60
37
  ## v1.4.2 (Apr 17, 2024)
61
-
62
- - Update SLAS private proxy path [#1752](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1752)
38
+ - Update SLAS private proxy path [#1752](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1752)
63
39
 
64
40
  ## v1.4.1 (Apr 16, 2024)
65
-
66
- - Add missing params keys `allVariationProperties` and `perPricebook` for Shopper Search [#1750](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1750)
41
+ - Add missing params keys `allVariationProperties` and `perPricebook` for Shopper Search [#1750](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1750)
67
42
 
68
43
  ## v1.4.0 (Apr 15, 2024)
69
44
 
70
- - Add Support for SLAS private flow [#1722](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1722)
71
- - Fix invalid query params warnings and allow custom query [#1655](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1655)
72
- - Fix cannot read properties of undefined (reading 'unshift') [#1689](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1689)
73
- - Add Shopper SEO hook [#1688](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1688)
74
- - Update useLocalStorage implementation to be more responsive [#1703](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1703)
75
- - Storefront Preview: avoid stale cached Commerce API responses, whenever the Shopper Context is set [#1701](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1701)
45
+ - Add Support for SLAS private flow [#1722](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1722)
46
+ - Fix invalid query params warnings and allow custom query [#1655](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1655)
47
+ - Fix cannot read properties of undefined (reading 'unshift') [#1689](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1689)
48
+ - Add Shopper SEO hook [#1688](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1688)
49
+ - Update useLocalStorage implementation to be more responsive [#1703](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1703)
50
+ - Storefront Preview: avoid stale cached Commerce API responses, whenever the Shopper Context is set [#1701](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1701)
76
51
 
77
52
  ## v1.3.0 (Jan 19, 2024)
78
53
 
79
- - Add support for node 20 [#1612](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1612)
54
+ - Add support for node 20 [#1612](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1612)
80
55
 
81
56
  ## v1.2.0 (Dec 08, 2023)
82
57
 
83
- - Add StorefrontPreview component 'onContextChange' property to prepare for future Storefront Preview release [#1527](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1527)
84
- - Update engine compatibility to include npm 10 [#1597](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1597)
58
+ - Add StorefrontPreview component 'onContextChange' property to prepare for future Storefront Preview release [#1527](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1527)
59
+ - Update engine compatibility to include npm 10 [#1597](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1597)
85
60
 
86
61
  ## v1.1.0 (Nov 03, 2023)
87
62
 
88
- - Add StorefrontPreview component [#1508](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1508)
89
- - Using `login` for authentication instead of `email` in registration process [#1464](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1464)
90
- - Fix bug to remove cookies using the default attributes used when setting cookie [#1505](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1505)
63
+ - Add StorefrontPreview component [#1508](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1508)
64
+ - Using `login` for authentication instead of `email` in registration process [#1464](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1464)
65
+ - Fix bug to remove cookies using the default attributes used when setting cookie [#1505](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1505)
91
66
 
92
67
  ## v1.0.2 (Sep 21, 2023)
93
68
 
94
- - commerce-sdk-react: have typedoc-related deps as dev dependencies [#1425](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1425)
95
- - Updated commerce-sdk-isomorphic to v1.10.4 [#137](https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic/pull/137)
69
+ - commerce-sdk-react: have typedoc-related deps as dev dependencies [#1425](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1425)
70
+ - Updated commerce-sdk-isomorphic to v1.10.4 [#137](https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic/pull/137)
96
71
 
97
72
  ## v1.0.1 (Jul 26, 2023)
98
73
 
99
- - Updated the expiry of the guest refresh token cookie to 30 days, to match the actual [duration of the token](https://developer.salesforce.com/docs/commerce/commerce-api/guide/slas.html?q=refresh+token#access-tokens-and-refresh-tokens). [#1342](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1342)
100
- - Fix potential security vulnerability in `semver` dependency [#1358](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1358)
101
- - Fix request headers to be the intended headers, rather than parameters [#1377](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1377)
74
+ - Updated the expiry of the guest refresh token cookie to 30 days, to match the actual [duration of the token](https://developer.salesforce.com/docs/commerce/commerce-api/guide/slas.html?q=refresh+token#access-tokens-and-refresh-tokens). [#1342](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1342)
75
+ - Fix potential security vulnerability in `semver` dependency [#1358](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1358)
76
+ - Fix request headers to be the intended headers, rather than parameters [#1377](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1377)
102
77
 
103
78
  ## v1.0.0 (Jun 15, 2023)
104
79
 
105
- - First public release of package on npm under `@salesforce/commerce-sdk-react`
106
- - Add missing cache invalidation for contexts/customers/login/order [#1073](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1073)
107
- - Upgrade React 18, React DOM 18, @types/react@18, @types/react-dom@v18 Testing library 14 [#1166](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1166)
80
+ - First public release of package on npm under `@salesforce/commerce-sdk-react`
81
+ - Add missing cache invalidation for contexts/customers/login/order [#1073](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1073)
82
+ - Upgrade React 18, React DOM 18, @types/react@18, @types/react-dom@v18 Testing library 14 [#1166](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1166)
108
83
 
109
84
  ## Older Versions Without Namespace
110
85
 
@@ -112,28 +87,28 @@ The older versions below were published without the `@salesforce` namespace.
112
87
 
113
88
  ## v2.7.1 (May 11, 2023)
114
89
 
115
- - Re-generate lock files and fix hook lib tests [#1186](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1186)
116
- - Add additional properties to ShopperLogin test types [#1185](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1185)
117
- - Add missing cache invalidation for contexts/customers/login/order [#1073](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1073)
118
- - Fix Shopper Baskets Test case [#1082](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1082)
119
- - Implement remaining Shopper Baskets cache logic [#1070](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1070)
120
- - Decode pre-fetched token and save auth data in storage [#1052](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1052)
121
- - Allow query hook parameters to be null. [#1046](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1046)
122
- - Implement updateCustomerPassword as no-op. [#1031](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1031)
90
+ - Re-generate lock files and fix hook lib tests [#1186](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1186)
91
+ - Add additional properties to ShopperLogin test types [#1185](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1185)
92
+ - Add missing cache invalidation for contexts/customers/login/order [#1073](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1073)
93
+ - Fix Shopper Baskets Test case [#1082](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1082)
94
+ - Implement remaining Shopper Baskets cache logic [#1070](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1070)
95
+ - Decode pre-fetched token and save auth data in storage [#1052](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1052)
96
+ - Allow query hook parameters to be null. [#1046](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1046)
97
+ - Implement updateCustomerPassword as no-op. [#1031](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1031)
123
98
 
124
99
  ## v2.7.0 (Mar 03, 2023)
125
100
 
126
- - Add Page/Region/Component components for shopper experience/page designer page rendering [#963](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/963)
127
- - Namespace `Auth` storage keys with site identifier to allow multi-site support [#911](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/911)
128
- - Add Shopper Experience `usePage` and `usePages` hooks[#958](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/958)
101
+ - Add Page/Region/Component components for shopper experience/page designer page rendering [#963](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/963)
102
+ - Namespace `Auth` storage keys with site identifier to allow multi-site support [#911](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/911)
103
+ - Add Shopper Experience `usePage` and `usePages` hooks[#958](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/958)
129
104
 
130
105
  ## v2.6.0 (Jan 25, 2023)
131
106
 
132
107
  ## v2.5.0 (Jan 05, 2023)
133
108
 
134
- - Exclude test files in package file to avoid publishing them [#856](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/856)
135
- - Pass in 'headers' and 'rawResponse' options to mutation hooks [#845](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/845)
136
- - Commerce hooks: basket mutations [#834](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/834)
137
- - Remove overriding of params in mutation hooks [#859](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/859)
109
+ - Exclude test files in package file to avoid publishing them [#856](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/856)
110
+ - Pass in 'headers' and 'rawResponse' options to mutation hooks [#845](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/845)
111
+ - Commerce hooks: basket mutations [#834](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/834)
112
+ - Remove overriding of params in mutation hooks [#859](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/859)
138
113
 
139
114
  ## v2.4.0 (Dec 01, 2022)
package/README.md CHANGED
@@ -321,135 +321,7 @@ const Example = ({basketId}) => {
321
321
  }
322
322
  ```
323
323
 
324
- ##### `useCustomMutation`
325
-
326
- The `useCustomMutation` hook facilitates communication with the SCAPI custom endpoint. It has a different signature than the other declared mutation hooks.
327
-
328
- ###### Parameters
329
-
330
- - `options` (Object): Configuration for the API request.
331
- - `method` (String): The HTTP method to use (e.g., 'POST', 'GET').
332
- - `customApiPathParameters` (Object): Contains parameters to define the API path.
333
- - `endpointPath` (String): Specific endpoint path to target in the API.
334
- - `apiName` (String): The name of the API.
335
-
336
- - `clientConfig` (Object): Configuration settings for the client.
337
- - `parameters` (Object): Essential parameters required by the Salesforce Commerce Cloud API.
338
- - `clientId` (String): Your client ID.
339
- - `siteId` (String): Your site ID.
340
- - `organizationId` (String): Your organization ID.
341
- - `shortCode` (String): Short code for your organization.
342
- - `proxy` (String): Proxy address for API calls.
343
-
344
- - `rawResponse` (Boolean): Determines whether to receive the raw response from the API or a parsed version.
345
-
346
- ###### `mutate` Method
347
-
348
- The `mutation.mutate(args)` function is used to execute the mutation. It accepts an argument `args`, which is an object that may contain the following properties:
349
-
350
- - `headers` (Object): Optional headers to send with the request.
351
- - `parameters` (Object): Optional query parameters to append to the API URL.
352
- - `body` (Object): Optional the payload for POST, PUT, PATCH methods.
353
-
354
- ##### Usage
355
-
356
- Below is a sample usage of the `useCustomMutation` hook within a React component.
357
-
358
-
359
-
360
- ```jsx
361
- const clientConfig = {
362
- parameters: {
363
- clientId: 'CLIENT_ID',
364
- siteId: 'SITE_ID',
365
- organizationId: 'ORG_ID',
366
- shortCode: 'SHORT_CODE'
367
- },
368
- proxy: 'http://localhost:8888/mobify/proxy/api'
369
- };
370
-
371
- const mutation = useCustomMutation({
372
- options: {
373
- method: 'POST',
374
- customApiPathParameters: {
375
- endpointPath: 'test-hello-world',
376
- apiName: 'hello-world'
377
- }
378
- },
379
- clientConfig,
380
- rawResponse: false
381
- });
382
-
383
- // In your React component
384
- <button onClick={() => mutation.mutate({
385
- body: { test: '123' },
386
- parameters: { additional: 'value' },
387
- headers: { ['X-Custom-Header']: 'test' }
388
- })}>
389
- Send Request
390
- </button>
391
- ```
392
-
393
- It is a common scenario that a mutate function might pass a value along to a request that is dynamic and therefore can't be available when the hook is declared (contrary to example in [Mutation Hooks](#mutation-hooks) above, which would work for a button that only adds one product to a basket, but doesn't handle a changeable input for adding a different product).
394
-
395
- Sending a custom body param is supported, the example below combines this strategy with the use of a `useCustomMutation()` hook, making it possible to dynamically declare a body when calling a custom API endpoint.
396
-
397
- ```jsx
398
- import {useCustomMutation} from '@salesforce/commerce-sdk-react'
399
- const clientConfig = {
400
- parameters: {
401
- clientId: 'CLIENT_ID',
402
- siteId: 'SITE_ID',
403
- organizationId: 'ORG_ID',
404
- shortCode: 'SHORT_CODE'
405
- },
406
- proxy: 'http://localhost:8888/mobify/proxy/api'
407
- };
408
-
409
- const mutation = useCustomMutation({
410
- options: {
411
- method: 'POST',
412
- customApiPathParameters: {
413
- endpointPath: 'path/to/resource',
414
- apiName: 'hello-world'
415
- }
416
- },
417
- clientConfig,
418
- rawResponse: false
419
- });
420
-
421
- // use it in a react component
422
- const ExampleDynamicMutation = () => {
423
- const [colors, setColors] = useState(['blue', 'green', 'white'])
424
- const [selectedColor, setSelectedColor] = useState(colors[0])
425
-
426
- return (
427
- <>
428
- <select value={selectedColor} onChange={(e) => setSelectedColor(e.target.value)}>
429
- {colors.map((color, index) => (
430
- <option key={index} value={color}>
431
- {color}
432
- </option>
433
- ))}
434
- </select>
435
- <button
436
- onClick={() =>
437
- mutation.mutate({
438
- parameters: {
439
- myCustomParam: 'custom parameters'
440
- },
441
- body: {
442
- resourceParam: selectedColor
443
- }
444
- })
445
- }
446
- />
447
- </>
448
- )
449
- }
450
- ```
451
-
452
- Mutations also have their named methods exported as constants, available in this way:
324
+ You could also import the mutation options as a constant like:
453
325
 
454
326
  ```jsx
455
327
  import {useShopperBasketsMutation, ShopperBasketsMutations} from '@salesforce/commerce-sdk-react'
package/auth/index.d.ts CHANGED
@@ -1,7 +1,6 @@
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 { DNT_COOKIE_NAME, DWSID_COOKIE_NAME } from '../constant';
5
4
  import { Logger } from '../types';
6
5
  type TokenResponse = ShopperLoginTypes.TokenResponse;
7
6
  type Helpers = typeof helpers;
@@ -10,13 +9,11 @@ interface AuthConfig extends ApiClientConfigParams {
10
9
  proxy: string;
11
10
  fetchOptions?: ShopperLoginTypes.FetchOptions;
12
11
  fetchedToken?: string;
12
+ OCAPISessionsURL?: string;
13
13
  enablePWAKitPrivateClient?: boolean;
14
14
  clientSecret?: string;
15
15
  silenceWarnings?: boolean;
16
16
  logger: Logger;
17
- defaultDnt?: boolean;
18
- refreshTokenRegisteredCookieTTL?: number;
19
- refreshTokenGuestCookieTTL?: number;
20
17
  }
21
18
  /**
22
19
  * The extended field is not from api response, we manually store the auth type,
@@ -29,9 +26,7 @@ export type AuthData = Prettify<RemoveStringIndex<TokenResponse> & {
29
26
  idp_access_token: string;
30
27
  }>;
31
28
  /** A shopper could be guest or registered, so we store the refresh tokens individually. */
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
- export declare const DEFAULT_SLAS_REFRESH_TOKEN_REGISTERED_TTL: number;
34
- export declare const DEFAULT_SLAS_REFRESH_TOKEN_GUEST_TTL: number;
29
+ type AuthDataKeys = Exclude<keyof AuthData, 'refresh_token'> | 'refresh_token_guest' | 'refresh_token_registered' | 'access_token_sfra';
35
30
  /**
36
31
  * This class is used to handle shopper authentication.
37
32
  * It is responsible for initializing shopper session, manage access
@@ -47,19 +42,13 @@ declare class Auth {
47
42
  private pendingToken;
48
43
  private stores;
49
44
  private fetchedToken;
45
+ private OCAPISessionsURL;
50
46
  private clientSecret;
51
47
  private silenceWarnings;
52
48
  private logger;
53
- private defaultDnt;
54
- private refreshTokenRegisteredCookieTTL;
55
- private refreshTokenGuestCookieTTL;
56
- private refreshTrustedAgentHandler;
57
49
  constructor(config: AuthConfig);
58
50
  get(name: AuthDataKeys): string;
59
51
  private set;
60
- private delete;
61
- getDnt(): boolean | undefined;
62
- setDnt(preference: boolean | null): Promise<void>;
63
52
  private clearStorage;
64
53
  /**
65
54
  * Every method in this class that returns a `TokenResponse` constructs it via this getter.
@@ -69,11 +58,6 @@ declare class Auth {
69
58
  * Used to validate JWT token expiration.
70
59
  */
71
60
  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;
77
61
  /**
78
62
  * Returns the SLAS access token or an empty string if the access token
79
63
  * is not found in local store or if SFRA wants PWA to trigger refresh token login.
@@ -89,46 +73,12 @@ declare class Auth {
89
73
  * @returns {string} access token
90
74
  */
91
75
  private getAccessToken;
92
- /**
93
- * For Hybrid storefronts ONLY!!!
94
- * This method clears out SLAS access token generated in Plugin SLAS and passed in via "cc-at" cookie.
95
- *
96
- * In a hybrid setup, whenever any SLAS flow executes in Plugin SLAS and an access token is generated,
97
- * the access token is sent over to PWA Kit using cc-at cookie.
98
- *
99
- * PWA Kit will check to see if cc-at cookie exists, if it does, the access token value in localStorage is updated
100
- * with value from the cc-at cookie and is then used for all SCAPI requests made from PWA Kit. The cc-at cookie is then cleared.
101
- */
102
76
  private clearSFRAAuthToken;
103
77
  /**
104
- * For Hybrid storefronts ONLY!!!
105
- * This method clears the dwsid cookie from the browser.
106
- * In a hybrid setup, dwsid points to an ECOM session and is passed between PWA Kit and SFRA/SG sites via "dwsid" cookie.
107
- *
108
- * Whenever a registered shopper logs in on PWA Kit, we must clear the dwsid cookie if one exists. When shopper navigates
109
- * to SFRA as a logged-in shopper, ECOM notices a missing DWSID, generates a new DWSID and triggers the onSession hook which uses
110
- * registered shopper refresh-token and restores session and basket on SFRA.
111
- */
112
- private clearECOMSession;
113
- /**
114
- * Converts a duration in seconds to a Date object.
115
- * This function takes a number representing seconds and returns a Date object
116
- * for the current time plus the given duration.
117
- *
118
- * @param {number} seconds - The number of seconds to add to the current time.
119
- * @returns {Date} A Date object for the expiration time.
120
- */
121
- private convertSecondsToDate;
122
- /**
123
- * Retrieves our refresh token cookie ttl value
124
- */
125
- private getRefreshTokenCookieTTLValue;
126
- /**
127
- * This method stores the TokenResponse object retrieved from SLAS, and
78
+ * This method stores the TokenResponse object retrived from SLAS, and
128
79
  * store the data in storage.
129
80
  */
130
81
  private handleTokenResponse;
131
- refreshAccessToken(): Promise<ShopperLoginTypes.TokenResponse>;
132
82
  /**
133
83
  * This method queues the requests and handles the SLAS token response.
134
84
  *
@@ -138,25 +88,6 @@ declare class Auth {
138
88
  */
139
89
  queueRequest(fn: () => Promise<TokenResponse>, isGuest: boolean): Promise<ShopperLoginTypes.TokenResponse>;
140
90
  logWarning: (msg: string) => void;
141
- /**
142
- * This method extracts the status and message from a ResponseError that is returned
143
- * by commerce-sdk-isomorphic.
144
- *
145
- * commerce-sdk-isomorphic throws a `ResponseError`, but doesn't export the class.
146
- * We can't use `instanceof`, so instead we just check for the `response` property
147
- * and assume it is a `ResponseError` if a response is present
148
- *
149
- * Once commerce-sdk-isomorphic exports `ResponseError` we can revisit if this method is
150
- * still required.
151
- *
152
- * @returns {status_code, responseMessage} contained within the ResponseError
153
- * @throws error if the error is not a ResponseError
154
- * @Internal
155
- */
156
- extractResponseError: (error: Error) => Promise<{
157
- status_code: string;
158
- responseMessage: string;
159
- }>;
160
91
  /**
161
92
  * The ready function returns a promise that resolves with valid ShopperLogin
162
93
  * token response.
@@ -166,8 +97,7 @@ declare class Auth {
166
97
  * The flow:
167
98
  * 1. If we have valid access token - use it
168
99
  * 2. If we have valid refresh token - refresh token flow
169
- * 3. If we have valid TAOB access token - refresh TAOB token flow
170
- * 4. PKCE flow
100
+ * 3. PKCE flow
171
101
  */
172
102
  ready(): Promise<ShopperLoginTypes.TokenResponse>;
173
103
  /**
@@ -285,54 +215,22 @@ declare class Auth {
285
215
  */
286
216
  loginRegisteredUserB2C(credentials: Parameters<Helpers['loginRegisteredUserB2C']>[1]): Promise<helpers.TokenResponse>;
287
217
  /**
288
- * Trusted agent authorization
218
+ * A wrapper method for commerce-sdk-isomorphic helper: logout.
289
219
  *
290
- * @warning This method is not supported on the server, it is a client-only method.
291
220
  */
292
- authorizeTrustedAgent(credentials: {
293
- loginId?: string;
294
- }): Promise<{
295
- url: string;
296
- codeVerifier: string;
297
- }>;
221
+ logout(): Promise<ShopperLoginTypes.TokenResponse>;
298
222
  /**
299
- * Trusted agent login
223
+ * Make a post request to the OCAPI /session endpoint to bridge the session.
300
224
  *
301
- * @warning This method is not supported on the server, it is a client-only method.
302
- */
303
- loginTrustedAgent(credentials: {
304
- loginId?: string;
305
- code: string;
306
- codeVerifier?: string;
307
- usid?: string;
308
- state?: string;
309
- clientSecret?: string;
310
- }): Promise<{
311
- access_token: string;
312
- id_token: string;
313
- refresh_token: string;
314
- expires_in: number;
315
- refresh_token_expires_in: any;
316
- token_type: string;
317
- usid: string;
318
- customer_id: string;
319
- enc_user_id: string;
320
- idp_access_token: string;
321
- } & {
322
- [key: string]: any;
323
- }>;
324
- /**
325
- * Trusted agent refresh handler
225
+ * The HTTP response contains a set-cookie header which sets the dwsid session cookie.
226
+ * This cookie is used on SFRA, and it allows shoppers to navigate between SFRA and
227
+ * this PWA site seamlessly; this is often used to enable hybrid deployment.
326
228
  *
327
- * @warning This method is not supported on the server, it is a client-only method.
328
- */
329
- registerTrustedAgentRefreshHandler(refreshTrustedAgentHandler: (loginId?: string, usid?: string, refresh?: boolean) => Promise<TokenResponse>): void;
330
- refreshTrustedAgent(loginId: string, usid: string): Promise<TokenResponse>;
331
- /**
332
- * A wrapper method for commerce-sdk-isomorphic helper: logout.
229
+ * (Note: this method is client side only, b/c MRT doesn't support set-cookie header right now)
333
230
  *
231
+ * @returns {Promise}
334
232
  */
335
- logout(): Promise<ShopperLoginTypes.TokenResponse>;
233
+ createOCAPISession(): Promise<Response>;
336
234
  /**
337
235
  * Decode SLAS JWT and extract information such as customer id, usid, etc.
338
236
  *
@@ -341,10 +239,6 @@ declare class Auth {
341
239
  isGuest: boolean;
342
240
  customerId: string;
343
241
  usid: string;
344
- dnt: string;
345
- loginId: string;
346
- isAgent: boolean;
347
- agentId: string | null;
348
242
  };
349
243
  }
350
244
  export default Auth;