@newfold/huapi-js 1.0.3 → 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 CHANGED
@@ -1,7 +1,53 @@
1
1
  {
2
2
  "openapi": "3.0.0",
3
- "info": { "title": "Hosting UAPI", "version": "0.1.0" },
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": { "type": "integer" }
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
- "type": "object",
34
- "properties": {
35
- "sso": { "type": "string", "example": "$randomUrl" }
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": "site_list",
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": { "type": "integer" }
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
- "type": "object",
65
- "properties": {
66
- "limit": { "type": "string" },
67
- "n_pages": { "type": "string" },
68
- "n_rows": { "type": "string" },
69
- "page": { "type": "string" },
70
- "rows": {
71
- "type": "array",
72
- "items": {
73
- "type": "object",
74
- "properties": {
75
- "id": { "type": "string" },
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
@@ -10,6 +10,7 @@ module.exports = {
10
10
  // schemas: "src/model",
11
11
  client: "react-query",
12
12
  mock: true,
13
+ clean: true,
13
14
  },
14
15
  },
15
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newfold/huapi-js",
3
- "version": "1.0.3",
3
+ "version": "1.1.1",
4
4
  "main": "src/huapi.js",
5
5
  "license": "MIT",
6
6
  "devDependencies": {
@@ -13,13 +13,16 @@
13
13
  "typescript": "^4.6.3"
14
14
  },
15
15
  "peerDependencies": {
16
+ "@faker-js/faker": "^6.1.2",
17
+ "axios": "^0.26.1",
18
+ "msw": "^0.39.2",
19
+ "orval": "^6.7.1",
16
20
  "react": "^18.0.0",
17
- "react-query": "^3.0.0"
21
+ "react-query": "^3.34.19"
18
22
  },
19
23
  "scripts": {
20
- "clean": "rm -rf ./src",
21
24
  "orval": "orval",
22
25
  "tsToJs": "npx tsc ./src/*",
23
- "build": "yarn clean && yarn orval && yarn tsToJs"
26
+ "build": "yarn orval && yarn tsToJs"
24
27
  }
25
28
  }
package/src/huapi.js CHANGED
@@ -20,11 +20,12 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
20
20
  return to.concat(ar || Array.prototype.slice.call(from));
21
21
  };
22
22
  exports.__esModule = true;
23
- exports.getHostingUAPIMSW = exports.getGetHostingHostingIdSitesMock = exports.getPostSitesSiteIdSsoMock = exports.useGetHostingHostingIdSites = exports.getGetHostingHostingIdSitesQueryKey = exports.getHostingHostingIdSites = exports.usePostSitesSiteIdSso = exports.postSitesSiteIdSso = void 0;
23
+ exports.getHostingUAPIMSW = exports.getGetHostingSitesMock = exports.getSiteSsoMock = exports.useGetHostingSites = exports.getGetHostingSitesQueryKey = exports.getHostingSites = exports.useSiteSso = exports.siteSso = void 0;
24
24
  /**
25
25
  * Generated by orval v6.7.1 🍺
26
26
  * Do not edit manually.
27
27
  * Hosting UAPI
28
+ * Hosting UAPI
28
29
  * OpenAPI spec version: 0.1.0
29
30
  */
30
31
  var axios_1 = require("axios");
@@ -32,50 +33,50 @@ var react_query_1 = require("react-query");
32
33
  var msw_1 = require("msw");
33
34
  var faker_1 = require("@faker-js/faker");
34
35
  /**
35
- * Return an SSO token or login URL for this site (if supported).
36
- * @summary site_sso
36
+ * TODO
37
+ * @summary Get SSO token
37
38
  */
38
- var postSitesSiteIdSso = function (siteId, options) {
39
+ var siteSso = function (siteId, options) {
39
40
  return axios_1["default"].post("/sites/".concat(siteId, "/sso"), undefined, options);
40
41
  };
41
- exports.postSitesSiteIdSso = postSitesSiteIdSso;
42
- var usePostSitesSiteIdSso = function (options) {
42
+ exports.siteSso = siteSso;
43
+ var useSiteSso = function (options) {
43
44
  var _a = options || {}, mutationOptions = _a.mutation, axiosOptions = _a.axios;
44
45
  var mutationFn = function (props) {
45
46
  var siteId = (props || {}).siteId;
46
- return (0, exports.postSitesSiteIdSso)(siteId, axiosOptions);
47
+ return (0, exports.siteSso)(siteId, axiosOptions);
47
48
  };
48
49
  return (0, react_query_1.useMutation)(mutationFn, mutationOptions);
49
50
  };
50
- exports.usePostSitesSiteIdSso = usePostSitesSiteIdSso;
51
+ exports.useSiteSso = useSiteSso;
51
52
  /**
52
53
  * Obtain a list of sites.
53
- * @summary site_list
54
+ * @summary Get sites for a hosting id
54
55
  */
55
- var getHostingHostingIdSites = function (hostingId, options) {
56
+ var getHostingSites = function (hostingId, options) {
56
57
  return axios_1["default"].get("/hosting/".concat(hostingId, "/sites"), options);
57
58
  };
58
- exports.getHostingHostingIdSites = getHostingHostingIdSites;
59
- var getGetHostingHostingIdSitesQueryKey = function (hostingId) { return ["/hosting/".concat(hostingId, "/sites")]; };
60
- exports.getGetHostingHostingIdSitesQueryKey = getGetHostingHostingIdSitesQueryKey;
61
- var useGetHostingHostingIdSites = function (hostingId, options) {
59
+ exports.getHostingSites = getHostingSites;
60
+ var getGetHostingSitesQueryKey = function (hostingId) { return ["/hosting/".concat(hostingId, "/sites")]; };
61
+ exports.getGetHostingSitesQueryKey = getGetHostingSitesQueryKey;
62
+ var useGetHostingSites = function (hostingId, options) {
62
63
  var _a;
63
64
  var _b = options || {}, queryOptions = _b.query, axiosOptions = _b.axios;
64
- var queryKey = (_a = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.queryKey) !== null && _a !== void 0 ? _a : (0, exports.getGetHostingHostingIdSitesQueryKey)(hostingId);
65
- var queryFn = function () { return (0, exports.getHostingHostingIdSites)(hostingId, axiosOptions); };
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); };
66
67
  var query = (0, react_query_1.useQuery)(queryKey, queryFn, __assign({ enabled: !!(hostingId) }, queryOptions));
67
68
  return __assign({ queryKey: queryKey }, query);
68
69
  };
69
- exports.useGetHostingHostingIdSites = useGetHostingHostingIdSites;
70
- var getPostSitesSiteIdSsoMock = function () { return ({ sso: faker_1.faker.random.word() }); };
71
- exports.getPostSitesSiteIdSsoMock = getPostSitesSiteIdSsoMock;
72
- var getGetHostingHostingIdSitesMock = function () { return ({ limit: faker_1.faker.random.word(), n_pages: faker_1.faker.random.word(), n_rows: faker_1.faker.random.word(), page: faker_1.faker.random.word(), rows: __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() }); }) }); };
73
- exports.getGetHostingHostingIdSitesMock = getGetHostingHostingIdSitesMock;
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;
74
75
  var getHostingUAPIMSW = function () { return [
75
76
  msw_1.rest.post('*/sites/:siteid/sso', function (_req, res, ctx) {
76
- return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getPostSitesSiteIdSsoMock)()));
77
+ return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getSiteSsoMock)()));
77
78
  }), msw_1.rest.get('*/hosting/:hostingid/sites', function (_req, res, ctx) {
78
- return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getGetHostingHostingIdSitesMock)()));
79
+ return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getGetHostingSitesMock)()));
79
80
  }),
