@newfold/huapi-js 1.2.0 → 1.2.3
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/README.md +6 -3
- package/{src → dist}/huapi.js +24 -34
- package/openapi.json +2 -2
- package/orval.config.js +41 -12
- package/package.json +3 -3
- package/src/mocks/sites.js +29 -0
- package/src/huapi.ts +0 -221
package/README.md
CHANGED
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```sh
|
|
8
|
+
$ yarn add @newfold/huapi-js
|
|
9
|
+
# yarn package installed
|
|
10
|
+
```
|
|
8
11
|
|
|
9
12
|
## Usage
|
|
10
13
|
|
|
@@ -13,11 +16,11 @@ TODO
|
|
|
13
16
|
```js
|
|
14
17
|
import React from "react";
|
|
15
18
|
|
|
16
|
-
import {
|
|
19
|
+
import { useHostingSites } from "@newfold/huapi-js";
|
|
17
20
|
|
|
18
21
|
const MyComponent = () => {
|
|
19
22
|
const hostingId = "2";
|
|
20
|
-
const { isLoading, data } =
|
|
23
|
+
const { isLoading, data } = useHostingSites(hostingId);
|
|
21
24
|
|
|
22
25
|
if (isLoading) return <h1>Loading...</h1>;
|
|
23
26
|
|
package/{src → dist}/huapi.js
RENAMED
|
@@ -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://bobtheblog.com/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: '1', name: 'Bob the Blog', url: 'https://bobtheblog.com' }, { id: '2', name: 'Wendy the Website', url: 'https://wendythewebsite.com' }, { id: '3', name: 'Cathy the Coding Camp', url: 'https://cathythecodingcamp.com' }] }); };
|
|
83
|
+
exports.getHostingSitesMock = getHostingSitesMock;
|
|
84
|
+
var getHostingSiteByIdMock = function () { return ({ id: '1', name: 'Bob the Blog', url: 'https://bobtheblog.com' }); };
|
|
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/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,45 @@
|
|
|
1
|
-
|
|
1
|
+
import { defineConfig } from "orval";
|
|
2
|
+
|
|
3
|
+
import { sites, site, siteSso } from "./src/mocks/sites";
|
|
4
|
+
|
|
5
|
+
const input = {
|
|
6
|
+
target: "./openapi.json",
|
|
7
|
+
validation: true,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const output = {
|
|
11
|
+
// mode: "tags-split",
|
|
12
|
+
target: "./dist/huapi.ts",
|
|
13
|
+
// schemas: "dist/model",
|
|
14
|
+
client: "react-query",
|
|
15
|
+
mock: true,
|
|
16
|
+
clean: true,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
2
20
|
huapi: {
|
|
3
|
-
input
|
|
4
|
-
target: "./openapi.json",
|
|
5
|
-
validation: true,
|
|
6
|
-
},
|
|
21
|
+
input,
|
|
7
22
|
output: {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
...output,
|
|
24
|
+
override: {
|
|
25
|
+
operations: {
|
|
26
|
+
site_sso: {
|
|
27
|
+
mock: {
|
|
28
|
+
data: siteSso,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
hosting_sites: {
|
|
32
|
+
mock: {
|
|
33
|
+
data: sites,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
hosting_site_by_id: {
|
|
37
|
+
mock: {
|
|
38
|
+
data: site,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
14
43
|
},
|
|
15
44
|
},
|
|
16
|
-
};
|
|
45
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newfold/huapi-js",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"main": "
|
|
3
|
+
"version": "1.2.3",
|
|
4
|
+
"main": "dist/huapi.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@faker-js/faker": "^6.1.2",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
24
|
"orval": "orval",
|
|
25
|
-
"tsToJs": "npx tsc ./
|
|
25
|
+
"tsToJs": "npx tsc ./dist/*",
|
|
26
26
|
"build": "yarn orval && yarn tsToJs"
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const sites = {
|
|
2
|
+
limit: 10,
|
|
3
|
+
n_pages: 1,
|
|
4
|
+
n_rows: 3,
|
|
5
|
+
page: 1,
|
|
6
|
+
rows: [
|
|
7
|
+
{
|
|
8
|
+
id: "1",
|
|
9
|
+
name: "Bob the Blog",
|
|
10
|
+
url: "https://bobtheblog.com",
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
id: "2",
|
|
14
|
+
name: "Wendy the Website",
|
|
15
|
+
url: "https://wendythewebsite.com",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: "3",
|
|
19
|
+
name: "Cathy the Coding Camp",
|
|
20
|
+
url: "https://cathythecodingcamp.com",
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// TODO: would be nice if we could take in the param (siteId) and return the proper site,
|
|
26
|
+
// but currently we are just dumbly returning the same site regardless of siteId
|
|
27
|
+
export const site = sites.rows[0];
|
|
28
|
+
|
|
29
|
+
export const siteSso = `${sites.rows[0].url}/wp-login.php?ssotoken=1234567890`;
|
package/src/huapi.ts
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generated by orval v6.7.1 🍺
|
|
3
|
-
* Do not edit manually.
|
|
4
|
-
* Hosting UAPI
|
|
5
|
-
* Hosting UAPI
|
|
6
|
-
* OpenAPI spec version: 0.1.0
|
|
7
|
-
*/
|
|
8
|
-
import axios,{
|
|
9
|
-
AxiosRequestConfig,
|
|
10
|
-
AxiosResponse,
|
|
11
|
-
AxiosError
|
|
12
|
-
} from 'axios'
|
|
13
|
-
import {
|
|
14
|
-
useQuery,
|
|
15
|
-
useMutation,
|
|
16
|
-
UseQueryOptions,
|
|
17
|
-
UseMutationOptions,
|
|
18
|
-
QueryFunction,
|
|
19
|
-
MutationFunction,
|
|
20
|
-
UseQueryResult,
|
|
21
|
-
QueryKey
|
|
22
|
-
} from 'react-query'
|
|
23
|
-
import {
|
|
24
|
-
rest
|
|
25
|
-
} from 'msw'
|
|
26
|
-
import {
|
|
27
|
-
faker
|
|
28
|
-
} from '@faker-js/faker'
|
|
29
|
-
/**
|
|
30
|
-
* SSO token or login URL
|
|
31
|
-
*/
|
|
32
|
-
export interface SiteSso {
|
|
33
|
-
/** TODO */
|
|
34
|
-
sso: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* A site
|
|
39
|
-
*/
|
|
40
|
-
export interface Site {
|
|
41
|
-
/** TODO */
|
|
42
|
-
id: string;
|
|
43
|
-
/** TODO */
|
|
44
|
-
name: string;
|
|
45
|
-
/** TODO */
|
|
46
|
-
url: string;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* List of sites
|
|
51
|
-
*/
|
|
52
|
-
export interface SiteList {
|
|
53
|
-
/** Max number of sites included in response */
|
|
54
|
-
limit: number;
|
|
55
|
-
/** TODO */
|
|
56
|
-
n_pages: number;
|
|
57
|
-
/** TODO */
|
|
58
|
-
n_rows: number;
|
|
59
|
-
/** TODO */
|
|
60
|
-
page: number;
|
|
61
|
-
/** TODO */
|
|
62
|
-
rows: Site[];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
|
-
type AsyncReturnType<
|
|
69
|
-
T extends (...args: any) => Promise<any>
|
|
70
|
-
> = T extends (...args: any) => Promise<infer R> ? R : any;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* TODO
|
|
75
|
-
* @summary Get SSO token
|
|
76
|
-
*/
|
|
77
|
-
export const siteSso = (
|
|
78
|
-
siteId: number, options?: AxiosRequestConfig
|
|
79
|
-
): Promise<AxiosResponse<SiteSso>> => {
|
|
80
|
-
return axios.post(
|
|
81
|
-
`/sites/${siteId}/sso`,undefined,options
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
export type SiteSsoMutationResult = NonNullable<AsyncReturnType<typeof siteSso>>
|
|
88
|
-
|
|
89
|
-
export type SiteSsoMutationError = AxiosError<unknown>
|
|
90
|
-
|
|
91
|
-
export const useSiteSso = <TError = AxiosError<unknown>,
|
|
92
|
-
|
|
93
|
-
TContext = unknown>(options?: { mutation?:UseMutationOptions<AsyncReturnType<typeof siteSso>, TError,{siteId: number}, TContext>, axios?: AxiosRequestConfig}
|
|
94
|
-
) => {
|
|
95
|
-
const {mutation: mutationOptions, axios: axiosOptions} = options || {}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const mutationFn: MutationFunction<AsyncReturnType<typeof siteSso>, {siteId: number}> = (props) => {
|
|
101
|
-
const {siteId} = props || {};
|
|
102
|
-
|
|
103
|
-
return siteSso(siteId,axiosOptions)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return useMutation<AsyncReturnType<typeof siteSso>, TError, {siteId: number}, TContext>(mutationFn, mutationOptions)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Obtain a list of sites.
|
|
111
|
-
* @summary Get sites for a hosting id
|
|
112
|
-
*/
|
|
113
|
-
export const getHostingSites = (
|
|
114
|
-
hostingId: number, options?: AxiosRequestConfig
|
|
115
|
-
): Promise<AxiosResponse<SiteList>> => {
|
|
116
|
-
return axios.get(
|
|
117
|
-
`/hosting/${hostingId}/sites`,options
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
export const getGetHostingSitesQueryKey = (hostingId: number,) => [`/hosting/${hostingId}/sites`];
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
export type GetHostingSitesQueryResult = NonNullable<AsyncReturnType<typeof getHostingSites>>
|
|
126
|
-
export type GetHostingSitesQueryError = AxiosError<unknown>
|
|
127
|
-
|
|
128
|
-
export const useGetHostingSites = <TData = AsyncReturnType<typeof getHostingSites>, TError = AxiosError<unknown>>(
|
|
129
|
-
hostingId: number, options?: { query?:UseQueryOptions<AsyncReturnType<typeof getHostingSites>, TError, TData>, axios?: AxiosRequestConfig}
|
|
130
|
-
|
|
131
|
-
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
132
|
-
|
|
133
|
-
const {query: queryOptions, axios: axiosOptions} = options || {}
|
|
134
|
-
|
|
135
|
-
const queryKey = queryOptions?.queryKey ?? getGetHostingSitesQueryKey(hostingId);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const queryFn: QueryFunction<AsyncReturnType<typeof getHostingSites>> = () => getHostingSites(hostingId, axiosOptions);
|
|
140
|
-
|
|
141
|
-
const query = useQuery<AsyncReturnType<typeof getHostingSites>, TError, TData>(queryKey, queryFn, {enabled: !!(hostingId), ...queryOptions})
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
queryKey,
|
|
145
|
-
...query
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Obtain a specific site.
|
|
152
|
-
* @summary For a hosting id, get a specific site by site id
|
|
153
|
-
*/
|
|
154
|
-
export const getHostingSiteById = (
|
|
155
|
-
hostingId: number,
|
|
156
|
-
siteId: string, options?: AxiosRequestConfig
|
|
157
|
-
): Promise<AxiosResponse<Site>> => {
|
|
158
|
-
return axios.get(
|
|
159
|
-
`/hosting/${hostingId}/sites/${siteId}`,options
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
export const getGetHostingSiteByIdQueryKey = (hostingId: number,
|
|
165
|
-
siteId: string,) => [`/hosting/${hostingId}/sites/${siteId}`];
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
export type GetHostingSiteByIdQueryResult = NonNullable<AsyncReturnType<typeof getHostingSiteById>>
|
|
169
|
-
export type GetHostingSiteByIdQueryError = AxiosError<unknown>
|
|
170
|
-
|
|
171
|
-
export const useGetHostingSiteById = <TData = AsyncReturnType<typeof getHostingSiteById>, TError = AxiosError<unknown>>(
|
|
172
|
-
hostingId: number,
|
|
173
|
-
siteId: string, options?: { query?:UseQueryOptions<AsyncReturnType<typeof getHostingSiteById>, TError, TData>, axios?: AxiosRequestConfig}
|
|
174
|
-
|
|
175
|
-
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
176
|
-
|
|
177
|
-
const {query: queryOptions, axios: axiosOptions} = options || {}
|
|
178
|
-
|
|
179
|
-
const queryKey = queryOptions?.queryKey ?? getGetHostingSiteByIdQueryKey(hostingId,siteId);
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const queryFn: QueryFunction<AsyncReturnType<typeof getHostingSiteById>> = () => getHostingSiteById(hostingId,siteId, axiosOptions);
|
|
184
|
-
|
|
185
|
-
const query = useQuery<AsyncReturnType<typeof getHostingSiteById>, TError, TData>(queryKey, queryFn, {enabled: !!(hostingId && siteId), ...queryOptions})
|
|
186
|
-
|
|
187
|
-
return {
|
|
188
|
-
queryKey,
|
|
189
|
-
...query
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
export const getSiteSsoMock = () => ({sso: faker.random.word()})
|
|
197
|
-
|
|
198
|
-
export const getGetHostingSitesMock = () => ({limit: faker.datatype.number(), n_pages: faker.datatype.number(), n_rows: faker.datatype.number(), page: faker.datatype.number(), rows: [...Array(faker.datatype.number({min: 1, max: 10}))].map(() => ({id: faker.random.word(), name: faker.random.word(), url: faker.random.word()}))})
|
|
199
|
-
|
|
200
|
-
export const getGetHostingSiteByIdMock = () => ({id: faker.random.word(), name: faker.random.word(), url: faker.random.word()})
|
|
201
|
-
|
|
202
|
-
export const getHostingUAPIMSW = () => [
|
|
203
|
-
rest.post('*/sites/:siteid/sso', (_req, res, ctx) => {
|
|
204
|
-
return res(
|
|
205
|
-
ctx.delay(1000),
|
|
206
|
-
ctx.status(200, 'Mocked status'),
|
|
207
|
-
ctx.json(getSiteSsoMock()),
|
|
208
|
-
)
|
|
209
|
-
}),rest.get('*/hosting/:hostingid/sites', (_req, res, ctx) => {
|
|
210
|
-
return res(
|
|
211
|
-
ctx.delay(1000),
|
|
212
|
-
ctx.status(200, 'Mocked status'),
|
|
213
|
-
ctx.json(getGetHostingSitesMock()),
|
|
214
|
-
)
|
|
215
|
-
}),rest.get('*/hosting/:hostingid/sites/:siteid', (_req, res, ctx) => {
|
|
216
|
-
return res(
|
|
217
|
-
ctx.delay(1000),
|
|
218
|
-
ctx.status(200, 'Mocked status'),
|
|
219
|
-
ctx.json(getGetHostingSiteByIdMock()),
|
|
220
|
-
)
|
|
221
|
-
}),]
|