@zthun/webigail-http 4.0.8 → 5.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.js CHANGED
@@ -1,26 +1,7 @@
1
1
  import { ZMimeTypeApplication } from '@zthun/webigail-url';
2
2
  import fetch from 'cross-fetch';
3
3
 
4
- function _class_call_check$3(instance, Constructor) {
5
- if (!(instance instanceof Constructor)) {
6
- throw new TypeError("Cannot call a class as a function");
7
- }
8
- }
9
- function _defineProperties$3(target, props) {
10
- for(var i = 0; i < props.length; i++){
11
- var descriptor = props[i];
12
- descriptor.enumerable = descriptor.enumerable || false;
13
- descriptor.configurable = true;
14
- if ("value" in descriptor) descriptor.writable = true;
15
- Object.defineProperty(target, descriptor.key, descriptor);
16
- }
17
- }
18
- function _create_class$3(Constructor, protoProps, staticProps) {
19
- if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
20
- if (staticProps) _defineProperties$3(Constructor, staticProps);
21
- return Constructor;
22
- }
23
- function _define_property$7(obj, key, value) {
4
+ function _define_property$2(obj, key, value) {
24
5
  if (key in obj) {
25
6
  Object.defineProperty(obj, key, {
26
7
  value: value,
@@ -33,40 +14,6 @@ function _define_property$7(obj, key, value) {
33
14
  }
34
15
  return obj;
35
16
  }
36
- function _object_spread$1(target) {
37
- for(var i = 1; i < arguments.length; i++){
38
- var source = arguments[i] != null ? arguments[i] : {};
39
- var ownKeys = Object.keys(source);
40
- if (typeof Object.getOwnPropertySymbols === "function") {
41
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
42
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
43
- }));
44
- }
45
- ownKeys.forEach(function(key) {
46
- _define_property$7(target, key, source[key]);
47
- });
48
- }
49
- return target;
50
- }
51
- function ownKeys(object, enumerableOnly) {
52
- var keys = Object.keys(object);
53
- if (Object.getOwnPropertySymbols) {
54
- var symbols = Object.getOwnPropertySymbols(object);
55
- keys.push.apply(keys, symbols);
56
- }
57
- return keys;
58
- }
59
- function _object_spread_props(target, source) {
60
- source = source != null ? source : {};
61
- if (Object.getOwnPropertyDescriptors) {
62
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
63
- } else {
64
- ownKeys(Object(source)).forEach(function(key) {
65
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
66
- });
67
- }
68
- return target;
69
- }
70
17
  /**
71
18
  * Represents an available method for an http invocation.
72
19
  */ var ZHttpMethod = /*#__PURE__*/ function(ZHttpMethod) {
@@ -112,25 +59,26 @@ function _object_spread_props(target, source) {
112
59
  }({});
113
60
  /**
114
61
  * Represents a builder for an http request.
115
- */ var ZHttpRequestBuilder = /*#__PURE__*/ function() {
116
- function ZHttpRequestBuilder() {
117
- _class_call_check$3(this, ZHttpRequestBuilder);
118
- _define_property$7(this, "_request", void 0);
119
- /**
120
- * Sets the content type to json.
62
+ */ class ZHttpRequestBuilder {
63
+ /**
64
+ * Duplicates a request, keeping it's structure intact.
65
+ *
66
+ * The underlying headers will be duplicated, but everything
67
+ * else will be a shallow copy to preserve the body in the
68
+ * case that it is a blob or other binary structure.
69
+ *
70
+ * @param other -
71
+ * The request to duplicate.
121
72
  *
122
73
  * @returns
123
- * This object.
124
- */ _define_property$7(this, "json", this.content.bind(this, ZMimeTypeApplication.JSON));
125
- this._request = {
126
- method: "GET",
127
- url: ""
74
+ * The duplicated object.
75
+ */ static duplicate(other) {
76
+ return {
77
+ ...other,
78
+ headers: structuredClone(other.headers)
128
79
  };
129
80
  }
130
- _create_class$3(ZHttpRequestBuilder, [
131
- {
132
- key: "_method",
133
- value: /**
81
+ /**
134
82
  * Sets the method.
135
83
  *
136
84
  * @param method -
@@ -140,95 +88,71 @@ function _object_spread_props(target, source) {
140
88
  *
141
89
  * @returns
142
90
  * This object.
143
- */ function _method(method, body) {
144
- this._request.method = method;
145
- this._request.body = body;
146
- if (this._request.body === undefined) {
147
- delete this._request.body;
148
- }
149
- return this;
150
- }
151
- },
152
- {
153
- key: "get",
154
- value: /**
91
+ */ _method(method, body) {
92
+ this._request.method = method;
93
+ this._request.body = body;
94
+ if (this._request.body === undefined) {
95
+ delete this._request.body;
96
+ }
97
+ return this;
98
+ }
99
+ /**
155
100
  * Constructs a get request.
156
101
  *
157
102
  * @returns
158
103
  * This object.
159
- */ function get() {
160
- return this._method("GET");
161
- }
162
- },
163
- {
164
- key: "post",
165
- value: /**
104
+ */ get() {
105
+ return this._method("GET");
106
+ }
107
+ /**
166
108
  * Constructs a post request.
167
109
  *
168
110
  * @returns
169
111
  * This object.
170
- */ function post(body) {
171
- return this._method("POST", body).json();
172
- }
173
- },
174
- {
175
- key: "put",
176
- value: /**
112
+ */ post(body) {
113
+ return this._method("POST", body).json();
114
+ }
115
+ /**
177
116
  * Constructs a put request.
178
117
  *
179
118
  * @returns
180
119
  * This object.
181
- */ function put(body) {
182
- return this._method("PUT", body).json();
183
- }
184
- },
185
- {
186
- key: "delete",
187
- value: /**
120
+ */ put(body) {
121
+ return this._method("PUT", body).json();
122
+ }
123
+ /**
188
124
  * Constructs a delete request.
189
125
  *
190
126
  * @returns
191
127
  * This object.
192
- */ function _delete() {
193
- return this._method("DELETE");
194
- }
195
- },
196
- {
197
- key: "patch",
198
- value: /**
128
+ */ delete() {
129
+ return this._method("DELETE");
130
+ }
131
+ /**
199
132
  * Constructs a patch request.
200
133
  *
201
134
  * @returns
202
135
  * This object.
203
- */ function patch(body) {
204
- return this._method("PATCH", body).json();
205
- }
206
- },
207
- {
208
- key: "options",
209
- value: /**
136
+ */ patch(body) {
137
+ return this._method("PATCH", body).json();
138
+ }
139
+ /**
210
140
  * Constructs a options request.
211
141
  *
212
142
  * @returns
213
143
  * This object.
214
- */ function options() {
215
- return this._method("OPTIONS");
216
- }
217
- },
218
- {
219
- key: "head",
220
- value: /**
144
+ */ options() {
145
+ return this._method("OPTIONS");
146
+ }
147
+ /**
221
148
  * Constructs a head request.
222
149
  *
223
150
  * @returns
224
151
  * This object.
225
- */ function head() {
226
- return this._method("HEAD");
227
- }
228
- },
229
- {
230
- key: "url",
231
- value: /**
152
+ */ head() {
153
+ return this._method("HEAD");
154
+ }
155
+ /**
232
156
  * Sets the url to make the request from.
233
157
  *
234
158
  * @param url -
@@ -236,14 +160,11 @@ function _object_spread_props(target, source) {
236
160
  *
237
161
  * @returns
238
162
  * This object.
239
- */ function url(url) {
240
- this._request.url = url;
241
- return this;
242
- }
243
- },
244
- {
245
- key: "timeout",
246
- value: /**
163
+ */ url(url) {
164
+ this._request.url = url;
165
+ return this;
166
+ }
167
+ /**
247
168
  * Sets the timeout for the url.
248
169
  *
249
170
  * @param ms -
@@ -251,14 +172,11 @@ function _object_spread_props(target, source) {
251
172
  *
252
173
  * @returns
253
174
  * The object.
254
- */ function timeout(ms) {
255
- this._request.timeout = ms;
256
- return this;
257
- }
258
- },
259
- {
260
- key: "headers",
261
- value: /**
175
+ */ timeout(ms) {
176
+ this._request.timeout = ms;
177
+ return this;
178
+ }
179
+ /**
262
180
  * Sets the headers.
263
181
  *
264
182
  * @param headers -
@@ -266,14 +184,11 @@ function _object_spread_props(target, source) {
266
184
  *
267
185
  * @returns
268
186
  * This object.
269
- */ function headers(headers) {
270
- this._request.headers = headers;
271
- return this;
272
- }
273
- },
274
- {
275
- key: "header",
276
- value: /**
187
+ */ headers(headers) {
188
+ this._request.headers = headers;
189
+ return this;
190
+ }
191
+ /**
277
192
  * Sets an individual header.
278
193
  *
279
194
  * @param key -
@@ -283,19 +198,16 @@ function _object_spread_props(target, source) {
283
198
  *
284
199
  * @returns
285
200
  * This object.
286
- */ function header(key, value) {
287
- this._request.headers = this._request.headers || {};
288
- if (value == null) {
289
- delete this._request.headers[key];
290
- } else {
291
- this._request.headers[key] = "".concat(value);
292
- }
293
- return this;
294
- }
295
- },
296
- {
297
- key: "content",
298
- value: /**
201
+ */ header(key, value) {
202
+ this._request.headers = this._request.headers || {};
203
+ if (value == null) {
204
+ delete this._request.headers[key];
205
+ } else {
206
+ this._request.headers[key] = `${value}`;
207
+ }
208
+ return this;
209
+ }
210
+ /**
299
211
  * Sets the content type header.
300
212
  *
301
213
  * @param type -
@@ -303,13 +215,10 @@ function _object_spread_props(target, source) {
303
215
  *
304
216
  * @returns
305
217
  * This object.
306
- */ function content(type) {
307
- return this.header("Content-Type", type);
308
- }
309
- },
310
- {
311
- key: "copy",
312
- value: /**
218
+ */ content(type) {
219
+ return this.header("Content-Type", type);
220
+ }
221
+ /**
313
222
  * Copies other to this object.
314
223
  *
315
224
  * @param other -
@@ -317,46 +226,34 @@ function _object_spread_props(target, source) {
317
226
  *
318
227
  * @returns
319
228
  * This object.
320
- */ function copy(other) {
321
- this._request = ZHttpRequestBuilder.duplicate(other);
322
- return this;
323
- }
324
- },
325
- {
326
- key: "build",
327
- value: /**
229
+ */ copy(other) {
230
+ this._request = ZHttpRequestBuilder.duplicate(other);
231
+ return this;
232
+ }
233
+ /**
328
234
  * Returns the constructed request.
329
235
  *
330
236
  * @returns
331
237
  * The constructed request.
332
- */ function build() {
333
- return ZHttpRequestBuilder.duplicate(this._request);
334
- }
335
- }
336
- ], [
337
- {
338
- key: "duplicate",
339
- value: /**
340
- * Duplicates a request, keeping it's structure intact.
341
- *
342
- * The underlying headers will be duplicated, but everything
343
- * else will be a shallow copy to preserve the body in the
344
- * case that it is a blob or other binary structure.
345
- *
346
- * @param other -
347
- * The request to duplicate.
238
+ */ build() {
239
+ return ZHttpRequestBuilder.duplicate(this._request);
240
+ }
241
+ /**
242
+ * Initializes a new instance of this object.
243
+ */ constructor(){
244
+ _define_property$2(this, "_request", void 0);
245
+ /**
246
+ * Sets the content type to json.
348
247
  *
349
248
  * @returns
350
- * The duplicated object.
351
- */ function duplicate(other) {
352
- return _object_spread_props(_object_spread$1({}, other), {
353
- headers: structuredClone(other.headers)
354
- });
355
- }
356
- }
357
- ]);
358
- return ZHttpRequestBuilder;
359
- }();
249
+ * This object.
250
+ */ _define_property$2(this, "json", this.content.bind(this, ZMimeTypeApplication.JSON));
251
+ this._request = {
252
+ method: "GET",
253
+ url: ""
254
+ };
255
+ }
256
+ }
360
257
 
361
258
  /**
362
259
  * This class of status code is intended for situations in which the error seems to have been caused by the client.
@@ -364,20 +261,7 @@ function _object_spread_props(target, source) {
364
261
  * Except when responding to a HEAD request, the server should include an entity containing an explanation
365
262
  * of the error situation, and whether it is a temporary or permanent condition. These status codes are applicable
366
263
  * to any request method. User agents should display any included entity to the user.
367
- */ function _define_property$6(obj, key, value) {
368
- if (key in obj) {
369
- Object.defineProperty(obj, key, {
370
- value: value,
371
- enumerable: true,
372
- configurable: true,
373
- writable: true
374
- });
375
- } else {
376
- obj[key] = value;
377
- }
378
- return obj;
379
- }
380
- var ZHttpCodeClient = /*#__PURE__*/ function(ZHttpCodeClient) {
264
+ */ var ZHttpCodeClient = /*#__PURE__*/ function(ZHttpCodeClient) {
381
265
  /**
382
266
  * The server cannot or will not process the request due to an apparent client error
383
267
  * (e.g., malformed request syntax, size too large, invalid request message framing,
@@ -520,14 +404,70 @@ var ZHttpCodeClient = /*#__PURE__*/ function(ZHttpCodeClient) {
520
404
  */ ZHttpCodeClient[ZHttpCodeClient["UnavailableForLegalReasons"] = 451] = "UnavailableForLegalReasons";
521
405
  return ZHttpCodeClient;
522
406
  }({});
523
- var _obj$4;
524
407
  /**
525
408
  * English friendly names of the codes.
526
- */ var ZHttpCodeClientNames = (_obj$4 = {}, _define_property$6(_obj$4, 400, "Bad Request"), _define_property$6(_obj$4, 401, "Unauthorized"), _define_property$6(_obj$4, 402, "Payment Required"), _define_property$6(_obj$4, 403, "Forbidden"), _define_property$6(_obj$4, 404, "Not Found"), _define_property$6(_obj$4, 405, "Method not Allowed"), _define_property$6(_obj$4, 406, "Not Acceptable"), _define_property$6(_obj$4, 407, "Proxy Authentication Required"), _define_property$6(_obj$4, 408, "Request Timeout"), _define_property$6(_obj$4, 409, "Conflict"), _define_property$6(_obj$4, 410, "Gone"), _define_property$6(_obj$4, 411, "Length Required"), _define_property$6(_obj$4, 412, "Precondition Failed"), _define_property$6(_obj$4, 413, "Payload Too Large"), _define_property$6(_obj$4, 414, "URI Too Long"), _define_property$6(_obj$4, 415, "Unsupported Media Type"), _define_property$6(_obj$4, 416, "Range Not Satisfiable"), _define_property$6(_obj$4, 417, "Expectation Failed"), _define_property$6(_obj$4, 418, "I am a Teapot"), _define_property$6(_obj$4, 421, "Misdirected Requested"), _define_property$6(_obj$4, 422, "Entity Not Processable"), _define_property$6(_obj$4, 423, "Locked"), _define_property$6(_obj$4, 424, "Failed Dependency"), _define_property$6(_obj$4, 426, "Upgrade Required"), _define_property$6(_obj$4, 428, "Precondition Required"), _define_property$6(_obj$4, 429, "Too Many Requests"), _define_property$6(_obj$4, 431, "Request Header Fields Too Large"), _define_property$6(_obj$4, 451, "Unavailable for Legal Reasons"), _obj$4);
527
- var _obj1$4;
409
+ */ const ZHttpCodeClientNames = {
410
+ [400]: "Bad Request",
411
+ [401]: "Unauthorized",
412
+ [402]: "Payment Required",
413
+ [403]: "Forbidden",
414
+ [404]: "Not Found",
415
+ [405]: "Method not Allowed",
416
+ [406]: "Not Acceptable",
417
+ [407]: "Proxy Authentication Required",
418
+ [408]: "Request Timeout",
419
+ [409]: "Conflict",
420
+ [410]: "Gone",
421
+ [411]: "Length Required",
422
+ [412]: "Precondition Failed",
423
+ [413]: "Payload Too Large",
424
+ [414]: "URI Too Long",
425
+ [415]: "Unsupported Media Type",
426
+ [416]: "Range Not Satisfiable",
427
+ [417]: "Expectation Failed",
428
+ [418]: "I am a Teapot",
429
+ [421]: "Misdirected Requested",
430
+ [422]: "Entity Not Processable",
431
+ [423]: "Locked",
432
+ [424]: "Failed Dependency",
433
+ [426]: "Upgrade Required",
434
+ [428]: "Precondition Required",
435
+ [429]: "Too Many Requests",
436
+ [431]: "Request Header Fields Too Large",
437
+ [451]: "Unavailable for Legal Reasons"
438
+ };
528
439
  /**
529
440
  * English friendly descriptions of HttpClientCodes
530
- */ var ZHttpCodeClientDescriptions = (_obj1$4 = {}, _define_property$6(_obj1$4, 400, "A bad request was sent."), _define_property$6(_obj1$4, 401, "You are not authenticated and cannot view this content."), _define_property$6(_obj1$4, 402, "Payment is required"), _define_property$6(_obj1$4, 403, "You are not authorized to view this content."), _define_property$6(_obj1$4, 404, "The resource you are looking for could not be found."), _define_property$6(_obj1$4, 405, "The requested operation was not allowed."), _define_property$6(_obj1$4, 406, "The requested resource is not capable of generating the content for you."), _define_property$6(_obj1$4, 407, "You must first authenticate your self with the proxy."), _define_property$6(_obj1$4, 408, "The server timed out waiting for a request. Please try again."), _define_property$6(_obj1$4, 409, "There was a conflict with request. Try something else."), _define_property$6(_obj1$4, 410, "The resource you requested is no longer available."), _define_property$6(_obj1$4, 411, "Your request did not specify the length of its content, which is required by the requested resource."), _define_property$6(_obj1$4, 412, "The server did not meet the requirements that was required to meet the request."), _define_property$6(_obj1$4, 413, "The request is too large and the server cannot handle it."), _define_property$6(_obj1$4, 414, "The URI provided was too long for the server to process."), _define_property$6(_obj1$4, 415, "The media type requested is not supported by the server."), _define_property$6(_obj1$4, 416, "A portion of the file was requested by the server cannot supply said portion."), _define_property$6(_obj1$4, 417, "The server cannot meet the requirements of the expectation made of it."), _define_property$6(_obj1$4, 418, "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!"), _define_property$6(_obj1$4, 421, "The request was directed at the server, but the server cannot produce a response."), _define_property$6(_obj1$4, 422, "The request was well-formed but was unable to be followed due to semantic errors."), _define_property$6(_obj1$4, 423, "The resource that is being accessed is locked."), _define_property$6(_obj1$4, 424, "The request failed because it depended on another request and that request failed."), _define_property$6(_obj1$4, 426, "The client needs to switch to a different protocol."), _define_property$6(_obj1$4, 428, "The origin server requires the request to be conditional."), _define_property$6(_obj1$4, 429, "The user has sent too many requests in a given amount of time."), _define_property$6(_obj1$4, 431, "The request cannot be processed because the collective header fields are too large."), _define_property$6(_obj1$4, 451, "Call your lawyer!"), _obj1$4);
441
+ */ const ZHttpCodeClientDescriptions = {
442
+ [400]: "A bad request was sent.",
443
+ [401]: "You are not authenticated and cannot view this content.",
444
+ [402]: "Payment is required",
445
+ [403]: "You are not authorized to view this content.",
446
+ [404]: "The resource you are looking for could not be found.",
447
+ [405]: "The requested operation was not allowed.",
448
+ [406]: "The requested resource is not capable of generating the content for you.",
449
+ [407]: "You must first authenticate your self with the proxy.",
450
+ [408]: "The server timed out waiting for a request. Please try again.",
451
+ [409]: "There was a conflict with request. Try something else.",
452
+ [410]: "The resource you requested is no longer available.",
453
+ [411]: "Your request did not specify the length of its content, which is required by the requested resource.",
454
+ [412]: "The server did not meet the requirements that was required to meet the request.",
455
+ [413]: "The request is too large and the server cannot handle it.",
456
+ [414]: "The URI provided was too long for the server to process.",
457
+ [415]: "The media type requested is not supported by the server.",
458
+ [416]: "A portion of the file was requested by the server cannot supply said portion.",
459
+ [417]: "The server cannot meet the requirements of the expectation made of it.",
460
+ [418]: "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!",
461
+ [421]: "The request was directed at the server, but the server cannot produce a response.",
462
+ [422]: "The request was well-formed but was unable to be followed due to semantic errors.",
463
+ [423]: "The resource that is being accessed is locked.",
464
+ [424]: "The request failed because it depended on another request and that request failed.",
465
+ [426]: "The client needs to switch to a different protocol.",
466
+ [428]: "The origin server requires the request to be conditional.",
467
+ [429]: "The user has sent too many requests in a given amount of time.",
468
+ [431]: "The request cannot be processed because the collective header fields are too large.",
469
+ [451]: "Call your lawyer!"
470
+ };
531
471
 
532
472
  /**
533
473
  * An informational response indicates that the request was received and understood.
@@ -537,20 +477,7 @@ var _obj1$4;
537
477
  * optional header fields, and is terminated by an empty line. As the HTTP/1.0 standard
538
478
  * did not define any 1xx status codes, servers must not[note 1] send a 1xx response to
539
479
  * an HTTP/1.0 compliant client except under experimental conditions.[4]
540
- */ function _define_property$5(obj, key, value) {
541
- if (key in obj) {
542
- Object.defineProperty(obj, key, {
543
- value: value,
544
- enumerable: true,
545
- configurable: true,
546
- writable: true
547
- });
548
- } else {
549
- obj[key] = value;
550
- }
551
- return obj;
552
- }
553
- var ZHttpCodeInformationalResponse = /*#__PURE__*/ function(ZHttpCodeInformationalResponse) {
480
+ */ var ZHttpCodeInformationalResponse = /*#__PURE__*/ function(ZHttpCodeInformationalResponse) {
554
481
  /**
555
482
  * The server has received the request headers and the client should proceed to send the
556
483
  * request body (in the case of a request for which a body needs to be sent; for example, a
@@ -577,14 +504,22 @@ var ZHttpCodeInformationalResponse = /*#__PURE__*/ function(ZHttpCodeInformation
577
504
  */ ZHttpCodeInformationalResponse[ZHttpCodeInformationalResponse["EarlyHints"] = 103] = "EarlyHints";
578
505
  return ZHttpCodeInformationalResponse;
579
506
  }({});
580
- var _obj$3;
581
507
  /**
582
508
  * English friendly names of the codes.
583
- */ var ZHttpCodeInformationalResponseNames = (_obj$3 = {}, _define_property$5(_obj$3, 100, "Continue"), _define_property$5(_obj$3, 101, "Switching Protocols"), _define_property$5(_obj$3, 102, "Processing"), _define_property$5(_obj$3, 103, "Early Hints"), _obj$3);
584
- var _obj1$3;
509
+ */ const ZHttpCodeInformationalResponseNames = {
510
+ [100]: "Continue",
511
+ [101]: "Switching Protocols",
512
+ [102]: "Processing",
513
+ [103]: "Early Hints"
514
+ };
585
515
  /**
586
516
  * English friendly descriptions of the codes.
587
- */ var ZHttpCodeInformationalResponseDescriptions = (_obj1$3 = {}, _define_property$5(_obj1$3, 100, "The client should continue to send the request body."), _define_property$5(_obj1$3, 101, "The requestor has asked the server to switch protocols and the server has agreed to do so."), _define_property$5(_obj1$3, 102, "The server has received and is processing the request, but a response is not available yet."), _define_property$5(_obj1$3, 103, "There are some early response headers available for you before the final message."), _obj1$3);
517
+ */ const ZHttpCodeInformationalResponseDescriptions = {
518
+ [100]: "The client should continue to send the request body.",
519
+ [101]: "The requestor has asked the server to switch protocols and the server has agreed to do so.",
520
+ [102]: "The server has received and is processing the request, but a response is not available yet.",
521
+ [103]: "There are some early response headers available for you before the final message."
522
+ };
588
523
 
589
524
  /**
590
525
  * This class of status code indicates the client must take additional action to complete the request.
@@ -593,20 +528,7 @@ var _obj1$3;
593
528
  * action with no user interaction only if the method used in the second request is GET or HEAD.
594
529
  * A user agent may automatically redirect a request. A user agent should detect and intervene
595
530
  * to prevent cyclical redirects.
596
- */ function _define_property$4(obj, key, value) {
597
- if (key in obj) {
598
- Object.defineProperty(obj, key, {
599
- value: value,
600
- enumerable: true,
601
- configurable: true,
602
- writable: true
603
- });
604
- } else {
605
- obj[key] = value;
606
- }
607
- return obj;
608
- }
609
- var ZHttpCodeRedirection = /*#__PURE__*/ function(ZHttpCodeRedirection) {
531
+ */ var ZHttpCodeRedirection = /*#__PURE__*/ function(ZHttpCodeRedirection) {
610
532
  /**
611
533
  * Indicates multiple options for the resource from which the client may choose
612
534
  * (via agent-driven content negotiation).
@@ -662,14 +584,32 @@ var ZHttpCodeRedirection = /*#__PURE__*/ function(ZHttpCodeRedirection) {
662
584
  */ ZHttpCodeRedirection[ZHttpCodeRedirection["PermanentRedirect"] = 308] = "PermanentRedirect";
663
585
  return ZHttpCodeRedirection;
664
586
  }({});
665
- var _obj$2;
666
587
  /**
667
588
  * English friendly names of the redirection codes.
668
- */ var ZHttpCodeRedirectionNames = (_obj$2 = {}, _define_property$4(_obj$2, 300, "Multiple Choices"), _define_property$4(_obj$2, 301, "Moved Permanently"), _define_property$4(_obj$2, 302, "Found"), _define_property$4(_obj$2, 303, "See Other"), _define_property$4(_obj$2, 304, "Not Modified"), _define_property$4(_obj$2, 305, "Use Proxy"), _define_property$4(_obj$2, 306, "Switch Proxy"), _define_property$4(_obj$2, 307, "Temporary Redirect"), _define_property$4(_obj$2, 308, "Permanent Redirect"), _obj$2);
669
- var _obj1$2;
589
+ */ const ZHttpCodeRedirectionNames = {
590
+ [300]: "Multiple Choices",
591
+ [301]: "Moved Permanently",
592
+ [302]: "Found",
593
+ [303]: "See Other",
594
+ [304]: "Not Modified",
595
+ [305]: "Use Proxy",
596
+ [306]: "Switch Proxy",
597
+ [307]: "Temporary Redirect",
598
+ [308]: "Permanent Redirect"
599
+ };
670
600
  /**
671
601
  * English friendly descriptions of the redirection codes.
672
- */ var ZHttpCodeRedirectionDescriptions = (_obj1$2 = {}, _define_property$4(_obj1$2, 300, "Indicates multiple options for the resource from which the client may choose."), _define_property$4(_obj1$2, 301, "This and all future requests should be directed to the given URI."), _define_property$4(_obj1$2, 302, "Tells the client to look at another url"), _define_property$4(_obj1$2, 303, "The response to the request can be found under another URI using the GET method."), _define_property$4(_obj1$2, 304, "Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match."), _define_property$4(_obj1$2, 305, "The requested resource is available only through a proxy, the address for which is provided in the response."), _define_property$4(_obj1$2, 306, 'No longer used. Originally meant "Subsequent requests should use the specified proxy.'), _define_property$4(_obj1$2, 307, "In this case, the request should be repeated with another URI; however, future requests should still use the original URI."), _define_property$4(_obj1$2, 308, "The request and all future requests should be repeated using another URI."), _obj1$2);
602
+ */ const ZHttpCodeRedirectionDescriptions = {
603
+ [300]: "Indicates multiple options for the resource from which the client may choose.",
604
+ [301]: "This and all future requests should be directed to the given URI.",
605
+ [302]: "Tells the client to look at another url",
606
+ [303]: "The response to the request can be found under another URI using the GET method.",
607
+ [304]: "Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match.",
608
+ [305]: "The requested resource is available only through a proxy, the address for which is provided in the response.",
609
+ [306]: 'No longer used. Originally meant "Subsequent requests should use the specified proxy.',
610
+ [307]: "In this case, the request should be repeated with another URI; however, future requests should still use the original URI.",
611
+ [308]: "The request and all future requests should be repeated using another URI."
612
+ };
673
613
 
674
614
  /**
675
615
  * The server failed to fulfil a request.
@@ -682,20 +622,7 @@ var _obj1$2;
682
622
  * is a temporary or permanent condition. Likewise, user agents should
683
623
  * display any included entity to the user. These response codes are applicable
684
624
  * to any request method.
685
- */ function _define_property$3(obj, key, value) {
686
- if (key in obj) {
687
- Object.defineProperty(obj, key, {
688
- value: value,
689
- enumerable: true,
690
- configurable: true,
691
- writable: true
692
- });
693
- } else {
694
- obj[key] = value;
695
- }
696
- return obj;
697
- }
698
- var ZHttpCodeServer = /*#__PURE__*/ function(ZHttpCodeServer) {
625
+ */ var ZHttpCodeServer = /*#__PURE__*/ function(ZHttpCodeServer) {
699
626
  /**
700
627
  * A generic error message, given when an unexpected condition was encountered
701
628
  * and no more specific message is suitable.
@@ -738,32 +665,41 @@ var ZHttpCodeServer = /*#__PURE__*/ function(ZHttpCodeServer) {
738
665
  */ ZHttpCodeServer[ZHttpCodeServer["NetworkAuthenticationRequired"] = 511] = "NetworkAuthenticationRequired";
739
666
  return ZHttpCodeServer;
740
667
  }({});
741
- var _obj$1;
742
668
  /**
743
669
  * English friendly names of the server codes.
744
- */ var ZHttpCodeServerNames = (_obj$1 = {}, _define_property$3(_obj$1, 500, "Internal Server Error"), _define_property$3(_obj$1, 501, "Not Implemented"), _define_property$3(_obj$1, 502, "Bad Gateway"), _define_property$3(_obj$1, 503, "Service Unavailable"), _define_property$3(_obj$1, 504, "Gateway Timeout"), _define_property$3(_obj$1, 505, "HTTP Version Not Supported"), _define_property$3(_obj$1, 506, "Variant Also Negotiates"), _define_property$3(_obj$1, 507, "Insufficient Storage"), _define_property$3(_obj$1, 508, "Loop Detected"), _define_property$3(_obj$1, 510, "Not Extended"), _define_property$3(_obj$1, 511, "Network Authentication Required"), _obj$1);
745
- var _obj1$1;
670
+ */ const ZHttpCodeServerNames = {
671
+ [500]: "Internal Server Error",
672
+ [501]: "Not Implemented",
673
+ [502]: "Bad Gateway",
674
+ [503]: "Service Unavailable",
675
+ [504]: "Gateway Timeout",
676
+ [505]: "HTTP Version Not Supported",
677
+ [506]: "Variant Also Negotiates",
678
+ [507]: "Insufficient Storage",
679
+ [508]: "Loop Detected",
680
+ [510]: "Not Extended",
681
+ [511]: "Network Authentication Required"
682
+ };
746
683
  /**
747
684
  * English friendly names of the server codes.
748
- */ var ZHttpCodeServerDescriptions = (_obj1$1 = {}, _define_property$3(_obj1$1, 500, "An unexpected condition was encountered on the server."), _define_property$3(_obj1$1, 501, "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)."), _define_property$3(_obj1$1, 502, " The server was acting as a gateway or proxy and received an invalid response from the upstream server."), _define_property$3(_obj1$1, 503, "The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state."), _define_property$3(_obj1$1, 504, "The server was acting as a gateway or proxy and did not receive a timely response from the upstream server."), _define_property$3(_obj1$1, 505, "The server does not support the HTTP protocol version used in the request."), _define_property$3(_obj1$1, 506, " Transparent content negotiation for the request results in a circular reference."), _define_property$3(_obj1$1, 507, "The server is unable to store the representation needed to complete the request."), _define_property$3(_obj1$1, 508, "The server detected an infinite loop while processing the request."), _define_property$3(_obj1$1, 510, "Further extensions to the request are required for the server to fulfil it."), _define_property$3(_obj1$1, 511, "The client needs to authenticate to gain network access."), _obj1$1);
685
+ */ const ZHttpCodeServerDescriptions = {
686
+ [500]: "An unexpected condition was encountered on the server.",
687
+ [501]: "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).",
688
+ [502]: " The server was acting as a gateway or proxy and received an invalid response from the upstream server.",
689
+ [503]: "The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state.",
690
+ [504]: "The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.",
691
+ [505]: "The server does not support the HTTP protocol version used in the request.",
692
+ [506]: " Transparent content negotiation for the request results in a circular reference.",
693
+ [507]: "The server is unable to store the representation needed to complete the request.",
694
+ [508]: "The server detected an infinite loop while processing the request.",
695
+ [510]: "Further extensions to the request are required for the server to fulfil it.",
696
+ [511]: "The client needs to authenticate to gain network access."
697
+ };
749
698
 
750
699
  /**
751
700
  * This class of status codes indicates the action requested by
752
701
  * the client was received, understood and accepted.
753
- */ function _define_property$2(obj, key, value) {
754
- if (key in obj) {
755
- Object.defineProperty(obj, key, {
756
- value: value,
757
- enumerable: true,
758
- configurable: true,
759
- writable: true
760
- });
761
- } else {
762
- obj[key] = value;
763
- }
764
- return obj;
765
- }
766
- var ZHttpCodeSuccess = /*#__PURE__*/ function(ZHttpCodeSuccess) {
702
+ */ var ZHttpCodeSuccess = /*#__PURE__*/ function(ZHttpCodeSuccess) {
767
703
  /**
768
704
  * Standard response for successful HTTP requests.
769
705
  *
@@ -813,14 +749,34 @@ var ZHttpCodeSuccess = /*#__PURE__*/ function(ZHttpCodeSuccess) {
813
749
  */ ZHttpCodeSuccess[ZHttpCodeSuccess["IMUsed"] = 226] = "IMUsed";
814
750
  return ZHttpCodeSuccess;
815
751
  }({});
816
- var _obj;
817
752
  /**
818
753
  * Friendly english names of success codes.
819
- */ var ZHttpCodeSuccessNames = (_obj = {}, _define_property$2(_obj, 200, "OK"), _define_property$2(_obj, 201, "Created"), _define_property$2(_obj, 202, "Accepted"), _define_property$2(_obj, 203, "Non-Authoritative Information"), _define_property$2(_obj, 204, "No Content"), _define_property$2(_obj, 205, "Reset Content"), _define_property$2(_obj, 206, "Partial Content"), _define_property$2(_obj, 207, "Multi Status"), _define_property$2(_obj, 208, "Already Reported"), _define_property$2(_obj, 226, "IM Used"), _obj);
820
- var _obj1;
754
+ */ const ZHttpCodeSuccessNames = {
755
+ [200]: "OK",
756
+ [201]: "Created",
757
+ [202]: "Accepted",
758
+ [203]: "Non-Authoritative Information",
759
+ [204]: "No Content",
760
+ [205]: "Reset Content",
761
+ [206]: "Partial Content",
762
+ [207]: "Multi Status",
763
+ [208]: "Already Reported",
764
+ [226]: "IM Used"
765
+ };
821
766
  /**
822
767
  * Friendly english descriptions of success codes.
823
- */ var ZHttpCodeSuccessDescriptions = (_obj1 = {}, _define_property$2(_obj1, 200, "The request was successful."), _define_property$2(_obj1, 201, "The request has been fulfilled, resulting in the creation of a new resource."), _define_property$2(_obj1, 202, "The request has been accepted for processing, but the processing has not been completed."), _define_property$2(_obj1, 203, "The server is a transforming proxy that received an OK from its origin,but is returning a modified version of the response."), _define_property$2(_obj1, 204, "The server successfully processed the request and is not returning any content."), _define_property$2(_obj1, 205, "The server successfully processed the request, but is not returning any content. The document view must be refreshed."), _define_property$2(_obj1, 206, "he server is delivering only part of the resource due to a range header sent by the client."), _define_property$2(_obj1, 207, "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."), _define_property$2(_obj1, 208, "The members of a DAV binding have already been enumerated in a preceding part of the response, and are not being included again."), _define_property$2(_obj1, 226, "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."), _obj1);
768
+ */ const ZHttpCodeSuccessDescriptions = {
769
+ [200]: "The request was successful.",
770
+ [201]: "The request has been fulfilled, resulting in the creation of a new resource.",
771
+ [202]: "The request has been accepted for processing, but the processing has not been completed.",
772
+ [203]: "The server is a transforming proxy that received an OK from its origin,but is returning a modified version of the response.",
773
+ [204]: "The server successfully processed the request and is not returning any content.",
774
+ [205]: "The server successfully processed the request, but is not returning any content. The document view must be refreshed.",
775
+ [206]: "he server is delivering only part of the resource due to a range header sent by the client.",
776
+ [207]: "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.",
777
+ [208]: "The members of a DAV binding have already been enumerated in a preceding part of the response, and are not being included again.",
778
+ [226]: "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."
779
+ };
824
780
 
825
781
  /**
826
782
  * Represents the category name for an http code.
@@ -925,24 +881,6 @@ var _obj1;
925
881
  return "Server Error";
926
882
  }
927
883
 
928
- function _class_call_check$2(instance, Constructor) {
929
- if (!(instance instanceof Constructor)) {
930
- throw new TypeError("Cannot call a class as a function");
931
- }
932
- }
933
- function _defineProperties$2(target, props) {
934
- for(var i = 0; i < props.length; i++){
935
- var descriptor = props[i];
936
- descriptor.enumerable = descriptor.enumerable || false;
937
- descriptor.configurable = true;
938
- if ("value" in descriptor) descriptor.writable = true;
939
- Object.defineProperty(target, descriptor.key, descriptor);
940
- }
941
- }
942
- function _create_class$2(Constructor, protoProps, staticProps) {
943
- if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
944
- return Constructor;
945
- }
946
884
  function _define_property$1(obj, key, value) {
947
885
  if (key in obj) {
948
886
  Object.defineProperty(obj, key, {
@@ -956,37 +894,10 @@ function _define_property$1(obj, key, value) {
956
894
  }
957
895
  return obj;
958
896
  }
959
- function _object_spread(target) {
960
- for(var i = 1; i < arguments.length; i++){
961
- var source = arguments[i] != null ? arguments[i] : {};
962
- var ownKeys = Object.keys(source);
963
- if (typeof Object.getOwnPropertySymbols === "function") {
964
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
965
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
966
- }));
967
- }
968
- ownKeys.forEach(function(key) {
969
- _define_property$1(target, key, source[key]);
970
- });
971
- }
972
- return target;
973
- }
974
897
  /**
975
898
  * Represents a builder for an IZHttpResult class.
976
- */ var ZHttpResultBuilder = /*#__PURE__*/ function() {
977
- function ZHttpResultBuilder(data) {
978
- _class_call_check$2(this, ZHttpResultBuilder);
979
- _define_property$1(this, "_result", void 0);
980
- this._result = {
981
- status: ZHttpCodeSuccess.OK,
982
- headers: {},
983
- data: data
984
- };
985
- }
986
- _create_class$2(ZHttpResultBuilder, [
987
- {
988
- key: "data",
989
- value: /**
899
+ */ class ZHttpResultBuilder {
900
+ /**
990
901
  * Sets the data.
991
902
  *
992
903
  * @param data -
@@ -994,14 +905,11 @@ function _object_spread(target) {
994
905
  *
995
906
  * @returns
996
907
  * This object.
997
- */ function data(data) {
998
- this._result.data = data;
999
- return this;
1000
- }
1001
- },
1002
- {
1003
- key: "status",
1004
- value: /**
908
+ */ data(data) {
909
+ this._result.data = data;
910
+ return this;
911
+ }
912
+ /**
1005
913
  * Sets the status code and the english description.
1006
914
  *
1007
915
  * @param code -
@@ -1009,14 +917,11 @@ function _object_spread(target) {
1009
917
  *
1010
918
  * @returns
1011
919
  * This object.
1012
- */ function status(code) {
1013
- this._result.status = code;
1014
- return this;
1015
- }
1016
- },
1017
- {
1018
- key: "headers",
1019
- value: /**
920
+ */ status(code) {
921
+ this._result.status = code;
922
+ return this;
923
+ }
924
+ /**
1020
925
  * Sets the return headers.
1021
926
  *
1022
927
  * @param headers -
@@ -1024,74 +929,35 @@ function _object_spread(target) {
1024
929
  *
1025
930
  * @returns
1026
931
  * This object.
1027
- */ function headers() {
1028
- var headers = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1029
- this._result.headers = headers;
1030
- return this;
1031
- }
1032
- },
1033
- {
1034
- key: "build",
1035
- value: /**
932
+ */ headers(headers = {}) {
933
+ this._result.headers = headers;
934
+ return this;
935
+ }
936
+ /**
1036
937
  * Returns the built up result.
1037
938
  *
1038
939
  * @returns
1039
940
  * A shallow copy of the built up result.
1040
- */ function build() {
1041
- return _object_spread({}, this._result);
1042
- }
1043
- }
1044
- ]);
1045
- return ZHttpResultBuilder;
1046
- }();
1047
-
1048
- function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
1049
- try {
1050
- var info = gen[key](arg);
1051
- var value = info.value;
1052
- } catch (error) {
1053
- reject(error);
1054
- return;
1055
- }
1056
- if (info.done) {
1057
- resolve(value);
1058
- } else {
1059
- Promise.resolve(value).then(_next, _throw);
1060
- }
1061
- }
1062
- function _async_to_generator$1(fn) {
1063
- return function() {
1064
- var self = this, args = arguments;
1065
- return new Promise(function(resolve, reject) {
1066
- var gen = fn.apply(self, args);
1067
- function _next(value) {
1068
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
1069
- }
1070
- function _throw(err) {
1071
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
1072
- }
1073
- _next(undefined);
1074
- });
1075
- };
1076
- }
1077
- function _class_call_check$1(instance, Constructor) {
1078
- if (!(instance instanceof Constructor)) {
1079
- throw new TypeError("Cannot call a class as a function");
941
+ */ build() {
942
+ return {
943
+ ...this._result
944
+ };
1080
945
  }
1081
- }
1082
- function _defineProperties$1(target, props) {
1083
- for(var i = 0; i < props.length; i++){
1084
- var descriptor = props[i];
1085
- descriptor.enumerable = descriptor.enumerable || false;
1086
- descriptor.configurable = true;
1087
- if ("value" in descriptor) descriptor.writable = true;
1088
- Object.defineProperty(target, descriptor.key, descriptor);
946
+ /**
947
+ * Initializes a new instance of this object.
948
+ *
949
+ * @param data -
950
+ * The data result.
951
+ */ constructor(data){
952
+ _define_property$1(this, "_result", void 0);
953
+ this._result = {
954
+ status: ZHttpCodeSuccess.OK,
955
+ headers: {},
956
+ data
957
+ };
1089
958
  }
1090
959
  }
1091
- function _create_class$1(Constructor, protoProps, staticProps) {
1092
- if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
1093
- return Constructor;
1094
- }
960
+
1095
961
  function _define_property(obj, key, value) {
1096
962
  if (key in obj) {
1097
963
  Object.defineProperty(obj, key, {
@@ -1105,109 +971,11 @@ function _define_property(obj, key, value) {
1105
971
  }
1106
972
  return obj;
1107
973
  }
1108
- function _ts_generator$1(thisArg, body) {
1109
- var f, y, t, _ = {
1110
- label: 0,
1111
- sent: function() {
1112
- if (t[0] & 1) throw t[1];
1113
- return t[1];
1114
- },
1115
- trys: [],
1116
- ops: []
1117
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
1118
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
1119
- return this;
1120
- }), g;
1121
- function verb(n) {
1122
- return function(v) {
1123
- return step([
1124
- n,
1125
- v
1126
- ]);
1127
- };
1128
- }
1129
- function step(op) {
1130
- if (f) throw new TypeError("Generator is already executing.");
1131
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
1132
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1133
- if (y = 0, t) op = [
1134
- op[0] & 2,
1135
- t.value
1136
- ];
1137
- switch(op[0]){
1138
- case 0:
1139
- case 1:
1140
- t = op;
1141
- break;
1142
- case 4:
1143
- _.label++;
1144
- return {
1145
- value: op[1],
1146
- done: false
1147
- };
1148
- case 5:
1149
- _.label++;
1150
- y = op[1];
1151
- op = [
1152
- 0
1153
- ];
1154
- continue;
1155
- case 7:
1156
- op = _.ops.pop();
1157
- _.trys.pop();
1158
- continue;
1159
- default:
1160
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1161
- _ = 0;
1162
- continue;
1163
- }
1164
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1165
- _.label = op[1];
1166
- break;
1167
- }
1168
- if (op[0] === 6 && _.label < t[1]) {
1169
- _.label = t[1];
1170
- t = op;
1171
- break;
1172
- }
1173
- if (t && _.label < t[2]) {
1174
- _.label = t[2];
1175
- _.ops.push(op);
1176
- break;
1177
- }
1178
- if (t[2]) _.ops.pop();
1179
- _.trys.pop();
1180
- continue;
1181
- }
1182
- op = body.call(thisArg, _);
1183
- } catch (e) {
1184
- op = [
1185
- 6,
1186
- e
1187
- ];
1188
- y = 0;
1189
- } finally{
1190
- f = t = 0;
1191
- }
1192
- if (op[0] & 5) throw op[1];
1193
- return {
1194
- value: op[0] ? op[1] : void 0,
1195
- done: true
1196
- };
1197
- }
1198
- }
1199
974
  /**
1200
975
  * Represents a mock http service that can be useful for demos,
1201
976
  * testing, and pre-api implementations.
1202
- */ var ZHttpServiceMock = /*#__PURE__*/ function() {
1203
- function ZHttpServiceMock() {
1204
- _class_call_check$1(this, ZHttpServiceMock);
1205
- _define_property(this, "_mapping", {});
1206
- }
1207
- _create_class$1(ZHttpServiceMock, [
1208
- {
1209
- key: "set",
1210
- value: /**
977
+ */ class ZHttpServiceMock {
978
+ /**
1211
979
  * Sets the result of a given endpoint.
1212
980
  *
1213
981
  * @param endpoint -
@@ -1216,16 +984,11 @@ function _ts_generator$1(thisArg, body) {
1216
984
  * The endpoint verb to respond to.
1217
985
  * @param invoke -
1218
986
  * The result method. If this is falsy, then the endpoint is removed.
1219
- */ function set(endpoint, verb, invoke) {
1220
- this._mapping[endpoint] = this._mapping[endpoint] || {};
1221
- this._mapping[endpoint][verb] = typeof invoke === "function" ? invoke : function() {
1222
- return invoke;
1223
- };
1224
- }
1225
- },
1226
- {
1227
- key: "request",
1228
- value: /**
987
+ */ set(endpoint, verb, invoke) {
988
+ this._mapping[endpoint] = this._mapping[endpoint] || {};
989
+ this._mapping[endpoint][verb] = typeof invoke === "function" ? invoke : ()=>invoke;
990
+ }
991
+ /**
1229
992
  * Invokes the request given the allowed api implementations.
1230
993
  *
1231
994
  * @param req -
@@ -1234,40 +997,21 @@ function _ts_generator$1(thisArg, body) {
1234
997
  * @returns
1235
998
  * A promise that resolves with the given result if the status code is less than 400.
1236
999
  * Any status code above 400 will result in a rejected promise.
1237
- */ function request(req) {
1238
- return _async_to_generator$1(function() {
1239
- var endpointConfig, result, notFound, errorThreshold, intermediate;
1240
- return _ts_generator$1(this, function(_state) {
1241
- switch(_state.label){
1242
- case 0:
1243
- endpointConfig = this._mapping[req.url];
1244
- result = endpointConfig === null || endpointConfig === void 0 ? void 0 : endpointConfig[req.method];
1245
- if (result == null) {
1246
- notFound = new ZHttpResultBuilder(null).status(ZHttpCodeClient.NotFound).build();
1247
- return [
1248
- 2,
1249
- Promise.reject(notFound)
1250
- ];
1251
- }
1252
- errorThreshold = 400;
1253
- return [
1254
- 4,
1255
- result(req)
1256
- ];
1257
- case 1:
1258
- intermediate = _state.sent();
1259
- return [
1260
- 2,
1261
- +intermediate.status < errorThreshold ? Promise.resolve(intermediate) : Promise.reject(intermediate)
1262
- ];
1263
- }
1264
- });
1265
- }).call(this);
1266
- }
1000
+ */ async request(req) {
1001
+ const endpointConfig = this._mapping[req.url];
1002
+ const result = endpointConfig?.[req.method];
1003
+ if (result == null) {
1004
+ const notFound = new ZHttpResultBuilder(null).status(ZHttpCodeClient.NotFound).build();
1005
+ return Promise.reject(notFound);
1267
1006
  }
1268
- ]);
1269
- return ZHttpServiceMock;
1270
- }();
1007
+ const errorThreshold = 400;
1008
+ const intermediate = await result(req);
1009
+ return +intermediate.status < errorThreshold ? Promise.resolve(intermediate) : Promise.reject(intermediate);
1010
+ }
1011
+ constructor(){
1012
+ _define_property(this, "_mapping", {});
1013
+ }
1014
+ }
1271
1015
 
1272
1016
  /**
1273
1017
  * A method that determines if an object conforms to a Request BodyInit shape.
@@ -1280,15 +1024,8 @@ function _ts_generator$1(thisArg, body) {
1280
1024
  *
1281
1025
  * @returns
1282
1026
  * True if obj is a BodyInit shape, false otherwise.
1283
- */ function _instanceof(left, right) {
1284
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
1285
- return !!right[Symbol.hasInstance](left);
1286
- } else {
1287
- return left instanceof right;
1288
- }
1289
- }
1290
- function isBodyInit(obj) {
1291
- return obj == null || typeof obj === "string" || _instanceof(obj, Blob) || _instanceof(obj, ArrayBuffer) || ArrayBuffer.isView(obj) || _instanceof(obj, FormData) || _instanceof(obj, URLSearchParams) || _instanceof(obj, ReadableStream);
1027
+ */ function isBodyInit(obj) {
1028
+ return obj == null || typeof obj === "string" || obj instanceof Blob || obj instanceof ArrayBuffer || ArrayBuffer.isView(obj) || obj instanceof FormData || obj instanceof URLSearchParams || obj instanceof ReadableStream;
1292
1029
  }
1293
1030
  /**
1294
1031
  * A helper method that converts an object to a BodyInit.
@@ -1313,228 +1050,48 @@ function isBodyInit(obj) {
1313
1050
  *
1314
1051
  * This will favor a blob as the default type.
1315
1052
  */ function fromContentType(res) {
1316
- var contentType = res.headers.get("content-type");
1317
- if ((contentType === null || contentType === void 0 ? void 0 : contentType.startsWith("application/json")) || (contentType === null || contentType === void 0 ? void 0 : contentType.endsWith("+json"))) {
1053
+ const contentType = res.headers.get("content-type");
1054
+ if (contentType?.startsWith("application/json") || contentType?.endsWith("+json")) {
1318
1055
  return res.json();
1319
1056
  }
1320
- if (contentType === null || contentType === void 0 ? void 0 : contentType.startsWith("multipart/form-data")) {
1057
+ if (contentType?.startsWith("multipart/form-data")) {
1321
1058
  return res.formData();
1322
1059
  }
1323
- if ((contentType === null || contentType === void 0 ? void 0 : contentType.startsWith("text")) || (contentType === null || contentType === void 0 ? void 0 : contentType.endsWith("+xml"))) {
1060
+ if (contentType?.startsWith("text") || contentType?.endsWith("+xml")) {
1324
1061
  return res.text();
1325
1062
  }
1326
1063
  return res.blob();
1327
1064
  }
1328
1065
 
1329
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
1330
- try {
1331
- var info = gen[key](arg);
1332
- var value = info.value;
1333
- } catch (error) {
1334
- reject(error);
1335
- return;
1336
- }
1337
- if (info.done) {
1338
- resolve(value);
1339
- } else {
1340
- Promise.resolve(value).then(_next, _throw);
1341
- }
1342
- }
1343
- function _async_to_generator(fn) {
1344
- return function() {
1345
- var self = this, args = arguments;
1346
- return new Promise(function(resolve, reject) {
1347
- var gen = fn.apply(self, args);
1348
- function _next(value) {
1349
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
1350
- }
1351
- function _throw(err) {
1352
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
1353
- }
1354
- _next(undefined);
1355
- });
1356
- };
1357
- }
1358
- function _class_call_check(instance, Constructor) {
1359
- if (!(instance instanceof Constructor)) {
1360
- throw new TypeError("Cannot call a class as a function");
1361
- }
1362
- }
1363
- function _defineProperties(target, props) {
1364
- for(var i = 0; i < props.length; i++){
1365
- var descriptor = props[i];
1366
- descriptor.enumerable = descriptor.enumerable || false;
1367
- descriptor.configurable = true;
1368
- if ("value" in descriptor) descriptor.writable = true;
1369
- Object.defineProperty(target, descriptor.key, descriptor);
1370
- }
1371
- }
1372
- function _create_class(Constructor, protoProps, staticProps) {
1373
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
1374
- return Constructor;
1375
- }
1376
- function _ts_generator(thisArg, body) {
1377
- var f, y, t, _ = {
1378
- label: 0,
1379
- sent: function() {
1380
- if (t[0] & 1) throw t[1];
1381
- return t[1];
1382
- },
1383
- trys: [],
1384
- ops: []
1385
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
1386
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
1387
- return this;
1388
- }), g;
1389
- function verb(n) {
1390
- return function(v) {
1391
- return step([
1392
- n,
1393
- v
1394
- ]);
1395
- };
1396
- }
1397
- function step(op) {
1398
- if (f) throw new TypeError("Generator is already executing.");
1399
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
1400
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1401
- if (y = 0, t) op = [
1402
- op[0] & 2,
1403
- t.value
1404
- ];
1405
- switch(op[0]){
1406
- case 0:
1407
- case 1:
1408
- t = op;
1409
- break;
1410
- case 4:
1411
- _.label++;
1412
- return {
1413
- value: op[1],
1414
- done: false
1415
- };
1416
- case 5:
1417
- _.label++;
1418
- y = op[1];
1419
- op = [
1420
- 0
1421
- ];
1422
- continue;
1423
- case 7:
1424
- op = _.ops.pop();
1425
- _.trys.pop();
1426
- continue;
1427
- default:
1428
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1429
- _ = 0;
1430
- continue;
1431
- }
1432
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1433
- _.label = op[1];
1434
- break;
1435
- }
1436
- if (op[0] === 6 && _.label < t[1]) {
1437
- _.label = t[1];
1438
- t = op;
1439
- break;
1440
- }
1441
- if (t && _.label < t[2]) {
1442
- _.label = t[2];
1443
- _.ops.push(op);
1444
- break;
1445
- }
1446
- if (t[2]) _.ops.pop();
1447
- _.trys.pop();
1448
- continue;
1449
- }
1450
- op = body.call(thisArg, _);
1451
- } catch (e) {
1452
- op = [
1453
- 6,
1454
- e
1455
- ];
1456
- y = 0;
1457
- } finally{
1458
- f = t = 0;
1459
- }
1460
- if (op[0] & 5) throw op[1];
1461
- return {
1462
- value: op[0] ? op[1] : void 0,
1463
- done: true
1464
- };
1465
- }
1466
- }
1467
1066
  /**
1468
1067
  * Represents an axios based implementation of the http service.
1469
- */ var ZHttpService = /*#__PURE__*/ function() {
1470
- function ZHttpService() {
1471
- _class_call_check(this, ZHttpService);
1472
- }
1473
- _create_class(ZHttpService, [
1474
- {
1475
- key: "request",
1476
- value: /**
1068
+ */ class ZHttpService {
1069
+ /**
1477
1070
  * Invokes the request with a real http service.
1478
1071
  *
1479
1072
  * @param req -
1480
1073
  * The request information to make.
1481
- */ function request(req) {
1482
- return _async_to_generator(function() {
1483
- var res, data, result, e, result1;
1484
- return _ts_generator(this, function(_state) {
1485
- switch(_state.label){
1486
- case 0:
1487
- _state.trys.push([
1488
- 0,
1489
- 3,
1490
- ,
1491
- 4
1492
- ]);
1493
- return [
1494
- 4,
1495
- fetch(req.url, {
1496
- method: req.method,
1497
- body: isBodyInit(req.body) ? req.body : JSON.stringify(req.body),
1498
- headers: req.headers,
1499
- redirect: "follow"
1500
- })
1501
- ];
1502
- case 1:
1503
- res = _state.sent();
1504
- return [
1505
- 4,
1506
- fromContentType(res)
1507
- ];
1508
- case 2:
1509
- data = _state.sent();
1510
- result = new ZHttpResultBuilder(data).headers(res.headers).status(res.status).build();
1511
- return [
1512
- 2,
1513
- res.ok ? Promise.resolve(result) : Promise.reject(result)
1514
- ];
1515
- case 3:
1516
- e = _state.sent();
1517
- result1 = new ZHttpResultBuilder(e.message).headers().status(ZHttpCodeServer.InternalServerError);
1518
- if (e.code === "ENOTFOUND") {
1519
- // The request was made, but some DNS lookup failed.
1520
- result1 = result1.status(ZHttpCodeClient.NotFound);
1521
- }
1522
- return [
1523
- 2,
1524
- Promise.reject(result1.build())
1525
- ];
1526
- case 4:
1527
- return [
1528
- 2
1529
- ];
1530
- }
1531
- });
1532
- })();
1074
+ */ async request(req) {
1075
+ try {
1076
+ const res = await fetch(req.url, {
1077
+ method: req.method,
1078
+ body: isBodyInit(req.body) ? req.body : JSON.stringify(req.body),
1079
+ headers: req.headers,
1080
+ redirect: "follow"
1081
+ });
1082
+ const data = await fromContentType(res);
1083
+ const result = new ZHttpResultBuilder(data).headers(res.headers).status(res.status).build();
1084
+ return res.ok ? Promise.resolve(result) : Promise.reject(result);
1085
+ } catch (e) {
1086
+ let result = new ZHttpResultBuilder(e.message).headers().status(ZHttpCodeServer.InternalServerError);
1087
+ if (e.code === "ENOTFOUND") {
1088
+ // The request was made, but some DNS lookup failed.
1089
+ result = result.status(ZHttpCodeClient.NotFound);
1533
1090
  }
1091
+ return Promise.reject(result.build());
1534
1092
  }
1535
- ]);
1536
- return ZHttpService;
1537
- }();
1093
+ }
1094
+ }
1538
1095
 
1539
1096
  export { ZHttpCodeCategory, ZHttpCodeClient, ZHttpCodeClientDescriptions, ZHttpCodeClientNames, ZHttpCodeInformationalResponse, ZHttpCodeInformationalResponseDescriptions, ZHttpCodeInformationalResponseNames, ZHttpCodeRedirection, ZHttpCodeRedirectionDescriptions, ZHttpCodeRedirectionNames, ZHttpCodeServer, ZHttpCodeServerDescriptions, ZHttpCodeServerNames, ZHttpCodeSeverity, ZHttpCodeSuccess, ZHttpCodeSuccessDescriptions, ZHttpCodeSuccessNames, ZHttpMethod, ZHttpRequestBuilder, ZHttpResultBuilder, ZHttpService, ZHttpServiceMock, fromContentType, getHttpCodeCategory, getHttpCodeDescription, getHttpCodeName, getHttpCodeSeverity, isBodyInit, toBodyInit };
1540
1097
  //# sourceMappingURL=index.js.map