@autometa/http 0.1.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/.eslintignore +3 -0
- package/.eslintrc.cjs +4 -0
- package/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/esm/index.js +484 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.cts +122 -0
- package/dist/index.d.ts +122 -0
- package/dist/index.js +524 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
- package/tsup.config.ts +14 -0
package/.eslintignore
ADDED
package/.eslintrc.cjs
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @autometa/http
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 04ed85d: feat: added HTP client based on axios
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [04ed85d]
|
|
12
|
+
- @autometa/status-codes@0.4.1
|
|
13
|
+
- @autometa/errors@0.1.4
|
|
14
|
+
- @autometa/app@0.1.13
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) undefined Ben Aherne
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
var __accessCheck = (obj, member, msg) => {
|
|
13
|
+
if (!member.has(obj))
|
|
14
|
+
throw TypeError("Cannot " + msg);
|
|
15
|
+
};
|
|
16
|
+
var __privateGet = (obj, member, getter) => {
|
|
17
|
+
__accessCheck(obj, member, "read from private field");
|
|
18
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
19
|
+
};
|
|
20
|
+
var __privateAdd = (obj, member, value) => {
|
|
21
|
+
if (member.has(obj))
|
|
22
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
23
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
24
|
+
};
|
|
25
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
26
|
+
__accessCheck(obj, member, "write to private field");
|
|
27
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// src/http.builder.ts
|
|
32
|
+
import { Fixture, LIFE_CYCLE } from "@autometa/app";
|
|
33
|
+
import { AutomationError as AutomationError2 } from "@autometa/errors";
|
|
34
|
+
import axios from "axios";
|
|
35
|
+
import { plainToClass } from "class-transformer";
|
|
36
|
+
import { urlJoinP } from "url-join-ts";
|
|
37
|
+
|
|
38
|
+
// src/http.response.ts
|
|
39
|
+
var HTTPResponse = class _HTTPResponse {
|
|
40
|
+
static fromRaw(data, status, statusText, headers, url) {
|
|
41
|
+
const response = new _HTTPResponse();
|
|
42
|
+
response.data = data;
|
|
43
|
+
response.status = status;
|
|
44
|
+
response.statusText = statusText;
|
|
45
|
+
response.headers = headers;
|
|
46
|
+
response.request = {
|
|
47
|
+
url
|
|
48
|
+
};
|
|
49
|
+
return response;
|
|
50
|
+
}
|
|
51
|
+
static derive(original, data) {
|
|
52
|
+
const response = new DerivedHTTPResponse();
|
|
53
|
+
if (typeof data === "function") {
|
|
54
|
+
const fn = data;
|
|
55
|
+
response.data = fn(original.data);
|
|
56
|
+
} else {
|
|
57
|
+
response.data = data;
|
|
58
|
+
}
|
|
59
|
+
response.status = original.status;
|
|
60
|
+
response.statusText = original.statusText;
|
|
61
|
+
response.headers = original.headers;
|
|
62
|
+
response.request = original.request;
|
|
63
|
+
response.actual = original;
|
|
64
|
+
return response;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var DerivedHTTPResponse = class extends HTTPResponse {
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/schema.map.ts
|
|
71
|
+
import { AutomationError } from "@autometa/errors";
|
|
72
|
+
import { StatusCodes } from "@autometa/status-codes";
|
|
73
|
+
var _children, _map;
|
|
74
|
+
var SchemaMap = class {
|
|
75
|
+
constructor() {
|
|
76
|
+
__privateAdd(this, _children, []);
|
|
77
|
+
__privateAdd(this, _map, /* @__PURE__ */ new Map());
|
|
78
|
+
}
|
|
79
|
+
register(parser, ...args) {
|
|
80
|
+
args.forEach((arg) => {
|
|
81
|
+
if (typeof arg === "number") {
|
|
82
|
+
this.registerSingle(parser, arg);
|
|
83
|
+
} else {
|
|
84
|
+
this.registerRange(parser, arg);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return parser.parse;
|
|
88
|
+
}
|
|
89
|
+
registerSingle(parser, ...codes) {
|
|
90
|
+
codes.forEach((code) => {
|
|
91
|
+
if (__privateGet(this, _map).has(code)) {
|
|
92
|
+
throw new AutomationError(
|
|
93
|
+
`Status code ${code} is already registered with a parser`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
assertIsStatusCode(code);
|
|
97
|
+
__privateGet(this, _map).set(code, parser);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
including(map) {
|
|
101
|
+
__privateGet(this, _children).includes(map);
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
registerRange(parser, ...range) {
|
|
105
|
+
range.forEach(({ from, to }) => {
|
|
106
|
+
assertIsStatusCode(from);
|
|
107
|
+
assertIsStatusCode(to);
|
|
108
|
+
for (let i = from; i <= to; i++) {
|
|
109
|
+
if (!IsStatusCode(i)) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (__privateGet(this, _map).has(i)) {
|
|
113
|
+
throw new AutomationError(
|
|
114
|
+
`Status code ${i} is already registered with a parser`
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
__privateGet(this, _map).set(i, parser);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
get(status) {
|
|
122
|
+
assertIsStatusCode(status);
|
|
123
|
+
const local = __privateGet(this, _map).get(status);
|
|
124
|
+
if (local) {
|
|
125
|
+
return local;
|
|
126
|
+
}
|
|
127
|
+
const nested = __privateGet(this, _children).find((it) => __privateGet(it, _map).has(status));
|
|
128
|
+
return nested?.get(status);
|
|
129
|
+
}
|
|
130
|
+
validate(status, response, strict) {
|
|
131
|
+
const parser = this.get(status);
|
|
132
|
+
if (!parser) {
|
|
133
|
+
if (!strict) {
|
|
134
|
+
return response;
|
|
135
|
+
}
|
|
136
|
+
throw new AutomationError(
|
|
137
|
+
`No schema parser registered for status code ${status} and 'requireSchema' is set to true`
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
return parser.parse(response);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
_children = new WeakMap();
|
|
144
|
+
_map = new WeakMap();
|
|
145
|
+
function assertIsStatusCode(value) {
|
|
146
|
+
const result = Object.values(StatusCodes).map((it) => it.status).includes(value);
|
|
147
|
+
if (!result) {
|
|
148
|
+
throw new AutomationError(
|
|
149
|
+
`Expected status code ${value} to be a valid status code, but it is not a known HTTP codeF`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function IsStatusCode(value) {
|
|
154
|
+
return Object.values(StatusCodes).map((it) => it.status).includes(value);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// src/http.builder.ts
|
|
158
|
+
import isJson from "@stdlib/assert-is-json";
|
|
159
|
+
import highlight from "cli-highlight";
|
|
160
|
+
var _headers, _params, _url, _route, _method, _schemaMap, _responseType, _data, _requireSchema, _allowPlainText, _onBeforeSend, _onAfterSend;
|
|
161
|
+
var HTTPRequestBuilder = class {
|
|
162
|
+
constructor(map) {
|
|
163
|
+
__privateAdd(this, _headers, /* @__PURE__ */ new Map());
|
|
164
|
+
__privateAdd(this, _params, /* @__PURE__ */ new Map());
|
|
165
|
+
__privateAdd(this, _url, void 0);
|
|
166
|
+
__privateAdd(this, _route, []);
|
|
167
|
+
__privateAdd(this, _method, void 0);
|
|
168
|
+
__privateAdd(this, _schemaMap, new SchemaMap());
|
|
169
|
+
__privateAdd(this, _responseType, "json");
|
|
170
|
+
__privateAdd(this, _data, void 0);
|
|
171
|
+
__privateAdd(this, _requireSchema, false);
|
|
172
|
+
__privateAdd(this, _allowPlainText, false);
|
|
173
|
+
__privateAdd(this, _onBeforeSend, []);
|
|
174
|
+
__privateAdd(this, _onAfterSend, []);
|
|
175
|
+
__privateSet(this, _schemaMap, new SchemaMap().including(map));
|
|
176
|
+
}
|
|
177
|
+
requireSchema(value) {
|
|
178
|
+
__privateSet(this, _requireSchema, value);
|
|
179
|
+
return this;
|
|
180
|
+
}
|
|
181
|
+
get currentState() {
|
|
182
|
+
const fullUrl = this.currentUrl;
|
|
183
|
+
return {
|
|
184
|
+
headers: __privateGet(this, _headers),
|
|
185
|
+
params: __privateGet(this, _params),
|
|
186
|
+
url: __privateGet(this, _url),
|
|
187
|
+
route: __privateGet(this, _route),
|
|
188
|
+
responseType: __privateGet(this, _responseType),
|
|
189
|
+
data: __privateGet(this, _data),
|
|
190
|
+
method: __privateGet(this, _method),
|
|
191
|
+
fullUrl
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
get currentUrl() {
|
|
195
|
+
const params = Object.fromEntries(__privateGet(this, _params));
|
|
196
|
+
return urlJoinP(__privateGet(this, _url), __privateGet(this, _route), params);
|
|
197
|
+
}
|
|
198
|
+
url(url) {
|
|
199
|
+
__privateSet(this, _url, url);
|
|
200
|
+
return this;
|
|
201
|
+
}
|
|
202
|
+
allowPlainText(value) {
|
|
203
|
+
__privateSet(this, _allowPlainText, value);
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
206
|
+
schema(parser, ...args) {
|
|
207
|
+
__privateGet(this, _schemaMap).register(parser, ...args);
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
210
|
+
onBeforeSend(hook) {
|
|
211
|
+
__privateGet(this, _onBeforeSend).push(hook);
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
onReceivedResponse(hook) {
|
|
215
|
+
__privateGet(this, _onAfterSend).push(hook);
|
|
216
|
+
return this;
|
|
217
|
+
}
|
|
218
|
+
route(...route) {
|
|
219
|
+
__privateGet(this, _route).push(...route.map((it) => `${it}`));
|
|
220
|
+
return this;
|
|
221
|
+
}
|
|
222
|
+
header(name, value) {
|
|
223
|
+
__privateGet(this, _headers).set(name, value);
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
headers(dict) {
|
|
227
|
+
Object.entries(dict).forEach(
|
|
228
|
+
([name, value]) => __privateGet(this, _headers).set(name, value)
|
|
229
|
+
);
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
param(name, value) {
|
|
233
|
+
__privateGet(this, _params).set(name, value);
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
params(dict) {
|
|
237
|
+
Object.entries(dict).forEach(
|
|
238
|
+
([name, value]) => __privateGet(this, _params).set(name, value)
|
|
239
|
+
);
|
|
240
|
+
return this;
|
|
241
|
+
}
|
|
242
|
+
data(data) {
|
|
243
|
+
__privateSet(this, _data, data);
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
async post() {
|
|
247
|
+
return this._request("POST");
|
|
248
|
+
}
|
|
249
|
+
async get() {
|
|
250
|
+
return this._request("GET");
|
|
251
|
+
}
|
|
252
|
+
async delete() {
|
|
253
|
+
return this._request("DELETE");
|
|
254
|
+
}
|
|
255
|
+
async put() {
|
|
256
|
+
return this._request("PUT");
|
|
257
|
+
}
|
|
258
|
+
async _request(method) {
|
|
259
|
+
__privateSet(this, _method, method);
|
|
260
|
+
const url = this.currentUrl;
|
|
261
|
+
const headers = __privateGet(this, _headers) && Object.fromEntries(__privateGet(this, _headers));
|
|
262
|
+
const responseType = __privateGet(this, _responseType);
|
|
263
|
+
const data = __privateGet(this, _data);
|
|
264
|
+
try {
|
|
265
|
+
this.tryRunBeforeHooks();
|
|
266
|
+
const response = await axios({
|
|
267
|
+
method,
|
|
268
|
+
url,
|
|
269
|
+
headers,
|
|
270
|
+
data,
|
|
271
|
+
responseType,
|
|
272
|
+
validateStatus: function(status) {
|
|
273
|
+
return status >= 100 && status < 500;
|
|
274
|
+
},
|
|
275
|
+
transformResponse: transformResponse.bind(null, __privateGet(this, _allowPlainText))
|
|
276
|
+
});
|
|
277
|
+
const instance = this.makeResponse(response);
|
|
278
|
+
this.tryRunAfterHooks(instance);
|
|
279
|
+
return instance;
|
|
280
|
+
} catch (e) {
|
|
281
|
+
const error = e;
|
|
282
|
+
const message = `HTTP Client failed while while making request to ${url} with:
|
|
283
|
+
* headers: ${JSON.stringify(headers, null, 2)}
|
|
284
|
+
|
|
285
|
+
* data: ${data && JSON.stringify(data, null, 2)}`;
|
|
286
|
+
throw new AutomationError2(message, { cause: error });
|
|
287
|
+
} finally {
|
|
288
|
+
__privateGet(this, _headers).clear();
|
|
289
|
+
__privateGet(this, _params).clear();
|
|
290
|
+
__privateSet(this, _route, []);
|
|
291
|
+
__privateSet(this, _url, "");
|
|
292
|
+
__privateSet(this, _responseType, void 0);
|
|
293
|
+
__privateSet(this, _data, void 0);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
tryRunBeforeHooks() {
|
|
297
|
+
let index = 0;
|
|
298
|
+
try {
|
|
299
|
+
for (const hook of __privateGet(this, _onBeforeSend)) {
|
|
300
|
+
hook(this.currentState);
|
|
301
|
+
index++;
|
|
302
|
+
}
|
|
303
|
+
} catch (e) {
|
|
304
|
+
const error = e;
|
|
305
|
+
const message = `HTTP Client encountered an error while running 'onBeforeRequest' hooks at index ${index}`;
|
|
306
|
+
throw new AutomationError2(message, { cause: error });
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
tryRunAfterHooks(response) {
|
|
310
|
+
let index = 0;
|
|
311
|
+
try {
|
|
312
|
+
for (const hook of __privateGet(this, _onAfterSend)) {
|
|
313
|
+
hook(response);
|
|
314
|
+
index++;
|
|
315
|
+
}
|
|
316
|
+
} catch (e) {
|
|
317
|
+
const error = e;
|
|
318
|
+
const message = `HTTP Client encountered an error while running 'onAfterRequest' hooks at index ${index}`;
|
|
319
|
+
throw new AutomationError2(message, { cause: error });
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
makeResponse(res) {
|
|
323
|
+
const { status, data, statusText, headers } = res;
|
|
324
|
+
const parsed = __privateGet(this, _schemaMap).validate(
|
|
325
|
+
status,
|
|
326
|
+
data,
|
|
327
|
+
__privateGet(this, _requireSchema)
|
|
328
|
+
);
|
|
329
|
+
const params = Object.fromEntries(__privateGet(this, _params));
|
|
330
|
+
const url = urlJoinP(__privateGet(this, _url), __privateGet(this, _route), params);
|
|
331
|
+
return plainToClass(HTTPResponse, {
|
|
332
|
+
status,
|
|
333
|
+
statusText,
|
|
334
|
+
headers,
|
|
335
|
+
data: parsed,
|
|
336
|
+
request: {
|
|
337
|
+
url
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
_headers = new WeakMap();
|
|
343
|
+
_params = new WeakMap();
|
|
344
|
+
_url = new WeakMap();
|
|
345
|
+
_route = new WeakMap();
|
|
346
|
+
_method = new WeakMap();
|
|
347
|
+
_schemaMap = new WeakMap();
|
|
348
|
+
_responseType = new WeakMap();
|
|
349
|
+
_data = new WeakMap();
|
|
350
|
+
_requireSchema = new WeakMap();
|
|
351
|
+
_allowPlainText = new WeakMap();
|
|
352
|
+
_onBeforeSend = new WeakMap();
|
|
353
|
+
_onAfterSend = new WeakMap();
|
|
354
|
+
HTTPRequestBuilder = __decorateClass([
|
|
355
|
+
Fixture(LIFE_CYCLE.Transient)
|
|
356
|
+
], HTTPRequestBuilder);
|
|
357
|
+
function transformResponse(allowPlainText, data) {
|
|
358
|
+
if (isJson(data)) {
|
|
359
|
+
return JSON.parse(data);
|
|
360
|
+
}
|
|
361
|
+
if (["true", "false"].includes(data)) {
|
|
362
|
+
return JSON.parse(data);
|
|
363
|
+
}
|
|
364
|
+
const asNumber = Number(data);
|
|
365
|
+
if (!isNaN(asNumber)) {
|
|
366
|
+
return asNumber;
|
|
367
|
+
}
|
|
368
|
+
if (allowPlainText) {
|
|
369
|
+
return data;
|
|
370
|
+
}
|
|
371
|
+
const response = highlight(data, { language: "html" });
|
|
372
|
+
const message = [
|
|
373
|
+
`HTTP Client received a response which could not be parsed as JSON, and plain text responses were not configured for this request, Instead the body was:`,
|
|
374
|
+
" ",
|
|
375
|
+
response
|
|
376
|
+
];
|
|
377
|
+
throw new AutomationError2(message.join("\n"));
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// src/http.ts
|
|
381
|
+
import { Fixture as Fixture2, LIFE_CYCLE as LIFE_CYCLE2 } from "@autometa/app";
|
|
382
|
+
var _url2, _route2, _headers2, _requireSchema2, _schemaMap2, _onBeforeSend2, _onAfterSend2, _allowPlainText2;
|
|
383
|
+
var HTTP = class {
|
|
384
|
+
constructor() {
|
|
385
|
+
__privateAdd(this, _url2, void 0);
|
|
386
|
+
__privateAdd(this, _route2, []);
|
|
387
|
+
__privateAdd(this, _headers2, /* @__PURE__ */ new Map());
|
|
388
|
+
__privateAdd(this, _requireSchema2, false);
|
|
389
|
+
__privateAdd(this, _schemaMap2, new SchemaMap());
|
|
390
|
+
__privateAdd(this, _onBeforeSend2, []);
|
|
391
|
+
__privateAdd(this, _onAfterSend2, []);
|
|
392
|
+
__privateAdd(this, _allowPlainText2, false);
|
|
393
|
+
}
|
|
394
|
+
allowPlainText(value) {
|
|
395
|
+
__privateSet(this, _allowPlainText2, value);
|
|
396
|
+
return this;
|
|
397
|
+
}
|
|
398
|
+
requireSchema(value) {
|
|
399
|
+
__privateSet(this, _requireSchema2, value);
|
|
400
|
+
return this;
|
|
401
|
+
}
|
|
402
|
+
url(url) {
|
|
403
|
+
__privateSet(this, _url2, url);
|
|
404
|
+
return this;
|
|
405
|
+
}
|
|
406
|
+
sharedOnBeforeSend(hook) {
|
|
407
|
+
__privateGet(this, _onBeforeSend2).push(hook);
|
|
408
|
+
return this;
|
|
409
|
+
}
|
|
410
|
+
sharedOnReceiveResponse(hook) {
|
|
411
|
+
__privateGet(this, _onAfterSend2).push(hook);
|
|
412
|
+
return this;
|
|
413
|
+
}
|
|
414
|
+
onBeforeSend(hook) {
|
|
415
|
+
return this.builder().onBeforeSend(hook);
|
|
416
|
+
}
|
|
417
|
+
onReceiveResponse(hook) {
|
|
418
|
+
return this.builder().onReceivedResponse(hook);
|
|
419
|
+
}
|
|
420
|
+
shareSchema(parser, ...args) {
|
|
421
|
+
__privateGet(this, _schemaMap2).register(parser, ...args);
|
|
422
|
+
return this;
|
|
423
|
+
}
|
|
424
|
+
schema(parser, ...args) {
|
|
425
|
+
return this.builder().schema(parser, ...args);
|
|
426
|
+
}
|
|
427
|
+
sharedRoute(...route) {
|
|
428
|
+
__privateGet(this, _route2).push(...route);
|
|
429
|
+
return this;
|
|
430
|
+
}
|
|
431
|
+
param(name, value) {
|
|
432
|
+
return this.builder().param(name, value);
|
|
433
|
+
}
|
|
434
|
+
params(dict) {
|
|
435
|
+
return this.builder().params(dict);
|
|
436
|
+
}
|
|
437
|
+
data(data) {
|
|
438
|
+
return this.builder().data(data);
|
|
439
|
+
}
|
|
440
|
+
sharedHeader(name, value) {
|
|
441
|
+
__privateGet(this, _headers2).set(name, value);
|
|
442
|
+
return this;
|
|
443
|
+
}
|
|
444
|
+
route(...route) {
|
|
445
|
+
return this.builder().route(...route);
|
|
446
|
+
}
|
|
447
|
+
header(name, value) {
|
|
448
|
+
return this.builder().header(name, value);
|
|
449
|
+
}
|
|
450
|
+
headers(dict) {
|
|
451
|
+
return this.builder().headers(dict);
|
|
452
|
+
}
|
|
453
|
+
get() {
|
|
454
|
+
return this.builder().get();
|
|
455
|
+
}
|
|
456
|
+
builder() {
|
|
457
|
+
return new HTTPRequestBuilder(__privateGet(this, _schemaMap2)).url(__privateGet(this, _url2)).route(...__privateGet(this, _route2)).allowPlainText(__privateGet(this, _allowPlainText2)).headers(Object.fromEntries(__privateGet(this, _headers2))).requireSchema(__privateGet(this, _requireSchema2)).onBeforeSend((state) => {
|
|
458
|
+
__privateGet(this, _onBeforeSend2).forEach((it) => it(state));
|
|
459
|
+
}).onReceivedResponse((state) => {
|
|
460
|
+
__privateGet(this, _onAfterSend2).forEach((it) => it(state));
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
_url2 = new WeakMap();
|
|
465
|
+
_route2 = new WeakMap();
|
|
466
|
+
_headers2 = new WeakMap();
|
|
467
|
+
_requireSchema2 = new WeakMap();
|
|
468
|
+
_schemaMap2 = new WeakMap();
|
|
469
|
+
_onBeforeSend2 = new WeakMap();
|
|
470
|
+
_onAfterSend2 = new WeakMap();
|
|
471
|
+
_allowPlainText2 = new WeakMap();
|
|
472
|
+
HTTP = __decorateClass([
|
|
473
|
+
Fixture2(LIFE_CYCLE2.Transient)
|
|
474
|
+
], HTTP);
|
|
475
|
+
export {
|
|
476
|
+
DerivedHTTPResponse,
|
|
477
|
+
HTTP,
|
|
478
|
+
HTTPRequestBuilder,
|
|
479
|
+
HTTPResponse,
|
|
480
|
+
IsStatusCode,
|
|
481
|
+
SchemaMap,
|
|
482
|
+
assertIsStatusCode
|
|
483
|
+
};
|
|
484
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/http.builder.ts","../../src/http.response.ts","../../src/schema.map.ts","../../src/http.ts"],"sourcesContent":["import { Fixture, LIFE_CYCLE } from \"@autometa/app\";\nimport { AutomationError } from \"@autometa/errors\";\nimport axios, { AxiosResponse, Method, ResponseType } from \"axios\";\nimport { plainToClass } from \"class-transformer\";\nimport { urlJoinP } from \"url-join-ts\";\nimport { HTTPResponse } from \"./http.response\";\nimport { SchemaMap } from \"./schema.map\";\nimport { SchemaParser, StatusCode } from \"./types\";\nimport isJson from \"@stdlib/assert-is-json\";\nimport highlight from \"cli-highlight\";\nexport type RequestState = {\n headers: Map<string, string>;\n params: Map<string, string>;\n url: string;\n route: string[];\n responseType: ResponseType | undefined;\n data: unknown;\n method: Method;\n get fullUrl(): string;\n};\n\nexport type RequestHook = (state: RequestState) => unknown;\nexport type ResponseHook<T> = (state: HTTPResponse<T>) => unknown;\n\n@Fixture(LIFE_CYCLE.Transient)\nexport class HTTPRequestBuilder {\n #headers = new Map<string, string>();\n #params = new Map<string, string>();\n #url: string;\n #route: string[] = [];\n #method: Method;\n #schemaMap = new SchemaMap();\n #responseType: ResponseType | undefined = \"json\";\n #data: unknown;\n #requireSchema = false;\n #allowPlainText = false;\n #onBeforeSend: RequestHook[] = [];\n #onAfterSend: ResponseHook<unknown>[] = [];\n constructor(map: SchemaMap) {\n this.#schemaMap = new SchemaMap().including(map);\n }\n requireSchema(value: boolean) {\n this.#requireSchema = value;\n return this;\n }\n get currentState(): RequestState {\n const fullUrl = this.currentUrl;\n return {\n headers: this.#headers,\n params: this.#params,\n url: this.#url,\n route: this.#route,\n responseType: this.#responseType,\n data: this.#data,\n method: this.#method,\n fullUrl\n };\n }\n\n get currentUrl() {\n const params = Object.fromEntries(this.#params);\n return urlJoinP(this.#url, this.#route, params);\n }\n\n url(url: string) {\n this.#url = url;\n return this;\n }\n allowPlainText(value: boolean) {\n this.#allowPlainText = value;\n return this;\n }\n schema(parser: SchemaParser, ...codes: number[]): HTTPRequestBuilder;\n schema(\n parser: SchemaParser,\n ...range: { from: number; to: number }[]\n ): HTTPRequestBuilder;\n\n schema(\n parser: SchemaParser,\n ...args: (number | { from: number; to: number })[]\n ) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.#schemaMap.register(parser, ...(args as any));\n return this;\n }\n\n onBeforeSend(hook: RequestHook) {\n this.#onBeforeSend.push(hook);\n return this;\n }\n\n onReceivedResponse(hook: ResponseHook<unknown>) {\n this.#onAfterSend.push(hook);\n return this;\n }\n\n route(...route: (string | number | boolean)[]) {\n this.#route.push(...route.map((it) => `${it}`));\n return this;\n }\n\n header(name: string, value: string) {\n this.#headers.set(name, value);\n return this;\n }\n\n headers(dict: Record<string, string>) {\n Object.entries(dict).forEach(([name, value]) =>\n this.#headers.set(name, value)\n );\n return this;\n }\n\n param(name: string, value: string) {\n this.#params.set(name, value);\n return this;\n }\n\n params(dict: Record<string, string>) {\n Object.entries(dict).forEach(([name, value]) =>\n this.#params.set(name, value)\n );\n return this;\n }\n\n data<T>(data: T) {\n this.#data = data;\n return this;\n }\n\n async post<TReturn>(): Promise<HTTPResponse<TReturn>> {\n return this._request(\"POST\");\n }\n\n async get<TReturn>(): Promise<HTTPResponse<TReturn>> {\n return this._request(\"GET\");\n }\n\n async delete<TReturn>(): Promise<HTTPResponse<TReturn>> {\n return this._request(\"DELETE\");\n }\n\n async put<TReturn>(): Promise<HTTPResponse<TReturn>> {\n return this._request(\"PUT\");\n }\n\n private async _request<T>(method: Method) {\n this.#method = method;\n const url = this.currentUrl;\n const headers = this.#headers && Object.fromEntries(this.#headers);\n const responseType = this.#responseType;\n const data = this.#data;\n try {\n this.tryRunBeforeHooks();\n const response = await axios({\n method,\n url,\n headers,\n data,\n responseType,\n validateStatus: function (status) {\n return status >= 100 && status < 500;\n },\n transformResponse: transformResponse.bind(null, this.#allowPlainText)\n });\n const instance = this.makeResponse<T>(response);\n\n this.tryRunAfterHooks<T>(instance);\n return instance;\n } catch (e) {\n const error = e as Error;\n const message = `HTTP Client failed while while making request to ${url} with:\n* headers: ${JSON.stringify(headers, null, 2)}\n\n* data: ${data && JSON.stringify(data, null, 2)}`;\n throw new AutomationError(message, { cause: error });\n } finally {\n this.#headers.clear();\n this.#params.clear();\n this.#route = [];\n this.#url = \"\";\n this.#responseType = undefined;\n this.#data = undefined;\n }\n }\n\n private tryRunBeforeHooks() {\n let index = 0;\n try {\n for (const hook of this.#onBeforeSend) {\n hook(this.currentState);\n index++;\n }\n } catch (e) {\n const error = e as Error;\n const message = `HTTP Client encountered an error while running 'onBeforeRequest' hooks at index ${index}`;\n throw new AutomationError(message, { cause: error });\n }\n }\n private tryRunAfterHooks<T>(response: HTTPResponse<T>) {\n let index = 0;\n try {\n for (const hook of this.#onAfterSend) {\n hook(response);\n index++;\n }\n } catch (e) {\n const error = e as Error;\n const message = `HTTP Client encountered an error while running 'onAfterRequest' hooks at index ${index}`;\n throw new AutomationError(message, { cause: error });\n }\n }\n makeResponse<T>(res: AxiosResponse) {\n const { status, data, statusText, headers } = res;\n const parsed = this.#schemaMap.validate<T>(\n status as StatusCode,\n data,\n this.#requireSchema\n );\n const params = Object.fromEntries(this.#params);\n const url = urlJoinP(this.#url, this.#route, params);\n return plainToClass(HTTPResponse<T>, {\n status,\n statusText,\n headers,\n data: parsed,\n request: {\n url\n }\n });\n }\n}\n\nfunction transformResponse(allowPlainText: boolean, data: string) {\n if (isJson(data)) {\n return JSON.parse(data);\n }\n if ([\"true\", \"false\"].includes(data)) {\n return JSON.parse(data);\n }\n const asNumber = Number(data);\n if (!isNaN(asNumber)) {\n return asNumber;\n }\n if (allowPlainText) {\n return data;\n }\n const response = highlight(data, { language: \"html\" });\n const message = [\n `HTTP Client received a response which could not be parsed as JSON, and plain text responses were not configured for this request, Instead the body was:`,\n \" \",\n response\n ];\n throw new AutomationError(message.join(\"\\n\"));\n}\n","export class HTTPResponse<T> {\n status: number;\n statusText: string;\n data: T;\n headers: Record<string, string>;\n request: {\n url: string;\n };\n\n static fromRaw<T>(\n data: T,\n status: number,\n statusText: string,\n headers: Record<string, string>,\n url: string\n ) {\n const response = new HTTPResponse<T>();\n response.data = data;\n response.status = status;\n response.statusText = statusText;\n response.headers = headers;\n response.request = {\n url\n };\n return response;\n }\n static derive<TOriginal, TDerived>(\n original: HTTPResponse<TOriginal>,\n data: TDerived\n ): HTTPResponse<TDerived>;\n static derive<TOriginal, TDerived>(\n original: HTTPResponse<TOriginal>,\n data: (original: TOriginal) => TDerived\n ): HTTPResponse<TDerived>;\n static derive<TOriginal, TDerived>(\n original: HTTPResponse<TOriginal>,\n data: TDerived | ((original: TOriginal) => TDerived)\n ) {\n const response = new DerivedHTTPResponse<TDerived, TOriginal>();\n if (typeof data === \"function\") {\n const fn = data as (original: TOriginal) => TDerived;\n response.data = fn(original.data);\n } else {\n response.data = data;\n }\n response.status = original.status;\n response.statusText = original.statusText;\n response.headers = original.headers;\n response.request = original.request;\n response.actual = original as HTTPResponse<TOriginal>;\n return response;\n }\n}\n\nexport class DerivedHTTPResponse<T, K> extends HTTPResponse<T> {\n actual: HTTPResponse<K>;\n}\n","import { StatusCode, SchemaParser } from \"./types\";\nimport { AutomationError } from \"@autometa/errors\";\nimport { StatusCodes } from \"@autometa/status-codes\";\n\nexport class SchemaMap {\n #children: SchemaMap[] = [];\n #map: Map<StatusCode, SchemaParser> = new Map();\n register(\n parser: SchemaParser,\n ...codes: StatusCode[]\n ): (typeof parser)[\"parse\"];\n register(\n parser: SchemaParser,\n ...range: { from: StatusCode; to: StatusCode }[]\n ): (typeof parser)[\"parse\"];\n register(\n parser: SchemaParser,\n ...args: (StatusCode | { from: StatusCode; to: StatusCode })[]\n ) {\n args.forEach((arg) => {\n if (typeof arg === \"number\") {\n this.registerSingle(parser, arg);\n } else {\n this.registerRange(parser, arg);\n }\n });\n return parser.parse;\n }\n\n registerSingle(parser: SchemaParser, ...codes: StatusCode[]) {\n codes.forEach((code) => {\n if (this.#map.has(code)) {\n throw new AutomationError(\n `Status code ${code} is already registered with a parser`\n );\n }\n assertIsStatusCode(code);\n this.#map.set(code, parser);\n });\n }\n\n including(map: SchemaMap) {\n this.#children.includes(map);\n return this;\n }\n registerRange(\n parser: SchemaParser,\n ...range: { from: StatusCode; to: StatusCode }[]\n ) {\n range.forEach(({ from, to }) => {\n assertIsStatusCode(from);\n assertIsStatusCode(to);\n for (let i = from; i <= to; i++) {\n if (!IsStatusCode(i)) {\n continue;\n }\n if (this.#map.has(i)) {\n throw new AutomationError(\n `Status code ${i} is already registered with a parser`\n );\n }\n this.#map.set(i, parser);\n }\n });\n }\n\n get(status: StatusCode): SchemaParser | undefined {\n assertIsStatusCode(status);\n const local = this.#map.get(status);\n if (local) {\n return local;\n }\n const nested = this.#children.find((it) => it.#map.has(status));\n return nested?.get(status);\n }\n\n validate<T>(status: StatusCode, response: T, strict: boolean) {\n const parser = this.get(status);\n if (!parser) {\n if (!strict) {\n return response;\n }\n throw new AutomationError(\n `No schema parser registered for status code ${status} and 'requireSchema' is set to true`\n );\n }\n return parser.parse(response);\n }\n}\n\nexport function assertIsStatusCode(value: number): asserts value is StatusCode {\n const result = Object.values(StatusCodes)\n .map((it) => it.status as number)\n .includes(value);\n if (!result) {\n throw new AutomationError(\n `Expected status code ${value} to be a valid status code, but it is not a known HTTP codeF`\n );\n }\n}\n\nexport function IsStatusCode(value: number): value is StatusCode {\n return Object.values(StatusCodes)\n .map((it) => it.status as number)\n .includes(value);\n}\n","import { Fixture, LIFE_CYCLE } from \"@autometa/app\";\nimport { HTTPRequestBuilder, RequestHook, ResponseHook } from \"./http.builder\";\nimport { SchemaMap } from \"./schema.map\";\nimport { SchemaParser, StatusCode } from \"./types\";\n@Fixture(LIFE_CYCLE.Transient)\nexport class HTTP {\n #url: string;\n #route: string[] = [];\n #headers = new Map<string, string>();\n #requireSchema = false;\n #schemaMap: SchemaMap = new SchemaMap();\n #onBeforeSend: RequestHook[] = [];\n #onAfterSend: ResponseHook<unknown>[] = [];\n #allowPlainText = false;\n\n allowPlainText(value: boolean) {\n this.#allowPlainText = value;\n return this;\n }\n requireSchema(value: boolean) {\n this.#requireSchema = value;\n return this;\n }\n\n url(url: string) {\n this.#url = url;\n return this;\n }\n\n sharedOnBeforeSend(hook: RequestHook) {\n this.#onBeforeSend.push(hook);\n return this;\n }\n\n sharedOnReceiveResponse(hook: ResponseHook<unknown>) {\n this.#onAfterSend.push(hook);\n return this;\n }\n\n onBeforeSend(hook: RequestHook) {\n return this.builder().onBeforeSend(hook);\n }\n\n onReceiveResponse(hook: ResponseHook<unknown>) {\n return this.builder().onReceivedResponse(hook);\n }\n\n shareSchema(parser: SchemaParser, ...codes: StatusCode[]): HTTP;\n shareSchema(\n parser: SchemaParser,\n ...range: { from: StatusCode; to: StatusCode }[]\n ): HTTP;\n shareSchema(\n parser: SchemaParser,\n ...args: (StatusCode | { from: StatusCode; to: StatusCode })[]\n ) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.#schemaMap.register(parser, ...(args as any));\n return this;\n }\n\n schema(parser: SchemaParser, ...codes: StatusCode[]): HTTPRequestBuilder;\n schema(\n parser: SchemaParser,\n ...range: { from: StatusCode; to: StatusCode }[]\n ): HTTPRequestBuilder;\n schema(\n parser: SchemaParser,\n ...args: (StatusCode | { from: StatusCode; to: StatusCode })[]\n ) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return this.builder().schema(parser, ...(args as any));\n }\n\n sharedRoute(...route: string[]) {\n this.#route.push(...route);\n return this;\n }\n\n param(name: string, value: string) {\n return this.builder().param(name, value);\n }\n\n params(dict: Record<string, string>) {\n return this.builder().params(dict);\n }\n\n data<T>(data: T) {\n return this.builder().data(data);\n }\n\n sharedHeader(name: string, value: string) {\n this.#headers.set(name, value);\n return this;\n }\n\n route(...route: (string | number | boolean)[]) {\n return this.builder().route(...route);\n }\n\n header(name: string, value: string) {\n return this.builder().header(name, value);\n }\n\n headers(dict: Record<string, string>) {\n return this.builder().headers(dict);\n }\n\n get() {\n return this.builder().get();\n }\n\n private builder() {\n return new HTTPRequestBuilder(this.#schemaMap)\n .url(this.#url)\n .route(...this.#route)\n .allowPlainText(this.#allowPlainText)\n .headers(Object.fromEntries(this.#headers))\n .requireSchema(this.#requireSchema)\n .onBeforeSend((state) => {\n this.#onBeforeSend.forEach((it) => it(state));\n })\n .onReceivedResponse((state) => {\n this.#onAfterSend.forEach((it) => it(state));\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,kBAAkB;AACpC,SAAS,mBAAAA,wBAAuB;AAChC,OAAO,WAAoD;AAC3D,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;;;ACJlB,IAAM,eAAN,MAAM,cAAgB;AAAA,EAS3B,OAAO,QACL,MACA,QACA,YACA,SACA,KACA;A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AO,IAAI;AAAA,EACnC;AAAA,EAEA,KAAQ,MAAS;AACf,WAAO,KAAK,QAAQ,EAAE,KAAK,IAAI;AAAA,EACjC;AAAA,EAEA,aAAa,MAAc,OAAe;AACxC,uBAAKC,WAAS,IAAI,MAAM,KAAK;AAC7B,WAAO;AAAA,EACT;AAAA,EAEA,SAAS,OAAsC;AAC7C,WAAO,KAAK,QAAQ,EAAE,MAAM,GAAG,KAAK;AAAA,EACtC;AAAA,EAEA,OAAO,MAAc,OAAe;AAClC,WAAO,KAAK,QAAQ,EAAE,OAAO,MAAM,KAAK;AAAA,EAC1C;AAAA,EAEA,QAAQ,MAA8B;AACpC,WAAO,KAAK,QAAQ,EAAE,QAAQ,IAAI;AAAA,EACpC;AAAA,EAEA,MAAM;AACJ,WAAO,KAAK,QAAQ,EAAE,IAAI;AAAA,EAC5B;AAAA,EAEQ,UAAU;AAChB,WAAO,IAAI,mBAAmB,mBAAKE,YAAU,EAC1C,IAAI,mBAAKJ,MAAI,EACb,MAAM,GAAG,mBAAKC,QAAM,EACpB,eAAe,mBAAKM,iBAAe,EACnC,QAAQ,OAAO,YAAY,mBAAKL,UAAQ,CAAC,EACzC,cAAc,mBAAKC,gBAAc,EACjC,aAAa,CAAC,UAAU;AACvB,yBAAKE,gBAAc,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC;AAAA,IAC9C,CAAC,EACA,mBAAmB,CAAC,UAAU;AAC7B,yBAAKC,eAAa,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC;AAAA,IAC7C,CAAC;AAAA,EACL;AACF;AAxHEN,QAAA;AACAC,UAAA;AACAC,YAAA;AACAC,kBAAA;AACAC,cAAA;AACAC,iBAAA;AACAC,gBAAA;AACAC,mBAAA;AARW,OAAN;AAAA,EADNC,SAAQC,YAAW,SAAS;AAAA,GAChB;","names":["AutomationError","AutomationError","Fixture","LIFE_CYCLE","_url","_route","_headers","_requireSchema","_schemaMap","_onBeforeSend","_onAfterSend","_allowPlainText","Fixture","LIFE_CYCLE"]}
|