Skip to content

Commit 92fb28d

Browse files
authored
W-21281890: Address v1 vs v2 integration into PWA (#3687)
* W-21281890 Address v1 vs v2 integration into PWA
1 parent 6135794 commit 92fb28d

File tree

71 files changed

+1824
-119
lines changed

Some content is hidden

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

71 files changed

+1824
-119
lines changed

packages/commerce-sdk-react/src/constant.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const SERVER_AFFINITY_HEADER_KEY = 'sfdc_dwsid'
4646

4747
export const CLIENT_KEYS = {
4848
SHOPPER_BASKETS: 'shopperBaskets',
49+
SHOPPER_BASKETS_V2: 'shopperBasketsV2',
4950
SHOPPER_CONFIGURATIONS: 'shopperConfigurations',
5051
SHOPPER_CONTEXTS: 'shopperContexts',
5152
SHOPPER_CUSTOMERS: 'shopperCustomers',

packages/commerce-sdk-react/src/hooks/ShopperBaskets/cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77
import {
8-
ShopperBasketsV2Types,
8+
ShopperBasketsTypes,
99
ShopperCustomers,
1010
ShopperCustomersTypes
1111
} from 'commerce-sdk-isomorphic'
@@ -30,7 +30,7 @@ import {CLIENT_KEYS} from '../../constant'
3030
const CLIENT_KEY = CLIENT_KEYS.SHOPPER_BASKETS
3131
type Client = NonNullable<ApiClients[typeof CLIENT_KEY]>
3232
/** Data returned by every Shopper Baskets endpoint (except `deleteBasket`) */
33-
type Basket = ShopperBasketsV2Types.Basket
33+
type Basket = ShopperBasketsTypes.Basket
3434
/** Data returned by `getCustomerBaskets` */
3535
type CustomerBasketsResult = ShopperCustomersTypes.BasketsResult
3636
/** Parameters that get passed around, includes client config and possible parameters from other endpoints */

packages/commerce-sdk-react/src/hooks/ShopperBaskets/helpers.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {useShopperBasketsMutationHelper} from './helpers'
99
import {useCustomerBaskets} from '../ShopperCustomers'
1010
import {renderWithProviders} from '../../test-utils'
1111
import {screen, waitFor} from '@testing-library/react'
12-
import {ShopperBasketsV2Types} from 'commerce-sdk-isomorphic'
12+
import {ShopperBasketsTypes} from 'commerce-sdk-isomorphic'
1313
import jwt from 'jsonwebtoken'
1414

1515
const basketId = '10cf6aa40edba4fcfcc6915594'
@@ -52,7 +52,7 @@ const MockComponent = () => {
5252
price: 100,
5353
quantity: 1
5454
}
55-
] as ShopperBasketsV2Types.ProductItem[] & Record<`c_${string}`, any>)
55+
] as ShopperBasketsTypes.ProductItem[] & Record<`c_${string}`, any>)
5656
.catch((e) => console.log('e', e))
5757
}}
5858
>

packages/commerce-sdk-react/src/hooks/ShopperBaskets/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
import {useCustomerId, useShopperBasketsMutation} from '../index'
99
import {useCustomerBaskets} from '../ShopperCustomers'
1010
import {ApiClients, Argument} from '../types'
11-
import {ShopperBasketsV2Types} from 'commerce-sdk-isomorphic'
11+
import {ShopperBasketsTypes} from 'commerce-sdk-isomorphic'
1212
import {CLIENT_KEYS} from '../../constant'
1313

1414
const CLIENT_KEY = CLIENT_KEYS.SHOPPER_BASKETS
1515
type Client = NonNullable<ApiClients[typeof CLIENT_KEY]>
16-
type Basket = ShopperBasketsV2Types.Basket
16+
type Basket = ShopperBasketsTypes.Basket
1717

