@squonk/account-server-client 0.1.31 → 0.1.32-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 (59) hide show
  1. package/asset/asset.cjs +130 -0
  2. package/asset/asset.cjs.map +1 -0
  3. package/asset/asset.d.ts +126 -0
  4. package/asset/asset.js +130 -0
  5. package/asset/asset.js.map +1 -0
  6. package/asset/package.json +7 -0
  7. package/{custom-instance-13412a15.d.ts → custom-instance-6b9df5d3.d.ts} +124 -34
  8. package/index.cjs +20 -2
  9. package/index.cjs.map +1 -1
  10. package/index.d.ts +1 -1
  11. package/index.js +20 -2
  12. package/index.js.map +1 -1
  13. package/merchant/merchant.cjs +48 -0
  14. package/merchant/merchant.cjs.map +1 -0
  15. package/merchant/merchant.d.ts +39 -0
  16. package/merchant/merchant.js +48 -0
  17. package/merchant/merchant.js.map +1 -0
  18. package/merchant/package.json +7 -0
  19. package/organisation/organisation.cjs +12 -12
  20. package/organisation/organisation.cjs.map +1 -1
  21. package/organisation/organisation.d.ts +10 -9
  22. package/organisation/organisation.js +12 -12
  23. package/organisation/organisation.js.map +1 -1
  24. package/package.json +9 -9
  25. package/product/product.cjs +36 -26
  26. package/product/product.cjs.map +1 -1
  27. package/product/product.d.ts +17 -16
  28. package/product/product.js +36 -26
  29. package/product/product.js.map +1 -1
  30. package/src/account-server-api.schemas.ts +152 -46
  31. package/src/asset/asset.ts +430 -0
  32. package/src/merchant/merchant.ts +145 -0
  33. package/src/organisation/organisation.ts +37 -37
  34. package/src/product/product.ts +91 -74
  35. package/src/state/state.ts +19 -16
  36. package/src/unit/unit.ts +64 -56
  37. package/src/user/user.ts +63 -62
  38. package/state/state.cjs +6 -4
  39. package/state/state.cjs.map +1 -1
  40. package/state/state.d.ts +7 -6
  41. package/state/state.js +6 -4
  42. package/state/state.js.map +1 -1
  43. package/unit/unit.cjs +22 -18
  44. package/unit/unit.cjs.map +1 -1
  45. package/unit/unit.d.ts +14 -13
  46. package/unit/unit.js +22 -18
  47. package/unit/unit.js.map +1 -1
  48. package/user/user.cjs +22 -20
  49. package/user/user.cjs.map +1 -1
  50. package/user/user.d.ts +14 -13
  51. package/user/user.js +22 -20
  52. package/user/user.js.map +1 -1
  53. package/service/package.json +0 -7
  54. package/service/service.cjs +0 -44
  55. package/service/service.cjs.map +0 -1
  56. package/service/service.d.ts +0 -49
  57. package/service/service.js +0 -44
  58. package/service/service.js.map +0 -1
  59. package/src/service/service.ts +0 -136
