Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
8190025
Make API clients injectable to allow tree-shaking
shethj May 30, 2025
cbd8e1e
Update changelog
shethj May 30, 2025
7fa34b2
Implemented commerce API provider proxy
shethj Jun 4, 2025
437e164
Allow promise based response from the transformer
shethj Jun 4, 2025
5f99885
Restore comment
shethj Jun 4, 2025
6138000
Revert lint change
shethj Jun 4, 2025
faf0069
Revert template changes
shethj Jun 5, 2025
03fbbb6
Revert template changes
shethj Jun 5, 2025
1b80c10
Revert template changes
shethj Jun 5, 2025
bc286ca
@W-18598001 improve order history test coverage prior to bonus changes
sf-kyle-wright Jun 5, 2025
4cf092f
@W-18598001 improve order history test coverage prior to bonus changes
sf-kyle-wright Jun 5, 2025
b0b0e20
Extract injector types out of provider
shethj Jun 5, 2025
749baef
Merge branch 'develop' into feature/commerce-sdk-react-refactor-2
shethj Jun 5, 2025
b6fb54a
Fix linting and add test cases
shethj Jun 5, 2025
fff68c0
Trigger CI commit
shethj Jun 5, 2025
0ab0673
Trigger CI commit
shethj Jun 5, 2025
8c7507c
Restore isomorphic SDK
shethj Jun 5, 2025
a089dd3
@W-18598001 improve order history test coverage prior to bonus changes
sf-kyle-wright Jun 6, 2025
5d74541
Rename withParameterInjection to be more self-explanatory
shethj Jun 6, 2025
7e7aada
Merge branch 'develop' into feature/commerce-sdk-react-refactor-2
shethj Jun 6, 2025
76c6cbf
Fix linting
shethj Jun 6, 2025
f14a74f
Added a test to PDP page for checking translations
snilakandan13 Jun 6, 2025
6998343
skip changelog
snilakandan13 Jun 6, 2025
48fd4e9
Merge branch 'develop' into t/commerce/W-18669904/addingTestToPDP
snilakandan13 Jun 6, 2025
3698a4a
Merge branch 'develop' into feature/commerce-sdk-react-refactor-2
shethj Jun 6, 2025
ffc2bba
skip changelog
snilakandan13 Jun 6, 2025
02b1df7
Merge branch 't/commerce/W-18669904/addingTestToPDP' of https://githu…
snilakandan13 Jun 6, 2025
576792a
Update changelog to point to correct PR
shethj Jun 6, 2025
6303c85
Linting errors
snilakandan13 Jun 9, 2025
cf90405
Moved the test over to product-view page and added translations for b…
snilakandan13 Jun 9, 2025
623135c
Linting changes
snilakandan13 Jun 9, 2025
1118b54
Merge branch 'develop' into t/commerce/W-18669904/addingTestToPDP
snilakandan13 Jun 9, 2025
968f1bb
@W-18670270 update unit test
yhsieh1 Jun 9, 2025
4259a1b
skip changelog
yhsieh1 Jun 9, 2025
58ad8fe
remove un-needed assertion
yhsieh1 Jun 9, 2025
5ae2eb9
Merge branch 'develop' into t/cc-shark/W-18598001/improve-coverage-be…
sf-kyle-wright Jun 9, 2025
8c44ea7
Merge pull request #2538 from SalesforceCommerceCloud/t/commerce/W-18…
yhsieh1 Jun 9, 2025
429f1c7
Merge branch 'develop' into t/cc-shark/W-18598001/improve-coverage-be…
sf-kyle-wright Jun 9, 2025
5faf77f
Remove unneeded hyphen from code comment
sf-cboscenco Jun 9, 2025
ce206ba
skip changelog
sf-cboscenco Jun 9, 2025
dbc0599
Merge branch 'develop' into feature/commerce-sdk-react-refactor-2
shethj Jun 9, 2025
e641626
migrate store locator implementation
kevinxh Jun 9, 2025
d8b11d2
create index file
kevinxh Jun 9, 2025
5a13692
add constants
kevinxh Jun 9, 2025
19911a8
remove path from store locator config
kevinxh Jun 9, 2025
98cc724
fix default page size
kevinxh Jun 9, 2025
cdaf6f8
remove store-locator modal OLD implementation
kevinxh Jun 9, 2025
40bfaf6
fix intl
kevinxh Jun 9, 2025
70360b5
get search to work
kevinxh Jun 9, 2025
fe8a647
fix types
kevinxh Jun 9, 2025
c8e5e04
move constants
kevinxh Jun 9, 2025
2ea8bce
fix tests
kevinxh Jun 10, 2025
64201c5
add tsconfig.json and lint
kevinxh Jun 10, 2025
a78111a
lint
kevinxh Jun 10, 2025
98ff55c
commit translation changes
kevinxh Jun 10, 2025
c5b952c
add diagram
kevinxh Jun 10, 2025
3c0c073
Merge branch 'develop' into t/commerce/W-18669904/addingTestToPDP
snilakandan13 Jun 10, 2025
78f0a13
Add apiClients as dependency
shethj Jun 10, 2025
dc90298
Merge branch 'develop' into t/cc-shark/W-18698408
sf-cboscenco Jun 10, 2025
c70e878
Merge pull request #2521 from SalesforceCommerceCloud/t/cc-shark/W-18…
sf-kyle-wright Jun 10, 2025
4592f43
Merge branch 'develop' into t/cc-shark/W-18698408
sf-cboscenco Jun 10, 2025
98df05d
Review comments
snilakandan13 Jun 10, 2025
95af8a5
Remove passing children to transformSDKClient
shethj Jun 10, 2025
149df85
Merge branch 'develop' into feature/commerce-sdk-react-refactor-2
shethj Jun 10, 2025
f7d7c26
move use-store-locator to hooks folder
kevinxh Jun 10, 2025
b967e26
move use-geolocation to hooks folder
kevinxh Jun 10, 2025
9d7519e
move store locator contants
kevinxh Jun 10, 2025
9938051
remove unused file
kevinxh Jun 10, 2025
fa7949f
move store locator contexts
kevinxh Jun 10, 2025
c093cd2
Merge branch 'develop' into t/commerce/W-18669904/addingTestToPDP
snilakandan13 Jun 10, 2025
4914cd6
convert store locator from ts to js
kevinxh Jun 10, 2025
ba22f97
convert store locator from ts to js
kevinxh Jun 10, 2025
ae11cda
remove tsconfig.json
kevinxh Jun 10, 2025
f21487a
Merge pull request #2545 from SalesforceCommerceCloud/t/cc-shark/W-18…
sf-cboscenco Jun 10, 2025
11b2fa2
linting issue
snilakandan13 Jun 10, 2025
84a08c8
Merge branch 'develop' into t/commerce/W-18669904/addingTestToPDP
snilakandan13 Jun 10, 2025
d6f43b4
Merge branch 't/commerce/W-18669904/addingTestToPDP' of https://githu…
snilakandan13 Jun 10, 2025
83d7d8b
Merge pull request #2528 from SalesforceCommerceCloud/t/commerce/W-18…
snilakandan13 Jun 10, 2025
1f9e6dc
add proptypes / fix lint
kevinxh Jun 10, 2025
3bce726
fix lint
kevinxh Jun 10, 2025
c5bbc3e
Merge branch 'develop' into next-store-locator
kevinxh Jun 10, 2025
79af6fc
Merge pull request #2542 from SalesforceCommerceCloud/next-store-locator
kevinxh Jun 10, 2025
b6b5f11
Merge branch 'develop' into feature/commerce-sdk-react-refactor-2
shethj Jun 11, 2025
a019b24
Update existing translations with updated localization (#2552)
alexvuong Jun 11, 2025
06077d0
Revert Bonus Label Change
sf-deepali-bharmal Jun 11, 2025
9d95e11
Merge branch 'develop' into feature/commerce-sdk-react-refactor-2
shethj Jun 12, 2025
0ae61e0
Merge pull request #2519 from SalesforceCommerceCloud/feature/commerc…
shethj Jun 12, 2025
3b3d278
Merge branch 'develop' into t/1c-shark/W-18597966/revertBonusLabelChange
sf-deepali-bharmal Jun 12, 2025
970a334
Merge pull request #2554 from SalesforceCommerceCloud/t/1c-shark/W-18…
sf-deepali-bharmal Jun 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/commerce-sdk-react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## v3.4.0-dev.0 (May 23, 2025)
- Now compatible with either React 17 and 18 [#2506](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2506)

- Refactor commerce-sdk-react to allow injecting ApiClients [#2519](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2519)

## v3.3.0 (May 22, 2025)

- Fix inconsistency between dwsid and access token for guest login when hybrid authentication is enabled [#2397](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2397)
Expand Down
15 changes: 15 additions & 0 deletions packages/commerce-sdk-react/src/hooks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
ShopperStores
} from 'commerce-sdk-isomorphic'
import {helpers} from 'commerce-sdk-isomorphic'
import {CommerceApiProviderProps} from '../provider'

// --- GENERAL UTILITIES --- //

Expand Down Expand Up @@ -226,3 +227,17 @@ export type TMutationVariables = {
parameters?: {[key: string]: string | number | boolean | string[] | number[]}
headers?: {[key: string]: string}
} | void

export type SDKClientTransformer<T> = (
params: T,
methodName: string,
options: any
) => any | Promise<any>

export type ErrorCallback<TParams> = (methodName: string, error: any, params: TParams) => void

export interface SDKClientTransformConfig<TParams = Record<string, any>> {
props: Omit<CommerceApiProviderProps, 'children'>
transformer?: SDKClientTransformer<TParams>
onError?: ErrorCallback<TParams>
}
2 changes: 1 addition & 1 deletion packages/commerce-sdk-react/src/hooks/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {ConfigContext, CommerceApiProviderProps} from '../provider'
/**
* @Internal
*/
const useConfig = (): Omit<CommerceApiProviderProps, 'children'> => {
const useConfig = (): Omit<CommerceApiProviderProps, 'children' | 'apiClients'> => {
return React.useContext(ConfigContext)
}

Expand Down
108 changes: 75 additions & 33 deletions packages/commerce-sdk-react/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import React, {ReactElement, useEffect, useMemo} from 'react'
import Auth from './auth'
import {ApiClientConfigParams, ApiClients, SDKClientTransformer} from './hooks/types'
import {Logger} from './types'
import {
DWSID_COOKIE_NAME,
MOBIFY_PATH,
SERVER_AFFINITY_HEADER_KEY,
SLAS_PRIVATE_PROXY_PATH
} from './constant'
import {
ShopperBaskets,
ShopperContexts,
Expand All @@ -20,15 +29,8 @@ import {
ShopperBasketsTypes,
ShopperStores
} from 'commerce-sdk-isomorphic'
import Auth from './auth'
import {ApiClientConfigParams, ApiClients} from './hooks/types'
import {Logger} from './types'
import {
DWSID_COOKIE_NAME,
MOBIFY_PATH,
SERVER_AFFINITY_HEADER_KEY,
SLAS_PRIVATE_PROXY_PATH
} from './constant'
import {transformSDKClient} from './utils'

export interface CommerceApiProviderProps extends ApiClientConfigParams {
children: React.ReactNode
proxy: string
Expand All @@ -46,6 +48,7 @@ export interface CommerceApiProviderProps extends ApiClientConfigParams {
passwordlessLoginCallbackURI?: string
refreshTokenRegisteredCookieTTL?: number
refreshTokenGuestCookieTTL?: number
apiClients?: ApiClients
}

/**
Expand All @@ -56,7 +59,9 @@ export const CommerceApiContext = React.createContext({} as ApiClients)
/**
* @internal
*/
export const ConfigContext = React.createContext({} as Omit<CommerceApiProviderProps, 'children'>)
export const ConfigContext = React.createContext(
{} as Omit<CommerceApiProviderProps, 'children' | 'apiClients'>
)

/**
* @internal
Expand Down Expand Up @@ -126,7 +131,8 @@ const CommerceApiProvider = (props: CommerceApiProviderProps): ReactElement => {
defaultDnt,
passwordlessLoginCallbackURI,
refreshTokenRegisteredCookieTTL,
refreshTokenGuestCookieTTL
refreshTokenGuestCookieTTL,
apiClients
} = props

// Set the logger based on provided configuration, or default to the console object if no logger is provided
Expand Down Expand Up @@ -167,7 +173,8 @@ const CommerceApiProvider = (props: CommerceApiProviderProps): ReactElement => {
defaultDnt,
passwordlessLoginCallbackURI,
refreshTokenRegisteredCookieTTL,
refreshTokenGuestCookieTTL
refreshTokenGuestCookieTTL,
apiClients
])

const dwsid = auth.get(DWSID_COOKIE_NAME)
Expand All @@ -176,28 +183,62 @@ const CommerceApiProvider = (props: CommerceApiProviderProps): ReactElement => {
serverAffinityHeader[SERVER_AFFINITY_HEADER_KEY] = dwsid
}

const config = {
proxy,
headers: {
...headers,
...serverAffinityHeader
},
parameters: {
clientId,
organizationId,
shortCode,
siteId,
locale,
currency
},
throwOnBadResponse: true,
fetchOptions
const _defaultTransformer: SDKClientTransformer<Record<string, any>> = (_, _$, options) => {
return {
...options,
headers: {
...options.headers,
...serverAffinityHeader
},
throwOnBadResponse: true,
fetchOptions: {
...options.fetchOptions,
...fetchOptions
}
}
}

const baseUrl = config.proxy.split(MOBIFY_PATH)[0]
const privateClientEndpoint = `${baseUrl}${SLAS_PRIVATE_PROXY_PATH}`
const updatedClients: ApiClients = useMemo(() => {
if (apiClients) {
const clients: Record<string, any> = {}

// transformSDKClient is simply a utility function that wraps the SDK Client instance
// in a Proxy that allows us to transform the method arguments and modify headers, parameters, and other options.
// We don't really need to pass in the children prop to the transformer function, so we'll just pass in the rest of the props.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const {children, ...restProps} = props

Object.entries(apiClients ?? {}).forEach(([key, apiClient]) => {
clients[key] = transformSDKClient(apiClient, {
props: restProps,
transformer: _defaultTransformer
})
})

return clients as ApiClients
}

const config = {
proxy,
headers: {
...headers,
...serverAffinityHeader
},
parameters: {
clientId,
organizationId,
shortCode,
siteId,
locale,
currency
},
throwOnBadResponse: true,
fetchOptions
}

const baseUrl = config.proxy.split(MOBIFY_PATH)[0]
const privateClientEndpoint = `${baseUrl}${SLAS_PRIVATE_PROXY_PATH}`

const apiClients = useMemo(() => {
return {
shopperBaskets: new ShopperBaskets(config),
shopperContexts: new ShopperContexts(config),
Expand All @@ -224,7 +265,8 @@ const CommerceApiProvider = (props: CommerceApiProviderProps): ReactElement => {
fetchOptions,
locale,
currency,
headers?.['correlation-id']
headers?.['correlation-id'],
apiClients
])

// Initialize the session
Expand All @@ -251,7 +293,7 @@ const CommerceApiProvider = (props: CommerceApiProviderProps): ReactElement => {
refreshTokenGuestCookieTTL
}}
>
<CommerceApiContext.Provider value={apiClients}>
<CommerceApiContext.Provider value={updatedClients}>
<AuthContext.Provider value={auth}>{children}</AuthContext.Provider>
</CommerceApiContext.Provider>
</ConfigContext.Provider>
Expand Down
Loading
Loading