@zthun/webigail-http 1.2.0 → 2.0.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/dist/index.cjs +1011 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +1011 -0
- package/dist/index.js.map +1 -0
- package/dist/{types/result/http-code.d.ts → result/http-code.d.mts} +5 -5
- package/dist/{types/result/http-result.d.ts → result/http-result.d.mts} +1 -1
- package/dist/{types/service/http-service-mock.d.ts → service/http-service-mock.d.mts} +3 -3
- package/dist/{types/service/http-service.d.ts → service/http-service.d.mts} +2 -2
- package/package.json +14 -9
- package/dist/lib/index.esm.js +0 -2
- package/dist/lib/index.esm.js.map +0 -1
- package/dist/lib/index.js +0 -2
- package/dist/lib/index.js.map +0 -1
- package/dist/types/index.d.ts +0 -10
- /package/dist/{types/request/http-request.d.ts → request/http-request.d.mts} +0 -0
- /package/dist/{types/result/http-code-client.d.ts → result/http-code-client.d.mts} +0 -0
- /package/dist/{types/result/http-code-informational-response.d.ts → result/http-code-informational-response.d.mts} +0 -0
- /package/dist/{types/result/http-code-redirection.d.ts → result/http-code-redirection.d.mts} +0 -0
- /package/dist/{types/result/http-code-server.d.ts → result/http-code-server.d.mts} +0 -0
- /package/dist/{types/result/http-code-success.d.ts → result/http-code-success.d.mts} +0 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1011 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => {
|
|
5
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
return value;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
|
+
const axios = require("axios");
|
|
10
|
+
var ZHttpMethod = /* @__PURE__ */ ((ZHttpMethod2) => {
|
|
11
|
+
ZHttpMethod2["Get"] = "get";
|
|
12
|
+
ZHttpMethod2["Put"] = "put";
|
|
13
|
+
ZHttpMethod2["Post"] = "post";
|
|
14
|
+
ZHttpMethod2["Delete"] = "delete";
|
|
15
|
+
ZHttpMethod2["Patch"] = "patch";
|
|
16
|
+
ZHttpMethod2["Options"] = "options";
|
|
17
|
+
ZHttpMethod2["Head"] = "head";
|
|
18
|
+
return ZHttpMethod2;
|
|
19
|
+
})(ZHttpMethod || {});
|
|
20
|
+
class ZHttpRequestBuilder {
|
|
21
|
+
/**
|
|
22
|
+
* Initializes a new instance of this object.
|
|
23
|
+
*/
|
|
24
|
+
constructor() {
|
|
25
|
+
__publicField(this, "_request");
|
|
26
|
+
/**
|
|
27
|
+
* Constructs a get request.
|
|
28
|
+
*
|
|
29
|
+
* @returns
|
|
30
|
+
* This object.
|
|
31
|
+
*/
|
|
32
|
+
__publicField(this, "get", this._method.bind(
|
|
33
|
+
this,
|
|
34
|
+
"get"
|
|
35
|
+
/* Get */
|
|
36
|
+
));
|
|
37
|
+
/**
|
|
38
|
+
* Constructs a post request.
|
|
39
|
+
*
|
|
40
|
+
* @returns
|
|
41
|
+
* This object.
|
|
42
|
+
*/
|
|
43
|
+
__publicField(this, "post", this._method.bind(
|
|
44
|
+
this,
|
|
45
|
+
"post"
|
|
46
|
+
/* Post */
|
|
47
|
+
));
|
|
48
|
+
/**
|
|
49
|
+
* Constructs a put request.
|
|
50
|
+
*
|
|
51
|
+
* @returns
|
|
52
|
+
* This object.
|
|
53
|
+
*/
|
|
54
|
+
__publicField(this, "put", this._method.bind(
|
|
55
|
+
this,
|
|
56
|
+
"put"
|
|
57
|
+
/* Put */
|
|
58
|
+
));
|
|
59
|
+
/**
|
|
60
|
+
* Constructs a delete request.
|
|
61
|
+
*
|
|
62
|
+
* @returns
|
|
63
|
+
* This object.
|
|
64
|
+
*/
|
|
65
|
+
__publicField(this, "delete", this._method.bind(
|
|
66
|
+
this,
|
|
67
|
+
"delete"
|
|
68
|
+
/* Delete */
|
|
69
|
+
));
|
|
70
|
+
/**
|
|
71
|
+
* Constructs a patch request.
|
|
72
|
+
*
|
|
73
|
+
* @returns
|
|
74
|
+
* This object.
|
|
75
|
+
*/
|
|
76
|
+
__publicField(this, "patch", this._method.bind(
|
|
77
|
+
this,
|
|
78
|
+
"patch"
|
|
79
|
+
/* Patch */
|
|
80
|
+
));
|
|
81
|
+
/**
|
|
82
|
+
* Constructs a options request.
|
|
83
|
+
*
|
|
84
|
+
* @returns
|
|
85
|
+
* This object.
|
|
86
|
+
*/
|
|
87
|
+
__publicField(this, "options", this._method.bind(
|
|
88
|
+
this,
|
|
89
|
+
"options"
|
|
90
|
+
/* Options */
|
|
91
|
+
));
|
|
92
|
+
/**
|
|
93
|
+
* Constructs a head request.
|
|
94
|
+
*
|
|
95
|
+
* @returns
|
|
96
|
+
* This object.
|
|
97
|
+
*/
|
|
98
|
+
__publicField(this, "head", this._method.bind(
|
|
99
|
+
this,
|
|
100
|
+
"head"
|
|
101
|
+
/* Head */
|
|
102
|
+
));
|
|
103
|
+
this._request = {
|
|
104
|
+
method: "get",
|
|
105
|
+
url: ""
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Sets the method.
|
|
110
|
+
*
|
|
111
|
+
* @param method -
|
|
112
|
+
* The method to set.
|
|
113
|
+
* @param body -
|
|
114
|
+
* The post, put, or patch body.
|
|
115
|
+
*
|
|
116
|
+
* @returns
|
|
117
|
+
* This object.
|
|
118
|
+
*/
|
|
119
|
+
_method(method, body) {
|
|
120
|
+
this._request.method = method;
|
|
121
|
+
this._request.body = body;
|
|
122
|
+
if (this._request.body === void 0) {
|
|
123
|
+
delete this._request.body;
|
|
124
|
+
}
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Sets the url to make the request from.
|
|
129
|
+
*
|
|
130
|
+
* @param url -
|
|
131
|
+
* The url to make the request to.
|
|
132
|
+
*
|
|
133
|
+
* @returns
|
|
134
|
+
* This object.
|
|
135
|
+
*/
|
|
136
|
+
url(url) {
|
|
137
|
+
this._request.url = url;
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Sets the timeout for the url.
|
|
142
|
+
*
|
|
143
|
+
* @param ms -
|
|
144
|
+
* The total number of milliseconds to wait.
|
|
145
|
+
*
|
|
146
|
+
* @returns
|
|
147
|
+
* The object.
|
|
148
|
+
*/
|
|
149
|
+
timeout(ms) {
|
|
150
|
+
this._request.timeout = ms;
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Sets the headers.
|
|
155
|
+
*
|
|
156
|
+
* @param headers -
|
|
157
|
+
* The headers to set.
|
|
158
|
+
*
|
|
159
|
+
* @returns
|
|
160
|
+
* This object.
|
|
161
|
+
*/
|
|
162
|
+
headers(headers) {
|
|
163
|
+
this._request.headers = headers;
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Sets an individual header.
|
|
168
|
+
*
|
|
169
|
+
* @param key -
|
|
170
|
+
* The header key to set.
|
|
171
|
+
* @param value -
|
|
172
|
+
* The value to set.
|
|
173
|
+
*
|
|
174
|
+
* @returns
|
|
175
|
+
* This object.
|
|
176
|
+
*/
|
|
177
|
+
header(key, value) {
|
|
178
|
+
this._request.headers = this._request.headers || {};
|
|
179
|
+
if (value == null) {
|
|
180
|
+
delete this._request.headers[key];
|
|
181
|
+
} else {
|
|
182
|
+
this._request.headers[key] = `${value}`;
|
|
183
|
+
}
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Copies other to this object.
|
|
188
|
+
*
|
|
189
|
+
* @param other -
|
|
190
|
+
* The request to copy.
|
|
191
|
+
*
|
|
192
|
+
* @returns
|
|
193
|
+
* This object.
|
|
194
|
+
*/
|
|
195
|
+
copy(other) {
|
|
196
|
+
this._request = JSON.parse(JSON.stringify(other));
|
|
197
|
+
return this;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Returns the constructed request.
|
|
201
|
+
*
|
|
202
|
+
* @returns
|
|
203
|
+
* The constructed request.
|
|
204
|
+
*/
|
|
205
|
+
build() {
|
|
206
|
+
return JSON.parse(JSON.stringify(this._request));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
var ZHttpCodeClient = /* @__PURE__ */ ((ZHttpCodeClient2) => {
|
|
210
|
+
ZHttpCodeClient2[ZHttpCodeClient2["BadRequest"] = 400] = "BadRequest";
|
|
211
|
+
ZHttpCodeClient2[ZHttpCodeClient2["Unauthorized"] = 401] = "Unauthorized";
|
|
212
|
+
ZHttpCodeClient2[ZHttpCodeClient2["PaymentRequired"] = 402] = "PaymentRequired";
|
|
213
|
+
ZHttpCodeClient2[ZHttpCodeClient2["Forbidden"] = 403] = "Forbidden";
|
|
214
|
+
ZHttpCodeClient2[ZHttpCodeClient2["NotFound"] = 404] = "NotFound";
|
|
215
|
+
ZHttpCodeClient2[ZHttpCodeClient2["MethodNotAllowed"] = 405] = "MethodNotAllowed";
|
|
216
|
+
ZHttpCodeClient2[ZHttpCodeClient2["NotAcceptable"] = 406] = "NotAcceptable";
|
|
217
|
+
ZHttpCodeClient2[ZHttpCodeClient2["ProxyAuthenticationRequired"] = 407] = "ProxyAuthenticationRequired";
|
|
218
|
+
ZHttpCodeClient2[ZHttpCodeClient2["RequestTimeout"] = 408] = "RequestTimeout";
|
|
219
|
+
ZHttpCodeClient2[ZHttpCodeClient2["Conflict"] = 409] = "Conflict";
|
|
220
|
+
ZHttpCodeClient2[ZHttpCodeClient2["Gone"] = 410] = "Gone";
|
|
221
|
+
ZHttpCodeClient2[ZHttpCodeClient2["LengthRequired"] = 411] = "LengthRequired";
|
|
222
|
+
ZHttpCodeClient2[ZHttpCodeClient2["PreconditionFailed"] = 412] = "PreconditionFailed";
|
|
223
|
+
ZHttpCodeClient2[ZHttpCodeClient2["PayloadTooLarge"] = 413] = "PayloadTooLarge";
|
|
224
|
+
ZHttpCodeClient2[ZHttpCodeClient2["URITooLong"] = 414] = "URITooLong";
|
|
225
|
+
ZHttpCodeClient2[ZHttpCodeClient2["UnsupportedMediaType"] = 415] = "UnsupportedMediaType";
|
|
226
|
+
ZHttpCodeClient2[ZHttpCodeClient2["RangeNotSatisfiable"] = 416] = "RangeNotSatisfiable";
|
|
227
|
+
ZHttpCodeClient2[ZHttpCodeClient2["ExpectationFailed"] = 417] = "ExpectationFailed";
|
|
228
|
+
ZHttpCodeClient2[ZHttpCodeClient2["ImATeapot"] = 418] = "ImATeapot";
|
|
229
|
+
ZHttpCodeClient2[ZHttpCodeClient2["MisdirectedRequest"] = 421] = "MisdirectedRequest";
|
|
230
|
+
ZHttpCodeClient2[ZHttpCodeClient2["UnProcessableEntity"] = 422] = "UnProcessableEntity";
|
|
231
|
+
ZHttpCodeClient2[ZHttpCodeClient2["Locked"] = 423] = "Locked";
|
|
232
|
+
ZHttpCodeClient2[ZHttpCodeClient2["FailedDependency"] = 424] = "FailedDependency";
|
|
233
|
+
ZHttpCodeClient2[ZHttpCodeClient2["UpgradeRequired"] = 426] = "UpgradeRequired";
|
|
234
|
+
ZHttpCodeClient2[ZHttpCodeClient2["PreconditionRequired"] = 428] = "PreconditionRequired";
|
|
235
|
+
ZHttpCodeClient2[ZHttpCodeClient2["TooManyRequests"] = 429] = "TooManyRequests";
|
|
236
|
+
ZHttpCodeClient2[ZHttpCodeClient2["RequestHeaderFieldsTooLarge"] = 431] = "RequestHeaderFieldsTooLarge";
|
|
237
|
+
ZHttpCodeClient2[ZHttpCodeClient2["UnavailableForLegalReasons"] = 451] = "UnavailableForLegalReasons";
|
|
238
|
+
return ZHttpCodeClient2;
|
|
239
|
+
})(ZHttpCodeClient || {});
|
|
240
|
+
const ZHttpCodeClientNames = {
|
|
241
|
+
[
|
|
242
|
+
400
|
|
243
|
+
/* BadRequest */
|
|
244
|
+
]: "Bad Request",
|
|
245
|
+
[
|
|
246
|
+
401
|
|
247
|
+
/* Unauthorized */
|
|
248
|
+
]: "Unauthorized",
|
|
249
|
+
[
|
|
250
|
+
402
|
|
251
|
+
/* PaymentRequired */
|
|
252
|
+
]: "Payment Required",
|
|
253
|
+
[
|
|
254
|
+
403
|
|
255
|
+
/* Forbidden */
|
|
256
|
+
]: "Forbidden",
|
|
257
|
+
[
|
|
258
|
+
404
|
|
259
|
+
/* NotFound */
|
|
260
|
+
]: "Not Found",
|
|
261
|
+
[
|
|
262
|
+
405
|
|
263
|
+
/* MethodNotAllowed */
|
|
264
|
+
]: "Method not Allowed",
|
|
265
|
+
[
|
|
266
|
+
406
|
|
267
|
+
/* NotAcceptable */
|
|
268
|
+
]: "Not Acceptable",
|
|
269
|
+
[
|
|
270
|
+
407
|
|
271
|
+
/* ProxyAuthenticationRequired */
|
|
272
|
+
]: "Proxy Authentication Required",
|
|
273
|
+
[
|
|
274
|
+
408
|
|
275
|
+
/* RequestTimeout */
|
|
276
|
+
]: "Request Timeout",
|
|
277
|
+
[
|
|
278
|
+
409
|
|
279
|
+
/* Conflict */
|
|
280
|
+
]: "Conflict",
|
|
281
|
+
[
|
|
282
|
+
410
|
|
283
|
+
/* Gone */
|
|
284
|
+
]: "Gone",
|
|
285
|
+
[
|
|
286
|
+
411
|
|
287
|
+
/* LengthRequired */
|
|
288
|
+
]: "Length Required",
|
|
289
|
+
[
|
|
290
|
+
412
|
|
291
|
+
/* PreconditionFailed */
|
|
292
|
+
]: "Precondition Failed",
|
|
293
|
+
[
|
|
294
|
+
413
|
|
295
|
+
/* PayloadTooLarge */
|
|
296
|
+
]: "Payload Too Large",
|
|
297
|
+
[
|
|
298
|
+
414
|
|
299
|
+
/* URITooLong */
|
|
300
|
+
]: "URI Too Long",
|
|
301
|
+
[
|
|
302
|
+
415
|
|
303
|
+
/* UnsupportedMediaType */
|
|
304
|
+
]: "Unsupported Media Type",
|
|
305
|
+
[
|
|
306
|
+
416
|
|
307
|
+
/* RangeNotSatisfiable */
|
|
308
|
+
]: "Range Not Satisfiable",
|
|
309
|
+
[
|
|
310
|
+
417
|
|
311
|
+
/* ExpectationFailed */
|
|
312
|
+
]: "Expectation Failed",
|
|
313
|
+
[
|
|
314
|
+
418
|
|
315
|
+
/* ImATeapot */
|
|
316
|
+
]: "I am a Teapot",
|
|
317
|
+
[
|
|
318
|
+
421
|
|
319
|
+
/* MisdirectedRequest */
|
|
320
|
+
]: "Misdirected Requested",
|
|
321
|
+
[
|
|
322
|
+
422
|
|
323
|
+
/* UnProcessableEntity */
|
|
324
|
+
]: "Entity Not Processable",
|
|
325
|
+
[
|
|
326
|
+
423
|
|
327
|
+
/* Locked */
|
|
328
|
+
]: "Locked",
|
|
329
|
+
[
|
|
330
|
+
424
|
|
331
|
+
/* FailedDependency */
|
|
332
|
+
]: "Failed Dependency",
|
|
333
|
+
[
|
|
334
|
+
426
|
|
335
|
+
/* UpgradeRequired */
|
|
336
|
+
]: "Upgrade Required",
|
|
337
|
+
[
|
|
338
|
+
428
|
|
339
|
+
/* PreconditionRequired */
|
|
340
|
+
]: "Precondition Required",
|
|
341
|
+
[
|
|
342
|
+
429
|
|
343
|
+
/* TooManyRequests */
|
|
344
|
+
]: "Too Many Requests",
|
|
345
|
+
[
|
|
346
|
+
431
|
|
347
|
+
/* RequestHeaderFieldsTooLarge */
|
|
348
|
+
]: "Request Header Fields Too Large",
|
|
349
|
+
[
|
|
350
|
+
451
|
|
351
|
+
/* UnavailableForLegalReasons */
|
|
352
|
+
]: "Unavailable for Legal Reasons"
|
|
353
|
+
};
|
|
354
|
+
const ZHttpCodeClientDescriptions = {
|
|
355
|
+
[
|
|
356
|
+
400
|
|
357
|
+
/* BadRequest */
|
|
358
|
+
]: "A bad request was sent.",
|
|
359
|
+
[
|
|
360
|
+
401
|
|
361
|
+
/* Unauthorized */
|
|
362
|
+
]: "You are not authenticated and cannot view this content.",
|
|
363
|
+
[
|
|
364
|
+
402
|
|
365
|
+
/* PaymentRequired */
|
|
366
|
+
]: "Payment is required",
|
|
367
|
+
[
|
|
368
|
+
403
|
|
369
|
+
/* Forbidden */
|
|
370
|
+
]: "You are not authorized to view this content.",
|
|
371
|
+
[
|
|
372
|
+
404
|
|
373
|
+
/* NotFound */
|
|
374
|
+
]: "The resource you are looking for could not be found.",
|
|
375
|
+
[
|
|
376
|
+
405
|
|
377
|
+
/* MethodNotAllowed */
|
|
378
|
+
]: "The requested operation was not allowed.",
|
|
379
|
+
[
|
|
380
|
+
406
|
|
381
|
+
/* NotAcceptable */
|
|
382
|
+
]: "The requested resource is not capable of generating the content for you.",
|
|
383
|
+
[
|
|
384
|
+
407
|
|
385
|
+
/* ProxyAuthenticationRequired */
|
|
386
|
+
]: "You must first authenticate your self with the proxy.",
|
|
387
|
+
[
|
|
388
|
+
408
|
|
389
|
+
/* RequestTimeout */
|
|
390
|
+
]: "The server timed out waiting for a request. Please try again.",
|
|
391
|
+
[
|
|
392
|
+
409
|
|
393
|
+
/* Conflict */
|
|
394
|
+
]: "There was a conflict with request. Try something else.",
|
|
395
|
+
[
|
|
396
|
+
410
|
|
397
|
+
/* Gone */
|
|
398
|
+
]: "The resource you requested is no longer available.",
|
|
399
|
+
[
|
|
400
|
+
411
|
|
401
|
+
/* LengthRequired */
|
|
402
|
+
]: "Your request did not specify the length of its content, which is required by the requested resource.",
|
|
403
|
+
[
|
|
404
|
+
412
|
|
405
|
+
/* PreconditionFailed */
|
|
406
|
+
]: "The server did not meet the requirements that was required to meet the request.",
|
|
407
|
+
[
|
|
408
|
+
413
|
|
409
|
+
/* PayloadTooLarge */
|
|
410
|
+
]: "The request is too large and the server cannot handle it.",
|
|
411
|
+
[
|
|
412
|
+
414
|
|
413
|
+
/* URITooLong */
|
|
414
|
+
]: "The URI provided was too long for the server to process.",
|
|
415
|
+
[
|
|
416
|
+
415
|
|
417
|
+
/* UnsupportedMediaType */
|
|
418
|
+
]: "The media type requested is not supported by the server.",
|
|
419
|
+
[
|
|
420
|
+
416
|
|
421
|
+
/* RangeNotSatisfiable */
|
|
422
|
+
]: "A portion of the file was requested by the server cannot supply said portion.",
|
|
423
|
+
[
|
|
424
|
+
417
|
|
425
|
+
/* ExpectationFailed */
|
|
426
|
+
]: "The server cannot meet the requirements of the expectation made of it.",
|
|
427
|
+
[
|
|
428
|
+
418
|
|
429
|
+
/* ImATeapot */
|
|
430
|
+
]: "Short and stout. Here is my handle, here is my spout. When I get all steamed up, hear me shout. Tip me over and pour me out!",
|
|
431
|
+
[
|
|
432
|
+
421
|
|
433
|
+
/* MisdirectedRequest */
|
|
434
|
+
]: "The request was directed at the server, but the server cannot produce a response.",
|
|
435
|
+
[
|
|
436
|
+
422
|
|
437
|
+
/* UnProcessableEntity */
|
|
438
|
+
]: "The request was well-formed but was unable to be followed due to semantic errors.",
|
|
439
|
+
[
|
|
440
|
+
423
|
|
441
|
+
/* Locked */
|
|
442
|
+
]: "The resource that is being accessed is locked.",
|
|
443
|
+
[
|
|
444
|
+
424
|
|
445
|
+
/* FailedDependency */
|
|
446
|
+
]: "The request failed because it depended on another request and that request failed.",
|
|
447
|
+
[
|
|
448
|
+
426
|
|
449
|
+
/* UpgradeRequired */
|
|
450
|
+
]: "The client needs to switch to a different protocol.",
|
|
451
|
+
[
|
|
452
|
+
428
|
|
453
|
+
/* PreconditionRequired */
|
|
454
|
+
]: "The origin server requires the request to be conditional.",
|
|
455
|
+
[
|
|
456
|
+
429
|
|
457
|
+
/* TooManyRequests */
|
|
458
|
+
]: "The user has sent too many requests in a given amount of time.",
|
|
459
|
+
[
|
|
460
|
+
431
|
|
461
|
+
/* RequestHeaderFieldsTooLarge */
|
|
462
|
+
]: "The request cannot be processed because the collective header fields are too large.",
|
|
463
|
+
[
|
|
464
|
+
451
|
|
465
|
+
/* UnavailableForLegalReasons */
|
|
466
|
+
]: "Call your lawyer!"
|
|
467
|
+
};
|
|
468
|
+
var ZHttpCodeInformationalResponse = /* @__PURE__ */ ((ZHttpCodeInformationalResponse2) => {
|
|
469
|
+
ZHttpCodeInformationalResponse2[ZHttpCodeInformationalResponse2["Continue"] = 100] = "Continue";
|
|
470
|
+
ZHttpCodeInformationalResponse2[ZHttpCodeInformationalResponse2["SwitchingProtocols"] = 101] = "SwitchingProtocols";
|
|
471
|
+
ZHttpCodeInformationalResponse2[ZHttpCodeInformationalResponse2["Processing"] = 102] = "Processing";
|
|
472
|
+
ZHttpCodeInformationalResponse2[ZHttpCodeInformationalResponse2["EarlyHints"] = 103] = "EarlyHints";
|
|
473
|
+
return ZHttpCodeInformationalResponse2;
|
|
474
|
+
})(ZHttpCodeInformationalResponse || {});
|
|
475
|
+
const ZHttpCodeInformationalResponseNames = {
|
|
476
|
+
[
|
|
477
|
+
100
|
|
478
|
+
/* Continue */
|
|
479
|
+
]: "Continue",
|
|
480
|
+
[
|
|
481
|
+
101
|
|
482
|
+
/* SwitchingProtocols */
|
|
483
|
+
]: "Switching Protocols",
|
|
484
|
+
[
|
|
485
|
+
102
|
|
486
|
+
/* Processing */
|
|
487
|
+
]: "Processing",
|
|
488
|
+
[
|
|
489
|
+
103
|
|
490
|
+
/* EarlyHints */
|
|
491
|
+
]: "Early Hints"
|
|
492
|
+
};
|
|
493
|
+
const ZHttpCodeInformationalResponseDescriptions = {
|
|
494
|
+
[
|
|
495
|
+
100
|
|
496
|
+
/* Continue */
|
|
497
|
+
]: "The client should continue to send the request body.",
|
|
498
|
+
[
|
|
499
|
+
101
|
|
500
|
+
/* SwitchingProtocols */
|
|
501
|
+
]: "The requestor has asked the server to switch protocols and the server has agreed to do so.",
|
|
502
|
+
[
|
|
503
|
+
102
|
|
504
|
+
/* Processing */
|
|
505
|
+
]: "The server has received and is processing the request, but a response is not available yet.",
|
|
506
|
+
[
|
|
507
|
+
103
|
|
508
|
+
/* EarlyHints */
|
|
509
|
+
]: "There are some early response headers available for you before the final message."
|
|
510
|
+
};
|
|
511
|
+
var ZHttpCodeRedirection = /* @__PURE__ */ ((ZHttpCodeRedirection2) => {
|
|
512
|
+
ZHttpCodeRedirection2[ZHttpCodeRedirection2["MultipleChoices"] = 300] = "MultipleChoices";
|
|
513
|
+
ZHttpCodeRedirection2[ZHttpCodeRedirection2["MovedPermanently"] = 301] = "MovedPermanently";
|
|
514
|
+
ZHttpCodeRedirection2[ZHttpCodeRedirection2["Found"] = 302] = "Found";
|
|
515
|
+
ZHttpCodeRedirection2[ZHttpCodeRedirection2["SeeOther"] = 303] = "SeeOther";
|
|
516
|
+
ZHttpCodeRedirection2[ZHttpCodeRedirection2["NotModified"] = 304] = "NotModified";
|
|
517
|
+
ZHttpCodeRedirection2[ZHttpCodeRedirection2["UseProxy"] = 305] = "UseProxy";
|
|
518
|
+
ZHttpCodeRedirection2[ZHttpCodeRedirection2["SwitchProxy"] = 306] = "SwitchProxy";
|
|
519
|
+
ZHttpCodeRedirection2[ZHttpCodeRedirection2["TemporaryRedirect"] = 307] = "TemporaryRedirect";
|
|
520
|
+
ZHttpCodeRedirection2[ZHttpCodeRedirection2["PermanentRedirect"] = 308] = "PermanentRedirect";
|
|
521
|
+
return ZHttpCodeRedirection2;
|
|
522
|
+
})(ZHttpCodeRedirection || {});
|
|
523
|
+
const ZHttpCodeRedirectionNames = {
|
|
524
|
+
[
|
|
525
|
+
300
|
|
526
|
+
/* MultipleChoices */
|
|
527
|
+
]: "Multiple Choices",
|
|
528
|
+
[
|
|
529
|
+
301
|
|
530
|
+
/* MovedPermanently */
|
|
531
|
+
]: "Moved Permanently",
|
|
532
|
+
[
|
|
533
|
+
302
|
|
534
|
+
/* Found */
|
|
535
|
+
]: "Found",
|
|
536
|
+
[
|
|
537
|
+
303
|
|
538
|
+
/* SeeOther */
|
|
539
|
+
]: "See Other",
|
|
540
|
+
[
|
|
541
|
+
304
|
|
542
|
+
/* NotModified */
|
|
543
|
+
]: "Not Modified",
|
|
544
|
+
[
|
|
545
|
+
305
|
|
546
|
+
/* UseProxy */
|
|
547
|
+
]: "Use Proxy",
|
|
548
|
+
[
|
|
549
|
+
306
|
|
550
|
+
/* SwitchProxy */
|
|
551
|
+
]: "Switch Proxy",
|
|
552
|
+
[
|
|
553
|
+
307
|
|
554
|
+
/* TemporaryRedirect */
|
|
555
|
+
]: "Temporary Redirect",
|
|
556
|
+
[
|
|
557
|
+
308
|
|
558
|
+
/* PermanentRedirect */
|
|
559
|
+
]: "Permanent Redirect"
|
|
560
|
+
};
|
|
561
|
+
const ZHttpCodeRedirectionDescriptions = {
|
|
562
|
+
[
|
|
563
|
+
300
|
|
564
|
+
/* MultipleChoices */
|
|
565
|
+
]: "Indicates multiple options for the resource from which the client may choose.",
|
|
566
|
+
[
|
|
567
|
+
301
|
|
568
|
+
/* MovedPermanently */
|
|
569
|
+
]: "This and all future requests should be directed to the given URI.",
|
|
570
|
+
[
|
|
571
|
+
302
|
|
572
|
+
/* Found */
|
|
573
|
+
]: "Tells the client to look at another url",
|
|
574
|
+
[
|
|
575
|
+
303
|
|
576
|
+
/* SeeOther */
|
|
577
|
+
]: "The response to the request can be found under another URI using the GET method.",
|
|
578
|
+
[
|
|
579
|
+
304
|
|
580
|
+
/* NotModified */
|
|
581
|
+
]: "Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match.",
|
|
582
|
+
[
|
|
583
|
+
305
|
|
584
|
+
/* UseProxy */
|
|
585
|
+
]: "The requested resource is available only through a proxy, the address for which is provided in the response.",
|
|
586
|
+
[
|
|
587
|
+
306
|
|
588
|
+
/* SwitchProxy */
|
|
589
|
+
]: 'No longer used. Originally meant "Subsequent requests should use the specified proxy.',
|
|
590
|
+
[
|
|
591
|
+
307
|
|
592
|
+
/* TemporaryRedirect */
|
|
593
|
+
]: "In this case, the request should be repeated with another URI; however, future requests should still use the original URI.",
|
|
594
|
+
[
|
|
595
|
+
308
|
|
596
|
+
/* PermanentRedirect */
|
|
597
|
+
]: "The request and all future requests should be repeated using another URI."
|
|
598
|
+
};
|
|
599
|
+
var ZHttpCodeServer = /* @__PURE__ */ ((ZHttpCodeServer2) => {
|
|
600
|
+
ZHttpCodeServer2[ZHttpCodeServer2["InternalServerError"] = 500] = "InternalServerError";
|
|
601
|
+
ZHttpCodeServer2[ZHttpCodeServer2["NotImplemented"] = 501] = "NotImplemented";
|
|
602
|
+
ZHttpCodeServer2[ZHttpCodeServer2["BadGateway"] = 502] = "BadGateway";
|
|
603
|
+
ZHttpCodeServer2[ZHttpCodeServer2["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
604
|
+
ZHttpCodeServer2[ZHttpCodeServer2["GatewayTimeout"] = 504] = "GatewayTimeout";
|
|
605
|
+
ZHttpCodeServer2[ZHttpCodeServer2["HttpVersionNotSupported"] = 505] = "HttpVersionNotSupported";
|
|
606
|
+
ZHttpCodeServer2[ZHttpCodeServer2["VariantAlsoNegotiates"] = 506] = "VariantAlsoNegotiates";
|
|
607
|
+
ZHttpCodeServer2[ZHttpCodeServer2["InsufficientStorage"] = 507] = "InsufficientStorage";
|
|
608
|
+
ZHttpCodeServer2[ZHttpCodeServer2["LoopDetected"] = 508] = "LoopDetected";
|
|
609
|
+
ZHttpCodeServer2[ZHttpCodeServer2["NotExtended"] = 510] = "NotExtended";
|
|
610
|
+
ZHttpCodeServer2[ZHttpCodeServer2["NetworkAuthenticationRequired"] = 511] = "NetworkAuthenticationRequired";
|
|
611
|
+
return ZHttpCodeServer2;
|
|
612
|
+
})(ZHttpCodeServer || {});
|
|
613
|
+
const ZHttpCodeServerNames = {
|
|
614
|
+
[
|
|
615
|
+
500
|
|
616
|
+
/* InternalServerError */
|
|
617
|
+
]: "Internal Server Error",
|
|
618
|
+
[
|
|
619
|
+
501
|
|
620
|
+
/* NotImplemented */
|
|
621
|
+
]: "Not Implemented",
|
|
622
|
+
[
|
|
623
|
+
502
|
|
624
|
+
/* BadGateway */
|
|
625
|
+
]: "Bad Gateway",
|
|
626
|
+
[
|
|
627
|
+
503
|
|
628
|
+
/* ServiceUnavailable */
|
|
629
|
+
]: "Service Unavailable",
|
|
630
|
+
[
|
|
631
|
+
504
|
|
632
|
+
/* GatewayTimeout */
|
|
633
|
+
]: "Gateway Timeout",
|
|
634
|
+
[
|
|
635
|
+
505
|
|
636
|
+
/* HttpVersionNotSupported */
|
|
637
|
+
]: "HTTP Version Not Supported",
|
|
638
|
+
[
|
|
639
|
+
506
|
|
640
|
+
/* VariantAlsoNegotiates */
|
|
641
|
+
]: "Variant Also Negotiates",
|
|
642
|
+
[
|
|
643
|
+
507
|
|
644
|
+
/* InsufficientStorage */
|
|
645
|
+
]: "Insufficient Storage",
|
|
646
|
+
[
|
|
647
|
+
508
|
|
648
|
+
/* LoopDetected */
|
|
649
|
+
]: "Loop Detected",
|
|
650
|
+
[
|
|
651
|
+
510
|
|
652
|
+
/* NotExtended */
|
|
653
|
+
]: "Not Extended",
|
|
654
|
+
[
|
|
655
|
+
511
|
|
656
|
+
/* NetworkAuthenticationRequired */
|
|
657
|
+
]: "Network Authentication Required"
|
|
658
|
+
};
|
|
659
|
+
const ZHttpCodeServerDescriptions = {
|
|
660
|
+
[
|
|
661
|
+
500
|
|
662
|
+
/* InternalServerError */
|
|
663
|
+
]: "An unexpected condition was encountered on the server.",
|
|
664
|
+
[
|
|
665
|
+
501
|
|
666
|
+
/* NotImplemented */
|
|
667
|
+
]: "The server either does not recognize the request method, or it lacks the ability to fulfil the request. Usually this implies future availability (e.g., a new feature of a web-service API).",
|
|
668
|
+
[
|
|
669
|
+
502
|
|
670
|
+
/* BadGateway */
|
|
671
|
+
]: " The server was acting as a gateway or proxy and received an invalid response from the upstream server.",
|
|
672
|
+
[
|
|
673
|
+
503
|
|
674
|
+
/* ServiceUnavailable */
|
|
675
|
+
]: "The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state.",
|
|
676
|
+
[
|
|
677
|
+
504
|
|
678
|
+
/* GatewayTimeout */
|
|
679
|
+
]: "The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.",
|
|
680
|
+
[
|
|
681
|
+
505
|
|
682
|
+
/* HttpVersionNotSupported */
|
|
683
|
+
]: "The server does not support the HTTP protocol version used in the request.",
|
|
684
|
+
[
|
|
685
|
+
506
|
|
686
|
+
/* VariantAlsoNegotiates */
|
|
687
|
+
]: " Transparent content negotiation for the request results in a circular reference.",
|
|
688
|
+
[
|
|
689
|
+
507
|
|
690
|
+
/* InsufficientStorage */
|
|
691
|
+
]: "The server is unable to store the representation needed to complete the request.",
|
|
692
|
+
[
|
|
693
|
+
508
|
|
694
|
+
/* LoopDetected */
|
|
695
|
+
]: "The server detected an infinite loop while processing the request.",
|
|
696
|
+
[
|
|
697
|
+
510
|
|
698
|
+
/* NotExtended */
|
|
699
|
+
]: "Further extensions to the request are required for the server to fulfil it.",
|
|
700
|
+
[
|
|
701
|
+
511
|
|
702
|
+
/* NetworkAuthenticationRequired */
|
|
703
|
+
]: "The client needs to authenticate to gain network access."
|
|
704
|
+
};
|
|
705
|
+
var ZHttpCodeSuccess = /* @__PURE__ */ ((ZHttpCodeSuccess2) => {
|
|
706
|
+
ZHttpCodeSuccess2[ZHttpCodeSuccess2["OK"] = 200] = "OK";
|
|
707
|
+
ZHttpCodeSuccess2[ZHttpCodeSuccess2["Created"] = 201] = "Created";
|
|
708
|
+
ZHttpCodeSuccess2[ZHttpCodeSuccess2["Accepted"] = 202] = "Accepted";
|
|
709
|
+
ZHttpCodeSuccess2[ZHttpCodeSuccess2["NonAuthoritativeInformation"] = 203] = "NonAuthoritativeInformation";
|
|
710
|
+
ZHttpCodeSuccess2[ZHttpCodeSuccess2["NoContent"] = 204] = "NoContent";
|
|
711
|
+
ZHttpCodeSuccess2[ZHttpCodeSuccess2["ResetContent"] = 205] = "ResetContent";
|
|
712
|
+
ZHttpCodeSuccess2[ZHttpCodeSuccess2["PartialContent"] = 206] = "PartialContent";
|
|
713
|
+
ZHttpCodeSuccess2[ZHttpCodeSuccess2["MultiStatus"] = 207] = "MultiStatus";
|
|
714
|
+
ZHttpCodeSuccess2[ZHttpCodeSuccess2["AlreadyReported"] = 208] = "AlreadyReported";
|
|
715
|
+
ZHttpCodeSuccess2[ZHttpCodeSuccess2["IMUsed"] = 226] = "IMUsed";
|
|
716
|
+
return ZHttpCodeSuccess2;
|
|
717
|
+
})(ZHttpCodeSuccess || {});
|
|
718
|
+
const ZHttpCodeSuccessNames = {
|
|
719
|
+
[
|
|
720
|
+
200
|
|
721
|
+
/* OK */
|
|
722
|
+
]: "OK",
|
|
723
|
+
[
|
|
724
|
+
201
|
|
725
|
+
/* Created */
|
|
726
|
+
]: "Created",
|
|
727
|
+
[
|
|
728
|
+
202
|
|
729
|
+
/* Accepted */
|
|
730
|
+
]: "Accepted",
|
|
731
|
+
[
|
|
732
|
+
203
|
|
733
|
+
/* NonAuthoritativeInformation */
|
|
734
|
+
]: "Non-Authoritative Information",
|
|
735
|
+
[
|
|
736
|
+
204
|
|
737
|
+
/* NoContent */
|
|
738
|
+
]: "No Content",
|
|
739
|
+
[
|
|
740
|
+
205
|
|
741
|
+
/* ResetContent */
|
|
742
|
+
]: "Reset Content",
|
|
743
|
+
[
|
|
744
|
+
206
|
|
745
|
+
/* PartialContent */
|
|
746
|
+
]: "Partial Content",
|
|
747
|
+
[
|
|
748
|
+
207
|
|
749
|
+
/* MultiStatus */
|
|
750
|
+
]: "Multi Status",
|
|
751
|
+
[
|
|
752
|
+
208
|
|
753
|
+
/* AlreadyReported */
|
|
754
|
+
]: "Already Reported",
|
|
755
|
+
[
|
|
756
|
+
226
|
|
757
|
+
/* IMUsed */
|
|
758
|
+
]: "IM Used"
|
|
759
|
+
};
|
|
760
|
+
const ZHttpCodeSuccessDescriptions = {
|
|
761
|
+
[
|
|
762
|
+
200
|
|
763
|
+
/* OK */
|
|
764
|
+
]: "The request was successful.",
|
|
765
|
+
[
|
|
766
|
+
201
|
|
767
|
+
/* Created */
|
|
768
|
+
]: "The request has been fulfilled, resulting in the creation of a new resource.",
|
|
769
|
+
[
|
|
770
|
+
202
|
|
771
|
+
/* Accepted */
|
|
772
|
+
]: "The request has been accepted for processing, but the processing has not been completed.",
|
|
773
|
+
[
|
|
774
|
+
203
|
|
775
|
+
/* NonAuthoritativeInformation */
|
|
776
|
+
]: "The server is a transforming proxy that received an OK from its origin,but is returning a modified version of the response.",
|
|
777
|
+
[
|
|
778
|
+
204
|
|
779
|
+
/* NoContent */
|
|
780
|
+
]: "The server successfully processed the request and is not returning any content.",
|
|
781
|
+
[
|
|
782
|
+
205
|
|
783
|
+
/* ResetContent */
|
|
784
|
+
]: "The server successfully processed the request, but is not returning any content. The document view must be refreshed.",
|
|
785
|
+
[
|
|
786
|
+
206
|
|
787
|
+
/* PartialContent */
|
|
788
|
+
]: "he server is delivering only part of the resource due to a range header sent by the client.",
|
|
789
|
+
[
|
|
790
|
+
207
|
|
791
|
+
/* MultiStatus */
|
|
792
|
+
]: "The message body that follows is by default an XML message and can contain a number of separate response codes, depending on how many sub-requests were made.",
|
|
793
|
+
[
|
|
794
|
+
208
|
|
795
|
+
/* AlreadyReported */
|
|
796
|
+
]: "The members of a DAV binding have already been enumerated in a preceding part of the response, and are not being included again.",
|
|
797
|
+
[
|
|
798
|
+
226
|
|
799
|
+
/* IMUsed */
|
|
800
|
+
]: "The server has fulfilled a request for the resource, and the response is a representation of the result of one or more instance-manipulations applied to the current instance."
|
|
801
|
+
};
|
|
802
|
+
var ZHttpCodeCategory = /* @__PURE__ */ ((ZHttpCodeCategory2) => {
|
|
803
|
+
ZHttpCodeCategory2["InformationalResponse"] = "Informational Response";
|
|
804
|
+
ZHttpCodeCategory2["Success"] = "Success";
|
|
805
|
+
ZHttpCodeCategory2["Redirection"] = "Redirection";
|
|
806
|
+
ZHttpCodeCategory2["Client"] = "Client Error";
|
|
807
|
+
ZHttpCodeCategory2["Server"] = "Server Error";
|
|
808
|
+
return ZHttpCodeCategory2;
|
|
809
|
+
})(ZHttpCodeCategory || {});
|
|
810
|
+
var ZHttpCodeSeverity = /* @__PURE__ */ ((ZHttpCodeSeverity2) => {
|
|
811
|
+
ZHttpCodeSeverity2["Info"] = "info";
|
|
812
|
+
ZHttpCodeSeverity2["Success"] = "success";
|
|
813
|
+
ZHttpCodeSeverity2["Warning"] = "warning";
|
|
814
|
+
ZHttpCodeSeverity2["Error"] = "error";
|
|
815
|
+
return ZHttpCodeSeverity2;
|
|
816
|
+
})(ZHttpCodeSeverity || {});
|
|
817
|
+
function getHttpCodeName(code) {
|
|
818
|
+
return ZHttpCodeInformationalResponseNames[code] || ZHttpCodeSuccessNames[code] || ZHttpCodeRedirectionNames[code] || ZHttpCodeClientNames[code] || ZHttpCodeServerNames[code];
|
|
819
|
+
}
|
|
820
|
+
function getHttpCodeDescription(code) {
|
|
821
|
+
return ZHttpCodeInformationalResponseDescriptions[code] || ZHttpCodeSuccessDescriptions[code] || ZHttpCodeRedirectionDescriptions[code] || ZHttpCodeClientDescriptions[code] || ZHttpCodeServerDescriptions[code];
|
|
822
|
+
}
|
|
823
|
+
function getHttpCodeSeverity(code) {
|
|
824
|
+
if (code >= 200 && code < 300) {
|
|
825
|
+
return "success";
|
|
826
|
+
}
|
|
827
|
+
if (code >= 400 && code < 500) {
|
|
828
|
+
return "warning";
|
|
829
|
+
}
|
|
830
|
+
if (code >= 500) {
|
|
831
|
+
return "error";
|
|
832
|
+
}
|
|
833
|
+
return "info";
|
|
834
|
+
}
|
|
835
|
+
function getHttpCodeCategory(code) {
|
|
836
|
+
if (code >= 100 && code < 200) {
|
|
837
|
+
return "Informational Response";
|
|
838
|
+
}
|
|
839
|
+
if (code >= 200 && code < 300) {
|
|
840
|
+
return "Success";
|
|
841
|
+
}
|
|
842
|
+
if (code >= 300 && code < 400) {
|
|
843
|
+
return "Redirection";
|
|
844
|
+
}
|
|
845
|
+
if (code >= 400 && code < 500) {
|
|
846
|
+
return "Client Error";
|
|
847
|
+
}
|
|
848
|
+
return "Server Error";
|
|
849
|
+
}
|
|
850
|
+
class ZHttpResultBuilder {
|
|
851
|
+
/**
|
|
852
|
+
* Initializes a new instance of this object.
|
|
853
|
+
*
|
|
854
|
+
* @param data -
|
|
855
|
+
* The data result.
|
|
856
|
+
*/
|
|
857
|
+
constructor(data) {
|
|
858
|
+
__publicField(this, "_result");
|
|
859
|
+
this._result = {
|
|
860
|
+
status: ZHttpCodeSuccess.OK,
|
|
861
|
+
headers: {},
|
|
862
|
+
data
|
|
863
|
+
};
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Sets the data.
|
|
867
|
+
*
|
|
868
|
+
* @param data -
|
|
869
|
+
* The data to set.
|
|
870
|
+
*
|
|
871
|
+
* @returns
|
|
872
|
+
* This object.
|
|
873
|
+
*/
|
|
874
|
+
data(data) {
|
|
875
|
+
this._result.data = data;
|
|
876
|
+
return this;
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* Sets the status code and the english description.
|
|
880
|
+
*
|
|
881
|
+
* @param code -
|
|
882
|
+
* The code to set.
|
|
883
|
+
*
|
|
884
|
+
* @returns
|
|
885
|
+
* This object.
|
|
886
|
+
*/
|
|
887
|
+
status(code) {
|
|
888
|
+
this._result.status = code;
|
|
889
|
+
return this;
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Sets the return headers.
|
|
893
|
+
*
|
|
894
|
+
* @param headers -
|
|
895
|
+
* The headers to set.
|
|
896
|
+
*
|
|
897
|
+
* @returns
|
|
898
|
+
* This object.
|
|
899
|
+
*/
|
|
900
|
+
headers(headers) {
|
|
901
|
+
this._result.headers = headers;
|
|
902
|
+
return this;
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Returns the built up result.
|
|
906
|
+
*
|
|
907
|
+
* @returns
|
|
908
|
+
* A shallow copy of the built up result.
|
|
909
|
+
*/
|
|
910
|
+
build() {
|
|
911
|
+
return { ...this._result };
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
class ZHttpServiceMock {
|
|
915
|
+
constructor() {
|
|
916
|
+
__publicField(this, "_mapping", {});
|
|
917
|
+
}
|
|
918
|
+
/**
|
|
919
|
+
* Sets the result of a given endpoint.
|
|
920
|
+
*
|
|
921
|
+
* @param endpoint -
|
|
922
|
+
* The endpoint to set.
|
|
923
|
+
* @param verb -
|
|
924
|
+
* The endpoint verb to respond to.
|
|
925
|
+
* @param invoke -
|
|
926
|
+
* The result method. If this is falsy, then the endpoint is removed.
|
|
927
|
+
*/
|
|
928
|
+
set(endpoint, verb, invoke) {
|
|
929
|
+
this._mapping[endpoint] = this._mapping[endpoint] || {};
|
|
930
|
+
this._mapping[endpoint][verb] = typeof invoke === "function" ? invoke : () => invoke;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Invokes the request given the allowed api implementations.
|
|
934
|
+
*
|
|
935
|
+
* @param req -
|
|
936
|
+
* The request that has been made.
|
|
937
|
+
*
|
|
938
|
+
* @returns
|
|
939
|
+
* A promise that resolves with the given result if the status code is less than 400.
|
|
940
|
+
* Any status code above 400 will result in a rejected promise.
|
|
941
|
+
*/
|
|
942
|
+
async request(req) {
|
|
943
|
+
const endpointConfig = this._mapping[req.url];
|
|
944
|
+
const result = endpointConfig == null ? void 0 : endpointConfig[req.method];
|
|
945
|
+
if (result == null) {
|
|
946
|
+
const notFound = new ZHttpResultBuilder(null).status(ZHttpCodeClient.NotFound).build();
|
|
947
|
+
return Promise.reject(notFound);
|
|
948
|
+
}
|
|
949
|
+
const errorThreshold = 400;
|
|
950
|
+
const intermediate = await result(req);
|
|
951
|
+
return +intermediate.status < errorThreshold ? Promise.resolve(intermediate) : Promise.reject(intermediate);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
class ZHttpService {
|
|
955
|
+
/**
|
|
956
|
+
* Invokes the request with a real http service.
|
|
957
|
+
*
|
|
958
|
+
* @param req -
|
|
959
|
+
* The request information to make.
|
|
960
|
+
*/
|
|
961
|
+
async request(req) {
|
|
962
|
+
try {
|
|
963
|
+
const res = await axios({
|
|
964
|
+
url: req.url,
|
|
965
|
+
method: req.method,
|
|
966
|
+
data: req.body,
|
|
967
|
+
timeout: req.timeout,
|
|
968
|
+
headers: req.headers
|
|
969
|
+
});
|
|
970
|
+
return new ZHttpResultBuilder(res.data).headers(res.headers).status(res.status).build();
|
|
971
|
+
} catch (e) {
|
|
972
|
+
const error = e;
|
|
973
|
+
let builder = new ZHttpResultBuilder(null).headers({});
|
|
974
|
+
if (error.response) {
|
|
975
|
+
builder = builder.headers(error.response.headers).status(error.response.status).data(error.response.data);
|
|
976
|
+
} else if (error.request) {
|
|
977
|
+
builder = builder.status(ZHttpCodeServer.ServiceUnavailable).data("The target endpoint could not be reached. You may need to try again later.");
|
|
978
|
+
} else {
|
|
979
|
+
builder = builder.status(ZHttpCodeServer.InternalServerError).data(error.message || "An unexpected error occurred.");
|
|
980
|
+
}
|
|
981
|
+
return Promise.reject(builder.build());
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
exports.ZHttpCodeCategory = ZHttpCodeCategory;
|
|
986
|
+
exports.ZHttpCodeClient = ZHttpCodeClient;
|
|
987
|
+
exports.ZHttpCodeClientDescriptions = ZHttpCodeClientDescriptions;
|
|
988
|
+
exports.ZHttpCodeClientNames = ZHttpCodeClientNames;
|
|
989
|
+
exports.ZHttpCodeInformationalResponse = ZHttpCodeInformationalResponse;
|
|
990
|
+
exports.ZHttpCodeInformationalResponseDescriptions = ZHttpCodeInformationalResponseDescriptions;
|
|
991
|
+
exports.ZHttpCodeInformationalResponseNames = ZHttpCodeInformationalResponseNames;
|
|
992
|
+
exports.ZHttpCodeRedirection = ZHttpCodeRedirection;
|
|
993
|
+
exports.ZHttpCodeRedirectionDescriptions = ZHttpCodeRedirectionDescriptions;
|
|
994
|
+
exports.ZHttpCodeRedirectionNames = ZHttpCodeRedirectionNames;
|
|
995
|
+
exports.ZHttpCodeServer = ZHttpCodeServer;
|
|
996
|
+
exports.ZHttpCodeServerDescriptions = ZHttpCodeServerDescriptions;
|
|
997
|
+
exports.ZHttpCodeServerNames = ZHttpCodeServerNames;
|
|
998
|
+
exports.ZHttpCodeSeverity = ZHttpCodeSeverity;
|
|
999
|
+
exports.ZHttpCodeSuccess = ZHttpCodeSuccess;
|
|
1000
|
+
exports.ZHttpCodeSuccessDescriptions = ZHttpCodeSuccessDescriptions;
|
|
1001
|
+
exports.ZHttpCodeSuccessNames = ZHttpCodeSuccessNames;
|
|
1002
|
+
exports.ZHttpMethod = ZHttpMethod;
|
|
1003
|
+
exports.ZHttpRequestBuilder = ZHttpRequestBuilder;
|
|
1004
|
+
exports.ZHttpResultBuilder = ZHttpResultBuilder;
|
|
1005
|
+
exports.ZHttpService = ZHttpService;
|
|
1006
|
+
exports.ZHttpServiceMock = ZHttpServiceMock;
|
|
1007
|
+
exports.getHttpCodeCategory = getHttpCodeCategory;
|
|
1008
|
+
exports.getHttpCodeDescription = getHttpCodeDescription;
|
|
1009
|
+
exports.getHttpCodeName = getHttpCodeName;
|
|
1010
|
+
exports.getHttpCodeSeverity = getHttpCodeSeverity;
|
|
1011
|
+
//# sourceMappingURL=index.cjs.map
|