@outseta/react 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/generated/activity/activity.ts +395 -0
- package/src/generated/billing/billing.ts +1333 -0
- package/src/generated/crm/crm.ts +1528 -63
- package/src/generated/email/email.ts +992 -0
- package/src/generated/outsetaAPI.schemas.ts +334 -27
- package/src/generated/support/support.ts +478 -1
- package/src/mutator.ts +32 -11
|
@@ -220,18 +220,28 @@ For help regarding the Outseta API please email [support@outseta.com](mailto:sup
|
|
|
220
220
|
* OpenAPI spec version: v1
|
|
221
221
|
*/
|
|
222
222
|
import {
|
|
223
|
+
useMutation,
|
|
223
224
|
useQuery
|
|
224
225
|
} from '@tanstack/react-query';
|
|
225
226
|
import type {
|
|
227
|
+
MutationFunction,
|
|
226
228
|
QueryFunction,
|
|
227
229
|
QueryKey,
|
|
230
|
+
UseMutationOptions,
|
|
231
|
+
UseMutationResult,
|
|
228
232
|
UseQueryOptions,
|
|
229
233
|
UseQueryResult
|
|
230
234
|
} from '@tanstack/react-query';
|
|
231
235
|
|
|
232
236
|
import type {
|
|
237
|
+
Article,
|
|
238
|
+
ArticleGetAllArticlesParams,
|
|
233
239
|
Case,
|
|
234
|
-
|
|
240
|
+
CaseAddCaseBody,
|
|
241
|
+
CaseAddCaseParams,
|
|
242
|
+
CaseGetAllCasesParams,
|
|
243
|
+
CaseHistory,
|
|
244
|
+
Category
|
|
235
245
|
} from '../outsetaAPI.schemas';
|
|
236
246
|
|
|
237
247
|
import { customFetch } from '../../mutator';
|
|
@@ -314,3 +324,470 @@ export function useCaseGetAllCases<TData = Awaited<ReturnType<typeof caseGetAllC
|
|
|
314
324
|
|
|
315
325
|
|
|
316
326
|
|
|
327
|
+
/**
|
|
328
|
+
* @summary Adds a case into the support system.
|
|
329
|
+
*/
|
|
330
|
+
export const caseAddCase = (
|
|
331
|
+
caseAddCaseBody: CaseAddCaseBody,
|
|
332
|
+
params?: CaseAddCaseParams,
|
|
333
|
+
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
|
334
|
+
) => {
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
return customFetch<Case>(
|
|
338
|
+
{url: `/api/v1/support/cases`, method: 'POST',
|
|
339
|
+
headers: {'Content-Type': 'application/json', },
|
|
340
|
+
data: caseAddCaseBody,
|
|
341
|
+
params, signal
|
|
342
|
+
},
|
|
343
|
+
options);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
export const getCaseAddCaseMutationOptions = <TError = void,
|
|
349
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof caseAddCase>>, TError,{data: CaseAddCaseBody;params?: CaseAddCaseParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
350
|
+
): UseMutationOptions<Awaited<ReturnType<typeof caseAddCase>>, TError,{data: CaseAddCaseBody;params?: CaseAddCaseParams}, TContext> => {
|
|
351
|
+
|
|
352
|
+
const mutationKey = ['caseAddCase'];
|
|
353
|
+
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
354
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
355
|
+
options
|
|
356
|
+
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
357
|
+
: {mutation: { mutationKey, }, request: undefined};
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<typeof caseAddCase>>, {data: CaseAddCaseBody;params?: CaseAddCaseParams}> = (props) => {
|
|
363
|
+
const {data,params} = props ?? {};
|
|
364
|
+
|
|
365
|
+
return caseAddCase(data,params,requestOptions)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
return { mutationFn, ...mutationOptions }}
|
|
372
|
+
|
|
373
|
+
export type CaseAddCaseMutationResult = NonNullable<Awaited<ReturnType<typeof caseAddCase>>>
|
|
374
|
+
export type CaseAddCaseMutationBody = CaseAddCaseBody
|
|
375
|
+
export type CaseAddCaseMutationError = void
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* @summary Adds a case into the support system.
|
|
379
|
+
*/
|
|
380
|
+
export const useCaseAddCase = <TError = void,
|
|
381
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof caseAddCase>>, TError,{data: CaseAddCaseBody;params?: CaseAddCaseParams}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
382
|
+
): UseMutationResult<
|
|
383
|
+
Awaited<ReturnType<typeof caseAddCase>>,
|
|
384
|
+
TError,
|
|
385
|
+
{data: CaseAddCaseBody;params?: CaseAddCaseParams},
|
|
386
|
+
TContext
|
|
387
|
+
> => {
|
|
388
|
+
|
|
389
|
+
const mutationOptions = getCaseAddCaseMutationOptions(options);
|
|
390
|
+
|
|
391
|
+
return useMutation(mutationOptions);
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* @summary Retrieve a specific case
|
|
395
|
+
*/
|
|
396
|
+
export const caseGetCase = (
|
|
397
|
+
caseUid: string | null,
|
|
398
|
+
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
|
399
|
+
) => {
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
return customFetch<Case>(
|
|
403
|
+
{url: `/api/v1/support/cases/${caseUid}`, method: 'GET', signal
|
|
404
|
+
},
|
|
405
|
+
options);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
export const getCaseGetCaseQueryKey = (caseUid?: string | null,) => {
|
|
412
|
+
return [
|
|
413
|
+
`/api/v1/support/cases/${caseUid}`
|
|
414
|
+
] as const;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
export const getCaseGetCaseQueryOptions = <TData = Awaited<ReturnType<typeof caseGetCase>>, TError = void>(caseUid: string | null, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof caseGetCase>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
419
|
+
) => {
|
|
420
|
+
|
|
421
|
+
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
422
|
+
|
|
423
|
+
const queryKey = queryOptions?.queryKey ?? getCaseGetCaseQueryKey(caseUid);
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
const queryFn: QueryFunction<Awaited<ReturnType<typeof caseGetCase>>> = ({ signal }) => caseGetCase(caseUid, requestOptions, signal);
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
return { queryKey, queryFn, enabled: !!(caseUid), ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof caseGetCase>>, TError, TData> & { queryKey: QueryKey }
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export type CaseGetCaseQueryResult = NonNullable<Awaited<ReturnType<typeof caseGetCase>>>
|
|
437
|
+
export type CaseGetCaseQueryError = void
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* @summary Retrieve a specific case
|
|
442
|
+
*/
|
|
443
|
+
|
|
444
|
+
export function useCaseGetCase<TData = Awaited<ReturnType<typeof caseGetCase>>, TError = void>(
|
|
445
|
+
caseUid: string | null, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof caseGetCase>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
446
|
+
|
|
447
|
+
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
448
|
+
|
|
449
|
+
const queryOptions = getCaseGetCaseQueryOptions(caseUid,options)
|
|
450
|
+
|
|
451
|
+
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
452
|
+
|
|
453
|
+
query.queryKey = queryOptions.queryKey ;
|
|
454
|
+
|
|
455
|
+
return query;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* @summary Adds a reply from an agent to a support case.
|
|
463
|
+
*/
|
|
464
|
+
export const caseAddReply = (
|
|
465
|
+
caseUid: string | null,
|
|
466
|
+
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
|
467
|
+
) => {
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
return customFetch<Blob>(
|
|
471
|
+
{url: `/api/v1/support/cases/${caseUid}/replies`, method: 'POST',
|
|
472
|
+
responseType: 'blob', signal
|
|
473
|
+
},
|
|
474
|
+
options);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
export const getCaseAddReplyMutationOptions = <TError = void,
|
|
480
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof caseAddReply>>, TError,{caseUid: string | null}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
481
|
+
): UseMutationOptions<Awaited<ReturnType<typeof caseAddReply>>, TError,{caseUid: string | null}, TContext> => {
|
|
482
|
+
|
|
483
|
+
const mutationKey = ['caseAddReply'];
|
|
484
|
+
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
485
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
486
|
+
options
|
|
487
|
+
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
488
|
+
: {mutation: { mutationKey, }, request: undefined};
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<typeof caseAddReply>>, {caseUid: string | null}> = (props) => {
|
|
494
|
+
const {caseUid} = props ?? {};
|
|
495
|
+
|
|
496
|
+
return caseAddReply(caseUid,requestOptions)
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
return { mutationFn, ...mutationOptions }}
|
|
503
|
+
|
|
504
|
+
export type CaseAddReplyMutationResult = NonNullable<Awaited<ReturnType<typeof caseAddReply>>>
|
|
505
|
+
|
|
506
|
+
export type CaseAddReplyMutationError = void
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* @summary Adds a reply from an agent to a support case.
|
|
510
|
+
*/
|
|
511
|
+
export const useCaseAddReply = <TError = void,
|
|
512
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof caseAddReply>>, TError,{caseUid: string | null}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
513
|
+
): UseMutationResult<
|
|
514
|
+
Awaited<ReturnType<typeof caseAddReply>>,
|
|
515
|
+
TError,
|
|
516
|
+
{caseUid: string | null},
|
|
517
|
+
TContext
|
|
518
|
+
> => {
|
|
519
|
+
|
|
520
|
+
const mutationOptions = getCaseAddReplyMutationOptions(options);
|
|
521
|
+
|
|
522
|
+
return useMutation(mutationOptions);
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* @summary Adds a response to the case from the person that opened the case.
|
|
526
|
+
*/
|
|
527
|
+
export const caseAddClientResponse = (
|
|
528
|
+
caseUid: string | null,
|
|
529
|
+
comment: string | null,
|
|
530
|
+
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
|
531
|
+
) => {
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
return customFetch<CaseHistory>(
|
|
535
|
+
{url: `/api/v1/support/cases/${caseUid}/clientresponse/${comment}`, method: 'POST', signal
|
|
536
|
+
},
|
|
537
|
+
options);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
export const getCaseAddClientResponseMutationOptions = <TError = void,
|
|
543
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof caseAddClientResponse>>, TError,{caseUid: string | null;comment: string | null}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
544
|
+
): UseMutationOptions<Awaited<ReturnType<typeof caseAddClientResponse>>, TError,{caseUid: string | null;comment: string | null}, TContext> => {
|
|
545
|
+
|
|
546
|
+
const mutationKey = ['caseAddClientResponse'];
|
|
547
|
+
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
548
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
549
|
+
options
|
|
550
|
+
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
551
|
+
: {mutation: { mutationKey, }, request: undefined};
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<typeof caseAddClientResponse>>, {caseUid: string | null;comment: string | null}> = (props) => {
|
|
557
|
+
const {caseUid,comment} = props ?? {};
|
|
558
|
+
|
|
559
|
+
return caseAddClientResponse(caseUid,comment,requestOptions)
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
return { mutationFn, ...mutationOptions }}
|
|
566
|
+
|
|
567
|
+
export type CaseAddClientResponseMutationResult = NonNullable<Awaited<ReturnType<typeof caseAddClientResponse>>>
|
|
568
|
+
|
|
569
|
+
export type CaseAddClientResponseMutationError = void
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* @summary Adds a response to the case from the person that opened the case.
|
|
573
|
+
*/
|
|
574
|
+
export const useCaseAddClientResponse = <TError = void,
|
|
575
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof caseAddClientResponse>>, TError,{caseUid: string | null;comment: string | null}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
576
|
+
): UseMutationResult<
|
|
577
|
+
Awaited<ReturnType<typeof caseAddClientResponse>>,
|
|
578
|
+
TError,
|
|
579
|
+
{caseUid: string | null;comment: string | null},
|
|
580
|
+
TContext
|
|
581
|
+
> => {
|
|
582
|
+
|
|
583
|
+
const mutationOptions = getCaseAddClientResponseMutationOptions(options);
|
|
584
|
+
|
|
585
|
+
return useMutation(mutationOptions);
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* @summary Retrieves all knowledge base articles.
|
|
589
|
+
Matches on title or body of the article"
|
|
590
|
+
*/
|
|
591
|
+
export const articleGetAllArticles = (
|
|
592
|
+
params?: ArticleGetAllArticlesParams,
|
|
593
|
+
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
|
594
|
+
) => {
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
return customFetch<Article[]>(
|
|
598
|
+
{url: `/api/v1/support/articles`, method: 'GET',
|
|
599
|
+
params, signal
|
|
600
|
+
},
|
|
601
|
+
options);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
export const getArticleGetAllArticlesQueryKey = (params?: ArticleGetAllArticlesParams,) => {
|
|
608
|
+
return [
|
|
609
|
+
`/api/v1/support/articles`, ...(params ? [params]: [])
|
|
610
|
+
] as const;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
export const getArticleGetAllArticlesQueryOptions = <TData = Awaited<ReturnType<typeof articleGetAllArticles>>, TError = unknown>(params?: ArticleGetAllArticlesParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof articleGetAllArticles>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
615
|
+
) => {
|
|
616
|
+
|
|
617
|
+
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
618
|
+
|
|
619
|
+
const queryKey = queryOptions?.queryKey ?? getArticleGetAllArticlesQueryKey(params);
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
const queryFn: QueryFunction<Awaited<ReturnType<typeof articleGetAllArticles>>> = ({ signal }) => articleGetAllArticles(params, requestOptions, signal);
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof articleGetAllArticles>>, TError, TData> & { queryKey: QueryKey }
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
export type ArticleGetAllArticlesQueryResult = NonNullable<Awaited<ReturnType<typeof articleGetAllArticles>>>
|
|
633
|
+
export type ArticleGetAllArticlesQueryError = unknown
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* @summary Retrieves all knowledge base articles.
|
|
638
|
+
Matches on title or body of the article"
|
|
639
|
+
*/
|
|
640
|
+
|
|
641
|
+
export function useArticleGetAllArticles<TData = Awaited<ReturnType<typeof articleGetAllArticles>>, TError = unknown>(
|
|
642
|
+
params?: ArticleGetAllArticlesParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof articleGetAllArticles>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
643
|
+
|
|
644
|
+
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
645
|
+
|
|
646
|
+
const queryOptions = getArticleGetAllArticlesQueryOptions(params,options)
|
|
647
|
+
|
|
648
|
+
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
649
|
+
|
|
650
|
+
query.queryKey = queryOptions.queryKey ;
|
|
651
|
+
|
|
652
|
+
return query;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* @summary Retrieves a knowledge base article.
|
|
660
|
+
*/
|
|
661
|
+
export const articleGetArticle = (
|
|
662
|
+
articleUid: string | null,
|
|
663
|
+
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
|
664
|
+
) => {
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
return customFetch<Article>(
|
|
668
|
+
{url: `/api/v1/support/articles/${articleUid}`, method: 'GET', signal
|
|
669
|
+
},
|
|
670
|
+
options);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
export const getArticleGetArticleQueryKey = (articleUid?: string | null,) => {
|
|
677
|
+
return [
|
|
678
|
+
`/api/v1/support/articles/${articleUid}`
|
|
679
|
+
] as const;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
export const getArticleGetArticleQueryOptions = <TData = Awaited<ReturnType<typeof articleGetArticle>>, TError = void>(articleUid: string | null, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof articleGetArticle>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
684
|
+
) => {
|
|
685
|
+
|
|
686
|
+
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
687
|
+
|
|
688
|
+
const queryKey = queryOptions?.queryKey ?? getArticleGetArticleQueryKey(articleUid);
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
const queryFn: QueryFunction<Awaited<ReturnType<typeof articleGetArticle>>> = ({ signal }) => articleGetArticle(articleUid, requestOptions, signal);
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
return { queryKey, queryFn, enabled: !!(articleUid), ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof articleGetArticle>>, TError, TData> & { queryKey: QueryKey }
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
export type ArticleGetArticleQueryResult = NonNullable<Awaited<ReturnType<typeof articleGetArticle>>>
|
|
702
|
+
export type ArticleGetArticleQueryError = void
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* @summary Retrieves a knowledge base article.
|
|
707
|
+
*/
|
|
708
|
+
|
|
709
|
+
export function useArticleGetArticle<TData = Awaited<ReturnType<typeof articleGetArticle>>, TError = void>(
|
|
710
|
+
articleUid: string | null, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof articleGetArticle>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
711
|
+
|
|
712
|
+
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
713
|
+
|
|
714
|
+
const queryOptions = getArticleGetArticleQueryOptions(articleUid,options)
|
|
715
|
+
|
|
716
|
+
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
717
|
+
|
|
718
|
+
query.queryKey = queryOptions.queryKey ;
|
|
719
|
+
|
|
720
|
+
return query;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* @summary Retrieves all knowledge base categories.
|
|
728
|
+
*/
|
|
729
|
+
export const categoryGetAllCategories = (
|
|
730
|
+
|
|
731
|
+
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
|
732
|
+
) => {
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
return customFetch<Category[]>(
|
|
736
|
+
{url: `/api/v1/support/categories`, method: 'GET', signal
|
|
737
|
+
},
|
|
738
|
+
options);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
export const getCategoryGetAllCategoriesQueryKey = () => {
|
|
745
|
+
return [
|
|
746
|
+
`/api/v1/support/categories`
|
|
747
|
+
] as const;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
export const getCategoryGetAllCategoriesQueryOptions = <TData = Awaited<ReturnType<typeof categoryGetAllCategories>>, TError = unknown>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof categoryGetAllCategories>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
752
|
+
) => {
|
|
753
|
+
|
|
754
|
+
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
755
|
+
|
|
756
|
+
const queryKey = queryOptions?.queryKey ?? getCategoryGetAllCategoriesQueryKey();
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
const queryFn: QueryFunction<Awaited<ReturnType<typeof categoryGetAllCategories>>> = ({ signal }) => categoryGetAllCategories(requestOptions, signal);
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof categoryGetAllCategories>>, TError, TData> & { queryKey: QueryKey }
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
export type CategoryGetAllCategoriesQueryResult = NonNullable<Awaited<ReturnType<typeof categoryGetAllCategories>>>
|
|
770
|
+
export type CategoryGetAllCategoriesQueryError = unknown
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* @summary Retrieves all knowledge base categories.
|
|
775
|
+
*/
|
|
776
|
+
|
|
777
|
+
export function useCategoryGetAllCategories<TData = Awaited<ReturnType<typeof categoryGetAllCategories>>, TError = unknown>(
|
|
778
|
+
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof categoryGetAllCategories>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
779
|
+
|
|
780
|
+
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
781
|
+
|
|
782
|
+
const queryOptions = getCategoryGetAllCategoriesQueryOptions(options)
|
|
783
|
+
|
|
784
|
+
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
785
|
+
|
|
786
|
+
query.queryKey = queryOptions.queryKey ;
|
|
787
|
+
|
|
788
|
+
return query;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
|
package/src/mutator.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OutsetaClient } from "@outseta/api-client";
|
|
2
2
|
|
|
3
3
|
type RequestConfig<T = unknown> = {
|
|
4
4
|
url: string;
|
|
@@ -12,15 +12,16 @@ type RequestConfig<T = unknown> = {
|
|
|
12
12
|
* Orval react-query mutator.
|
|
13
13
|
*
|
|
14
14
|
* First arg is a request config object `{ url, method, params, signal }`.
|
|
15
|
-
* Second arg is a
|
|
15
|
+
* Second arg is a client from `createClient()` (provided via the React
|
|
16
|
+
* context/provider).
|
|
16
17
|
*/
|
|
17
|
-
export const customFetch = <T>(
|
|
18
|
+
export const customFetch = async <T>(
|
|
18
19
|
config: RequestConfig,
|
|
19
|
-
client?:
|
|
20
|
+
client?: OutsetaClient,
|
|
20
21
|
): Promise<T> => {
|
|
21
22
|
if (!client) {
|
|
22
23
|
throw new Error(
|
|
23
|
-
"@outseta/react: No client provided. Pass a
|
|
24
|
+
"@outseta/react: No client provided. Pass a client from createClient() via the request option.",
|
|
24
25
|
);
|
|
25
26
|
}
|
|
26
27
|
|
|
@@ -29,17 +30,37 @@ export const customFetch = <T>(
|
|
|
29
30
|
const searchParams = params
|
|
30
31
|
? new URLSearchParams(
|
|
31
32
|
Object.entries(params)
|
|
32
|
-
.filter(([,
|
|
33
|
-
.map(([
|
|
33
|
+
.filter(([, value]) => value !== undefined)
|
|
34
|
+
.map(([key, value]) => [key, String(value)]),
|
|
34
35
|
)
|
|
35
36
|
: undefined;
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
const requestUrl = searchParams?.size
|
|
39
|
+
? `${url}${url.includes("?") ? "&" : "?"}${searchParams.toString()}`
|
|
40
|
+
: url;
|
|
41
|
+
|
|
42
|
+
const response = await client(requestUrl, {
|
|
38
43
|
method,
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
headers: data === undefined
|
|
45
|
+
? undefined
|
|
46
|
+
: { "Content-Type": "application/json" },
|
|
47
|
+
body: data === undefined ? undefined : JSON.stringify(data),
|
|
41
48
|
signal,
|
|
42
|
-
})
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`@outseta/react: Request failed with status ${response.status}`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (response.status === 204) {
|
|
58
|
+
return undefined as T;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return response.headers.get("content-type")?.includes("application/json")
|
|
62
|
+
? await response.json() as T
|
|
63
|
+
: undefined as T;
|
|
43
64
|
};
|
|
44
65
|
|
|
45
66
|
export default customFetch;
|