@newfold/huapi-js 1.2.6-alpha → 1.2.6-alpha.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/dist/index.d.ts +41 -0
- package/dist/index.js +51 -0
- package/dist/index.msw.d.ts +15 -0
- package/dist/index.msw.js +24 -0
- package/dist/models/{index.ts → index.d.ts} +0 -0
- package/dist/models/index.js +19 -0
- package/dist/models/{site.ts → site.d.ts} +6 -7
- package/dist/models/site.js +9 -0
- package/dist/models/{siteList.ts → siteList.d.ts} +10 -11
- package/dist/models/siteList.js +2 -0
- package/dist/models/{siteSso.ts → siteSso.d.ts} +2 -3
- package/dist/models/siteSso.js +9 -0
- package/package.json +5 -5
- package/dist/huapi.msw.ts +0 -32
- package/dist/huapi.ts +0 -110
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
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 { AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios';
|
|
9
|
+
import { UseQueryOptions, UseMutationOptions, UseQueryResult, QueryKey } from 'react-query';
|
|
10
|
+
import type { SiteSso, SiteList } from './models';
|
|
11
|
+
declare type AsyncReturnType<T extends (...args: any) => Promise<any>> = T extends (...args: any) => Promise<infer R> ? R : any;
|
|
12
|
+
/**
|
|
13
|
+
* TODO
|
|
14
|
+
* @summary Get SSO token
|
|
15
|
+
*/
|
|
16
|
+
export declare const siteSso: (siteId: number, options?: AxiosRequestConfig<any> | undefined) => Promise<AxiosResponse<SiteSso>>;
|
|
17
|
+
export declare type SiteSsoMutationResult = NonNullable<AsyncReturnType<typeof siteSso>>;
|
|
18
|
+
export declare type SiteSsoMutationError = AxiosError<unknown>;
|
|
19
|
+
export declare const useSiteSso: <TError = AxiosError<unknown, any>, TContext = unknown>(options?: {
|
|
20
|
+
mutation?: UseMutationOptions<AxiosResponse<SiteSso, any>, TError, {
|
|
21
|
+
siteId: number;
|
|
22
|
+
}, TContext> | undefined;
|
|
23
|
+
axios?: AxiosRequestConfig<any> | undefined;
|
|
24
|
+
} | undefined) => import("react-query").UseMutationResult<AxiosResponse<SiteSso, any>, TError, {
|
|
25
|
+
siteId: number;
|
|
26
|
+
}, TContext>;
|
|
27
|
+
/**
|
|
28
|
+
* Obtain a list of sites.
|
|
29
|
+
* @summary Get sites for a hosting id
|
|
30
|
+
*/
|
|
31
|
+
export declare const hostingSites: (hostingId: number, options?: AxiosRequestConfig<any> | undefined) => Promise<AxiosResponse<SiteList>>;
|
|
32
|
+
export declare const getHostingSitesQueryKey: (hostingId: number) => string[];
|
|
33
|
+
export declare type HostingSitesQueryResult = NonNullable<AsyncReturnType<typeof hostingSites>>;
|
|
34
|
+
export declare type HostingSitesQueryError = AxiosError<unknown>;
|
|
35
|
+
export declare const useHostingSites: <TData = AxiosResponse<SiteList, any>, TError = AxiosError<unknown, any>>(hostingId: number, options?: {
|
|
36
|
+
query?: UseQueryOptions<AxiosResponse<SiteList, any>, TError, TData, QueryKey> | undefined;
|
|
37
|
+
axios?: AxiosRequestConfig<any> | undefined;
|
|
38
|
+
} | undefined) => UseQueryResult<TData, TError> & {
|
|
39
|
+
queryKey: QueryKey;
|
|
40
|
+
};
|
|
41
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.useHostingSites = exports.getHostingSitesQueryKey = exports.hostingSites = exports.useSiteSso = exports.siteSso = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Generated by orval v6.7.1 🍺
|
|
9
|
+
* Do not edit manually.
|
|
10
|
+
* Hosting UAPI
|
|
11
|
+
* Hosting UAPI
|
|
12
|
+
* OpenAPI spec version: 0.1.0
|
|
13
|
+
*/
|
|
14
|
+
const axios_1 = __importDefault(require("axios"));
|
|
15
|
+
const react_query_1 = require("react-query");
|
|
16
|
+
/**
|
|
17
|
+
* TODO
|
|
18
|
+
* @summary Get SSO token
|
|
19
|
+
*/
|
|
20
|
+
const siteSso = (siteId, options) => {
|
|
21
|
+
return axios_1.default.post(`/sites/${siteId}/sso`, undefined, options);
|
|
22
|
+
};
|
|
23
|
+
exports.siteSso = siteSso;
|
|
24
|
+
const useSiteSso = (options) => {
|
|
25
|
+
const { mutation: mutationOptions, axios: axiosOptions } = options || {};
|
|
26
|
+
const mutationFn = (props) => {
|
|
27
|
+
const { siteId } = props || {};
|
|
28
|
+
return (0, exports.siteSso)(siteId, axiosOptions);
|
|
29
|
+
};
|
|
30
|
+
return (0, react_query_1.useMutation)(mutationFn, mutationOptions);
|
|
31
|
+
};
|
|
32
|
+
exports.useSiteSso = useSiteSso;
|
|
33
|
+
/**
|
|
34
|
+
* Obtain a list of sites.
|
|
35
|
+
* @summary Get sites for a hosting id
|
|
36
|
+
*/
|
|
37
|
+
const hostingSites = (hostingId, options) => {
|
|
38
|
+
return axios_1.default.get(`/hosting/${hostingId}/sites`, options);
|
|
39
|
+
};
|
|
40
|
+
exports.hostingSites = hostingSites;
|
|
41
|
+
const getHostingSitesQueryKey = (hostingId) => [`/hosting/${hostingId}/sites`];
|
|
42
|
+
exports.getHostingSitesQueryKey = getHostingSitesQueryKey;
|
|
43
|
+
const useHostingSites = (hostingId, options) => {
|
|
44
|
+
var _a;
|
|
45
|
+
const { query: queryOptions, axios: axiosOptions } = options || {};
|
|
46
|
+
const queryKey = (_a = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.queryKey) !== null && _a !== void 0 ? _a : (0, exports.getHostingSitesQueryKey)(hostingId);
|
|
47
|
+
const queryFn = () => (0, exports.hostingSites)(hostingId, axiosOptions);
|
|
48
|
+
const query = (0, react_query_1.useQuery)(queryKey, queryFn, Object.assign({ enabled: !!(hostingId) }, queryOptions));
|
|
49
|
+
return Object.assign({ queryKey }, query);
|
|
50
|
+
};
|
|
51
|
+
exports.useHostingSites = useHostingSites;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const getSiteSsoMock: () => {
|
|
2
|
+
sso: string;
|
|
3
|
+
};
|
|
4
|
+
export declare const getHostingSitesMock: () => {
|
|
5
|
+
limit: number;
|
|
6
|
+
n_pages: number;
|
|
7
|
+
n_rows: number;
|
|
8
|
+
page: number;
|
|
9
|
+
rows: {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
url: string;
|
|
13
|
+
}[];
|
|
14
|
+
};
|
|
15
|
+
export declare const getHostingUAPIMSW: () => import("msw").RestHandler<import("msw").MockedRequest<import("msw").DefaultRequestBody>>[];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHostingUAPIMSW = exports.getHostingSitesMock = exports.getSiteSsoMock = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Generated by orval v6.7.1 🍺
|
|
6
|
+
* Do not edit manually.
|
|
7
|
+
* Hosting UAPI
|
|
8
|
+
* Hosting UAPI
|
|
9
|
+
* OpenAPI spec version: 0.1.0
|
|
10
|
+
*/
|
|
11
|
+
const msw_1 = require("msw");
|
|
12
|
+
const faker_1 = require("@faker-js/faker");
|
|
13
|
+
const getSiteSsoMock = () => ({ sso: faker_1.faker.random.word() });
|
|
14
|
+
exports.getSiteSsoMock = getSiteSsoMock;
|
|
15
|
+
const getHostingSitesMock = () => ({ limit: faker_1.faker.datatype.number(), n_pages: faker_1.faker.datatype.number(), n_rows: faker_1.faker.datatype.number(), page: faker_1.faker.datatype.number(), rows: [...Array(faker_1.faker.datatype.number({ min: 1, max: 10 }))].map(() => ({ id: faker_1.faker.random.word(), name: faker_1.faker.random.word(), url: faker_1.faker.random.word() })) });
|
|
16
|
+
exports.getHostingSitesMock = getHostingSitesMock;
|
|
17
|
+
const getHostingUAPIMSW = () => [
|
|
18
|
+
msw_1.rest.post('*/sites/:siteid/sso', (_req, res, ctx) => {
|
|
19
|
+
return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getSiteSsoMock)()));
|
|
20
|
+
}), msw_1.rest.get('*/hosting/:hostingid/sites', (_req, res, ctx) => {
|
|
21
|
+
return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getHostingSitesMock)()));
|
|
22
|
+
}),
|
|
23
|
+
];
|
|
24
|
+
exports.getHostingUAPIMSW = getHostingUAPIMSW;
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./site"), exports);
|
|
18
|
+
__exportStar(require("./siteList"), exports);
|
|
19
|
+
__exportStar(require("./siteSso"), exports);
|
|
@@ -5,15 +5,14 @@
|
|
|
5
5
|
* Hosting UAPI
|
|
6
6
|
* OpenAPI spec version: 0.1.0
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
8
|
/**
|
|
10
9
|
* A site
|
|
11
10
|
*/
|
|
12
11
|
export interface Site {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
/** TODO */
|
|
13
|
+
id: string;
|
|
14
|
+
/** TODO */
|
|
15
|
+
name: string;
|
|
16
|
+
/** TODO */
|
|
17
|
+
url: string;
|
|
19
18
|
}
|
|
@@ -6,19 +6,18 @@
|
|
|
6
6
|
* OpenAPI spec version: 0.1.0
|
|
7
7
|
*/
|
|
8
8
|
import type { Site } from './site';
|
|
9
|
-
|
|
10
9
|
/**
|
|
11
10
|
* List of sites
|
|
12
11
|
*/
|
|
13
12
|
export interface SiteList {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
/** Max number of sites included in response */
|
|
14
|
+
limit: number;
|
|
15
|
+
/** TODO */
|
|
16
|
+
n_pages: number;
|
|
17
|
+
/** TODO */
|
|
18
|
+
n_rows: number;
|
|
19
|
+
/** TODO */
|
|
20
|
+
page: number;
|
|
21
|
+
/** TODO */
|
|
22
|
+
rows: Site[];
|
|
24
23
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newfold/huapi-js",
|
|
3
|
-
"version": "1.2.6-alpha",
|
|
4
|
-
"main": "dist/huapi.ts",
|
|
3
|
+
"version": "1.2.6-alpha.3",
|
|
5
4
|
"license": "MIT",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
6
7
|
"files": [
|
|
7
8
|
"dist/*",
|
|
8
9
|
"src/*"
|
|
@@ -19,12 +20,11 @@
|
|
|
19
20
|
"typescript": "^4.6.3"
|
|
20
21
|
},
|
|
21
22
|
"peerDependencies": {
|
|
22
|
-
"react": "^17.0.0 || ^18.0.0"
|
|
23
|
-
"react-query": "^3.34.19"
|
|
23
|
+
"react": "^17.0.0 || ^18.0.0"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"orval": "orval",
|
|
27
|
-
"
|
|
27
|
+
"tsc": "npx tsc",
|
|
28
28
|
"build": "yarn orval && yarn tsToJs"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/dist/huapi.msw.ts
DELETED
|
@@ -1,32 +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 {
|
|
9
|
-
rest
|
|
10
|
-
} from 'msw'
|
|
11
|
-
import {
|
|
12
|
-
faker
|
|
13
|
-
} from '@faker-js/faker'
|
|
14
|
-
|
|
15
|
-
export const getSiteSsoMock = () => ({sso: faker.random.word()})
|
|
16
|
-
|
|
17
|
-
export const getHostingSitesMock = () => ({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()}))})
|
|
18
|
-
|
|
19
|
-
export const getHostingUAPIMSW = () => [
|
|
20
|
-
rest.post('*/sites/:siteid/sso', (_req, res, ctx) => {
|
|
21
|
-
return res(
|
|
22
|
-
ctx.delay(1000),
|
|
23
|
-
ctx.status(200, 'Mocked status'),
|
|
24
|
-
ctx.json(getSiteSsoMock()),
|
|
25
|
-
)
|
|
26
|
-
}),rest.get('*/hosting/:hostingid/sites', (_req, res, ctx) => {
|
|
27
|
-
return res(
|
|
28
|
-
ctx.delay(1000),
|
|
29
|
-
ctx.status(200, 'Mocked status'),
|
|
30
|
-
ctx.json(getHostingSitesMock()),
|
|
31
|
-
)
|
|
32
|
-
}),]
|
package/dist/huapi.ts
DELETED
|
@@ -1,110 +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 type {
|
|
24
|
-
SiteSso,
|
|
25
|
-
SiteList
|
|
26
|
-
} from './models'
|
|
27
|
-
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
-
type AsyncReturnType<
|
|
30
|
-
T extends (...args: any) => Promise<any>
|
|
31
|
-
> = T extends (...args: any) => Promise<infer R> ? R : any;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* TODO
|
|
36
|
-
* @summary Get SSO token
|
|
37
|
-
*/
|
|
38
|
-
export const siteSso = (
|
|
39
|
-
siteId: number, options?: AxiosRequestConfig
|
|
40
|
-
): Promise<AxiosResponse<SiteSso>> => {
|
|
41
|
-
return axios.post(
|
|
42
|
-
`/sites/${siteId}/sso`,undefined,options
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
export type SiteSsoMutationResult = NonNullable<AsyncReturnType<typeof siteSso>>
|
|
49
|
-
|
|
50
|
-
export type SiteSsoMutationError = AxiosError<unknown>
|
|
51
|
-
|
|
52
|
-
export const useSiteSso = <TError = AxiosError<unknown>,
|
|
53
|
-
|
|
54
|
-
TContext = unknown>(options?: { mutation?:UseMutationOptions<AsyncReturnType<typeof siteSso>, TError,{siteId: number}, TContext>, axios?: AxiosRequestConfig}
|
|
55
|
-
) => {
|
|
56
|
-
const {mutation: mutationOptions, axios: axiosOptions} = options || {}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const mutationFn: MutationFunction<AsyncReturnType<typeof siteSso>, {siteId: number}> = (props) => {
|
|
62
|
-
const {siteId} = props || {};
|
|
63
|
-
|
|
64
|
-
return siteSso(siteId,axiosOptions)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return useMutation<AsyncReturnType<typeof siteSso>, TError, {siteId: number}, TContext>(mutationFn, mutationOptions)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Obtain a list of sites.
|
|
72
|
-
* @summary Get sites for a hosting id
|
|
73
|
-
*/
|
|
74
|
-
export const hostingSites = (
|
|
75
|
-
hostingId: number, options?: AxiosRequestConfig
|
|
76
|
-
): Promise<AxiosResponse<SiteList>> => {
|
|
77
|
-
return axios.get(
|
|
78
|
-
`/hosting/${hostingId}/sites`,options
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
export const getHostingSitesQueryKey = (hostingId: number,) => [`/hosting/${hostingId}/sites`];
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
export type HostingSitesQueryResult = NonNullable<AsyncReturnType<typeof hostingSites>>
|
|
87
|
-
export type HostingSitesQueryError = AxiosError<unknown>
|
|
88
|
-
|
|
89
|
-
export const useHostingSites = <TData = AsyncReturnType<typeof hostingSites>, TError = AxiosError<unknown>>(
|
|
90
|
-
hostingId: number, options?: { query?:UseQueryOptions<AsyncReturnType<typeof hostingSites>, TError, TData>, axios?: AxiosRequestConfig}
|
|
91
|
-
|
|
92
|
-
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
|
|
93
|
-
|
|
94
|
-
const {query: queryOptions, axios: axiosOptions} = options || {}
|
|
95
|
-
|
|
96
|
-
const queryKey = queryOptions?.queryKey ?? getHostingSitesQueryKey(hostingId);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const queryFn: QueryFunction<AsyncReturnType<typeof hostingSites>> = () => hostingSites(hostingId, axiosOptions);
|
|
101
|
-
|
|
102
|
-
const query = useQuery<AsyncReturnType<typeof hostingSites>, TError, TData>(queryKey, queryFn, {enabled: !!(hostingId), ...queryOptions})
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
queryKey,
|
|
106
|
-
...query
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|