@newfold/huapi-js 1.1.3 → 1.2.2

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 CHANGED
@@ -4,7 +4,10 @@
4
4
 
5
5
  ## Installation
6
6
 
7
- TODO
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 { useGetHostingSites } from "@newfold/huapi-js";
19
+ import { useHostingSites } from "@newfold/huapi-js";
17
20
 
18
21
  const MyComponent = () => {
19
22
  const hostingId = "2";
20
- const { isLoading, data } = useGetHostingSites(hostingId);
23
+ const { isLoading, data } = useHostingSites(hostingId);
21
24
 
22
25
  if (isLoading) return <h1>Loading...</h1>;
23
26
 
package/openapi.json CHANGED
@@ -12,9 +12,9 @@
12
12
  "description": "A site",
13
13
  "properties": {
14
14
  "id": {
15
- "type": "integer",
15
+ "type": "string",
16
16
  "description": "TODO",
17
- "example": 1
17
+ "example": "1"
18
18
  },
19
19
  "name": {
20
20
  "type": "string",
@@ -67,12 +67,12 @@
67
67
  },
68
68
  "example": [
69
69
  {
70
- "id": 1,
70
+ "id": "1",
71
71
  "name": "Example Site 1",
72
72
  "url": "https://example.com"
73
73
  },
74
74
  {
75
- "id": 2,
75
+ "id": "2",
76
76
  "name": "Example Site 2",
77
77
  "url": "https://example2.com"
78
78
  }
@@ -87,12 +87,12 @@
87
87
  "rows": [
88
88
  [
89
89
  {
90
- "id": 1,
90
+ "id": "1",
91
91
  "name": "Example Site 1",
92
92
  "url": "https://example.com"
93
93
  },
94
94
  {
95
- "id": 2,
95
+ "id": "2",
96
96
  "name": "Example Site 2",
97
97
  "url": "https://example2.com"
98
98
  }
@@ -165,7 +165,7 @@
165
165
  },
166
166
  "/hosting/{hosting_id}/sites": {
167
167
  "get": {
168
- "operationId": "get_hosting_sites",
168
+ "operationId": "hosting_sites",
169
169
  "tags": ["sites"],
170
170
  "security": [{ "bearerAuth": [] }],
171
171
  "summary": "Get sites for a hosting id",
@@ -194,6 +194,47 @@
194
194
  }
195
195
  }
196
196
  }
197
+ },
198
+ "/hosting/{hosting_id}/sites/{site_id}": {
199
+ "get": {
200
+ "operationId": "hosting_site_by_id",
201
+ "tags": ["sites"],
202
+ "security": [{ "bearerAuth": [] }],
203
+ "summary": "For a hosting id, get a specific site by site id",
204
+ "description": "Obtain a specific site.",
205
+ "parameters": [
206
+ {
207
+ "name": "hosting_id",
208
+ "in": "path",
209
+ "required": true,
210
+ "schema": {
211
+ "type": "integer",
212
+ "description": "Specify the hosting id to get sites for."
213
+ }
214
+ },
215
+ {
216
+ "name": "site_id",
217
+ "in": "path",
218
+ "required": true,
219
+ "schema": {
220
+ "type": "string",
221
+ "description": "Specify the site id to get the site for."
222
+ }
223
+ }
224
+ ],
225
+ "responses": {
226
+ "200": {
227
+ "description": "OK",
228
+ "content": {
229
+ "application/json": {
230
+ "schema": {
231
+ "$ref": "#/components/schemas/Site"
232
+ }
233
+ }
234
+ }
235
+ }
236
+ }
237
+ }
197
238
  }
198
239
  },
199
240
  "servers": [
package/orval.config.js CHANGED
@@ -1,16 +1,45 @@
1
- module.exports = {
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
- // mode: "tags-split",
9
- target: "./src/huapi.ts",
10
- // schemas: "src/model",
11
- client: "react-query",
12
- mock: true,
13
- clean: true,
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.1.3",
4
- "main": "src/huapi.js",
3
+ "version": "1.2.2",
4
+ "main": "dist/huapi.js",
5
5
  "license": "MIT",
6
6
  "devDependencies": {
7
7
  "@faker-js/faker": "^6.1.2",
@@ -0,0 +1,17 @@
1
+ import { faker } from "@faker-js/faker";
2
+
3
+ export const sites = {
4
+ limit: 10,
5
+ n_pages: 1,
6
+ n_rows: 3,
7
+ page: 1,
8
+ rows: [...Array(3)].map((site, idx) => ({
9
+ id: idx,
10
+ name: faker.company.companyName(),
11
+ url: faker.internet.url(),
12
+ })),
13
+ };
14
+
15
+ export const site = sites.rows[0];
16
+
17
+ export const siteSso = `${sites.rows[0].url}/wp-login.php?ssotoken=1234567890`;
package/src/huapi.js DELETED
@@ -1,82 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
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
- exports.__esModule = true;
23
- exports.getHostingUAPIMSW = exports.getGetHostingSitesMock = exports.getSiteSsoMock = exports.useGetHostingSites = exports.getGetHostingSitesQueryKey = exports.getHostingSites = exports.useSiteSso = exports.siteSso = void 0;
24
- /**
25
- * Generated by orval v6.7.1 🍺
26
- * Do not edit manually.
27
- * Hosting UAPI
28
- * Hosting UAPI
29
- * OpenAPI spec version: 0.1.0
30
- */
31
- var axios_1 = require("axios");
32
- var react_query_1 = require("react-query");
33
- var msw_1 = require("msw");
34
- var faker_1 = require("@faker-js/faker");
35
- /**
36
- * TODO
37
- * @summary Get SSO token
38
- */
39
- var siteSso = function (siteId, options) {
40
- return axios_1["default"].post("/sites/".concat(siteId, "/sso"), undefined, options);
41
- };
42
- exports.siteSso = siteSso;
43
- var useSiteSso = function (options) {
44
- var _a = options || {}, mutationOptions = _a.mutation, axiosOptions = _a.axios;
45
- var mutationFn = function (props) {
46
- var siteId = (props || {}).siteId;
47
- return (0, exports.siteSso)(siteId, axiosOptions);
48
- };
49
- return (0, react_query_1.useMutation)(mutationFn, mutationOptions);
50
- };
51
- exports.useSiteSso = useSiteSso;
52
- /**
53
- * Obtain a list of sites.
54
- * @summary Get sites for a hosting id
55
- */
56
- var getHostingSites = function (hostingId, options) {
57
- return axios_1["default"].get("/hosting/".concat(hostingId, "/sites"), options);
58
- };
59
- exports.getHostingSites = getHostingSites;
60
- var getGetHostingSitesQueryKey = function (hostingId) { return ["/hosting/".concat(hostingId, "/sites")]; };
61
- exports.getGetHostingSitesQueryKey = getGetHostingSitesQueryKey;
62
- var useGetHostingSites = function (hostingId, options) {
63
- var _a;
64
- 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.getGetHostingSitesQueryKey)(hostingId);
66
- var queryFn = function () { return (0, exports.getHostingSites)(hostingId, axiosOptions); };
67
- var query = (0, react_query_1.useQuery)(queryKey, queryFn, __assign({ enabled: !!(hostingId) }, queryOptions));
68
- return __assign({ queryKey: queryKey }, query);
69
- };
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.datatype.number(), n_pages: faker_1.faker.datatype.number(), n_rows: faker_1.faker.datatype.number(), page: faker_1.faker.datatype.number(), rows: __spreadArray([], Array(faker_1.faker.datatype.number({ min: 1, max: 10 })), true).map(function () { return ({ id: faker_1.faker.datatype.number(), name: faker_1.faker.random.word(), url: faker_1.faker.random.word() }); }) }); };
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,169 +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: number;
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
-
152
- export const getSiteSsoMock = () => ({sso: faker.random.word()})
153
-
154
- 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.datatype.number(), name: faker.random.word(), url: faker.random.word()}))})
155
-
156
- export const getHostingUAPIMSW = () => [
157
- rest.post('*/sites/:siteid/sso', (_req, res, ctx) => {
158
- return res(
159
- ctx.delay(1000),
160
- ctx.status(200, 'Mocked status'),
161
- ctx.json(getSiteSsoMock()),
162
- )
163
- }),rest.get('*/hosting/:hostingid/sites', (_req, res, ctx) => {
164
- return res(
165
- ctx.delay(1000),
166
- ctx.status(200, 'Mocked status'),
167
- ctx.json(getGetHostingSitesMock()),
168
- )
169
- }),]