-
Notifications
You must be signed in to change notification settings - Fork 215
Expand file tree
/
Copy pathquery.ts
More file actions
560 lines (522 loc) · 33.8 KB
/
query.ts
File metadata and controls
560 lines (522 loc) · 33.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
/*
* 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
*/
/* eslint-disable @typescript-eslint/ban-ts-comment */
import {UseQueryResult} from '@tanstack/react-query'
import {ShopperCustomers} from 'commerce-sdk-isomorphic'
import {ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters} from '../types'
import useCommerceApi from '../useCommerceApi'
import {useQuery} from '../useQuery'
import {mergeOptions, omitNullableParameters, pickValidParams} from '../utils'
import * as queryKeyHelpers from './queryKeyHelpers'
type Client = ApiClients['shopperCustomers']
// TODO: Re-implement (and update description from RAML spec) when the endpoint exits closed beta.
// /**
// * Gets the new external profile for a customer.This endpoint is in closed beta, available to select few customers. Please get in touch with your Account Team if you'd like to participate in the beta program
// * @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 Customers `getExternalProfile` endpoint.
// * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-customers?meta=getExternalProfile| Salesforce Developer Center} for more information about the API endpoint.
// * @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercustomers.shoppercustomers-1.html#getexternalprofile | `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 useExternalProfile = (
// apiOptions: NullableParameters<Argument<Client['getExternalProfile']>>,
// queryOptions: ApiQueryOptions<Client['getExternalProfile']> = {}
// ): UseQueryResult<DataType<Client['getExternalProfile']>> => {
// type Options = Argument<Client['getExternalProfile']>
// type Data = DataType<Client['getExternalProfile']>
// const {shopperCustomers: client} = useCommerceApi()
// const methodName = 'getExternalProfile'
// const requiredParameters = ShopperCustomers.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 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)
// // 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, queryOptions, {
// method,
// queryKey,
// requiredParameters
// })
// }
/**
* Gets a customer's information.
*
* @group ShopperCustomers
* @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 Customers `getCustomer` endpoint.
* @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-customers?meta=getCustomer| Salesforce Developer Center} for more information about the API endpoint.
* @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercustomers.shoppercustomers-1.html#getcustomer | `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 useCustomer = (
apiOptions: NullableParameters<Argument<Client['getCustomer']>>,
queryOptions: ApiQueryOptions<Client['getCustomer']> = {}
): UseQueryResult<DataType<Client['getCustomer']>, Error> => {
type Options = Argument<Client['getCustomer']>
type Data = DataType<Client['getCustomer']>
const {shopperCustomers: client} = useCommerceApi()
const methodName = 'getCustomer'
const requiredParameters = ShopperCustomers.paramKeys[`${methodName}Required`]
const netOptions = omitNullableParameters(mergeOptions(client, apiOptions))
const parameters = pickValidParams(
netOptions.parameters,
ShopperCustomers.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: 'useCustomer',
...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.
// @ts-ignore TODO: Fix react query result error generics
return useQuery<Client, Options, Data>({...netOptions, parameters}, queryOptions, {
method,
queryKey,
requiredParameters
})
}
/**
* Retrieves a customer's address by address name.
* @group ShopperCustomers
* @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 Customers `getCustomerAddress` endpoint.
* @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-customers?meta=getCustomerAddress| Salesforce Developer Center} for more information about the API endpoint.
* @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercustomers.shoppercustomers-1.html#getcustomeraddress | `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 useCustomerAddress = (
apiOptions: NullableParameters<Argument<Client['getCustomerAddress']>>,
queryOptions: ApiQueryOptions<Client['getCustomerAddress']> = {}
): UseQueryResult<DataType<Client['getCustomerAddress']>, Error> => {
type Options = Argument<Client['getCustomerAddress']>
type Data = DataType<Client['getCustomerAddress']>
const {shopperCustomers: client} = useCommerceApi()
const methodName = 'getCustomerAddress'
const requiredParameters = ShopperCustomers.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,
ShopperCustomers.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: 'useCustomerAddress',
...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.
// @ts-ignore TODO: Fix react query result error generics
return useQuery<Client, Options, Data>({...netOptions, parameters}, queryOptions, {
method,
queryKey,
requiredParameters
})
}
/**
* Gets the baskets of a customer.
* @group ShopperCustomers
* @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 Customers `getCustomerBaskets` endpoint.
* @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-customers?meta=getCustomerBaskets| Salesforce Developer Center} for more information about the API endpoint.
* @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercustomers.shoppercustomers-1.html#getcustomerbaskets | `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 useCustomerBaskets = (
apiOptions: NullableParameters<Argument<Client['getCustomerBaskets']>>,
queryOptions: ApiQueryOptions<Client['getCustomerBaskets']> = {}
): UseQueryResult<DataType<Client['getCustomerBaskets']>, Error> => {
type Options = Argument<Client['getCustomerBaskets']>
type Data = DataType<Client['getCustomerBaskets']>
const {shopperCustomers: client} = useCommerceApi()
const methodName = 'getCustomerBaskets'
const requiredParameters = ShopperCustomers.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,
ShopperCustomers.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: 'useCustomerBaskets',
...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.
// @ts-ignore TODO: Fix react query result error generics
return useQuery<Client, Options, Data>({...netOptions, parameters}, queryOptions, {
method,
queryKey,
requiredParameters
})
}
/**
* Returns a pageable list of all customer's orders.
*
* The default page size is 10.
* @group ShopperCustomers
* @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 Customers `getCustomerOrders` endpoint.
* @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-customers?meta=getCustomerOrders| Salesforce Developer Center} for more information about the API endpoint.
* @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercustomers.shoppercustomers-1.html#getcustomerorders | `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 useCustomerOrders = (
apiOptions: NullableParameters<Argument<Client['getCustomerOrders']>>,
queryOptions: ApiQueryOptions<Client['getCustomerOrders']> = {}
): UseQueryResult<DataType<Client['getCustomerOrders']>, Error> => {
type Options = Argument<Client['getCustomerOrders']>
type Data = DataType<Client['getCustomerOrders']>
const {shopperCustomers: client} = useCommerceApi()
const methodName = 'getCustomerOrders'
const requiredParameters = ShopperCustomers.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,
ShopperCustomers.paramKeys[methodName]
)
const queryKey = queryKeyHelpers[methodName].queryKey(netOptions.parameters)
// We don't use `netOptions` here because we manipulate the option in `useQuery`.
const method = async (options: Options) => await client[methodName](options)
queryOptions.meta = {
displayName: 'useCustomerOrders',
...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.
// @ts-ignore TODO: Fix react query result error generics
return useQuery<Client, Options, Data>({...netOptions, parameters}, queryOptions, {
method,
queryKey,
requiredParameters
})
}
/**
* Retrieves a customer's payment instrument by its ID.
* @group ShopperCustomers
* @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 Customers `getCustomerPaymentInstrument` endpoint.
* @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-customers?meta=getCustomerPaymentInstrument| Salesforce Developer Center} for more information about the API endpoint.
* @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercustomers.shoppercustomers-1.html#getcustomerpaymentinstrument | `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 useCustomerPaymentInstrument = (
apiOptions: NullableParameters<Argument<Client['getCustomerPaymentInstrument']>>,
queryOptions: ApiQueryOptions<Client['getCustomerPaymentInstrument']> = {}
): UseQueryResult<DataType<Client['getCustomerPaymentInstrument']>, Error> => {
type Options = Argument<Client['getCustomerPaymentInstrument']>
type Data = DataType<Client['getCustomerPaymentInstrument']>
const {shopperCustomers: client} = useCommerceApi()
const methodName = 'getCustomerPaymentInstrument'
const requiredParameters = ShopperCustomers.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,
ShopperCustomers.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: 'useCustomerPaymentInstrument',
...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.
// @ts-ignore TODO: Fix react query result error generics
return useQuery<Client, Options, Data>({...netOptions, parameters}, queryOptions, {
method,
queryKey,
requiredParameters
})
}
/**
* Returns all customer product lists.
* @group ShopperCustomers
* @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 Customers `getCustomerProductLists` endpoint.
* @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-customers?meta=getCustomerProductLists| Salesforce Developer Center} for more information about the API endpoint.
* @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercustomers.shoppercustomers-1.html#getcustomerproductlists | `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 useCustomerProductLists = (
apiOptions: NullableParameters<Argument<Client['getCustomerProductLists']>>,
queryOptions: ApiQueryOptions<Client['getCustomerProductLists']> = {}
): UseQueryResult<DataType<Client['getCustomerProductLists']>, Error> => {
type Options = Argument<Client['getCustomerProductLists']>
type Data = DataType<Client['getCustomerProductLists']>
const {shopperCustomers: client} = useCommerceApi()
const methodName = 'getCustomerProductLists'
const requiredParameters = ShopperCustomers.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,
ShopperCustomers.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: 'useCustomerProductLists',
...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.
// @ts-ignore TODO: Fix react query result error generics
return useQuery<Client, Options, Data>({...netOptions, parameters}, queryOptions, {
method,
queryKey,
requiredParameters
})
}
/**
* Returns a customer product list of the given customer and the items in the list.
* @group ShopperCustomers
* @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 Customers `getCustomerProductList` endpoint.
* @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-customers?meta=getCustomerProductList| Salesforce Developer Center} for more information about the API endpoint.
* @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercustomers.shoppercustomers-1.html#getcustomerproductlist | `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 useCustomerProductList = (
apiOptions: NullableParameters<Argument<Client['getCustomerProductList']>>,
queryOptions: ApiQueryOptions<Client['getCustomerProductList']> = {}
): UseQueryResult<DataType<Client['getCustomerProductList']>, Error> => {
type Options = Argument<Client['getCustomerProductList']>
type Data = DataType<Client['getCustomerProductList']>
const {shopperCustomers: client} = useCommerceApi()
const methodName = 'getCustomerProductList'
const requiredParameters = ShopperCustomers.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,
ShopperCustomers.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: 'useCustomerProductList',
...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.
// @ts-ignore TODO: Fix react query result error generics
return useQuery<Client, Options, Data>({...netOptions, parameters}, queryOptions, {
method,
queryKey,
requiredParameters
})
}
/**
* Returns an item of a customer product list and the actual product details like image, availability and price.
* @group ShopperCustomers
* @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 Customers `getCustomerProductListItem` endpoint.
* @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-customers?meta=getCustomerProductListItem| Salesforce Developer Center} for more information about the API endpoint.
* @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercustomers.shoppercustomers-1.html#getcustomerproductlistitem | `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 useCustomerProductListItem = (
apiOptions: NullableParameters<Argument<Client['getCustomerProductListItem']>>,
queryOptions: ApiQueryOptions<Client['getCustomerProductListItem']> = {}
): UseQueryResult<DataType<Client['getCustomerProductListItem']>, Error> => {
type Options = Argument<Client['getCustomerProductListItem']>
type Data = DataType<Client['getCustomerProductListItem']>
const {shopperCustomers: client} = useCommerceApi()
const methodName = 'getCustomerProductListItem'
const requiredParameters = ShopperCustomers.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,
ShopperCustomers.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: 'useCustomerProductListItem',
...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.
// @ts-ignore TODO: Fix react query result error generics
return useQuery<Client, Options, Data>({...netOptions, parameters}, queryOptions, {
method,
queryKey,
requiredParameters
})
}
/**
* Retrieves all public product lists as defined by the given search term (for example, email OR first name and last name).
* @group ShopperCustomers
* @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 Customers `getPublicProductListsBySearchTerm` endpoint.
* @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-customers?meta=getPublicProductListsBySearchTerm| Salesforce Developer Center} for more information about the API endpoint.
* @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercustomers.shoppercustomers-1.html#getpublicproductlistsbysearchterm | `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 usePublicProductListsBySearchTerm = (
apiOptions: NullableParameters<Argument<Client['getPublicProductListsBySearchTerm']>>,
queryOptions: ApiQueryOptions<Client['getPublicProductListsBySearchTerm']> = {}
): UseQueryResult<DataType<Client['getPublicProductListsBySearchTerm']>, Error> => {
type Options = Argument<Client['getPublicProductListsBySearchTerm']>
type Data = DataType<Client['getPublicProductListsBySearchTerm']>
const {shopperCustomers: client} = useCommerceApi()
const methodName = 'getPublicProductListsBySearchTerm'
const requiredParameters = ShopperCustomers.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,
ShopperCustomers.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: 'usePublicProductListsBySearchTerm',
...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.
// @ts-ignore TODO: Fix react query result error generics
return useQuery<Client, Options, Data>({...netOptions, parameters}, queryOptions, {
method,
queryKey,
requiredParameters
})
}
/**
* Retrieves a public product list by ID and the items under that product list.
* @group ShopperCustomers
* @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 Customers `getPublicProductList` endpoint.
* @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-customers?meta=getPublicProductList| Salesforce Developer Center} for more information about the API endpoint.
* @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercustomers.shoppercustomers-1.html#getpublicproductlist | `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 usePublicProductList = (
apiOptions: NullableParameters<Argument<Client['getPublicProductList']>>,
queryOptions: ApiQueryOptions<Client['getPublicProductList']> = {}
): UseQueryResult<DataType<Client['getPublicProductList']>, Error> => {
type Options = Argument<Client['getPublicProductList']>
type Data = DataType<Client['getPublicProductList']>
const {shopperCustomers: client} = useCommerceApi()
const methodName = 'getPublicProductList'
const requiredParameters = ShopperCustomers.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,
ShopperCustomers.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: 'usePublicProductList',
...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.
// @ts-ignore TODO: Fix react query result error generics
return useQuery<Client, Options, Data>({...netOptions, parameters}, queryOptions, {
method,
queryKey,
requiredParameters
})
}
/**
* Retrieves an item from a public product list and the actual product details like product, image, availability and price.
* @group ShopperCustomers
* @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 Customers `getProductListItem` endpoint.
* @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-customers?meta=getProductListItem| Salesforce Developer Center} for more information about the API endpoint.
* @see {@link https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/classes/shoppercustomers.shoppercustomers-1.html#getproductlistitem | `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 useProductListItem = (
apiOptions: NullableParameters<Argument<Client['getProductListItem']>>,
queryOptions: ApiQueryOptions<Client['getProductListItem']> = {}
): UseQueryResult<DataType<Client['getProductListItem']>, Error> => {
type Options = Argument<Client['getProductListItem']>
type Data = DataType<Client['getProductListItem']>
const {shopperCustomers: client} = useCommerceApi()
const methodName = 'getProductListItem'
const requiredParameters = ShopperCustomers.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,
ShopperCustomers.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: 'useProductListItem',
...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.
// @ts-ignore TODO: Fix react query result error generics
return useQuery<Client, Options, Data>({...netOptions, parameters}, queryOptions, {
method,
queryKey,
requiredParameters
})
}