@newfold/huapi-js 1.2.1 → 1.2.4

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
 
@@ -77,11 +77,11 @@ var useHostingSiteById = function (hostingId, siteId, options) {
77
77
  return __assign({ queryKey: queryKey }, query);
78
78
  };
79
79
  exports.useHostingSiteById = useHostingSiteById;
80
- var getSiteSsoMock = function () { return ('https://parched-robe.name/wp-login.php?ssotoken=1234567890'); };
80
+ var getSiteSsoMock = function () { return ('https://bobtheblog.com/wp-login.php?ssotoken=1234567890'); };
81
81
  exports.getSiteSsoMock = getSiteSsoMock;
82
- var getHostingSitesMock = function () { return ({ limit: 10, n_pages: 1, n_rows: 3, page: 1, rows: [{ id: 0, name: 'Murazik - Weber', url: 'https://parched-robe.name' }, { id: 1, name: 'Gutmann - Bahringer', url: 'http://kindhearted-boogeyman.com' }, { id: 2, name: 'Volkman - Stiedemann', url: 'https://coarse-vendor.com' }] }); };
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
83
  exports.getHostingSitesMock = getHostingSitesMock;
84
- var getHostingSiteByIdMock = function () { return ({ id: 0, name: 'Murazik - Weber', url: 'https://parched-robe.name' }); };
84
+ var getHostingSiteByIdMock = function () { return ({ id: '1', name: 'Bob the Blog', url: 'https://bobtheblog.com' }); };
85
85
  exports.getHostingSiteByIdMock = getHostingSiteByIdMock;