1818
/**
1919
* This is a helper function for Basket Mutations.

packages/commerce-sdk-react/src/hooks/ShopperBaskets/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: BSD-3-Clause
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
import {ShopperBasketsV2} from 'commerce-sdk-isomorphic'
7+
import {ShopperBaskets} from 'commerce-sdk-isomorphic'
88
import {getUnimplementedEndpoints} from '../../test-utils'
99
import {cacheUpdateMatrix} from './cache'
1010
import {ShopperBasketsMutations as mutations} from './mutation'
@@ -13,7 +13,7 @@ import * as queries from './query'
1313
describe('Shopper Baskets hooks', () => {
1414
test('all endpoints have hooks', () => {
1515
// unimplemented = SDK method exists, but no query hook or value in mutations enum
16-
const unimplemented = getUnimplementedEndpoints(ShopperBasketsV2, queries, mutations)
16+
const unimplemented = getUnimplementedEndpoints(ShopperBaskets, queries, mutations)
1717
// If this test fails: create a new query hook, add the endpoint to the mutations enum,
1818
// or add it to the `expected` array with a comment explaining "TODO" or "never" (and why).
1919
expect(unimplemented).toEqual([

packages/commerce-sdk-react/src/hooks/ShopperBaskets/mutation.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77
import {act} from '@testing-library/react'
8-
import {ShopperBasketsV2Types, ShopperCustomersTypes} from 'commerce-sdk-isomorphic'
8+
import {ShopperBasketsTypes, ShopperCustomersTypes} from 'commerce-sdk-isomorphic'
99
import nock from 'nock'
1010
import {
1111
assertInvalidateQuery,
@@ -32,9 +32,9 @@ jest.mock('../../auth/index.ts', () => {
3232

3333
const CLIENT_KEY = CLIENT_KEYS.SHOPPER_BASKETS
3434
type Client = NonNullable<ApiClients[typeof CLIENT_KEY]>
35-
type Basket = ShopperBasketsV2Types.Basket
35+
type Basket = ShopperBasketsTypes.Basket
3636
type BasketsResult = ShopperCustomersTypes.BasketsResult
37-
type ProductItem = ShopperBasketsV2Types.ProductItem
37+
type ProductItem = ShopperBasketsTypes.ProductItem
3838

3939
/** Create an options object for Shopper Baskets endpoints, with `basketId` pre-filled. */
4040
const createOptions = <Method extends Exclude<keyof Client, 'clientConfig'>>(

packages/commerce-sdk-react/src/hooks/ShopperBaskets/query.ts

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters} fro
99
import {useQuery} from '../useQuery'
1010
import {mergeOptions, omitNullableParameters, pickValidParams} from '../utils'
1111
import * as queryKeyHelpers from './queryKeyHelpers'
12-
import {ShopperBasketsV2} from 'commerce-sdk-isomorphic'
12+
import {ShopperBaskets} from 'commerce-sdk-isomorphic'
1313
import {CLIENT_KEYS} from '../../constant'
1414
import useCommerceApi from '../useCommerceApi'
1515

