@squonk/account-server-client 0.1.26-rc.1 → 0.1.28-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 (51) hide show
  1. package/{chunk-GWBPVOL2.js → chunk-6EEIAH4R.js} +23 -2
  2. package/chunk-6EEIAH4R.js.map +1 -0
  3. package/chunk-NGBTCJWS.cjs +46 -0
  4. package/chunk-NGBTCJWS.cjs.map +1 -0
  5. package/{account-server-api.schemas-078442c3.d.ts → custom-instance-13412a15.d.ts} +32 -1
  6. package/index.cjs +5 -21
  7. package/index.cjs.map +1 -1
  8. package/index.d.ts +2 -20
  9. package/index.js +5 -21
  10. package/index.js.map +1 -1
  11. package/organisation/organisation.cjs +70 -20
  12. package/organisation/organisation.cjs.map +1 -1
  13. package/organisation/organisation.d.ts +68 -18
  14. package/organisation/organisation.js +70 -20
  15. package/organisation/organisation.js.map +1 -1
  16. package/package.json +1 -1
  17. package/product/product.cjs +121 -31
  18. package/product/product.cjs.map +1 -1
  19. package/product/product.d.ts +115 -24
  20. package/product/product.js +121 -31
  21. package/product/product.js.map +1 -1
  22. package/service/service.cjs +38 -11
  23. package/service/service.cjs.map +1 -1
  24. package/service/service.d.ts +35 -8
  25. package/service/service.js +38 -11
  26. package/service/service.js.map +1 -1
  27. package/src/account-server-api.schemas.ts +13 -0
  28. package/src/organisation/organisation.ts +219 -44
  29. package/src/product/product.ts +375 -84
  30. package/src/service/service.ts +110 -16
  31. package/src/state/state.ts +70 -16
  32. package/src/unit/unit.ts +354 -74
  33. package/src/user/user.ts +368 -67
  34. package/state/state.cjs +22 -8
  35. package/state/state.cjs.map +1 -1
  36. package/state/state.d.ts +18 -6
  37. package/state/state.js +22 -8
  38. package/state/state.js.map +1 -1
  39. package/unit/unit.cjs +110 -30
  40. package/unit/unit.cjs.map +1 -1
  41. package/unit/unit.d.ts +108 -25
  42. package/unit/unit.js +110 -30
  43. package/unit/unit.js.map +1 -1
  44. package/user/user.cjs +107 -30
  45. package/user/user.cjs.map +1 -1
  46. package/user/user.d.ts +133 -20
  47. package/user/user.js +107 -30
  48. package/user/user.js.map +1 -1
  49. package/chunk-GWBPVOL2.js.map +0 -1
  50. package/chunk-N3RLW53G.cjs +0 -25
  51. package/chunk-N3RLW53G.cjs.map +0 -1
@@ -8,78 +8,253 @@ 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 {
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
  OrganisationsGetResponse,
23
+ AsError,
14
24
  OrganisationPostResponse,
15
25
  OrganisationPostBodyBody,
16
26
  OrganisationGetDefaultResponse,
17
27
  } from "../account-server-api.schemas";
28
+ import { customInstance, ErrorType } from ".././custom-instance";
18
29
 
