@salesforce/commerce-sdk-react 4.0.0-extensibility-preview.0 → 4.0.0-nightly-20250827080202
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 +37 -14
- package/README.md +139 -66
- package/auth/index.d.ts +181 -43
- package/auth/index.js +437 -80
- package/components/ShopperExperience/types.d.ts +2 -1
- package/components/ShopperExperience/types.js +11 -3
- package/components/StorefrontPreview/utils.js +5 -2
- package/constant.d.ts +14 -4
- package/constant.js +16 -8
- package/hooks/ShopperBaskets/cache.d.ts +2 -1
- package/hooks/ShopperBaskets/cache.js +3 -0
- package/hooks/ShopperBaskets/helpers.d.ts +34 -22
- package/hooks/ShopperBaskets/helpers.js +2 -0
- package/hooks/ShopperBaskets/mutation.d.ts +2 -1
- package/hooks/ShopperBaskets/mutation.js +4 -4
- package/hooks/ShopperBaskets/query.d.ts +2 -1
- package/hooks/ShopperBaskets/query.js +9 -17
- package/hooks/ShopperBaskets/queryKeyHelpers.js +10 -10
- package/hooks/ShopperContexts/cache.d.ts +2 -1
- package/hooks/ShopperContexts/cache.js +2 -0
- package/hooks/ShopperContexts/mutation.d.ts +2 -1
- package/hooks/ShopperContexts/mutation.js +4 -4
- package/hooks/ShopperContexts/query.d.ts +2 -1
- package/hooks/ShopperContexts/query.js +5 -5
- package/hooks/ShopperContexts/queryKeyHelpers.js +2 -2
- package/hooks/ShopperCustomers/cache.d.ts +2 -1
- package/hooks/ShopperCustomers/cache.js +2 -0
- package/hooks/ShopperCustomers/mutation.d.ts +2 -1
- package/hooks/ShopperCustomers/mutation.js +4 -4
- package/hooks/ShopperCustomers/query.d.ts +2 -1
- package/hooks/ShopperCustomers/query.js +16 -36
- package/hooks/ShopperCustomers/queryKeyHelpers.js +22 -22
- package/hooks/ShopperExperience/query.d.ts +2 -1
- package/hooks/ShopperExperience/query.js +6 -8
- package/hooks/ShopperExperience/queryKeyHelpers.js +4 -4
- package/hooks/ShopperGiftCertificates/query.d.ts +2 -1
- package/hooks/ShopperGiftCertificates/query.js +5 -5
- package/hooks/ShopperGiftCertificates/queryKeyHelpers.js +2 -2
- package/hooks/ShopperLogin/cache.d.ts +4 -1
- package/hooks/ShopperLogin/cache.js +2 -0
- package/hooks/ShopperLogin/mutation.d.ts +2 -1
- package/hooks/ShopperLogin/mutation.js +4 -4
- package/hooks/ShopperLogin/query.d.ts +2 -1
- package/hooks/ShopperLogin/query.js +7 -11
- package/hooks/ShopperLogin/queryKeyHelpers.js +6 -6
- package/hooks/ShopperOrders/cache.d.ts +2 -1
- package/hooks/ShopperOrders/cache.js +3 -0
- package/hooks/ShopperOrders/mutation.d.ts +2 -1
- package/hooks/ShopperOrders/mutation.js +4 -4
- package/hooks/ShopperOrders/query.d.ts +2 -1
- package/hooks/ShopperOrders/query.js +7 -11
- package/hooks/ShopperOrders/queryKeyHelpers.js +6 -6
- package/hooks/ShopperProducts/query.d.ts +2 -1
- package/hooks/ShopperProducts/query.js +8 -14
- package/hooks/ShopperProducts/queryKeyHelpers.js +8 -8
- package/hooks/ShopperPromotions/query.d.ts +2 -1
- package/hooks/ShopperPromotions/query.js +6 -8
- package/hooks/ShopperPromotions/queryKeyHelpers.js +4 -4
- package/hooks/{ShopperSeo → ShopperSEO}/query.d.ts +3 -2
- package/hooks/{ShopperSeo → ShopperSEO}/query.js +8 -8
- package/hooks/{ShopperSeo → ShopperSEO}/queryKeyHelpers.d.ts +2 -2
- package/hooks/{ShopperSeo → ShopperSEO}/queryKeyHelpers.js +2 -2
- package/hooks/ShopperSearch/query.d.ts +2 -1
- package/hooks/ShopperSearch/query.js +6 -8
- package/hooks/ShopperSearch/queryKeyHelpers.js +4 -4
- package/hooks/ShopperStores/query.d.ts +2 -1
- package/hooks/ShopperStores/query.js +6 -8
- package/hooks/ShopperStores/queryKeyHelpers.js +4 -4
- package/hooks/helpers.d.ts +14 -1
- package/hooks/index.d.ts +1 -1
- package/hooks/index.js +4 -4
- package/hooks/types.d.ts +23 -20
- package/hooks/useAccessToken.js +2 -3
- package/hooks/useAuthHelper.d.ts +8 -0
- package/hooks/useAuthHelper.js +9 -1
- package/hooks/useCommerceApi.d.ts +9 -1
- package/hooks/useCommerceApi.js +26 -3
- package/hooks/useConfig.d.ts +1 -1
- package/hooks/useCustomerId.js +2 -3
- package/hooks/useCustomerType.d.ts +1 -0
- package/hooks/useCustomerType.js +11 -3
- package/hooks/useDNT.d.ts +13 -7
- package/hooks/useDNT.js +19 -10
- package/hooks/useEncUserId.js +2 -3
- package/hooks/useLocalStorage.js +46 -19
- package/hooks/useQuery.js +2 -0
- package/package.json +10 -10
- package/provider.d.ts +19 -4
- package/provider.js +78 -25
- package/utils.d.ts +47 -1
- package/utils.js +86 -2
- /package/hooks/{ShopperSeo → ShopperSEO}/index.d.ts +0 -0
- /package/hooks/{ShopperSeo → ShopperSEO}/index.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,21 +1,44 @@
|
|
|
1
|
-
##
|
|
2
|
-
-
|
|
3
|
-
|
|
4
|
-
##
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
## v4.0.0-nightly-20250827080202 (Aug 27, 2025)
|
|
2
|
+
## v4.0.0-dev (Aug 27, 2025)
|
|
3
|
+
## v3.12.0-nightly-20250827080202 (Aug 27, 2025)
|
|
4
|
+
## v4.0.0-dev (Aug 18, 2025)
|
|
5
|
+
- Upgrade to commerce-sdk-isomorphic v4.0.0 [2879](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2879)
|
|
6
|
+
- Add support for environment level base paths on /mobify routes [#2892](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2892)
|
|
7
|
+
- Update USID expiry to match SLAS refresh token expiry[#2854](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2854)
|
|
8
|
+
- [Bugfix] Skip deleting dwsid on shopper login if hybrid auth is enabled for current site. [#3151](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3151)
|
|
9
|
+
- Remove deprecated properties in commerce-sdk-react [#3177](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3177)
|
|
10
|
+
- Update Auth class and CommerceApiProvider to support custom headers in SCAPI requests [#3183](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3183)
|
|
11
|
+
|
|
12
|
+
## v3.4.0 (Jul 22, 2025)
|
|
13
|
+
|
|
14
|
+
- Optionally disable auth init in CommerceApiProvider [#2629](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2629)
|
|
15
|
+
- Now compatible with either React 17 and 18 [#2506](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2506)
|
|
16
|
+
- Gracefully handle missing SDK Clients in CommerceApiProvider [#2539](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2539)
|
|
17
|
+
- Refactor commerce-sdk-react to allow injecting ApiClients [#2519](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2519)
|
|
18
|
+
- Upgrade to commerce-sdk-isomorphic v3.4.0 [#2866](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2866)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## v3.3.0 (May 22, 2025)
|
|
22
|
+
|
|
23
|
+
- Fix inconsistency between dwsid and access token for guest login when hybrid authentication is enabled [#2397](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2397)
|
|
24
|
+
- Invalidate cache instead of removing cache when triggering logout [#2323](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2323)
|
|
25
|
+
- Fix dependencies vulnerabilities [#2338](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2338)
|
|
26
|
+
- Allow custom parameters/body to be passed to SLAS authorize/authenticate calls via commerce-sdk-react auth helpers [#2358](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2358)
|
|
27
|
+
|
|
28
|
+
## v3.2.1 (Mar 05, 2025)
|
|
29
|
+
- Update PWA-Kit SDKs to v3.9.1 [#2301](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2301)
|
|
30
|
+
|
|
31
|
+
## v3.2.0 (Feb 18, 2025)
|
|
32
|
+
|
|
14
33
|
- Allow cookies for ShopperLogin API [#2190](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2190
|
|
15
34
|
- Fix refresh token TTL warning from firing when override is not provided [#2114](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2114)
|
|
16
|
-
|
|
35
|
+
- Readme updates for private clients [#2212](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2212)
|
|
17
36
|
- Update CacheUpdateMatrix for mergeBasket mutation [#2138](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2092)
|
|
18
37
|
- Clear auth state if session has been invalidated by a password change [#2092](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2092)
|
|
38
|
+
- DNT interface improvement [#2203](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2203)
|
|
39
|
+
- Support Node 22 [#2218](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2218)
|
|
40
|
+
- Add `authorizeIDP`, `loginIDPUser`, `authorizePasswordless`, `getPasswordLessAccessToken`, `getPasswordResetToken`, and `resetPassword` wrapper functions to support Social Login, Passwordless Login, and Password Reset [#2079] (https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2079)
|
|
41
|
+
|
|
19
42
|
|
|
20
43
|
## v3.1.0 (Oct 28, 2024)
|
|
21
44
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
:loudspeaker: Hey there, Salesforce Commerce Cloud community!
|
|
2
2
|
|
|
3
|
-
We
|
|
3
|
+
We're excited to hear your thoughts on your developer experience with PWA Kit and the Composable Storefront generally! Your feedback is incredibly valuable in helping us guide our roadmap and improve our offering.
|
|
4
4
|
|
|
5
5
|
:clipboard: Take our quick survey here: [Survey](https://forms.gle/bUZNxQ3QKUcrjhV18)
|
|
6
6
|
|
|
@@ -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
|
|
46
|
+
## ⚡️ Quickstart (PWA Kit v3.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,6 +54,10 @@ 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
|
+
|
|
57
61
|
return (
|
|
58
62
|
<CommerceApiProvider
|
|
59
63
|
clientId="12345678-1234-1234-1234-123412341234"
|
|
@@ -64,6 +68,11 @@ const AppConfig = ({children}) => {
|
|
|
64
68
|
shortCode="12345678"
|
|
65
69
|
locale="en-US"
|
|
66
70
|
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'})}
|
|
67
76
|
>
|
|
68
77
|
{children}
|
|
69
78
|
</CommerceApiProvider>
|
|
@@ -125,68 +134,10 @@ export default App
|
|
|
125
134
|
|
|
126
135
|
_💡 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._
|
|
127
136
|
|
|
128
|
-
To help reduce boilerplate code for managing shopper authentication, by default, this library automatically initializes shopper session and manages the tokens for developers.
|
|
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`
|
|
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.
|
|
169
138
|
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
```
|
|
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).
|
|
190
141
|
|
|
191
142
|
### Shopper Session Initialization
|
|
192
143
|
|
|
@@ -209,9 +160,27 @@ const Example = () => {
|
|
|
209
160
|
const login = useAuthHelper(AuthHelpers.LoginRegisteredUserB2C)
|
|
210
161
|
const logout = useAuthHelper(AuthHelpers.LogOut)
|
|
211
162
|
|
|
212
|
-
return
|
|
213
|
-
|
|
214
|
-
|
|
163
|
+
return (
|
|
164
|
+
<div>
|
|
165
|
+
{/* Simple login */}
|
|
166
|
+
<button onClick={() => {
|
|
167
|
+
login.mutate({username: 'kevin', password: 'pa$$word'})
|
|
168
|
+
}}>
|
|
169
|
+
Login
|
|
170
|
+
</button>
|
|
171
|
+
|
|
172
|
+
{/* Login with custom parameters */}
|
|
173
|
+
<button onClick={() => {
|
|
174
|
+
login.mutate({
|
|
175
|
+
username: 'kevin',
|
|
176
|
+
password: 'pa$$word',
|
|
177
|
+
customParameters: {c_customField: 'customValue'}
|
|
178
|
+
})
|
|
179
|
+
}}>
|
|
180
|
+
Login with Custom Parameters
|
|
181
|
+
</button>
|
|
182
|
+
</div>
|
|
183
|
+
)
|
|
215
184
|
}
|
|
216
185
|
```
|
|
217
186
|
|
|
@@ -532,6 +501,109 @@ useEncUserId() => {encUserId: String, getEncUserIdWhenReady: Promise}
|
|
|
532
501
|
useUsid() => {usid: String, getUsidWhenReady: Promise}
|
|
533
502
|
```
|
|
534
503
|
|
|
504
|
+
## Advanced: Customizing SDK Clients with `transformSDKClient`
|
|
505
|
+
|
|
506
|
+
To support advanced use cases, such as integrating with older templates or customizing API client behavior, `commerce-sdk-react` provides a utility called `transformSDKClient`. This utility wraps any Commerce SDK client instance in a JavaScript Proxy, enabling you to intercept and transform method arguments, headers, parameters, and other options before each SDK call is made.
|
|
507
|
+
|
|
508
|
+
This is especially useful for:
|
|
509
|
+
- Adapting SDK clients for legacy or custom templates.
|
|
510
|
+
- Removing references to unused SDK clients.
|
|
511
|
+
|
|
512
|
+
### How It Works
|
|
513
|
+
|
|
514
|
+
`transformSDKClient` takes an SDK client instance and a configuration object. The configuration can include:
|
|
515
|
+
- `props`: Arbitrary props you want to pass to your transformer.
|
|
516
|
+
- `transformer`: A function that receives the props, method name, and options, and returns the transformed options.
|
|
517
|
+
- `onError`: (Optional) A function to handle errors thrown by SDK methods.
|
|
518
|
+
|
|
519
|
+
Every method call on the proxied client passes through your transformer before being executed.
|
|
520
|
+
|
|
521
|
+
#### Example: Passing Custom SDK Clients to the Provider
|
|
522
|
+
|
|
523
|
+
You can use this utility to pass in your own SDK clients to the `CommerceApiProvider` via the `apiClients` prop, and apply custom transformations globally.
|
|
524
|
+
|
|
525
|
+
```js
|
|
526
|
+
import {CommerceApiProvider} from '@salesforce/commerce-sdk-react'
|
|
527
|
+
import {ShopperProducts} from 'commerce-sdk-isomorphic'
|
|
528
|
+
|
|
529
|
+
// Create your SDK client instances as usual
|
|
530
|
+
const myShopperProductsClient = new ShopperProducts({
|
|
531
|
+
// ...your config
|
|
532
|
+
})
|
|
533
|
+
|
|
534
|
+
// Pass your client(s) in the apiClients prop
|
|
535
|
+
const apiClients = {
|
|
536
|
+
shopperProducts: myShopperProductsClient
|
|
537
|
+
// ...add other clients as needed
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
const App = ({children}) => (
|
|
541
|
+
<CommerceApiProvider
|
|
542
|
+
// ...other required props
|
|
543
|
+
apiClients={apiClients}
|
|
544
|
+
// You can also pass custom headers, fetchOptions, etc.
|
|
545
|
+
>
|
|
546
|
+
{children}
|
|
547
|
+
</CommerceApiProvider>
|
|
548
|
+
)
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
> **Note:** The `CommerceApiProvider` will automatically wrap each client in `apiClients` with `transformSDKClient`, using a default transformer that injects headers and fetch options from the provider props. You must use props passed to `CommerceApiProvider` for setting custom headers and fetch options. `transformSDKClient` merges headers and options passed in as props with the default values.
|
|
552
|
+
|
|
553
|
+
### API Reference
|
|
554
|
+
|
|
555
|
+
```ts
|
|
556
|
+
transformSDKClient<T>(
|
|
557
|
+
client: T,
|
|
558
|
+
config: {
|
|
559
|
+
props?: any,
|
|
560
|
+
transformer?: (props, methodName: string, options: any) => any,
|
|
561
|
+
onError?: (methodName: string, error: any, options: any) => void
|
|
562
|
+
}
|
|
563
|
+
): T
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
- **client**: The SDK client instance to wrap.
|
|
567
|
+
- **config**:
|
|
568
|
+
- **props**: Any extra data you want to pass to your transformer.
|
|
569
|
+
- **transformer**: Function to transform method arguments before each SDK call.
|
|
570
|
+
- **onError**: (Optional) Function to handle errors from SDK methods.
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
> **Note:** If you choose to pass the `apiClients` prop, you are responsible for providing all SDK clients you intend to use in your application. Any hooks or features that rely on a missing client will throw an error at runtime. This allows for customization, but requires you to explicitly include each client you need.
|
|
574
|
+
|
|
575
|
+
### Handling Missing SDK Clients
|
|
576
|
+
|
|
577
|
+
With the introduction of the optional `apiClients` prop and support for custom SDK client injection, `commerce-sdk-react` now provides robust error handling for missing clients. If you attempt to use a query or mutation hook for a client that was not initialized or passed to the `CommerceApiProvider`, a clear error will be thrown.
|
|
578
|
+
|
|
579
|
+
For example, if you call a hook like `useShopperProducts` but did not provide a `shopperProducts` client in your `apiClients` prop, you will see an error message similar to this error.
|
|
580
|
+
|
|
581
|
+
```text
|
|
582
|
+
Missing required client: shopperProducts. Please initialize shopperProducts class and provide it in CommerceApiProvider's apiClients prop.
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
This ensures that your application fails fast and provides actionable feedback, making it easier to debug configuration issues—especially when integrating with older templates or customizing your SDK client setup.
|
|
586
|
+
|
|
587
|
+
### Disabling Automatic Auth Initialization
|
|
588
|
+
|
|
589
|
+
By default, `CommerceApiProvider` automatically initializes authentication by calling `auth.ready()` as soon as the provider renders. This is the standard and recommended behavior for most applications.
|
|
590
|
+
|
|
591
|
+
**New in v3.4.0:** You can now optionally disable this automatic initialization by passing the `disableAuthInit` prop:
|
|
592
|
+
|
|
593
|
+
```jsx
|
|
594
|
+
<CommerceApiProvider
|
|
595
|
+
// ...other required props
|
|
596
|
+
disableAuthInit={true}
|
|
597
|
+
>
|
|
598
|
+
{children}
|
|
599
|
+
</CommerceApiProvider>
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
- **Default:** `disableAuthInit` is `false` (auth is initialized automatically).
|
|
603
|
+
- **When to use:** Set `disableAuthInit` to `true` if you are initializing authentication outside of the provider (for example, in legacy PWA Kit templates or when using SSR with `getProps`). This prevents duplicate initialization and potential issues with tokens or customer information.
|
|
604
|
+
|
|
605
|
+
> **Note:** For most modern PWA Kit and React Query-based apps, you do **not** need to set this prop.
|
|
606
|
+
|
|
535
607
|
## Roadmap
|
|
536
608
|
|
|
537
609
|
- Optimistic update support
|
|
@@ -550,3 +622,4 @@ useUsid() => {usid: String, getUsidWhenReady: Promise}
|
|
|
550
622
|
- [Routing](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/routing.html)
|
|
551
623
|
- [Phased Headless Rollouts](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/phased-headless-rollouts.html)
|
|
552
624
|
- [Launch Your Storefront](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/launching-your-storefront.html)
|
|
625
|
+
|