@squonk/account-server-client 0.1.26 → 0.1.27-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 (42) hide show
  1. package/{account-server-api.schemas-078442c3.d.ts → account-server-api.schemas-e6c5f956.d.ts} +13 -0
  2. package/index.cjs.map +1 -1
  3. package/index.d.ts +1 -1
  4. package/index.js.map +1 -1
  5. package/organisation/organisation.cjs +64 -19
  6. package/organisation/organisation.cjs.map +1 -1
  7. package/organisation/organisation.d.ts +67 -18
  8. package/organisation/organisation.js +64 -19
  9. package/organisation/organisation.js.map +1 -1
  10. package/package.json +1 -1
  11. package/product/product.cjs +108 -30
  12. package/product/product.cjs.map +1 -1
  13. package/product/product.d.ts +114 -24
  14. package/product/product.js +108 -30
  15. package/product/product.js.map +1 -1
  16. package/service/service.cjs +39 -10
  17. package/service/service.cjs.map +1 -1
  18. package/service/service.d.ts +34 -8
  19. package/service/service.js +39 -10
  20. package/service/service.js.map +1 -1
  21. package/src/account-server-api.schemas.ts +13 -0
  22. package/src/organisation/organisation.ts +195 -44
  23. package/src/product/product.ts +356 -84
  24. package/src/service/service.ts +108 -16
  25. package/src/state/state.ts +64 -16
  26. package/src/unit/unit.ts +339 -74
  27. package/src/user/user.ts +340 -67
  28. package/state/state.cjs +21 -7
  29. package/state/state.cjs.map +1 -1
  30. package/state/state.d.ts +17 -6
  31. package/state/state.js +21 -7
  32. package/state/state.js.map +1 -1
  33. package/unit/unit.cjs +104 -29
  34. package/unit/unit.cjs.map +1 -1
  35. package/unit/unit.d.ts +107 -25
  36. package/unit/unit.js +104 -29
  37. package/unit/unit.js.map +1 -1
  38. package/user/user.cjs +106 -29
  39. package/user/user.cjs.map +1 -1
  40. package/user/user.d.ts +132 -20
  41. package/user/user.js +106 -29
  42. package/user/user.js.map +1 -1
