@newfold/huapi-js 1.0.1 → 1.1.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/openapi.json +91 -31
- package/orval.config.js +2 -0
- package/package.json +10 -4
- package/src/huapi.js +41 -17
- package/src/huapi.ts +0 -124
package/openapi.json
CHANGED
|
@@ -1,7 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"openapi": "3.0.0",
|
|
3
|
-
"info": {
|
|
3
|
+
"info": {
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"title": "Hosting UAPI",
|
|
6
|
+
"description": "Hosting UAPI"
|
|
7
|
+
},
|
|
4
8
|
"components": {
|
|
9
|
+
"schemas": {
|
|
10
|
+
"Site": {
|
|
11
|
+
"type": "object",
|
|
12
|
+
"description": "A site",
|
|
13
|
+
"properties": {
|
|
14
|
+
"id": { "type": "string", "description": "TODO" },
|
|
15
|
+
"name": { "type": "string", "description": "TODO" },
|
|
16
|
+
"url": { "type": "string", "description": "TODO" }
|
|
17
|
+
},
|
|
18
|
+
"required": ["id", "name", "url"]
|
|
19
|
+
},
|
|
20
|
+
"SiteList": {
|
|
21
|
+
"description": "List of sites",
|
|
22
|
+
"type": "object",
|
|
23
|
+
"properties": {
|
|
24
|
+
"limit": { "type": "string", "description": "TODO" },
|
|
25
|
+
"n_pages": { "type": "string", "description": "TODO" },
|
|
26
|
+
"n_rows": { "type": "string", "description": "TODO" },
|
|
27
|
+
"page": { "type": "string", "description": "TODO" },
|
|
28
|
+
"rows": {
|
|
29
|
+
"type": "array",
|
|
30
|
+
"description": "TODO",
|
|
31
|
+
"items": {
|
|
32
|
+
"type": "array",
|
|
33
|
+
"$ref": "#/components/schemas/Site"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"SiteSso": {
|
|
39
|
+
"description": "SSO token or login URL",
|
|
40
|
+
"type": "object",
|
|
41
|
+
"properties": {
|
|
42
|
+
"sso": {
|
|
43
|
+
"type": "string",
|
|
44
|
+
"example": "$randomUrl",
|
|
45
|
+
"description": "TODO"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"required": ["sso"]
|
|
49
|
+
}
|
|
50
|
+
},
|
|
5
51
|
"securitySchemes": {
|
|
6
52
|
"bearerAuth": {
|
|
7
53
|
"type": "http",
|
|
@@ -13,15 +59,21 @@
|
|
|
13
59
|
"paths": {
|
|
14
60
|
"/sites/{site_id}/sso": {
|
|
15
61
|
"post": {
|
|
62
|
+
"summary": "Get SSO token",
|
|
63
|
+
"operationId": "site_sso",
|
|
64
|
+
"description": "TODO",
|
|
65
|
+
"tags": ["sites"],
|
|
16
66
|
"security": [{ "bearerAuth": [] }],
|
|
17
|
-
"summary": "site_sso",
|
|
18
|
-
"description": "Return an SSO token or login URL for this site (if supported).",
|
|
19
67
|
"parameters": [
|
|
20
68
|
{
|
|
21
69
|
"name": "site_id",
|
|
70
|
+
"description": "Specify the site id to get the SSO token for.",
|
|
22
71
|
"in": "path",
|
|
23
72
|
"required": true,
|
|
24
|
-
"schema": {
|
|
73
|
+
"schema": {
|
|
74
|
+
"type": "integer",
|
|
75
|
+
"description": "Specify the site id to get the SSO token for."
|
|
76
|
+
}
|
|
25
77
|
}
|
|
26
78
|
],
|
|
27
79
|
"responses": {
|
|
@@ -30,11 +82,10 @@
|
|
|
30
82
|
"content": {
|
|
31
83
|
"application/json": {
|
|
32
84
|
"schema": {
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"required": ["sso"]
|
|
85
|
+
"$ref": "#/components/schemas/SiteSso"
|
|
86
|
+
},
|
|
87
|
+
"example": {
|
|
88
|
+
"sso": "$randomUrl"
|
|
38
89
|
}
|
|
39
90
|
}
|
|
40
91
|
}
|
|
@@ -44,15 +95,20 @@
|
|
|
44
95
|
},
|
|
45
96
|
"/hosting/{hosting_id}/sites": {
|
|
46
97
|
"get": {
|
|
98
|
+
"operationId": "get_hosting_sites",
|
|
99
|
+
"tags": ["sites"],
|
|
47
100
|
"security": [{ "bearerAuth": [] }],
|
|
48
|
-
"summary": "
|
|
101
|
+
"summary": "Get sites for a hosting id",
|
|
49
102
|
"description": "Obtain a list of sites.",
|
|
50
103
|
"parameters": [
|
|
51
104
|
{
|
|
52
105
|
"name": "hosting_id",
|
|
53
106
|
"in": "path",
|
|
54
107
|
"required": true,
|
|
55
|
-
"schema": {
|
|
108
|
+
"schema": {
|
|
109
|
+
"type": "integer",
|
|
110
|
+
"description": "Specify the hosting id to get sites for."
|
|
111
|
+
}
|
|
56
112
|
}
|
|
57
113
|
],
|
|
58
114
|
"responses": {
|
|
@@ -61,26 +117,20 @@
|
|
|
61
117
|
"content": {
|
|
62
118
|
"application/json": {
|
|
63
119
|
"schema": {
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"name": { "type": "string" },
|
|
77
|
-
"url": { "type": "string" }
|
|
78
|
-
},
|
|
79
|
-
"required": ["id", "name", "url"]
|
|
80
|
-
}
|
|
120
|
+
"$ref": "#/components/schemas/SiteList"
|
|
121
|
+
},
|
|
122
|
+
"example": {
|
|
123
|
+
"limit": "10",
|
|
124
|
+
"n_pages": "1",
|
|
125
|
+
"n_rows": "1",
|
|
126
|
+
"page": "1",
|
|
127
|
+
"rows": [
|
|
128
|
+
{
|
|
129
|
+
"id": "1",
|
|
130
|
+
"name": "Example Site",
|
|
131
|
+
"url": "https://example.com"
|
|
81
132
|
}
|
|
82
|
-
|
|
83
|
-
"required": ["limit", "n_pages", "n_rows", "page", "rows"]
|
|
133
|
+
]
|
|
84
134
|
}
|
|
85
135
|
}
|
|
86
136
|
}
|
|
@@ -88,5 +138,15 @@
|
|
|
88
138
|
}
|
|
89
139
|
}
|
|
90
140
|
}
|
|
91
|
-
}
|
|
141
|
+
},
|
|
142
|
+
"servers": [
|
|
143
|
+
{
|
|
144
|
+
"url": "https://api.example.com/v1",
|
|
145
|
+
"description": "Production server (uses live data)"
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"url": "https://sandbox-api.example.com:8443/v1",
|
|
149
|
+
"description": "Sandbox server (uses test data)"
|
|
150
|
+
}
|
|
151
|
+
]
|
|
92
152
|
}
|
package/orval.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newfold/huapi-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"main": "src/huapi.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"devDependencies": {
|
|
7
|
+
"@faker-js/faker": "^6.1.2",
|
|
7
8
|
"axios": "^0.26.1",
|
|
9
|
+
"msw": "^0.39.2",
|
|
8
10
|
"orval": "^6.7.1",
|
|
9
11
|
"react": "^18.0.0",
|
|
10
12
|
"react-query": "^3.34.19",
|
|
11
13
|
"typescript": "^4.6.3"
|
|
12
14
|
},
|
|
13
15
|
"peerDependencies": {
|
|
14
|
-
"
|
|
16
|
+
"@faker-js/faker": "^6.1.2",
|
|
17
|
+
"axios": "^0.26.1",
|
|
18
|
+
"msw": "^0.39.2",
|
|
19
|
+
"orval": "^6.7.1",
|
|
20
|
+
"react": "^18.0.0",
|
|
21
|
+
"react-query": "^3.34.19"
|
|
15
22
|
},
|
|
16
23
|
"scripts": {
|
|
17
|
-
"clean": "rm -rf ./src",
|
|
18
24
|
"orval": "orval",
|
|
19
25
|
"tsToJs": "npx tsc ./src/*",
|
|
20
|
-
"build": "yarn
|
|
26
|
+
"build": "yarn orval && yarn tsToJs"
|
|
21
27
|
}
|
|
22
28
|
}
|
package/src/huapi.js
CHANGED
|
@@ -10,49 +10,73 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
+
if (ar || !(i in from)) {
|
|
16
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
+
ar[i] = from[i];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
+
};
|
|
13
22
|
exports.__esModule = true;
|
|
14
|
-
exports.
|
|
23
|
+
exports.getHostingUAPIMSW = exports.getGetHostingSitesMock = exports.getSiteSsoMock = exports.useGetHostingSites = exports.getGetHostingSitesQueryKey = exports.getHostingSites = exports.useSiteSso = exports.siteSso = void 0;
|
|
15
24
|
/**
|
|
16
25
|
* Generated by orval v6.7.1 🍺
|
|
17
26
|
* Do not edit manually.
|
|
18
27
|
* Hosting UAPI
|
|
28
|
+
* Hosting UAPI
|
|
19
29
|
* OpenAPI spec version: 0.1.0
|
|
20
30
|
*/
|
|
21
31
|
var axios_1 = require("axios");
|
|
22
32
|
var react_query_1 = require("react-query");
|
|
33
|
+
var msw_1 = require("msw");
|
|
34
|
+
var faker_1 = require("@faker-js/faker");
|
|
23
35
|
/**
|
|
24
|
-
*
|
|
25
|
-
* @summary
|
|
36
|
+
* TODO
|
|
37
|
+
* @summary Get SSO token
|
|
26
38
|
*/
|
|
27
|
-
var
|
|
39
|
+
var siteSso = function (siteId, options) {
|
|
28
40
|
return axios_1["default"].post("/sites/".concat(siteId, "/sso"), undefined, options);
|
|
29
41
|
};
|
|
30
|
-
exports.
|
|
31
|
-
var
|
|
42
|
+
exports.siteSso = siteSso;
|
|
43
|
+
var useSiteSso = function (options) {
|
|
32
44
|
var _a = options || {}, mutationOptions = _a.mutation, axiosOptions = _a.axios;
|
|
33
45
|
var mutationFn = function (props) {
|
|
34
46
|
var siteId = (props || {}).siteId;
|
|
35
|
-
return (0, exports.
|
|
47
|
+
return (0, exports.siteSso)(siteId, axiosOptions);
|
|
36
48
|
};
|
|
37
49
|
return (0, react_query_1.useMutation)(mutationFn, mutationOptions);
|
|
38
50
|
};
|
|
39
|
-
exports.
|
|
51
|
+
exports.useSiteSso = useSiteSso;
|
|
40
52
|
/**
|
|
41
53
|
* Obtain a list of sites.
|
|
42
|
-
* @summary
|
|
54
|
+
* @summary Get sites for a hosting id
|
|
43
55
|
*/
|
|
44
|
-
var
|
|
56
|
+
var getHostingSites = function (hostingId, options) {
|
|
45
57
|
return axios_1["default"].get("/hosting/".concat(hostingId, "/sites"), options);
|
|
46
58
|
};
|
|
47
|
-
exports.
|
|
48
|
-
var
|
|
49
|
-
exports.
|
|
50
|
-
var
|
|
59
|
+
exports.getHostingSites = getHostingSites;
|
|
60
|
+
var getGetHostingSitesQueryKey = function (hostingId) { return ["/hosting/".concat(hostingId, "/sites")]; };
|
|
61
|
+
exports.getGetHostingSitesQueryKey = getGetHostingSitesQueryKey;
|
|
62
|
+
var useGetHostingSites = function (hostingId, options) {
|
|
51
63
|
var _a;
|
|
52
64
|
var _b = options || {}, queryOptions = _b.query, axiosOptions = _b.axios;
|
|
53
|
-
var queryKey = (_a = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.queryKey) !== null && _a !== void 0 ? _a : (0, exports.
|
|
54
|
-
var queryFn = function () { return (0, exports.
|
|
65
|
+
var queryKey = (_a = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.queryKey) !== null && _a !== void 0 ? _a : (0, exports.getGetHostingSitesQueryKey)(hostingId);
|
|
66
|
+
var queryFn = function () { return (0, exports.getHostingSites)(hostingId, axiosOptions); };
|
|
55
67
|
var query = (0, react_query_1.useQuery)(queryKey, queryFn, __assign({ enabled: !!(hostingId) }, queryOptions));
|
|
56
68
|
return __assign({ queryKey: queryKey }, query);
|
|
57
69
|
};
|
|
58
|
-
exports.
|
|
70
|
+
exports.useGetHostingSites = useGetHostingSites;
|
|
71
|
+
var getSiteSsoMock = function () { return ({ sso: faker_1.faker.random.word() }); };
|
|
72
|
+
exports.getSiteSsoMock = getSiteSsoMock;
|
|
73
|
+
var getGetHostingSitesMock = function () { return ({ limit: faker_1.faker.helpers.randomize([faker_1.faker.random.word(), undefined]), n_pages: faker_1.faker.helpers.randomize([faker_1.faker.random.word(), undefined]), n_rows: faker_1.faker.helpers.randomize([faker_1.faker.random.word(), undefined]), page: faker_1.faker.helpers.randomize([faker_1.faker.random.word(), undefined]), rows: faker_1.faker.helpers.randomize([__spreadArray([], Array(faker_1.faker.datatype.number({ min: 1, max: 10 })), true).map(function () { return ({ id: faker_1.faker.random.word(), name: faker_1.faker.random.word(), url: faker_1.faker.random.word() }); }), undefined]) }); };
|
|
74
|
+
exports.getGetHostingSitesMock = getGetHostingSitesMock;
|
|
75
|
+
var getHostingUAPIMSW = function () { return [
|
|
76
|
+
msw_1.rest.post('*/sites/:siteid/sso', function (_req, res, ctx) {
|
|
77
|
+
return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getSiteSsoMock)()));
|
|
78
|
+
}), msw_1.rest.get('*/hosting/:hostingid/sites', function (_req, res, ctx) {
|
|
79
|
+
return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getGetHostingSitesMock)()));
|
|
80
|
+
}),
|
|
81
|
+
]; };
|
|
82
|
+
exports.getHostingUAPIMSW = getHostingUAPIMSW;
|
package/src/huapi.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
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
|
-
|