19
- export const getOrganisation = () => {
20
- /**
21
- * Gets all the Organisations you are a member of. Admin users can see all Organisations
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ type AsyncReturnType<T extends (...args: any) => Promise<any>> = T extends (
32
+ ...args: any
33
+ ) => Promise<infer R>
34
+ ? R
35
+ : any;
36
+
37
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
+ type SecondParameter<T extends (...args: any) => any> = T extends (
39
+ config: any,
40
+ args: infer P
41
+ ) => any
42
+ ? P
43
+ : never;
44
+
45
+ /**
46
+ * Gets all the Organisations that you are a member of or are public. Admin users are members of all organisation and can see all Organisations
22
47
 
23
48
  * @summary Gets Organisations
24
49
  */
25
- const appApiOrganisationGet = <
26
- TData = AxiosResponse<OrganisationsGetResponse>
27
- >(
28
- options?: AxiosRequestConfig
29
- ): Promise<TData> => {
30
- return axios.get(`/organisation`, options);
50
+ export const getOrganisations = (
51
+ options?: SecondParameter<typeof customInstance>
52
+ ) => {
53
+ return customInstance<OrganisationsGetResponse>(
54
+ { url: `/organisation`, method: "get" },
55
+ options
56
+ );
57
+ };
58
+
59
+ export const getGetOrganisationsQueryKey = () => [`/organisation`];
60
+
61
+ export type GetOrganisationsQueryResult = NonNullable<
62
+ AsyncReturnType<typeof getOrganisations>
63
+ >;
64
+ export type GetOrganisationsQueryError = ErrorType<void | AsError>;
65
+
66
+ export const useGetOrganisations = <
67
+ TData = AsyncReturnType<typeof getOrganisations>,
68
+ TError = ErrorType<void | AsError>
69
+ >(options?: {
70
+ query?: UseQueryOptions<
71
+ AsyncReturnType<typeof getOrganisations>,
72
+ TError,
73
+ TData
74
+ >;
75
+ request?: SecondParameter<typeof customInstance>;
76
+ }): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
77
+ const { query: queryOptions, request: requestOptions } = options || {};
78
+
79
+ const queryKey = queryOptions?.queryKey ?? getGetOrganisationsQueryKey();
80
+
81
+ const queryFn: QueryFunction<AsyncReturnType<typeof getOrganisations>> = () =>
82
+ getOrganisations(requestOptions);
83
+
84
+ const query = useQuery<
85
+ AsyncReturnType<typeof getOrganisations>,
86
+ TError,
87
+ TData
88
+ >(queryKey, queryFn, queryOptions);
89
+
90
+ return {
91
+ queryKey,
92
+ ...query,
31
93
  };
32
- /**
94
+ };
95
+
96
+ /**
33
97
  * Creates a new Organisation
34
98
 
35
99
  You need **admin** rights to use this method
36
100
 
37
101
  * @summary Create a new organisation
38
102
  */
39
- const appApiOrganisationPost = <
40
- TData = AxiosResponse<OrganisationPostResponse>
41
- >(
42
- organisationPostBodyBody: OrganisationPostBodyBody,
43
- options?: AxiosRequestConfig
44
- ): Promise<TData> => {
45
- return axios.post(`/organisation`, organisationPostBodyBody, options);
103
+ export const createOrganisation = (
104
+ organisationPostBodyBody: OrganisationPostBodyBody,
105
+ options?: SecondParameter<typeof customInstance>
106
+ ) => {
107
+ return customInstance<OrganisationPostResponse>(
108
+ {
109
+ url: `/organisation`,
110
+ method: "post",
111
+ headers: { "Content-Type": "application/json" },
112
+ data: organisationPostBodyBody,
113
+ },
114
+ options
115
+ );
116
+ };
117
+
118
+ export type CreateOrganisationMutationResult = NonNullable<
119
+ AsyncReturnType<typeof createOrganisation>
120
+ >;
121
+ export type CreateOrganisationMutationBody = OrganisationPostBodyBody;
122
+ export type CreateOrganisationMutationError = ErrorType<AsError | void>;
123
+
124
+ export const useCreateOrganisation = <
125
+ TError = ErrorType<AsError | void>,
126
+ TContext = unknown
127
+ >(options?: {
128
+ mutation?: UseMutationOptions<
129
+ AsyncReturnType<typeof createOrganisation>,
130
+ TError,
131
+ { data: OrganisationPostBodyBody },
132
+ TContext
133
+ >;
134
+ request?: SecondParameter<typeof customInstance>;
135
+ }) => {
136
+ const { mutation: mutationOptions, request: requestOptions } = options || {};
137
+
138
+ const mutationFn: MutationFunction<
139
+ AsyncReturnType<typeof createOrganisation>,
140
+ { data: OrganisationPostBodyBody }
141
+ > = (props) => {
142
+ const { data } = props || {};
143
+
144
+ return createOrganisation(data, requestOptions);
46
145
  };
47
- /**
146
+
147
+ return useMutation<
148
+ AsyncReturnType<typeof createOrganisation>,
149
+ TError,
150
+ { data: OrganisationPostBodyBody },
151
+ TContext
152
+ >(mutationFn, mutationOptions);
153
+ };
154
+ /**
48
155
  * Units must first be deleted before an Organisation can be deleted
49
156
 
50
157
  You need **admin** rights to use this method
51
158
 
52
159
  * @summary Deletes an Organisation
53
160
  */
54
- const appApiOrganisationDelete = <TData = AxiosResponse<void>>(
55
- orgId: string,
56
- options?: AxiosRequestConfig
57
- ): Promise<TData> => {
58
- return axios.delete(`/organisation/${orgId}`, options);
161
+ export const deleteOrganisation = (
162
+ orgId: string,
163
+ options?: SecondParameter<typeof customInstance>
164
+ ) => {
165
+ return customInstance<void>(
166
+ { url: `/organisation/${orgId}`, method: "delete" },
167
+ options
168
+ );
169
+ };
170
+
171
+ export type DeleteOrganisationMutationResult = NonNullable<
172
+ AsyncReturnType<typeof deleteOrganisation>
173
+ >;
174
+
175
+ export type DeleteOrganisationMutationError = ErrorType<AsError>;
176
+
177
+ export const useDeleteOrganisation = <
178
+ TError = ErrorType<AsError>,
179
+ TContext = unknown
180
+ >(options?: {
181
+ mutation?: UseMutationOptions<
182
+ AsyncReturnType<typeof deleteOrganisation>,
183
+ TError,
184
+ { orgId: string },
185
+ TContext
186
+ >;
187
+ request?: SecondParameter<typeof customInstance>;
188
+ }) => {
189
+ const { mutation: mutationOptions, request: requestOptions } = options || {};
190
+
191
+ const mutationFn: MutationFunction<
192
+ AsyncReturnType<typeof deleteOrganisation>,
193
+ { orgId: string }
194
+ > = (props) => {
195
+ const { orgId } = props || {};
196
+
197
+ return deleteOrganisation(orgId, requestOptions);
59
198
  };
60
- /**
61
- * Gets the built-in Default Organisation, used exclusively for Independent Units
199
+
200
+ return useMutation<
201
+ AsyncReturnType<typeof deleteOrganisation>,
202
+ TError,
203
+ { orgId: string },
204
+ TContext
205
+ >(mutationFn, mutationOptions);
206
+ };
207
+ /**
208
+ * Gets the built-in Default Organisation, used exclusively for Personal Units
62
209
 
63
210
  * @summary Gets the (built-in) Default Organisation
64
211
  */
65
- const appApiOrganisationGetDefault = <
66
- TData = AxiosResponse<OrganisationGetDefaultResponse>
67
- >(
68
- options?: AxiosRequestConfig
69
- ): Promise<TData> => {
70
- return axios.get(`/organisation/default`, options);
71
- };
212
+ export const getDefaultOrganisation = (
213
+ options?: SecondParameter<typeof customInstance>
214
+ ) => {
215
+ return customInstance<OrganisationGetDefaultResponse>(
216
+ { url: `/organisation/default`, method: "get" },
217
+ options
218
+ );
219
+ };
220
+
221
+ export const getGetDefaultOrganisationQueryKey = () => [
222
+ `/organisation/default`,
223
+ ];
224
+
225
+ export type GetDefaultOrganisationQueryResult = NonNullable<
226
+ AsyncReturnType<typeof getDefaultOrganisation>
227
+ >;
228
+ export type GetDefaultOrganisationQueryError = ErrorType<void | AsError>;
229
+
230
+ export const useGetDefaultOrganisation = <
231
+ TData = AsyncReturnType<typeof getDefaultOrganisation>,
232
+ TError = ErrorType<void | AsError>
233
+ >(options?: {
234
+ query?: UseQueryOptions<
235
+ AsyncReturnType<typeof getDefaultOrganisation>,
236
+ TError,
237
+ TData
238
+ >;
239
+ request?: SecondParameter<typeof customInstance>;
240
+ }): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
241
+ const { query: queryOptions, request: requestOptions } = options || {};
242
+
243
+ const queryKey =
244
+ queryOptions?.queryKey ?? getGetDefaultOrganisationQueryKey();
245
+
246
+ const queryFn: QueryFunction<
247
+ AsyncReturnType<typeof getDefaultOrganisation>
248
+ > = () => getDefaultOrganisation(requestOptions);
249
+
250
+ const query = useQuery<
251
+ AsyncReturnType<typeof getDefaultOrganisation>,
252
+ TError,
253
+ TData
254
+ >(queryKey, queryFn, queryOptions);
255
+
72
256
  return {
73
- appApiOrganisationGet,
74
- appApiOrganisationPost,
75
- appApiOrganisationDelete,
76
- appApiOrganisationGetDefault,
257
+ queryKey,
258
+ ...query,
77
259
  };
78
260
  };
79
- export type AppApiOrganisationGetResult =
80
- AxiosResponse<OrganisationsGetResponse>;
81
- export type AppApiOrganisationPostResult =
82
- AxiosResponse<OrganisationPostResponse>;
83
- export type AppApiOrganisationDeleteResult = AxiosResponse<void>;
84
- export type AppApiOrganisationGetDefaultResult =
85
- AxiosResponse<OrganisationGetDefaultResponse>;