@newfold/huapi-js 1.0.3 → 1.2.0

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 ADDED
@@ -0,0 +1,32 @@
1
+ # @newfold/huapi-js
2
+
3
+ > A JavaScript Client Library for HUAPI
4
+
5
+ ## Installation
6
+
7
+ TODO
8
+
9
+ ## Usage
10
+
11
+ ### React Hooks
12
+
13
+ ```js
14
+ import React from "react";
15
+
16
+ import { useGetHostingSites } from "@newfold/huapi-js";
17
+
18
+ const MyComponent = () => {
19
+ const hostingId = "2";
20
+ const { isLoading, data } = useGetHostingSites(hostingId);
21
+
22
+ if (isLoading) return <h1>Loading...</h1>;
23
+
24
+ return (
25
+ <div>
26
+ {data?.data?.rows?.map((site) => {
27
+ <div key={site.id}>{site.name}</div>;
28
+ })}
29
+ </div>
30
+ );
31
+ };
32
+ ```
package/openapi.json CHANGED
@@ -1,7 +1,122 @@
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": {
15
+ "type": "string",
16
+ "description": "TODO",
17
+ "example": "1"
18
+ },
19
+ "name": {
20
+ "type": "string",
21
+ "description": "TODO",
22
+ "example": "Example Site 1"
23
+ },
24
+ "url": {
25
+ "type": "string",
26
+ "description": "TODO",
27
+ "example": "https://example.com"
28
+ }
29
+ },
30
+ "example": {
31
+ "id": 1,
32
+ "name": "Example Site 1",
33
+ "url": "https://example.com"
34
+ },
35
+ "required": ["id", "name", "url"]
36
+ },
37
+ "SiteList": {
38
+ "description": "List of sites",
39
+ "type": "object",
40
+ "properties": {
41
+ "limit": {
42
+ "type": "integer",
43
+ "description": "Max number of sites included in response",
44
+ "example": 10
45
+ },
46
+ "n_pages": {
47
+ "type": "integer",
48
+ "description": "TODO",
49
+ "example": 1
50
+ },
51
+ "n_rows": {
52
+ "type": "integer",
53
+ "description": "TODO",
54
+ "example": 1
55
+ },
56
+ "page": {
57
+ "type": "integer",
58
+ "description": "TODO",
59
+ "example": 1
60
+ },
61
+ "rows": {
62
+ "type": "array",
63
+ "description": "TODO",
64
+ "items": {
65
+ "type": "array",
66
+ "$ref": "#/components/schemas/Site"
67
+ },
68
+ "example": [
69
+ {
70
+ "id": "1",
71
+ "name": "Example Site 1",
72
+ "url": "https://example.com"
73
+ },
74
+ {
75
+ "id": "2",
76
+ "name": "Example Site 2",
77
+ "url": "https://example2.com"
78
+ }
79
+ ]
80
+ }
81
+ },
82
+ "example": {
83
+ "limit": 10,
84
+ "n_pages": 1,
85
+ "n_rows": 1,
86
+ "page": 1,
87
+ "rows": [
88
+ [
89
+ {
90
+ "id": "1",
91
+ "name": "Example Site 1",
92
+ "url": "https://example.com"
93
+ },
94
+ {
95
+ "id": "2",
96
+ "name": "Example Site 2",
97
+ "url": "https://example2.com"
98
+ }
99
+ ]
100
+ ]
101
+ },
102
+ "required": ["limit", "n_pages", "n_rows", "page", "rows"]
103
+ },
104
+ "SiteSso": {
105
+ "description": "SSO token or login URL",
106
+ "type": "object",
107
+ "properties": {
108
+ "sso": {
109
+ "type": "string",
110
+ "example": "$randomUrl",
111
+ "description": "TODO"
112
+ }
113
+ },
114
+ "example": {
115
+ "sso": "$randomUrl"
116
+ },
117
+ "required": ["sso"]
118
+ }
119
+ },
5
120
  "securitySchemes": {
6
121
  "bearerAuth": {
7
122
  "type": "http",
@@ -13,15 +128,25 @@
13
128
  "paths": {
14
129
  "/sites/{site_id}/sso": {
15
130
  "post": {
16
- "security": [{ "bearerAuth": [] }],
17
- "summary": "site_sso",
18
- "description": "Return an SSO token or login URL for this site (if supported).",
131
+ "summary": "Get SSO token",
132
+ "operationId": "site_sso",
133
+ "description": "TODO",
134
+ "tags": ["sites"],
135
+ "security": [
136
+ {
137
+ "bearerAuth": []
138
+ }
139
+ ],
19
140
  "parameters": [
20
141
  {
21
142
  "name": "site_id",
143
+ "description": "Specify the site id to get the SSO token for.",
22
144
  "in": "path",
23
145
  "required": true,
24
- "schema": { "type": "integer" }
146
+ "schema": {
147
+ "type": "integer",
148
+ "description": "Specify the site id to get the SSO token for."
149
+ }
25
150
  }
26
151
  ],
27
152
  "responses": {
@@ -30,11 +155,7 @@
30
155
  "content": {
31
156
  "application/json": {
32
157
  "schema": {
33
- "type": "object",
34
- "properties": {
35
- "sso": { "type": "string", "example": "$randomUrl" }
36
- },
37
- "required": ["sso"]
158
+ "$ref": "#/components/schemas/SiteSso"
38
159
  }
39
160
  }
40
161
  }
@@ -44,15 +165,20 @@
44
165
  },
45
166
  "/hosting/{hosting_id}/sites": {
46
167
  "get": {
168
+ "operationId": "get_hosting_sites",
169
+ "tags": ["sites"],
47
170
  "security": [{ "bearerAuth": [] }],
48
- "summary": "site_list",
171
+ "summary": "Get sites for a hosting id",
49
172
  "description": "Obtain a list of sites.",
50
173
  "parameters": [
51
174
  {
52
175
  "name": "hosting_id",
53
176
  "in": "path",
54
177
  "required": true,
55
- "schema": { "type": "integer" }
178
+ "schema": {
179
+ "type": "integer",
180
+ "description": "Specify the hosting id to get sites for."
181
+ }
56
182
  }
57
183
  ],
58
184
  "responses": {
@@ -61,32 +187,64 @@
61
187
  "content": {
62
188
  "application/json": {
63
189
  "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
- }
81
- }
82
- },
83
- "required": ["limit", "n_pages", "n_rows", "page", "rows"]
190
+ "$ref": "#/components/schemas/SiteList"
84
191
  }
85
192
  }
86
193
  }
87
194
  }
88
195
  }
89
196
  }
197
+ },
198
+ "/hosting/{hosting_id}/sites/{site_id}": {
199
+ "get": {
200
+ "operationId": "get_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
+ }
238
+ }
239
+ },
240
+ "servers": [
241
+ {
242
+ "url": "https://api.example.com/v1",
243
+ "description": "Production server (uses live data)"
244
+ },
245
+ {
246
+ "url": "https://sandbox-api.example.com:8443/v1",
247
+ "description": "Sandbox server (uses test data)"
90
248
  }
91
- }
249
+ ]
92
250
  }
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.2.0",
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
- "react": "^18.0.0",
17
- "react-query": "^3.0.0"
16
+ "@faker-js/faker": "^6.1.2",
17
+ "axios": "^0.26.1",
18
+ "msw": "^0.39.2",
19
+ "orval": "^6.7.1",
20
+ "react": "^17.0.2",
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.getGetHostingSiteByIdMock = exports.getGetHostingSitesMock = exports.getSiteSsoMock = exports.useGetHostingSiteById = exports.getGetHostingSiteByIdQueryKey = exports.getHostingSiteById = 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,73 @@ 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
+ /**
72
+ * Obtain a specific site.
73
+ * @summary For a hosting id, get a specific site by site id
74
+ */
75
+ var getHostingSiteById = function (hostingId, siteId, options) {
76
+ return axios_1["default"].get("/hosting/".concat(hostingId, "/sites/").concat(siteId), options);
77
+ };
78
+ exports.getHostingSiteById = getHostingSiteById;
79
+ var getGetHostingSiteByIdQueryKey = function (hostingId, siteId) { return ["/hosting/".concat(hostingId, "/sites/").concat(siteId)]; };
80
+ exports.getGetHostingSiteByIdQueryKey = getGetHostingSiteByIdQueryKey;
81
+ var useGetHostingSiteById = function (hostingId, siteId, options) {
82
+ var _a;
83
+ 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.getGetHostingSiteByIdQueryKey)(hostingId, siteId);
85
+ var queryFn = function () { return (0, exports.getHostingSiteById)(hostingId, siteId, axiosOptions); };
86
+ var query = (0, react_query_1.useQuery)(queryKey, queryFn, __assign({ enabled: !!(hostingId && siteId) }, queryOptions));
87
+ return __assign({ queryKey: queryKey }, query);
88
+ };
89
+ exports.useGetHostingSiteById = useGetHostingSiteById;
90
+ var getSiteSsoMock = function () { return ({ sso: faker_1.faker.random.word() }); };
91
+ exports.getSiteSsoMock = getSiteSsoMock;
92
+ 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.random.word(), name: faker_1.faker.random.word(), url: faker_1.faker.random.word() }); }) }); };
93
+ exports.getGetHostingSitesMock = getGetHostingSitesMock;
94
+ var getGetHostingSiteByIdMock = function () { return ({ id: faker_1.faker.random.word(), name: faker_1.faker.random.word(), url: faker_1.faker.random.word() }); };
95
+ exports.getGetHostingSiteByIdMock = getGetHostingSiteByIdMock;
74
96
  var getHostingUAPIMSW = function () { return [
75
97
  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)()));
