@newfold/huapi-js 1.2.3 → 1.2.6
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 +0 -41
- package/orval.config.js +7 -30
- package/package.json +7 -9
- package/prettier.config.js +4 -0
- package/src/msw/handlers/index.js +5 -0
- package/src/msw/handlers/sites/data/sites.js +172 -0
- package/src/msw/handlers/sites/getHostingSitesHandler.js +24 -0
- package/src/msw/sites.js +153 -0
- package/dist/huapi.js +0 -95
- package/src/mocks/sites.js +0 -29
package/openapi.json
CHANGED
|
@@ -194,47 +194,6 @@
|
|
|
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
|
-
}
|
|
238
197
|
}
|
|
239
198
|
},
|
|
240
199
|
"servers": [
|
package/orval.config.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import { defineConfig } from
|
|
2
|
-
|
|
3
|
-
import { sites, site, siteSso } from "./src/mocks/sites";
|
|
1
|
+
import { defineConfig } from 'orval';
|
|
4
2
|
|
|
5
3
|
const input = {
|
|
6
|
-
target:
|
|
4
|
+
target: './openapi.json',
|
|
7
5
|
validation: true,
|
|
8
6
|
};
|
|
9
7
|
|
|
10
8
|
const output = {
|
|
11
|
-
|
|
12
|
-
target:
|
|
13
|
-
|
|
14
|
-
client:
|
|
9
|
+
mode: 'split',
|
|
10
|
+
target: './dist/huapi.ts',
|
|
11
|
+
schemas: './dist/models',
|
|
12
|
+
client: 'react-query',
|
|
15
13
|
mock: true,
|
|
16
14
|
clean: true,
|
|
17
15
|
};
|
|
@@ -19,27 +17,6 @@ const output = {
|
|
|
19
17
|
export default defineConfig({
|
|
20
18
|
huapi: {
|
|
21
19
|
input,
|
|
22
|
-
output
|
|
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
|
-
},
|
|
43
|
-
},
|
|
20
|
+
output,
|
|
44
21
|
},
|
|
45
22
|
});
|
package/package.json
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newfold/huapi-js",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"main": "dist/huapi.js",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"
|
|
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": "^
|
|
12
|
-
"react-query": "^3.34.19",
|
|
14
|
+
"react": "^17.0.0",
|
|
13
15
|
"typescript": "^4.6.3"
|
|
14
16
|
},
|
|
15
17
|
"peerDependencies": {
|
|
16
|
-
"
|
|
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": {
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
const rows = [
|
|
2
|
+
{
|
|
3
|
+
id: '1',
|
|
4
|
+
name: 'Site 1',
|
|
5
|
+
url: 'https://www.bluehost.com',
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
id: '2',
|
|
9
|
+
name: 'Site 2',
|
|
10
|
+
url: 'https://www.web.com',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
id: '3',
|
|
14
|
+
name: 'Site 3',
|
|
15
|
+
url: 'https://www.bluehost.com',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: '4',
|
|
19
|
+
name: 'Site 4',
|
|
20
|
+
url: 'https://www.web.com',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: '5',
|
|
24
|
+
name: 'Site 5',
|
|
25
|
+
url: 'https://www.bluehost.com',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: '6',
|
|
29
|
+
name: 'Site 6',
|
|
30
|
+
url: 'https://www.web.com',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: '7',
|
|
34
|
+
name: 'Site 7',
|
|
35
|
+
url: 'https://www.bluehost.com',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: '8',
|
|
39
|
+
name: 'Site 8',
|
|
40
|
+
url: 'https://www.web.com',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: '9',
|
|
44
|
+
name: 'Site 9',
|
|
45
|
+
url: 'https://www.bluehost.com',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: '10',
|
|
49
|
+
name: 'Site 10',
|
|
50
|
+
url: 'https://www.web.com',
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
export const sitesResponses = {
|
|
55
|
+
200: {
|
|
56
|
+
0: {
|
|
57
|
+
limit: 10,
|
|
58
|
+
n_pages: 0,
|
|
59
|
+
n_rows: 0,
|
|
60
|
+
page: 1,
|
|
61
|
+
rows: [],
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
1: {
|
|
65
|
+
limit: 10,
|
|
66
|
+
n_pages: 1,
|
|
67
|
+
n_rows: 1,
|
|
68
|
+
page: 1,
|
|
69
|
+
rows: [rows[0]],
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
some: {
|
|
73
|
+
limit: 10,
|
|
74
|
+
n_pages: 1,
|
|
75
|
+
n_rows: 3,
|
|
76
|
+
page: 1,
|
|
77
|
+
rows,
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
many: {
|
|
81
|
+
limit: 10,
|
|
82
|
+
n_pages: 50,
|
|
83
|
+
n_rows: 3,
|
|
84
|
+
page: 1,
|
|
85
|
+
rows: [
|
|
86
|
+
...rows,
|
|
87
|
+
{
|
|
88
|
+
id: '11',
|
|
89
|
+
name: 'Site 11',
|
|
90
|
+
url: 'https://www.bluehost.com',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
id: '12',
|
|
94
|
+
name: 'Site 12',
|
|
95
|
+
url: 'https://www.web.com',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: '13',
|
|
99
|
+
name: 'Site 13',
|
|
100
|
+
url: 'https://www.bluehost.com',
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: '14',
|
|
104
|
+
name: 'Site 14',
|
|
105
|
+
url: 'https://www.web.com',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
id: '15',
|
|
109
|
+
name: 'Site 15',
|
|
110
|
+
url: 'https://www.bluehost.com',
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
id: '16',
|
|
114
|
+
name: 'Site 16',
|
|
115
|
+
url: 'https://www.web.com',
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
id: '17',
|
|
119
|
+
name: 'Site 17',
|
|
120
|
+
url: 'https://www.bluehost.com',
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
id: '18',
|
|
124
|
+
name: 'Site 18',
|
|
125
|
+
url: 'https://www.web.com',
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: '19',
|
|
129
|
+
name: 'Site 19',
|
|
130
|
+
url: 'https://www.bluehost.com',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
id: '20',
|
|
134
|
+
name: 'Site 20',
|
|
135
|
+
url: 'https://www.web.com',
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
id: '21',
|
|
139
|
+
name: 'Site 21',
|
|
140
|
+
url: 'https://www.bluehost.com',
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
id: '22',
|
|
144
|
+
name: 'Site 22',
|
|
145
|
+
url: 'https://www.web.com',
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
id: '23',
|
|
149
|
+
name: 'Site 23',
|
|
150
|
+
url: 'https://www.bluehost.com',
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
id: '24',
|
|
154
|
+
name: 'Site 24',
|
|
155
|
+
url: 'https://www.web.com',
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
id: '25',
|
|
159
|
+
name: 'Site 25',
|
|
160
|
+
url: 'https://www.bluehost.com',
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
500: {
|
|
166
|
+
0: {
|
|
167
|
+
message: 'Something went wrong',
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export default sitesResponses;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { rest } from 'msw';
|
|
2
|
+
|
|
3
|
+
import responses from './data/sites';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* getHostingSitesHandler
|
|
7
|
+
* @param {string} responseKey - the key of the response to return from the responses object
|
|
8
|
+
* @param {int} status - the status code to mock
|
|
9
|
+
* @param {int} delay - the delay in ms to wait before returning the response
|
|
10
|
+
* @returns - a msw handler
|
|
11
|
+
*/
|
|
12
|
+
export function getHostingSitesHandler(
|
|
13
|
+
responseKey = 1, // int or string
|
|
14
|
+
status = 200,
|
|
15
|
+
delay = 1000,
|
|
16
|
+
) {
|
|
17
|
+
return rest.get('*/hosting/:hostingId/sites', (req, res, ctx) =>
|
|
18
|
+
res(
|
|
19
|
+
ctx.delay(delay),
|
|
20
|
+
ctx.status(status, 'Mocked status'),
|
|
21
|
+
ctx.json(responses[status][responseKey ?? 0]),
|
|
22
|
+
),
|
|
23
|
+
);
|
|
24
|
+
}
|
package/src/msw/sites.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
const sitesCollection = [
|
|
2
|
+
{
|
|
3
|
+
id: '1',
|
|
4
|
+
name: 'Coffee Beans',
|
|
5
|
+
url: 'https://coffeebeans.com',
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
id: '2',
|
|
9
|
+
name: 'Chilli Beans',
|
|
10
|
+
url: 'https://chillibeans.com',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
id: '3',
|
|
14
|
+
name: 'Cannellini Beans',
|
|
15
|
+
url: 'https://cannellinibeans.com',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: '4',
|
|
19
|
+
name: 'Soy Beans',
|
|
20
|
+
url: 'https://soybeans.com',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: '5',
|
|
24
|
+
name: 'Cool Beans',
|
|
25
|
+
url: 'https://coolbeans.com',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: '6',
|
|
29
|
+
name: 'Hot Beans',
|
|
30
|
+
url: 'https://hotbeans.com',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: '7',
|
|
34
|
+
name: 'Black Beans',
|
|
35
|
+
url: 'https://blackbeans.com',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: '8',
|
|
39
|
+
name: 'Pinto Beans',
|
|
40
|
+
url: 'https://pintobeans.com',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: '9',
|
|
44
|
+
name: 'Refried Beans',
|
|
45
|
+
url: 'https://refriedbeans.com',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: '10',
|
|
49
|
+
name: 'Baked Beans',
|
|
50
|
+
url: 'https://bakedbeans.com',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: '11',
|
|
54
|
+
name: 'Lima Beans',
|
|
55
|
+
url: 'https://limabeans.com',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: '12',
|
|
59
|
+
name: 'Kidney Beans',
|
|
60
|
+
url: 'https://kidneybeans.com',
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
export const sites = ({ responseType, page }) => {
|
|
65
|
+
const pageOne = {
|
|
66
|
+
limit: 10,
|
|
67
|
+
n_pages: 2,
|
|
68
|
+
n_rows: 3,
|
|
69
|
+
page: 1,
|
|
70
|
+
rows: sitesCollection,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const pageTwo = {
|
|
74
|
+
limit: 10,
|
|
75
|
+
n_pages: 2,
|
|
76
|
+
n_rows: 3,
|
|
77
|
+
page: 2,
|
|
78
|
+
rows: [
|
|
79
|
+
{
|
|
80
|
+
id: '11',
|
|
81
|
+
name: 'Bob the Blog',
|
|
82
|
+
url: 'https://bobtheblog.com',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
id: '12',
|
|
86
|
+
name: 'Wendy the Website',
|
|
87
|
+
url: 'https://wendythewebsite.com',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
id: '13',
|
|
91
|
+
name: 'Cathy the Coding Camp',
|
|
92
|
+
url: 'https://cathythecodingcamp.com',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: '14',
|
|
96
|
+
name: 'Harry Potter',
|
|
97
|
+
url: 'https://hogwarts.com',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
id: '15',
|
|
101
|
+
name: 'Cool Beans',
|
|
102
|
+
url: 'https://coolbeans.com',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
id: '16',
|
|
106
|
+
name: 'Hot Beans',
|
|
107
|
+
url: 'https://hotbeans.com',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
id: '17',
|
|
111
|
+
name: 'Black Beans',
|
|
112
|
+
url: 'https://blackbeans.com',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: '18',
|
|
116
|
+
name: 'Pinto Beans',
|
|
117
|
+
url: 'https://pintobeans.com',
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: '19',
|
|
121
|
+
name: 'Refried Beans',
|
|
122
|
+
url: 'https://refriedbeans.com',
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
id: '20',
|
|
126
|
+
name: 'Baked Beans',
|
|
127
|
+
url: 'https://bakedbeans.com',
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const resp = page === 1 ? pageOne : pageTwo;
|
|
133
|
+
switch (responseType) {
|
|
134
|
+
case 'empty':
|
|
135
|
+
resp.rows = [];
|
|
136
|
+
break;
|
|
137
|
+
case 'one':
|
|
138
|
+
resp.rows = resp.rows[0];
|
|
139
|
+
break;
|
|
140
|
+
case 'some':
|
|
141
|
+
resp.rows = resp.rows.slice(0, 5);
|
|
142
|
+
break;
|
|
143
|
+
default:
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
return resp;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// TODO: would be nice if we could take in the param (siteId) and return the proper site,
|
|
150
|
+
// but currently we are just dumbly returning the same site regardless of siteId
|
|
151
|
+
export const site = sitesCollection[0];
|
|
152
|
+
|
|
153
|
+
export const siteSso = `${sitesCollection[0].url}/wp-login.php?ssotoken=1234567890`;
|
package/dist/huapi.js
DELETED
|
@@ -1,95 +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
|
-
exports.__esModule = true;
|
|
14
|
-
exports.getHostingUAPIMSW = exports.getHostingSiteByIdMock = exports.getHostingSitesMock = exports.getSiteSsoMock = exports.useHostingSiteById = exports.getHostingSiteByIdQueryKey = exports.hostingSiteById = exports.useHostingSites = exports.getHostingSitesQueryKey = exports.hostingSites = exports.useSiteSso = exports.siteSso = void 0;
|
|
15
|
-
/**
|
|
16
|
-
* Generated by orval v6.7.1 🍺
|
|
17
|
-
* Do not edit manually.
|
|
18
|
-
* Hosting UAPI
|
|
19
|
-
* Hosting UAPI
|
|
20
|
-
* OpenAPI spec version: 0.1.0
|
|
21
|
-
*/
|
|
22
|
-
var axios_1 = require("axios");
|
|
23
|
-
var react_query_1 = require("react-query");
|
|
24
|
-
var msw_1 = require("msw");
|
|
25
|
-
/**
|
|
26
|
-
* TODO
|
|
27
|
-
* @summary Get SSO token
|
|
28
|
-
*/
|
|
29
|
-
var siteSso = function (siteId, options) {
|
|
30
|
-
return axios_1["default"].post("/sites/".concat(siteId, "/sso"), undefined, options);
|
|
31
|
-
};
|
|
32
|
-
exports.siteSso = siteSso;
|
|
33
|
-
var useSiteSso = function (options) {
|
|
34
|
-
var _a = options || {}, mutationOptions = _a.mutation, axiosOptions = _a.axios;
|
|
35
|
-
var mutationFn = function (props) {
|
|
36
|
-
var siteId = (props || {}).siteId;
|
|
37
|
-
return (0, exports.siteSso)(siteId, axiosOptions);
|
|
38
|
-
};
|
|
39
|
-
return (0, react_query_1.useMutation)(mutationFn, mutationOptions);
|
|
40
|
-
};
|
|
41
|
-
exports.useSiteSso = useSiteSso;
|
|
42
|
-
/**
|
|
43
|
-
* Obtain a list of sites.
|
|
44
|
-
* @summary Get sites for a hosting id
|
|
45
|
-
*/
|
|
46
|
-
var hostingSites = function (hostingId, options) {
|
|
47
|
-
return axios_1["default"].get("/hosting/".concat(hostingId, "/sites"), options);
|
|
48
|
-
};
|
|
49
|
-
exports.hostingSites = hostingSites;
|
|
50
|
-
var getHostingSitesQueryKey = function (hostingId) { return ["/hosting/".concat(hostingId, "/sites")]; };
|
|
51
|
-
exports.getHostingSitesQueryKey = getHostingSitesQueryKey;
|
|
52
|
-
var useHostingSites = function (hostingId, options) {
|
|
53
|
-
var _a;
|
|
54
|
-
var _b = options || {}, queryOptions = _b.query, axiosOptions = _b.axios;
|
|
55
|
-
var queryKey = (_a = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.queryKey) !== null && _a !== void 0 ? _a : (0, exports.getHostingSitesQueryKey)(hostingId);
|
|
56
|
-
var queryFn = function () { return (0, exports.hostingSites)(hostingId, axiosOptions); };
|
|
57
|
-
var query = (0, react_query_1.useQuery)(queryKey, queryFn, __assign({ enabled: !!(hostingId) }, queryOptions));
|
|
58
|
-
return __assign({ queryKey: queryKey }, query);
|
|
59
|
-
};
|
|
60
|
-
exports.useHostingSites = useHostingSites;
|
|
61
|
-
/**
|
|
62
|
-
* Obtain a specific site.
|
|
63
|
-
* @summary For a hosting id, get a specific site by site id
|
|
64
|
-
*/
|
|
65
|
-
var hostingSiteById = function (hostingId, siteId, options) {
|
|
66
|
-
return axios_1["default"].get("/hosting/".concat(hostingId, "/sites/").concat(siteId), options);
|
|
67
|
-
};
|
|
68
|
-
exports.hostingSiteById = hostingSiteById;
|
|
69
|
-
var getHostingSiteByIdQueryKey = function (hostingId, siteId) { return ["/hosting/".concat(hostingId, "/sites/").concat(siteId)]; };
|
|
70
|
-
exports.getHostingSiteByIdQueryKey = getHostingSiteByIdQueryKey;
|
|
71
|
-
var useHostingSiteById = function (hostingId, siteId, options) {
|
|
72
|
-
var _a;
|
|
73
|
-
var _b = options || {}, queryOptions = _b.query, axiosOptions = _b.axios;
|
|
74
|
-
var queryKey = (_a = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.queryKey) !== null && _a !== void 0 ? _a : (0, exports.getHostingSiteByIdQueryKey)(hostingId, siteId);
|
|
75
|
-
var queryFn = function () { return (0, exports.hostingSiteById)(hostingId, siteId, axiosOptions); };
|
|
76
|
-
var query = (0, react_query_1.useQuery)(queryKey, queryFn, __assign({ enabled: !!(hostingId && siteId) }, queryOptions));
|
|
77
|
-
return __assign({ queryKey: queryKey }, query);
|
|
78
|
-
};
|
|
79
|
-
exports.useHostingSiteById = useHostingSiteById;
|
|
80
|
-
var getSiteSsoMock = function () { return ('https://bobtheblog.com/wp-login.php?ssotoken=1234567890'); };
|
|
81
|
-
exports.getSiteSsoMock = getSiteSsoMock;
|
|
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
|
-
exports.getHostingSitesMock = getHostingSitesMock;
|
|
84
|
-
var getHostingSiteByIdMock = function () { return ({ id: '1', name: 'Bob the Blog', url: 'https://bobtheblog.com' }); };
|
|
85
|
-
exports.getHostingSiteByIdMock = getHostingSiteByIdMock;
|
|
86
|
-
var getHostingUAPIMSW = function () { return [
|
|
87
|
-
msw_1.rest.post('*/sites/:siteid/sso', function (_req, res, ctx) {
|
|
88
|
-
return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getSiteSsoMock)()));
|
|
89
|
-
}), msw_1.rest.get('*/hosting/:hostingid/sites', function (_req, res, ctx) {
|
|
90
|
-
return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getHostingSitesMock)()));
|
|
91
|
-
}), msw_1.rest.get('*/hosting/:hostingid/sites/:siteid', function (_req, res, ctx) {
|
|
92
|
-
return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getHostingSiteByIdMock)()));
|
|
93
|
-
}),
|
|
94
|
-
]; };
|
|
95
|
-
exports.getHostingUAPIMSW = getHostingUAPIMSW;
|
package/src/mocks/sites.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
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`;
|