@newfold/huapi-js 1.2.0 → 1.2.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 +2 -2
- package/orval.config.js +52 -11
- package/package.json +1 -1
- package/src/huapi.js +24 -34
- package/src/huapi.ts +23 -26
package/openapi.json
CHANGED
|
@@ -165,7 +165,7 @@
|
|
|
165
165
|
},
|
|
166
166
|
"/hosting/{hosting_id}/sites": {
|
|
167
167
|
"get": {
|
|
168
|
-
"operationId": "
|
|
168
|
+
"operationId": "hosting_sites",
|
|
169
169
|
"tags": ["sites"],
|
|
170
170
|
"security": [{ "bearerAuth": [] }],
|
|
171
171
|
"summary": "Get sites for a hosting id",
|
|
@@ -197,7 +197,7 @@
|
|
|
197
197
|
},
|
|
198
198
|
"/hosting/{hosting_id}/sites/{site_id}": {
|
|
199
199
|
"get": {
|
|
200
|
-
"operationId": "
|
|
200
|
+
"operationId": "hosting_site_by_id",
|
|
201
201
|
"tags": ["sites"],
|
|
202
202
|
"security": [{ "bearerAuth": [] }],
|
|
203
203
|
"summary": "For a hosting id, get a specific site by site id",
|
package/orval.config.js
CHANGED
|
@@ -1,16 +1,57 @@
|
|
|
1
|
-
|
|
1
|
+
import { faker } from "@faker-js/faker";
|
|
2
|
+
import { defineConfig } from "orval";
|
|
3
|
+
|
|
4
|
+
const input = {
|
|
5
|
+
target: "./openapi.json",
|
|
6
|
+
validation: true,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const output = {
|
|
10
|
+
// mode: "tags-split",
|
|
11
|
+
target: "./src/huapi.ts",
|
|
12
|
+
// schemas: "src/model",
|
|
13
|
+
client: "react-query",
|
|
14
|
+
mock: true,
|
|
15
|
+
clean: true,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const sites = {
|
|
19
|
+
limit: 10,
|
|
20
|
+
n_pages: 1,
|
|
21
|
+
n_rows: 3,
|
|
22
|
+
page: 1,
|
|
23
|
+
rows: [...Array(3)].map((site, idx) => ({
|
|
24
|
+
id: idx,
|
|
25
|
+
name: faker.company.companyName(),
|
|
26
|
+
url: faker.internet.url(),
|
|
27
|
+
})),
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default defineConfig({
|
|
2
31
|
huapi: {
|
|
3
|
-
input
|
|
4
|
-
target: "./openapi.json",
|
|
5
|
-
validation: true,
|
|
6
|
-
},
|
|
32
|
+
input,
|
|
7
33
|
output: {
|
|
8
|
-
|
|
34
|
+
...output,
|
|
9
35
|
target: "./src/huapi.ts",
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
36
|
+
override: {
|
|
37
|
+
operations: {
|
|
38
|
+
site_sso: {
|
|
39
|
+
mock: {
|
|
40
|
+
data: `${sites.rows[0].url}/wp-login.php?ssotoken=1234567890`,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
hosting_sites: {
|
|
44
|
+
mock: {
|
|
45
|
+
data: sites,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
hosting_site_by_id: {
|
|
49
|
+
mock: {
|
|
50
|
+
data: sites.rows[0],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
14
55
|
},
|
|
15
56
|
},
|
|
16
|
-
};
|
|
57
|
+
});
|
package/package.json
CHANGED
package/src/huapi.js
CHANGED
|
@@ -10,17 +10,8 @@ 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
|
-
};
|
|
22
13
|
exports.__esModule = true;
|
|
23
|
-
exports.getHostingUAPIMSW = exports.
|
|
14
|
+
exports.getHostingUAPIMSW = exports.getHostingSiteByIdMock = exports.getHostingSitesMock = exports.getSiteSsoMock = exports.useHostingSiteById = exports.getHostingSiteByIdQueryKey = exports.hostingSiteById = exports.useHostingSites = exports.getHostingSitesQueryKey = exports.hostingSites = exports.useSiteSso = exports.siteSso = void 0;
|
|
24
15
|
/**
|
|
25
16
|
* Generated by orval v6.7.1 🍺
|
|
26
17
|
* Do not edit manually.
|
|
@@ -31,7 +22,6 @@ exports.getHostingUAPIMSW = exports.getGetHostingSiteByIdMock = exports.getGetHo
|
|
|
31
22
|
var axios_1 = require("axios");
|
|
32
23
|
var react_query_1 = require("react-query");
|
|
33
24
|
var msw_1 = require("msw");
|
|
34
|
-
var faker_1 = require("@faker-js/faker");
|
|
35
25
|
/**
|
|
36
26
|
* TODO
|
|
37
27
|
* @summary Get SSO token
|
|
@@ -53,53 +43,53 @@ exports.useSiteSso = useSiteSso;
|
|
|
53
43
|
* Obtain a list of sites.
|
|
54
44
|
* @summary Get sites for a hosting id
|
|
55
45
|
*/
|
|
56
|
-
var
|
|
46
|
+
var hostingSites = function (hostingId, options) {
|
|
57
47
|
return axios_1["default"].get("/hosting/".concat(hostingId, "/sites"), options);
|
|
58
48
|
};
|
|
59
|
-
exports.
|
|
60
|
-
var
|
|
61
|
-
exports.
|
|
62
|
-
var
|
|
49
|
+
exports.hostingSites = hostingSites;
|
|
50
|
+
var getHostingSitesQueryKey = function (hostingId) { return ["/hosting/".concat(hostingId, "/sites")]; };
|
|
51
|
+
exports.getHostingSitesQueryKey = getHostingSitesQueryKey;
|
|
52
|
+
var useHostingSites = function (hostingId, options) {
|
|
63
53
|
var _a;
|
|
64
54
|
var _b = options || {}, queryOptions = _b.query, axiosOptions = _b.axios;
|
|
65
|
-
var queryKey = (_a = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.queryKey) !== null && _a !== void 0 ? _a : (0, exports.
|
|
66
|
-
var queryFn = function () { return (0, exports.
|
|
55
|
+
var queryKey = (_a = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.queryKey) !== null && _a !== void 0 ? _a : (0, exports.getHostingSitesQueryKey)(hostingId);
|
|
56
|
+
var queryFn = function () { return (0, exports.hostingSites)(hostingId, axiosOptions); };
|
|
67
57
|
var query = (0, react_query_1.useQuery)(queryKey, queryFn, __assign({ enabled: !!(hostingId) }, queryOptions));
|
|
68
58
|
return __assign({ queryKey: queryKey }, query);
|
|
69
59
|
};
|
|
70
|
-
exports.
|
|
60
|
+
exports.useHostingSites = useHostingSites;
|
|
71
61
|
/**
|
|
72
62
|
* Obtain a specific site.
|
|
73
63
|
* @summary For a hosting id, get a specific site by site id
|
|
74
64
|
*/
|
|
75
|
-
var
|
|
65
|
+
var hostingSiteById = function (hostingId, siteId, options) {
|
|
76
66
|
return axios_1["default"].get("/hosting/".concat(hostingId, "/sites/").concat(siteId), options);
|
|
77
67
|
};
|
|
78
|
-
exports.
|
|
79
|
-
var
|
|
80
|
-
exports.
|
|
81
|
-
var
|
|
68
|
+
exports.hostingSiteById = hostingSiteById;
|
|
69
|
+
var getHostingSiteByIdQueryKey = function (hostingId, siteId) { return ["/hosting/".concat(hostingId, "/sites/").concat(siteId)]; };
|
|
70
|
+
exports.getHostingSiteByIdQueryKey = getHostingSiteByIdQueryKey;
|
|
71
|
+
var useHostingSiteById = function (hostingId, siteId, options) {
|
|
82
72
|
var _a;
|
|
83
73
|
var _b = options || {}, queryOptions = _b.query, axiosOptions = _b.axios;
|
|
84
|
-
var queryKey = (_a = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.queryKey) !== null && _a !== void 0 ? _a : (0, exports.
|
|
85
|
-
var queryFn = function () { return (0, exports.
|
|
74
|
+
var queryKey = (_a = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.queryKey) !== null && _a !== void 0 ? _a : (0, exports.getHostingSiteByIdQueryKey)(hostingId, siteId);
|
|
75
|
+
var queryFn = function () { return (0, exports.hostingSiteById)(hostingId, siteId, axiosOptions); };
|
|
86
76
|
var query = (0, react_query_1.useQuery)(queryKey, queryFn, __assign({ enabled: !!(hostingId && siteId) }, queryOptions));
|
|
87
77
|
return __assign({ queryKey: queryKey }, query);
|
|
88
78
|
};
|
|
89
|
-
exports.
|
|
90
|
-
var getSiteSsoMock = function () { return (
|
|
79
|
+
exports.useHostingSiteById = useHostingSiteById;
|
|
80
|
+
var getSiteSsoMock = function () { return ('https://parched-robe.name/wp-login.php?ssotoken=1234567890'); };
|
|
91
81
|
exports.getSiteSsoMock = getSiteSsoMock;
|
|
92
|
-
var
|
|
93
|
-
exports.
|
|
94
|
-
var
|
|
95
|
-
exports.
|
|
82
|
+
var getHostingSitesMock = function () { return ({ limit: 10, n_pages: 1, n_rows: 3, page: 1, rows: [{ id: 0, name: 'Murazik - Weber', url: 'https://parched-robe.name' }, { id: 1, name: 'Gutmann - Bahringer', url: 'http://kindhearted-boogeyman.com' }, { id: 2, name: 'Volkman - Stiedemann', url: 'https://coarse-vendor.com' }] }); };
|
|
83
|
+
exports.getHostingSitesMock = getHostingSitesMock;
|
|
84
|
+
var getHostingSiteByIdMock = function () { return ({ id: 0, name: 'Murazik - Weber', url: 'https://parched-robe.name' }); };
|
|
85
|
+
exports.getHostingSiteByIdMock = getHostingSiteByIdMock;
|
|
96
86
|
var getHostingUAPIMSW = function () { return [
|
|
97
87
|
msw_1.rest.post('*/sites/:siteid/sso', function (_req, res, ctx) {
|
|
98
88
|
return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getSiteSsoMock)()));
|
|
99
89
|
}), msw_1.rest.get('*/hosting/:hostingid/sites', function (_req, res, ctx) {
|
|
100
|
-
return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.
|
|
90
|
+
return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getHostingSitesMock)()));
|
|
101
91
|
}), msw_1.rest.get('*/hosting/:hostingid/sites/:siteid', function (_req, res, ctx) {
|
|
102
|
-
return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.
|
|
92
|
+
return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getHostingSiteByIdMock)()));
|
|
103
93
|
}),
|
|
104
94
|
]; };
|
|
105
95
|
exports.getHostingUAPIMSW = getHostingUAPIMSW;
|
package/src/huapi.ts
CHANGED
|
@@ -23,9 +23,6 @@ import {
|
|
|
23
23
|
import {
|
|
24
24
|
rest
|
|
25
25
|
} from 'msw'
|
|
26
|
-
import {
|
|
27
|
-
faker
|
|
28
|
-
} from '@faker-js/faker'
|
|
29
26
|
/**
|
|
30
27
|
* SSO token or login URL
|
|
31
28
|
*/
|
|
@@ -110,7 +107,7 @@ export const siteSso = (
|
|
|
110
107
|
* Obtain a list of sites.
|
|
111
108
|
* @summary Get sites for a hosting id
|
|
112
109
|
*/
|
|
113
|
-
export const
|
|
110
|
+
export const hostingSites = (
|
|
114
111
|
hostingId: number, options?: AxiosRequestConfig
|
|
115
112
|
): Promise<AxiosResponse<SiteList>> => {
|
|
116
113
|
return axios.get(
|
|
@@ -119,26 +116,26 @@ export const getHostingSites = (
|
|
|
119
116
|
}
|
|
120
117
|
|
|
121
118
|
|
|
122
|
-
export const
|
|
119
|
+
export const getHostingSitesQueryKey = (hostingId: number,) => [`/hosting/${hostingId}/sites`];
|
|
123
120
|
|
|
124
121
|
|
|
125
|
-
export type
|
|
126
|
-
export type
|
|
122
|
+
export type HostingSitesQueryResult = NonNullable<AsyncReturnType<typeof hostingSites>>
|
|
123
|
+
export type HostingSitesQueryError = AxiosError<unknown>
|
|
127
124
|
|
|
128
|
-
export const
|
|
129
|
-
hostingId: number, options?: { query?:UseQueryOptions<AsyncReturnType<typeof
|
|
125
|
+
export const useHostingSites = <TData = AsyncReturnType<typeof hostingSites>, TError = AxiosError<unknown>>(
|
|
126
|
+
hostingId: number, options?: { query?:UseQueryOptions<AsyncReturnType<typeof hostingSites>, TError, TData>, axios?: AxiosRequestConfig}
|
|
130
127
|
|
|
131
128
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
132
129
|
|
|
133
130
|
const {query: queryOptions, axios: axiosOptions} = options || {}
|
|
134
131
|
|
|
135
|
-
const queryKey = queryOptions?.queryKey ??
|
|
132
|
+
const queryKey = queryOptions?.queryKey ?? getHostingSitesQueryKey(hostingId);
|
|
136
133
|
|
|
137
134
|
|
|
138
135
|
|
|
139
|
-
const queryFn: QueryFunction<AsyncReturnType<typeof
|
|
136
|
+
const queryFn: QueryFunction<AsyncReturnType<typeof hostingSites>> = () => hostingSites(hostingId, axiosOptions);
|
|
140
137
|
|
|
141
|
-
const query = useQuery<AsyncReturnType<typeof
|
|
138
|
+
const query = useQuery<AsyncReturnType<typeof hostingSites>, TError, TData>(queryKey, queryFn, {enabled: !!(hostingId), ...queryOptions})
|
|
142
139
|
|
|
143
140
|
return {
|
|
144
141
|
queryKey,
|
|
@@ -151,7 +148,7 @@ export const useGetHostingSites = <TData = AsyncReturnType<typeof getHostingSite
|
|
|
151
148
|
* Obtain a specific site.
|
|
152
149
|
* @summary For a hosting id, get a specific site by site id
|
|
153
150
|
*/
|
|
154
|
-
export const
|
|
151
|
+
export const hostingSiteById = (
|
|
155
152
|
hostingId: number,
|
|
156
153
|
siteId: string, options?: AxiosRequestConfig
|
|
157
154
|
): Promise<AxiosResponse<Site>> => {
|
|
@@ -161,28 +158,28 @@ export const getHostingSiteById = (
|
|
|
161
158
|
}
|
|
162
159
|
|
|
163
160
|
|
|
164
|
-
export const
|
|
161
|
+
export const getHostingSiteByIdQueryKey = (hostingId: number,
|
|
165
162
|
siteId: string,) => [`/hosting/${hostingId}/sites/${siteId}`];
|
|
166
163
|
|
|
167
164
|
|
|
168
|
-
export type
|
|
169
|
-
export type
|
|
165
|
+
export type HostingSiteByIdQueryResult = NonNullable<AsyncReturnType<typeof hostingSiteById>>
|
|
166
|
+
export type HostingSiteByIdQueryError = AxiosError<unknown>
|
|
170
167
|
|
|
171
|
-
export const
|
|
168
|
+
export const useHostingSiteById = <TData = AsyncReturnType<typeof hostingSiteById>, TError = AxiosError<unknown>>(
|
|
172
169
|
hostingId: number,
|
|
173
|
-
siteId: string, options?: { query?:UseQueryOptions<AsyncReturnType<typeof
|
|
170
|
+
siteId: string, options?: { query?:UseQueryOptions<AsyncReturnType<typeof hostingSiteById>, TError, TData>, axios?: AxiosRequestConfig}
|
|
174
171
|
|
|
175
172
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
176
173
|
|
|
177
174
|
const {query: queryOptions, axios: axiosOptions} = options || {}
|
|
178
175
|
|
|
179
|
-
const queryKey = queryOptions?.queryKey ??
|
|
176
|
+
const queryKey = queryOptions?.queryKey ?? getHostingSiteByIdQueryKey(hostingId,siteId);
|
|
180
177
|
|
|
181
178
|
|
|
182
179
|
|
|
183
|
-
const queryFn: QueryFunction<AsyncReturnType<typeof
|
|
180
|
+
const queryFn: QueryFunction<AsyncReturnType<typeof hostingSiteById>> = () => hostingSiteById(hostingId,siteId, axiosOptions);
|
|
184
181
|
|
|
185
|
-
const query = useQuery<AsyncReturnType<typeof
|
|
182
|
+
const query = useQuery<AsyncReturnType<typeof hostingSiteById>, TError, TData>(queryKey, queryFn, {enabled: !!(hostingId && siteId), ...queryOptions})
|
|
186
183
|
|
|
187
184
|
return {
|
|
188
185
|
queryKey,
|
|
@@ -193,11 +190,11 @@ export const useGetHostingSiteById = <TData = AsyncReturnType<typeof getHostingS
|
|
|
193
190
|
|
|
194
191
|
|
|
195
192
|
|
|
196
|
-
export const getSiteSsoMock = () => (
|
|
193
|
+
export const getSiteSsoMock = () => ('https://parched-robe.name/wp-login.php?ssotoken=1234567890')
|
|
197
194
|
|
|
198
|
-
export const
|
|
195
|
+
export const getHostingSitesMock = () => ({ limit: 10, n_pages: 1, n_rows: 3, page: 1, rows: [{ id: 0, name: 'Murazik - Weber', url: 'https://parched-robe.name', }, { id: 1, name: 'Gutmann - Bahringer', url: 'http://kindhearted-boogeyman.com', }, { id: 2, name: 'Volkman - Stiedemann', url: 'https://coarse-vendor.com', }], })
|
|
199
196
|
|
|
200
|
-
export const
|
|
197
|
+
export const getHostingSiteByIdMock = () => ({ id: 0, name: 'Murazik - Weber', url: 'https://parched-robe.name', })
|
|
201
198
|
|
|
202
199
|
export const getHostingUAPIMSW = () => [
|
|
203
200
|
rest.post('*/sites/:siteid/sso', (_req, res, ctx) => {
|
|
@@ -210,12 +207,12 @@ ctx.json(getSiteSsoMock()),
|
|
|
210
207
|
return res(
|
|
211
208
|
ctx.delay(1000),
|
|
212
209
|
ctx.status(200, 'Mocked status'),
|
|
213
|
-
ctx.json(
|
|
210
|
+
ctx.json(getHostingSitesMock()),
|
|
214
211
|
)
|
|
215
212
|
}),rest.get('*/hosting/:hostingid/sites/:siteid', (_req, res, ctx) => {
|
|
216
213
|
return res(
|
|
217
214
|
ctx.delay(1000),
|
|
218
215
|
ctx.status(200, 'Mocked status'),
|
|
219
|
-
ctx.json(
|
|
216
|
+
ctx.json(getHostingSiteByIdMock()),
|
|
220
217
|
)
|
|
221
218
|
}),]
|