@@ -35,15 +35,12 @@ export const useBasket = (
3535
type Data = DataType<Client['getBasket']>
3636
const client = useCommerceApi(CLIENT_KEY)
3737
const methodName = 'getBasket'
38-
const requiredParameters = ShopperBasketsV2.paramKeys[`${methodName}Required`]
38+
const requiredParameters = ShopperBaskets.paramKeys[`${methodName}Required`]
3939

4040
// Parameters can be set in `apiOptions` or `client.clientConfig`;
4141
// we must merge them in order to generate the correct query key.
4242
const netOptions = omitNullableParameters(mergeOptions(client, apiOptions))
43-
const parameters = pickValidParams(
44-
netOptions.parameters,
45-
ShopperBasketsV2.paramKeys[methodName]
46-
)
43+
const parameters = pickValidParams(netOptions.parameters, ShopperBaskets.paramKeys[methodName])
4744
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters)
4845
// We don't use `netOptions` here because we manipulate the options in `useQuery`.
4946
const method = async (options: Options) => await client[methodName](options)
@@ -80,15 +77,12 @@ export const usePaymentMethodsForBasket = (
8077
type Data = DataType<Client['getPaymentMethodsForBasket']>
8178
const client = useCommerceApi(CLIENT_KEY)
8279
const methodName = 'getPaymentMethodsForBasket'
83-
const requiredParameters = ShopperBasketsV2.paramKeys[`${methodName}Required`]
80+
const requiredParameters = ShopperBaskets.paramKeys[`${methodName}Required`]
8481

8582
// Parameters can be set in `apiOptions` or `client.clientConfig`;
8683
// we must merge them in order to generate the correct query key.
8784
const netOptions = omitNullableParameters(mergeOptions(client, apiOptions))
88-
const parameters = pickValidParams(
89-
netOptions.parameters,
90-
ShopperBasketsV2.paramKeys[methodName]
91-
)
85+
const parameters = pickValidParams(netOptions.parameters, ShopperBaskets.paramKeys[methodName])
9286
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters)
9387
// We don't use `netOptions` here because we manipulate the options in `useQuery`.
9488
const method = async (options: Options) => await client[methodName](options)
@@ -125,15 +119,12 @@ export const usePriceBooksForBasket = (
125119
type Data = DataType<Client['getPriceBooksForBasket']>
126120
const client = useCommerceApi(CLIENT_KEY)
127121
const methodName = 'getPriceBooksForBasket'
128-
const requiredParameters = ShopperBasketsV2.paramKeys[`${methodName}Required`]
122+
const requiredParameters = ShopperBaskets.paramKeys[`${methodName}Required`]
129123

130124
// Parameters can be set in `apiOptions` or `client.clientConfig`;
131125
// we must merge them in order to generate the correct query key.
132126
const netOptions = omitNullableParameters(mergeOptions(client, apiOptions))
133-
const parameters = pickValidParams(
134-
netOptions.parameters,
135-
ShopperBasketsV2.paramKeys[methodName]
136-
)
127+
const parameters = pickValidParams(netOptions.parameters, ShopperBaskets.paramKeys[methodName])
137128
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters)
138129
// We don't use `netOptions` here because we manipulate the options in `useQuery`.
139130
const method = async (options: Options) => await client[methodName](options)
@@ -170,15 +161,12 @@ export const useShippingMethodsForShipment = (
170161
type Data = DataType<Client['getShippingMethodsForShipment']>
171162
const client = useCommerceApi(CLIENT_KEY)
172163
const methodName = 'getShippingMethodsForShipment'
173-
const requiredParameters = ShopperBasketsV2.paramKeys[`${methodName}Required`]
164+
const requiredParameters = ShopperBaskets.paramKeys[`${methodName}Required`]
174165

175166
// Parameters can be set in `apiOptions` or `client.clientConfig`;
176167
// we must merge them in order to generate the correct query key.
177168
const netOptions = omitNullableParameters(mergeOptions(client, apiOptions))
178-
const parameters = pickValidParams(
179-
netOptions.parameters,
180-
ShopperBasketsV2.paramKeys[methodName]
181-
)
169+
const parameters = pickValidParams(netOptions.parameters, ShopperBaskets.paramKeys[methodName])
182170
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters)
183171
// We don't use `netOptions` here because we manipulate the options in `useQuery`.
184172
const method = async (options: Options) => await client[methodName](options)
@@ -215,15 +203,12 @@ export const useTaxesFromBasket = (
215203
type Data = DataType<Client['getTaxesFromBasket']>
216204
const client = useCommerceApi(CLIENT_KEY)
217205
const methodName = 'getTaxesFromBasket'
218-
const requiredParameters = ShopperBasketsV2.paramKeys[`${methodName}Required`]
206+
const requiredParameters = ShopperBaskets.paramKeys[`${methodName}Required`]
219207

220208
// Parameters can be set in `apiOptions` or `client.clientConfig`;
221209
// we must merge them in order to generate the correct query key.
222210
const netOptions = omitNullableParameters(mergeOptions(client, apiOptions))
223-
const parameters = pickValidParams(
224-
netOptions.parameters,
225-
ShopperBasketsV2.paramKeys[methodName]
226-
)
211+
const parameters = pickValidParams(netOptions.parameters, ShopperBaskets.paramKeys[methodName])
227212
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters)
228213
// We don't use `netOptions` here because we manipulate the options in `useQuery`.
229214
const method = async (options: Options) => await client[methodName](options)