80
81
  ]; };
81
82
  exports.getHostingUAPIMSW = getHostingUAPIMSW;
package/src/huapi.ts DELETED
@@ -1,150 +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
- import {
23
- rest
24
- } from 'msw'
25
- import {
26
- faker
27
- } from '@faker-js/faker'
28
- export type GetHostingHostingIdSites200RowsItem = {
29
- id: string;
30
- name: string;
31
- url: string;
32
- };
33
-
34
- export type GetHostingHostingIdSites200 = {
35
- limit: string;
36
- n_pages: string;
37
- n_rows: string;
38
- page: string;
39
- rows: GetHostingHostingIdSites200RowsItem[];
40
- };
41
-
42
- export type PostSitesSiteIdSso200 = {
43
- sso: string;
44
- };
45
-
46
-
47
-
48
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
- type AsyncReturnType<
50
- T extends (...args: any) => Promise<any>
51
- > = T extends (...args: any) => Promise<infer R> ? R : any;
52
-
53
-
54
- /**
55
- * Return an SSO token or login URL for this site (if supported).
56
- * @summary site_sso
57
- */
58
- export const postSitesSiteIdSso = (
59
- siteId: number, options?: AxiosRequestConfig
60
- ): Promise<AxiosResponse<PostSitesSiteIdSso200>> => {
61
- return axios.post(
62
- `/sites/${siteId}/sso`,undefined,options
63
- );
64
- }
65
-
66
-
67
-
68
- export type PostSitesSiteIdSsoMutationResult = NonNullable<AsyncReturnType<typeof postSitesSiteIdSso>>
69
-
70
- export type PostSitesSiteIdSsoMutationError = AxiosError<unknown>
71
-
72
- export const usePostSitesSiteIdSso = <TError = AxiosError<unknown>,
73
-
74
- TContext = unknown>(options?: { mutation?:UseMutationOptions<AsyncReturnType<typeof postSitesSiteIdSso>, TError,{siteId: number}, TContext>, axios?: AxiosRequestConfig}
75
- ) => {
76
- const {mutation: mutationOptions, axios: axiosOptions} = options || {}
77
-
78
-
79
-
80
-
81
- const mutationFn: MutationFunction<AsyncReturnType<typeof postSitesSiteIdSso>, {siteId: number}> = (props) => {
82
- const {siteId} = props || {};
83
-
84
- return postSitesSiteIdSso(siteId,axiosOptions)
85
- }
86
-
87
- return useMutation<AsyncReturnType<typeof postSitesSiteIdSso>, TError, {siteId: number}, TContext>(mutationFn, mutationOptions)
88
- }
89
-
90
- /**
91
- * Obtain a list of sites.
92
- * @summary site_list
93
- */
94
- export const getHostingHostingIdSites = (
95
- hostingId: number, options?: AxiosRequestConfig
96
- ): Promise<AxiosResponse<GetHostingHostingIdSites200>> => {
97
- return axios.get(
98
- `/hosting/${hostingId}/sites`,options
99
- );
100
- }
101
-
102
-
103
- export const getGetHostingHostingIdSitesQueryKey = (hostingId: number,) => [`/hosting/${hostingId}/sites`];
104
-
105
-
106
- export type GetHostingHostingIdSitesQueryResult = NonNullable<AsyncReturnType<typeof getHostingHostingIdSites>>
107
- export type GetHostingHostingIdSitesQueryError = AxiosError<unknown>
108
-
109
- export const useGetHostingHostingIdSites = <TData = AsyncReturnType<typeof getHostingHostingIdSites>, TError = AxiosError<unknown>>(
110
- hostingId: number, options?: { query?:UseQueryOptions<AsyncReturnType<typeof getHostingHostingIdSites>, TError, TData>, axios?: AxiosRequestConfig}
111
-
112
- ): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
113
-
114
- const {query: queryOptions, axios: axiosOptions} = options || {}
115
-
116
- const queryKey = queryOptions?.queryKey ?? getGetHostingHostingIdSitesQueryKey(hostingId);
117
-
118
-
119
-
120
- const queryFn: QueryFunction<AsyncReturnType<typeof getHostingHostingIdSites>> = () => getHostingHostingIdSites(hostingId, axiosOptions);
121
-
122
- const query = useQuery<AsyncReturnType<typeof getHostingHostingIdSites>, TError, TData>(queryKey, queryFn, {enabled: !!(hostingId), ...queryOptions})
123
-
124
- return {
125
- queryKey,
126
- ...query
127
- }
128
- }
129
-
130
-
131
-
132
-
133
- export const getPostSitesSiteIdSsoMock = () => ({sso: faker.random.word()})
134
-
135
- export const getGetHostingHostingIdSitesMock = () => ({limit: faker.random.word(), n_pages: faker.random.word(), n_rows: faker.random.word(), page: faker.random.word(), rows: [...Array(faker.datatype.number({min: 1, max: 10}))].map(() => ({id: faker.random.word(), name: faker.random.word(), url: faker.random.word()}))})
136
-
137
- export const getHostingUAPIMSW = () => [
138
- rest.post('*/sites/:siteid/sso', (_req, res, ctx) => {
139
- return res(
140
- ctx.delay(1000),
141
- ctx.status(200, 'Mocked status'),
142
- ctx.json(getPostSitesSiteIdSsoMock()),
143
- )
144
- }),rest.get('*/hosting/:hostingid/sites', (_req, res, ctx) => {
145
- return res(
146
- ctx.delay(1000),
147
- ctx.status(200, 'Mocked status'),
148
- ctx.json(getGetHostingHostingIdSitesMock()),
149
- )
150
- }),]