@@ -8,21 +8,69 @@ 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 axios, { AxiosRequestConfig, AxiosResponse } from "axios";
12
- import type { StateGetVersionResponse } from "../account-server-api.schemas";
13
-
14
- export const getState = () => {
15
- /**
16
- * @summary Gets the Account Server version
17
- */
18
- const appApiStateGetVersion = <
19
- TData = AxiosResponse<StateGetVersionResponse>
20
- >(
21
- options?: AxiosRequestConfig
22
- ): Promise<TData> => {
23
- return axios.get(`/version`, options);
11
+ import axios, { AxiosRequestConfig, AxiosResponse, AxiosError } from "axios";
12
+ import {
13
+ useQuery,
14
+ UseQueryOptions,
15
+ QueryFunction,
16
+ UseQueryResult,
17
+ QueryKey,
18
+ } from "react-query";
19
+ import type {
20
+ StateGetVersionResponse,
21
+ AsError,
22
+ } from "../account-server-api.schemas";
23
+
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ type AsyncReturnType<T extends (...args: any) => Promise<any>> = T extends (
26
+ ...args: any
27
+ ) => Promise<infer R>
28
+ ? R
29
+ : any;
30
+
31
+ /**
32
+ * @summary Gets the Account Server version
33
+ */
34
+ export const appApiStateGetVersion = (
35
+ options?: AxiosRequestConfig
36
+ ): Promise<AxiosResponse<StateGetVersionResponse>> => {
37
+ return axios.get(`/version`, options);
38
+ };
39
+
40
+ export const getAppApiStateGetVersionQueryKey = () => [`/version`];
41
+
42
+ export type AppApiStateGetVersionQueryResult = NonNullable<
43
+ AsyncReturnType<typeof appApiStateGetVersion>
44
+ >;
45
+ export type AppApiStateGetVersionQueryError = AxiosError<AsError | void>;
46
+
47
+ export const useAppApiStateGetVersion = <
48
+ TData = AsyncReturnType<typeof appApiStateGetVersion>,
49
+ TError = AxiosError<AsError | void>
50
+ >(options?: {
51
+ query?: UseQueryOptions<
52
+ AsyncReturnType<typeof appApiStateGetVersion>,
53
+ TError,
54
+ TData
55
+ >;
56
+ axios?: AxiosRequestConfig;
57
+ }): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
58
+ const { query: queryOptions, axios: axiosOptions } = options || {};
59
+
60
+ const queryKey = queryOptions?.queryKey ?? getAppApiStateGetVersionQueryKey();
61
+
62
+ const queryFn: QueryFunction<
63
+ AsyncReturnType<typeof appApiStateGetVersion>
64
+ > = () => appApiStateGetVersion(axiosOptions);
65
+
66
+ const query = useQuery<
67
+ AsyncReturnType<typeof appApiStateGetVersion>,
68
+ TError,
69
+ TData
70
+ >(queryKey, queryFn, queryOptions);
71
+
72
+ return {
73
+ queryKey,
74
+ ...query,
24
75
  };
25
- return { appApiStateGetVersion };
26
76
  };
27
- export type AppApiStateGetVersionResult =
28
- AxiosResponse<StateGetVersionResponse>;
package/src/unit/unit.ts CHANGED
@@ -8,9 +8,20 @@ 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 axios, { AxiosRequestConfig, AxiosResponse } from "axios";
11
+ import axios, { AxiosRequestConfig, AxiosResponse, AxiosError } from "axios";
12
+ import {
13
+ useQuery,
14
+ useMutation,
15
+ UseQueryOptions,
16
+ UseMutationOptions,
17
+ QueryFunction,
18
+ MutationFunction,
19
+ UseQueryResult,
20
+ QueryKey,
21
+ } from "react-query";
12
22
  import type {
13
23
  OrganisationUnitsGetResponse,
24
+ AsError,
14
25
  OrganisationUnitPostResponse,
15
26
  OrganisationUnitPostBodyBody,
16
27
  UnitGetResponse,
@@ -18,108 +29,362 @@ import type {
18
29
  PersonalUnitPutResponse,
19
30
  } from "../account-server-api.schemas";
20
31
 
21
- export const getUnit = () => {
22
- /**
23
- * Gets Organisational Units you have access to
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
+ /**
40
+ * Gets Organisational Units you have access to or that are public
24
41
 
25
42
  * @summary Gets Organisational Units
26
43
  */
27
- const appApiUnitGetOrgUnits = <
28
- TData = AxiosResponse<OrganisationUnitsGetResponse>
29
- >(
30
- orgId: string,
31
- options?: AxiosRequestConfig
32
- ): Promise<TData> => {
33
- return axios.get(`/organisation/${orgId}/unit`, options);
44
+ export const appApiUnitGetOrgUnits = (
45
+ orgId: string,
46
+ options?: AxiosRequestConfig
47
+ ): Promise<AxiosResponse<OrganisationUnitsGetResponse>> => {
48
+ return axios.get(`/organisation/${orgId}/unit`, options);
49
+ };
50
+
51
+ export const getAppApiUnitGetOrgUnitsQueryKey = (orgId: string) => [
52
+ `/organisation/${orgId}/unit`,
53
+ ];
54
+
55
+ export type AppApiUnitGetOrgUnitsQueryResult = NonNullable<
56
+ AsyncReturnType<typeof appApiUnitGetOrgUnits>
57
+ >;
58
+ export type AppApiUnitGetOrgUnitsQueryError = AxiosError<void | AsError>;
59
+
60
+ export const useAppApiUnitGetOrgUnits = <
61
+ TData = AsyncReturnType<typeof appApiUnitGetOrgUnits>,
62
+ TError = AxiosError<void | AsError>
63
+ >(
64
+ orgId: string,
65
+ options?: {
66
+ query?: UseQueryOptions<
67
+ AsyncReturnType<typeof appApiUnitGetOrgUnits>,
68
+ TError,
69
+ TData
70
+ >;
71
+ axios?: AxiosRequestConfig;
72
+ }
73
+ ): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
74
+ const { query: queryOptions, axios: axiosOptions } = options || {};
75
+
76
+ const queryKey =
77
+ queryOptions?.queryKey ?? getAppApiUnitGetOrgUnitsQueryKey(orgId);
78
+
79
+ const queryFn: QueryFunction<
80
+ AsyncReturnType<typeof appApiUnitGetOrgUnits>
81
+ > = () => appApiUnitGetOrgUnits(orgId, axiosOptions);
82
+
83
+ const query = useQuery<
84
+ AsyncReturnType<typeof appApiUnitGetOrgUnits>,
85
+ TError,
86
+ TData
87
+ >(queryKey, queryFn, { enabled: !!orgId, ...queryOptions });
88
+
89
+ return {
90
+ queryKey,
91
+ ...query,
34
92
  };
35
- /**
93
+ };
94
+
95
+ /**
36
96
  * Creates a new organisation unit. You need to be in the Organisation or an Admin user to use this endpoint
37
97
 
38
98
  * @summary Create a new Organisational Unit
39
99
  */
40
- const appApiUnitPost = <TData = AxiosResponse<OrganisationUnitPostResponse>>(
41
- orgId: string,
42
- organisationUnitPostBodyBody: OrganisationUnitPostBodyBody,
43
- options?: AxiosRequestConfig
44
- ): Promise<TData> => {
45
- return axios.post(
46
- `/organisation/${orgId}/unit`,
47
- organisationUnitPostBodyBody,
48
- options
49
- );
100
+ export const appApiUnitPost = (
101
+ orgId: string,
102
+ organisationUnitPostBodyBody: OrganisationUnitPostBodyBody,
103
+ options?: AxiosRequestConfig
104
+ ): Promise<AxiosResponse<OrganisationUnitPostResponse>> => {
105
+ return axios.post(
106
+ `/organisation/${orgId}/unit`,
107
+ organisationUnitPostBodyBody,
108
+ options
109
+ );
110
+ };
111
+
112
+ export type AppApiUnitPostMutationResult = NonNullable<
113
+ AsyncReturnType<typeof appApiUnitPost>
114
+ >;
115
+ export type AppApiUnitPostMutationBody = OrganisationUnitPostBodyBody;
116
+ export type AppApiUnitPostMutationError = AxiosError<AsError | void>;
117
+
118
+ export const useAppApiUnitPost = <
119
+ TError = AxiosError<AsError | void>,
120
+ TContext = unknown
121
+ >(options?: {
122
+ mutation?: UseMutationOptions<
123
+ AsyncReturnType<typeof appApiUnitPost>,
124
+ TError,
125
+ { orgId: string; data: OrganisationUnitPostBodyBody },
126
+ TContext
127
+ >;
128
+ axios?: AxiosRequestConfig;
129
+ }) => {
130
+ const { mutation: mutationOptions, axios: axiosOptions } = options || {};
131
+
132
+ const mutationFn: MutationFunction<
133
+ AsyncReturnType<typeof appApiUnitPost>,
134
+ { orgId: string; data: OrganisationUnitPostBodyBody }
135
+ > = (props) => {
136
+ const { orgId, data } = props || {};
137
+
138
+ return appApiUnitPost(orgId, data, axiosOptions);
50
139
  };
51
- /**
52
- * Gets the Unit, assuming you are a member of it. Admin users can see all Units
140
+
141
+ return useMutation<
142
+ AsyncReturnType<typeof appApiUnitPost>,
143
+ TError,
144
+ { orgId: string; data: OrganisationUnitPostBodyBody },
145
+ TContext
146
+ >(mutationFn, mutationOptions);
147
+ };
148
+ /**
149
+ * Gets the Unit, assuming you are a member of it or it is public. Admin users can see all Units
53
150
 
54
151
  * @summary Gets a Unit
55
152
  */
56
- const appApiUnitGetUnit = <TData = AxiosResponse<UnitGetResponse>>(
57
- orgId: string,
58
- unitId: string,
59
- options?: AxiosRequestConfig
60
- ): Promise<TData> => {
61
- return axios.get(`/organisation/${orgId}/unit/${unitId}`, options);
153
+ export const appApiUnitGetUnit = (
154
+ orgId: string,
155
+ unitId: string,
156
+ options?: AxiosRequestConfig
157
+ ): Promise<AxiosResponse<UnitGetResponse>> => {
158
+ return axios.get(`/organisation/${orgId}/unit/${unitId}`, options);
159
+ };
160
+
161
+ export const getAppApiUnitGetUnitQueryKey = (orgId: string, unitId: string) => [
162
+ `/organisation/${orgId}/unit/${unitId}`,
163
+ ];
164
+
165
+ export type AppApiUnitGetUnitQueryResult = NonNullable<
166
+ AsyncReturnType<typeof appApiUnitGetUnit>
167
+ >;
168
+ export type AppApiUnitGetUnitQueryError = AxiosError<void | AsError>;
169
+
170
+ export const useAppApiUnitGetUnit = <
171
+ TData = AsyncReturnType<typeof appApiUnitGetUnit>,
172
+ TError = AxiosError<void | AsError>
173
+ >(
174
+ orgId: string,
175
+ unitId: string,
176
+ options?: {
177
+ query?: UseQueryOptions<
178
+ AsyncReturnType<typeof appApiUnitGetUnit>,
179
+ TError,
180
+ TData
181
+ >;
182
+ axios?: AxiosRequestConfig;
183
+ }
184
+ ): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
185
+ const { query: queryOptions, axios: axiosOptions } = options || {};
186
+
187
+ const queryKey =
188
+ queryOptions?.queryKey ?? getAppApiUnitGetUnitQueryKey(orgId, unitId);
189
+
190
+ const queryFn: QueryFunction<
191
+ AsyncReturnType<typeof appApiUnitGetUnit>
192
+ > = () => appApiUnitGetUnit(orgId, unitId, axiosOptions);
193
+
194
+ const query = useQuery<
195
+ AsyncReturnType<typeof appApiUnitGetUnit>,
196
+ TError,
197
+ TData
198
+ >(queryKey, queryFn, { enabled: !!(orgId && unitId), ...queryOptions });
199
+
200
+ return {
201
+ queryKey,
202
+ ...query,
62
203
  };
63
- /**
204
+ };
205
+
206
+ /**
64
207
  * Deletes an Organisational Unit you have access to. Units can only be deleted by Organisation users or Admin users. You cannot delete a Unit that contains Products
65
208
 
66
209
  * @summary Deletes an Organisational Unit
67
210
  */
68
- const appApiUnitDelete = <TData = AxiosResponse<void>>(
69
- orgId: string,
70
- unitId: string,
71
- options?: AxiosRequestConfig
72
- ): Promise<TData> => {
73
- return axios.delete(`/organisation/${orgId}/unit/${unitId}`, options);
211
+ export const appApiUnitDelete = (
212
+ orgId: string,
213
+ unitId: string,
214
+ options?: AxiosRequestConfig
215
+ ): Promise<AxiosResponse<void>> => {
216
+ return axios.delete(`/organisation/${orgId}/unit/${unitId}`, options);
217
+ };
218
+
219
+ export type AppApiUnitDeleteMutationResult = NonNullable<
220
+ AsyncReturnType<typeof appApiUnitDelete>
221
+ >;
222
+
223
+ export type AppApiUnitDeleteMutationError = AxiosError<AsError>;
224
+
225
+ export const useAppApiUnitDelete = <
226
+ TError = AxiosError<AsError>,
227
+ TContext = unknown
228
+ >(options?: {
229
+ mutation?: UseMutationOptions<
230
+ AsyncReturnType<typeof appApiUnitDelete>,
231
+ TError,
232
+ { orgId: string; unitId: string },
233
+ TContext
234
+ >;
235
+ axios?: AxiosRequestConfig;
236
+ }) => {
237
+ const { mutation: mutationOptions, axios: axiosOptions } = options || {};
238
+
239
+ const mutationFn: MutationFunction<
240
+ AsyncReturnType<typeof appApiUnitDelete>,
241
+ { orgId: string; unitId: string }
242
+ > = (props) => {
243
+ const { orgId, unitId } = props || {};
244
+
245
+ return appApiUnitDelete(orgId, unitId, axiosOptions);
74
246
  };
75
- /**
76
- * Gets all the Units you are a member of. Admin users can see all Units
77
247
 
78
- * @summary Gets Units a User has access to
248
+ return useMutation<
249
+ AsyncReturnType<typeof appApiUnitDelete>,
250
+ TError,
251
+ { orgId: string; unitId: string },
252
+ TContext
253
+ >(mutationFn, mutationOptions);
254
+ };
255
+ /**
256
+ * Gets all the Units that are public or you are a member of. Admin users can see all Units
257
+
258
+ * @summary Gets Units
79
259
  */
80
- const appApiUnitGet = <TData = AxiosResponse<UnitsGetResponse>>(
81
- options?: AxiosRequestConfig
82
- ): Promise<TData> => {
83
- return axios.get(`/unit`, options);
260
+ export const appApiUnitGet = (
261
+ options?: AxiosRequestConfig
262
+ ): Promise<AxiosResponse<UnitsGetResponse>> => {
263
+ return axios.get(`/unit`, options);
264
+ };
265
+
266
+ export const getAppApiUnitGetQueryKey = () => [`/unit`];
267
+
268
+ export type AppApiUnitGetQueryResult = NonNullable<
269
+ AsyncReturnType<typeof appApiUnitGet>
270
+ >;
271
+ export type AppApiUnitGetQueryError = AxiosError<void | AsError>;
272
+
273
+ export const useAppApiUnitGet = <
274
+ TData = AsyncReturnType<typeof appApiUnitGet>,
275
+ TError = AxiosError<void | AsError>
276
+ >(options?: {
277
+ query?: UseQueryOptions<AsyncReturnType<typeof appApiUnitGet>, TError, TData>;
278
+ axios?: AxiosRequestConfig;
279
+ }): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
280
+ const { query: queryOptions, axios: axiosOptions } = options || {};
281
+
282
+ const queryKey = queryOptions?.queryKey ?? getAppApiUnitGetQueryKey();
283
+
284
+ const queryFn: QueryFunction<AsyncReturnType<typeof appApiUnitGet>> = () =>
285
+ appApiUnitGet(axiosOptions);
286
+
287
+ const query = useQuery<AsyncReturnType<typeof appApiUnitGet>, TError, TData>(
288
+ queryKey,
289
+ queryFn,
290
+ queryOptions
291
+ );
292
+
293
+ return {
294
+ queryKey,
295
+ ...query,
84
296
  };
85
- /**
297
+ };
298
+
299
+ /**
86
300
  * Creates a 'Personal' Unit for a User. The unit will belong to the built-in **Default** Organisation. Users can only have one Personal Unit and Personal Units cannot have other Users
87
301
 
88
302
  * @summary Create a new Independent User Unit
89
303
  */
90
- const appApiUnitPersonalPut = <
91
- TData = AxiosResponse<PersonalUnitPutResponse>
92
- >(
93
- options?: AxiosRequestConfig
94
- ): Promise<TData> => {
95
- return axios.put(`/unit`, undefined, options);
304
+ export const appApiUnitPersonalPut = (
305
+ options?: AxiosRequestConfig
306
+ ): Promise<AxiosResponse<PersonalUnitPutResponse>> => {
307
+ return axios.put(`/unit`, undefined, options);
308
+ };
309
+
310
+ export type AppApiUnitPersonalPutMutationResult = NonNullable<
311
+ AsyncReturnType<typeof appApiUnitPersonalPut>
312
+ >;
313
+
314
+ export type AppApiUnitPersonalPutMutationError = AxiosError<AsError | void>;
315
+
316
+ export const useAppApiUnitPersonalPut = <
317
+ TError = AxiosError<AsError | void>,
318
+ TVariables = void,
319
+ TContext = unknown
320
+ >(options?: {
321
+ mutation?: UseMutationOptions<
322
+ AsyncReturnType<typeof appApiUnitPersonalPut>,
323
+ TError,
324
+ TVariables,
325
+ TContext
326
+ >;
327
+ axios?: AxiosRequestConfig;
328
+ }) => {
329
+ const { mutation: mutationOptions, axios: axiosOptions } = options || {};
330
+
331
+ const mutationFn: MutationFunction<
332
+ AsyncReturnType<typeof appApiUnitPersonalPut>,
333
+ TVariables
334
+ > = () => {
335
+ return appApiUnitPersonalPut(axiosOptions);
96
336
  };
97
- /**
337
+
338
+ return useMutation<
339
+ AsyncReturnType<typeof appApiUnitPersonalPut>,
340
+ TError,
341
+ TVariables,
342
+ TContext
343
+ >(mutationFn, mutationOptions);
344
+ };
345
+ /**
98
346
  * Deletes a 'Personal' Unit. It must be your Unit, which belongs to the Default Organisation
99
347
 
100
348
  * @summary Deletes an Independent Unit
101
349
  */
102
- const appApiUnitPersonalDelete = <TData = AxiosResponse<void>>(
103
- options?: AxiosRequestConfig
104
- ): Promise<TData> => {
105
- return axios.delete(`/unit`, options);
106
- };
107
- return {
108
- appApiUnitGetOrgUnits,
109
- appApiUnitPost,
110
- appApiUnitGetUnit,
111
- appApiUnitDelete,
112
- appApiUnitGet,
113
- appApiUnitPersonalPut,
114
- appApiUnitPersonalDelete,
350
+ export const appApiUnitPersonalDelete = (
351
+ options?: AxiosRequestConfig
352
+ ): Promise<AxiosResponse<void>> => {
353
+ return axios.delete(`/unit`, options);
354
+ };
355
+
356
+ export type AppApiUnitPersonalDeleteMutationResult = NonNullable<
357
+ AsyncReturnType<typeof appApiUnitPersonalDelete>
358
+ >;
359
+
360
+ export type AppApiUnitPersonalDeleteMutationError = AxiosError<AsError>;
361
+
362
+ export const useAppApiUnitPersonalDelete = <
363
+ TError = AxiosError<AsError>,
364
+ TVariables = void,
365
+ TContext = unknown
366
+ >(options?: {
367
+ mutation?: UseMutationOptions<
368
+ AsyncReturnType<typeof appApiUnitPersonalDelete>,
369
+ TError,
370
+ TVariables,
371
+ TContext
372
+ >;
373
+ axios?: AxiosRequestConfig;
374
+ }) => {
375
+ const { mutation: mutationOptions, axios: axiosOptions } = options || {};
376
+
377
+ const mutationFn: MutationFunction<
378
+ AsyncReturnType<typeof appApiUnitPersonalDelete>,
379
+ TVariables
380
+ > = () => {
381
+ return appApiUnitPersonalDelete(axiosOptions);
115
382
  };
383
+
384
+ return useMutation<
385
+ AsyncReturnType<typeof appApiUnitPersonalDelete>,
386
+ TError,
387
+ TVariables,
388
+ TContext
389
+ >(mutationFn, mutationOptions);
116
390
  };
117
- export type AppApiUnitGetOrgUnitsResult =
118
- AxiosResponse<OrganisationUnitsGetResponse>;
119
- export type AppApiUnitPostResult = AxiosResponse<OrganisationUnitPostResponse>;
120
- export type AppApiUnitGetUnitResult = AxiosResponse<UnitGetResponse>;
121
- export type AppApiUnitDeleteResult = AxiosResponse<void>;
122
- export type AppApiUnitGetResult = AxiosResponse<UnitsGetResponse>;
123
- export type AppApiUnitPersonalPutResult =
124
- AxiosResponse<PersonalUnitPutResponse>;
125
- export type AppApiUnitPersonalDeleteResult = AxiosResponse<void>;