@dynatrace-sdk/http-client 1.1.1 → 1.2.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/CHANGELOG.md +7 -0
- package/cjs/index.js +16 -2
- package/docs/DOCS.md +177 -96
- package/esm/index.js +16 -2
- package/package.json +1 -1
- package/types/packages/http-client/src/lib/platform/http-client.d.ts +19 -0
package/CHANGELOG.md
CHANGED
package/cjs/index.js
CHANGED
|
@@ -544,13 +544,27 @@ var send = async (info, init) => {
|
|
|
544
544
|
}
|
|
545
545
|
};
|
|
546
546
|
var HttpClient = class {
|
|
547
|
+
_baseUrl;
|
|
548
|
+
_defaultHeaders;
|
|
549
|
+
constructor(options) {
|
|
550
|
+
this._baseUrl = options?.baseUrl;
|
|
551
|
+
this._defaultHeaders = options?.defaultHeaders;
|
|
552
|
+
}
|
|
553
|
+
_setBaseURL(baseUrl) {
|
|
554
|
+
this._baseUrl = baseUrl;
|
|
555
|
+
}
|
|
556
|
+
_setDefaultHeaders(defaultHeaders) {
|
|
557
|
+
this._defaultHeaders = defaultHeaders;
|
|
558
|
+
}
|
|
547
559
|
async send(options) {
|
|
548
560
|
const { statusValidator = defaultStatusValidator } = options;
|
|
549
561
|
const requestBodyType = options.requestBodyType ?? "json";
|
|
550
562
|
const body = options.body !== void 0 ? await encodeRequestBody(options.body, requestBodyType) : void 0;
|
|
551
|
-
const
|
|
563
|
+
const url = this._baseUrl ? new URL(options.url, this._baseUrl).toString() : options.url;
|
|
564
|
+
const requestHeaders = { ...this._defaultHeaders, ...options?.headers };
|
|
565
|
+
const response = await send(url, {
|
|
552
566
|
method: options.method,
|
|
553
|
-
headers: applyContentTypeHeader(
|
|
567
|
+
headers: applyContentTypeHeader(requestHeaders, requestBodyType),
|
|
554
568
|
signal: options.abortSignal,
|
|
555
569
|
body
|
|
556
570
|
});
|
package/docs/DOCS.md
CHANGED
|
@@ -15,7 +15,7 @@ import NpmLogo from '@site/static/img/npm-logo.png';
|
|
|
15
15
|
<a href="https://www.npmjs.com/package/@dynatrace-sdk/http-client" target="_blank" rel="noopener noreferrer"> <span class="margin-right--xs">@dynatrace-sdk/http-client</span> <img className="no-zoom" width="20px" src={NpmLogo} /> </a>
|
|
16
16
|
</div>
|
|
17
17
|
<div class="col" style={{textAlign: 'right'}}>
|
|
18
|
-
<a href="https://www.npmjs.com/package/@dynatrace-sdk/http-client/v/1.
|
|
18
|
+
<a href="https://www.npmjs.com/package/@dynatrace-sdk/http-client/v/1.2.0" target="_blank" rel="noopener noreferrer">v1.2.0</a>
|
|
19
19
|
</div>
|
|
20
20
|
</div>
|
|
21
21
|
|
|
@@ -38,8 +38,8 @@ npm install @dynatrace-sdk/http-client
|
|
|
38
38
|
|
|
39
39
|
#### Parameters
|
|
40
40
|
|
|
41
|
-
| Name | Type|
|
|
42
|
-
|
|
41
|
+
| Name | Type |
|
|
42
|
+
| --- | --- |
|
|
43
43
|
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
44
44
|
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
|
|
45
45
|
|
|
@@ -52,8 +52,8 @@ npm install @dynatrace-sdk/http-client
|
|
|
52
52
|
|
|
53
53
|
#### Properties
|
|
54
54
|
|
|
55
|
-
| Name | Type|
|
|
56
|
-
|
|
55
|
+
| Name | Type |
|
|
56
|
+
| --- | --- |
|
|
57
57
|
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
|
|
58
58
|
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
59
59
|
|name<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
@@ -69,8 +69,8 @@ Represents an environment agnostic (browser vs node) abstraction layer for binar
|
|
|
69
69
|
|
|
70
70
|
#### Properties
|
|
71
71
|
|
|
72
|
-
| Name | Type|
|
|
73
|
-
|
|
72
|
+
| Name | Type |
|
|
73
|
+
| --- | --- |
|
|
74
74
|
|data<sup>*required</sup>|ArrayBuffer | Blob | ReadableStream<Uint8Array>|
|
|
75
75
|
|
|
76
76
|
#### Methods
|
|
@@ -92,8 +92,8 @@ Returns the binary data in a form that conforms to the specified type.
|
|
|
92
92
|
|
|
93
93
|
#### Parameters
|
|
94
94
|
|
|
95
|
-
| Name | Type| Description|
|
|
96
|
-
|
|
95
|
+
| Name | Type | Description |
|
|
96
|
+
| --- | --- | --- |
|
|
97
97
|
|type<sup>*required</sup>|T|<p>The type of the data. Can be <code>text</code>, <code>json</code>, <code>array-buffer</code>, <code>blob</code>, <code>readable-stream</code>, <code>buffer</code> or <code>stream</code>.</p> |
|
|
98
98
|
|
|
99
99
|
|
|
@@ -123,8 +123,8 @@ Returns the binary data in a form that conforms to the specified type.
|
|
|
123
123
|
|
|
124
124
|
#### Parameters
|
|
125
125
|
|
|
126
|
-
| Name | Type|
|
|
127
|
-
|
|
126
|
+
| Name | Type |
|
|
127
|
+
| --- | --- |
|
|
128
128
|
|data<sup>*required</sup>|ArrayBuffer | Blob | ReadableStream<Uint8Array> | Buffer | Readable|
|
|
129
129
|
|
|
130
130
|
|
|
@@ -154,8 +154,8 @@ Returns the binary data in a form that conforms to the specified type.
|
|
|
154
154
|
|
|
155
155
|
#### Parameters
|
|
156
156
|
|
|
157
|
-
| Name | Type|
|
|
158
|
-
|
|
157
|
+
| Name | Type |
|
|
158
|
+
| --- | --- |
|
|
159
159
|
|json<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
|
|
160
160
|
|
|
161
161
|
|
|
@@ -185,8 +185,8 @@ Returns the binary data in a form that conforms to the specified type.
|
|
|
185
185
|
|
|
186
186
|
#### Parameters
|
|
187
187
|
|
|
188
|
-
| Name | Type|
|
|
189
|
-
|
|
188
|
+
| Name | Type |
|
|
189
|
+
| --- | --- |
|
|
190
190
|
|text<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
191
191
|
|
|
192
192
|
|
|
@@ -212,8 +212,8 @@ Returns the binary data in a form that conforms to the specified type.
|
|
|
212
212
|
|
|
213
213
|
#### Parameters
|
|
214
214
|
|
|
215
|
-
| Name | Type|
|
|
216
|
-
|
|
215
|
+
| Name | Type |
|
|
216
|
+
| --- | --- |
|
|
217
217
|
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
218
218
|
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
|
|
219
219
|
|
|
@@ -226,8 +226,8 @@ Returns the binary data in a form that conforms to the specified type.
|
|
|
226
226
|
|
|
227
227
|
#### Properties
|
|
228
228
|
|
|
229
|
-
| Name | Type| Description|
|
|
230
|
-
|
|
229
|
+
| Name | Type | Description |
|
|
230
|
+
| --- | --- | --- |
|
|
231
231
|
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
|
|
232
232
|
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|
|
233
233
|
|name<sup>*required</sup>|"DataTypeError"|The error name. |
|
|
@@ -246,13 +246,94 @@ Currently, only the requests to the Platform Services and the Serverless Functio
|
|
|
246
246
|
|
|
247
247
|
#### Constructors
|
|
248
248
|
|
|
249
|
-
##### new PlatformHttpClient()
|
|
249
|
+
##### new PlatformHttpClient(options?)
|
|
250
|
+
<div class="padding-left--md">
|
|
251
|
+
|
|
252
|
+
#### Parameters
|
|
253
|
+
|
|
254
|
+
| Name | Type |
|
|
255
|
+
| --- | --- |
|
|
256
|
+
|options|HttpClientConfiguration|
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
</div>
|
|
262
|
+
|
|
250
263
|
|
|
251
264
|
|
|
265
|
+
#### Properties
|
|
266
|
+
|
|
267
|
+
| Name | Type |
|
|
268
|
+
| --- | --- |
|
|
269
|
+
|_baseUrl<sup>*required</sup>|undefined | [string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
270
|
+
|_defaultHeaders<sup>*required</sup>|undefined | [Headers](#headers)|
|
|
252
271
|
|
|
253
272
|
#### Methods
|
|
254
273
|
|
|
255
274
|
|
|
275
|
+
##### _setBaseURL
|
|
276
|
+
|
|
277
|
+
<div class="padding-bottom--md">
|
|
278
|
+
<strong>_setBaseURL(baseUrl): void</strong>
|
|
279
|
+
|
|
280
|
+
<div class="padding-left--md">
|
|
281
|
+
|
|
282
|
+
Sets HTTP Client Instance baseUrl param to the incoming value `baseUrl`.
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
</div>
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
#### Parameters
|
|
290
|
+
|
|
291
|
+
| Name | Type | Description |
|
|
292
|
+
| --- | --- | --- |
|
|
293
|
+
|baseUrl<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|Base URL used in the request path. |
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
</div>
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
##### _setDefaultHeaders
|
|
307
|
+
|
|
308
|
+
<div class="padding-bottom--md">
|
|
309
|
+
<strong>_setDefaultHeaders(defaultHeaders): void</strong>
|
|
310
|
+
|
|
311
|
+
<div class="padding-left--md">
|
|
312
|
+
|
|
313
|
+
Sets HTTP Client Instance defaultHeaders param to the incoming value `defaultHeaders`.
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
</div>
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
#### Parameters
|
|
321
|
+
|
|
322
|
+
| Name | Type | Description |
|
|
323
|
+
| --- | --- | --- |
|
|
324
|
+
|defaultHeaders<sup>*required</sup>|[Headers](#headers)|HTTP Headers to be used in outgoing requests. |
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
</div>
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
256
337
|
##### send
|
|
257
338
|
|
|
258
339
|
<div class="padding-bottom--md">
|
|
@@ -275,8 +356,8 @@ when one of the following situations happen:
|
|
|
275
356
|
|
|
276
357
|
#### Parameters
|
|
277
358
|
|
|
278
|
-
| Name | Type| Description|
|
|
279
|
-
|
|
359
|
+
| Name | Type | Description |
|
|
360
|
+
| --- | --- | --- |
|
|
280
361
|
|options<sup>*required</sup>|[HttpClientRequestOptions](#httpclientrequestoptions)<T>|Options used to configure the request. |
|
|
281
362
|
|
|
282
363
|
|
|
@@ -306,8 +387,8 @@ Represents a situation when the request was aborted.
|
|
|
306
387
|
|
|
307
388
|
#### Parameters
|
|
308
389
|
|
|
309
|
-
| Name | Type|
|
|
310
|
-
|
|
390
|
+
| Name | Type |
|
|
391
|
+
| --- | --- |
|
|
311
392
|
|cause<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
|
|
312
393
|
|
|
313
394
|
|
|
@@ -319,8 +400,8 @@ Represents a situation when the request was aborted.
|
|
|
319
400
|
|
|
320
401
|
#### Properties
|
|
321
402
|
|
|
322
|
-
| Name | Type| Description|
|
|
323
|
-
|
|
403
|
+
| Name | Type | Description |
|
|
404
|
+
| --- | --- | --- |
|
|
324
405
|
|cause<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
|
|
325
406
|
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|
|
326
407
|
|name<sup>*required</sup>|"AbortError"|The error name. |
|
|
@@ -341,8 +422,8 @@ Represents a situation when the request is invalid and cannot be sent.
|
|
|
341
422
|
|
|
342
423
|
#### Parameters
|
|
343
424
|
|
|
344
|
-
| Name | Type|
|
|
345
|
-
|
|
425
|
+
| Name | Type |
|
|
426
|
+
| --- | --- |
|
|
346
427
|
|cause<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
|
|
347
428
|
|
|
348
429
|
|
|
@@ -354,8 +435,8 @@ Represents a situation when the request is invalid and cannot be sent.
|
|
|
354
435
|
|
|
355
436
|
#### Properties
|
|
356
437
|
|
|
357
|
-
| Name | Type| Description|
|
|
358
|
-
|
|
438
|
+
| Name | Type | Description |
|
|
439
|
+
| --- | --- | --- |
|
|
359
440
|
|cause<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
|
|
360
441
|
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|
|
361
442
|
|name<sup>*required</sup>|"RequestError"|The error name. |
|
|
@@ -376,8 +457,8 @@ Represents the response to a request.
|
|
|
376
457
|
|
|
377
458
|
#### Parameters
|
|
378
459
|
|
|
379
|
-
| Name | Type|
|
|
380
|
-
|
|
460
|
+
| Name | Type |
|
|
461
|
+
| --- | --- |
|
|
381
462
|
|response<sup>*required</sup>|Response|
|
|
382
463
|
|
|
383
464
|
|
|
@@ -389,8 +470,8 @@ Represents the response to a request.
|
|
|
389
470
|
|
|
390
471
|
#### Properties
|
|
391
472
|
|
|
392
|
-
| Name | Type|
|
|
393
|
-
|
|
473
|
+
| Name | Type |
|
|
474
|
+
| --- | --- |
|
|
394
475
|
|response<sup>*required</sup>|Response|
|
|
395
476
|
|
|
396
477
|
#### Accessors
|
|
@@ -434,8 +515,8 @@ Returns the response body in a form that conforms to the specified response body
|
|
|
434
515
|
|
|
435
516
|
#### Parameters
|
|
436
517
|
|
|
437
|
-
| Name | Type| Description|
|
|
438
|
-
|
|
518
|
+
| Name | Type | Description |
|
|
519
|
+
| --- | --- | --- |
|
|
439
520
|
|responseBodyType<sup>*required</sup>|T|<p>The type of the response body. Can be <code>text</code>, <code>json</code>, <code>binary</code>, <code>form-data</code>, <code>array-buffer</code>, <code>blob</code>, <code>readable-stream</code>, <code>buffer</code> or <code>stream</code>. The default response body type is <code>json</code>.</p> |
|
|
440
521
|
|
|
441
522
|
|
|
@@ -461,8 +542,8 @@ Represents a situation when the response status is considered invalid by the sta
|
|
|
461
542
|
|
|
462
543
|
#### Parameters
|
|
463
544
|
|
|
464
|
-
| Name | Type|
|
|
465
|
-
|
|
545
|
+
| Name | Type |
|
|
546
|
+
| --- | --- |
|
|
466
547
|
|response<sup>*required</sup>|Response|
|
|
467
548
|
|data|Object|
|
|
468
549
|
|data.requestMethod|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
@@ -476,8 +557,8 @@ Represents a situation when the response status is considered invalid by the sta
|
|
|
476
557
|
|
|
477
558
|
#### Properties
|
|
478
559
|
|
|
479
|
-
| Name | Type| Description|
|
|
480
|
-
|
|
560
|
+
| Name | Type | Description |
|
|
561
|
+
| --- | --- | --- |
|
|
481
562
|
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
|
|
482
563
|
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|
|
483
564
|
|name<sup>*required</sup>|"ResponseError"|The error name. |
|
|
@@ -500,8 +581,8 @@ Represents a situation when the response status is considered invalid by the sta
|
|
|
500
581
|
|
|
501
582
|
#### Parameters
|
|
502
583
|
|
|
503
|
-
| Name | Type|
|
|
504
|
-
|
|
584
|
+
| Name | Type |
|
|
585
|
+
| --- | --- |
|
|
505
586
|
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
506
587
|
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
|
|
507
588
|
|
|
@@ -514,8 +595,8 @@ Represents a situation when the response status is considered invalid by the sta
|
|
|
514
595
|
|
|
515
596
|
#### Properties
|
|
516
597
|
|
|
517
|
-
| Name | Type| Description|
|
|
518
|
-
|
|
598
|
+
| Name | Type | Description |
|
|
599
|
+
| --- | --- | --- |
|
|
519
600
|
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
|
|
520
601
|
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|
|
521
602
|
|name<sup>*required</sup>|"UnsupportedOperationError"|The error name. |
|
|
@@ -537,8 +618,8 @@ DO NOT USE - internal use only.
|
|
|
537
618
|
|
|
538
619
|
#### Properties
|
|
539
620
|
|
|
540
|
-
| Name | Type|
|
|
541
|
-
|
|
621
|
+
| Name | Type |
|
|
622
|
+
| --- | --- |
|
|
542
623
|
|oauthToken|OAuthToken|
|
|
543
624
|
|
|
544
625
|
#### Methods
|
|
@@ -566,8 +647,8 @@ when one of the following situations happen:
|
|
|
566
647
|
|
|
567
648
|
#### Parameters
|
|
568
649
|
|
|
569
|
-
| Name | Type| Description|
|
|
570
|
-
|
|
650
|
+
| Name | Type | Description |
|
|
651
|
+
| --- | --- | --- |
|
|
571
652
|
|options<sup>*required</sup>|[HttpClientRequestOptions](#httpclientrequestoptions)<T>|Options used to configure the request. |
|
|
572
653
|
|
|
573
654
|
|
|
@@ -594,8 +675,8 @@ Represents a controller object that allows to abort one or more requests as and
|
|
|
594
675
|
|
|
595
676
|
#### Properties
|
|
596
677
|
|
|
597
|
-
| Name | Type| Description|
|
|
598
|
-
|
|
678
|
+
| Name | Type | Description |
|
|
679
|
+
| --- | --- | --- |
|
|
599
680
|
|signal<sup>*required</sup>|[AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)|Returns an AbortSignal object instance, which can be used to communicate with a request. |
|
|
600
681
|
|
|
601
682
|
#### Methods
|
|
@@ -631,8 +712,8 @@ Represents a signal object that allows to communicate with the request and abort
|
|
|
631
712
|
|
|
632
713
|
#### Properties
|
|
633
714
|
|
|
634
|
-
| Name | Type| Description|
|
|
635
|
-
|
|
715
|
+
| Name | Type | Description |
|
|
716
|
+
| --- | --- | --- |
|
|
636
717
|
|aborted<sup>*required</sup>|[boolean](https://developer.mozilla.org/en-US/docs/Glossary/Boolean)|A flag indicating whether the requests the signal is communicating with are aborted. |
|
|
637
718
|
|onabort<sup>*required</sup>|null | Object|Invoked when the requests the signal is communicating with are aborted. |
|
|
638
719
|
|reason<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)| |
|
|
@@ -670,8 +751,8 @@ Represents a signal object that allows to communicate with the request and abort
|
|
|
670
751
|
|
|
671
752
|
#### Properties
|
|
672
753
|
|
|
673
|
-
| Name | Type|
|
|
674
|
-
|
|
754
|
+
| Name | Type |
|
|
755
|
+
| --- | --- |
|
|
675
756
|
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
|
|
676
757
|
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
677
758
|
|name<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
@@ -702,8 +783,8 @@ Returns the binary data in a form that conforms to the specified type.
|
|
|
702
783
|
|
|
703
784
|
#### Parameters
|
|
704
785
|
|
|
705
|
-
| Name | Type| Description|
|
|
706
|
-
|
|
786
|
+
| Name | Type | Description |
|
|
787
|
+
| --- | --- | --- |
|
|
707
788
|
|type<sup>*required</sup>|T|<p>The type of the data. Can be <code>text</code>, <code>json</code>, <code>array-buffer</code>, <code>blob</code>, <code>readable-stream</code>, <code>buffer</code> or <code>stream</code>.</p> |
|
|
708
789
|
|
|
709
790
|
|
|
@@ -724,8 +805,8 @@ Represents an binary field.
|
|
|
724
805
|
|
|
725
806
|
#### Properties
|
|
726
807
|
|
|
727
|
-
| Name | Type| Description|
|
|
728
|
-
|
|
808
|
+
| Name | Type | Description |
|
|
809
|
+
| --- | --- | --- |
|
|
729
810
|
|contentType|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|<p>The content type of the data contained in <code>value</code>. The default content type for the binary is 'application/octet-stream'.</p> |
|
|
730
811
|
|filename|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|<p>The filename reported to the server. The default filename for the binary is 'binary'.</p> |
|
|
731
812
|
|name<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The name of the field. |
|
|
@@ -740,8 +821,8 @@ Represents an binary field.
|
|
|
740
821
|
|
|
741
822
|
#### Properties
|
|
742
823
|
|
|
743
|
-
| Name | Type|
|
|
744
|
-
|
|
824
|
+
| Name | Type |
|
|
825
|
+
| --- | --- |
|
|
745
826
|
|contentType<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
746
827
|
|filename<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
747
828
|
|name<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
@@ -756,8 +837,8 @@ Represents an binary field.
|
|
|
756
837
|
|
|
757
838
|
#### Properties
|
|
758
839
|
|
|
759
|
-
| Name | Type| Description|
|
|
760
|
-
|
|
840
|
+
| Name | Type | Description |
|
|
841
|
+
| --- | --- | --- |
|
|
761
842
|
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
|
|
762
843
|
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|
|
763
844
|
|name<sup>*required</sup>|"DataTypeError"|The error name. |
|
|
@@ -802,8 +883,8 @@ when one of the following situations happen:
|
|
|
802
883
|
|
|
803
884
|
#### Parameters
|
|
804
885
|
|
|
805
|
-
| Name | Type| Description|
|
|
806
|
-
|
|
886
|
+
| Name | Type | Description |
|
|
887
|
+
| --- | --- | --- |
|
|
807
888
|
|options<sup>*required</sup>|[HttpClientRequestOptions](#httpclientrequestoptions)<T>|Options used to configure the request. |
|
|
808
889
|
|
|
809
890
|
|
|
@@ -828,8 +909,8 @@ Represents a situation when the request was aborted.
|
|
|
828
909
|
|
|
829
910
|
#### Properties
|
|
830
911
|
|
|
831
|
-
| Name | Type| Description|
|
|
832
|
-
|
|
912
|
+
| Name | Type | Description |
|
|
913
|
+
| --- | --- | --- |
|
|
833
914
|
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
|
|
834
915
|
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|
|
835
916
|
|name<sup>*required</sup>|"AbortError"|The error name. |
|
|
@@ -843,8 +924,8 @@ Represents a situation when a network error occurred.
|
|
|
843
924
|
|
|
844
925
|
#### Properties
|
|
845
926
|
|
|
846
|
-
| Name | Type| Description|
|
|
847
|
-
|
|
927
|
+
| Name | Type | Description |
|
|
928
|
+
| --- | --- | --- |
|
|
848
929
|
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
|
|
849
930
|
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|
|
850
931
|
|name<sup>*required</sup>|"NetworkError"|The error name. |
|
|
@@ -858,8 +939,8 @@ Represents a situation when the request is invalid and cannot be sent.
|
|
|
858
939
|
|
|
859
940
|
#### Properties
|
|
860
941
|
|
|
861
|
-
| Name | Type| Description|
|
|
862
|
-
|
|
942
|
+
| Name | Type | Description |
|
|
943
|
+
| --- | --- | --- |
|
|
863
944
|
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
|
|
864
945
|
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|
|
865
946
|
|name<sup>*required</sup>|"RequestError"|The error name. |
|
|
@@ -873,8 +954,8 @@ Represents the options used to configure the request.
|
|
|
873
954
|
|
|
874
955
|
#### Properties
|
|
875
956
|
|
|
876
|
-
| Name | Type| Description|
|
|
877
|
-
|
|
957
|
+
| Name | Type | Description |
|
|
958
|
+
| --- | --- | --- |
|
|
878
959
|
|body|RequestBodyTypes<T>|<p>A request body that will be send along with the request. The structure of the request body needs to conform to the specified request body type.</p> |
|
|
879
960
|
|headers|[Headers](#headers)|The request headers. |
|
|
880
961
|
|method|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The request method, e.g. <code>GET</code>, <code>POST</code>. |
|
|
@@ -890,8 +971,8 @@ Represents the response to a request.
|
|
|
890
971
|
|
|
891
972
|
#### Properties
|
|
892
973
|
|
|
893
|
-
| Name | Type| Description|
|
|
894
|
-
|
|
974
|
+
| Name | Type | Description |
|
|
975
|
+
| --- | --- | --- |
|
|
895
976
|
|headers<sup>*required</sup>|[Headers](#headers)|The response headers. |
|
|
896
977
|
|status<sup>*required</sup>|[number](https://developer.mozilla.org/en-US/docs/Glossary/Number)|The status code of the response. |
|
|
897
978
|
|statusText<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The status message corresponding to the status code. |
|
|
@@ -916,8 +997,8 @@ Returns the response body in a form that conforms to the specified response body
|
|
|
916
997
|
|
|
917
998
|
#### Parameters
|
|
918
999
|
|
|
919
|
-
| Name | Type| Description|
|
|
920
|
-
|
|
1000
|
+
| Name | Type | Description |
|
|
1001
|
+
| --- | --- | --- |
|
|
921
1002
|
|responseBodyType|T|<p>The type of the response body. Can be <code>text</code>, <code>json</code>, <code>binary</code>, <code>form-data</code>, <code>array-buffer</code>, <code>blob</code>, <code>readable-stream</code>, <code>buffer</code> or <code>stream</code>. The default response body type is <code>json</code>.</p> |
|
|
922
1003
|
|
|
923
1004
|
|
|
@@ -938,8 +1019,8 @@ Represents a situation when the response status is considered invalid by the sta
|
|
|
938
1019
|
|
|
939
1020
|
#### Properties
|
|
940
1021
|
|
|
941
|
-
| Name | Type| Description|
|
|
942
|
-
|
|
1022
|
+
| Name | Type | Description |
|
|
1023
|
+
| --- | --- | --- |
|
|
943
1024
|
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
|
|
944
1025
|
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|
|
945
1026
|
|name<sup>*required</sup>|"ResponseError"|The error name. |
|
|
@@ -954,8 +1035,8 @@ Represents a JSON field.
|
|
|
954
1035
|
|
|
955
1036
|
#### Properties
|
|
956
1037
|
|
|
957
|
-
| Name | Type| Description|
|
|
958
|
-
|
|
1038
|
+
| Name | Type | Description |
|
|
1039
|
+
| --- | --- | --- |
|
|
959
1040
|
|contentType|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|<p>The content type of the data contained in <code>value</code>. The default content type for the JSON is 'application/json'.</p> |
|
|
960
1041
|
|filename|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|<p>The filename reported to the server. The default filename for the JSON is 'json'.</p> |
|
|
961
1042
|
|name<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The name of the field. |
|
|
@@ -975,8 +1056,8 @@ Represents a plain text field. No filename and content type is set.
|
|
|
975
1056
|
|
|
976
1057
|
#### Properties
|
|
977
1058
|
|
|
978
|
-
| Name | Type| Description|
|
|
979
|
-
|
|
1059
|
+
| Name | Type | Description |
|
|
1060
|
+
| --- | --- | --- |
|
|
980
1061
|
|name<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The name of the field. |
|
|
981
1062
|
|type<sup>*required</sup>|"text"|A plain text field type discriminator. |
|
|
982
1063
|
|value<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The field's value. |
|
|
@@ -989,8 +1070,8 @@ Represents a plain text field. No filename and content type is set.
|
|
|
989
1070
|
|
|
990
1071
|
#### Properties
|
|
991
1072
|
|
|
992
|
-
| Name | Type|
|
|
993
|
-
|
|
1073
|
+
| Name | Type |
|
|
1074
|
+
| --- | --- |
|
|
994
1075
|
|name<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
995
1076
|
|type<sup>*required</sup>|"text"|
|
|
996
1077
|
|value<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
@@ -1003,8 +1084,8 @@ Represents a plain text field. No filename and content type is set.
|
|
|
1003
1084
|
|
|
1004
1085
|
#### Properties
|
|
1005
1086
|
|
|
1006
|
-
| Name | Type| Description|
|
|
1007
|
-
|
|
1087
|
+
| Name | Type | Description |
|
|
1088
|
+
| --- | --- | --- |
|
|
1008
1089
|
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
|
|
1009
1090
|
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|
|
1010
1091
|
|name<sup>*required</sup>|"UnsupportedOperationError"|The error name. |
|
|
@@ -1018,8 +1099,8 @@ DO NOT USE - internal use only.
|
|
|
1018
1099
|
|
|
1019
1100
|
#### Properties
|
|
1020
1101
|
|
|
1021
|
-
| Name | Type|
|
|
1022
|
-
|
|
1102
|
+
| Name | Type |
|
|
1103
|
+
| --- | --- |
|
|
1023
1104
|
|authUrl<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
1024
1105
|
|clientId<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
1025
1106
|
|environmentUrl<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|
|
@@ -1084,8 +1165,8 @@ DO NOT USE - internal use only.
|
|
|
1084
1165
|
|
|
1085
1166
|
#### Parameters
|
|
1086
1167
|
|
|
1087
|
-
| Name | Type|
|
|
1088
|
-
|
|
1168
|
+
| Name | Type |
|
|
1169
|
+
| --- | --- |
|
|
1089
1170
|
|e<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
|
|
1090
1171
|
|
|
1091
1172
|
|
|
@@ -1115,8 +1196,8 @@ DO NOT USE - internal use only.
|
|
|
1115
1196
|
|
|
1116
1197
|
#### Parameters
|
|
1117
1198
|
|
|
1118
|
-
| Name | Type|
|
|
1119
|
-
|
|
1199
|
+
| Name | Type |
|
|
1200
|
+
| --- | --- |
|
|
1120
1201
|
|e<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
|
|
1121
1202
|
|
|
1122
1203
|
|
|
@@ -1146,8 +1227,8 @@ DO NOT USE - internal use only.
|
|
|
1146
1227
|
|
|
1147
1228
|
#### Parameters
|
|
1148
1229
|
|
|
1149
|
-
| Name | Type|
|
|
1150
|
-
|
|
1230
|
+
| Name | Type |
|
|
1231
|
+
| --- | --- |
|
|
1151
1232
|
|e<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
|
|
1152
1233
|
|
|
1153
1234
|
|
|
@@ -1177,8 +1258,8 @@ DO NOT USE - internal use only.
|
|
|
1177
1258
|
|
|
1178
1259
|
#### Parameters
|
|
1179
1260
|
|
|
1180
|
-
| Name | Type|
|
|
1181
|
-
|
|
1261
|
+
| Name | Type |
|
|
1262
|
+
| --- | --- |
|
|
1182
1263
|
|e<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
|
|
1183
1264
|
|
|
1184
1265
|
|
package/esm/index.js
CHANGED
|
@@ -507,13 +507,27 @@ var send = async (info, init) => {
|
|
|
507
507
|
}
|
|
508
508
|
};
|
|
509
509
|
var HttpClient = class {
|
|
510
|
+
_baseUrl;
|
|
511
|
+
_defaultHeaders;
|
|
512
|
+
constructor(options) {
|
|
513
|
+
this._baseUrl = options?.baseUrl;
|
|
514
|
+
this._defaultHeaders = options?.defaultHeaders;
|
|
515
|
+
}
|
|
516
|
+
_setBaseURL(baseUrl) {
|
|
517
|
+
this._baseUrl = baseUrl;
|
|
518
|
+
}
|
|
519
|
+
_setDefaultHeaders(defaultHeaders) {
|
|
520
|
+
this._defaultHeaders = defaultHeaders;
|
|
521
|
+
}
|
|
510
522
|
async send(options) {
|
|
511
523
|
const { statusValidator = defaultStatusValidator } = options;
|
|
512
524
|
const requestBodyType = options.requestBodyType ?? "json";
|
|
513
525
|
const body = options.body !== void 0 ? await encodeRequestBody(options.body, requestBodyType) : void 0;
|
|
514
|
-
const
|
|
526
|
+
const url = this._baseUrl ? new URL(options.url, this._baseUrl).toString() : options.url;
|
|
527
|
+
const requestHeaders = { ...this._defaultHeaders, ...options?.headers };
|
|
528
|
+
const response = await send(url, {
|
|
515
529
|
method: options.method,
|
|
516
|
-
headers: applyContentTypeHeader(
|
|
530
|
+
headers: applyContentTypeHeader(requestHeaders, requestBodyType),
|
|
517
531
|
signal: options.abortSignal,
|
|
518
532
|
body
|
|
519
533
|
});
|
package/package.json
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
import * as types from '../types';
|
|
2
|
+
import { Headers } from '../types';
|
|
3
|
+
interface HttpClientConfiguration {
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
defaultHeaders?: Headers;
|
|
6
|
+
}
|
|
2
7
|
export declare class HttpClient implements types.HttpClient {
|
|
8
|
+
private _baseUrl;
|
|
9
|
+
private _defaultHeaders;
|
|
10
|
+
constructor(options?: HttpClientConfiguration);
|
|
11
|
+
/**
|
|
12
|
+
* Sets HTTP Client Instance baseUrl param to the incoming value `baseUrl`.
|
|
13
|
+
* @param baseUrl Base URL used in the request path.
|
|
14
|
+
*/
|
|
15
|
+
_setBaseURL(baseUrl: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* Sets HTTP Client Instance defaultHeaders param to the incoming value `defaultHeaders`.
|
|
18
|
+
* @param defaultHeaders HTTP Headers to be used in outgoing requests.
|
|
19
|
+
*/
|
|
20
|
+
_setDefaultHeaders(defaultHeaders: Headers): void;
|
|
3
21
|
send<T extends keyof types.RequestBodyTypes = 'json'>(options: types.HttpClientRequestOptions<T>): Promise<types.HttpClientResponse>;
|
|
4
22
|
}
|
|
5
23
|
export declare const httpClient: HttpClient;
|
|
24
|
+
export {};
|