86
86
  var getHostingUAPIMSW = function () { return [
87
87
  msw_1.rest.post('*/sites/:siteid/sso', function (_req, res, ctx) {
package/orval.config.js CHANGED
@@ -1,6 +1,7 @@
1
- import { faker } from "@faker-js/faker";
2
1
  import { defineConfig } from "orval";
3
2
 
3
+ import { sites, site, siteSso } from "./src/mocks/sites";
4
+
4
5
  const input = {
5
6
  target: "./openapi.json",
6
7
  validation: true,
@@ -8,36 +9,23 @@ const input = {
8
9
 
9
10
  const output = {
10
11
  // mode: "tags-split",
11
- target: "./src/huapi.ts",
12
- // schemas: "src/model",
12
+ target: "./dist/huapi.ts",
13
+ // schemas: "dist/model",
13
14
  client: "react-query",
14
15
  mock: true,
15
16
  clean: true,
16
17
  };
17
18
 
18
- const sites = {
19
- limit: 10,
20
- n_pages: 1,
21
- n_rows: 3,
22
- page: 1,
23
- rows: [...Array(3)].map((site, idx) => ({
24
- id: idx,
25
- name: faker.company.companyName(),
26
- url: faker.internet.url(),
27
- })),
28
- };
29
-
30
19
  export default defineConfig({
31
20
  huapi: {
32
21
  input,
33
22
  output: {
34
23
  ...output,
35
- target: "./src/huapi.ts",
36
24
  override: {
37
25
  operations: {
38
26
  site_sso: {
39
27
  mock: {
40
- data: `${sites.rows[0].url}/wp-login.php?ssotoken=1234567890`,
28
+ data: siteSso,
41
29
  },
42
30
  },
43
31
  hosting_sites: {
@@ -47,7 +35,7 @@ export default defineConfig({
47
35
  },
48
36
  hosting_site_by_id: {
49
37
  mock: {
50
- data: sites.rows[0],
38
+ data: site,
51
39
  },
52
40
  },
53
41
  },
package/package.json CHANGED
@@ -1,28 +1,26 @@
1
1
  {
2
2
  "name": "@newfold/huapi-js",
3
- "version": "1.2.1",
4
- "main": "src/huapi.js",
3
+ "version": "1.2.4",
4
+ "main": "dist/huapi.js",
5
5
  "license": "MIT",
6
- "devDependencies": {
6
+ "dependencies": {
7
7
  "@faker-js/faker": "^6.1.2",
8
8
  "axios": "^0.26.1",
9
9
  "msw": "^0.39.2",
10
+ "react-query": "^3.34.19"
11
+ },
12
+ "devDependencies": {
10
13
  "orval": "^6.7.1",
11
- "react": "^18.0.0",
12
- "react-query": "^3.34.19",
14
+ "react": "^17.0.0",
13
15
  "typescript": "^4.6.3"
14
16
  },
15
17
  "peerDependencies": {
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",
18
+ "react": "^17.0.0 || ^18.0.0",
21
19
  "react-query": "^3.34.19"
22
20
  },
23
21
  "scripts": {
24
22
  "orval": "orval",
25
- "tsToJs": "npx tsc ./src/*",
23
+ "tsToJs": "npx tsc ./dist/*",
26
24
  "build": "yarn orval && yarn tsToJs"
27
25
  }
28
26
  }
@@ -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,218 +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
- /**
27
- * SSO token or login URL
28
- */
29
- export interface SiteSso {
30
- /** TODO */
31
- sso: string;
32
- }
33
-
34
- /**
35
- * A site
36
- */
37
- export interface Site {
38
- /** TODO */
39
- id: string;
40
- /** TODO */
41
- name: string;
42
- /** TODO */
43
- url: string;
44
- }
45
-
46
- /**
47
- * List of sites
48
- */
49
- export interface SiteList {
50
- /** Max number of sites included in response */
51
- limit: number;
52
- /** TODO */
53
- n_pages: number;
54
- /** TODO */
55
- n_rows: number;
56
- /** TODO */
57
- page: number;
58
- /** TODO */
59
- rows: Site[];
60
- }
61
-
62
-
63
-
64
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
- type AsyncReturnType<
66
- T extends (...args: any) => Promise<any>
67
- > = T extends (...args: any) => Promise<infer R> ? R : any;
68
-
69
-
70
- /**
71
- * TODO
72
- * @summary Get SSO token
73
- */
74
- export const siteSso = (
75
- siteId: number, options?: AxiosRequestConfig
76
- ): Promise<AxiosResponse<SiteSso>> => {
77
- return axios.post(
78
- `/sites/${siteId}/sso`,undefined,options
79
- );
80
- }
81
-
82
-
83
-
84
- export type SiteSsoMutationResult = NonNullable<AsyncReturnType<typeof siteSso>>
85
-
86
- export type SiteSsoMutationError = AxiosError<unknown>
87
-
88
- export const useSiteSso = <TError = AxiosError<unknown>,
89
-
90
- TContext = unknown>(options?: { mutation?:UseMutationOptions<AsyncReturnType<typeof siteSso>, TError,{siteId: number}, TContext>, axios?: AxiosRequestConfig}
91
- ) => {
92
- const {mutation: mutationOptions, axios: axiosOptions} = options || {}
93
-
94
-
95
-
96
-
97
- const mutationFn: MutationFunction<AsyncReturnType<typeof siteSso>, {siteId: number}> = (props) => {
98
- const {siteId} = props || {};
99
-
100
- return siteSso(siteId,axiosOptions)
101
- }
102
-
103
- return useMutation<AsyncReturnType<typeof siteSso>, TError, {siteId: number}, TContext>(mutationFn, mutationOptions)
104
- }
105
-
106
- /**
107
- * Obtain a list of sites.
108
- * @summary Get sites for a hosting id
109
- */
110
- export const hostingSites = (
111
- hostingId: number, options?: AxiosRequestConfig
112
- ): Promise<AxiosResponse<SiteList>> => {
113
- return axios.get(
114
- `/hosting/${hostingId}/sites`,options
115
- );
116
- }
117
-
118
-
119
- export const getHostingSitesQueryKey = (hostingId: number,) => [`/hosting/${hostingId}/sites`];
120
-
121
-
122
- export type HostingSitesQueryResult = NonNullable<AsyncReturnType<typeof hostingSites>>
123
- export type HostingSitesQueryError = AxiosError<unknown>
124
-
125
- export const useHostingSites = <TData = AsyncReturnType<typeof hostingSites>, TError = AxiosError<unknown>>(
126
- hostingId: number, options?: { query?:UseQueryOptions<AsyncReturnType<typeof hostingSites>, TError, TData>, axios?: AxiosRequestConfig}
127
-
128
- ): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
129
-
130
- const {query: queryOptions, axios: axiosOptions} = options || {}
131
-
132
- const queryKey = queryOptions?.queryKey ?? getHostingSitesQueryKey(hostingId);
133
-
134
-
135
-
136
- const queryFn: QueryFunction<AsyncReturnType<typeof hostingSites>> = () => hostingSites(hostingId, axiosOptions);
137
-
138
- const query = useQuery<AsyncReturnType<typeof hostingSites>, TError, TData>(queryKey, queryFn, {enabled: !!(hostingId), ...queryOptions})
139
-
140
- return {
141
- queryKey,
142
- ...query
143
- }
144
- }
145
-
146
-
147
- /**
148
- * Obtain a specific site.
149
- * @summary For a hosting id, get a specific site by site id
150
- */
151
- export const hostingSiteById = (
152
- hostingId: number,
153
- siteId: string, options?: AxiosRequestConfig
154
- ): Promise<AxiosResponse<Site>> => {
155
- return axios.get(
156
- `/hosting/${hostingId}/sites/${siteId}`,options
157
- );
158
- }
159
-
160
-
161
- export const getHostingSiteByIdQueryKey = (hostingId: number,
162
- siteId: string,) => [`/hosting/${hostingId}/sites/${siteId}`];
163
-
164
-
165
- export type HostingSiteByIdQueryResult = NonNullable<AsyncReturnType<typeof hostingSiteById>>
166
- export type HostingSiteByIdQueryError = AxiosError<unknown>
167
-
168
- export const useHostingSiteById = <TData = AsyncReturnType<typeof hostingSiteById>, TError = AxiosError<unknown>>(
169
- hostingId: number,
170
- siteId: string, options?: { query?:UseQueryOptions<AsyncReturnType<typeof hostingSiteById>, TError, TData>, axios?: AxiosRequestConfig}
171
-
172
- ): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
173
-
174
- const {query: queryOptions, axios: axiosOptions} = options || {}
175
-
176
- const queryKey = queryOptions?.queryKey ?? getHostingSiteByIdQueryKey(hostingId,siteId);
177
-
178
-
179
-
180
- const queryFn: QueryFunction<AsyncReturnType<typeof hostingSiteById>> = () => hostingSiteById(hostingId,siteId, axiosOptions);
181
-
182
- const query = useQuery<AsyncReturnType<typeof hostingSiteById>, TError, TData>(queryKey, queryFn, {enabled: !!(hostingId && siteId), ...queryOptions})
183
-
184
- return {
185
- queryKey,
186
- ...query
187
- }
188
- }
189
-
190
-
191
-
192
-
193
- export const getSiteSsoMock = () => ('https://parched-robe.name/wp-login.php?ssotoken=1234567890')
194
-
195
- export const getHostingSitesMock = () => ({ limit: 10, n_pages: 1, n_rows: 3, page: 1, rows: [{ id: 0, name: 'Murazik - Weber', url: 'https://parched-robe.name', }, { id: 1, name: 'Gutmann - Bahringer', url: 'http://kindhearted-boogeyman.com', }, { id: 2, name: 'Volkman - Stiedemann', url: 'https://coarse-vendor.com', }], })
196
-
197
- export const getHostingSiteByIdMock = () => ({ id: 0, name: 'Murazik - Weber', url: 'https://parched-robe.name', })
198
-
199
- export const getHostingUAPIMSW = () => [
200
- rest.post('*/sites/:siteid/sso', (_req, res, ctx) => {
201
- return res(
202
- ctx.delay(1000),
203
- ctx.status(200, 'Mocked status'),
204
- ctx.json(getSiteSsoMock()),
205
- )
206
- }),rest.get('*/hosting/:hostingid/sites', (_req, res, ctx) => {
207
- return res(
208
- ctx.delay(1000),
209
- ctx.status(200, 'Mocked status'),
210
- ctx.json(getHostingSitesMock()),
211
- )
212
- }),rest.get('*/hosting/:hostingid/sites/:siteid', (_req, res, ctx) => {
213
- return res(
214
- ctx.delay(1000),
215
- ctx.status(200, 'Mocked status'),
216
- ctx.json(getHostingSiteByIdMock()),
217
- )
218
- }),]