@newfold/huapi-js 1.2.6-alpha.3 → 1.2.7

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.
@@ -0,0 +1,19 @@
1
+ export declare const getResponseByStatus: (responseKey: string, status: number) => {
2
+ message: string;
3
+ limit?: undefined;
4
+ n_pages?: undefined;
5
+ n_rows?: undefined;
6
+ page?: undefined;
7
+ rows?: undefined;
8
+ } | {
9
+ limit: number;
10
+ n_pages: number;
11
+ n_rows: number;
12
+ page: number;
13
+ rows: {
14
+ id: string;
15
+ name: string;
16
+ url: string;
17
+ }[];
18
+ message?: undefined;
19
+ };
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getResponseByStatus = void 0;
4
+ const rows = [
5
+ {
6
+ id: '1',
7
+ name: 'Site 1',
8
+ url: 'https://site-1.com',
9
+ },
10
+ {
11
+ id: '2',
12
+ name: 'Site 2',
13
+ url: 'https://site-2.com',
14
+ },
15
+ {
16
+ id: '3',
17
+ name: 'Site 3',
18
+ url: 'https://site-3.com',
19
+ },
20
+ {
21
+ id: '4',
22
+ name: 'Site 4',
23
+ url: 'https://site-4.com',
24
+ },
25
+ {
26
+ id: '5',
27
+ name: 'Site 5',
28
+ url: 'https://site-5.com',
29
+ },
30
+ {
31
+ id: '6',
32
+ name: 'Site 6',
33
+ url: 'https://site-6.com',
34
+ },
35
+ {
36
+ id: '7',
37
+ name: 'Site 7',
38
+ url: 'https://site-7.com',
39
+ },
40
+ {
41
+ id: '8',
42
+ name: 'Site 8',
43
+ url: 'https://site-8.com',
44
+ },
45
+ {
46
+ id: '9',
47
+ name: 'Site 9',
48
+ url: 'https://site-9.com',
49
+ },
50
+ {
51
+ id: '10',
52
+ name: 'Site 10',
53
+ url: 'https://site-10.com',
54
+ },
55
+ ];
56
+ const getResponseByStatus = (responseKey, status) => {
57
+ switch (status) {
58
+ case 500 - 599:
59
+ return {
60
+ message: 'Something went wrong',
61
+ };
62
+ case 200 - 299:
63
+ default:
64
+ switch (responseKey) {
65
+ case '0':
66
+ return {
67
+ limit: 10,
68
+ n_pages: 0,
69
+ n_rows: 0,
70
+ page: 1,
71
+ rows: [],
72
+ };
73
+ case '1':
74
+ return {
75
+ limit: 10,
76
+ n_pages: 1,
77
+ n_rows: 1,
78
+ page: 1,
79
+ rows: [rows[0]],
80
+ };
81
+ default:
82
+ case 'some':
83
+ return {
84
+ limit: 10,
85
+ n_pages: 1,
86
+ n_rows: 3,
87
+ page: 1,
88
+ rows,
89
+ };
90
+ case 'many':
91
+ return {
92
+ limit: 10,
93
+ n_pages: 50,
94
+ n_rows: 3,
95
+ page: 1,
96
+ rows: [
97
+ ...rows,
98
+ {
99
+ id: '11',
100
+ name: 'Site 11',
101
+ url: 'https://site-11.com',
102
+ },
103
+ {
104
+ id: '12',
105
+ name: 'Site 12',
106
+ url: 'https://site-12.com',
107
+ },
108
+ {
109
+ id: '13',
110
+ name: 'Site 13',
111
+ url: 'https://site-13.com',
112
+ },
113
+ {
114
+ id: '14',
115
+ name: 'Site 14',
116
+ url: 'https://site-14.com',
117
+ },
118
+ {
119
+ id: '15',
120
+ name: 'Site 15',
121
+ url: 'https://site-15.com',
122
+ },
123
+ {
124
+ id: '16',
125
+ name: 'Site 16',
126
+ url: 'https://site-16.com',
127
+ },
128
+ {
129
+ id: '17',
130
+ name: 'Site 17',
131
+ url: 'https://site-17.com',
132
+ },
133
+ {
134
+ id: '18',
135
+ name: 'Site 18',
136
+ url: 'https://site-18.com',
137
+ },
138
+ {
139
+ id: '19',
140
+ name: 'Site 19',
141
+ url: 'https://site-19.com',
142
+ },
143
+ {
144
+ id: '20',
145
+ name: 'Site 20',
146
+ url: 'https://site-20.com',
147
+ },
148
+ {
149
+ id: '21',
150
+ name: 'Site 21',
151
+ url: 'https://site-21.com',
152
+ },
153
+ {
154
+ id: '22',
155
+ name: 'Site 22',
156
+ url: 'https://site-22.com',
157
+ },
158
+ {
159
+ id: '23',
160
+ name: 'Site 23',
161
+ url: 'https://site-23.com',
162
+ },
163
+ {
164
+ id: '24',
165
+ name: 'Site 24',
166
+ url: 'https://site-24.com',
167
+ },
168
+ {
169
+ id: '25',
170
+ name: 'Site 25',
171
+ url: 'https://site-25.com',
172
+ },
173
+ ],
174
+ };
175
+ }
176
+ }
177
+ };
178
+ exports.getResponseByStatus = getResponseByStatus;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * getHostingSitesHandler
3
+ * @param {string} responseKey - the key of the response to return from the responses object
4
+ * @param {int} status - the status code to mock
5
+ * @param {int} delay - the delay in ms to wait before returning the response
6
+ * @returns - a msw handler
7
+ */
8
+ export declare function getHostingSitesHandler(responseKey?: string, // int or string
9
+ status?: number, delay?: number): import("msw").RestHandler<import("msw").MockedRequest<import("msw").DefaultRequestBody>>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHostingSitesHandler = void 0;
4
+ const msw_1 = require("msw");
5
+ const sites_1 = require("./data/sites");
6
+ /**
7
+ * getHostingSitesHandler
8
+ * @param {string} responseKey - the key of the response to return from the responses object
9
+ * @param {int} status - the status code to mock
10
+ * @param {int} delay - the delay in ms to wait before returning the response
11
+ * @returns - a msw handler
12
+ */
13
+ function getHostingSitesHandler(responseKey = '1', // int or string
14
+ status = 200, delay = 1000) {
15
+ return msw_1.rest.get('*/hosting/:hostingId/sites', (req, res, ctx) => res(ctx.delay(delay), ctx.status(status, 'Mocked status'), ctx.json((0, sites_1.getResponseByStatus)(responseKey, status))));
16
+ }
17
+ exports.getHostingSitesHandler = getHostingSitesHandler;
@@ -2,4 +2,4 @@
2
2
  * NOTE: this will move to @newfold/huapi-js in the future
