@dynatrace-sdk/http-client 0.4.4

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +3 -0
  3. package/cjs/index.js +455 -0
  4. package/docs/DOCS.md +1813 -0
  5. package/dynatrace-metadata.json +5 -0
  6. package/esm/index.js +435 -0
  7. package/package.json +10 -0
  8. package/types/index.d.ts +1 -0
  9. package/types/packages/http-client/src/index.d.ts +2 -0
  10. package/types/packages/http-client/src/lib/platform/abort-controller.d.ts +6 -0
  11. package/types/packages/http-client/src/lib/platform/abort-signal.d.ts +6 -0
  12. package/types/packages/http-client/src/lib/platform/apply-content-type-header.d.ts +2 -0
  13. package/types/packages/http-client/src/lib/platform/base-error.d.ts +5 -0
  14. package/types/packages/http-client/src/lib/platform/binary.d.ts +13 -0
  15. package/types/packages/http-client/src/lib/platform/data-type-error.d.ts +6 -0
  16. package/types/packages/http-client/src/lib/platform/decode-response-body.d.ts +3 -0
  17. package/types/packages/http-client/src/lib/platform/default-status-validator.d.ts +2 -0
  18. package/types/packages/http-client/src/lib/platform/encode-request-body.d.ts +2 -0
  19. package/types/packages/http-client/src/lib/platform/http-client-abort-error.d.ts +7 -0
  20. package/types/packages/http-client/src/lib/platform/http-client-request-error.d.ts +7 -0
  21. package/types/packages/http-client/src/lib/platform/http-client-response-error-serializer.d.ts +1 -0
  22. package/types/packages/http-client/src/lib/platform/http-client-response-error.d.ts +8 -0
  23. package/types/packages/http-client/src/lib/platform/http-client-response.d.ts +10 -0
  24. package/types/packages/http-client/src/lib/platform/http-client.d.ts +5 -0
  25. package/types/packages/http-client/src/lib/platform/index.d.ts +11 -0
  26. package/types/packages/http-client/src/lib/platform/unsupported-operation-error.d.ts +6 -0
  27. package/types/packages/http-client/src/lib/types/abort-controller.d.ts +14 -0
  28. package/types/packages/http-client/src/lib/types/abort-signal.d.ts +15 -0
  29. package/types/packages/http-client/src/lib/types/base-error.d.ts +4 -0
  30. package/types/packages/http-client/src/lib/types/binary.d.ts +15 -0
  31. package/types/packages/http-client/src/lib/types/data-type-error.d.ts +14 -0
  32. package/types/packages/http-client/src/lib/types/data-types.d.ts +36 -0
  33. package/types/packages/http-client/src/lib/types/form-data-request-body.d.ts +83 -0
  34. package/types/packages/http-client/src/lib/types/form-data-response-body.d.ts +15 -0
  35. package/types/packages/http-client/src/lib/types/headers.d.ts +6 -0
  36. package/types/packages/http-client/src/lib/types/http-client-abort-error.d.ts +14 -0
  37. package/types/packages/http-client/src/lib/types/http-client-network-error.d.ts +14 -0
  38. package/types/packages/http-client/src/lib/types/http-client-request-error.d.ts +14 -0
  39. package/types/packages/http-client/src/lib/types/http-client-request-options.d.ts +42 -0
  40. package/types/packages/http-client/src/lib/types/http-client-response-error.d.ts +19 -0
  41. package/types/packages/http-client/src/lib/types/http-client-response.d.ts +33 -0
  42. package/types/packages/http-client/src/lib/types/http-client.d.ts +24 -0
  43. package/types/packages/http-client/src/lib/types/index.d.ts +20 -0
  44. package/types/packages/http-client/src/lib/types/request-body-types.d.ts +26 -0
  45. package/types/packages/http-client/src/lib/types/response-body-types.d.ts +46 -0
  46. package/types/packages/http-client/src/lib/types/status-validator.d.ts +7 -0
  47. package/types/packages/http-client/src/lib/types/unsupported-operation-error.d.ts +14 -0