@@ -0,0 +1,430 @@
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
+
127
+ return customInstance<AssetPostResponse>(
128
+ {
129
+ url: `/asset`,
130
+ method: "post",
131
+ headers: { "Content-Type": "multipart/form-data" },
132
+ data: formData,
133
+ },
134
+ options
135
+ );
136
+ };
137
+
138
+ export type CreateAssetMutationResult = NonNullable<
139
+ Awaited<ReturnType<typeof createAsset>>
140
+ >;
141
+ export type CreateAssetMutationBody = AssetPostBodyBody;
142
+ export type CreateAssetMutationError = ErrorType<AsError | void>;
143
+
144
+ export const useCreateAsset = <
145
+ TError = ErrorType<AsError | void>,
146
+ TContext = unknown
147
+ >(options?: {
148
+ mutation?: UseMutationOptions<
149
+ Awaited<ReturnType<typeof createAsset>>,
150
+ TError,
151
+ { data: AssetPostBodyBody },
152
+ TContext
153
+ >;
154
+ request?: SecondParameter<typeof customInstance>;
155
+ }) => {
156
+ const { mutation: mutationOptions, request: requestOptions } = options ?? {};
157
+
158
+ const mutationFn: MutationFunction<
159
+ Awaited<ReturnType<typeof createAsset>>,
160
+ { data: AssetPostBodyBody }
161
+ > = (props) => {
162
+ const { data } = props ?? {};
163
+
164
+ return createAsset(data, requestOptions);
165
+ };
166
+
167
+ return useMutation<
168
+ Awaited<ReturnType<typeof createAsset>>,
169
+ TError,
170
+ { data: AssetPostBodyBody },
171
+ TContext
172
+ >(mutationFn, mutationOptions);
173
+ };
174
+ /**
175
+ * Deletes a known Asset. Assets that are attached to merchants cannot be deleted
176
+
177
+ * @summary Deletes an Asset
178
+ */
179
+ export const deleteAsset = (
180
+ assetId: string,
181
+ options?: SecondParameter<typeof customInstance>
182
+ ) => {
183
+ return customInstance<void>(
184
+ { url: `/asset/${assetId}`, method: "delete" },
185
+ options
186
+ );
187
+ };
188
+
189
+ export type DeleteAssetMutationResult = NonNullable<
190
+ Awaited<ReturnType<typeof deleteAsset>>
191
+ >;
192
+
193
+ export type DeleteAssetMutationError = ErrorType<AsError>;
194
+
195
+ export const useDeleteAsset = <
196
+ TError = ErrorType<AsError>,
197
+ TContext = unknown
198
+ >(options?: {
199
+ mutation?: UseMutationOptions<
200
+ Awaited<ReturnType<typeof deleteAsset>>,
201
+ TError,
202
+ { assetId: string },
203
+ TContext
204
+ >;
205
+ request?: SecondParameter<typeof customInstance>;
206
+ }) => {
207
+ const { mutation: mutationOptions, request: requestOptions } = options ?? {};
208
+
209
+ const mutationFn: MutationFunction<
210
+ Awaited<ReturnType<typeof deleteAsset>>,
211
+ { assetId: string }
212
+ > = (props) => {
213
+ const { assetId } = props ?? {};
214
+
215
+ return deleteAsset(assetId, requestOptions);
216
+ };
217
+
218
+ return useMutation<
219
+ Awaited<ReturnType<typeof deleteAsset>>,
220
+ TError,
221
+ { assetId: string },
222
+ TContext
223
+ >(mutationFn, mutationOptions);
224
+ };
225
+ /**
226
+ * Disables a known Asset
227
+
228
+ * @summary Disables an Asset
229
+ */
230
+ export const disableAsset = (
231
+ assetId: string,
232
+ options?: SecondParameter<typeof customInstance>
233
+ ) => {
234
+ return customInstance<void>(
235
+ { url: `/asset/${assetId}/disable`, method: "patch" },
236
+ options
237
+ );
238
+ };
239
+
240
+ export type DisableAssetMutationResult = NonNullable<
241
+ Awaited<ReturnType<typeof disableAsset>>
242
+ >;
243
+
244
+ export type DisableAssetMutationError = ErrorType<AsError>;
245
+
246
+ export const useDisableAsset = <
247
+ TError = ErrorType<AsError>,
248
+ TContext = unknown
249
+ >(options?: {
250
+ mutation?: UseMutationOptions<
251
+ Awaited<ReturnType<typeof disableAsset>>,
252
+ TError,
253
+ { assetId: string },
254
+ TContext
255
+ >;
256
+ request?: SecondParameter<typeof customInstance>;
257
+ }) => {
258
+ const { mutation: mutationOptions, request: requestOptions } = options ?? {};
259
+
260
+ const mutationFn: MutationFunction<
261
+ Awaited<ReturnType<typeof disableAsset>>,
262
+ { assetId: string }
263
+ > = (props) => {
264
+ const { assetId } = props ?? {};
265
+
266
+ return disableAsset(assetId, requestOptions);
267
+ };
268
+
269
+ return useMutation<
270
+ Awaited<ReturnType<typeof disableAsset>>,
271
+ TError,
272
+ { assetId: string },
273
+ TContext
274
+ >(mutationFn, mutationOptions);
275
+ };
276
+ /**
277
+ * Enables a known Asset
278
+
279
+ * @summary Enables an Asset
280
+ */
281
+ export const enableAsset = (
282
+ assetId: string,
283
+ options?: SecondParameter<typeof customInstance>
284
+ ) => {
285
+ return customInstance<void>(
286
+ { url: `/asset/${assetId}/enable`, method: "patch" },
287
+ options
288
+ );
289
+ };
290
+
291
+ export type EnableAssetMutationResult = NonNullable<
292
+ Awaited<ReturnType<typeof enableAsset>>
293
+ >;
294
+
295
+ export type EnableAssetMutationError = ErrorType<AsError>;
296
+
297
+ export const useEnableAsset = <
298
+ TError = ErrorType<AsError>,
299
+ TContext = unknown
300
+ >(options?: {
301
+ mutation?: UseMutationOptions<
302
+ Awaited<ReturnType<typeof enableAsset>>,
303
+ TError,
304
+ { assetId: string },
305
+ TContext
306
+ >;
307
+ request?: SecondParameter<typeof customInstance>;
308
+ }) => {
309
+ const { mutation: mutationOptions, request: requestOptions } = options ?? {};
310
+
311
+ const mutationFn: MutationFunction<
312
+ Awaited<ReturnType<typeof enableAsset>>,
313
+ { assetId: string }
314
+ > = (props) => {
315
+ const { assetId } = props ?? {};
316
+
317
+ return enableAsset(assetId, requestOptions);
318
+ };
319
+
320
+ return useMutation<
321
+ Awaited<ReturnType<typeof enableAsset>>,
322
+ TError,
323
+ { assetId: string },
324
+ TContext
325
+ >(mutationFn, mutationOptions);
326
+ };
327
+ /**
328
+ * Attaches an Asset to a merchant
329
+
330
+ * @summary Attaches an Asset to a Merchant
331
+ */
332
+ export const attachAsset = (
333
+ assetId: string,
334
+ params?: AttachAssetParams,
335
+ options?: SecondParameter<typeof customInstance>
336
+ ) => {
337
+ return customInstance<void>(
338
+ { url: `/asset/${assetId}/attach`, method: "patch", params },
339
+ options
340
+ );
341
+ };
342
+
343
+ export type AttachAssetMutationResult = NonNullable<
344
+ Awaited<ReturnType<typeof attachAsset>>
345
+ >;
346
+
347
+ export type AttachAssetMutationError = ErrorType<AsError>;
348
+
349
+ export const useAttachAsset = <
350
+ TError = ErrorType<AsError>,
351
+ TContext = unknown
352
+ >(options?: {
353
+ mutation?: UseMutationOptions<
354
+ Awaited<ReturnType<typeof attachAsset>>,
355
+ TError,
356
+ { assetId: string; params?: AttachAssetParams },
357
+ TContext
358
+ >;
359
+ request?: SecondParameter<typeof customInstance>;
360
+ }) => {
361
+ const { mutation: mutationOptions, request: requestOptions } = options ?? {};
362
+
363
+ const mutationFn: MutationFunction<
364
+ Awaited<ReturnType<typeof attachAsset>>,
365
+ { assetId: string; params?: AttachAssetParams }
366
+ > = (props) => {
367
+ const { assetId, params } = props ?? {};
368
+
369
+ return attachAsset(assetId, params, requestOptions);
370
+ };
371
+
372
+ return useMutation<
373
+ Awaited<ReturnType<typeof attachAsset>>,
374
+ TError,
375
+ { assetId: string; params?: AttachAssetParams },
376
+ TContext
377
+ >(mutationFn, mutationOptions);
378
+ };
379
+ /**
380
+ * Detaches an Asset from a merchant
381
+
382
+ * @summary Detaches an Asset from a Merchant
383
+ */
384
+ export const detachAsset = (
385
+ assetId: string,
386
+ params?: DetachAssetParams,
387
+ options?: SecondParameter<typeof customInstance>
388
+ ) => {
389
+ return customInstance<void>(
390
+ { url: `/asset/${assetId}/detach`, method: "patch", params },
391
+ options
392
+ );
393
+ };
394
+
395
+ export type DetachAssetMutationResult = NonNullable<
396
+ Awaited<ReturnType<typeof detachAsset>>
397
+ >;
398
+
399
+ export type DetachAssetMutationError = ErrorType<AsError>;
400
+
401
+ export const useDetachAsset = <
402
+ TError = ErrorType<AsError>,
403
+ TContext = unknown
404
+ >(options?: {
405
+ mutation?: UseMutationOptions<
406
+ Awaited<ReturnType<typeof detachAsset>>,
407
+ TError,
408
+ { assetId: string; params?: DetachAssetParams },
409
+ TContext
410
+ >;
411
+ request?: SecondParameter<typeof customInstance>;
412
+ }) => {
413
+ const { mutation: mutationOptions, request: requestOptions } = options ?? {};
414
+
415
+ const mutationFn: MutationFunction<
416
+ Awaited<ReturnType<typeof detachAsset>>,
417
+ { assetId: string; params?: DetachAssetParams }
418
+ > = (props) => {
419
+ const { assetId, params } = props ?? {};
420
+
421
+ return detachAsset(assetId, params, requestOptions);
422
+ };
423
+
424
+ return useMutation<
425
+ Awaited<ReturnType<typeof detachAsset>>,
426
+ TError,
427
+ { assetId: string; params?: DetachAssetParams },
428
+ TContext
429
+ >(mutationFn, mutationOptions);
430
+ };
@@ -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
+ };