@squonk/account-server-client 0.1.31-rc.1 → 0.1.32-rc.2
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/asset/asset.cjs +133 -0
- package/asset/asset.cjs.map +1 -0
- package/asset/asset.d.ts +126 -0
- package/asset/asset.js +133 -0
- package/asset/asset.js.map +1 -0
- package/asset/package.json +7 -0
- package/{custom-instance-13412a15.d.ts → custom-instance-b985e1be.d.ts} +127 -40
- package/index.cjs +20 -2
- package/index.cjs.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +20 -2
- package/index.js.map +1 -1
- package/merchant/merchant.cjs +48 -0
- package/merchant/merchant.cjs.map +1 -0
- package/merchant/merchant.d.ts +39 -0
- package/merchant/merchant.js +48 -0
- package/merchant/merchant.js.map +1 -0
- package/merchant/package.json +7 -0
- package/organisation/organisation.cjs +12 -12
- package/organisation/organisation.cjs.map +1 -1
- package/organisation/organisation.d.ts +10 -9
- package/organisation/organisation.js +12 -12
- package/organisation/organisation.js.map +1 -1
- package/package.json +9 -9
- package/product/product.cjs +36 -26
- package/product/product.cjs.map +1 -1
- package/product/product.d.ts +23 -16
- package/product/product.js +36 -26
- package/product/product.js.map +1 -1
- package/src/account-server-api.schemas.ts +155 -52
- package/src/asset/asset.ts +433 -0
- package/src/merchant/merchant.ts +145 -0
- package/src/organisation/organisation.ts +37 -37
- package/src/product/product.ts +97 -74
- package/src/state/state.ts +19 -16
- package/src/unit/unit.ts +64 -56
- package/src/user/user.ts +63 -62
- package/state/state.cjs +6 -4
- package/state/state.cjs.map +1 -1
- package/state/state.d.ts +7 -6
- package/state/state.js +6 -4
- package/state/state.js.map +1 -1
- package/unit/unit.cjs +22 -18
- package/unit/unit.cjs.map +1 -1
- package/unit/unit.d.ts +16 -15
- package/unit/unit.js +22 -18
- package/unit/unit.js.map +1 -1
- package/user/user.cjs +22 -20
- package/user/user.cjs.map +1 -1
- package/user/user.d.ts +14 -13
- package/user/user.js +22 -20
- package/user/user.js.map +1 -1
- package/service/package.json +0 -7
- package/service/service.cjs +0 -44
- package/service/service.cjs.map +0 -1
- package/service/service.d.ts +0 -49
- package/service/service.js +0 -44
- package/service/service.js.map +0 -1
- package/src/service/service.ts +0 -136
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by orval v6.8.0 🍺
|
|
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
|
+
AssetGetResponse,
|
|
23
|
+
AsError,
|
|
24
|
+
GetAssetParams,
|
|
25
|
+
AssetPostResponse,
|
|
26
|
+
AssetPostBodyBody,
|
|
27
|
+
AttachAssetParams,
|
|
28
|
+
DetachAssetParams,
|
|
29
|
+
} from "../account-server-api.schemas";
|
|
30
|
+
import { customInstance, ErrorType } from ".././custom-instance";
|
|
31
|
+
|
|
32
|
+
export type AwaitedInput<T> = PromiseLike<T> | T;
|
|
33
|
+
|
|
34
|
+
export type Awaited<O> = O extends AwaitedInput<infer T> ? T : never;
|
|
35
|
+
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
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 Assets
|
|
46
|
+
|
|
47
|
+
* @summary Gets Assets
|
|
48
|
+
*/
|
|
49
|
+
export const getAsset = (
|
|
50
|
+
params?: GetAssetParams,
|
|
51
|
+
options?: SecondParameter<typeof customInstance>,
|
|
52
|
+
signal?: AbortSignal
|
|
53
|
+
) => {
|
|
54
|
+
return customInstance<AssetGetResponse>(
|
|
55
|
+
{ url: `/asset`, method: "get", signal, params },
|
|
56
|
+
options
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const getGetAssetQueryKey = (params?: GetAssetParams) => [
|
|
61
|
+
`/asset`,
|
|
62
|
+
...(params ? [params] : []),
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
export type GetAssetQueryResult = NonNullable<
|
|
66
|
+
Awaited<ReturnType<typeof getAsset>>
|
|
67
|
+
>;
|
|
68
|
+
export type GetAssetQueryError = ErrorType<AsError | void>;
|
|
69
|
+
|
|
70
|
+
export const useGetAsset = <
|
|
71
|
+
TData = Awaited<ReturnType<typeof getAsset>>,
|
|
72
|
+
TError = ErrorType<AsError | void>
|
|
73
|
+
>(
|
|
74
|
+
params?: GetAssetParams,
|
|
75
|
+
options?: {
|
|
76
|
+
query?: UseQueryOptions<
|
|
77
|
+
Awaited<ReturnType<typeof getAsset>>,
|
|
78
|
+
TError,
|
|
79
|
+
TData
|
|
80
|
+
>;
|
|
81
|
+
request?: SecondParameter<typeof customInstance>;
|
|
82
|
+
}
|
|
83
|
+
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
84
|
+
const { query: queryOptions, request: requestOptions } = options ?? {};
|
|
85
|
+
|
|
86
|
+
const queryKey = queryOptions?.queryKey ?? getGetAssetQueryKey(params);
|
|
87
|
+
|
|
88
|
+
const queryFn: QueryFunction<Awaited<ReturnType<typeof getAsset>>> = ({
|
|
89
|
+
signal,
|
|
90
|
+
}) => getAsset(params, requestOptions, signal);
|
|
91
|
+
|
|
92
|
+
const query = useQuery<Awaited<ReturnType<typeof getAsset>>, TError, TData>(
|
|
93
|
+
queryKey,
|
|
94
|
+
queryFn,
|
|
95
|
+
queryOptions
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
queryKey,
|
|
100
|
+
...query,
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Creates an Asset, which can be attached to our User account, or a Product, Unit or Organisation you have access to
|
|
106
|
+
|
|
107
|
+
* @summary Create an Asset
|
|
108
|
+
*/
|
|
109
|
+
export const createAsset = (
|
|
110
|
+
assetPostBodyBody: AssetPostBodyBody,
|
|
111
|
+
options?: SecondParameter<typeof customInstance>
|
|
112
|
+
) => {
|
|
113
|
+
const formData = new FormData();
|
|
114
|
+
formData.append("name", assetPostBodyBody.name);
|
|
115
|
+
if (assetPostBodyBody.content_file !== undefined) {
|
|
116
|
+
formData.append("content_file", assetPostBodyBody.content_file);
|
|
117
|
+
}
|
|
118
|
+
if (assetPostBodyBody.content_string !== undefined) {
|
|
119
|
+
formData.append("content_string", assetPostBodyBody.content_string);
|
|
120
|
+
}
|
|
121
|
+
formData.append("scope", assetPostBodyBody.scope);
|
|
122
|
+
if (assetPostBodyBody.scope_id !== undefined) {
|
|
123
|
+
formData.append("scope_id", assetPostBodyBody.scope_id);
|
|
124
|
+
}
|
|
125
|
+
formData.append("secret", assetPostBodyBody.secret.toString());
|
|
126
|
+
if (assetPostBodyBody.description !== undefined) {
|
|
127
|
+
formData.append("description", assetPostBodyBody.description);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return customInstance<AssetPostResponse>(
|
|
131
|
+
{
|
|
132
|
+
url: `/asset`,
|
|
133
|
+
method: "post",
|
|
134
|
+
headers: { "Content-Type": "multipart/form-data" },
|
|
135
|
+
data: formData,
|
|
136
|
+
},
|
|
137
|
+
options
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export type CreateAssetMutationResult = NonNullable<
|
|
142
|
+
Awaited<ReturnType<typeof createAsset>>
|
|
143
|
+
>;
|
|
144
|
+
export type CreateAssetMutationBody = AssetPostBodyBody;
|
|
145
|
+
export type CreateAssetMutationError = ErrorType<AsError | void>;
|
|
146
|
+
|
|
147
|
+
export const useCreateAsset = <
|
|
148
|
+
TError = ErrorType<AsError | void>,
|
|
149
|
+
TContext = unknown
|
|
150
|
+
>(options?: {
|
|
151
|
+
mutation?: UseMutationOptions<
|
|
152
|
+
Awaited<ReturnType<typeof createAsset>>,
|
|
153
|
+
TError,
|
|
154
|
+
{ data: AssetPostBodyBody },
|
|
155
|
+
TContext
|
|
156
|
+
>;
|
|
157
|
+
request?: SecondParameter<typeof customInstance>;
|
|
158
|
+
}) => {
|
|
159
|
+
const { mutation: mutationOptions, request: requestOptions } = options ?? {};
|
|
160
|
+
|
|
161
|
+
const mutationFn: MutationFunction<
|
|
162
|
+
Awaited<ReturnType<typeof createAsset>>,
|
|
163
|
+
{ data: AssetPostBodyBody }
|
|
164
|
+
> = (props) => {
|
|
165
|
+
const { data } = props ?? {};
|
|
166
|
+
|
|
167
|
+
return createAsset(data, requestOptions);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
return useMutation<
|
|
171
|
+
Awaited<ReturnType<typeof createAsset>>,
|
|
172
|
+
TError,
|
|
173
|
+
{ data: AssetPostBodyBody },
|
|
174
|
+
TContext
|
|
175
|
+
>(mutationFn, mutationOptions);
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Deletes a known Asset. Assets that are attached to merchants cannot be deleted
|
|
179
|
+
|
|
180
|
+
* @summary Deletes an Asset
|
|
181
|
+
*/
|
|
182
|
+
export const deleteAsset = (
|
|
183
|
+
assetId: string,
|
|
184
|
+
options?: SecondParameter<typeof customInstance>
|
|
185
|
+
) => {
|
|
186
|
+
return customInstance<void>(
|
|
187
|
+
{ url: `/asset/${assetId}`, method: "delete" },
|
|
188
|
+
options
|
|
189
|
+
);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export type DeleteAssetMutationResult = NonNullable<
|
|
193
|
+
Awaited<ReturnType<typeof deleteAsset>>
|
|
194
|
+
>;
|
|
195
|
+
|
|
196
|
+
export type DeleteAssetMutationError = ErrorType<AsError>;
|
|
197
|
+
|
|
198
|
+
export const useDeleteAsset = <
|
|
199
|
+
TError = ErrorType<AsError>,
|
|
200
|
+
TContext = unknown
|
|
201
|
+
>(options?: {
|
|
202
|
+
mutation?: UseMutationOptions<
|
|
203
|
+
Awaited<ReturnType<typeof deleteAsset>>,
|
|
204
|
+
TError,
|
|
205
|
+
{ assetId: string },
|
|
206
|
+
TContext
|
|
207
|
+
>;
|
|
208
|
+
request?: SecondParameter<typeof customInstance>;
|
|
209
|
+
}) => {
|
|
210
|
+
const { mutation: mutationOptions, request: requestOptions } = options ?? {};
|
|
211
|
+
|
|
212
|
+
const mutationFn: MutationFunction<
|
|
213
|
+
Awaited<ReturnType<typeof deleteAsset>>,
|
|
214
|
+
{ assetId: string }
|
|
215
|
+
> = (props) => {
|
|
216
|
+
const { assetId } = props ?? {};
|
|
217
|
+
|
|
218
|
+
return deleteAsset(assetId, requestOptions);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
return useMutation<
|
|
222
|
+
Awaited<ReturnType<typeof deleteAsset>>,
|
|
223
|
+
TError,
|
|
224
|
+
{ assetId: string },
|
|
225
|
+
TContext
|
|
226
|
+
>(mutationFn, mutationOptions);
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Disables a known Asset
|
|
230
|
+
|
|
231
|
+
* @summary Disables an Asset
|
|
232
|
+
*/
|
|
233
|
+
export const disableAsset = (
|
|
234
|
+
assetId: string,
|
|
235
|
+
options?: SecondParameter<typeof customInstance>
|
|
236
|
+
) => {
|
|
237
|
+
return customInstance<void>(
|
|
238
|
+
{ url: `/asset/${assetId}/disable`, method: "patch" },
|
|
239
|
+
options
|
|
240
|
+
);
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
export type DisableAssetMutationResult = NonNullable<
|
|
244
|
+
Awaited<ReturnType<typeof disableAsset>>
|
|
245
|
+
>;
|
|
246
|
+
|
|
247
|
+
export type DisableAssetMutationError = ErrorType<AsError>;
|
|
248
|
+
|
|
249
|
+
export const useDisableAsset = <
|
|
250
|
+
TError = ErrorType<AsError>,
|
|
251
|
+
TContext = unknown
|
|
252
|
+
>(options?: {
|
|
253
|
+
mutation?: UseMutationOptions<
|
|
254
|
+
Awaited<ReturnType<typeof disableAsset>>,
|
|
255
|
+
TError,
|
|
256
|
+
{ assetId: string },
|
|
257
|
+
TContext
|
|
258
|
+
>;
|
|
259
|
+
request?: SecondParameter<typeof customInstance>;
|
|
260
|
+
}) => {
|
|
261
|
+
const { mutation: mutationOptions, request: requestOptions } = options ?? {};
|
|
262
|
+
|
|
263
|
+
const mutationFn: MutationFunction<
|
|
264
|
+
Awaited<ReturnType<typeof disableAsset>>,
|
|
265
|
+
{ assetId: string }
|
|
266
|
+
> = (props) => {
|
|
267
|
+
const { assetId } = props ?? {};
|
|
268
|
+
|
|
269
|
+
return disableAsset(assetId, requestOptions);
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
return useMutation<
|
|
273
|
+
Awaited<ReturnType<typeof disableAsset>>,
|
|
274
|
+
TError,
|
|
275
|
+
{ assetId: string },
|
|
276
|
+
TContext
|
|
277
|
+
>(mutationFn, mutationOptions);
|
|
278
|
+
};
|
|
279
|
+
/**
|
|
280
|
+
* Enables a known Asset
|
|
281
|
+
|
|
282
|
+
* @summary Enables an Asset
|
|
283
|
+
*/
|
|
284
|
+
export const enableAsset = (
|
|
285
|
+
assetId: string,
|
|
286
|
+
options?: SecondParameter<typeof customInstance>
|
|
287
|
+
) => {
|
|
288
|
+
return customInstance<void>(
|
|
289
|
+
{ url: `/asset/${assetId}/enable`, method: "patch" },
|
|
290
|
+
options
|
|
291
|
+
);
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
export type EnableAssetMutationResult = NonNullable<
|
|
295
|
+
Awaited<ReturnType<typeof enableAsset>>
|
|
296
|
+
>;
|
|
297
|
+
|
|
298
|
+
export type EnableAssetMutationError = ErrorType<AsError>;
|
|
299
|
+
|
|
300
|
+
export const useEnableAsset = <
|
|
301
|
+
TError = ErrorType<AsError>,
|
|
302
|
+
TContext = unknown
|
|
303
|
+
>(options?: {
|
|
304
|
+
mutation?: UseMutationOptions<
|
|
305
|
+
Awaited<ReturnType<typeof enableAsset>>,
|
|
306
|
+
TError,
|
|
307
|
+
{ assetId: string },
|
|
308
|
+
TContext
|
|
309
|
+
>;
|
|
310
|
+
request?: SecondParameter<typeof customInstance>;
|
|
311
|
+
}) => {
|
|
312
|
+
const { mutation: mutationOptions, request: requestOptions } = options ?? {};
|
|
313
|
+
|
|
314
|
+
const mutationFn: MutationFunction<
|
|
315
|
+
Awaited<ReturnType<typeof enableAsset>>,
|
|
316
|
+
{ assetId: string }
|
|
317
|
+
> = (props) => {
|
|
318
|
+
const { assetId } = props ?? {};
|
|
319
|
+
|
|
320
|
+
return enableAsset(assetId, requestOptions);
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
return useMutation<
|
|
324
|
+
Awaited<ReturnType<typeof enableAsset>>,
|
|
325
|
+
TError,
|
|
326
|
+
{ assetId: string },
|
|
327
|
+
TContext
|
|
328
|
+
>(mutationFn, mutationOptions);
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* Attaches an Asset to a merchant
|
|
332
|
+
|
|
333
|
+
* @summary Attaches an Asset to a Merchant
|
|
334
|
+
*/
|
|
335
|
+
export const attachAsset = (
|
|
336
|
+
assetId: string,
|
|
337
|
+
params?: AttachAssetParams,
|
|
338
|
+
options?: SecondParameter<typeof customInstance>
|
|
339
|
+
) => {
|
|
340
|
+
return customInstance<void>(
|
|
341
|
+
{ url: `/asset/${assetId}/attach`, method: "patch", params },
|
|
342
|
+
options
|
|
343
|
+
);
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
export type AttachAssetMutationResult = NonNullable<
|
|
347
|
+
Awaited<ReturnType<typeof attachAsset>>
|
|
348
|
+
>;
|
|
349
|
+
|
|
350
|
+
export type AttachAssetMutationError = ErrorType<AsError>;
|
|
351
|
+
|
|
352
|
+
export const useAttachAsset = <
|
|
353
|
+
TError = ErrorType<AsError>,
|
|
354
|
+
TContext = unknown
|
|
355
|
+
>(options?: {
|
|
356
|
+
mutation?: UseMutationOptions<
|
|
357
|
+
Awaited<ReturnType<typeof attachAsset>>,
|
|
358
|
+
TError,
|
|
359
|
+
{ assetId: string; params?: AttachAssetParams },
|
|
360
|
+
TContext
|
|
361
|
+
>;
|
|
362
|
+
request?: SecondParameter<typeof customInstance>;
|
|
363
|
+
}) => {
|
|
364
|
+
const { mutation: mutationOptions, request: requestOptions } = options ?? {};
|
|
365
|
+
|
|
366
|
+
const mutationFn: MutationFunction<
|
|
367
|
+
Awaited<ReturnType<typeof attachAsset>>,
|
|
368
|
+
{ assetId: string; params?: AttachAssetParams }
|
|
369
|
+
> = (props) => {
|
|
370
|
+
const { assetId, params } = props ?? {};
|
|
371
|
+
|
|
372
|
+
return attachAsset(assetId, params, requestOptions);
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
return useMutation<
|
|
376
|
+
Awaited<ReturnType<typeof attachAsset>>,
|
|
377
|
+
TError,
|
|
378
|
+
{ assetId: string; params?: AttachAssetParams },
|
|
379
|
+
TContext
|
|
380
|
+
>(mutationFn, mutationOptions);
|
|
381
|
+
};
|
|
382
|
+
/**
|
|
383
|
+
* Detaches an Asset from a merchant
|
|
384
|
+
|
|
385
|
+
* @summary Detaches an Asset from a Merchant
|
|
386
|
+
*/
|
|
387
|
+
export const detachAsset = (
|
|
388
|
+
assetId: string,
|
|
389
|
+
params?: DetachAssetParams,
|
|
390
|
+
options?: SecondParameter<typeof customInstance>
|
|
391
|
+
) => {
|
|
392
|
+
return customInstance<void>(
|
|
393
|
+
{ url: `/asset/${assetId}/detach`, method: "patch", params },
|
|
394
|
+
options
|
|
395
|
+
);
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
export type DetachAssetMutationResult = NonNullable<
|
|
399
|
+
Awaited<ReturnType<typeof detachAsset>>
|
|
400
|
+
>;
|
|
401
|
+
|
|
402
|
+
export type DetachAssetMutationError = ErrorType<AsError>;
|
|
403
|
+
|
|
404
|
+
export const useDetachAsset = <
|
|
405
|
+
TError = ErrorType<AsError>,
|
|
406
|
+
TContext = unknown
|
|
407
|
+
>(options?: {
|
|
408
|
+
mutation?: UseMutationOptions<
|
|
409
|
+
Awaited<ReturnType<typeof detachAsset>>,
|
|
410
|
+
TError,
|
|
411
|
+
{ assetId: string; params?: DetachAssetParams },
|
|
412
|
+
TContext
|
|
413
|
+
>;
|
|
414
|
+
request?: SecondParameter<typeof customInstance>;
|
|
415
|
+
}) => {
|
|
416
|
+
const { mutation: mutationOptions, request: requestOptions } = options ?? {};
|
|
417
|
+
|
|
418
|
+
const mutationFn: MutationFunction<
|
|
419
|
+
Awaited<ReturnType<typeof detachAsset>>,
|
|
420
|
+
{ assetId: string; params?: DetachAssetParams }
|
|
421
|
+
> = (props) => {
|
|
422
|
+
const { assetId, params } = props ?? {};
|
|
423
|
+
|
|
424
|
+
return detachAsset(assetId, params, requestOptions);
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
return useMutation<
|
|
428
|
+
Awaited<ReturnType<typeof detachAsset>>,
|
|
429
|
+
TError,
|
|
430
|
+
{ assetId: string; params?: DetachAssetParams },
|
|
431
|
+
TContext
|
|
432
|
+
>(mutationFn, mutationOptions);
|
|
433
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by orval v6.8.0 🍺
|
|
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
|
+
MerchantsGetResponse,
|
|
20
|
+
AsError,
|
|
21
|
+
MerchantGetResponse,
|
|
22
|
+
} from "../account-server-api.schemas";
|
|
23
|
+
import { customInstance, ErrorType } from ".././custom-instance";
|
|
24
|
+
|
|
25
|
+
export type AwaitedInput<T> = PromiseLike<T> | T;
|
|
26
|
+
|
|
27
|
+
export type Awaited<O> = O extends AwaitedInput<infer T> ? T : never;
|
|
28
|
+
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
type SecondParameter<T extends (...args: any) => any> = T extends (
|
|
31
|
+
config: any,
|
|
32
|
+
args: infer P
|
|
33
|
+
) => any
|
|
34
|
+
? P
|
|
35
|
+
: never;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Gets merchants known to the Account Server
|
|
39
|
+
|
|
40
|
+
* @summary Gets all Merchants
|
|
41
|
+
*/
|
|
42
|
+
export const getMerchants = (
|
|
43
|
+
options?: SecondParameter<typeof customInstance>,
|
|
44
|
+
signal?: AbortSignal
|
|
45
|
+
) => {
|
|
46
|
+
return customInstance<MerchantsGetResponse>(
|
|
47
|
+
{ url: `/merchant`, method: "get", signal },
|
|
48
|
+
options
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const getGetMerchantsQueryKey = () => [`/merchant`];
|
|
53
|
+
|
|
54
|
+
export type GetMerchantsQueryResult = NonNullable<
|
|
55
|
+
Awaited<ReturnType<typeof getMerchants>>
|
|
56
|
+
>;
|
|
57
|
+
export type GetMerchantsQueryError = ErrorType<AsError | void>;
|
|
58
|
+
|
|
59
|
+
export const useGetMerchants = <
|
|
60
|
+
TData = Awaited<ReturnType<typeof getMerchants>>,
|
|
61
|
+
TError = ErrorType<AsError | void>
|
|
62
|
+
>(options?: {
|
|
63
|
+
query?: UseQueryOptions<
|
|
64
|
+
Awaited<ReturnType<typeof getMerchants>>,
|
|
65
|
+
TError,
|
|
66
|
+
TData
|
|
67
|
+
>;
|
|
68
|
+
request?: SecondParameter<typeof customInstance>;
|
|
69
|
+
}): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
70
|
+
const { query: queryOptions, request: requestOptions } = options ?? {};
|
|
71
|
+
|
|
72
|
+
const queryKey = queryOptions?.queryKey ?? getGetMerchantsQueryKey();
|
|
73
|
+
|
|
74
|
+
const queryFn: QueryFunction<Awaited<ReturnType<typeof getMerchants>>> = ({
|
|
75
|
+
signal,
|
|
76
|
+
}) => getMerchants(requestOptions, signal);
|
|
77
|
+
|
|
78
|
+
const query = useQuery<
|
|
79
|
+
Awaited<ReturnType<typeof getMerchants>>,
|
|
80
|
+
TError,
|
|
81
|
+
TData
|
|
82
|
+
>(queryKey, queryFn, queryOptions);
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
queryKey,
|
|
86
|
+
...query,
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Gets a known merchant
|
|
92
|
+
|
|
93
|
+
* @summary Gets a specific Merchant
|
|
94
|
+
*/
|
|
95
|
+
export const getService = (
|
|
96
|
+
mId: number,
|
|
97
|
+
options?: SecondParameter<typeof customInstance>,
|
|
98
|
+
signal?: AbortSignal
|
|
99
|
+
) => {
|
|
100
|
+
return customInstance<MerchantGetResponse>(
|
|
101
|
+
{ url: `/merchant/${mId}`, method: "get", signal },
|
|
102
|
+
options
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const getGetServiceQueryKey = (mId: number) => [`/merchant/${mId}`];
|
|
107
|
+
|
|
108
|
+
export type GetServiceQueryResult = NonNullable<
|
|
109
|
+
Awaited<ReturnType<typeof getService>>
|
|
110
|
+
>;
|
|
111
|
+
export type GetServiceQueryError = ErrorType<AsError | void>;
|
|
112
|
+
|
|
113
|
+
export const useGetService = <
|
|
114
|
+
TData = Awaited<ReturnType<typeof getService>>,
|
|
115
|
+
TError = ErrorType<AsError | void>
|
|
116
|
+
>(
|
|
117
|
+
mId: number,
|
|
118
|
+
options?: {
|
|
119
|
+
query?: UseQueryOptions<
|
|
120
|
+
Awaited<ReturnType<typeof getService>>,
|
|
121
|
+
TError,
|
|
122
|
+
TData
|
|
123
|
+
>;
|
|
124
|
+
request?: SecondParameter<typeof customInstance>;
|
|
125
|
+
}
|
|
126
|
+
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
127
|
+
const { query: queryOptions, request: requestOptions } = options ?? {};
|
|
128
|
+
|
|
129
|
+
const queryKey = queryOptions?.queryKey ?? getGetServiceQueryKey(mId);
|
|
130
|
+
|
|
131
|
+
const queryFn: QueryFunction<Awaited<ReturnType<typeof getService>>> = ({
|
|
132
|
+
signal,
|
|
133
|
+
}) => getService(mId, requestOptions, signal);
|
|
134
|
+
|
|
135
|
+
const query = useQuery<Awaited<ReturnType<typeof getService>>, TError, TData>(
|
|
136
|
+
queryKey,
|
|
137
|
+
queryFn,
|
|
138
|
+
{ enabled: !!mId, ...queryOptions }
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
queryKey,
|
|
143
|
+
...query,
|
|
144
|
+
};
|
|
145
|
+
};
|