packages/commerce-sdk-react/src/hooks/ShopperBaskets/queryKeyHelpers.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
* SPDX-License-Identifier: BSD-3-Clause
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
import {ShopperBasketsV2} from 'commerce-sdk-isomorphic'
7+
import {ShopperBaskets} from 'commerce-sdk-isomorphic'
88
import {Argument, ExcludeTail} from '../types'
99
import {pickValidParams} from '../utils'
1010

1111
// We must use a client with no parameters in order to have required/optional match the API spec
12-
type Client = ShopperBasketsV2<{shortCode: string}>
12+
type Client = ShopperBaskets<{shortCode: string}>
1313
type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>
1414
export type QueryKeys = {
1515
getBasket: [
@@ -80,7 +80,7 @@ export const getBasket: QueryKeyHelper<'getBasket'> = {
8080
queryKey: (params: Params<'getBasket'>) => {
8181
return [
8282
...getBasket.path(params),
83-
pickValidParams(params || {}, ShopperBasketsV2.paramKeys.getBasket)
83+
pickValidParams(params || {}, ShopperBaskets.paramKeys.getBasket)
8484
]
8585
}
8686
}
@@ -97,7 +97,7 @@ export const getPaymentMethodsForBasket: QueryKeyHelper<'getPaymentMethodsForBas
9797
queryKey: (params: Params<'getPaymentMethodsForBasket'>) => {
9898
return [
9999
...getPaymentMethodsForBasket.path(params),
100-
pickValidParams(params || {}, ShopperBasketsV2.paramKeys.getPaymentMethodsForBasket)
100+
pickValidParams(params || {}, ShopperBaskets.paramKeys.getPaymentMethodsForBasket)
101101
]
102102
}
103103
}
@@ -114,7 +114,7 @@ export const getPriceBooksForBasket: QueryKeyHelper<'getPriceBooksForBasket'> =
114114
queryKey: (params: Params<'getPriceBooksForBasket'>) => {
115115
return [
116116
...getPriceBooksForBasket.path(params),
117-
pickValidParams(params || {}, ShopperBasketsV2.paramKeys.getPriceBooksForBasket)
117+
pickValidParams(params || {}, ShopperBaskets.paramKeys.getPriceBooksForBasket)
118118
]
119119
}
120120
}
@@ -133,7 +133,7 @@ export const getShippingMethodsForShipment: QueryKeyHelper<'getShippingMethodsFo
133133
queryKey: (params: Params<'getShippingMethodsForShipment'>) => {
134134
return [
135135
...getShippingMethodsForShipment.path(params),
136-
pickValidParams(params || {}, ShopperBasketsV2.paramKeys.getShippingMethodsForShipment)
136+
pickValidParams(params || {}, ShopperBaskets.paramKeys.getShippingMethodsForShipment)
137137
]
138138
}
139139
}
@@ -150,7 +150,7 @@ export const getTaxesFromBasket: QueryKeyHelper<'getTaxesFromBasket'> = {
150150
queryKey: (params: Params<'getTaxesFromBasket'>) => {
151151
return [
152152
...getTaxesFromBasket.path(params),
153-
pickValidParams(params || {}, ShopperBasketsV2.paramKeys.getTaxesFromBasket)
153+
pickValidParams(params || {}, ShopperBaskets.paramKeys.getTaxesFromBasket)
154154
]
155155
}
156156
}

0 commit comments

Comments
 (0)