@squonk/account-server-client 0.1.7-rc.1 → 0.1.11-rc.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.
Files changed (49) hide show
  1. package/{custom-instance-0d593da2.d.ts → custom-instance-108ca7f1.d.ts} +39 -5
  2. package/index.cjs +103 -2
  3. package/index.cjs.map +3 -3
  4. package/index.d.ts +1 -1
  5. package/index.js +69 -2
  6. package/index.js.map +3 -3
  7. package/organisation/organisation.cjs +111 -2
  8. package/organisation/organisation.cjs.map +3 -3
  9. package/organisation/organisation.d.ts +19 -5
  10. package/organisation/organisation.js +83 -2
  11. package/organisation/organisation.js.map +3 -3
  12. package/organisation/package.json +2 -1
  13. package/package.json +7 -7
  14. package/product/package.json +2 -1
  15. package/product/product.cjs +180 -2
  16. package/product/product.cjs.map +3 -3
  17. package/product/product.d.ts +16 -3
  18. package/product/product.js +143 -2
  19. package/product/product.js.map +3 -3
  20. package/service/package.json +7 -0
  21. package/service/service.cjs +100 -0
  22. package/service/service.cjs.map +7 -0
  23. package/service/service.d.ts +44 -0
  24. package/service/service.js +72 -0
  25. package/service/service.js.map +7 -0
  26. package/src/account-server-api.schemas.ts +309 -0
  27. package/src/custom-instance.ts +52 -0
  28. package/src/index.ts +6 -0
  29. package/src/organisation/organisation.ts +181 -0
  30. package/src/product/product.ts +336 -0
  31. package/src/service/service.ts +124 -0
  32. package/src/unit/unit.ts +322 -0
  33. package/src/user/user.ts +340 -0
  34. package/unit/package.json +2 -1
  35. package/unit/unit.cjs +168 -2
  36. package/unit/unit.cjs.map +3 -3
  37. package/unit/unit.d.ts +52 -3
  38. package/unit/unit.js +133 -2
  39. package/unit/unit.js.map +3 -3
  40. package/user/package.json +2 -1
  41. package/user/user.cjs +176 -2
  42. package/user/user.cjs.map +3 -3
  43. package/user/user.d.ts +7 -7
  44. package/user/user.js +141 -2
  45. package/user/user.js.map +3 -3
  46. package/chunk-33VR3IML.js +0 -2
  47. package/chunk-33VR3IML.js.map +0 -7
  48. package/chunk-3KO3PKBX.cjs +0 -2
  49. package/chunk-3KO3PKBX.cjs.map +0 -7