@@ -0,0 +1,5 @@
1
+ {
2
+ "docs": {
3
+ "title": "http-client"
4
+ }
5
+ }
package/esm/index.js ADDED
@@ -0,0 +1,435 @@
1
+ // packages/http-client/src/lib/platform/abort-controller.ts
2
+ var AbortController = globalThis.AbortController;
3
+
4
+ // packages/http-client/src/lib/platform/abort-signal.ts
5
+ var AbortSignal = globalThis.AbortSignal;
6
+
7
+ // packages/http-client/src/lib/platform/base-error.ts
8
+ var BaseError = class extends Error {
9
+ constructor(message, cause) {
10
+ super(message);
11
+ this.cause = cause;
12
+ }
13
+ };
14
+
15
+ // packages/http-client/src/lib/platform/unsupported-operation-error.ts
16
+ var UnsupportedOperationError = class extends BaseError {
17
+ name = "UnsupportedOperationError";
18
+ constructor(message, cause) {
19
+ super(message, cause);
20
+ }
21
+ };
22
+
23
+ // packages/http-client/src/lib/platform/binary.ts
24
+ function getImpl(data, type) {
25
+ const response = new Response(data);
26
+ switch (type) {
27
+ case "text":
28
+ return response.text();
29
+ case "json":
30
+ return response.json();
31
+ case "array-buffer":
32
+ return response.arrayBuffer();
33
+ case "blob":
34
+ return response.blob();
35
+ case "readable-stream":
36
+ return response.body;
37
+ }
38
+ throw new UnsupportedOperationError(`Unsupported binary type: ${type}.`);
39
+ }
40
+ var Binary = class {
41
+ constructor(data) {
42
+ this.data = data;
43
+ }
44
+ static fromText(text) {
45
+ return new Binary(new Blob([text]));
46
+ }
47
+ static fromJson(json) {
48
+ return new Binary(new Blob([JSON.stringify(json)]));
49
+ }
50
+ static from(data) {
51
+ if (data instanceof Blob || data instanceof ArrayBuffer || data instanceof ReadableStream) {
52
+ return new Binary(data);
53
+ } else {
54
+ throw new UnsupportedOperationError("Unsupported binary type.");
55
+ }
56
+ }
57
+ get(type) {
58
+ return getImpl(this.data, type);
59
+ }
60
+ };
61
+ function isBinary(body) {
62
+ return typeof body.get === "function";
63
+ }
64
+
65
+ // packages/http-client/src/lib/platform/data-type-error.ts
66
+ var DataTypeError = class extends BaseError {
67
+ name = "DataTypeError";
68
+ constructor(message, cause) {
69
+ super(message, cause);
70
+ }
71
+ };
72
+
73
+ // packages/http-client/src/lib/platform/default-status-validator.ts
74
+ var defaultStatusValidator = (status) => 200 <= status && status < 300;
75
+
76
+ // packages/http-client/src/lib/platform/encode-request-body.ts
77
+ function encodeTextRequestBody(body) {
78
+ return String(body);
79
+ }
80
+ function encodeJsonRequestBody(body) {
81
+ return JSON.stringify(body);
82
+ }
83
+ async function encodeBinaryFormDataField(field) {
84
+ if (field instanceof ArrayBuffer || field instanceof Blob) {
85
+ return field;
86
+ } else if (field instanceof ReadableStream) {
87
+ return new Response(field).arrayBuffer();
88
+ } else if (isBinary(field)) {
89
+ return field.get("array-buffer");
90
+ } else {
91
+ throw new DataTypeError("Cannot encode form data field as binary type.");
92
+ }
93
+ }
94
+ async function encodeFormDataRequestBody(body) {
95
+ const formData = new FormData();
96
+ for (const field of body) {
97
+ switch (field.type) {
98
+ case "text":
99
+ formData.append(field.name, encodeTextRequestBody(field.value));
100
+ break;
101
+ case "json":
102
+ formData.append(
103
+ field.name,
104
+ new Blob([encodeJsonRequestBody(field.value)], {
105
+ type: field.contentType ?? "application/json"
106
+ }),
107
+ field.filename ?? "json"
108
+ );
109
+ break;
110
+ case "binary": {
111
+ if (field.value instanceof File) {
112
+ const file = field.value;
113
+ formData.append(
114
+ field.name,
115
+ new File([file], field.filename ?? file.name, {
116
+ type: field.contentType ?? file.type ?? "application/octet-stream",
117
+ lastModified: file.lastModified
118
+ }),
119
+ field.filename ?? file.name
120
+ );
121
+ } else {
122
+ const blobType = "type" in field.value ? field.value.type : void 0;
123
+ formData.append(
124
+ field.name,
125
+ new Blob([await encodeBinaryFormDataField(field.value)], {
126
+ type: field.contentType ?? blobType ?? "application/octet-stream"
127
+ }),
128
+ field.filename ?? "binary"
129
+ );
130
+ }
131
+ break;
132
+ }
133
+ }
134
+ }
135
+ return formData;
136
+ }
137
+ async function encodeBinaryRequestBody(body) {
138
+ if (body instanceof Blob || body instanceof ArrayBuffer || body instanceof ReadableStream) {
139
+ return body;
140
+ } else if (isBinary(body)) {
141
+ try {
142
+ return await body.get("array-buffer");
143
+ } catch (e) {
144
+ throw new DataTypeError("Cannot encode body as binary type.", e);
145
+ }
146
+ } else {
147
+ throw new DataTypeError("Cannot encode body as binary type.");
148
+ }
149
+ }
150
+ async function encodeRequestBody(body, requestBodyType) {
151
+ switch (requestBodyType) {
152
+ case "text":
153
+ return encodeTextRequestBody(body);
154
+ case "json":
155
+ return encodeJsonRequestBody(body);
156
+ case "form-data":
157
+ return await encodeFormDataRequestBody(body);
158
+ case "binary":
159
+ return await encodeBinaryRequestBody(body);
160
+ }
161
+ throw new DataTypeError(`Invalid body type: '${requestBodyType}'`);
162
+ }
163
+
164
+ // packages/http-client/src/lib/platform/apply-content-type-header.ts
165
+ function getContentTypeBy(bodyType) {
166
+ switch (bodyType) {
167
+ case "json":
168
+ return "application/json";
169
+ case "text":
170
+ return "text/plain";
171
+ case "binary":
172
+ return "application/octet-stream";
173
+ }
174
+ throw new DataTypeError(`Invalid body type: '${bodyType}'`);
175
+ }
176
+ function applyContentTypeHeader(headers, requestBodyType) {
177
+ const isContentTypePresent = Object.keys(headers ?? {}).some(
178
+ (header) => header.toLowerCase() === "content-type"
179
+ );
180
+ if (!isContentTypePresent && requestBodyType !== "form-data") {
181
+ return {
182
+ "content-type": getContentTypeBy(requestBodyType),
183
+ ...headers
184
+ };
185
+ }
186
+ return headers;
187
+ }
188
+
189
+ // packages/http-client/src/lib/platform/http-client-abort-error.ts
190
+ var HttpClientAbortError = class extends Error {
191
+ constructor(cause) {
192
+ super(
193
+ typeof cause?.message === "string" ? `Request aborted: ${cause.message}` : "Request aborted."
194
+ );
195
+ this.cause = cause;
196
+ }
197
+ name = "AbortError";
198
+ };
199
+ var throwIfAbortError = (e) => {
200
+ if (e instanceof DOMException && e.name === "AbortError") {
201
+ throw new HttpClientAbortError(e);
202
+ }
203
+ };
204
+
205
+ // packages/http-client/src/lib/platform/http-client-request-error.ts
206
+ var HttpClientRequestError = class extends BaseError {
207
+ constructor(cause) {
208
+ super("Request failed.");
209
+ this.cause = cause;
210
+ }
211
+ name = "RequestError";
212
+ };
213
+
214
+ // packages/http-client/src/lib/platform/decode-response-body.ts
215
+ function emptyReadableStream() {
216
+ return new ReadableStream({
217
+ start(controller) {
218
+ controller.close();
219
+ }
220
+ });
221
+ }
222
+ async function decodeTextResponseBody(response) {
223
+ return response.body !== null ? response.text() : "";
224
+ }
225
+ async function decodeJsonResponseBody(response) {
226
+ return response.body !== null ? response.json() : null;
227
+ }
228
+ async function decodeBinaryResponseBody(response) {
229
+ return Binary.from(decodeReadableStreamResponseBody(response));
230
+ }
231
+ async function decodeFormDataResponseBody(response) {
232
+ if (response.body === null) {
233
+ return [];
234
+ } else {
235
+ const formData = await response.formData();
236
+ const result = [];
237
+ formData.forEach((value, key) => {
238
+ if (value instanceof File) {
239
+ result.push({
240
+ type: "binary",
241
+ name: key,
242
+ contentType: value.type,
243
+ filename: value.name,
244
+ value: Binary.from(value)
245
+ });
246
+ } else {
247
+ result.push({
248
+ type: "text",
249
+ name: key,
250
+ value
251
+ });
252
+ }
253
+ });
254
+ return result;
255
+ }
256
+ }
257
+ async function decodeArrayBufferResponseBody(response) {
258
+ return response !== null ? response.arrayBuffer() : new ArrayBuffer(0);
259
+ }
260
+ async function decodeBlobResponseBody(response) {
261
+ return response !== null ? response.blob() : new Blob();
262
+ }
263
+ function decodeReadableStreamResponseBody(response) {
264
+ return response.body !== null ? response.body : emptyReadableStream();
265
+ }
266
+ async function decodeAsyncResponseBody(response, responseBodyType) {
267
+ try {
268
+ switch (responseBodyType) {
269
+ case "text":
270
+ return await decodeTextResponseBody(response);
271
+ case "json":
272
+ return await decodeJsonResponseBody(response);
273
+ case "binary":
274
+ return await decodeBinaryResponseBody(response);
275
+ case "form-data":
276
+ return await decodeFormDataResponseBody(response);
277
+ case "array-buffer":
278
+ return await decodeArrayBufferResponseBody(response);
279
+ case "blob":
280
+ return await decodeBlobResponseBody(response);
281
+ }
282
+ } catch (e) {
283
+ throwIfAbortError(e);
284
+ throw new DataTypeError(
285
+ `Response body does not conform to the specified response body type: '${responseBodyType}'.`,
286
+ e
287
+ );
288
+ }
289
+ }
290
+ function decodeSyncResponseBody(response, responseBodyType) {
291
+ try {
292
+ return decodeReadableStreamResponseBody(response);
293
+ } catch (e) {
294
+ throwIfAbortError(e);
295
+ throw new DataTypeError(
296
+ `Response body does not conform to the specified response body type: '${responseBodyType}'.`,
297
+ e
298
+ );
299
+ }
300
+ }
301
+ function decodeResponseBodyImpl(response, responseBodyType) {
302
+ switch (responseBodyType) {
303
+ case "text":
304
+ case "json":
305
+ case "binary":
306
+ case "form-data":
307
+ case "array-buffer":
308
+ case "blob":
309
+ return decodeAsyncResponseBody(response, responseBodyType);
310
+ case "readable-stream":
311
+ return decodeSyncResponseBody(response, responseBodyType);
312
+ }
313
+ switch (responseBodyType) {
314
+ case "buffer":
315
+ case "stream":
316
+ throw new UnsupportedOperationError(
317
+ `Unsupported response body type: '${responseBodyType}'`
318
+ );
319
+ default:
320
+ throw new DataTypeError(`Invalid body type: '${responseBodyType}'`);
321
+ }
322
+ }
323
+ function decodeResponseBody(response, responseBodyType) {
324
+ return decodeResponseBodyImpl(
325
+ response,
326
+ responseBodyType
327
+ );
328
+ }
329
+
330
+ // packages/http-client/src/lib/platform/http-client-response.ts
331
+ var HttpClientResponse = class {
332
+ constructor(response) {
333
+ this.response = response;
334
+ }
335
+ get url() {
336
+ return this.response.url;
337
+ }
338
+ get status() {
339
+ return this.response.status;
340
+ }
341
+ get statusText() {
342
+ return this.response.statusText;
343
+ }
344
+ get headers() {
345
+ const headers = {};
346
+ this.response.headers.forEach((value, key) => {
347
+ headers[key] = value;
348
+ });
349
+ return headers;
350
+ }
351
+ body(responseBodyType = "json") {
352
+ return decodeResponseBody(this.response, responseBodyType);
353
+ }
354
+ };
355
+
356
+ // packages/http-client/src/lib/platform/http-client-response-error-serializer.ts
357
+ import {
358
+ addGlobalErrorSerializer,
359
+ ErrorType
360
+ } from "@dynatrace/sdk-web";
361
+ var errorSerializerAdded = false;
362
+ function addHttpClientResponseErrorSerializer() {
363
+ if (!errorSerializerAdded && typeof window.dtSdk !== "undefined") {
364
+ addGlobalErrorSerializer(httpClientResponseErrorSerializer);
365
+ errorSerializerAdded = true;
366
+ }
367
+ }
368
+ var httpClientResponseErrorSerializer = async (error) => {
369
+ if (error instanceof HttpClientResponseError) {
370
+ const status = error.response.status;
371
+ const message = await error.response.body("text");
372
+ return {
373
+ name: error.name,
374
+ status,
375
+ message,
376
+ stack: error.stack,
377
+ type: ErrorType.HTTP
378
+ };
379
+ }
380
+ };
381
+
382
+ // packages/http-client/src/lib/platform/http-client-response-error.ts
383
+ var HttpClientResponseError = class extends BaseError {
384
+ name = "ResponseError";
385
+ response;
386
+ constructor(response) {
387
+ addHttpClientResponseErrorSerializer();
388
+ super(`HTTP Error ${response.status}: ${response.statusText}`);
389
+ this.response = new HttpClientResponse(response);
390
+ }
391
+ };
392
+
393
+ // packages/http-client/src/lib/platform/http-client.ts
394
+ var send = async (info, init) => {
395
+ try {
396
+ return await fetch(info, init);
397
+ } catch (e) {
398
+ throwIfAbortError(e);
399
+ throw new HttpClientRequestError(e);
400
+ }
401
+ };
402
+ var HttpClient = class {
403
+ async send(options) {
404
+ const { statusValidator = defaultStatusValidator } = options;
405
+ const requestBodyType = options.requestBodyType ?? "json";
406
+ const body = options.body !== void 0 ? await encodeRequestBody(options.body, requestBodyType) : void 0;
407
+ const response = await send(options.url, {
408
+ method: options.method,
409
+ headers: applyContentTypeHeader(options.headers, requestBodyType),
410
+ signal: options.abortSignal,
411
+ body
412
+ });
413
+ const ok = statusValidator(response.status);
414
+ if (ok) {
415
+ return new HttpClientResponse(response);
416
+ } else {
417
+ throw new HttpClientResponseError(response);
418
+ }
419
+ }
420
+ };
421
+ var httpClient = new HttpClient();
422
+ export {
423
+ AbortController as PlatformAbortController,
424
+ AbortSignal as PlatformAbortSignal,
425
+ BaseError as PlatformBaseError,
426
+ Binary as PlatformBinary,
427
+ DataTypeError as PlatformDataTypeError,
428
+ HttpClient as PlatformHttpClient,
429
+ HttpClientAbortError as PlatformHttpClientAbortError,
430
+ HttpClientRequestError as PlatformHttpClientRequestError,
431
+ HttpClientResponse as PlatformHttpClientResponse,
432
+ HttpClientResponseError as PlatformHttpClientResponseError,
433
+ UnsupportedOperationError as PlatformUnsupportedOperationError,
434
+ httpClient
435
+ };
package/package.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "@dynatrace-sdk/http-client",
3
+ "version": "0.4.4",
4
+ "dependencies": {
5
+ "@dynatrace/sdk-web": ">=0.5.12"
6
+ },
7
+ "main": "./cjs/index.js",
8
+ "module": "./esm/index.js",
9
+ "types": "./types/index.d.ts"
10
+ }
@@ -0,0 +1 @@
1
+ export * from './packages/http-client/src';
@@ -0,0 +1,2 @@
1
+ export { AbortController, AbortSignal, BaseError, Binary, BinaryFormDataRequestField, BinaryFormDataResponseField, DataTypeError, DataTypes, FormDataRequestBody, FormDataRequestField, FormDataResponseBody, FormDataResponseField, Headers, HttpClient, HttpClientAbortError, HttpClientNetworkError, HttpClientRequestError, HttpClientRequestOptions, HttpClientResponse, HttpClientResponseError, JsonFormDataRequestField, RequestBodyTypes, ResponseBodyTypes, StatusValidator, TextFormDataRequestField, TextFormDataResponseField, UnsupportedOperationError, } from './lib/types';
2
+ export { AbortController as PlatformAbortController, AbortSignal as PlatformAbortSignal, BaseError as PlatformBaseError, Binary as PlatformBinary, DataTypeError as PlatformDataTypeError, HttpClient as PlatformHttpClient, HttpClientAbortError as PlatformHttpClientAbortError, HttpClientRequestError as PlatformHttpClientRequestError, HttpClientResponse as PlatformHttpClientResponse, HttpClientResponseError as PlatformHttpClientResponseError, UnsupportedOperationError as PlatformUnsupportedOperationError, httpClient, } from './lib/platform';
@@ -0,0 +1,6 @@
1
+ import * as types from '../types';
2
+ declare const AbortController: {
3
+ new (): types.AbortController;
4
+ };
5
+ declare type AbortController = InstanceType<typeof AbortController>;
6
+ export { AbortController };
@@ -0,0 +1,6 @@
1
+ import * as types from '../types';
2
+ declare const AbortSignal: {
3
+ new (): types.AbortSignal;
4
+ };
5
+ declare type AbortSignal = InstanceType<typeof AbortSignal>;
6
+ export { AbortSignal };
@@ -0,0 +1,2 @@
1
+ import { Headers, RequestBodyTypes } from '../types';
2
+ export declare function applyContentTypeHeader<T extends keyof RequestBodyTypes>(headers: Headers | undefined, requestBodyType: T): Headers | undefined;
@@ -0,0 +1,5 @@
1
+ import * as types from '../types';
2
+ export declare abstract class BaseError extends Error implements types.BaseError {
3
+ readonly cause?: any;
4
+ protected constructor(message: string, cause?: any);
5
+ }
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import type * as stream from 'stream';
4
+ import * as types from '../types';
5
+ export declare class Binary implements types.Binary {
6
+ readonly data: Blob | ArrayBuffer | ReadableStream<Uint8Array>;
7
+ static fromText(text: string): Binary;
8
+ static fromJson(json: any): Binary;
9
+ static from(data: Blob | ArrayBuffer | ReadableStream<Uint8Array> | Buffer | stream.Readable): Binary;
10
+ private constructor();
11
+ get<T extends keyof types.DataTypes>(type: T): types.DataTypes[T];
12
+ }
13
+ export declare function isBinary(body: any): body is Binary;
@@ -0,0 +1,6 @@
1
+ import * as types from '../types';
2
+ import { BaseError } from './base-error';
3
+ export declare class DataTypeError extends BaseError implements types.DataTypeError {
4
+ readonly name = "DataTypeError";
5
+ constructor(message: string, cause?: any);
6
+ }
@@ -0,0 +1,3 @@
1
+ import * as types from '../types';
2
+ import { ResponseBodyTypes } from '../types';
3
+ export declare function decodeResponseBody<T extends keyof types.ResponseBodyTypes>(response: Response, responseBodyType: T): ResponseBodyTypes[T];
@@ -0,0 +1,2 @@
1
+ import { StatusValidator } from '../types';
2
+ export declare const defaultStatusValidator: StatusValidator;
@@ -0,0 +1,2 @@
1
+ import { RequestBodyTypes } from '../types';
2
+ export declare function encodeRequestBody<T extends keyof RequestBodyTypes>(body: RequestBodyTypes[T], requestBodyType: T): Promise<string | ArrayBuffer | Blob | ReadableStream<any> | FormData>;
@@ -0,0 +1,7 @@
1
+ import * as types from '../types';
2
+ export declare class HttpClientAbortError extends Error implements types.HttpClientAbortError {
3
+ readonly cause: any;
4
+ readonly name = "AbortError";
5
+ constructor(cause: any);
6
+ }
7
+ export declare const throwIfAbortError: (e: unknown) => void;
@@ -0,0 +1,7 @@
1
+ import * as types from '../types';
2
+ import { BaseError } from './base-error';
3
+ export declare class HttpClientRequestError extends BaseError implements types.HttpClientRequestError {
4
+ readonly cause: any;
5
+ readonly name = "RequestError";
6
+ constructor(cause: any);
7
+ }
@@ -0,0 +1 @@
1
+ export declare function addHttpClientResponseErrorSerializer(): void;
@@ -0,0 +1,8 @@
1
+ import * as types from '../types';
2
+ import { HttpClientResponse } from './http-client-response';
3
+ import { BaseError } from './base-error';
4
+ export declare class HttpClientResponseError extends BaseError implements types.HttpClientResponseError {
5
+ readonly name = "ResponseError";
6
+ readonly response: HttpClientResponse;
7
+ constructor(response: Response);
8
+ }
@@ -0,0 +1,10 @@
1
+ import * as types from '../types';
2
+ export declare class HttpClientResponse implements types.HttpClientResponse {
3
+ private response;
4
+ constructor(response: Response);
5
+ get url(): string;
6
+ get status(): number;
7
+ get statusText(): string;
8
+ get headers(): types.Headers;
9
+ body<T extends keyof types.ResponseBodyTypes = 'json'>(responseBodyType?: T): types.ResponseBodyTypes[T];
10
+ }
@@ -0,0 +1,5 @@
1
+ import * as types from '../types';
2
+ export declare class HttpClient implements types.HttpClient {
3
+ send<T extends keyof types.RequestBodyTypes = 'json'>(options: types.HttpClientRequestOptions<T>): Promise<types.HttpClientResponse>;
4
+ }
5
+ export declare const httpClient: HttpClient;
@@ -0,0 +1,11 @@
1
+ export * from './abort-controller';
2
+ export * from './abort-signal';
3
+ export * from './base-error';
4
+ export * from './binary';
5
+ export * from './data-type-error';
6
+ export * from './http-client';
7
+ export * from './http-client-abort-error';
8
+ export * from './http-client-request-error';
9
+ export * from './http-client-response';
10
+ export * from './http-client-response-error';
11
+ export * from './unsupported-operation-error';
@@ -0,0 +1,6 @@
1
+ import * as types from '../types';
2
+ import { BaseError } from './base-error';
3
+ export declare class UnsupportedOperationError extends BaseError implements types.UnsupportedOperationError {
4
+ readonly name = "UnsupportedOperationError";
5
+ constructor(message: string, cause?: any);
6
+ }
@@ -0,0 +1,14 @@
1
+ import { AbortSignal } from './abort-signal';
2
+ /**
3
+ * Represents a controller object that allows to abort one or more requests as and when desired.
4
+ */
5
+ export interface AbortController {
6
+ /**
7
+ * Aborts a request before it has completed.
8
+ */
9
+ abort(): void;
10
+ /**
11
+ * Returns an AbortSignal object instance, which can be used to communicate with a request.
12
+ */
13
+ signal: AbortSignal;
14
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Represents a signal object that allows to communicate with the request and abort it using the `AbortController`.
3
+ */
4
+ export interface AbortSignal extends EventTarget {
5
+ readonly reason: any;
6
+ throwIfAborted(): void;
7
+ /**
8
+ * A flag indicating whether the requests the signal is communicating with are aborted.
9
+ */
10
+ readonly aborted: boolean;
11
+ /**
12
+ * Invoked when the requests the signal is communicating with are aborted.
13
+ */
14
+ onabort: ((this: AbortSignal, event: Event) => void) | null;
15
+ }
@@ -0,0 +1,4 @@
1
+ export interface BaseError extends Error {
2
+ readonly name: string;
3
+ readonly cause?: any;
4
+ }
@@ -0,0 +1,15 @@
1
+ import { DataTypes } from './data-types';
2
+ /**
3
+ * Represents an environment agnostic (browser vs node) abstraction layer for binary data.
4
+ */
5
+ export interface Binary {
6
+ /**
7
+ * Returns the binary data in a form that conforms to the specified type.
8
+ *
9
+ * @param type The type of the data.
10
+ * Can be `text`, `json`, `array-buffer`, `blob`, `readable-stream`, `buffer` or `stream`.
11
+ * @throws DataTypeError when the data does not conform to the specified type.
12
+ * @throws UnsupportedOperationError when the type is not supported by the platform.
13
+ */
14
+ get<T extends keyof DataTypes>(type: T): DataTypes[T];
15
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Represents a situation when the response body does not conform to the specified response body type.
3
+ */
4
+ import { BaseError } from './base-error';
5
+ export interface DataTypeError extends BaseError {
6
+ /**
7
+ * The error name.
8
+ */
9
+ readonly name: 'DataTypeError';
10
+ /**
11
+ * The error root cause.
12
+ */
13
+ readonly cause?: any;
14
+ }