@quantcdn/quant-client 1.0.0 → 2.0.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/README.md +70 -12
- package/dist/client.d.ts +15 -0
- package/dist/client.js +342 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +18 -3
- package/dist/interfaces.d.ts +34 -0
- package/dist/{config.js → interfaces.js} +0 -1
- package/dist/response.d.ts +15 -0
- package/dist/response.js +101 -0
- package/dist/types.d.ts +60 -0
- package/dist/types.js +8 -0
- package/package.json +20 -6
- package/dist/config.d.ts +0 -7
- package/dist/helper/quant-url.d.ts +0 -15
- package/dist/helper/quant-url.js +0 -29
- package/dist/quant-client.d.ts +0 -230
- package/dist/quant-client.js +0 -696
package/README.md
CHANGED
|
@@ -7,24 +7,82 @@ Provides a client to common API interfaces on QuantCDN.
|
|
|
7
7
|
The preferred method for installation is via npm.
|
|
8
8
|
|
|
9
9
|
```
|
|
10
|
-
npm i @quantcdn/quant-
|
|
10
|
+
npm i @quantcdn/quant-client
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* `QUANT_PROJECT`: The project identifier
|
|
18
|
-
* `QUANT_TOKEN`: The project token
|
|
15
|
+
- Import `types` form '@quantcdn/quant-client' to correctly type parameters
|
|
16
|
+
- All responses are generated using the `PaginatedResponse` object which provides an async iterator
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
```
|
|
19
|
+
import { QuantClient, types } from '@quantcdn/quant-client'
|
|
20
|
+
|
|
21
|
+
const config:types.Config = {
|
|
22
|
+
organization: process.env.QUANT_CUSTOMER,
|
|
23
|
+
project: process.env.QUANT_PROJECT,
|
|
24
|
+
token: process.env.QUANT_TOKEN
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// If making organization API requests with the client you need to provide bearer
|
|
28
|
+
# config.bearer = process.env.QUANT_BEARER_TOKEN
|
|
29
|
+
|
|
30
|
+
// Create a new client instance.
|
|
31
|
+
const client = new QuantClient(config)
|
|
32
|
+
|
|
33
|
+
// Perform requests to the project API.
|
|
34
|
+
const p:types.URLPayload = {"url": "/*"}
|
|
35
|
+
client.project.purge(p).then(async res => {
|
|
36
|
+
const r = await res.first()
|
|
37
|
+
console.log(r)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
// Ping the API to verify details.
|
|
41
|
+
client.project.ping().then(async res => {
|
|
42
|
+
const b = await res.first()
|
|
43
|
+
console.log(b)
|
|
44
|
+
})
|
|
21
45
|
|
|
46
|
+
// Access project metadata.
|
|
47
|
+
client.project.meta().then(async res => {
|
|
48
|
+
// res.first() will return the first page of the paginated response.
|
|
49
|
+
for await (const i of res) {
|
|
50
|
+
console.log(i)
|
|
51
|
+
}
|
|
52
|
+
})
|
|
22
53
|
```
|
|
23
|
-
import { QuantClient } from "@quantcdn/quant-client"
|
|
24
54
|
|
|
25
|
-
|
|
26
|
-
|
|
55
|
+
## Available methods
|
|
56
|
+
|
|
57
|
+
The `QuantClient` class has three properties to access different APIs that are exposed by Quant. These are `project`, `organization`, `search`. Both the project and search clients are project specific.
|
|
58
|
+
|
|
59
|
+
### `client.project`
|
|
60
|
+
|
|
61
|
+
| Method | Description | Parameters |
|
|
62
|
+
| --------- | -------------------------------------- | --------------------- |
|
|
63
|
+
| ping | Ping the API to validate credentials | |
|
|
64
|
+
| meta | Access the global meta for the project | |
|
|
65
|
+
| markup | Send a HTML file | types.MarkupPayload |
|
|
66
|
+
| file | Send a non-HTML file | types.FilePayload |
|
|
67
|
+
| publish | Publish a URL | types.PublishPayload |
|
|
68
|
+
| unpublish | Unpublish a URL | types.PublishPayload |
|
|
69
|
+
| redirect | Create a redirect | types.RedirectPayload |
|
|
70
|
+
| proxy | Create an origin proxy | types.ProxyPayload |
|
|
71
|
+
| delete | Delete a resource | types.URLPayload |
|
|
72
|
+
| revisions | Show revisions for a URL | types.URLPayload |
|
|
73
|
+
| purge | Purge cache for the given URL | types.URLPayload |
|
|
74
|
+
|
|
75
|
+
### `client.organization`
|
|
76
|
+
|
|
77
|
+
| Method | Description | Parameters |
|
|
78
|
+
| ------- | ------------------------------------ | -------------------- |
|
|
79
|
+
| wafLogs | Access WAF logs for the organization | types.WafLogsPayload |
|
|
80
|
+
|
|
81
|
+
### `client.search`
|
|
27
82
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
83
|
+
| Method | Description | Parameters |
|
|
84
|
+
| ------ | --------------------------- | ------------------------ |
|
|
85
|
+
| index | Add a new item to the index | types.SearchIndexPayload |
|
|
86
|
+
| remove | Remove a URL form the index | types.URLPayload |
|
|
87
|
+
| clear | Clear the projects index | |
|
|
88
|
+
| status | Get the index status | |
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quant API client.
|
|
3
|
+
*/
|
|
4
|
+
import type * as types from './types';
|
|
5
|
+
import type * as interfaces from './interfaces';
|
|
6
|
+
export declare class QuantClient {
|
|
7
|
+
private readonly _project;
|
|
8
|
+
private readonly _organization;
|
|
9
|
+
private readonly _search;
|
|
10
|
+
constructor(config: types.Config, Client?: interfaces.ClientConstructor);
|
|
11
|
+
getClient(name: string): interfaces.Client;
|
|
12
|
+
project: interfaces.ProjectApi;
|
|
13
|
+
organization: interfaces.OrganizationApi;
|
|
14
|
+
search: interfaces.SearchApi;
|
|
15
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Quant API client.
|
|
4
|
+
*/
|
|
5
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.QuantClient = void 0;
|
|
16
|
+
const request = require("@cypress/request");
|
|
17
|
+
const response_1 = require("./response");
|
|
18
|
+
class HttpClient {
|
|
19
|
+
constructor(baseUrl, headers) {
|
|
20
|
+
this.baseUrl = baseUrl;
|
|
21
|
+
this.headers = headers;
|
|
22
|
+
}
|
|
23
|
+
do(options) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
return yield new Promise((resolve, reject) => {
|
|
26
|
+
request(options, (error, repsonse, body) => {
|
|
27
|
+
if (error !== null) {
|
|
28
|
+
reject(error);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
resolve(body);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
get(path, qs, headers) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const options = {
|
|
40
|
+
url: `${this.baseUrl}/${path}`,
|
|
41
|
+
method: 'GET',
|
|
42
|
+
headers: Object.assign(Object.assign({}, this.headers), headers),
|
|
43
|
+
json: true,
|
|
44
|
+
qs
|
|
45
|
+
};
|
|
46
|
+
const res = new response_1.PaginatedResponse(this, options);
|
|
47
|
+
return yield new Promise((resolve) => { resolve(res); });
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
post(path, body, headers, formData, qs) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const options = {
|
|
53
|
+
url: `${this.baseUrl}/${path}`,
|
|
54
|
+
method: 'POST',
|
|
55
|
+
headers: Object.assign(Object.assign({}, this.headers), headers),
|
|
56
|
+
json: true,
|
|
57
|
+
body,
|
|
58
|
+
formData,
|
|
59
|
+
qs
|
|
60
|
+
};
|
|
61
|
+
const res = new response_1.PaginatedResponse(this, options);
|
|
62
|
+
return yield new Promise((resolve) => { resolve(res); });
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
delete(path, body, headers) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const options = {
|
|
68
|
+
url: `${this.baseUrl}/${path}`,
|
|
69
|
+
method: 'DELETE',
|
|
70
|
+
headers: Object.assign(Object.assign({}, this.headers), headers),
|
|
71
|
+
json: true,
|
|
72
|
+
body
|
|
73
|
+
};
|
|
74
|
+
const res = new response_1.PaginatedResponse(this, options);
|
|
75
|
+
return yield new Promise((resolve) => { resolve(res); });
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
patch(path, body, headers) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const options = {
|
|
81
|
+
url: `${this.baseUrl}/${path}`,
|
|
82
|
+
method: 'PATCH',
|
|
83
|
+
headers: Object.assign(Object.assign({}, this.headers), headers),
|
|
84
|
+
json: true,
|
|
85
|
+
body
|
|
86
|
+
};
|
|
87
|
+
const res = new response_1.PaginatedResponse(this, options);
|
|
88
|
+
return yield new Promise((resolve) => { resolve(res); });
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
class QuantClient {
|
|
93
|
+
constructor(config, Client) {
|
|
94
|
+
this.project = {
|
|
95
|
+
/**
|
|
96
|
+
* Ping and ensure the API credentials are valid.
|
|
97
|
+
*
|
|
98
|
+
* @returns Promise<any>
|
|
99
|
+
* The response object.
|
|
100
|
+
*/
|
|
101
|
+
ping: () => __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
return yield this._project.get('ping');
|
|
103
|
+
}),
|
|
104
|
+
/**
|
|
105
|
+
* Fetch metadata for all objects stored in Quant.
|
|
106
|
+
*
|
|
107
|
+
* @returns Promise<any>
|
|
108
|
+
* The repsonse object.
|
|
109
|
+
*/
|
|
110
|
+
meta: () => __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
return yield this._project.get('global-meta');
|
|
112
|
+
}),
|
|
113
|
+
/**
|
|
114
|
+
* Send markup directly to the Quant API.
|
|
115
|
+
*
|
|
116
|
+
* @param markup MarkupPayload
|
|
117
|
+
* The markup payload data.
|
|
118
|
+
*
|
|
119
|
+
* @returns Promise<any>
|
|
120
|
+
* The repsonse object.
|
|
121
|
+
*/
|
|
122
|
+
markup: (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
const headers = {};
|
|
124
|
+
const body = {
|
|
125
|
+
url: payload.url,
|
|
126
|
+
content: payload.data.toString('utf-8'),
|
|
127
|
+
published: payload.published,
|
|
128
|
+
find_attachments: 'false'
|
|
129
|
+
};
|
|
130
|
+
if (typeof payload.skipPurge !== 'undefined') {
|
|
131
|
+
headers['Quant-Skip-Purge'] = 'true';
|
|
132
|
+
}
|
|
133
|
+
if (typeof payload.findAttachments !== 'undefined') {
|
|
134
|
+
body.find_attachments = 'true';
|
|
135
|
+
}
|
|
136
|
+
return yield this._project.post('markup', body, headers);
|
|
137
|
+
}),
|
|
138
|
+
/**
|
|
139
|
+
* Upload a file asset to Quant.
|
|
140
|
+
*
|
|
141
|
+
* @param payload FilePayload
|
|
142
|
+
* The file payload data.
|
|
143
|
+
*
|
|
144
|
+
* @returns Promose<any>
|
|
145
|
+
* The repsonse object.
|
|
146
|
+
*/
|
|
147
|
+
file: (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
const headers = {
|
|
149
|
+
'Content-Type': 'multipart/form-data',
|
|
150
|
+
'Quant-File-Url': payload.location
|
|
151
|
+
};
|
|
152
|
+
const formData = { data: payload.data };
|
|
153
|
+
if (typeof payload.skipPurge !== 'undefined') {
|
|
154
|
+
headers['Quant-Skip-Purge'] = 'true';
|
|
155
|
+
}
|
|
156
|
+
return yield this._project.post('file', {}, headers, formData);
|
|
157
|
+
}),
|
|
158
|
+
/**
|
|
159
|
+
* Publish a revision.
|
|
160
|
+
*
|
|
161
|
+
* @param payload PublishPayload
|
|
162
|
+
* The payload object
|
|
163
|
+
*
|
|
164
|
+
* @returns Promise<any>
|
|
165
|
+
* The response object.
|
|
166
|
+
*/
|
|
167
|
+
publish: (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
return yield this._project.patch(`publish/${payload.revision}`, {}, {
|
|
169
|
+
'Quant-Url': payload.location
|
|
170
|
+
});
|
|
171
|
+
}),
|
|
172
|
+
/**
|
|
173
|
+
* Unpublish a revision.
|
|
174
|
+
*
|
|
175
|
+
* @param payload PublishPayload
|
|
176
|
+
* The payload object.
|
|
177
|
+
*
|
|
178
|
+
* @returns Promise<any>
|
|
179
|
+
* The response object.
|
|
180
|
+
*/
|
|
181
|
+
unpublish: (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
182
|
+
return yield this._project.patch(`unpublish/${payload.revision}`, {}, {
|
|
183
|
+
'Quant-Url': payload.location
|
|
184
|
+
});
|
|
185
|
+
}),
|
|
186
|
+
/**
|
|
187
|
+
* Redirect a URL.
|
|
188
|
+
*
|
|
189
|
+
* @param payload RedirectPayload
|
|
190
|
+
* The redirect payload.
|
|
191
|
+
*
|
|
192
|
+
* @returns Promise<any>
|
|
193
|
+
* The repsonse object.
|
|
194
|
+
*/
|
|
195
|
+
redirect: (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
196
|
+
return yield this._project.post('redirect', payload);
|
|
197
|
+
}),
|
|
198
|
+
/**
|
|
199
|
+
* Proxy a URL to a different origin.
|
|
200
|
+
*
|
|
201
|
+
* @param payload ProxyPayload
|
|
202
|
+
* The proxy API payload.
|
|
203
|
+
*
|
|
204
|
+
* @returns Promise<any>
|
|
205
|
+
* The repsonse object.
|
|
206
|
+
*/
|
|
207
|
+
proxy: (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
return yield this._project.post('proxy', payload);
|
|
209
|
+
}),
|
|
210
|
+
/**
|
|
211
|
+
* Delete a URL from Quant.
|
|
212
|
+
*
|
|
213
|
+
* @param payload URLPayload
|
|
214
|
+
* The API payload.
|
|
215
|
+
*
|
|
216
|
+
* @returns Promise<any>
|
|
217
|
+
* The repsonse object.
|
|
218
|
+
*/
|
|
219
|
+
delete: (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
return yield this._project.delete('delete/all', {}, {
|
|
221
|
+
'Quant-Url': payload.url
|
|
222
|
+
});
|
|
223
|
+
}),
|
|
224
|
+
/**
|
|
225
|
+
* Get a revision from the API.
|
|
226
|
+
*
|
|
227
|
+
* @param payload URLPayload
|
|
228
|
+
* The URL payload.
|
|
229
|
+
*
|
|
230
|
+
* @returns Promise<any>
|
|
231
|
+
* The repsonse object.
|
|
232
|
+
*/
|
|
233
|
+
revisions: (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
234
|
+
return yield this._project.get('revisions/latest', {}, {
|
|
235
|
+
'Quant-Url': payload.url
|
|
236
|
+
});
|
|
237
|
+
}),
|
|
238
|
+
/**
|
|
239
|
+
* Purge Varnish for a given URL pattern.
|
|
240
|
+
*
|
|
241
|
+
* @param payload URLPayload
|
|
242
|
+
* The URL payload.
|
|
243
|
+
*
|
|
244
|
+
* @returns Promise<any>
|
|
245
|
+
* The repsonse object.
|
|
246
|
+
*/
|
|
247
|
+
purge: (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
248
|
+
return yield this._project.post('purge', {}, {
|
|
249
|
+
'Quant-Url': payload.url
|
|
250
|
+
});
|
|
251
|
+
})
|
|
252
|
+
};
|
|
253
|
+
this.organization = {
|
|
254
|
+
/**
|
|
255
|
+
* Fetch WAF logs from.
|
|
256
|
+
*
|
|
257
|
+
* @param payload types.WafLogsPayload
|
|
258
|
+
* The API request payload.
|
|
259
|
+
*
|
|
260
|
+
* @returns Promise<any>
|
|
261
|
+
* The response object.
|
|
262
|
+
*/
|
|
263
|
+
wafLogs: (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
264
|
+
const headers = { 'Quant-Project': payload.project };
|
|
265
|
+
return yield this._organization.get('waf/logs', {}, headers);
|
|
266
|
+
})
|
|
267
|
+
};
|
|
268
|
+
this.search = {
|
|
269
|
+
/**
|
|
270
|
+
* Index search data.
|
|
271
|
+
*
|
|
272
|
+
* @param payload types.SearchIndexPayload
|
|
273
|
+
* The search index paylod.
|
|
274
|
+
*
|
|
275
|
+
* @returns Promose<any>
|
|
276
|
+
* The respose.
|
|
277
|
+
*/
|
|
278
|
+
index: (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
279
|
+
return yield this._search.post('search', JSON.parse(payload.data.toString()));
|
|
280
|
+
}),
|
|
281
|
+
/**
|
|
282
|
+
* Remove an item from the search index.
|
|
283
|
+
*
|
|
284
|
+
* @param payload types.URLPayload
|
|
285
|
+
* The URL payload.
|
|
286
|
+
*
|
|
287
|
+
* @returns Promise<any>
|
|
288
|
+
* The response obejct.
|
|
289
|
+
*/
|
|
290
|
+
remove: (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
return yield this._search.delete('search', {}, {
|
|
292
|
+
'Quant-Url': payload.url
|
|
293
|
+
});
|
|
294
|
+
}),
|
|
295
|
+
/**
|
|
296
|
+
* Clear the search index.
|
|
297
|
+
*
|
|
298
|
+
* @returns Promise<any>
|
|
299
|
+
* The response object.
|
|
300
|
+
*/
|
|
301
|
+
clear: () => __awaiter(this, void 0, void 0, function* () {
|
|
302
|
+
return yield this._search.delete('search/all');
|
|
303
|
+
}),
|
|
304
|
+
/**
|
|
305
|
+
* Get the search index status.
|
|
306
|
+
*
|
|
307
|
+
* @returns Promise<any>
|
|
308
|
+
* The response object.
|
|
309
|
+
*/
|
|
310
|
+
status: () => __awaiter(this, void 0, void 0, function* () {
|
|
311
|
+
return yield this._search.get('search');
|
|
312
|
+
})
|
|
313
|
+
};
|
|
314
|
+
if (typeof Client === 'undefined') {
|
|
315
|
+
Client = HttpClient;
|
|
316
|
+
}
|
|
317
|
+
this._project = new Client('https://api.quantcdn.io/v1', {
|
|
318
|
+
'User-Agent': 'Quant (+http://api.quantcdn.io)',
|
|
319
|
+
'Quant-Token': config.token,
|
|
320
|
+
'Quant-Customer': config.organization,
|
|
321
|
+
'Quant-Project': config.project,
|
|
322
|
+
'Content-Type': 'application/json'
|
|
323
|
+
});
|
|
324
|
+
this._search = new Client('https://api.quantcdn.io/v1', {
|
|
325
|
+
'User-Agent': 'Quant (+http://api.quantcdn.io)',
|
|
326
|
+
'Quant-Token': config.token,
|
|
327
|
+
'Quant-Customer': config.organization,
|
|
328
|
+
'Quant-Project': config.project,
|
|
329
|
+
'Content-Type': 'application/json'
|
|
330
|
+
});
|
|
331
|
+
this._organization = new Client('https://dashboard.quantcdn.io/api/v1', {
|
|
332
|
+
'User-Agent': 'Quant (+http://api.quantcdn.io)',
|
|
333
|
+
// @todo: Americanise.
|
|
334
|
+
'Quant-Organisation': config.organization,
|
|
335
|
+
Authorization: `Bearer ${config.bearer}`
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
getClient(name) {
|
|
339
|
+
return this[`_${name}`];
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
exports.QuantClient = QuantClient;
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './client';
|
|
2
|
+
export * as types from './types';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
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
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
17
|
+
exports.types = void 0;
|
|
18
|
+
// export { QuantClient } from './quant-client'
|
|
19
|
+
__exportStar(require("./client"), exports);
|
|
20
|
+
exports.types = require("./types");
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type * as types from './types';
|
|
2
|
+
import type * as request from '@cypress/request';
|
|
3
|
+
export type ClientConstructor = new (baseUrl: string, headers: object) => Client;
|
|
4
|
+
export interface Client {
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
headers: object;
|
|
7
|
+
do: (options: request.Options) => Promise<any>;
|
|
8
|
+
get: (path: string, qs?: object, headers?: object) => Promise<any>;
|
|
9
|
+
post: (path: string, body?: any, headers?: object, formData?: object, qs?: object) => Promise<any>;
|
|
10
|
+
delete: (path: string, body?: any, headers?: object) => Promise<any>;
|
|
11
|
+
patch: (path: string, body?: any, headers?: object) => Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
export interface ProjectApi {
|
|
14
|
+
ping: () => Promise<any>;
|
|
15
|
+
meta: () => Promise<any>;
|
|
16
|
+
markup: (payload: types.MarkupPayload) => Promise<any>;
|
|
17
|
+
file: (payload: types.FilePayload) => Promise<any>;
|
|
18
|
+
publish: (payload: types.PublishPayload) => Promise<any>;
|
|
19
|
+
unpublish: (payload: types.PublishPayload) => Promise<any>;
|
|
20
|
+
redirect: (payload: types.RedirectPayload) => Promise<any>;
|
|
21
|
+
proxy: (payload: types.ProxyPayload) => Promise<any>;
|
|
22
|
+
delete: (payload: types.URLPayload) => Promise<any>;
|
|
23
|
+
revisions: (payload: types.URLPayload) => Promise<any>;
|
|
24
|
+
purge: (payload: types.URLPayload) => Promise<any>;
|
|
25
|
+
}
|
|
26
|
+
export interface OrganizationApi {
|
|
27
|
+
wafLogs: (payload: types.WafLogsPayload) => Promise<any>;
|
|
28
|
+
}
|
|
29
|
+
export interface SearchApi {
|
|
30
|
+
index: (payload: types.SearchIndexPayload) => Promise<any>;
|
|
31
|
+
remove: (payload: types.URLPayload) => Promise<any>;
|
|
32
|
+
clear: () => Promise<any>;
|
|
33
|
+
status: () => Promise<any>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Client } from './interfaces';
|
|
2
|
+
import type * as request from '@cypress/request';
|
|
3
|
+
export declare class PaginatedResponse implements AsyncIterator<any> {
|
|
4
|
+
private readonly client;
|
|
5
|
+
private readonly request;
|
|
6
|
+
private readonly per_page;
|
|
7
|
+
private page;
|
|
8
|
+
private total;
|
|
9
|
+
private hasNext;
|
|
10
|
+
constructor(client: Client, options: request.Options);
|
|
11
|
+
first(): Promise<any>;
|
|
12
|
+
do(): Promise<any>;
|
|
13
|
+
next(): Promise<IteratorResult<any>>;
|
|
14
|
+
[Symbol.asyncIterator](): AsyncIterator<any>;
|
|
15
|
+
}
|
package/dist/response.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
12
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
13
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
14
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
15
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
16
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
17
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
18
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
19
|
+
function fulfill(value) { resume("next", value); }
|
|
20
|
+
function reject(value) { resume("throw", value); }
|
|
21
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.PaginatedResponse = void 0;
|
|
25
|
+
class PaginatedResponse {
|
|
26
|
+
constructor(client, options) {
|
|
27
|
+
this.per_page = 10;
|
|
28
|
+
this.page = 0;
|
|
29
|
+
this.total = 0;
|
|
30
|
+
this.hasNext = true;
|
|
31
|
+
this.client = client;
|
|
32
|
+
this.request = options;
|
|
33
|
+
this.per_page = 10;
|
|
34
|
+
this.page = 1;
|
|
35
|
+
if (typeof this.request.qs !== 'object') {
|
|
36
|
+
this.request.qs = {};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
first() {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
let body = { data: {} };
|
|
42
|
+
try {
|
|
43
|
+
body = yield this.client.do(this.request);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
return yield new Promise((resolve, reject) => { reject(err); });
|
|
47
|
+
}
|
|
48
|
+
return yield new Promise(resolve => { resolve(body); });
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
do() {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
return yield this.first();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
next() {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
let body = { data: {} };
|
|
59
|
+
if (this.page > this.total && this.total !== 0) {
|
|
60
|
+
this.hasNext = false;
|
|
61
|
+
return body;
|
|
62
|
+
}
|
|
63
|
+
this.request.qs.page = this.page;
|
|
64
|
+
this.request.qs.per_page = this.per_page;
|
|
65
|
+
try {
|
|
66
|
+
body = yield this.client.do(this.request);
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
this.hasNext = false;
|
|
70
|
+
return body;
|
|
71
|
+
}
|
|
72
|
+
this.page += 1;
|
|
73
|
+
if ('global_meta' in body) {
|
|
74
|
+
// Handle meta responses.
|
|
75
|
+
this.total = body.global_meta.total_pages;
|
|
76
|
+
this.hasNext = this.page <= body.global_meta.total_pages;
|
|
77
|
+
return body.global_meta.records;
|
|
78
|
+
}
|
|
79
|
+
else if ('total_records' in body) {
|
|
80
|
+
// WAFlog responses.
|
|
81
|
+
this.total = Math.ceil(body.total_reccords % this.per_page);
|
|
82
|
+
this.hasNext = body.next !== '';
|
|
83
|
+
return body.data;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
this.total = body.pagination.total_pages;
|
|
87
|
+
this.hasNext = this.page <= body.pagination.total_pages;
|
|
88
|
+
return body.data;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
[Symbol.asyncIterator]() {
|
|
93
|
+
return __asyncGenerator(this, arguments, function* _a() {
|
|
94
|
+
while (this.hasNext) {
|
|
95
|
+
const data = yield __await(this.next());
|
|
96
|
+
yield yield __await(data);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.PaginatedResponse = PaginatedResponse;
|