@@ -0,0 +1,52 @@
1
+ /** Based off the example custom-instance from Orval docs
2
+ * https://github.com/anymaniax/orval/blob/master/samples/react-app-with-react-query/src/api/mutator/custom-instance.ts
3
+ *
4
+ * See https://react-query.tanstack.com/guides/query-cancellation
5
+ *
6
+ * TODO: Considering using Fetch-API instead of axios. This instance will have to change. Could be
7
+ * achieved without changing much using `redaxios`
8
+ * Or use 'ky'
9
+ */
10
+
11
+ import Axios, { AxiosError, AxiosRequestConfig } from 'axios';
12
+
13
+ // ? Need the baseUrl or does it default to ''?
14
+ export const AXIOS_INSTANCE = Axios.create({ baseURL: '' });
15
+
16
+ /**
17
+ * Set the access token to be added as the `Authorization: Bearer 'token'` header
18
+ * Useful for client only apps where a proxy API route isn't involved to securely add the access token
19
+ * @param token access token
20
+ */
21
+ export const setAuthToken = (token: string) => {
22
+ AXIOS_INSTANCE.defaults.headers.common['Authorization'] = `Bearer ${token}`;
23
+ };
24
+
25
+ /**
26
+ * Set the url to which request paths are added to.
27
+ * @param baseUrl origin + subpath e.g. 'https://example.com/subpath' or '/subpath'
28
+ */
29
+ export const setBaseUrl = (baseUrl: string) => {
30
+ AXIOS_INSTANCE.defaults.baseURL = baseUrl;
31
+ };
32
+
33
+ export const customInstance = <TReturn>(
34
+ config: AxiosRequestConfig,
35
+ options?: AxiosRequestConfig,
36
+ ): Promise<TReturn> => {
37
+ const source = Axios.CancelToken.source();
38
+
39
+ const promise = AXIOS_INSTANCE({ ...config, ...options, cancelToken: source.token }).then(
40
+ ({ data }) => data,
41
+ );
42
+
43
+ // Promise doesn't have a cancel method but react-query requires this method to make cancellations general.
44
+ // This can either be a any assertion or a @ts-ignore comment.
45
+ (promise as any).cancel = () => {
46
+ source.cancel('Query was cancelled by React Query');
47
+ };
48
+
49
+ return promise;
50
+ };
51
+
52
+ export type ErrorType<TError> = AxiosError<TError>;
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ // Generated by orval
2
+ // account-server-api Is replaced with the api name
3
+ export * from './account-server-api.schemas';
4
+
5
+ // Request instance and methods to change the baseUrl and auth token
6
+ export * from './custom-instance';
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Generated by orval v6.4.2 🍺
3
+ * Do not edit manually.
4
+ * Account Server API
5
+ * The Informatics Matters Account Server API.
6
+
7
+ A service that provides access to the Account Server, which gives *registered* users access to and management of **Products**, **Organisations**, **Units** and **Users**.
8
+
9
+ * OpenAPI spec version: 0.1
10
+ */
11
+ import {
12
+ useQuery,
13
+ useMutation,
14
+ UseQueryOptions,
15
+ UseMutationOptions,
16
+ QueryFunction,
17
+ MutationFunction,
18
+ UseQueryResult,
19
+ QueryKey,
20
+ } from "react-query";
21
+ import type {
22
+ OrganisationsGetResponse,
23
+ AsError,
24
+ OrganisationPostResponse,
25
+ OrganisationPostBodyBody,
26
+ } from "../account-server-api.schemas";
27
+ import { customInstance, ErrorType } from ".././custom-instance";
28
+
29
+ type AsyncReturnType<T extends (...args: any) => Promise<any>> = T extends (
30
+ ...args: any
31
+ ) => Promise<infer R>
32
+ ? R
33
+ : any;
34
+
35
+ type SecondParameter<T extends (...args: any) => any> = T extends (
36
+ config: any,
37
+ args: infer P
38
+ ) => any
39
+ ? P
40
+ : never;
41
+
42
+ /**
43
+ * Gets all the Organisations you are a member of. Admin users can see all Organisations
44
+
45
+ * @summary Gets Organisations
46
+ */
47
+ export const getOrganisations = (
48
+ options?: SecondParameter<typeof customInstance>
49
+ ) => {
50
+ return customInstance<OrganisationsGetResponse>(
51
+ { url: `/organisation`, method: "get" },
52
+ options
53
+ );
54
+ };
55
+
56
+ export const getGetOrganisationsQueryKey = () => [`/organisation`];
57
+
58
+ export const useGetOrganisations = <
59
+ TData = AsyncReturnType<typeof getOrganisations>,
60
+ TError = ErrorType<void | AsError>
61
+ >(options?: {
62
+ query?: UseQueryOptions<
63
+ AsyncReturnType<typeof getOrganisations>,
64
+ TError,
65
+ TData
66
+ >;
67
+ request?: SecondParameter<typeof customInstance>;
68
+ }): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
69
+ const { query: queryOptions, request: requestOptions } = options || {};
70
+
71
+ const queryKey = queryOptions?.queryKey ?? getGetOrganisationsQueryKey();
72
+
73
+ const queryFn: QueryFunction<AsyncReturnType<typeof getOrganisations>> = () =>
74
+ getOrganisations(requestOptions);
75
+
76
+ const query = useQuery<
77
+ AsyncReturnType<typeof getOrganisations>,
78
+ TError,
79
+ TData
80
+ >(queryKey, queryFn, queryOptions);
81
+
82
+ return {
83
+ queryKey,
84
+ ...query,
85
+ };
86
+ };
87
+
88
+ /**
89
+ * Creates a new Organisation
90
+
91
+ You need **admin** rights to use this method
92
+
93
+ * @summary Create a new organisation
94
+ */
95
+ export const createOrganisation = (
96
+ organisationPostBodyBody: OrganisationPostBodyBody,
97
+ options?: SecondParameter<typeof customInstance>
98
+ ) => {
99
+ return customInstance<OrganisationPostResponse>(
100
+ { url: `/organisation`, method: "post", data: organisationPostBodyBody },
101
+ options
102
+ );
103
+ };
104
+
105
+ export const useCreateOrganisation = <
106
+ TError = ErrorType<AsError | void>,
107
+ TContext = unknown
108
+ >(options?: {
109
+ mutation?: UseMutationOptions<
110
+ AsyncReturnType<typeof createOrganisation>,
111
+ TError,
112
+ { data: OrganisationPostBodyBody },
113
+ TContext
114
+ >;
115
+ request?: SecondParameter<typeof customInstance>;
116
+ }) => {
117
+ const { mutation: mutationOptions, request: requestOptions } = options || {};
118
+
119
+ const mutationFn: MutationFunction<
120
+ AsyncReturnType<typeof createOrganisation>,
121
+ { data: OrganisationPostBodyBody }
122
+ > = (props) => {
123
+ const { data } = props || {};
124
+
125
+ return createOrganisation(data, requestOptions);
126
+ };
127
+
128
+ return useMutation<
129
+ AsyncReturnType<typeof createOrganisation>,
130
+ TError,
131
+ { data: OrganisationPostBodyBody },
132
+ TContext
133
+ >(mutationFn, mutationOptions);
134
+ };
135
+ /**
136
+ * Units must first be deleted before an Organisation can be deleted
137
+
138
+ You need **admin** rights to use this method
139
+
140
+ * @summary Deletes an Organisation
141
+ */
142
+ export const deleteOrganisation = (
143
+ orgid: string,
144
+ options?: SecondParameter<typeof customInstance>
145
+ ) => {
146
+ return customInstance<void>(
147
+ { url: `/organisation/${orgid}`, method: "delete", data: undefined },
148
+ options
149
+ );
150
+ };
151
+
152
+ export const useDeleteOrganisation = <
153
+ TError = ErrorType<AsError>,
154
+ TContext = unknown
155
+ >(options?: {
156
+ mutation?: UseMutationOptions<
157
+ AsyncReturnType<typeof deleteOrganisation>,
158
+ TError,
159
+ { orgid: string },
160
+ TContext
161
+ >;
162
+ request?: SecondParameter<typeof customInstance>;
163
+ }) => {
164
+ const { mutation: mutationOptions, request: requestOptions } = options || {};
165
+
166
+ const mutationFn: MutationFunction<
167
+ AsyncReturnType<typeof deleteOrganisation>,
168
+ { orgid: string }
169
+ > = (props) => {
170
+ const { orgid } = props || {};
171
+
172
+ return deleteOrganisation(orgid, requestOptions);
173
+ };
174
+
175
+ return useMutation<
176
+ AsyncReturnType<typeof deleteOrganisation>,
177
+ TError,
178
+ { orgid: string },
179
+ TContext
180
+ >(mutationFn, mutationOptions);
181
+ };
@@ -0,0 +1,336 @@
1
+ /**
2
+ * Generated by orval v6.4.2 🍺
3
+ * Do not edit manually.
4
+ * Account Server API
5
+ * The Informatics Matters Account Server API.
6
+
7
+ A service that provides access to the Account Server, which gives *registered* users access to and management of **Products**, **Organisations**, **Units** and **Users**.
8
+
9
+ * OpenAPI spec version: 0.1
10
+ */
11
+ import {
12
+ useQuery,
13
+ useMutation,
14
+ UseQueryOptions,
15
+ UseMutationOptions,
16
+ QueryFunction,
17
+ MutationFunction,
18
+ UseQueryResult,
19
+ QueryKey,
20
+ } from "react-query";
21
+ import type {
22
+ ProductsGetTypesResponse,
23
+ AsError,
24
+ ProductsGetResponse,
25
+ UnitProductPostResponse,
26
+ UnitProductPostBodyBody,
27
+ ProductUnitGetResponse,
28
+ ProductPatchBodyBody,
29
+ } from "../account-server-api.schemas";
30
+ import { customInstance, ErrorType } from ".././custom-instance";
31
+
32
+ type AsyncReturnType<T extends (...args: any) => Promise<any>> = T extends (
33
+ ...args: any
34
+ ) => Promise<infer R>
35
+ ? R
36
+ : any;
37
+
38
+ type SecondParameter<T extends (...args: any) => any> = T extends (
39
+ config: any,
40
+ args: infer P
41
+ ) => any
42
+ ? P
43
+ : never;
44
+
45
+ /**
46
+ * Gets product types you can purchase
47
+
48
+ * @summary Gets all Product Types
49
+ */
50
+ export const getProductTypes = (
51
+ options?: SecondParameter<typeof customInstance>
52
+ ) => {
53
+ return customInstance<ProductsGetTypesResponse>(
54
+ { url: `/product-type`, method: "get" },
55
+ options
56
+ );
57
+ };
58
+
59
+ export const getGetProductTypesQueryKey = () => [`/product-type`];
60
+
61
+ export const useGetProductTypes = <
62
+ TData = AsyncReturnType<typeof getProductTypes>,
63
+ TError = ErrorType<AsError | void>
64
+ >(options?: {
65
+ query?: UseQueryOptions<
66
+ AsyncReturnType<typeof getProductTypes>,
67
+ TError,
68
+ TData
69
+ >;
70
+ request?: SecondParameter<typeof customInstance>;
71
+ }): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
72
+ const { query: queryOptions, request: requestOptions } = options || {};
73
+
74
+ const queryKey = queryOptions?.queryKey ?? getGetProductTypesQueryKey();
75
+
76
+ const queryFn: QueryFunction<AsyncReturnType<typeof getProductTypes>> = () =>
77
+ getProductTypes(requestOptions);
78
+
79
+ const query = useQuery<
80
+ AsyncReturnType<typeof getProductTypes>,
81
+ TError,
82
+ TData
83
+ >(queryKey, queryFn, queryOptions);
84
+
85
+ return {
86
+ queryKey,
87
+ ...query,
88
+ };
89
+ };
90
+
91
+ /**
92
+ * Gets products you have access to, across all Units and Organisations
93
+
94
+ * @summary Gets all Products
95
+ */
96
+ export const getProducts = (
97
+ options?: SecondParameter<typeof customInstance>
98
+ ) => {
99
+ return customInstance<ProductsGetResponse>(
100
+ { url: `/product`, method: "get" },
101
+ options
102
+ );
103
+ };
104
+
105
+ export const getGetProductsQueryKey = () => [`/product`];
106
+
107
+ export const useGetProducts = <
108
+ TData = AsyncReturnType<typeof getProducts>,
109
+ TError = ErrorType<AsError | void>
110
+ >(options?: {
111
+ query?: UseQueryOptions<AsyncReturnType<typeof getProducts>, TError, TData>;
112
+ request?: SecondParameter<typeof customInstance>;
113
+ }): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
114
+ const { query: queryOptions, request: requestOptions } = options || {};
115
+
116
+ const queryKey = queryOptions?.queryKey ?? getGetProductsQueryKey();
117
+
118
+ const queryFn: QueryFunction<AsyncReturnType<typeof getProducts>> = () =>
119
+ getProducts(requestOptions);
120
+
121
+ const query = useQuery<AsyncReturnType<typeof getProducts>, TError, TData>(
122
+ queryKey,
123
+ queryFn,
124
+ queryOptions
125
+ );
126
+
127
+ return {
128
+ queryKey,
129
+ ...query,
130
+ };
131
+ };
132
+
133
+ /**
134
+ * @summary Creates a Product for an Organisational Unit
135
+ */
136
+ export const createUnitProduct = (
137
+ unitid: string,
138
+ unitProductPostBodyBody: UnitProductPostBodyBody,
139
+ options?: SecondParameter<typeof customInstance>
140
+ ) => {
141
+ return customInstance<UnitProductPostResponse>(
142
+ {
143
+ url: `/product/unit/${unitid}`,
144
+ method: "post",
145
+ data: unitProductPostBodyBody,
146
+ },
147
+ options
148
+ );
149
+ };
150
+
151
+ export const useCreateUnitProduct = <
152
+ TError = ErrorType<AsError | void>,
153
+ TContext = unknown
154
+ >(options?: {
155
+ mutation?: UseMutationOptions<
156
+ AsyncReturnType<typeof createUnitProduct>,
157
+ TError,
158
+ { unitid: string; data: UnitProductPostBodyBody },
159
+ TContext
160
+ >;
161
+ request?: SecondParameter<typeof customInstance>;
162
+ }) => {
163
+ const { mutation: mutationOptions, request: requestOptions } = options || {};
164
+
165
+ const mutationFn: MutationFunction<
166
+ AsyncReturnType<typeof createUnitProduct>,
167
+ { unitid: string; data: UnitProductPostBodyBody }
168
+ > = (props) => {
169
+ const { unitid, data } = props || {};
170
+
171
+ return createUnitProduct(unitid, data, requestOptions);
172
+ };
173
+
174
+ return useMutation<
175
+ AsyncReturnType<typeof createUnitProduct>,
176
+ TError,
177
+ { unitid: string; data: UnitProductPostBodyBody },
178
+ TContext
179
+ >(mutationFn, mutationOptions);
180
+ };
181
+ /**
182
+ * Gets products you have access to based on an Organisational Unit
183
+
184
+ * @summary Gets Products for an Organisational Unit
185
+ */
186
+ export const getProductsForUnit = (
187
+ unitid: string,
188
+ options?: SecondParameter<typeof customInstance>
189
+ ) => {
190
+ return customInstance<ProductsGetResponse>(
191
+ { url: `/product/unit/${unitid}`, method: "get" },
192
+ options
193
+ );
194
+ };
195
+
196
+ export const getGetProductsForUnitQueryKey = (unitid: string) => [
197
+ `/product/unit/${unitid}`,
198
+ ];
199
+
200
+ export const useGetProductsForUnit = <
201
+ TData = AsyncReturnType<typeof getProductsForUnit>,
202
+ TError = ErrorType<void | AsError>
203
+ >(
204
+ unitid: string,
205
+ options?: {
206
+ query?: UseQueryOptions<
207
+ AsyncReturnType<typeof getProductsForUnit>,
208
+ TError,
209
+ TData
210
+ >;
211
+ request?: SecondParameter<typeof customInstance>;
212
+ }
213
+ ): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
214
+ const { query: queryOptions, request: requestOptions } = options || {};
215
+
216
+ const queryKey =
217
+ queryOptions?.queryKey ?? getGetProductsForUnitQueryKey(unitid);
218
+
219
+ const queryFn: QueryFunction<
220
+ AsyncReturnType<typeof getProductsForUnit>
221
+ > = () => getProductsForUnit(unitid, requestOptions);
222
+
223
+ const query = useQuery<
224
+ AsyncReturnType<typeof getProductsForUnit>,
225
+ TError,
226
+ TData
227
+ >(queryKey, queryFn, { enabled: !!unitid, ...queryOptions });
228
+
229
+ return {
230
+ queryKey,
231
+ ...query,
232
+ };
233
+ };
234
+
235
+ /**
236
+ * Gets a Unit's Product
237
+
238
+ * @summary Gets a Unit's Product
239
+ */
240
+ export const getProduct = (
241
+ unitid: string,
242
+ productid: string,
243
+ options?: SecondParameter<typeof customInstance>
244
+ ) => {
245
+ return customInstance<ProductUnitGetResponse>(
246
+ { url: `/product/unit/${unitid}/product/${productid}`, method: "get" },
247
+ options
248
+ );
249
+ };
250
+
251
+ export const getGetProductQueryKey = (unitid: string, productid: string) => [
252
+ `/product/unit/${unitid}/product/${productid}`,
253
+ ];
254
+
255
+ export const useGetProduct = <
256
+ TData = AsyncReturnType<typeof getProduct>,
257
+ TError = ErrorType<AsError | void>
258
+ >(
259
+ unitid: string,
260
+ productid: string,
261
+ options?: {
262
+ query?: UseQueryOptions<AsyncReturnType<typeof getProduct>, TError, TData>;
263
+ request?: SecondParameter<typeof customInstance>;
264
+ }
265
+ ): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
266
+ const { query: queryOptions, request: requestOptions } = options || {};
267
+
268
+ const queryKey =
269
+ queryOptions?.queryKey ?? getGetProductQueryKey(unitid, productid);
270
+
271
+ const queryFn: QueryFunction<AsyncReturnType<typeof getProduct>> = () =>
272
+ getProduct(unitid, productid, requestOptions);
273
+
274
+ const query = useQuery<AsyncReturnType<typeof getProduct>, TError, TData>(
275
+ queryKey,
276
+ queryFn,
277
+ { enabled: !!(unitid && productid), ...queryOptions }
278
+ );
279
+
280
+ return {
281
+ queryKey,
282
+ ...query,
283
+ };
284
+ };
285
+
286
+ /**
287
+ * Used to update some adjustable parameters of a Product, i.e. to extend the Allowance or Limit. Curently you can only patch storage Products
288
+
289
+ * @summary Adjust an existing Product
290
+ */
291
+ export const patchProduct = (
292
+ unitid: string,
293
+ productid: string,
294
+ productPatchBodyBody: ProductPatchBodyBody,
295
+ options?: SecondParameter<typeof customInstance>
296
+ ) => {
297
+ return customInstance<void>(
298
+ {
299
+ url: `/product/unit/${unitid}/product/${productid}`,
300
+ method: "patch",
301
+ data: productPatchBodyBody,
302
+ },
303
+ options
304
+ );
305
+ };
306
+
307
+ export const usePatchProduct = <
308
+ TError = ErrorType<AsError>,
309
+ TContext = unknown
310
+ >(options?: {
311
+ mutation?: UseMutationOptions<
312
+ AsyncReturnType<typeof patchProduct>,
313
+ TError,
314
+ { unitid: string; productid: string; data: ProductPatchBodyBody },
315
+ TContext
316
+ >;
317
+ request?: SecondParameter<typeof customInstance>;
318
+ }) => {
319
+ const { mutation: mutationOptions, request: requestOptions } = options || {};
320
+
321
+ const mutationFn: MutationFunction<
322
+ AsyncReturnType<typeof patchProduct>,
323
+ { unitid: string; productid: string; data: ProductPatchBodyBody }
324
+ > = (props) => {
325
+ const { unitid, productid, data } = props || {};
326
+
327
+ return patchProduct(unitid, productid, data, requestOptions);
328
+ };
329
+
330
+ return useMutation<
331
+ AsyncReturnType<typeof patchProduct>,
332
+ TError,
333
+ { unitid: string; productid: string; data: ProductPatchBodyBody },
334
+ TContext
335
+ >(mutationFn, mutationOptions);
336
+ };
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Generated by orval v6.4.2 🍺
3
+ * Do not edit manually.
4
+ * Account Server API
5
+ * The Informatics Matters Account Server API.
6
+
7
+ A service that provides access to the Account Server, which gives *registered* users access to and management of **Products**, **Organisations**, **Units** and **Users**.
8
+
9
+ * OpenAPI spec version: 0.1
10
+ */
11
+ import {
12
+ useQuery,
13
+ UseQueryOptions,
14
+ QueryFunction,
15
+ UseQueryResult,
16
+ QueryKey,
17
+ } from "react-query";
18
+ import type {
19
+ ServicesGetResponse,
20
+ AsError,
21
+ ServiceGetResponse,
22
+ } from "../account-server-api.schemas";
23
+ import { customInstance, ErrorType } from ".././custom-instance";
24
+
25
+ type AsyncReturnType<T extends (...args: any) => Promise<any>> = T extends (
26
+ ...args: any
27
+ ) => Promise<infer R>
28
+ ? R
29
+ : any;
30
+
31
+ type SecondParameter<T extends (...args: any) => any> = T extends (
32
+ config: any,
33
+ args: infer P
34
+ ) => any
35
+ ? P
36
+ : never;
37
+
38
+ /**
39
+ * Gets services known to the Account Server
40
+
41
+ * @summary Gets all Services
42
+ */
43
+ export const getServices = (
44
+ options?: SecondParameter<typeof customInstance>
45
+ ) => {
46
+ return customInstance<ServicesGetResponse>(
47
+ { url: `/service`, method: "get" },
48
+ options
49
+ );
50
+ };
51
+
52
+ export const getGetServicesQueryKey = () => [`/service`];
53
+
54
+ export const useGetServices = <
55
+ TData = AsyncReturnType<typeof getServices>,
56
+ TError = ErrorType<AsError | void>
57
+ >(options?: {
58
+ query?: UseQueryOptions<AsyncReturnType<typeof getServices>, TError, TData>;
59
+ request?: SecondParameter<typeof customInstance>;
60
+ }): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
61
+ const { query: queryOptions, request: requestOptions } = options || {};
62
+
63
+ const queryKey = queryOptions?.queryKey ?? getGetServicesQueryKey();
64
+
65
+ const queryFn: QueryFunction<AsyncReturnType<typeof getServices>> = () =>
66
+ getServices(requestOptions);
67
+
68
+ const query = useQuery<AsyncReturnType<typeof getServices>, TError, TData>(
69
+ queryKey,
70
+ queryFn,
71
+ queryOptions
72
+ );
73
+
74
+ return {
75
+ queryKey,
76
+ ...query,
77
+ };
78
+ };
79
+
80
+ /**
81
+ * Gets a known service
82
+
83
+ * @summary Gets a specific Service
84
+ */
85
+ export const getService = (
86
+ svcid: number,
87
+ options?: SecondParameter<typeof customInstance>
88
+ ) => {
89
+ return customInstance<ServiceGetResponse>(
90
+ { url: `/service/${svcid}`, method: "get" },
91
+ options
92
+ );
93
+ };
94
+
95
+ export const getGetServiceQueryKey = (svcid: number) => [`/service/${svcid}`];
96
+
97
+ export const useGetService = <
98
+ TData = AsyncReturnType<typeof getService>,
99
+ TError = ErrorType<AsError | void>
100
+ >(
101
+ svcid: number,
102
+ options?: {
103
+ query?: UseQueryOptions<AsyncReturnType<typeof getService>, TError, TData>;
104
+ request?: SecondParameter<typeof customInstance>;
105
+ }
106
+ ): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
107
+ const { query: queryOptions, request: requestOptions } = options || {};
108
+
109
+ const queryKey = queryOptions?.queryKey ?? getGetServiceQueryKey(svcid);
110
+
111
+ const queryFn: QueryFunction<AsyncReturnType<typeof getService>> = () =>
112
+ getService(svcid, requestOptions);
113
+
114
+ const query = useQuery<AsyncReturnType<typeof getService>, TError, TData>(
115
+ queryKey,
116
+ queryFn,
117
+ { enabled: !!svcid, ...queryOptions }
118
+ );
119
+
120
+ return {
121
+ queryKey,
122
+ ...query,
123
+ };
124
+ };