@squonk/account-server-client 0.1.26 → 0.1.28
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/{chunk-GWBPVOL2.js → chunk-6EEIAH4R.js} +23 -2
- package/chunk-6EEIAH4R.js.map +1 -0
- package/chunk-NGBTCJWS.cjs +46 -0
- package/chunk-NGBTCJWS.cjs.map +1 -0
- package/{account-server-api.schemas-078442c3.d.ts → custom-instance-13412a15.d.ts} +32 -1
- package/index.cjs +5 -21
- package/index.cjs.map +1 -1
- package/index.d.ts +2 -20
- package/index.js +5 -21
- package/index.js.map +1 -1
- package/organisation/organisation.cjs +70 -20
- package/organisation/organisation.cjs.map +1 -1
- package/organisation/organisation.d.ts +68 -18
- package/organisation/organisation.js +70 -20
- package/organisation/organisation.js.map +1 -1
- package/package.json +1 -1
- package/product/product.cjs +121 -31
- package/product/product.cjs.map +1 -1
- package/product/product.d.ts +115 -24
- package/product/product.js +121 -31
- package/product/product.js.map +1 -1
- package/service/service.cjs +38 -11
- package/service/service.cjs.map +1 -1
- package/service/service.d.ts +35 -8
- package/service/service.js +38 -11
- package/service/service.js.map +1 -1
- package/src/account-server-api.schemas.ts +13 -0
- package/src/organisation/organisation.ts +219 -44
- package/src/product/product.ts +375 -84
- package/src/service/service.ts +110 -16
- package/src/state/state.ts +70 -16
- package/src/unit/unit.ts +354 -74
- package/src/user/user.ts +368 -67
- package/state/state.cjs +22 -8
- package/state/state.cjs.map +1 -1
- package/state/state.d.ts +18 -6
- package/state/state.js +22 -8
- package/state/state.js.map +1 -1
- package/unit/unit.cjs +110 -30
- package/unit/unit.cjs.map +1 -1
- package/unit/unit.d.ts +108 -25
- package/unit/unit.js +110 -30
- package/unit/unit.js.map +1 -1
- package/user/user.cjs +107 -30
- package/user/user.cjs.map +1 -1
- package/user/user.d.ts +133 -20
- package/user/user.js +107 -30
- package/user/user.js.map +1 -1
- package/chunk-GWBPVOL2.js.map +0 -1
- package/chunk-N3RLW53G.cjs +0 -25
- package/chunk-N3RLW53G.cjs.map +0 -1
package/src/product/product.ts
CHANGED
|
@@ -8,124 +8,415 @@ A service that provides access to the Account Server, which gives *registered* u
|
|
|
8
8
|
|
|
9
9
|
* OpenAPI spec version: 0.1
|
|
10
10
|
*/
|
|
11
|
-
import
|
|
11
|
+
import {
|
|
12
|
+
useQuery,
|
|
13
|
+
useMutation,
|
|
14
|
+
UseQueryOptions,
|
|
15
|
+
UseMutationOptions,
|
|
16
|
+
QueryFunction,
|
|
17
|
+
MutationFunction,
|
|
18
|
+
UseQueryResult,
|
|
19
|
+
QueryKey,
|
|
20
|
+
} from "react-query";
|
|
12
21
|
import type {
|
|
13
22
|
ProductsGetTypesResponse,
|
|
23
|
+
AsError,
|
|
14
24
|
ProductsGetResponse,
|
|
15
25
|
UnitProductPostResponse,
|
|
16
26
|
UnitProductPostBodyBody,
|
|
17
27
|
ProductUnitGetResponse,
|
|
18
28
|
ProductPatchBodyBody,
|
|
19
29
|
} from "../account-server-api.schemas";
|
|
30
|
+
import { customInstance, ErrorType } from ".././custom-instance";
|
|
20
31
|
|
|
21
|
-
|
|
22
|
-
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
type AsyncReturnType<T extends (...args: any) => Promise<any>> = T extends (
|
|
34
|
+
...args: any
|
|
35
|
+
) => Promise<infer R>
|
|
36
|
+
? R
|
|
37
|
+
: any;
|
|
38
|
+
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
type SecondParameter<T extends (...args: any) => any> = T extends (
|
|
41
|
+
config: any,
|
|
42
|
+
args: infer P
|
|
43
|
+
) => any
|
|
44
|
+
? P
|
|
45
|
+
: never;
|
|
46
|
+
|
|
47
|
+
/**
|
|
23
48
|
* Gets product types you can purchase
|
|
24
49
|
|
|
25
50
|
* @summary Gets all Product Types
|
|
26
51
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
52
|
+
export const getProductTypes = (
|
|
53
|
+
options?: SecondParameter<typeof customInstance>
|
|
54
|
+
) => {
|
|
55
|
+
return customInstance<ProductsGetTypesResponse>(
|
|
56
|
+
{ url: `/product-type`, method: "get" },
|
|
57
|
+
options
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const getGetProductTypesQueryKey = () => [`/product-type`];
|
|
62
|
+
|
|
63
|
+
export type GetProductTypesQueryResult = NonNullable<
|
|
64
|
+
AsyncReturnType<typeof getProductTypes>
|
|
65
|
+
>;
|
|
66
|
+
export type GetProductTypesQueryError = ErrorType<AsError | void>;
|
|
67
|
+
|
|
68
|
+
export const useGetProductTypes = <
|
|
69
|
+
TData = AsyncReturnType<typeof getProductTypes>,
|
|
70
|
+
TError = ErrorType<AsError | void>
|
|
71
|
+
>(options?: {
|
|
72
|
+
query?: UseQueryOptions<
|
|
73
|
+
AsyncReturnType<typeof getProductTypes>,
|
|
74
|
+
TError,
|
|
75
|
+
TData
|
|
76
|
+
>;
|
|
77
|
+
request?: SecondParameter<typeof customInstance>;
|
|
78
|
+
}): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
79
|
+
const { query: queryOptions, request: requestOptions } = options || {};
|
|
80
|
+
|
|
81
|
+
const queryKey = queryOptions?.queryKey ?? getGetProductTypesQueryKey();
|
|
82
|
+
|
|
83
|
+
const queryFn: QueryFunction<AsyncReturnType<typeof getProductTypes>> = () =>
|
|
84
|
+
getProductTypes(requestOptions);
|
|
85
|
+
|
|
86
|
+
const query = useQuery<
|
|
87
|
+
AsyncReturnType<typeof getProductTypes>,
|
|
88
|
+
TError,
|
|
89
|
+
TData
|
|
90
|
+
>(queryKey, queryFn, queryOptions);
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
queryKey,
|
|
94
|
+
...query,
|
|
33
95
|
};
|
|
34
|
-
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
35
99
|
* Gets products you have access to, across all Units and Organisations
|
|
36
100
|
|
|
37
101
|
* @summary Gets all Products
|
|
38
102
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
103
|
+
export const getProducts = (
|
|
104
|
+
options?: SecondParameter<typeof customInstance>
|
|
105
|
+
) => {
|
|
106
|
+
return customInstance<ProductsGetResponse>(
|
|
107
|
+
{ url: `/product`, method: "get" },
|
|
108
|
+
options
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const getGetProductsQueryKey = () => [`/product`];
|
|
113
|
+
|
|
114
|
+
export type GetProductsQueryResult = NonNullable<
|
|
115
|
+
AsyncReturnType<typeof getProducts>
|
|
116
|
+
>;
|
|
117
|
+
export type GetProductsQueryError = ErrorType<AsError | void>;
|
|
118
|
+
|
|
119
|
+
export const useGetProducts = <
|
|
120
|
+
TData = AsyncReturnType<typeof getProducts>,
|
|
121
|
+
TError = ErrorType<AsError | void>
|
|
122
|
+
>(options?: {
|
|
123
|
+
query?: UseQueryOptions<AsyncReturnType<typeof getProducts>, TError, TData>;
|
|
124
|
+
request?: SecondParameter<typeof customInstance>;
|
|
125
|
+
}): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
126
|
+
const { query: queryOptions, request: requestOptions } = options || {};
|
|
127
|
+
|
|
128
|
+
const queryKey = queryOptions?.queryKey ?? getGetProductsQueryKey();
|
|
129
|
+
|
|
130
|
+
const queryFn: QueryFunction<AsyncReturnType<typeof getProducts>> = () =>
|
|
131
|
+
getProducts(requestOptions);
|
|
132
|
+
|
|
133
|
+
const query = useQuery<AsyncReturnType<typeof getProducts>, TError, TData>(
|
|
134
|
+
queryKey,
|
|
135
|
+
queryFn,
|
|
136
|
+
queryOptions
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
queryKey,
|
|
141
|
+
...query,
|
|
43
142
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @summary Creates a Product for an Organisational Unit
|
|
147
|
+
*/
|
|
148
|
+
export const createUnitProduct = (
|
|
149
|
+
unitId: string,
|
|
150
|
+
unitProductPostBodyBody: UnitProductPostBodyBody,
|
|
151
|
+
options?: SecondParameter<typeof customInstance>
|
|
152
|
+
) => {
|
|
153
|
+
return customInstance<UnitProductPostResponse>(
|
|
154
|
+
{
|
|
155
|
+
url: `/product/unit/${unitId}`,
|
|
156
|
+
method: "post",
|
|
157
|
+
headers: { "Content-Type": "application/json" },
|
|
158
|
+
data: unitProductPostBodyBody,
|
|
159
|
+
},
|
|
160
|
+
options
|
|
161
|
+
);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export type CreateUnitProductMutationResult = NonNullable<
|
|
165
|
+
AsyncReturnType<typeof createUnitProduct>
|
|
166
|
+
>;
|
|
167
|
+
export type CreateUnitProductMutationBody = UnitProductPostBodyBody;
|
|
168
|
+
export type CreateUnitProductMutationError = ErrorType<AsError | void>;
|
|
169
|
+
|
|
170
|
+
export const useCreateUnitProduct = <
|
|
171
|
+
TError = ErrorType<AsError | void>,
|
|
172
|
+
TContext = unknown
|
|
173
|
+
>(options?: {
|
|
174
|
+
mutation?: UseMutationOptions<
|
|
175
|
+
AsyncReturnType<typeof createUnitProduct>,
|
|
176
|
+
TError,
|
|
177
|
+
{ unitId: string; data: UnitProductPostBodyBody },
|
|
178
|
+
TContext
|
|
179
|
+
>;
|
|
180
|
+
request?: SecondParameter<typeof customInstance>;
|
|
181
|
+
}) => {
|
|
182
|
+
const { mutation: mutationOptions, request: requestOptions } = options || {};
|
|
183
|
+
|
|
184
|
+
const mutationFn: MutationFunction<
|
|
185
|
+
AsyncReturnType<typeof createUnitProduct>,
|
|
186
|
+
{ unitId: string; data: UnitProductPostBodyBody }
|
|
187
|
+
> = (props) => {
|
|
188
|
+
const { unitId, data } = props || {};
|
|
189
|
+
|
|
190
|
+
return createUnitProduct(unitId, data, requestOptions);
|
|
57
191
|
};
|
|
58
|
-
|
|
192
|
+
|
|
193
|
+
return useMutation<
|
|
194
|
+
AsyncReturnType<typeof createUnitProduct>,
|
|
195
|
+
TError,
|
|
196
|
+
{ unitId: string; data: UnitProductPostBodyBody },
|
|
197
|
+
TContext
|
|
198
|
+
>(mutationFn, mutationOptions);
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
59
201
|
* Gets products you have access to based on an Organisational Unit
|
|
60
202
|
|
|
61
203
|
* @summary Gets Products for an Organisational Unit
|
|
62
204
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
205
|
+
export const getProductsForUnit = (
|
|
206
|
+
unitId: string,
|
|
207
|
+
options?: SecondParameter<typeof customInstance>
|
|
208
|
+
) => {
|
|
209
|
+
return customInstance<ProductsGetResponse>(
|
|
210
|
+
{ url: `/product/unit/${unitId}`, method: "get" },
|
|
211
|
+
options
|
|
212
|
+
);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export const getGetProductsForUnitQueryKey = (unitId: string) => [
|
|
216
|
+
`/product/unit/${unitId}`,
|
|
217
|
+
];
|
|
218
|
+
|
|
219
|
+
export type GetProductsForUnitQueryResult = NonNullable<
|
|
220
|
+
AsyncReturnType<typeof getProductsForUnit>
|
|
221
|
+
>;
|
|
222
|
+
export type GetProductsForUnitQueryError = ErrorType<void | AsError>;
|
|
223
|
+
|
|
224
|
+
export const useGetProductsForUnit = <
|
|
225
|
+
TData = AsyncReturnType<typeof getProductsForUnit>,
|
|
226
|
+
TError = ErrorType<void | AsError>
|
|
227
|
+
>(
|
|
228
|
+
unitId: string,
|
|
229
|
+
options?: {
|
|
230
|
+
query?: UseQueryOptions<
|
|
231
|
+
AsyncReturnType<typeof getProductsForUnit>,
|
|
232
|
+
TError,
|
|
233
|
+
TData
|
|
234
|
+
>;
|
|
235
|
+
request?: SecondParameter<typeof customInstance>;
|
|
236
|
+
}
|
|
237
|
+
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
238
|
+
const { query: queryOptions, request: requestOptions } = options || {};
|
|
239
|
+
|
|
240
|
+
const queryKey =
|
|
241
|
+
queryOptions?.queryKey ?? getGetProductsForUnitQueryKey(unitId);
|
|
242
|
+
|
|
243
|
+
const queryFn: QueryFunction<
|
|
244
|
+
AsyncReturnType<typeof getProductsForUnit>
|
|
245
|
+
> = () => getProductsForUnit(unitId, requestOptions);
|
|
246
|
+
|
|
247
|
+
const query = useQuery<
|
|
248
|
+
AsyncReturnType<typeof getProductsForUnit>,
|
|
249
|
+
TError,
|
|
250
|
+
TData
|
|
251
|
+
>(queryKey, queryFn, { enabled: !!unitId, ...queryOptions });
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
queryKey,
|
|
255
|
+
...query,
|
|
68
256
|
};
|
|
69
|
-
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
/**
|
|
70
260
|
* Gets a Unit's Product
|
|
71
261
|
|
|
72
262
|
* @summary Gets a Unit's Product
|
|
73
263
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
264
|
+
export const getProduct = (
|
|
265
|
+
unitId: string,
|
|
266
|
+
productId: string,
|
|
267
|
+
options?: SecondParameter<typeof customInstance>
|
|
268
|
+
) => {
|
|
269
|
+
return customInstance<ProductUnitGetResponse>(
|
|
270
|
+
{ url: `/product/unit/${unitId}/product/${productId}`, method: "get" },
|
|
271
|
+
options
|
|
272
|
+
);
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
export const getGetProductQueryKey = (unitId: string, productId: string) => [
|
|
276
|
+
`/product/unit/${unitId}/product/${productId}`,
|
|
277
|
+
];
|
|
278
|
+
|
|
279
|
+
export type GetProductQueryResult = NonNullable<
|
|
280
|
+
AsyncReturnType<typeof getProduct>
|
|
281
|
+
>;
|
|
282
|
+
export type GetProductQueryError = ErrorType<AsError | void>;
|
|
283
|
+
|
|
284
|
+
export const useGetProduct = <
|
|
285
|
+
TData = AsyncReturnType<typeof getProduct>,
|
|
286
|
+
TError = ErrorType<AsError | void>
|
|
287
|
+
>(
|
|
288
|
+
unitId: string,
|
|
289
|
+
productId: string,
|
|
290
|
+
options?: {
|
|
291
|
+
query?: UseQueryOptions<AsyncReturnType<typeof getProduct>, TError, TData>;
|
|
292
|
+
request?: SecondParameter<typeof customInstance>;
|
|
293
|
+
}
|
|
294
|
+
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
295
|
+
const { query: queryOptions, request: requestOptions } = options || {};
|
|
296
|
+
|
|
297
|
+
const queryKey =
|
|
298
|
+
queryOptions?.queryKey ?? getGetProductQueryKey(unitId, productId);
|
|
299
|
+
|
|
300
|
+
const queryFn: QueryFunction<AsyncReturnType<typeof getProduct>> = () =>
|
|
301
|
+
getProduct(unitId, productId, requestOptions);
|
|
302
|
+
|
|
303
|
+
const query = useQuery<AsyncReturnType<typeof getProduct>, TError, TData>(
|
|
304
|
+
queryKey,
|
|
305
|
+
queryFn,
|
|
306
|
+
{ enabled: !!(unitId && productId), ...queryOptions }
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
return {
|
|
310
|
+
queryKey,
|
|
311
|
+
...query,
|
|
82
312
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* @summary Deletes an existing Product
|
|
317
|
+
*/
|
|
318
|
+
export const deleteProduct = (
|
|
319
|
+
unitId: string,
|
|
320
|
+
productId: string,
|
|
321
|
+
options?: SecondParameter<typeof customInstance>
|
|
322
|
+
) => {
|
|
323
|
+
return customInstance<void>(
|
|
324
|
+
{ url: `/product/unit/${unitId}/product/${productId}`, method: "delete" },
|
|
325
|
+
options
|
|
326
|
+
);
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
export type DeleteProductMutationResult = NonNullable<
|
|
330
|
+
AsyncReturnType<typeof deleteProduct>
|
|
331
|
+
>;
|
|
332
|
+
|
|
333
|
+
export type DeleteProductMutationError = ErrorType<AsError>;
|
|
334
|
+
|
|
335
|
+
export const useDeleteProduct = <
|
|
336
|
+
TError = ErrorType<AsError>,
|
|
337
|
+
TContext = unknown
|
|
338
|
+
>(options?: {
|
|
339
|
+
mutation?: UseMutationOptions<
|
|
340
|
+
AsyncReturnType<typeof deleteProduct>,
|
|
341
|
+
TError,
|
|
342
|
+
{ unitId: string; productId: string },
|
|
343
|
+
TContext
|
|
344
|
+
>;
|
|
345
|
+
request?: SecondParameter<typeof customInstance>;
|
|
346
|
+
}) => {
|
|
347
|
+
const { mutation: mutationOptions, request: requestOptions } = options || {};
|
|
348
|
+
|
|
349
|
+
const mutationFn: MutationFunction<
|
|
350
|
+
AsyncReturnType<typeof deleteProduct>,
|
|
351
|
+
{ unitId: string; productId: string }
|
|
352
|
+
> = (props) => {
|
|
353
|
+
const { unitId, productId } = props || {};
|
|
354
|
+
|
|
355
|
+
return deleteProduct(unitId, productId, requestOptions);
|
|
95
356
|
};
|
|
96
|
-
|
|
357
|
+
|
|
358
|
+
return useMutation<
|
|
359
|
+
AsyncReturnType<typeof deleteProduct>,
|
|
360
|
+
TError,
|
|
361
|
+
{ unitId: string; productId: string },
|
|
362
|
+
TContext
|
|
363
|
+
>(mutationFn, mutationOptions);
|
|
364
|
+
};
|
|
365
|
+
/**
|
|
97
366
|
* Used to update some adjustable parameters of a Product, i.e. to extend the Allowance or Limit. At the moment Data Manager products can be patched by changing the `name`, it's coin `allowance` or `limit`
|
|
98
367
|
|
|
99
368
|
* @summary Adjust an existing Product
|
|
100
369
|
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
370
|
+
export const patchProduct = (
|
|
371
|
+
unitId: string,
|
|
372
|
+
productId: string,
|
|
373
|
+
productPatchBodyBody: ProductPatchBodyBody,
|
|
374
|
+
options?: SecondParameter<typeof customInstance>
|
|
375
|
+
) => {
|
|
376
|
+
return customInstance<void>(
|
|
377
|
+
{
|
|
378
|
+
url: `/product/unit/${unitId}/product/${productId}`,
|
|
379
|
+
method: "patch",
|
|
380
|
+
headers: { "Content-Type": "application/json" },
|
|
381
|
+
data: productPatchBodyBody,
|
|
382
|
+
},
|
|
383
|
+
options
|
|
384
|
+
);
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
export type PatchProductMutationResult = NonNullable<
|
|
388
|
+
AsyncReturnType<typeof patchProduct>
|
|
389
|
+
>;
|
|
390
|
+
export type PatchProductMutationBody = ProductPatchBodyBody;
|
|
391
|
+
export type PatchProductMutationError = ErrorType<AsError>;
|
|
392
|
+
|
|
393
|
+
export const usePatchProduct = <
|
|
394
|
+
TError = ErrorType<AsError>,
|
|
395
|
+
TContext = unknown
|
|
396
|
+
>(options?: {
|
|
397
|
+
mutation?: UseMutationOptions<
|
|
398
|
+
AsyncReturnType<typeof patchProduct>,
|
|
399
|
+
TError,
|
|
400
|
+
{ unitId: string; productId: string; data: ProductPatchBodyBody },
|
|
401
|
+
TContext
|
|
402
|
+
>;
|
|
403
|
+
request?: SecondParameter<typeof customInstance>;
|
|
404
|
+
}) => {
|
|
405
|
+
const { mutation: mutationOptions, request: requestOptions } = options || {};
|
|
406
|
+
|
|
407
|
+
const mutationFn: MutationFunction<
|
|
408
|
+
AsyncReturnType<typeof patchProduct>,
|
|
409
|
+
{ unitId: string; productId: string; data: ProductPatchBodyBody }
|
|
410
|
+
> = (props) => {
|
|
411
|
+
const { unitId, productId, data } = props || {};
|
|
412
|
+
|
|
413
|
+
return patchProduct(unitId, productId, data, requestOptions);
|
|
121
414
|
};
|
|
415
|
+
|
|
416
|
+
return useMutation<
|
|
417
|
+
AsyncReturnType<typeof patchProduct>,
|
|
418
|
+
TError,
|
|
419
|
+
{ unitId: string; productId: string; data: ProductPatchBodyBody },
|
|
420
|
+
TContext
|
|
421
|
+
>(mutationFn, mutationOptions);
|
|
122
422
|
};
|
|
123
|
-
export type AppApiProductGetTypesResult =
|
|
124
|
-
AxiosResponse<ProductsGetTypesResponse>;
|
|
125
|
-
export type AppApiProductGetResult = AxiosResponse<ProductsGetResponse>;
|
|
126
|
-
export type AppApiProductPostResult = AxiosResponse<UnitProductPostResponse>;
|
|
127
|
-
export type AppApiProductGetForUnitResult = AxiosResponse<ProductsGetResponse>;
|
|
128
|
-
export type AppApiProductGetUnitProductResult =
|
|
129
|
-
AxiosResponse<ProductUnitGetResponse>;
|
|
130
|
-
export type AppApiProductDeleteResult = AxiosResponse<void>;
|
|
131
|
-
export type AppApiProductPatchResult = AxiosResponse<void>;
|
package/src/service/service.ts
CHANGED
|
@@ -8,35 +8,129 @@ A service that provides access to the Account Server, which gives *registered* u
|
|
|
8
8
|
|
|
9
9
|
* OpenAPI spec version: 0.1
|
|
10
10
|
*/
|
|
11
|
-
import
|
|
11
|
+
import {
|
|
12
|
+
useQuery,
|
|
13
|
+
UseQueryOptions,
|
|
14
|
+
QueryFunction,
|
|
15
|
+
UseQueryResult,
|
|
16
|
+
QueryKey,
|
|
17
|
+
} from "react-query";
|
|
12
18
|
import type {
|
|
13
19
|
ServicesGetResponse,
|
|
20
|
+
AsError,
|
|
14
21
|
ServiceGetResponse,
|
|
15
22
|
} from "../account-server-api.schemas";
|
|
23
|
+
import { customInstance, ErrorType } from ".././custom-instance";
|
|
16
24
|
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
type AsyncReturnType<T extends (...args: any) => Promise<any>> = T extends (
|
|
27
|
+
...args: any
|
|
28
|
+
) => Promise<infer R>
|
|
29
|
+
? R
|
|
30
|
+
: any;
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
type SecondParameter<T extends (...args: any) => any> = T extends (
|
|
34
|
+
config: any,
|
|
35
|
+
args: infer P
|
|
36
|
+
) => any
|
|
37
|
+
? P
|
|
38
|
+
: never;
|
|
39
|
+
|
|
40
|
+
/**
|
|
19
41
|
* Gets services known to the Account Server
|
|
20
42
|
|
|
21
43
|
* @summary Gets all Services
|
|
22
44
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
45
|
+
export const getServices = (
|
|
46
|
+
options?: SecondParameter<typeof customInstance>
|
|
47
|
+
) => {
|
|
48
|
+
return customInstance<ServicesGetResponse>(
|
|
49
|
+
{ url: `/service`, method: "get" },
|
|
50
|
+
options
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const getGetServicesQueryKey = () => [`/service`];
|
|
55
|
+
|
|
56
|
+
export type GetServicesQueryResult = NonNullable<
|
|
57
|
+
AsyncReturnType<typeof getServices>
|
|
58
|
+
>;
|
|
59
|
+
export type GetServicesQueryError = ErrorType<AsError | void>;
|
|
60
|
+
|
|
61
|
+
export const useGetServices = <
|
|
62
|
+
TData = AsyncReturnType<typeof getServices>,
|
|
63
|
+
TError = ErrorType<AsError | void>
|
|
64
|
+
>(options?: {
|
|
65
|
+
query?: UseQueryOptions<AsyncReturnType<typeof getServices>, TError, TData>;
|
|
66
|
+
request?: SecondParameter<typeof customInstance>;
|
|
67
|
+
}): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
68
|
+
const { query: queryOptions, request: requestOptions } = options || {};
|
|
69
|
+
|
|
70
|
+
const queryKey = queryOptions?.queryKey ?? getGetServicesQueryKey();
|
|
71
|
+
|
|
72
|
+
const queryFn: QueryFunction<AsyncReturnType<typeof getServices>> = () =>
|
|
73
|
+
getServices(requestOptions);
|
|
74
|
+
|
|
75
|
+
const query = useQuery<AsyncReturnType<typeof getServices>, TError, TData>(
|
|
76
|
+
queryKey,
|
|
77
|
+
queryFn,
|
|
78
|
+
queryOptions
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
queryKey,
|
|
83
|
+
...query,
|
|
27
84
|
};
|
|
28
|
-
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
29
88
|
* Gets a known service
|
|
30
89
|
|
|
31
90
|
* @summary Gets a specific Service
|
|
32
91
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
92
|
+
export const getService = (
|
|
93
|
+
svcId: number,
|
|
94
|
+
options?: SecondParameter<typeof customInstance>
|
|
95
|
+
) => {
|
|
96
|
+
return customInstance<ServiceGetResponse>(
|
|
97
|
+
{ url: `/service/${svcId}`, method: "get" },
|
|
98
|
+
options
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const getGetServiceQueryKey = (svcId: number) => [`/service/${svcId}`];
|
|
103
|
+
|
|
104
|
+
export type GetServiceQueryResult = NonNullable<
|
|
105
|
+
AsyncReturnType<typeof getService>
|
|
106
|
+
>;
|
|
107
|
+
export type GetServiceQueryError = ErrorType<AsError | void>;
|
|
108
|
+
|
|
109
|
+
export const useGetService = <
|
|
110
|
+
TData = AsyncReturnType<typeof getService>,
|
|
111
|
+
TError = ErrorType<AsError | void>
|
|
112
|
+
>(
|
|
113
|
+
svcId: number,
|
|
114
|
+
options?: {
|
|
115
|
+
query?: UseQueryOptions<AsyncReturnType<typeof getService>, TError, TData>;
|
|
116
|
+
request?: SecondParameter<typeof customInstance>;
|
|
117
|
+
}
|
|
118
|
+
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
119
|
+
const { query: queryOptions, request: requestOptions } = options || {};
|
|
120
|
+
|
|
121
|
+
const queryKey = queryOptions?.queryKey ?? getGetServiceQueryKey(svcId);
|
|
122
|
+
|
|
123
|
+
const queryFn: QueryFunction<AsyncReturnType<typeof getService>> = () =>
|
|
124
|
+
getService(svcId, requestOptions);
|
|
125
|
+
|
|
126
|
+
const query = useQuery<AsyncReturnType<typeof getService>, TError, TData>(
|
|
127
|
+
queryKey,
|
|
128
|
+
queryFn,
|
|
129
|
+
{ enabled: !!svcId, ...queryOptions }
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
queryKey,
|
|
134
|
+
...query,
|
|
38
135
|
};
|
|
39
|
-
return { appApiServiceGet, appApiServiceGetId };
|
|
40
136
|
};
|
|
41
|
-
export type AppApiServiceGetResult = AxiosResponse<ServicesGetResponse>;
|
|
42
|
-
export type AppApiServiceGetIdResult = AxiosResponse<ServiceGetResponse>;
|