3
3
  * Usage: `import { getHostingSitesHandler } from '@newfold/huapi-js';`
4
4
  */
5
- export * from './sites/getHostingSitesHandler';
5
+ export * from './handlers/sites/getHostingSitesHandler';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * NOTE: this will move to @newfold/huapi-js in the future
19
+ * Usage: `import { getHostingSitesHandler } from '@newfold/huapi-js';`
20
+ */
21
+ __exportStar(require("./handlers/sites/getHostingSitesHandler"), exports);
@@ -1,3 +1,3 @@
1
- export * from './site';
2
1
  export * from './siteList';
2
+ export * from './site';
3
3
  export * from './siteSso';
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./site"), exports);
18
17
  __exportStar(require("./siteList"), exports);
18
+ __exportStar(require("./site"), exports);
19
19
  __exportStar(require("./siteSso"), exports);
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@newfold/huapi-js",
3
- "version": "1.2.6-alpha.3",
3
+ "version": "1.2.7",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
- "dist/*",
9
- "src/*"
8
+ "dist"
10
9
  ],
11
10
  "dependencies": {
12
11
  "@faker-js/faker": "^6.1.2",
@@ -25,6 +24,6 @@
25
24
  "scripts": {
26
25
  "orval": "orval",
27
26
  "tsc": "npx tsc",
28
- "build": "yarn orval && yarn tsToJs"
27
+ "build": "yarn orval && yarn tsc"
29
28
  }
30
29
  }
@@ -1,172 +0,0 @@
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;
@@ -1,24 +0,0 @@
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 DELETED
@@ -1,153 +0,0 @@
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`;