Skip to content

Commit d33ca67

Browse files
authored
Merge branch 'develop' into W-18685522-reset-and-passwordless-integration-test
2 parents ecd8171 + a12b0f8 commit d33ca67

File tree

75 files changed

+9167
-1222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+9167
-1222
lines changed

packages/commerce-sdk-react/README.md

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:loudspeaker: Hey there, Salesforce Commerce Cloud community!
22

3-
Were 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.
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.
44

55
:clipboard: Take our quick survey here: [Survey](https://forms.gle/bUZNxQ3QKUcrjhV18)
66

@@ -483,6 +483,109 @@ useEncUserId() => {encUserId: String, getEncUserIdWhenReady: Promise}
483483
useUsid() => {usid: String, getUsidWhenReady: Promise}
484484
```
485485
486+
## Advanced: Customizing SDK Clients with `transformSDKClient`
487+
488+
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.
489+
490+
This is especially useful for:
491+
- Adapting SDK clients for legacy or custom templates.
492+
- Removing references to unused SDK clients.
493+
494+
### How It Works
495+
496+
`transformSDKClient` takes an SDK client instance and a configuration object. The configuration can include:
497+
- `props`: Arbitrary props you want to pass to your transformer.
498+
- `transformer`: A function that receives the props, method name, and options, and returns the transformed options.
499+
- `onError`: (Optional) A function to handle errors thrown by SDK methods.
500+
501+
Every method call on the proxied client passes through your transformer before being executed.
502+
503+
#### Example: Passing Custom SDK Clients to the Provider
504+
505+
You can use this utility to pass in your own SDK clients to the `CommerceApiProvider` via the `apiClients` prop, and apply custom transformations globally.
506+
507+
```js
508+
import {CommerceApiProvider} from '@salesforce/commerce-sdk-react'
509+
import {ShopperProducts} from 'commerce-sdk-isomorphic'
510+
511+
// Create your SDK client instances as usual
512+
const myShopperProductsClient = new ShopperProducts({
513+
// ...your config
514+
})
515+
516+
// Pass your client(s) in the apiClients prop
517+
const apiClients = {
518+
shopperProducts: myShopperProductsClient
519+
// ...add other clients as needed
520+
}
521+
522+
const App = ({children}) => (
523+
<CommerceApiProvider
524+
// ...other required props
525+
apiClients={apiClients}
526+
// You can also pass custom headers, fetchOptions, etc.
527+
>
528+
{children}
529+
</CommerceApiProvider>
530+
)
531+
```
532+
533+
> **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.
534+
535+
### API Reference
536+
537+
```ts
538+
transformSDKClient<T>(
539+
client: T,
540+
config: {
541+
props?: any,
542+
transformer?: (props, methodName: string, options: any) => any,
543+
onError?: (methodName: string, error: any, options: any) => void
544+
}
545+
): T
546+
```
547+
548+
- **client**: The SDK client instance to wrap.
549+
- **config**:
550+
- **props**: Any extra data you want to pass to your transformer.
551+
- **transformer**: Function to transform method arguments before each SDK call.
552+
- **onError**: (Optional) Function to handle errors from SDK methods.
553+
554+
555+
> **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.
556+
557+
### Handling Missing SDK Clients
558+
559+
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.
560+
561+
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.
562+
563+
```text
564+
Missing required client: shopperProducts. Please initialize shopperProducts class and provide it in CommerceApiProvider's apiClients prop.
565+
```
566+
567+
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.
568+
569+
### Disabling Automatic Auth Initialization
570+
571+
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.
572+
573+
**New in v3.4.0:** You can now optionally disable this automatic initialization by passing the `disableAuthInit` prop:
574+
575+
```jsx
576+
<CommerceApiProvider
577+
// ...other required props
578+
disableAuthInit={true}
579+
>
580+
{children}
581+
</CommerceApiProvider>
582+
```
583+
584+
- **Default:** `disableAuthInit` is `false` (auth is initialized automatically).
585+
- **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.
586+
587+
> **Note:** For most modern PWA Kit and React Query-based apps, you do **not** need to set this prop.
588+
486589
## Roadmap
487590
488591
- Optimistic update support
@@ -501,3 +604,4 @@ useUsid() => {usid: String, getUsidWhenReady: Promise}
501604
- [Routing](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/routing.html)
502605
- [Phased Headless Rollouts](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/phased-headless-rollouts.html)
503606
- [Launch Your Storefront](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/launching-your-storefront.html)
607+

packages/pwa-kit-create-app/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## v3.11.0-dev.0 (May 23, 2025)
2+
- Add `program.json` + Support for Agent-Friendly CLI Input via stdio [#2662](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2662)
23
- Change the default ECOM instance in the generated application [#2610](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2610)
34
- Load active data scripts on demand only [#2623](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2623)
45

packages/pwa-kit-create-app/assets/bootstrap/js/overrides/app/constants.js.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import {
1717
DEFAULT_LIMIT_VALUES,
1818
DEFAULT_SEARCH_PARAMS
19-
} from '{{preset.templateSource.id}}/app/constants'
19+
} from '{{template.source.name}}/app/constants'
2020

2121
// original value is 25
2222
DEFAULT_LIMIT_VALUES[0] = 3
@@ -26,4 +26,4 @@ export const CUSTOM_HOME_TITLE = '🎉 Hello Extensible React Template!'
2626

2727
export {DEFAULT_LIMIT_VALUES, DEFAULT_SEARCH_PARAMS}
2828

29-
export * from '{{preset.templateSource.id}}/app/constants'
29+
export * from '{{template.source.name}}/app/constants'

packages/pwa-kit-create-app/assets/bootstrap/js/overrides/app/pages/home/index.jsx.hbs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ import {useIntl, FormattedMessage} from 'react-intl'
99
import {useLocation} from 'react-router-dom'
1010

1111
// Components
12-
import {Box, Button, Stack, Link} from '{{preset.templateSource.id}}/app/components/shared/ui'
12+
import {Box, Button, Stack, Link} from '{{template.source.name}}/app/components/shared/ui'
1313

1414
// Project Components
15-
import Hero from '{{preset.templateSource.id}}/app/components/hero'
16-
import Seo from '{{preset.templateSource.id}}/app/components/seo'
17-
import Section from '{{preset.templateSource.id}}/app/components/section'
18-
import ProductScroller from '{{preset.templateSource.id}}/app/components/product-scroller'
15+
import Hero from '{{template.source.name}}/app/components/hero'
16+
import Seo from '{{template.source.name}}/app/components/seo'
17+
import Section from '{{template.source.name}}/app/components/section'
18+
import ProductScroller from '{{template.source.name}}/app/components/product-scroller'
1919

2020
// Others
2121
import {getAssetUrl} from '@salesforce/pwa-kit-react-sdk/ssr/universal/utils'
2222

2323
//Hooks
24-
import useEinstein from '{{preset.templateSource.id}}/app/hooks/use-einstein'
24+
import useEinstein from '{{template.source.name}}/app/hooks/use-einstein'
2525

2626
// Constants
2727
import {

packages/pwa-kit-create-app/assets/bootstrap/js/overrides/app/routes.jsx.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import loadable from '@loadable/component'
1515
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
1616

1717
// Components
18-
import {Skeleton} from '{{preset.templateSource.id}}/app/components/shared/ui'
19-
import {configureRoutes} from '{{preset.templateSource.id}}/app/utils/routes-utils'
20-
import {routes as _routes} from '{{preset.templateSource.id}}/app/routes'
18+
import {Skeleton} from '{{template.source.name}}/app/components/shared/ui'
19+
import {configureRoutes} from '{{template.source.name}}/app/utils/routes-utils'
20+
import {routes as _routes} from '{{template.source.name}}/app/routes'
2121

2222
const fallback = <Skeleton height="75vh" width="100%" />
2323

packages/pwa-kit-create-app/assets/bootstrap/js/overrides/app/static/manifest.json.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "{{preset.id}}",
3-
"short_name": "{{preset.id}}",
2+
"name": "{{general.presetOrTemplateId}}",
3+
"short_name": "{{general.presetOrTemplateId}}",
44
"start_url": "/?homescreen=1",
55
"background_color": "#fff",
66
"theme_color": "#4e439b",

packages/pwa-kit-create-app/assets/bootstrap/js/package.json.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
"npm": "^9.0.0 || ^10.0.0 || ^11.0.0"
88
},
99
"ccExtensibility": {
10-
"extends": "{{preset.templateSource.id}}",
10+
"extends": "{{template.source.name}}",
1111
"overridesDir": "overrides"
1212
},
1313
"devDependencies": {
14-
"{{preset.templateSource.id}}": "{{answers.general.packageJSON.version}}"
14+
"{{template.source.name}}": "{{answers.general.packageJSON.version}}"
1515
},
1616
"scripts": {
1717
{{#each answers.general.packageJSON.scripts}}

packages/pwa-kit-create-app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
},
1818
"files": [
1919
"assets",
20-
"templates"
20+
"templates",
21+
"program.json"
2122
],
2223
"scripts": {
2324
"format": "internal-lib-build format \"**/*.{js,jsx}\"",

0 commit comments

Comments
 (0)