Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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,5 +1,7 @@
## v4.3.0-dev (Nov 05, 2025)

- Upgrade to commerce-sdk-isomorphic v4.2.0 and introduce Shopper Configurations SCAPI integration [#3071](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3071)

## v4.2.0 (Nov 04, 2025)

- Upgrade to commerce-sdk-isomorphic v4.0.1 [#3449](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3449)
Expand Down
9 changes: 4 additions & 5 deletions packages/commerce-sdk-react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/commerce-sdk-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"version": "node ./scripts/version.js"
},
"dependencies": {
"commerce-sdk-isomorphic": "^4.0.1",
"commerce-sdk-isomorphic": "4.2.0",
"js-cookie": "^3.0.1",
"jwt-decode": "^4.0.0"
},
Expand Down
8 changes: 8 additions & 0 deletions packages/commerce-sdk-react/src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ const DATA_MAP: AuthDataMap = {
storageType: 'local',
key: 'idp_access_token'
},
idp_refresh_token: {
storageType: 'local',
key: 'idp_refresh_token'
},
dnt: {
storageType: 'local',
key: 'dnt'
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for the changes to auth.index.ts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sf-mkosak mentioned that this was needed with the new SCAPI changes in updating to the latest commerce-sdk-isomorphic version

token_type: {
storageType: 'local',
key: 'token_type'
Expand Down
3 changes: 2 additions & 1 deletion packages/commerce-sdk-react/src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ export const CLIENT_KEYS = {
SHOPPER_PROMOTIONS: 'shopperPromotions',
SHOPPER_SEARCH: 'shopperSearch',
SHOPPER_SEO: 'shopperSeo',
SHOPPER_STORES: 'shopperStores'
SHOPPER_STORES: 'shopperStores',
SHOPPER_CONFIGURATIONS: 'shopperConfigurations'
} as const
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2023, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import {CLIENT_KEYS} from '../../constant'
import {ApiClients, CacheUpdateMatrix} from '../types'

const CLIENT_KEY = CLIENT_KEYS.SHOPPER_CONFIGURATIONS
type Client = NonNullable<ApiClients[typeof CLIENT_KEY]>

// ShopperConfigurations API is primarily for reading configuration data
// No mutations are currently supported
export const cacheUpdateMatrix: CacheUpdateMatrix<Client> = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2023, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import {useConfigurations} from './query'

describe('ShopperConfigurations', () => {
describe('useConfigurations', () => {
it('should be defined', () => {
expect(useConfigurations).toBeDefined()
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright (c) 2023, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
export * from './query'
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2023, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import nock from 'nock'
import {
mockQueryEndpoint,
renderHookWithProviders,
waitAndExpectError,
waitAndExpectSuccess,
createQueryClient
} from '../../test-utils'

import {Argument} from '../types'
import * as queries from './query'

jest.mock('../../auth/index.ts', () => {
const {default: mockAuth} = jest.requireActual('../../auth/index.ts')
mockAuth.prototype.ready = jest.fn().mockResolvedValue({access_token: 'access_token'})
return mockAuth
})

type Queries = typeof queries
const configurationsEndpoint = '/organizations/'
// Not all endpoints use all parameters, but unused parameters are safely discarded
const OPTIONS: Argument<Queries[keyof Queries]> = {
parameters: {organizationId: 'f_ecom_zzrmy_orgf_001'}
}

// Mock data for configurations
const mockConfigurationsData = {
configurations: [
{
id: 'gcp',
value: 'test-gcp-api-key'
},
{
id: 'einstein',
value: 'test-einstein-api-key'
}
]
}

describe('Shopper Configurations query hooks', () => {
beforeEach(() => nock.cleanAll())
afterEach(() => {
expect(nock.pendingMocks()).toHaveLength(0)
})

test('`useConfigurations` has meta.displayName defined', async () => {
mockQueryEndpoint(configurationsEndpoint, mockConfigurationsData)
const queryClient = createQueryClient()
const {result} = renderHookWithProviders(
() => {
return queries.useConfigurations(OPTIONS)
},
{queryClient}
)
await waitAndExpectSuccess(() => result.current)
expect(queryClient.getQueryCache().getAll()[0].meta?.displayName).toBe('useConfigurations')
})

test('`useConfigurations` returns data on success', async () => {
mockQueryEndpoint(configurationsEndpoint, mockConfigurationsData)
const {result} = renderHookWithProviders(() => {
return queries.useConfigurations(OPTIONS)
})
await waitAndExpectSuccess(() => result.current)
expect(result.current.data).toEqual(mockConfigurationsData)
})

test('`useConfigurations` returns error on error', async () => {
mockQueryEndpoint(configurationsEndpoint, {}, 400)
const {result} = renderHookWithProviders(() => {
return queries.useConfigurations(OPTIONS)
})
await waitAndExpectError(() => result.current)
})

test('`useConfigurations` handles 500 server error', async () => {
mockQueryEndpoint(configurationsEndpoint, {}, 500)
const {result} = renderHookWithProviders(() => {
return queries.useConfigurations(OPTIONS)
})
await waitAndExpectError(() => result.current)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2023, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import {UseQueryResult} from '@tanstack/react-query'
import {ShopperConfigurations} from 'commerce-sdk-isomorphic'
import {ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters} from '../types'
import {useQuery} from '../useQuery'
import {mergeOptions, omitNullableParameters, pickValidParams} from '../utils'
import * as queryKeyHelpers from './queryKeyHelpers'
import {CLIENT_KEYS} from '../../constant'
import useCommerceApi from '../useCommerceApi'

const CLIENT_KEY = CLIENT_KEYS.SHOPPER_CONFIGURATIONS
type Client = NonNullable<ApiClients[typeof CLIENT_KEY]>

/**
* Gets configuration information that encompasses toggles, preferences, and configuration that allow the application to be reactive to changes performed by the merchant, admin, or support engineer.
*
* @group ShopperConfigurations
* @category Query
* @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
* @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
* @returns A TanStack Query query hook with data from the Shopper Configurations `getConfigurations` endpoint.
* @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-configurations?meta=getConfigurations| Salesforce Developer Center} for more information about the API endpoint.
* @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shopperconfigurations.shopperconfigurations-1.html#getconfigurations | `commerce-sdk-isomorphic` documentation} for more information on the parameters and returned data type.
* @see {@link https://tanstack.com/query/latest/docs/react/reference/useQuery | TanStack Query `useQuery` reference} for more information about the return value.
*/
export const useConfigurations = (
apiOptions: NullableParameters<Argument<Client['getConfigurations']>>,
queryOptions: ApiQueryOptions<Client['getConfigurations']> = {}
): UseQueryResult<DataType<Client['getConfigurations']>> => {
type Options = Argument<Client['getConfigurations']>
type Data = DataType<Client['getConfigurations']>
const client = useCommerceApi(CLIENT_KEY)
const methodName = 'getConfigurations'
const requiredParameters = ShopperConfigurations.paramKeys[`${methodName}Required`]

// Parameters can be set in `apiOptions` or `client.clientConfig`
// we must merge them in order to generate the correct query key.
const netOptions = omitNullableParameters(mergeOptions(client, apiOptions || {}))
const parameters = pickValidParams(
netOptions.parameters,
ShopperConfigurations.paramKeys[methodName]
)
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters)
// We don't use `netOptions` here because we manipulate the options in `useQuery`.
const method = async (options: Options) => await client[methodName](options)

queryOptions.meta = {
displayName: 'useConfigurations',
...queryOptions.meta
}

// For some reason, if we don't explicitly set these generic parameters, the inferred type for
// `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why.
return useQuery<Client, Options, Data>({...netOptions, parameters}, queryOptions, {
method,
queryKey,
requiredParameters
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2023, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import {ShopperConfigurations} from 'commerce-sdk-isomorphic'
import {Argument, ExcludeTail} from '../types'
import {pickValidParams} from '../utils'

// We must use a client with no parameters in order to have required/optional match the API spec
type Client = ShopperConfigurations<{shortCode: string}>
type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>
export type QueryKeys = {
getConfigurations: [
'/commerce-sdk-react',
'/organizations/',
string | undefined,
'/configurations',
Params<'getConfigurations'>
]
}

// This is defined here, rather than `types.ts`, because it relies on `Client` and `QueryKeys`,
// and making those generic would add too much complexity.
type QueryKeyHelper<T extends keyof QueryKeys> = {
/** Generates the path component of the query key for an endpoint. */
path: (params: Params<T>) => ExcludeTail<QueryKeys[T]>
/** Generates the full query key for an endpoint. */
queryKey: (params: Params<T>) => QueryKeys[T]
}

export const getConfigurations: QueryKeyHelper<'getConfigurations'> = {
path: (params) => [
'/commerce-sdk-react',
'/organizations/',
params?.organizationId,
'/configurations'
],
queryKey: (params: Params<'getConfigurations'>) => {
return [
...getConfigurations.path(params),
pickValidParams(params || {}, ShopperConfigurations.paramKeys.getConfigurations)
]
}
}
1 change: 1 addition & 0 deletions packages/commerce-sdk-react/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export * from './ShopperSearch'
export * from './ShopperStores'
export * from './ShopperSEO'
export * from './useAuthHelper'
export * from './ShopperConfigurations'
export {default as useAccessToken} from './useAccessToken'
export {default as useCommerceApi} from './useCommerceApi'
export {default as useEncUserId} from './useEncUserId'
Expand Down
2 changes: 2 additions & 0 deletions packages/commerce-sdk-react/src/hooks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import {InvalidateQueryFilters, QueryFilters, Updater, UseQueryOptions} from '@tanstack/react-query'
import {
ShopperBaskets,
ShopperConfigurations,
ShopperContexts,
ShopperCustomers,
ShopperExperience,
Expand Down Expand Up @@ -96,6 +97,7 @@ export interface ApiClients {
shopperSearch?: ShopperSearch<ApiClientConfigParams>
shopperSeo?: ShopperSEO<ApiClientConfigParams>
shopperStores?: ShopperStores<ApiClientConfigParams>
shopperConfigurations?: ShopperConfigurations<ApiClientConfigParams>
}

export type ApiClient = NonNullable<ApiClients[keyof ApiClients]>
Expand Down
2 changes: 2 additions & 0 deletions packages/commerce-sdk-react/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {DWSID_COOKIE_NAME, SERVER_AFFINITY_HEADER_KEY} from './constant'
import {
ShopperBaskets,
ShopperContexts,
ShopperConfigurations,
ShopperCustomers,
ShopperExperience,
ShopperGiftCertificates,
Expand Down Expand Up @@ -257,6 +258,7 @@ const CommerceApiProvider = (props: CommerceApiProviderProps): ReactElement => {
return {
shopperBaskets: new ShopperBaskets(config),
shopperContexts: new ShopperContexts(config),
shopperConfigurations: new ShopperConfigurations(config),
shopperCustomers: new ShopperCustomers(config),
shopperExperience: new ShopperExperience(config),
shopperGiftCertificates: new ShopperGiftCertificates(config),
Expand Down
1 change: 1 addition & 0 deletions packages/template-retail-react-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## v8.3.0-dev (Nov 05, 2025)
- [Bugfix] Fix Forgot Password link not working from Account Profile password update form [#3493](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3493)
- Introduce Address Autocompletion feature in the checkout flow, powered by Google Maps Platform [#3071](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3071)

## v8.2.0 (Nov 04, 2025)
- Add support for Rule Based Promotions for Choice of Bonus Products. We are currently supporting only one product level rule based promotion per product [#3418](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3418)
Expand Down
Loading
Loading