@squonk/account-server-client 0.1.5-rc.2 → 0.1.8-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/{custom-instance-d8cc704b.d.ts → custom-instance-cc5da68e.d.ts} +169 -120
- package/index.cjs +103 -2
- package/index.cjs.map +3 -3
- package/index.d.ts +1 -1
- package/index.js +69 -2
- package/index.js.map +3 -3
- package/organisation/organisation.cjs +111 -2
- package/organisation/organisation.cjs.map +3 -3
- package/organisation/organisation.d.ts +28 -123
- package/organisation/organisation.js +83 -2
- package/organisation/organisation.js.map +3 -3
- package/organisation/package.json +2 -1
- package/package.json +8 -8
- package/product/package.json +2 -1
- package/product/product.cjs +161 -2
- package/product/product.cjs.map +3 -3
- package/product/product.d.ts +60 -241
- package/product/product.js +127 -2
- package/product/product.js.map +3 -3
- package/src/account-server-api.schemas.ts +278 -0
- package/src/custom-instance.ts +52 -0
- package/src/index.ts +6 -0
- package/src/organisation/organisation.ts +181 -0
- package/src/product/product.ts +289 -0
- package/src/unit/unit.ts +322 -0
- package/src/user/user.ts +340 -0
- package/unit/package.json +2 -1
- package/unit/unit.cjs +168 -2
- package/unit/unit.cjs.map +3 -3
- package/unit/unit.d.ts +58 -122
- package/unit/unit.js +133 -2
- package/unit/unit.js.map +3 -3
- package/user/package.json +2 -1
- package/user/user.cjs +176 -2
- package/user/user.cjs.map +3 -3
- package/user/user.d.ts +20 -246
- package/user/user.js +141 -2
- package/user/user.js.map +3 -3
- package/chunk-OULWOQLW.cjs +0 -2
- package/chunk-OULWOQLW.cjs.map +0 -7
- package/chunk-WMX3LCLR.js +0 -2
- package/chunk-WMX3LCLR.js.map +0 -7
|
@@ -1,2 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
25
|
+
var __export = (target, all) => {
|
|
26
|
+
__markAsModule(target);
|
|
27
|
+
for (var name in all)
|
|
28
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
29
|
+
};
|
|
30
|
+
var __reExport = (target, module2, desc) => {
|
|
31
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
32
|
+
for (let key of __getOwnPropNames(module2))
|
|
33
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
34
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
35
|
+
}
|
|
36
|
+
return target;
|
|
37
|
+
};
|
|
38
|
+
var __toModule = (module2) => {
|
|
39
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/organisation/organisation.ts
|
|
43
|
+
__export(exports, {
|
|
44
|
+
createOrganisation: () => createOrganisation,
|
|
45
|
+
deleteOrganisation: () => deleteOrganisation,
|
|
46
|
+
getGetOrganisationsQueryKey: () => getGetOrganisationsQueryKey,
|
|
47
|
+
getOrganisations: () => getOrganisations,
|
|
48
|
+
useCreateOrganisation: () => useCreateOrganisation,
|
|
49
|
+
useDeleteOrganisation: () => useDeleteOrganisation,
|
|
50
|
+
useGetOrganisations: () => useGetOrganisations
|
|
51
|
+
});
|
|
52
|
+
var import_react_query = __toModule(require("react-query"));
|
|
53
|
+
|
|
54
|
+
// src/custom-instance.ts
|
|
55
|
+
var import_axios = __toModule(require("axios"));
|
|
56
|
+
var AXIOS_INSTANCE = import_axios.default.create({ baseURL: "" });
|
|
57
|
+
var customInstance = (config, options) => {
|
|
58
|
+
const source = import_axios.default.CancelToken.source();
|
|
59
|
+
const promise = AXIOS_INSTANCE(__spreadProps(__spreadValues(__spreadValues({}, config), options), { cancelToken: source.token })).then(({ data }) => data);
|
|
60
|
+
promise.cancel = () => {
|
|
61
|
+
source.cancel("Query was cancelled by React Query");
|
|
62
|
+
};
|
|
63
|
+
return promise;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/organisation/organisation.ts
|
|
67
|
+
var getOrganisations = (options) => {
|
|
68
|
+
return customInstance({ url: `/organisation`, method: "get" }, options);
|
|
69
|
+
};
|
|
70
|
+
var getGetOrganisationsQueryKey = () => [`/organisation`];
|
|
71
|
+
var useGetOrganisations = (options) => {
|
|
72
|
+
const { query: queryOptions, request: requestOptions } = options || {};
|
|
73
|
+
const queryKey = (queryOptions == null ? void 0 : queryOptions.queryKey) ?? getGetOrganisationsQueryKey();
|
|
74
|
+
const queryFn = () => getOrganisations(requestOptions);
|
|
75
|
+
const query = (0, import_react_query.useQuery)(queryKey, queryFn, queryOptions);
|
|
76
|
+
return __spreadValues({
|
|
77
|
+
queryKey
|
|
78
|
+
}, query);
|
|
79
|
+
};
|
|
80
|
+
var createOrganisation = (organisationPostBodyBody, options) => {
|
|
81
|
+
return customInstance({ url: `/organisation`, method: "post", data: organisationPostBodyBody }, options);
|
|
82
|
+
};
|
|
83
|
+
var useCreateOrganisation = (options) => {
|
|
84
|
+
const { mutation: mutationOptions, request: requestOptions } = options || {};
|
|
85
|
+
const mutationFn = (props) => {
|
|
86
|
+
const { data } = props || {};
|
|
87
|
+
return createOrganisation(data, requestOptions);
|
|
88
|
+
};
|
|
89
|
+
return (0, import_react_query.useMutation)(mutationFn, mutationOptions);
|
|
90
|
+
};
|
|
91
|
+
var deleteOrganisation = (orgid, options) => {
|
|
92
|
+
return customInstance({ url: `/organisation/${orgid}`, method: "delete", data: void 0 }, options);
|
|
93
|
+
};
|
|
94
|
+
var useDeleteOrganisation = (options) => {
|
|
95
|
+
const { mutation: mutationOptions, request: requestOptions } = options || {};
|
|
96
|
+
const mutationFn = (props) => {
|
|
97
|
+
const { orgid } = props || {};
|
|
98
|
+
return deleteOrganisation(orgid, requestOptions);
|
|
99
|
+
};
|
|
100
|
+
return (0, import_react_query.useMutation)(mutationFn, mutationOptions);
|
|
101
|
+
};
|
|
102
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
+
0 && (module.exports = {
|
|
104
|
+
createOrganisation,
|
|
105
|
+
deleteOrganisation,
|
|
106
|
+
getGetOrganisationsQueryKey,
|
|
107
|
+
getOrganisations,
|
|
108
|
+
useCreateOrganisation,
|
|
109
|
+
useDeleteOrganisation,
|
|
110
|
+
useGetOrganisations
|
|
111
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/organisation/organisation.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Generated by orval v6.
|
|
5
|
-
"mappings": "
|
|
3
|
+
"sources": ["../../src/organisation/organisation.ts", "../../src/custom-instance.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Generated by orval v6.4.2 \uD83C\uDF7A\n * Do not edit manually.\n * Account Server API\n * The Informatics Matters Account Server API.\n\nA service that provides access to the Account Server, which gives *registered* users access to and management of **Products**, **Organisations**, **Units** and **Users**.\n\n * OpenAPI spec version: 0.1\n */\nimport {\n useQuery,\n useMutation,\n UseQueryOptions,\n UseMutationOptions,\n QueryFunction,\n MutationFunction,\n UseQueryResult,\n QueryKey,\n} from \"react-query\";\nimport type {\n OrganisationsGetResponse,\n AsError,\n OrganisationPostResponse,\n OrganisationPostBodyBody,\n} from \"../account-server-api.schemas\";\nimport { customInstance, ErrorType } from \".././custom-instance\";\n\ntype AsyncReturnType<T extends (...args: any) => Promise<any>> = T extends (\n ...args: any\n) => Promise<infer R>\n ? R\n : any;\n\ntype SecondParameter<T extends (...args: any) => any> = T extends (\n config: any,\n args: infer P\n) => any\n ? P\n : never;\n\n/**\n * Gets all the Organisations you are a member of. Admin users can see all Organisations\n\n * @summary Gets Organisations\n */\nexport const getOrganisations = (\n options?: SecondParameter<typeof customInstance>\n) => {\n return customInstance<OrganisationsGetResponse>(\n { url: `/organisation`, method: \"get\" },\n options\n );\n};\n\nexport const getGetOrganisationsQueryKey = () => [`/organisation`];\n\nexport const useGetOrganisations = <\n TData = AsyncReturnType<typeof getOrganisations>,\n TError = ErrorType<void | AsError>\n>(options?: {\n query?: UseQueryOptions<\n AsyncReturnType<typeof getOrganisations>,\n TError,\n TData\n >;\n request?: SecondParameter<typeof customInstance>;\n}): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {\n const { query: queryOptions, request: requestOptions } = options || {};\n\n const queryKey = queryOptions?.queryKey ?? getGetOrganisationsQueryKey();\n\n const queryFn: QueryFunction<AsyncReturnType<typeof getOrganisations>> = () =>\n getOrganisations(requestOptions);\n\n const query = useQuery<\n AsyncReturnType<typeof getOrganisations>,\n TError,\n TData\n >(queryKey, queryFn, queryOptions);\n\n return {\n queryKey,\n ...query,\n };\n};\n\n/**\n * Creates a new Organisation\n\nYou need **admin** rights to use this method\n\n * @summary Create a new organisation\n */\nexport const createOrganisation = (\n organisationPostBodyBody: OrganisationPostBodyBody,\n options?: SecondParameter<typeof customInstance>\n) => {\n return customInstance<OrganisationPostResponse>(\n { url: `/organisation`, method: \"post\", data: organisationPostBodyBody },\n options\n );\n};\n\nexport const useCreateOrganisation = <\n TError = ErrorType<AsError | void>,\n TContext = unknown\n>(options?: {\n mutation?: UseMutationOptions<\n AsyncReturnType<typeof createOrganisation>,\n TError,\n { data: OrganisationPostBodyBody },\n TContext\n >;\n request?: SecondParameter<typeof customInstance>;\n}) => {\n const { mutation: mutationOptions, request: requestOptions } = options || {};\n\n const mutationFn: MutationFunction<\n AsyncReturnType<typeof createOrganisation>,\n { data: OrganisationPostBodyBody }\n > = (props) => {\n const { data } = props || {};\n\n return createOrganisation(data, requestOptions);\n };\n\n return useMutation<\n AsyncReturnType<typeof createOrganisation>,\n TError,\n { data: OrganisationPostBodyBody },\n TContext\n >(mutationFn, mutationOptions);\n};\n/**\n * Units must first be deleted before an Organisation can be deleted\n\nYou need **admin** rights to use this method\n\n * @summary Deletes an Organisation\n */\nexport const deleteOrganisation = (\n orgid: string,\n options?: SecondParameter<typeof customInstance>\n) => {\n return customInstance<void>(\n { url: `/organisation/${orgid}`, method: \"delete\", data: undefined },\n options\n );\n};\n\nexport const useDeleteOrganisation = <\n TError = ErrorType<AsError>,\n TContext = unknown\n>(options?: {\n mutation?: UseMutationOptions<\n AsyncReturnType<typeof deleteOrganisation>,\n TError,\n { orgid: string },\n TContext\n >;\n request?: SecondParameter<typeof customInstance>;\n}) => {\n const { mutation: mutationOptions, request: requestOptions } = options || {};\n\n const mutationFn: MutationFunction<\n AsyncReturnType<typeof deleteOrganisation>,\n { orgid: string }\n > = (props) => {\n const { orgid } = props || {};\n\n return deleteOrganisation(orgid, requestOptions);\n };\n\n return useMutation<\n AsyncReturnType<typeof deleteOrganisation>,\n TError,\n { orgid: string },\n TContext\n >(mutationFn, mutationOptions);\n};\n", "/** Based off the example custom-instance from Orval docs\n * https://github.com/anymaniax/orval/blob/master/samples/react-app-with-react-query/src/api/mutator/custom-instance.ts\n *\n * See https://react-query.tanstack.com/guides/query-cancellation\n *\n * TODO: Considering using Fetch-API instead of axios. This instance will have to change. Could be\n * achieved without changing much using `redaxios`\n * Or use 'ky'\n */\n\nimport Axios, { AxiosError, AxiosRequestConfig } from 'axios';\n\n// ? Need the baseUrl or does it default to ''?\nexport const AXIOS_INSTANCE = Axios.create({ baseURL: '' });\n\n/**\n * Set the access token to be added as the `Authorization: Bearer 'token'` header\n * Useful for client only apps where a proxy API route isn't involved to securely add the access token\n * @param token access token\n */\nexport const setAuthToken = (token: string) => {\n AXIOS_INSTANCE.defaults.headers.common['Authorization'] = `Bearer ${token}`;\n};\n\n/**\n * Set the url to which request paths are added to.\n * @param baseUrl origin + subpath e.g. 'https://example.com/subpath' or '/subpath'\n */\nexport const setBaseUrl = (baseUrl: string) => {\n AXIOS_INSTANCE.defaults.baseURL = baseUrl;\n};\n\nexport const customInstance = <TReturn>(\n config: AxiosRequestConfig,\n options?: AxiosRequestConfig,\n): Promise<TReturn> => {\n const source = Axios.CancelToken.source();\n\n const promise = AXIOS_INSTANCE({ ...config, ...options, cancelToken: source.token }).then(\n ({ data }) => data,\n );\n\n // Promise doesn't have a cancel method but react-query requires this method to make cancellations general.\n // This can either be a any assertion or a @ts-ignore comment.\n (promise as any).cancel = () => {\n source.cancel('Query was cancelled by React Query');\n };\n\n return promise;\n};\n\nexport type ErrorType<TError> = AxiosError<TError>;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,yBASO;;;ACTP,mBAAsD;AAG/C,IAAM,iBAAiB,qBAAM,OAAO,EAAE,SAAS;AAmB/C,IAAM,iBAAiB,CAC5B,QACA,YACqB;AACrB,QAAM,SAAS,qBAAM,YAAY;AAEjC,QAAM,UAAU,eAAe,gDAAK,SAAW,UAAhB,EAAyB,aAAa,OAAO,UAAS,KACnF,CAAC,EAAE,WAAW;AAKhB,EAAC,QAAgB,SAAS,MAAM;AAC9B,WAAO,OAAO;AAAA;AAGhB,SAAO;AAAA;;;ADFF,IAAM,mBAAmB,CAC9B,YACG;AACH,SAAO,eACL,EAAE,KAAK,iBAAiB,QAAQ,SAChC;AAAA;AAIG,IAAM,8BAA8B,MAAM,CAAC;AAE3C,IAAM,sBAAsB,CAGjC,YAO4D;AAC5D,QAAM,EAAE,OAAO,cAAc,SAAS,mBAAmB,WAAW;AAEpE,QAAM,WAAW,8CAAc,aAAY;AAE3C,QAAM,UAAmE,MACvE,iBAAiB;AAEnB,QAAM,QAAQ,iCAIZ,UAAU,SAAS;AAErB,SAAO;AAAA,IACL;AAAA,KACG;AAAA;AAWA,IAAM,qBAAqB,CAChC,0BACA,YACG;AACH,SAAO,eACL,EAAE,KAAK,iBAAiB,QAAQ,QAAQ,MAAM,4BAC9C;AAAA;AAIG,IAAM,wBAAwB,CAGnC,YAQI;AACJ,QAAM,EAAE,UAAU,iBAAiB,SAAS,mBAAmB,WAAW;AAE1E,QAAM,aAGF,CAAC,UAAU;AACb,UAAM,EAAE,SAAS,SAAS;AAE1B,WAAO,mBAAmB,MAAM;AAAA;AAGlC,SAAO,oCAKL,YAAY;AAAA;AAST,IAAM,qBAAqB,CAChC,OACA,YACG;AACH,SAAO,eACL,EAAE,KAAK,iBAAiB,SAAS,QAAQ,UAAU,MAAM,UACzD;AAAA;AAIG,IAAM,wBAAwB,CAGnC,YAQI;AACJ,QAAM,EAAE,UAAU,iBAAiB,SAAS,mBAAmB,WAAW;AAE1E,QAAM,aAGF,CAAC,UAAU;AACb,UAAM,EAAE,UAAU,SAAS;AAE3B,WAAO,mBAAmB,OAAO;AAAA;AAGnC,SAAO,oCAKL,YAAY;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,142 +1,31 @@
|
|
|
1
1
|
import * as react_query from 'react-query';
|
|
2
|
-
import { UseQueryOptions, UseMutationOptions } from 'react-query';
|
|
3
|
-
import {
|
|
2
|
+
import { UseQueryOptions, QueryKey, UseQueryResult, UseMutationOptions } from 'react-query';
|
|
3
|
+
import { H as customInstance, y as OrganisationsGetResponse, I as ErrorType, D as AsError, c as OrganisationPostBodyBody, C as OrganisationPostResponse } from '../custom-instance-cc5da68e';
|
|
4
4
|
import 'axios';
|
|
5
5
|
|
|
6
6
|
declare type SecondParameter<T extends (...args: any) => any> = T extends (config: any, args: infer P) => any ? P : never;
|
|
7
7
|
/**
|
|
8
|
-
* Gets
|
|
8
|
+
* Gets all the Organisations you are a member of. Admin users can see all Organisations
|
|
9
9
|
|
|
10
10
|
* @summary Gets Organisations
|
|
11
11
|
*/
|
|
12
12
|
declare const getOrganisations: (options?: SecondParameter<typeof customInstance>) => Promise<OrganisationsGetResponse>;
|
|
13
13
|
declare const getGetOrganisationsQueryKey: () => string[];
|
|
14
|
-
declare const useGetOrganisations: <TData = OrganisationsGetResponse, TError = void |
|
|
15
|
-
query?: UseQueryOptions<OrganisationsGetResponse, TError, TData,
|
|
14
|
+
declare const useGetOrganisations: <TData = OrganisationsGetResponse, TError = ErrorType<void | AsError>>(options?: {
|
|
15
|
+
query?: UseQueryOptions<OrganisationsGetResponse, TError, TData, QueryKey> | undefined;
|
|
16
16
|
request?: SecondParameter<typeof customInstance>;
|
|
17
|
-
} | undefined) => {
|
|
18
|
-
|
|
19
|
-
error: null;
|
|
20
|
-
isError: false;
|
|
21
|
-
isIdle: true;
|
|
22
|
-
isLoading: false;
|
|
23
|
-
isLoadingError: false;
|
|
24
|
-
isRefetchError: false;
|
|
25
|
-
isSuccess: false;
|
|
26
|
-
status: "idle";
|
|
27
|
-
dataUpdatedAt: number;
|
|
28
|
-
errorUpdatedAt: number;
|
|
29
|
-
failureCount: number;
|
|
30
|
-
isFetched: boolean;
|
|
31
|
-
isFetchedAfterMount: boolean;
|
|
32
|
-
isFetching: boolean;
|
|
33
|
-
isPlaceholderData: boolean;
|
|
34
|
-
isPreviousData: boolean;
|
|
35
|
-
isRefetching: boolean;
|
|
36
|
-
isStale: boolean;
|
|
37
|
-
refetch: <TPageData>(options?: (react_query.RefetchOptions & react_query.RefetchQueryFilters<TPageData>) | undefined) => Promise<react_query.QueryObserverResult<TData, TError>>;
|
|
38
|
-
remove: () => void;
|
|
39
|
-
queryKey: react_query.QueryKey;
|
|
40
|
-
} | {
|
|
41
|
-
data: undefined;
|
|
42
|
-
error: TError;
|
|
43
|
-
isError: true;
|
|
44
|
-
isIdle: false;
|
|
45
|
-
isLoading: false;
|
|
46
|
-
isLoadingError: true;
|
|
47
|
-
isRefetchError: false;
|
|
48
|
-
isSuccess: false;
|
|
49
|
-
status: "error";
|
|
50
|
-
dataUpdatedAt: number;
|
|
51
|
-
errorUpdatedAt: number;
|
|
52
|
-
failureCount: number;
|
|
53
|
-
isFetched: boolean;
|
|
54
|
-
isFetchedAfterMount: boolean;
|
|
55
|
-
isFetching: boolean;
|
|
56
|
-
isPlaceholderData: boolean;
|
|
57
|
-
isPreviousData: boolean;
|
|
58
|
-
isRefetching: boolean;
|
|
59
|
-
isStale: boolean;
|
|
60
|
-
refetch: <TPageData>(options?: (react_query.RefetchOptions & react_query.RefetchQueryFilters<TPageData>) | undefined) => Promise<react_query.QueryObserverResult<TData, TError>>;
|
|
61
|
-
remove: () => void;
|
|
62
|
-
queryKey: react_query.QueryKey;
|
|
63
|
-
} | {
|
|
64
|
-
data: undefined;
|
|
65
|
-
error: null;
|
|
66
|
-
isError: false;
|
|
67
|
-
isIdle: false;
|
|
68
|
-
isLoading: true;
|
|
69
|
-
isLoadingError: false;
|
|
70
|
-
isRefetchError: false;
|
|
71
|
-
isSuccess: false;
|
|
72
|
-
status: "loading";
|
|
73
|
-
dataUpdatedAt: number;
|
|
74
|
-
errorUpdatedAt: number;
|
|
75
|
-
failureCount: number;
|
|
76
|
-
isFetched: boolean;
|
|
77
|
-
isFetchedAfterMount: boolean;
|
|
78
|
-
isFetching: boolean;
|
|
79
|
-
isPlaceholderData: boolean;
|
|
80
|
-
isPreviousData: boolean;
|
|
81
|
-
isRefetching: boolean;
|
|
82
|
-
isStale: boolean;
|
|
83
|
-
refetch: <TPageData>(options?: (react_query.RefetchOptions & react_query.RefetchQueryFilters<TPageData>) | undefined) => Promise<react_query.QueryObserverResult<TData, TError>>;
|
|
84
|
-
remove: () => void;
|
|
85
|
-
queryKey: react_query.QueryKey;
|
|
86
|
-
} | {
|
|
87
|
-
data: TData;
|
|
88
|
-
error: TError;
|
|
89
|
-
isError: true;
|
|
90
|
-
isIdle: false;
|
|
91
|
-
isLoading: false;
|
|
92
|
-
isLoadingError: false;
|
|
93
|
-
isRefetchError: true;
|
|
94
|
-
isSuccess: false;
|
|
95
|
-
status: "error";
|
|
96
|
-
dataUpdatedAt: number;
|
|
97
|
-
errorUpdatedAt: number;
|
|
98
|
-
failureCount: number;
|
|
99
|
-
isFetched: boolean;
|
|
100
|
-
isFetchedAfterMount: boolean;
|
|
101
|
-
isFetching: boolean;
|
|
102
|
-
isPlaceholderData: boolean;
|
|
103
|
-
isPreviousData: boolean;
|
|
104
|
-
isRefetching: boolean;
|
|
105
|
-
isStale: boolean;
|
|
106
|
-
refetch: <TPageData>(options?: (react_query.RefetchOptions & react_query.RefetchQueryFilters<TPageData>) | undefined) => Promise<react_query.QueryObserverResult<TData, TError>>;
|
|
107
|
-
remove: () => void;
|
|
108
|
-
queryKey: react_query.QueryKey;
|
|
109
|
-
} | {
|
|
110
|
-
data: TData;
|
|
111
|
-
error: null;
|
|
112
|
-
isError: false;
|
|
113
|
-
isIdle: false;
|
|
114
|
-
isLoading: false;
|
|
115
|
-
isLoadingError: false;
|
|
116
|
-
isRefetchError: false;
|
|
117
|
-
isSuccess: true;
|
|
118
|
-
status: "success";
|
|
119
|
-
dataUpdatedAt: number;
|
|
120
|
-
errorUpdatedAt: number;
|
|
121
|
-
failureCount: number;
|
|
122
|
-
isFetched: boolean;
|
|
123
|
-
isFetchedAfterMount: boolean;
|
|
124
|
-
isFetching: boolean;
|
|
125
|
-
isPlaceholderData: boolean;
|
|
126
|
-
isPreviousData: boolean;
|
|
127
|
-
isRefetching: boolean;
|
|
128
|
-
isStale: boolean;
|
|
129
|
-
refetch: <TPageData>(options?: (react_query.RefetchOptions & react_query.RefetchQueryFilters<TPageData>) | undefined) => Promise<react_query.QueryObserverResult<TData, TError>>;
|
|
130
|
-
remove: () => void;
|
|
131
|
-
queryKey: react_query.QueryKey;
|
|
17
|
+
} | undefined) => UseQueryResult<TData, TError> & {
|
|
18
|
+
queryKey: QueryKey;
|
|
132
19
|
};
|
|
133
20
|
/**
|
|
134
|
-
* Creates a new
|
|
21
|
+
* Creates a new Organisation
|
|
22
|
+
|
|
23
|
+
You need **admin** rights to use this method
|
|
135
24
|
|
|
136
25
|
* @summary Create a new organisation
|
|
137
26
|
*/
|
|
138
27
|
declare const createOrganisation: (organisationPostBodyBody: OrganisationPostBodyBody, options?: SecondParameter<typeof customInstance>) => Promise<OrganisationPostResponse>;
|
|
139
|
-
declare const useCreateOrganisation: <TError = void |
|
|
28
|
+
declare const useCreateOrganisation: <TError = ErrorType<void | AsError>, TContext = unknown>(options?: {
|
|
140
29
|
mutation?: UseMutationOptions<OrganisationPostResponse, TError, {
|
|
141
30
|
data: OrganisationPostBodyBody;
|
|
142
31
|
}, TContext> | undefined;
|
|
@@ -144,5 +33,21 @@ declare const useCreateOrganisation: <TError = void | Error, TContext = unknown>
|
|
|
144
33
|
} | undefined) => react_query.UseMutationResult<OrganisationPostResponse, TError, {
|
|
145
34
|
data: OrganisationPostBodyBody;
|
|
146
35
|
}, TContext>;
|
|
36
|
+
/**
|
|
37
|
+
* Units must first be deleted before an Organisation can be deleted
|
|
38
|
+
|
|
39
|
+
You need **admin** rights to use this method
|
|
40
|
+
|
|
41
|
+
* @summary Deletes an Organisation
|
|
42
|
+
*/
|
|
43
|
+
declare const deleteOrganisation: (orgid: string, options?: SecondParameter<typeof customInstance>) => Promise<void>;
|
|
44
|
+
declare const useDeleteOrganisation: <TError = ErrorType<AsError>, TContext = unknown>(options?: {
|
|
45
|
+
mutation?: UseMutationOptions<void, TError, {
|
|
46
|
+
orgid: string;
|
|
47
|
+
}, TContext> | undefined;
|
|
48
|
+
request?: SecondParameter<typeof customInstance>;
|
|
49
|
+
} | undefined) => react_query.UseMutationResult<void, TError, {
|
|
50
|
+
orgid: string;
|
|
51
|
+
}, TContext>;
|
|
147
52
|
|
|
148
|
-
export { createOrganisation, getGetOrganisationsQueryKey, getOrganisations, useCreateOrganisation, useGetOrganisations };
|
|
53
|
+
export { createOrganisation, deleteOrganisation, getGetOrganisationsQueryKey, getOrganisations, useCreateOrganisation, useDeleteOrganisation, useGetOrganisations };
|
|
@@ -1,2 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
|
|
21
|
+
// src/organisation/organisation.ts
|
|
22
|
+
import {
|
|
23
|
+
useQuery,
|
|
24
|
+
useMutation
|
|
25
|
+
} from "react-query";
|
|
26
|
+
|
|
27
|
+
// src/custom-instance.ts
|
|
28
|
+
import Axios from "axios";
|
|
29
|
+
var AXIOS_INSTANCE = Axios.create({ baseURL: "" });
|
|
30
|
+
var customInstance = (config, options) => {
|
|
31
|
+
const source = Axios.CancelToken.source();
|
|
32
|
+
const promise = AXIOS_INSTANCE(__spreadProps(__spreadValues(__spreadValues({}, config), options), { cancelToken: source.token })).then(({ data }) => data);
|
|
33
|
+
promise.cancel = () => {
|
|
34
|
+
source.cancel("Query was cancelled by React Query");
|
|
35
|
+
};
|
|
36
|
+
return promise;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/organisation/organisation.ts
|
|
40
|
+
var getOrganisations = (options) => {
|
|
41
|
+
return customInstance({ url: `/organisation`, method: "get" }, options);
|
|
42
|
+
};
|
|
43
|
+
var getGetOrganisationsQueryKey = () => [`/organisation`];
|
|
44
|
+
var useGetOrganisations = (options) => {
|
|
45
|
+
const { query: queryOptions, request: requestOptions } = options || {};
|
|
46
|
+
const queryKey = (queryOptions == null ? void 0 : queryOptions.queryKey) ?? getGetOrganisationsQueryKey();
|
|
47
|
+
const queryFn = () => getOrganisations(requestOptions);
|
|
48
|
+
const query = useQuery(queryKey, queryFn, queryOptions);
|
|
49
|
+
return __spreadValues({
|
|
50
|
+
queryKey
|
|
51
|
+
}, query);
|
|
52
|
+
};
|
|
53
|
+
var createOrganisation = (organisationPostBodyBody, options) => {
|
|
54
|
+
return customInstance({ url: `/organisation`, method: "post", data: organisationPostBodyBody }, options);
|
|
55
|
+
};
|
|
56
|
+
var useCreateOrganisation = (options) => {
|
|
57
|
+
const { mutation: mutationOptions, request: requestOptions } = options || {};
|
|
58
|
+
const mutationFn = (props) => {
|
|
59
|
+
const { data } = props || {};
|
|
60
|
+
return createOrganisation(data, requestOptions);
|
|
61
|
+
};
|
|
62
|
+
return useMutation(mutationFn, mutationOptions);
|
|
63
|
+
};
|
|
64
|
+
var deleteOrganisation = (orgid, options) => {
|
|
65
|
+
return customInstance({ url: `/organisation/${orgid}`, method: "delete", data: void 0 }, options);
|
|
66
|
+
};
|
|
67
|
+
var useDeleteOrganisation = (options) => {
|
|
68
|
+
const { mutation: mutationOptions, request: requestOptions } = options || {};
|
|
69
|
+
const mutationFn = (props) => {
|
|
70
|
+
const { orgid } = props || {};
|
|
71
|
+
return deleteOrganisation(orgid, requestOptions);
|
|
72
|
+
};
|
|
73
|
+
return useMutation(mutationFn, mutationOptions);
|
|
74
|
+
};
|
|
75
|
+
export {
|
|
76
|
+
createOrganisation,
|
|
77
|
+
deleteOrganisation,
|
|
78
|
+
getGetOrganisationsQueryKey,
|
|
79
|
+
getOrganisations,
|
|
80
|
+
useCreateOrganisation,
|
|
81
|
+
useDeleteOrganisation,
|
|
82
|
+
useGetOrganisations
|
|
83
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/organisation/organisation.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Generated by orval v6.
|
|
5
|
-
"mappings": "
|
|
3
|
+
"sources": ["../../src/organisation/organisation.ts", "../../src/custom-instance.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Generated by orval v6.4.2 \uD83C\uDF7A\n * Do not edit manually.\n * Account Server API\n * The Informatics Matters Account Server API.\n\nA service that provides access to the Account Server, which gives *registered* users access to and management of **Products**, **Organisations**, **Units** and **Users**.\n\n * OpenAPI spec version: 0.1\n */\nimport {\n useQuery,\n useMutation,\n UseQueryOptions,\n UseMutationOptions,\n QueryFunction,\n MutationFunction,\n UseQueryResult,\n QueryKey,\n} from \"react-query\";\nimport type {\n OrganisationsGetResponse,\n AsError,\n OrganisationPostResponse,\n OrganisationPostBodyBody,\n} from \"../account-server-api.schemas\";\nimport { customInstance, ErrorType } from \".././custom-instance\";\n\ntype AsyncReturnType<T extends (...args: any) => Promise<any>> = T extends (\n ...args: any\n) => Promise<infer R>\n ? R\n : any;\n\ntype SecondParameter<T extends (...args: any) => any> = T extends (\n config: any,\n args: infer P\n) => any\n ? P\n : never;\n\n/**\n * Gets all the Organisations you are a member of. Admin users can see all Organisations\n\n * @summary Gets Organisations\n */\nexport const getOrganisations = (\n options?: SecondParameter<typeof customInstance>\n) => {\n return customInstance<OrganisationsGetResponse>(\n { url: `/organisation`, method: \"get\" },\n options\n );\n};\n\nexport const getGetOrganisationsQueryKey = () => [`/organisation`];\n\nexport const useGetOrganisations = <\n TData = AsyncReturnType<typeof getOrganisations>,\n TError = ErrorType<void | AsError>\n>(options?: {\n query?: UseQueryOptions<\n AsyncReturnType<typeof getOrganisations>,\n TError,\n TData\n >;\n request?: SecondParameter<typeof customInstance>;\n}): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {\n const { query: queryOptions, request: requestOptions } = options || {};\n\n const queryKey = queryOptions?.queryKey ?? getGetOrganisationsQueryKey();\n\n const queryFn: QueryFunction<AsyncReturnType<typeof getOrganisations>> = () =>\n getOrganisations(requestOptions);\n\n const query = useQuery<\n AsyncReturnType<typeof getOrganisations>,\n TError,\n TData\n >(queryKey, queryFn, queryOptions);\n\n return {\n queryKey,\n ...query,\n };\n};\n\n/**\n * Creates a new Organisation\n\nYou need **admin** rights to use this method\n\n * @summary Create a new organisation\n */\nexport const createOrganisation = (\n organisationPostBodyBody: OrganisationPostBodyBody,\n options?: SecondParameter<typeof customInstance>\n) => {\n return customInstance<OrganisationPostResponse>(\n { url: `/organisation`, method: \"post\", data: organisationPostBodyBody },\n options\n );\n};\n\nexport const useCreateOrganisation = <\n TError = ErrorType<AsError | void>,\n TContext = unknown\n>(options?: {\n mutation?: UseMutationOptions<\n AsyncReturnType<typeof createOrganisation>,\n TError,\n { data: OrganisationPostBodyBody },\n TContext\n >;\n request?: SecondParameter<typeof customInstance>;\n}) => {\n const { mutation: mutationOptions, request: requestOptions } = options || {};\n\n const mutationFn: MutationFunction<\n AsyncReturnType<typeof createOrganisation>,\n { data: OrganisationPostBodyBody }\n > = (props) => {\n const { data } = props || {};\n\n return createOrganisation(data, requestOptions);\n };\n\n return useMutation<\n AsyncReturnType<typeof createOrganisation>,\n TError,\n { data: OrganisationPostBodyBody },\n TContext\n >(mutationFn, mutationOptions);\n};\n/**\n * Units must first be deleted before an Organisation can be deleted\n\nYou need **admin** rights to use this method\n\n * @summary Deletes an Organisation\n */\nexport const deleteOrganisation = (\n orgid: string,\n options?: SecondParameter<typeof customInstance>\n) => {\n return customInstance<void>(\n { url: `/organisation/${orgid}`, method: \"delete\", data: undefined },\n options\n );\n};\n\nexport const useDeleteOrganisation = <\n TError = ErrorType<AsError>,\n TContext = unknown\n>(options?: {\n mutation?: UseMutationOptions<\n AsyncReturnType<typeof deleteOrganisation>,\n TError,\n { orgid: string },\n TContext\n >;\n request?: SecondParameter<typeof customInstance>;\n}) => {\n const { mutation: mutationOptions, request: requestOptions } = options || {};\n\n const mutationFn: MutationFunction<\n AsyncReturnType<typeof deleteOrganisation>,\n { orgid: string }\n > = (props) => {\n const { orgid } = props || {};\n\n return deleteOrganisation(orgid, requestOptions);\n };\n\n return useMutation<\n AsyncReturnType<typeof deleteOrganisation>,\n TError,\n { orgid: string },\n TContext\n >(mutationFn, mutationOptions);\n};\n", "/** Based off the example custom-instance from Orval docs\n * https://github.com/anymaniax/orval/blob/master/samples/react-app-with-react-query/src/api/mutator/custom-instance.ts\n *\n * See https://react-query.tanstack.com/guides/query-cancellation\n *\n * TODO: Considering using Fetch-API instead of axios. This instance will have to change. Could be\n * achieved without changing much using `redaxios`\n * Or use 'ky'\n */\n\nimport Axios, { AxiosError, AxiosRequestConfig } from 'axios';\n\n// ? Need the baseUrl or does it default to ''?\nexport const AXIOS_INSTANCE = Axios.create({ baseURL: '' });\n\n/**\n * Set the access token to be added as the `Authorization: Bearer 'token'` header\n * Useful for client only apps where a proxy API route isn't involved to securely add the access token\n * @param token access token\n */\nexport const setAuthToken = (token: string) => {\n AXIOS_INSTANCE.defaults.headers.common['Authorization'] = `Bearer ${token}`;\n};\n\n/**\n * Set the url to which request paths are added to.\n * @param baseUrl origin + subpath e.g. 'https://example.com/subpath' or '/subpath'\n */\nexport const setBaseUrl = (baseUrl: string) => {\n AXIOS_INSTANCE.defaults.baseURL = baseUrl;\n};\n\nexport const customInstance = <TReturn>(\n config: AxiosRequestConfig,\n options?: AxiosRequestConfig,\n): Promise<TReturn> => {\n const source = Axios.CancelToken.source();\n\n const promise = AXIOS_INSTANCE({ ...config, ...options, cancelToken: source.token }).then(\n ({ data }) => data,\n );\n\n // Promise doesn't have a cancel method but react-query requires this method to make cancellations general.\n // This can either be a any assertion or a @ts-ignore comment.\n (promise as any).cancel = () => {\n source.cancel('Query was cancelled by React Query');\n };\n\n return promise;\n};\n\nexport type ErrorType<TError> = AxiosError<TError>;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAUA;AAAA;AAAA;AAAA;;;ACAA;AAGO,IAAM,iBAAiB,MAAM,OAAO,EAAE,SAAS;AAmB/C,IAAM,iBAAiB,CAC5B,QACA,YACqB;AACrB,QAAM,SAAS,MAAM,YAAY;AAEjC,QAAM,UAAU,eAAe,gDAAK,SAAW,UAAhB,EAAyB,aAAa,OAAO,UAAS,KACnF,CAAC,EAAE,WAAW;AAKhB,EAAC,QAAgB,SAAS,MAAM;AAC9B,WAAO,OAAO;AAAA;AAGhB,SAAO;AAAA;;;ADFF,IAAM,mBAAmB,CAC9B,YACG;AACH,SAAO,eACL,EAAE,KAAK,iBAAiB,QAAQ,SAChC;AAAA;AAIG,IAAM,8BAA8B,MAAM,CAAC;AAE3C,IAAM,sBAAsB,CAGjC,YAO4D;AAC5D,QAAM,EAAE,OAAO,cAAc,SAAS,mBAAmB,WAAW;AAEpE,QAAM,WAAW,8CAAc,aAAY;AAE3C,QAAM,UAAmE,MACvE,iBAAiB;AAEnB,QAAM,QAAQ,SAIZ,UAAU,SAAS;AAErB,SAAO;AAAA,IACL;AAAA,KACG;AAAA;AAWA,IAAM,qBAAqB,CAChC,0BACA,YACG;AACH,SAAO,eACL,EAAE,KAAK,iBAAiB,QAAQ,QAAQ,MAAM,4BAC9C;AAAA;AAIG,IAAM,wBAAwB,CAGnC,YAQI;AACJ,QAAM,EAAE,UAAU,iBAAiB,SAAS,mBAAmB,WAAW;AAE1E,QAAM,aAGF,CAAC,UAAU;AACb,UAAM,EAAE,SAAS,SAAS;AAE1B,WAAO,mBAAmB,MAAM;AAAA;AAGlC,SAAO,YAKL,YAAY;AAAA;AAST,IAAM,qBAAqB,CAChC,OACA,YACG;AACH,SAAO,eACL,EAAE,KAAK,iBAAiB,SAAS,QAAQ,UAAU,MAAM,UACzD;AAAA;AAIG,IAAM,wBAAwB,CAGnC,YAQI;AACJ,QAAM,EAAE,UAAU,iBAAiB,SAAS,mBAAmB,WAAW;AAE1E,QAAM,aAGF,CAAC,UAAU;AACb,UAAM,EAAE,UAAU,SAAS;AAE3B,WAAO,mBAAmB,OAAO;AAAA;AAGnC,SAAO,YAKL,YAAY;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.1.
|
|
2
|
+
"version": "0.1.8-rc.1",
|
|
3
3
|
"author": "Oliver Dudgeon",
|
|
4
4
|
"name": "@squonk/account-server-client",
|
|
5
5
|
"private": false,
|
|
@@ -15,17 +15,17 @@
|
|
|
15
15
|
"orval": "orval --config ./orval.config.cjs"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
18
|
+
"@typescript-eslint/eslint-plugin": "^5.6.0",
|
|
19
19
|
"axios": "^0.24.0",
|
|
20
|
-
"eslint": "^8.
|
|
20
|
+
"eslint": "^8.4.1",
|
|
21
21
|
"eslint-plugin-prettier": "^4.0.0",
|
|
22
22
|
"js-yaml": "^4.1.0",
|
|
23
|
-
"orval": "^6.
|
|
24
|
-
"prettier": "^2.
|
|
25
|
-
"react-query": "^3.
|
|
23
|
+
"orval": "^6.4.2",
|
|
24
|
+
"prettier": "^2.5.1",
|
|
25
|
+
"react-query": "^3.34.0",
|
|
26
26
|
"tslib": "^2.3.1",
|
|
27
|
-
"tsup": "^5.
|
|
28
|
-
"typescript": "^4.
|
|
27
|
+
"tsup": "^5.10.3",
|
|
28
|
+
"typescript": "^4.5.2"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"axios": ">=0.23",
|