98
+ return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getSiteSsoMock)()));
77
99
  }), 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)()));
100
+ return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getGetHostingSitesMock)()));
101
+ }), 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.getGetHostingSiteByIdMock)()));
79
103
  }),
80
104
  ]; };
81
105
  exports.getHostingUAPIMSW = getHostingUAPIMSW;
package/src/huapi.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  * Generated by orval v6.7.1 🍺
3
3
  * Do not edit manually.
4
4
  * Hosting UAPI
5
+ * Hosting UAPI
5
6
  * OpenAPI spec version: 0.1.0
6
7
  */
7
8
  import axios,{
@@ -25,23 +26,41 @@ import {
25
26
  import {
26
27
  faker
27
28
  } from '@faker-js/faker'
28
- export type GetHostingHostingIdSites200RowsItem = {
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 */
29
42
  id: string;
43
+ /** TODO */
30
44
  name: string;
45
+ /** TODO */
31
46
  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
- };
47
+ }
41
48
 
42
- export type PostSitesSiteIdSso200 = {
43
- sso: string;
44
- };
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
+ }
45
64
 
46
65
 
47
66
 
@@ -52,12 +71,12 @@ T extends (...args: any) => Promise<any>
52
71
 
53
72
 
54
73
  /**
55
- * Return an SSO token or login URL for this site (if supported).
56
- * @summary site_sso
74
+ * TODO
75
+ * @summary Get SSO token
57
76
  */
