@dynatrace-sdk/http-client 1.4.0 → 1.5.2
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 +28 -0
- package/cjs/index.js +32 -14
- package/docs/DOCS.md +101 -97
- package/esm/index.js +29 -11
- package/esm/package.json +3 -0
- package/package.json +13 -2
- package/types/index.d.ts +617 -1
- package/types/packages/http-client/src/index.d.ts +0 -2
- package/types/packages/http-client/src/lib/platform/abort-controller.d.ts +0 -6
- package/types/packages/http-client/src/lib/platform/abort-signal.d.ts +0 -6
- package/types/packages/http-client/src/lib/platform/apply-content-type-header.d.ts +0 -2
- package/types/packages/http-client/src/lib/platform/base-error.d.ts +0 -5
- package/types/packages/http-client/src/lib/platform/binary.d.ts +0 -13
- package/types/packages/http-client/src/lib/platform/data-type-error.d.ts +0 -6
- package/types/packages/http-client/src/lib/platform/decode-form-data.d.ts +0 -48
- package/types/packages/http-client/src/lib/platform/decode-response-body.d.ts +0 -3
- package/types/packages/http-client/src/lib/platform/default-status-validator.d.ts +0 -2
- package/types/packages/http-client/src/lib/platform/encode-request-body.d.ts +0 -2
- package/types/packages/http-client/src/lib/platform/http-client-abort-error.d.ts +0 -7
- package/types/packages/http-client/src/lib/platform/http-client-request-error.d.ts +0 -7
- package/types/packages/http-client/src/lib/platform/http-client-response-error-serializer.d.ts +0 -3
- package/types/packages/http-client/src/lib/platform/http-client-response-error.d.ts +0 -11
- package/types/packages/http-client/src/lib/platform/http-client-response.d.ts +0 -10
- package/types/packages/http-client/src/lib/platform/http-client.d.ts +0 -24
- package/types/packages/http-client/src/lib/platform/index.d.ts +0 -12
- package/types/packages/http-client/src/lib/platform/oauth-http-client.d.ts +0 -41
- package/types/packages/http-client/src/lib/platform/unsupported-operation-error.d.ts +0 -6
- package/types/packages/http-client/src/lib/types/abort-controller.d.ts +0 -14
- package/types/packages/http-client/src/lib/types/abort-signal.d.ts +0 -18
- package/types/packages/http-client/src/lib/types/base-error.d.ts +0 -4
- package/types/packages/http-client/src/lib/types/binary.d.ts +0 -15
- package/types/packages/http-client/src/lib/types/data-type-error.d.ts +0 -14
- package/types/packages/http-client/src/lib/types/data-types.d.ts +0 -36
- package/types/packages/http-client/src/lib/types/form-data-request-body.d.ts +0 -83
- package/types/packages/http-client/src/lib/types/form-data-response-body.d.ts +0 -15
- package/types/packages/http-client/src/lib/types/headers.d.ts +0 -6
- package/types/packages/http-client/src/lib/types/http-client-abort-error.d.ts +0 -15
- package/types/packages/http-client/src/lib/types/http-client-network-error.d.ts +0 -15
- package/types/packages/http-client/src/lib/types/http-client-request-error.d.ts +0 -15
- package/types/packages/http-client/src/lib/types/http-client-request-options.d.ts +0 -42
- package/types/packages/http-client/src/lib/types/http-client-response-error.d.ts +0 -20
- package/types/packages/http-client/src/lib/types/http-client-response.d.ts +0 -33
- package/types/packages/http-client/src/lib/types/http-client.d.ts +0 -24
- package/types/packages/http-client/src/lib/types/index.d.ts +0 -20
- package/types/packages/http-client/src/lib/types/request-body-types.d.ts +0 -26
- package/types/packages/http-client/src/lib/types/response-body-types.d.ts +0 -46
- package/types/packages/http-client/src/lib/types/status-validator.d.ts +0 -7
- package/types/packages/http-client/src/lib/types/unsupported-operation-error.d.ts +0 -14
package/esm/index.js
CHANGED
|
@@ -46,6 +46,7 @@ var BaseError = class extends Error {
|
|
|
46
46
|
super(message);
|
|
47
47
|
this.cause = cause;
|
|
48
48
|
}
|
|
49
|
+
cause;
|
|
49
50
|
};
|
|
50
51
|
|
|
51
52
|
// packages/http-client/src/lib/platform/unsupported-operation-error.ts
|
|
@@ -77,6 +78,7 @@ var Binary = class _Binary {
|
|
|
77
78
|
constructor(data) {
|
|
78
79
|
this.data = data;
|
|
79
80
|
}
|
|
81
|
+
data;
|
|
80
82
|
static fromText(text) {
|
|
81
83
|
return new _Binary(new Blob([text]));
|
|
82
84
|
}
|
|
@@ -238,6 +240,7 @@ var HttpClientAbortError = class extends Error {
|
|
|
238
240
|
);
|
|
239
241
|
this.cause = cause;
|
|
240
242
|
}
|
|
243
|
+
cause;
|
|
241
244
|
name = "AbortError";
|
|
242
245
|
};
|
|
243
246
|
var throwIfAbortError = (e) => {
|
|
@@ -254,21 +257,20 @@ var HttpClientRequestError = class extends BaseError {
|
|
|
254
257
|
);
|
|
255
258
|
this.cause = cause;
|
|
256
259
|
}
|
|
260
|
+
cause;
|
|
257
261
|
name = "RequestError";
|
|
258
262
|
};
|
|
259
263
|
|
|
260
264
|
// packages/http-client/src/lib/platform/decode-form-data.ts
|
|
261
265
|
function byteToChar(byte) {
|
|
262
|
-
if (byte === void 0)
|
|
263
|
-
return void 0;
|
|
266
|
+
if (byte === void 0) return void 0;
|
|
264
267
|
return String.fromCharCode(byte);
|
|
265
268
|
}
|
|
266
269
|
function isTextContentType(contentType) {
|
|
267
270
|
return ["application/json", "text/plain"].includes(String(contentType).toLowerCase());
|
|
268
271
|
}
|
|
269
272
|
function removeEscaping(value) {
|
|
270
|
-
if (!value)
|
|
271
|
-
return value;
|
|
273
|
+
if (!value) return value;
|
|
272
274
|
return JSON.parse(`"${value}"`);
|
|
273
275
|
}
|
|
274
276
|
function parseContentDisposition(contentDisposition) {
|
|
@@ -288,6 +290,8 @@ var FormDataParser = class {
|
|
|
288
290
|
this.sourceArray = sourceArray;
|
|
289
291
|
this.boundary = boundary;
|
|
290
292
|
}
|
|
293
|
+
sourceArray;
|
|
294
|
+
boundary;
|
|
291
295
|
currentChar = null;
|
|
292
296
|
currentByte = null;
|
|
293
297
|
offset = 0;
|
|
@@ -595,9 +599,12 @@ function decodeResponseBody(response, responseBodyType) {
|
|
|
595
599
|
|
|
596
600
|
// packages/http-client/src/lib/platform/http-client-response.ts
|
|
597
601
|
var HttpClientResponse = class {
|
|
598
|
-
constructor(response) {
|
|
602
|
+
constructor(response, data) {
|
|
599
603
|
this.response = response;
|
|
604
|
+
this.requestUrl = data?.requestUrl ?? response.url;
|
|
600
605
|
}
|
|
606
|
+
response;
|
|
607
|
+
requestUrl;
|
|
601
608
|
get url() {
|
|
602
609
|
return this.response.url;
|
|
603
610
|
}
|
|
@@ -680,6 +687,7 @@ var httpClientResponseErrorSerializer = async (error) => {
|
|
|
680
687
|
type: ErrorType.HTTP,
|
|
681
688
|
details: {
|
|
682
689
|
url: error.response.url,
|
|
690
|
+
requestUrl: error.response.requestUrl,
|
|
683
691
|
method: error.requestMethod,
|
|
684
692
|
errorCode,
|
|
685
693
|
responseContentType: getHeaderValue(error.response, "content-type"),
|
|
@@ -713,7 +721,9 @@ var HttpClientResponseError = class extends BaseError {
|
|
|
713
721
|
constructor(response, data) {
|
|
714
722
|
addHttpClientResponseErrorSerializer();
|
|
715
723
|
super(`HTTP Error ${response.status}: ${response.statusText}`);
|
|
716
|
-
this.response = new HttpClientResponse(response
|
|
724
|
+
this.response = new HttpClientResponse(response, {
|
|
725
|
+
requestUrl: data?.requestUrl ?? response.url
|
|
726
|
+
});
|
|
717
727
|
this.requestMethod = data?.requestMethod;
|
|
718
728
|
}
|
|
719
729
|
};
|
|
@@ -762,9 +772,12 @@ var HttpClient = class {
|
|
|
762
772
|
});
|
|
763
773
|
const ok = statusValidator(response.status);
|
|
764
774
|
if (ok) {
|
|
765
|
-
return new HttpClientResponse(response);
|
|
775
|
+
return new HttpClientResponse(response, { requestUrl: url });
|
|
766
776
|
} else {
|
|
767
|
-
throw new HttpClientResponseError(response, {
|
|
777
|
+
throw new HttpClientResponseError(response, {
|
|
778
|
+
requestUrl: url,
|
|
779
|
+
requestMethod: options.method
|
|
780
|
+
});
|
|
768
781
|
}
|
|
769
782
|
}
|
|
770
783
|
};
|
|
@@ -812,6 +825,7 @@ var OAuthHttpClient = class {
|
|
|
812
825
|
constructor(config) {
|
|
813
826
|
this.config = config;
|
|
814
827
|
}
|
|
828
|
+
config;
|
|
815
829
|
oauthToken;
|
|
816
830
|
async send(options) {
|
|
817
831
|
const { statusValidator = defaultStatusValidator } = options;
|
|
@@ -825,7 +839,8 @@ var OAuthHttpClient = class {
|
|
|
825
839
|
...applyContentTypeHeader(options.headers, requestBodyType),
|
|
826
840
|
Authorization: `${this.oauthToken.tokenType} ${this.oauthToken.accessToken}`
|
|
827
841
|
};
|
|
828
|
-
const
|
|
842
|
+
const requestUrl = url.toString();
|
|
843
|
+
const response = await send2(requestUrl, {
|
|
829
844
|
method: options.method,
|
|
830
845
|
signal: options.abortSignal,
|
|
831
846
|
body,
|
|
@@ -833,9 +848,12 @@ var OAuthHttpClient = class {
|
|
|
833
848
|
});
|
|
834
849
|
const ok = statusValidator(response.status);
|
|
835
850
|
if (ok) {
|
|
836
|
-
return new HttpClientResponse(response);
|
|
851
|
+
return new HttpClientResponse(response, { requestUrl });
|
|
837
852
|
} else {
|
|
838
|
-
throw new HttpClientResponseError(response, {
|
|
853
|
+
throw new HttpClientResponseError(response, {
|
|
854
|
+
requestUrl,
|
|
855
|
+
requestMethod: options.method
|
|
856
|
+
});
|
|
839
857
|
}
|
|
840
858
|
}
|
|
841
859
|
async requestToken() {
|
package/esm/package.json
ADDED
package/package.json
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynatrace-sdk/http-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "An environment agnostic (browser/deno vs nodejs) abstraction layer for making HTTP calls.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
-
"
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./types/index.d.ts",
|
|
9
|
+
"require": "./cjs/index.js",
|
|
10
|
+
"browser": "./esm/index.js",
|
|
11
|
+
"module": "./esm/index.js",
|
|
12
|
+
"import": "./esm/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@dynatrace-sdk/error-handlers": "^1.2.0"
|
|
17
|
+
},
|
|
7
18
|
"main": "./cjs/index.js",
|
|
8
19
|
"module": "./esm/index.js",
|
|
9
20
|
"types": "./types/index.d.ts"
|