@squonk/account-server-client 0.1.6-rc.1 → 0.1.9-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-d52e4104.d.ts → custom-instance-3334b00b.d.ts} +28 -6
  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 +21 -7
  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 +161 -2
  16. package/product/product.cjs.map +3 -3
  17. package/product/product.d.ts +7 -7
  18. package/product/product.js +127 -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 +295 -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 +289 -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 +54 -5
  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 +13 -13
  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,289 @@
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
+ ProductsGetResponse,
23
+ AsError,
24
+ UnitProductPostResponse,
25
+ UnitProductPostBodyBody,
26
+ ProductUnitGetResponse,
27
+ ProductPatchBodyBody,
28
+ } from "../account-server-api.schemas";
29
+ import { customInstance, ErrorType } from ".././custom-instance";
30
+
31
+ type AsyncReturnType<T extends (...args: any) => Promise<any>> = T extends (
32
+ ...args: any
33
+ ) => Promise<infer R>
34
+ ? R
35
+ : any;
36
+
37
+ type SecondParameter<T extends (...args: any) => any> = T extends (
38
+ config: any,
39
+ args: infer P
40
+ ) => any
41
+ ? P
42
+ : never;
43
+
44
+ /**
45
+ * Gets products you have access to, across all Units and Organisations
46
+
47
+ * @summary Gets all Products
48
+ */
49
+ export const getProducts = (
50
+ options?: SecondParameter<typeof customInstance>
51
+ ) => {
52
+ return customInstance<ProductsGetResponse>(
53
+ { url: `/product`, method: "get" },
54
+ options
55
+ );
56
+ };
57
+
58
+ export const getGetProductsQueryKey = () => [`/product`];
59
+
60
+ export const useGetProducts = <
61
+ TData = AsyncReturnType<typeof getProducts>,
62
+ TError = ErrorType<AsError | void>
63
+ >(options?: {
64
+ query?: UseQueryOptions<AsyncReturnType<typeof getProducts>, TError, TData>;
65
+ request?: SecondParameter<typeof customInstance>;
66
+ }): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
67
+ const { query: queryOptions, request: requestOptions } = options || {};
68
+
69
+ const queryKey = queryOptions?.queryKey ?? getGetProductsQueryKey();
70
+
71
+ const queryFn: QueryFunction<AsyncReturnType<typeof getProducts>> = () =>
72
+ getProducts(requestOptions);
73
+
74
+ const query = useQuery<AsyncReturnType<typeof getProducts>, TError, TData>(
75
+ queryKey,
76
+ queryFn,
77
+ queryOptions
78
+ );
79
+
80
+ return {
81
+ queryKey,
82
+ ...query,
83
+ };
84
+ };
85
+
86
+ /**
87
+ * @summary Creates a Product for an Organisational Unit
88
+ */
89
+ export const createUnitProduct = (
90
+ unitid: string,
91
+ unitProductPostBodyBody: UnitProductPostBodyBody,
92
+ options?: SecondParameter<typeof customInstance>
93
+ ) => {
94
+ return customInstance<UnitProductPostResponse>(
95
+ {
96
+ url: `/product/unit/${unitid}`,
97
+ method: "post",
98
+ data: unitProductPostBodyBody,
99
+ },
100
+ options
101
+ );
102
+ };
103
+
104
+ export const useCreateUnitProduct = <
105
+ TError = ErrorType<AsError | void>,
106
+ TContext = unknown
107
+ >(options?: {
108
+ mutation?: UseMutationOptions<
109
+ AsyncReturnType<typeof createUnitProduct>,
110
+ TError,
111
+ { unitid: string; data: UnitProductPostBodyBody },
112
+ TContext
113
+ >;
114
+ request?: SecondParameter<typeof customInstance>;
115
+ }) => {
116
+ const { mutation: mutationOptions, request: requestOptions } = options || {};
117
+
118
+ const mutationFn: MutationFunction<
119
+ AsyncReturnType<typeof createUnitProduct>,
120
+ { unitid: string; data: UnitProductPostBodyBody }
121
+ > = (props) => {
122
+ const { unitid, data } = props || {};
123
+
124
+ return createUnitProduct(unitid, data, requestOptions);
125
+ };
126
+
127
+ return useMutation<
128
+ AsyncReturnType<typeof createUnitProduct>,
129
+ TError,
130
+ { unitid: string; data: UnitProductPostBodyBody },
131
+ TContext
132
+ >(mutationFn, mutationOptions);
133
+ };
134
+ /**
135
+ * Gets products you have access to based on an Organisational Unit
136
+
137
+ * @summary Gets Products for an Organisational Unit
138
+ */
139
+ export const getProductsForUnit = (
140
+ unitid: string,
141
+ options?: SecondParameter<typeof customInstance>
142
+ ) => {
143
+ return customInstance<ProductsGetResponse>(
144
+ { url: `/product/unit/${unitid}`, method: "get" },
145
+ options
146
+ );
147
+ };
148
+
149
+ export const getGetProductsForUnitQueryKey = (unitid: string) => [
150
+ `/product/unit/${unitid}`,
151
+ ];
152
+
153
+ export const useGetProductsForUnit = <
154
+ TData = AsyncReturnType<typeof getProductsForUnit>,
155
+ TError = ErrorType<void | AsError>
156
+ >(
157
+ unitid: string,
158
+ options?: {
159
+ query?: UseQueryOptions<
160
+ AsyncReturnType<typeof getProductsForUnit>,
161
+ TError,
162
+ TData
163
+ >;
164
+ request?: SecondParameter<typeof customInstance>;
165
+ }
166
+ ): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
167
+ const { query: queryOptions, request: requestOptions } = options || {};
168
+
169
+ const queryKey =
170
+ queryOptions?.queryKey ?? getGetProductsForUnitQueryKey(unitid);
171
+
172
+ const queryFn: QueryFunction<
173
+ AsyncReturnType<typeof getProductsForUnit>
174
+ > = () => getProductsForUnit(unitid, requestOptions);
175
+
176
+ const query = useQuery<
177
+ AsyncReturnType<typeof getProductsForUnit>,
178
+ TError,
179
+ TData
180
+ >(queryKey, queryFn, { enabled: !!unitid, ...queryOptions });
181
+
182
+ return {
183
+ queryKey,
184
+ ...query,
185
+ };
186
+ };
187
+
188
+ /**
189
+ * Gets a Unit's Product
190
+
191
+ * @summary Gets a Unit's Product
192
+ */
193
+ export const getProduct = (
194
+ unitid: string,
195
+ productid: string,
196
+ options?: SecondParameter<typeof customInstance>
197
+ ) => {
198
+ return customInstance<ProductUnitGetResponse>(
199
+ { url: `/product/unit/${unitid}/product/${productid}`, method: "get" },
200
+ options
201
+ );
202
+ };
203
+
204
+ export const getGetProductQueryKey = (unitid: string, productid: string) => [
205
+ `/product/unit/${unitid}/product/${productid}`,
206
+ ];
207
+
208
+ export const useGetProduct = <
209
+ TData = AsyncReturnType<typeof getProduct>,
210
+ TError = ErrorType<AsError | void>
211
+ >(
212
+ unitid: string,
213
+ productid: string,
214
+ options?: {
215
+ query?: UseQueryOptions<AsyncReturnType<typeof getProduct>, TError, TData>;
216
+ request?: SecondParameter<typeof customInstance>;
217
+ }
218
+ ): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
219
+ const { query: queryOptions, request: requestOptions } = options || {};
220
+
221
+ const queryKey =
222
+ queryOptions?.queryKey ?? getGetProductQueryKey(unitid, productid);
223
+
224
+ const queryFn: QueryFunction<AsyncReturnType<typeof getProduct>> = () =>
225
+ getProduct(unitid, productid, requestOptions);
226
+
227
+ const query = useQuery<AsyncReturnType<typeof getProduct>, TError, TData>(
228
+ queryKey,
229
+ queryFn,
230
+ { enabled: !!(unitid && productid), ...queryOptions }
231
+ );
232
+
233
+ return {
234
+ queryKey,
235
+ ...query,
236
+ };
237
+ };
238
+
239
+ /**
240
+ * Used to update some adjustable parameters of a Product, i.e. to extend the Allowance or Limit. Curently you can only patch storage Products
241
+
242
+ * @summary Adjust an existing Product
243
+ */
244
+ export const patchProduct = (
245
+ unitid: string,
246
+ productid: string,
247
+ productPatchBodyBody: ProductPatchBodyBody,
248
+ options?: SecondParameter<typeof customInstance>
249
+ ) => {
250
+ return customInstance<void>(
251
+ {
252
+ url: `/product/unit/${unitid}/product/${productid}`,
253
+ method: "patch",
254
+ data: productPatchBodyBody,
255
+ },
256
+ options
257
+ );
258
+ };
259
+
260
+ export const usePatchProduct = <
261
+ TError = ErrorType<AsError>,
262
+ TContext = unknown
263
+ >(options?: {
264
+ mutation?: UseMutationOptions<
265
+ AsyncReturnType<typeof patchProduct>,
266
+ TError,
267
+ { unitid: string; productid: string; data: ProductPatchBodyBody },
268
+ TContext
269
+ >;
270
+ request?: SecondParameter<typeof customInstance>;
271
+ }) => {
272
+ const { mutation: mutationOptions, request: requestOptions } = options || {};
273
+
274
+ const mutationFn: MutationFunction<
275
+ AsyncReturnType<typeof patchProduct>,
276
+ { unitid: string; productid: string; data: ProductPatchBodyBody }
277
+ > = (props) => {
278
+ const { unitid, productid, data } = props || {};
279
+
280
+ return patchProduct(unitid, productid, data, requestOptions);
281
+ };
282
+
283
+ return useMutation<
284
+ AsyncReturnType<typeof patchProduct>,
285
+ TError,
286
+ { unitid: string; productid: string; data: ProductPatchBodyBody },
287
+ TContext
288
+ >(mutationFn, mutationOptions);
289
+ };
@@ -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
+ };