@newfold/huapi-js 1.0.0

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/openapi.json ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "openapi": "3.0.0",
3
+ "info": { "title": "Hosting UAPI", "version": "0.1.0" },
4
+ "components": {
5
+ "securitySchemes": {
6
+ "bearerAuth": {
7
+ "type": "http",
8
+ "scheme": "bearer",
9
+ "bearerFormat": "JWT"
10
+ }
11
+ }
12
+ },
13
+ "paths": {
14
+ "/sites/{site_id}/sso": {
15
+ "post": {
16
+ "security": [{ "bearerAuth": [] }],
17
+ "summary": "site_sso",
18
+ "description": "Return an SSO token or login URL for this site (if supported).",
19
+ "parameters": [
20
+ {
21
+ "name": "site_id",
22
+ "in": "path",
23
+ "required": true,
24
+ "schema": { "type": "integer" }
25
+ }
26
+ ],
27
+ "responses": {
28
+ "200": {
29
+ "description": "OK",
30
+ "content": {
31
+ "application/json": {
32
+ "schema": {
33
+ "type": "object",
34
+ "properties": {
35
+ "sso": { "type": "string", "example": "$randomUrl" }
36
+ },
37
+ "required": ["sso"]
38
+ }
39
+ }
40
+ }
41
+ }
42
+ }
43
+ }
44
+ },
45
+ "/hosting/{hosting_id}/sites": {
46
+ "get": {
47
+ "security": [{ "bearerAuth": [] }],
48
+ "summary": "site_list",
49
+ "description": "Obtain a list of sites.",
50
+ "parameters": [
51
+ {
52
+ "name": "hosting_id",
53
+ "in": "path",
54
+ "required": true,
55
+ "schema": { "type": "integer" }
56
+ }
57
+ ],
58
+ "responses": {
59
+ "200": {
60
+ "description": "OK",
61
+ "content": {
62
+ "application/json": {
63
+ "schema": {
64
+ "type": "object",
65
+ "properties": {
66
+ "limit": { "type": "string" },
67
+ "n_pages": { "type": "string" },
68
+ "n_rows": { "type": "string" },
69
+ "page": { "type": "string" },
70
+ "rows": {
71
+ "type": "array",
72
+ "items": {
73
+ "type": "object",
74
+ "properties": {
75
+ "id": { "type": "string" },
76
+ "name": { "type": "string" },
77
+ "url": { "type": "string" }
78
+ },
79
+ "required": ["id", "name", "url"]
80
+ }
81
+ }
82
+ },
83
+ "required": ["limit", "n_pages", "n_rows", "page", "rows"]
84
+ }
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+ }
91
+ }
92
+ }
@@ -0,0 +1,14 @@
1
+ module.exports = {
2
+ huapi: {
3
+ input: {
4
+ target: "./openapi.json",
5
+ validation: true,
6
+ },
7
+ output: {
8
+ // mode: "tags-split",
9
+ target: "./src/huapi.ts",
10
+ // schemas: "src/model",
11
+ client: "react-query",
12
+ },
13
+ },
14
+ };
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@newfold/huapi-js",
3
+ "version": "1.0.0",
4
+ "main": "src/huapi.ts",
5
+ "license": "MIT",
6
+ "dependencies": {
7
+ "axios": "^0.26.1",
8
+ "react-query": "^3.34.19"
9
+ },
10
+ "peerDependencies": {
11
+ "react-query": "^3.0.0"
12
+ }
13
+ }
package/src/huapi.ts ADDED
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Generated by orval v6.7.1 🍺
3
+ * Do not edit manually.
4
+ * Hosting UAPI
5
+ * OpenAPI spec version: 0.1.0
6
+ */
7
+ import axios,{
8
+ AxiosRequestConfig,
9
+ AxiosResponse,
10
+ AxiosError
11
+ } from 'axios'
12
+ import {
13
+ useQuery,
14
+ useMutation,
15
+ UseQueryOptions,
16
+ UseMutationOptions,
17
+ QueryFunction,
18
+ MutationFunction,
19
+ UseQueryResult,
20
+ QueryKey
21
+ } from 'react-query'
22
+ export type GetHostingHostingIdSites200RowsItem = {
23
+ id: string;
24
+ name: string;
25
+ url: string;
26
+ };
27
+
28
+ export type GetHostingHostingIdSites200 = {
29
+ limit: string;
30
+ n_pages: string;
31
+ n_rows: string;
32
+ page: string;
33
+ rows: GetHostingHostingIdSites200RowsItem[];
34
+ };
35
+
36
+ export type PostSitesSiteIdSso200 = {
37
+ sso: string;
38
+ };
39
+
40
+
41
+
42
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
+ type AsyncReturnType<
44
+ T extends (...args: any) => Promise<any>
45
+ > = T extends (...args: any) => Promise<infer R> ? R : any;
46
+
47
+
48
+ /**
49
+ * Return an SSO token or login URL for this site (if supported).
50
+ * @summary site_sso
51
+ */
52
+ export const postSitesSiteIdSso = (
53
+ siteId: number, options?: AxiosRequestConfig
54
+ ): Promise<AxiosResponse<PostSitesSiteIdSso200>> => {
55
+ return axios.post(
56
+ `/sites/${siteId}/sso`,undefined,options
57
+ );
58
+ }
59
+
60
+
61
+
62
+ export type PostSitesSiteIdSsoMutationResult = NonNullable<AsyncReturnType<typeof postSitesSiteIdSso>>
63
+
64
+ export type PostSitesSiteIdSsoMutationError = AxiosError<unknown>
65
+
66
+ export const usePostSitesSiteIdSso = <TError = AxiosError<unknown>,
67
+
68
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<AsyncReturnType<typeof postSitesSiteIdSso>, TError,{siteId: number}, TContext>, axios?: AxiosRequestConfig}
69
+ ) => {
70
+ const {mutation: mutationOptions, axios: axiosOptions} = options || {}
71
+
72
+
73
+
74
+
75
+ const mutationFn: MutationFunction<AsyncReturnType<typeof postSitesSiteIdSso>, {siteId: number}> = (props) => {
76
+ const {siteId} = props || {};
77
+
78
+ return postSitesSiteIdSso(siteId,axiosOptions)
79
+ }
80
+
81
+ return useMutation<AsyncReturnType<typeof postSitesSiteIdSso>, TError, {siteId: number}, TContext>(mutationFn, mutationOptions)
82
+ }
83
+
84
+ /**
85
+ * Obtain a list of sites.
86
+ * @summary site_list
87
+ */
88
+ export const getHostingHostingIdSites = (
89
+ hostingId: number, options?: AxiosRequestConfig
90
+ ): Promise<AxiosResponse<GetHostingHostingIdSites200>> => {
91
+ return axios.get(
92
+ `/hosting/${hostingId}/sites`,options
93
+ );
94
+ }
95
+
96
+
97
+ export const getGetHostingHostingIdSitesQueryKey = (hostingId: number,) => [`/hosting/${hostingId}/sites`];
98
+
99
+
100
+ export type GetHostingHostingIdSitesQueryResult = NonNullable<AsyncReturnType<typeof getHostingHostingIdSites>>
101
+ export type GetHostingHostingIdSitesQueryError = AxiosError<unknown>
102
+
103
+ export const useGetHostingHostingIdSites = <TData = AsyncReturnType<typeof getHostingHostingIdSites>, TError = AxiosError<unknown>>(
104
+ hostingId: number, options?: { query?:UseQueryOptions<AsyncReturnType<typeof getHostingHostingIdSites>, TError, TData>, axios?: AxiosRequestConfig}
105
+
106
+ ): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
107
+
108
+ const {query: queryOptions, axios: axiosOptions} = options || {}
109
+
110
+ const queryKey = queryOptions?.queryKey ?? getGetHostingHostingIdSitesQueryKey(hostingId);
111
+
112
+
113
+
114
+ const queryFn: QueryFunction<AsyncReturnType<typeof getHostingHostingIdSites>> = () => getHostingHostingIdSites(hostingId, axiosOptions);
115
+
116
+ const query = useQuery<AsyncReturnType<typeof getHostingHostingIdSites>, TError, TData>(queryKey, queryFn, {enabled: !!(hostingId), ...queryOptions})
117
+
118
+ return {
119
+ queryKey,
120
+ ...query
121
+ }
122
+ }
123
+
124
+