@squonk/account-server-client 1.0.2-rc.3 → 1.0.3-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.
- package/asset/asset.cjs +34 -18
- package/asset/asset.cjs.map +1 -1
- package/asset/asset.d.ts +16 -16
- package/asset/asset.js +35 -19
- package/asset/asset.js.map +1 -1
- package/{custom-instance-b8075093.d.ts → custom-instance-93fb01eb.d.ts} +22 -20
- package/index.cjs.map +1 -1
- package/index.d.ts +1 -1
- package/index.js.map +1 -1
- package/merchant/merchant.cjs +15 -13
- package/merchant/merchant.cjs.map +1 -1
- package/merchant/merchant.d.ts +1 -1
- package/merchant/merchant.js +16 -14
- package/merchant/merchant.js.map +1 -1
- package/organisation/organisation.cjs +18 -6
- package/organisation/organisation.cjs.map +1 -1
- package/organisation/organisation.d.ts +7 -7
- package/organisation/organisation.js +19 -7
- package/organisation/organisation.js.map +1 -1
- package/package.json +1 -1
- package/product/product.cjs +47 -38
- package/product/product.cjs.map +1 -1
- package/product/product.d.ts +10 -10
- package/product/product.js +48 -39
- package/product/product.js.map +1 -1
- package/src/account-server-api.schemas.ts +73 -87
- package/src/asset/asset.ts +248 -345
- package/src/merchant/merchant.ts +62 -84
- package/src/organisation/organisation.ts +131 -184
- package/src/product/product.ts +279 -422
- package/src/state/state.ts +36 -42
- package/src/unit/unit.ts +218 -301
- package/src/user/user.ts +224 -327
- package/state/state.cjs +9 -9
- package/state/state.cjs.map +1 -1
- package/state/state.d.ts +1 -1
- package/state/state.js +10 -10
- package/state/state.js.map +1 -1
- package/unit/unit.cjs +40 -25
- package/unit/unit.cjs.map +1 -1
- package/unit/unit.d.ts +10 -10
- package/unit/unit.js +41 -26
- package/unit/unit.js.map +1 -1
- package/user/user.cjs +38 -20
- package/user/user.cjs.map +1 -1
- package/user/user.d.ts +10 -10
- package/user/user.js +39 -21
- package/user/user.js.map +1 -1
package/src/product/product.ts
CHANGED
|
@@ -8,15 +8,18 @@ A service that provides access to the Account Server, which gives *registered* u
|
|
|
8
8
|
|
|
9
9
|
* OpenAPI spec version: 1.0
|
|
10
10
|
*/
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
useQuery,
|
|
13
|
+
useMutation
|
|
14
|
+
} from 'react-query'
|
|
12
15
|
import type {
|
|
13
16
|
UseQueryOptions,
|
|
14
17
|
UseMutationOptions,
|
|
15
18
|
QueryFunction,
|
|
16
19
|
MutationFunction,
|
|
17
20
|
UseQueryResult,
|
|
18
|
-
QueryKey
|
|
19
|
-
} from
|
|
21
|
+
QueryKey
|
|
22
|
+
} from 'react-query'
|
|
20
23
|
import type {
|
|
21
24
|
ProductsGetTypesResponse,
|
|
22
25
|
AsError,
|
|
@@ -26,15 +29,16 @@ import type {
|
|
|
26
29
|
ProductUnitGetResponse,
|
|
27
30
|
ProductPatchBodyBody,
|
|
28
31
|
ProductChargesGetResponse,
|
|
29
|
-
GetProductChargesParams
|
|
30
|
-
} from
|
|
31
|
-
import { customInstance } from
|
|
32
|
-
import type { ErrorType } from
|
|
32
|
+
GetProductChargesParams
|
|
33
|
+
} from '../account-server-api.schemas'
|
|
34
|
+
import { customInstance } from '.././custom-instance'
|
|
35
|
+
import type { ErrorType } from '.././custom-instance'
|
|
36
|
+
|
|
33
37
|
|
|
34
38
|
// eslint-disable-next-line
|
|
35
|
-
type SecondParameter<T extends (...args: any) => any> = T extends (
|
|
39
|
+
type SecondParameter<T extends (...args: any) => any> = T extends (
|
|
36
40
|
config: any,
|
|
37
|
-
args: infer P
|
|
41
|
+
args: infer P,
|
|
38
42
|
) => any
|
|
39
43
|
? P
|
|
40
44
|
: never;
|
|
@@ -45,53 +49,41 @@ type SecondParameter<T extends (...args: any) => any> = T extends (
|
|
|
45
49
|
* @summary Gets all Product Types
|
|
46
50
|
*/
|
|
47
51
|
export const getProductTypes = (
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
|
|
53
|
+
options?: SecondParameter<typeof customInstance>,signal?: AbortSignal
|
|
50
54
|
) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
55
|
+
return customInstance<ProductsGetTypesResponse>(
|
|
56
|
+
{url: `/product-type`, method: 'get', signal
|
|
57
|
+
},
|
|
58
|
+
options);
|
|
59
|
+
}
|
|
60
|
+
|
|
56
61
|
|
|
57
62
|
export const getGetProductTypesQueryKey = () => [`/product-type`];
|
|
58
63
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
TError
|
|
67
|
-
|
|
68
|
-
query
|
|
69
|
-
Awaited<ReturnType<typeof getProductTypes>>,
|
|
70
|
-
TError,
|
|
71
|
-
TData
|
|
72
|
-
>;
|
|
73
|
-
request?: SecondParameter<typeof customInstance>;
|
|
74
|
-
}): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
75
|
-
const { query: queryOptions, request: requestOptions } = options ?? {};
|
|
64
|
+
|
|
65
|
+
export type GetProductTypesQueryResult = NonNullable<Awaited<ReturnType<typeof getProductTypes>>>
|
|
66
|
+
export type GetProductTypesQueryError = ErrorType<AsError | void>
|
|
67
|
+
|
|
68
|
+
export const useGetProductTypes = <TData = Awaited<ReturnType<typeof getProductTypes>>, TError = ErrorType<AsError | void>>(
|
|
69
|
+
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getProductTypes>>, TError, TData>, request?: SecondParameter<typeof customInstance>}
|
|
70
|
+
|
|
71
|
+
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
72
|
+
|
|
73
|
+
const {query: queryOptions, request: requestOptions} = options ?? {}
|
|
76
74
|
|
|
77
75
|
const queryKey = queryOptions?.queryKey ?? getGetProductTypesQueryKey();
|
|
78
76
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}) => getProductTypes(requestOptions, signal);
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
const queryFn: QueryFunction<Awaited<ReturnType<typeof getProductTypes>>> = ({ signal }) => getProductTypes(requestOptions, signal);
|
|
82
80
|
|
|
83
|
-
const query = useQuery<
|
|
84
|
-
Awaited<ReturnType<typeof getProductTypes>>,
|
|
85
|
-
TError,
|
|
86
|
-
TData
|
|
87
|
-
>(queryKey, queryFn, queryOptions) as UseQueryResult<TData, TError> & {
|
|
88
|
-
queryKey: QueryKey;
|
|
89
|
-
};
|
|
81
|
+
const query = useQuery<Awaited<ReturnType<typeof getProductTypes>>, TError, TData>(queryKey, queryFn, queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
90
82
|
|
|
91
83
|
query.queryKey = queryKey;
|
|
92
84
|
|
|
93
85
|
return query;
|
|
94
|
-
}
|
|
86
|
+
}
|
|
95
87
|
|
|
96
88
|
/**
|
|
97
89
|
* Gets products you have access to, across all Units and Organisations
|
|
@@ -99,53 +91,41 @@ export const useGetProductTypes = <
|
|
|
99
91
|
* @summary Gets all Products
|
|
100
92
|
*/
|
|
101
93
|
export const getProducts = (
|
|
102
|
-
|
|
103
|
-
|
|
94
|
+
|
|
95
|
+
options?: SecondParameter<typeof customInstance>,signal?: AbortSignal
|
|
104
96
|
) => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
97
|
+
return customInstance<ProductsGetResponse>(
|
|
98
|
+
{url: `/product`, method: 'get', signal
|
|
99
|
+
},
|
|
100
|
+
options);
|
|
101
|
+
}
|
|
102
|
+
|
|
110
103
|
|
|
111
104
|
export const getGetProductsQueryKey = () => [`/product`];
|
|
112
105
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
TError
|
|
121
|
-
|
|
122
|
-
query
|
|
123
|
-
Awaited<ReturnType<typeof getProducts>>,
|
|
124
|
-
TError,
|
|
125
|
-
TData
|
|
126
|
-
>;
|
|
127
|
-
request?: SecondParameter<typeof customInstance>;
|
|
128
|
-
}): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
129
|
-
const { query: queryOptions, request: requestOptions } = options ?? {};
|
|
106
|
+
|
|
107
|
+
export type GetProductsQueryResult = NonNullable<Awaited<ReturnType<typeof getProducts>>>
|
|
108
|
+
export type GetProductsQueryError = ErrorType<AsError | void>
|
|
109
|
+
|
|
110
|
+
export const useGetProducts = <TData = Awaited<ReturnType<typeof getProducts>>, TError = ErrorType<AsError | void>>(
|
|
111
|
+
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getProducts>>, TError, TData>, request?: SecondParameter<typeof customInstance>}
|
|
112
|
+
|
|
113
|
+
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
114
|
+
|
|
115
|
+
const {query: queryOptions, request: requestOptions} = options ?? {}
|
|
130
116
|
|
|
131
117
|
const queryKey = queryOptions?.queryKey ?? getGetProductsQueryKey();
|
|
132
118
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}) => getProducts(requestOptions, signal);
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
const queryFn: QueryFunction<Awaited<ReturnType<typeof getProducts>>> = ({ signal }) => getProducts(requestOptions, signal);
|
|
136
122
|
|
|
137
|
-
const query = useQuery<
|
|
138
|
-
Awaited<ReturnType<typeof getProducts>>,
|
|
139
|
-
TError,
|
|
140
|
-
TData
|
|
141
|
-
>(queryKey, queryFn, queryOptions) as UseQueryResult<TData, TError> & {
|
|
142
|
-
queryKey: QueryKey;
|
|
143
|
-
};
|
|
123
|
+
const query = useQuery<Awaited<ReturnType<typeof getProducts>>, TError, TData>(queryKey, queryFn, queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
144
124
|
|
|
145
125
|
query.queryKey = queryKey;
|
|
146
126
|
|
|
147
127
|
return query;
|
|
148
|
-
}
|
|
128
|
+
}
|
|
149
129
|
|
|
150
130
|
/**
|
|
151
131
|
* Gets products you have access to based on an Organisation
|
|
@@ -153,61 +133,41 @@ export const useGetProducts = <
|
|
|
153
133
|
* @summary Gets Products for an Organisation
|
|
154
134
|
*/
|
|
155
135
|
export const getProductsForOrganisation = (
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
signal?: AbortSignal
|
|
136
|
+
orgId: string,
|
|
137
|
+
options?: SecondParameter<typeof customInstance>,signal?: AbortSignal
|
|
159
138
|
) => {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
export type GetProductsForOrganisationQueryResult = NonNullable<
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
export
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
TData
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
189
|
-
const { query: queryOptions, request: requestOptions } = options ?? {};
|
|
190
|
-
|
|
191
|
-
const queryKey =
|
|
192
|
-
queryOptions?.queryKey ?? getGetProductsForOrganisationQueryKey(orgId);
|
|
193
|
-
|
|
194
|
-
const queryFn: QueryFunction<
|
|
195
|
-
Awaited<ReturnType<typeof getProductsForOrganisation>>
|
|
196
|
-
> = ({ signal }) => getProductsForOrganisation(orgId, requestOptions, signal);
|
|
197
|
-
|
|
198
|
-
const query = useQuery<
|
|
199
|
-
Awaited<ReturnType<typeof getProductsForOrganisation>>,
|
|
200
|
-
TError,
|
|
201
|
-
TData
|
|
202
|
-
>(queryKey, queryFn, { enabled: !!orgId, ...queryOptions }) as UseQueryResult<
|
|
203
|
-
TData,
|
|
204
|
-
TError
|
|
205
|
-
> & { queryKey: QueryKey };
|
|
139
|
+
return customInstance<ProductsGetResponse>(
|
|
140
|
+
{url: `/product/organisation/${orgId}`, method: 'get', signal
|
|
141
|
+
},
|
|
142
|
+
options);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
export const getGetProductsForOrganisationQueryKey = (orgId: string,) => [`/product/organisation/${orgId}`];
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
export type GetProductsForOrganisationQueryResult = NonNullable<Awaited<ReturnType<typeof getProductsForOrganisation>>>
|
|
150
|
+
export type GetProductsForOrganisationQueryError = ErrorType<void | AsError>
|
|
151
|
+
|
|
152
|
+
export const useGetProductsForOrganisation = <TData = Awaited<ReturnType<typeof getProductsForOrganisation>>, TError = ErrorType<void | AsError>>(
|
|
153
|
+
orgId: string, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getProductsForOrganisation>>, TError, TData>, request?: SecondParameter<typeof customInstance>}
|
|
154
|
+
|
|
155
|
+
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
156
|
+
|
|
157
|
+
const {query: queryOptions, request: requestOptions} = options ?? {}
|
|
158
|
+
|
|
159
|
+
const queryKey = queryOptions?.queryKey ?? getGetProductsForOrganisationQueryKey(orgId);
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
const queryFn: QueryFunction<Awaited<ReturnType<typeof getProductsForOrganisation>>> = ({ signal }) => getProductsForOrganisation(orgId, requestOptions, signal);
|
|
164
|
+
|
|
165
|
+
const query = useQuery<Awaited<ReturnType<typeof getProductsForOrganisation>>, TError, TData>(queryKey, queryFn, {enabled: !!(orgId), ...queryOptions}) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
206
166
|
|
|
207
167
|
query.queryKey = queryKey;
|
|
208
168
|
|
|
209
169
|
return query;
|
|
210
|
-
}
|
|
170
|
+
}
|
|
211
171
|
|
|
212
172
|
/**
|
|
213
173
|
* Products are **Subscriptions** that you create in a Unit and use **Merchant** services like the `DATA_MANAGER`.
|
|
@@ -219,118 +179,81 @@ Some subscriptions, like the `DATA_MANAGER_PROJECT_TIER_SUBSCRIPTION` are availa
|
|
|
219
179
|
* @summary Creates a Product for an Organisational Unit
|
|
220
180
|
*/
|
|
221
181
|
export const createUnitProduct = (
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
method: "post",
|
|
230
|
-
headers: { "Content-Type": "application/json" },
|
|
231
|
-
data: unitProductPostBodyBody,
|
|
182
|
+
unitId: string,
|
|
183
|
+
unitProductPostBodyBody: UnitProductPostBodyBody,
|
|
184
|
+
options?: SecondParameter<typeof customInstance>,) => {
|
|
185
|
+
return customInstance<UnitProductPostResponse>(
|
|
186
|
+
{url: `/product/unit/${unitId}`, method: 'post',
|
|
187
|
+
headers: {'Content-Type': 'application/json', },
|
|
188
|
+
data: unitProductPostBodyBody
|
|
232
189
|
},
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
export type
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
> = (props) => {
|
|
261
|
-
const { unitId, data } = props ?? {};
|
|
262
|
-
|
|
263
|
-
return createUnitProduct(unitId, data, requestOptions);
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
return useMutation<
|
|
267
|
-
Awaited<ReturnType<typeof createUnitProduct>>,
|
|
268
|
-
TError,
|
|
269
|
-
{ unitId: string; data: UnitProductPostBodyBody },
|
|
270
|
-
TContext
|
|
271
|
-
>(mutationFn, mutationOptions);
|
|
272
|
-
};
|
|
273
|
-
/**
|
|
190
|
+
options);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
export type CreateUnitProductMutationResult = NonNullable<Awaited<ReturnType<typeof createUnitProduct>>>
|
|
196
|
+
export type CreateUnitProductMutationBody = UnitProductPostBodyBody
|
|
197
|
+
export type CreateUnitProductMutationError = ErrorType<AsError | void>
|
|
198
|
+
|
|
199
|
+
export const useCreateUnitProduct = <TError = ErrorType<AsError | void>,
|
|
200
|
+
|
|
201
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createUnitProduct>>, TError,{unitId: string;data: UnitProductPostBodyBody}, TContext>, request?: SecondParameter<typeof customInstance>}
|
|
202
|
+
) => {
|
|
203
|
+
const {mutation: mutationOptions, request: requestOptions} = options ?? {}
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<typeof createUnitProduct>>, {unitId: string;data: UnitProductPostBodyBody}> = (props) => {
|
|
209
|
+
const {unitId,data} = props ?? {};
|
|
210
|
+
|
|
211
|
+
return createUnitProduct(unitId,data,requestOptions)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return useMutation<Awaited<ReturnType<typeof createUnitProduct>>, TError, {unitId: string;data: UnitProductPostBodyBody}, TContext>(mutationFn, mutationOptions)
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
274
217
|
* Gets products you have access to based on an Organisational Unit
|
|
275
218
|
|
|
276
219
|
* @summary Gets Products for an Organisational Unit
|
|
277
220
|
*/
|
|
278
221
|
export const getProductsForUnit = (
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
signal?: AbortSignal
|
|
222
|
+
unitId: string,
|
|
223
|
+
options?: SecondParameter<typeof customInstance>,signal?: AbortSignal
|
|
282
224
|
) => {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
export type GetProductsForUnitQueryResult = NonNullable<
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
export
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
TData
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
312
|
-
const { query: queryOptions, request: requestOptions } = options ?? {};
|
|
313
|
-
|
|
314
|
-
const queryKey =
|
|
315
|
-
queryOptions?.queryKey ?? getGetProductsForUnitQueryKey(unitId);
|
|
316
|
-
|
|
317
|
-
const queryFn: QueryFunction<
|
|
318
|
-
Awaited<ReturnType<typeof getProductsForUnit>>
|
|
319
|
-
> = ({ signal }) => getProductsForUnit(unitId, requestOptions, signal);
|
|
320
|
-
|
|
321
|
-
const query = useQuery<
|
|
322
|
-
Awaited<ReturnType<typeof getProductsForUnit>>,
|
|
323
|
-
TError,
|
|
324
|
-
TData
|
|
325
|
-
>(queryKey, queryFn, {
|
|
326
|
-
enabled: !!unitId,
|
|
327
|
-
...queryOptions,
|
|
328
|
-
}) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
225
|
+
return customInstance<ProductsGetResponse>(
|
|
226
|
+
{url: `/product/unit/${unitId}`, method: 'get', signal
|
|
227
|
+
},
|
|
228
|
+
options);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
export const getGetProductsForUnitQueryKey = (unitId: string,) => [`/product/unit/${unitId}`];
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
export type GetProductsForUnitQueryResult = NonNullable<Awaited<ReturnType<typeof getProductsForUnit>>>
|
|
236
|
+
export type GetProductsForUnitQueryError = ErrorType<void | AsError>
|
|
237
|
+
|
|
238
|
+
export const useGetProductsForUnit = <TData = Awaited<ReturnType<typeof getProductsForUnit>>, TError = ErrorType<void | AsError>>(
|
|
239
|
+
unitId: string, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getProductsForUnit>>, TError, TData>, request?: SecondParameter<typeof customInstance>}
|
|
240
|
+
|
|
241
|
+
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
242
|
+
|
|
243
|
+
const {query: queryOptions, request: requestOptions} = options ?? {}
|
|
244
|
+
|
|
245
|
+
const queryKey = queryOptions?.queryKey ?? getGetProductsForUnitQueryKey(unitId);
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
const queryFn: QueryFunction<Awaited<ReturnType<typeof getProductsForUnit>>> = ({ signal }) => getProductsForUnit(unitId, requestOptions, signal);
|
|
250
|
+
|
|
251
|
+
const query = useQuery<Awaited<ReturnType<typeof getProductsForUnit>>, TError, TData>(queryKey, queryFn, {enabled: !!(unitId), ...queryOptions}) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
329
252
|
|
|
330
253
|
query.queryKey = queryKey;
|
|
331
254
|
|
|
332
255
|
return query;
|
|
333
|
-
}
|
|
256
|
+
}
|
|
334
257
|
|
|
335
258
|
/**
|
|
336
259
|
* Gets a Product
|
|
@@ -338,165 +261,118 @@ export const useGetProductsForUnit = <
|
|
|
338
261
|
* @summary Gets a Product
|
|
339
262
|
*/
|
|
340
263
|
export const getProduct = (
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
signal?: AbortSignal
|
|
264
|
+
productId: string,
|
|
265
|
+
options?: SecondParameter<typeof customInstance>,signal?: AbortSignal
|
|
344
266
|
) => {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
export type GetProductQueryResult = NonNullable<
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
export
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
TData
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
productId: string,
|
|
365
|
-
options?: {
|
|
366
|
-
query?: UseQueryOptions<
|
|
367
|
-
Awaited<ReturnType<typeof getProduct>>,
|
|
368
|
-
TError,
|
|
369
|
-
TData
|
|
370
|
-
>;
|
|
371
|
-
request?: SecondParameter<typeof customInstance>;
|
|
372
|
-
}
|
|
373
|
-
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
374
|
-
const { query: queryOptions, request: requestOptions } = options ?? {};
|
|
267
|
+
return customInstance<ProductUnitGetResponse>(
|
|
268
|
+
{url: `/product/${productId}`, method: 'get', signal
|
|
269
|
+
},
|
|
270
|
+
options);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
export const getGetProductQueryKey = (productId: string,) => [`/product/${productId}`];
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
export type GetProductQueryResult = NonNullable<Awaited<ReturnType<typeof getProduct>>>
|
|
278
|
+
export type GetProductQueryError = ErrorType<AsError | void>
|
|
279
|
+
|
|
280
|
+
export const useGetProduct = <TData = Awaited<ReturnType<typeof getProduct>>, TError = ErrorType<AsError | void>>(
|
|
281
|
+
productId: string, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getProduct>>, TError, TData>, request?: SecondParameter<typeof customInstance>}
|
|
282
|
+
|
|
283
|
+
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
284
|
+
|
|
285
|
+
const {query: queryOptions, request: requestOptions} = options ?? {}
|
|
375
286
|
|
|
376
287
|
const queryKey = queryOptions?.queryKey ?? getGetProductQueryKey(productId);
|
|
377
288
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}) => getProduct(productId, requestOptions, signal);
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
const queryFn: QueryFunction<Awaited<ReturnType<typeof getProduct>>> = ({ signal }) => getProduct(productId, requestOptions, signal);
|
|
381
292
|
|
|
382
|
-
const query = useQuery<Awaited<ReturnType<typeof getProduct>>, TError, TData>(
|
|
383
|
-
queryKey,
|
|
384
|
-
queryFn,
|
|
385
|
-
{ enabled: !!productId, ...queryOptions }
|
|
386
|
-
) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
293
|
+
const query = useQuery<Awaited<ReturnType<typeof getProduct>>, TError, TData>(queryKey, queryFn, {enabled: !!(productId), ...queryOptions}) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
387
294
|
|
|
388
295
|
query.queryKey = queryKey;
|
|
389
296
|
|
|
390
297
|
return query;
|
|
391
|
-
}
|
|
298
|
+
}
|
|
392
299
|
|
|
393
300
|
/**
|
|
394
301
|
* @summary Deletes an existing Product
|
|
395
302
|
*/
|
|
396
303
|
export const deleteProduct = (
|
|
397
|
-
|
|
398
|
-
|
|
304
|
+
productId: string,
|
|
305
|
+
options?: SecondParameter<typeof customInstance>,) => {
|
|
306
|
+
return customInstance<void>(
|
|
307
|
+
{url: `/product/${productId}`, method: 'delete'
|
|
308
|
+
},
|
|
309
|
+
options);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
export type DeleteProductMutationResult = NonNullable<Awaited<ReturnType<typeof deleteProduct>>>
|
|
315
|
+
|
|
316
|
+
export type DeleteProductMutationError = ErrorType<AsError>
|
|
317
|
+
|
|
318
|
+
export const useDeleteProduct = <TError = ErrorType<AsError>,
|
|
319
|
+
|
|
320
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteProduct>>, TError,{productId: string}, TContext>, request?: SecondParameter<typeof customInstance>}
|
|
399
321
|
) => {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
TContext = unknown
|
|
415
|
-
>(options?: {
|
|
416
|
-
mutation?: UseMutationOptions<
|
|
417
|
-
Awaited<ReturnType<typeof deleteProduct>>,
|
|
418
|
-
TError,
|
|
419
|
-
{ productId: string },
|
|
420
|
-
TContext
|
|
421
|
-
>;
|
|
422
|
-
request?: SecondParameter<typeof customInstance>;
|
|
423
|
-
}) => {
|
|
424
|
-
const { mutation: mutationOptions, request: requestOptions } = options ?? {};
|
|
425
|
-
|
|
426
|
-
const mutationFn: MutationFunction<
|
|
427
|
-
Awaited<ReturnType<typeof deleteProduct>>,
|
|
428
|
-
{ productId: string }
|
|
429
|
-
> = (props) => {
|
|
430
|
-
const { productId } = props ?? {};
|
|
431
|
-
|
|
432
|
-
return deleteProduct(productId, requestOptions);
|
|
433
|
-
};
|
|
434
|
-
|
|
435
|
-
return useMutation<
|
|
436
|
-
Awaited<ReturnType<typeof deleteProduct>>,
|
|
437
|
-
TError,
|
|
438
|
-
{ productId: string },
|
|
439
|
-
TContext
|
|
440
|
-
>(mutationFn, mutationOptions);
|
|
441
|
-
};
|
|
442
|
-
/**
|
|
322
|
+
const {mutation: mutationOptions, request: requestOptions} = options ?? {}
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteProduct>>, {productId: string}> = (props) => {
|
|
328
|
+
const {productId} = props ?? {};
|
|
329
|
+
|
|
330
|
+
return deleteProduct(productId,requestOptions)
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return useMutation<Awaited<ReturnType<typeof deleteProduct>>, TError, {productId: string}, TContext>(mutationFn, mutationOptions)
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
443
336
|
* 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`
|
|
444
337
|
|
|
445
338
|
* @summary Adjust an existing Product
|
|
446
339
|
*/
|
|
447
340
|
export const patchProduct = (
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
method: "patch",
|
|
456
|
-
headers: { "Content-Type": "application/json" },
|
|
457
|
-
data: productPatchBodyBody,
|
|
341
|
+
productId: string,
|
|
342
|
+
productPatchBodyBody: ProductPatchBodyBody,
|
|
343
|
+
options?: SecondParameter<typeof customInstance>,) => {
|
|
344
|
+
return customInstance<void>(
|
|
345
|
+
{url: `/product/${productId}`, method: 'patch',
|
|
346
|
+
headers: {'Content-Type': 'application/json', },
|
|
347
|
+
data: productPatchBodyBody
|
|
458
348
|
},
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
export type
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
> = (props) => {
|
|
487
|
-
const { productId, data } = props ?? {};
|
|
488
|
-
|
|
489
|
-
return patchProduct(productId, data, requestOptions);
|
|
490
|
-
};
|
|
491
|
-
|
|
492
|
-
return useMutation<
|
|
493
|
-
Awaited<ReturnType<typeof patchProduct>>,
|
|
494
|
-
TError,
|
|
495
|
-
{ productId: string; data: ProductPatchBodyBody },
|
|
496
|
-
TContext
|
|
497
|
-
>(mutationFn, mutationOptions);
|
|
498
|
-
};
|
|
499
|
-
/**
|
|
349
|
+
options);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
export type PatchProductMutationResult = NonNullable<Awaited<ReturnType<typeof patchProduct>>>
|
|
355
|
+
export type PatchProductMutationBody = ProductPatchBodyBody
|
|
356
|
+
export type PatchProductMutationError = ErrorType<AsError>
|
|
357
|
+
|
|
358
|
+
export const usePatchProduct = <TError = ErrorType<AsError>,
|
|
359
|
+
|
|
360
|
+
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof patchProduct>>, TError,{productId: string;data: ProductPatchBodyBody}, TContext>, request?: SecondParameter<typeof customInstance>}
|
|
361
|
+
) => {
|
|
362
|
+
const {mutation: mutationOptions, request: requestOptions} = options ?? {}
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<typeof patchProduct>>, {productId: string;data: ProductPatchBodyBody}> = (props) => {
|
|
368
|
+
const {productId,data} = props ?? {};
|
|
369
|
+
|
|
370
|
+
return patchProduct(productId,data,requestOptions)
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return useMutation<Awaited<ReturnType<typeof patchProduct>>, TError, {productId: string;data: ProductPatchBodyBody}, TContext>(mutationFn, mutationOptions)
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
500
376
|
* Get the charges made against a product with optional **from** (inclusive) and **until** (exclusive) dates. If no dates are provided, the charges for the current billing period are returned.
|
|
501
377
|
|
|
502
378
|
Dates are interpreted using the Python dateutil parser so the input strings are extremely flexible, i.e. `1 December 2021` is an acceptable format.
|
|
@@ -507,62 +383,43 @@ You need **admin** rights to use this method
|
|
|
507
383
|
* @summary Get charges made against a Product
|
|
508
384
|
*/
|
|
509
385
|
export const getProductCharges = (
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
signal?: AbortSignal
|
|
386
|
+
productId: string,
|
|
387
|
+
params?: GetProductChargesParams,
|
|
388
|
+
options?: SecondParameter<typeof customInstance>,signal?: AbortSignal
|
|
514
389
|
) => {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
) => [`/product/${productId}/charges`, ...(params ? [params]
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
>
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
}
|
|
545
|
-
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
546
|
-
const { query: queryOptions, request: requestOptions } = options ?? {};
|
|
547
|
-
|
|
548
|
-
const queryKey =
|
|
549
|
-
queryOptions?.queryKey ?? getGetProductChargesQueryKey(productId, params);
|
|
550
|
-
|
|
551
|
-
const queryFn: QueryFunction<
|
|
552
|
-
Awaited<ReturnType<typeof getProductCharges>>
|
|
553
|
-
> = ({ signal }) =>
|
|
554
|
-
getProductCharges(productId, params, requestOptions, signal);
|
|
555
|
-
|
|
556
|
-
const query = useQuery<
|
|
557
|
-
Awaited<ReturnType<typeof getProductCharges>>,
|
|
558
|
-
TError,
|
|
559
|
-
TData
|
|
560
|
-
>(queryKey, queryFn, {
|
|
561
|
-
enabled: !!productId,
|
|
562
|
-
...queryOptions,
|
|
563
|
-
}) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
390
|
+
return customInstance<ProductChargesGetResponse>(
|
|
391
|
+
{url: `/product/${productId}/charges`, method: 'get',
|
|
392
|
+
params, signal
|
|
393
|
+
},
|
|
394
|
+
options);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
export const getGetProductChargesQueryKey = (productId: string,
|
|
399
|
+
params?: GetProductChargesParams,) => [`/product/${productId}/charges`, ...(params ? [params]: [])];
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
export type GetProductChargesQueryResult = NonNullable<Awaited<ReturnType<typeof getProductCharges>>>
|
|
403
|
+
export type GetProductChargesQueryError = ErrorType<AsError | void>
|
|
404
|
+
|
|
405
|
+
export const useGetProductCharges = <TData = Awaited<ReturnType<typeof getProductCharges>>, TError = ErrorType<AsError | void>>(
|
|
406
|
+
productId: string,
|
|
407
|
+
params?: GetProductChargesParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getProductCharges>>, TError, TData>, request?: SecondParameter<typeof customInstance>}
|
|
408
|
+
|
|
409
|
+
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
410
|
+
|
|
411
|
+
const {query: queryOptions, request: requestOptions} = options ?? {}
|
|
412
|
+
|
|
413
|
+
const queryKey = queryOptions?.queryKey ?? getGetProductChargesQueryKey(productId,params);
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
const queryFn: QueryFunction<Awaited<ReturnType<typeof getProductCharges>>> = ({ signal }) => getProductCharges(productId,params, requestOptions, signal);
|
|
418
|
+
|
|
419
|
+
const query = useQuery<Awaited<ReturnType<typeof getProductCharges>>, TError, TData>(queryKey, queryFn, {enabled: !!(productId), ...queryOptions}) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
564
420
|
|
|
565
421
|
query.queryKey = queryKey;
|
|
566
422
|
|
|
567
423
|
return query;
|
|
568
|
-
}
|
|
424
|
+
}
|
|
425
|
+
|