58
- export const postSitesSiteIdSso = (
77
+ export const siteSso = (
59
78
  siteId: number, options?: AxiosRequestConfig
60
- ): Promise<AxiosResponse<PostSitesSiteIdSso200>> => {
79
+ ): Promise<AxiosResponse<SiteSso>> => {
61
80
  return axios.post(
62
81
  `/sites/${siteId}/sso`,undefined,options
63
82
  );
@@ -65,61 +84,105 @@ export const postSitesSiteIdSso = (
65
84
 
66
85
 
67
86
 
68
- export type PostSitesSiteIdSsoMutationResult = NonNullable<AsyncReturnType<typeof postSitesSiteIdSso>>
87
+ export type SiteSsoMutationResult = NonNullable<AsyncReturnType<typeof siteSso>>
69
88
 
70
- export type PostSitesSiteIdSsoMutationError = AxiosError<unknown>
89
+ export type SiteSsoMutationError = AxiosError<unknown>
71
90
 
72
- export const usePostSitesSiteIdSso = <TError = AxiosError<unknown>,
91
+ export const useSiteSso = <TError = AxiosError<unknown>,
73
92
 
74
- TContext = unknown>(options?: { mutation?:UseMutationOptions<AsyncReturnType<typeof postSitesSiteIdSso>, TError,{siteId: number}, TContext>, axios?: AxiosRequestConfig}
93
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<AsyncReturnType<typeof siteSso>, TError,{siteId: number}, TContext>, axios?: AxiosRequestConfig}
75
94
  ) => {
76
95
  const {mutation: mutationOptions, axios: axiosOptions} = options || {}
77
96
 
78
97
 
79
98
 
80
99
 
81
- const mutationFn: MutationFunction<AsyncReturnType<typeof postSitesSiteIdSso>, {siteId: number}> = (props) => {
100
+ const mutationFn: MutationFunction<AsyncReturnType<typeof siteSso>, {siteId: number}> = (props) => {
82
101
  const {siteId} = props || {};
83
102
 
84
- return postSitesSiteIdSso(siteId,axiosOptions)
103
+ return siteSso(siteId,axiosOptions)
85
104
  }
86
105
 
87
- return useMutation<AsyncReturnType<typeof postSitesSiteIdSso>, TError, {siteId: number}, TContext>(mutationFn, mutationOptions)
106
+ return useMutation<AsyncReturnType<typeof siteSso>, TError, {siteId: number}, TContext>(mutationFn, mutationOptions)
88
107
  }
89
108
 
90
109
  /**
91
110
  * Obtain a list of sites.
92
- * @summary site_list
111
+ * @summary Get sites for a hosting id
93
112
  */
94
- export const getHostingHostingIdSites = (
113
+ export const getHostingSites = (
95
114
  hostingId: number, options?: AxiosRequestConfig
96
- ): Promise<AxiosResponse<GetHostingHostingIdSites200>> => {
115
+ ): Promise<AxiosResponse<SiteList>> => {
97
116
  return axios.get(
98
117
  `/hosting/${hostingId}/sites`,options
99
118
  );
100
119
  }
101
120
 
102
121
 
103
- export const getGetHostingHostingIdSitesQueryKey = (hostingId: number,) => [`/hosting/${hostingId}/sites`];
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}`];
104
166
 
105
167
 
106
- export type GetHostingHostingIdSitesQueryResult = NonNullable<AsyncReturnType<typeof getHostingHostingIdSites>>
107
- export type GetHostingHostingIdSitesQueryError = AxiosError<unknown>
168
+ export type GetHostingSiteByIdQueryResult = NonNullable<AsyncReturnType<typeof getHostingSiteById>>
169
+ export type GetHostingSiteByIdQueryError = AxiosError<unknown>
108
170
 
109
- export const useGetHostingHostingIdSites = <TData = AsyncReturnType<typeof getHostingHostingIdSites>, TError = AxiosError<unknown>>(
110
- hostingId: number, options?: { query?:UseQueryOptions<AsyncReturnType<typeof getHostingHostingIdSites>, TError, TData>, axios?: AxiosRequestConfig}
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}
111
174
 
112
175
  ): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
113
176
 
114
177
  const {query: queryOptions, axios: axiosOptions} = options || {}
115
178
 
116
- const queryKey = queryOptions?.queryKey ?? getGetHostingHostingIdSitesQueryKey(hostingId);
179
+ const queryKey = queryOptions?.queryKey ?? getGetHostingSiteByIdQueryKey(hostingId,siteId);
117
180
 
118
181
 
119
182
 
120
- const queryFn: QueryFunction<AsyncReturnType<typeof getHostingHostingIdSites>> = () => getHostingHostingIdSites(hostingId, axiosOptions);
183
+ const queryFn: QueryFunction<AsyncReturnType<typeof getHostingSiteById>> = () => getHostingSiteById(hostingId,siteId, axiosOptions);
121
184
 
122
- const query = useQuery<AsyncReturnType<typeof getHostingHostingIdSites>, TError, TData>(queryKey, queryFn, {enabled: !!(hostingId), ...queryOptions})
185
+ const query = useQuery<AsyncReturnType<typeof getHostingSiteById>, TError, TData>(queryKey, queryFn, {enabled: !!(hostingId && siteId), ...queryOptions})
123
186
 
124
187
  return {
125
188
  queryKey,
@@ -130,21 +193,29 @@ export const useGetHostingHostingIdSites = <TData = AsyncReturnType<typeof getHo
130
193
 
131
194
 
132
195
 
133
- export const getPostSitesSiteIdSsoMock = () => ({sso: faker.random.word()})
196
+ export const getSiteSsoMock = () => ({sso: faker.random.word()})
134
197
 
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()}))})
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()})
136
201
 
137
202
  export const getHostingUAPIMSW = () => [
138
203
  rest.post('*/sites/:siteid/sso', (_req, res, ctx) => {
139
204
  return res(
140
205
  ctx.delay(1000),
141
206
  ctx.status(200, 'Mocked status'),
142
- ctx.json(getPostSitesSiteIdSsoMock()),
207
+ ctx.json(getSiteSsoMock()),
143
208
  )
144
209
  }),rest.get('*/hosting/:hostingid/sites', (_req, res, ctx) => {
145
210
  return res(
146
211
  ctx.delay(1000),
147
212
  ctx.status(200, 'Mocked status'),
148
- ctx.json(getGetHostingHostingIdSitesMock()),
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()),
149
220
  )
150
221
  }),]