@dynatrace-sdk/http-client 1.3.1 → 1.5.1
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 +23 -1
- package/cjs/index.js +22 -9
- package/docs/DOCS.md +191 -320
- package/esm/index.js +22 -9
- package/package.json +3 -5
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright 2023-
|
|
3
|
+
* Copyright 2023-2026 Dynatrace LLC
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
6
6
|
* You may obtain a copy of the License at
|
|
@@ -595,9 +595,11 @@ function decodeResponseBody(response, responseBodyType) {
|
|
|
595
595
|
|
|
596
596
|
// packages/http-client/src/lib/platform/http-client-response.ts
|
|
597
597
|
var HttpClientResponse = class {
|
|
598
|
-
constructor(response) {
|
|
598
|
+
constructor(response, data) {
|
|
599
599
|
this.response = response;
|
|
600
|
+
this.requestUrl = data?.requestUrl ?? response.url;
|
|
600
601
|
}
|
|
602
|
+
requestUrl;
|
|
601
603
|
get url() {
|
|
602
604
|
return this.response.url;
|
|
603
605
|
}
|
|
@@ -680,6 +682,7 @@ var httpClientResponseErrorSerializer = async (error) => {
|
|
|
680
682
|
type: ErrorType.HTTP,
|
|
681
683
|
details: {
|
|
682
684
|
url: error.response.url,
|
|
685
|
+
requestUrl: error.response.requestUrl,
|
|
683
686
|
method: error.requestMethod,
|
|
684
687
|
errorCode,
|
|
685
688
|
responseContentType: getHeaderValue(error.response, "content-type"),
|
|
@@ -713,7 +716,9 @@ var HttpClientResponseError = class extends BaseError {
|
|
|
713
716
|
constructor(response, data) {
|
|
714
717
|
addHttpClientResponseErrorSerializer();
|
|
715
718
|
super(`HTTP Error ${response.status}: ${response.statusText}`);
|
|
716
|
-
this.response = new HttpClientResponse(response
|
|
719
|
+
this.response = new HttpClientResponse(response, {
|
|
720
|
+
requestUrl: data?.requestUrl ?? response.url
|
|
721
|
+
});
|
|
717
722
|
this.requestMethod = data?.requestMethod;
|
|
718
723
|
}
|
|
719
724
|
};
|
|
@@ -762,15 +767,19 @@ var HttpClient = class {
|
|
|
762
767
|
});
|
|
763
768
|
const ok = statusValidator(response.status);
|
|
764
769
|
if (ok) {
|
|
765
|
-
return new HttpClientResponse(response);
|
|
770
|
+
return new HttpClientResponse(response, { requestUrl: url });
|
|
766
771
|
} else {
|
|
767
|
-
throw new HttpClientResponseError(response, {
|
|
772
|
+
throw new HttpClientResponseError(response, {
|
|
773
|
+
requestUrl: url,
|
|
774
|
+
requestMethod: options.method
|
|
775
|
+
});
|
|
768
776
|
}
|
|
769
777
|
}
|
|
770
778
|
};
|
|
771
779
|
var httpClient = new HttpClient();
|
|
772
780
|
|
|
773
781
|
// packages/http-client/src/lib/platform/oauth-http-client.ts
|
|
782
|
+
var TOKEN_EXPIRATION_SAFETY_MARGIN_SECONDS = 1;
|
|
774
783
|
var OAuthToken = class {
|
|
775
784
|
_scope;
|
|
776
785
|
_tokenType;
|
|
@@ -781,7 +790,7 @@ var OAuthToken = class {
|
|
|
781
790
|
this._tokenType = oauthTokenResponse.token_type;
|
|
782
791
|
this._expirationDate = ((expiresIn) => {
|
|
783
792
|
const date = /* @__PURE__ */ new Date();
|
|
784
|
-
date.setSeconds(date.getSeconds() + expiresIn);
|
|
793
|
+
date.setSeconds(date.getSeconds() + expiresIn - TOKEN_EXPIRATION_SAFETY_MARGIN_SECONDS);
|
|
785
794
|
return date;
|
|
786
795
|
})(oauthTokenResponse.expires_in);
|
|
787
796
|
this._accessToken = oauthTokenResponse.access_token;
|
|
@@ -824,7 +833,8 @@ var OAuthHttpClient = class {
|
|
|
824
833
|
...applyContentTypeHeader(options.headers, requestBodyType),
|
|
825
834
|
Authorization: `${this.oauthToken.tokenType} ${this.oauthToken.accessToken}`
|
|
826
835
|
};
|
|
827
|
-
const
|
|
836
|
+
const requestUrl = url.toString();
|
|
837
|
+
const response = await send2(requestUrl, {
|
|
828
838
|
method: options.method,
|
|
829
839
|
signal: options.abortSignal,
|
|
830
840
|
body,
|
|
@@ -832,9 +842,12 @@ var OAuthHttpClient = class {
|
|
|
832
842
|
});
|
|
833
843
|
const ok = statusValidator(response.status);
|
|
834
844
|
if (ok) {
|
|
835
|
-
return new HttpClientResponse(response);
|
|
845
|
+
return new HttpClientResponse(response, { requestUrl });
|
|
836
846
|
} else {
|
|
837
|
-
throw new HttpClientResponseError(response, {
|
|
847
|
+
throw new HttpClientResponseError(response, {
|
|
848
|
+
requestUrl,
|
|
849
|
+
requestMethod: options.method
|
|
850
|
+
});
|
|
838
851
|
}
|
|
839
852
|
}
|
|
840
853
|
async requestToken() {
|
package/package.json
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynatrace-sdk/http-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "An environment agnostic (browser/deno vs nodejs) abstraction layer for making HTTP calls.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
-
"dependencies": {
|
|
7
|
-
"@dynatrace-sdk/error-handlers": "^1.2.0"
|
|
8
|
-
},
|
|
6
|
+
"dependencies": { "@dynatrace-sdk/error-handlers": "^1.2.0" },
|
|
9
7
|
"main": "./cjs/index.js",
|
|
10
8
|
"module": "./esm/index.js",
|
|
11
9
|
"types": "./types/index.d.ts"
|
|
12
|
-
}
|
|
10
|
+
}
|