@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/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,29 @@
|
|
|
1
|
-
# http-client
|
|
1
|
+
# @dynatrace-sdk/http-client
|
|
2
2
|
|
|
3
3
|
@dynatrace-sdk/http-client
|
|
4
4
|
|
|
5
|
+
## 1.5.1
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- Make `data` constructor argument optional in `HttpClientResponse` and `HttpClientResponseError`, falling back to `response.url` when `requestUrl` is not provided. Restores backward compatibility broken in v1.5.0. (APPDEV-17720)
|
|
10
|
+
|
|
11
|
+
## 1.5.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- Add `requestUrl` to `HttpClientResponse` so the originally requested URL is preserved (and surfaced in error logs) even when `fetch` follows a redirect. (APPDEV-16083)
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Generated TypeScript declarations are now rolled up into a single `types/index.d.ts` per entry point. (APPDEV-11700)
|
|
20
|
+
|
|
21
|
+
## 1.4.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- Add safety margin token expiration time. (APPDEV-11345)
|
|
26
|
+
|
|
5
27
|
## 1.3.1
|
|
6
28
|
|
|
7
29
|
### Patch Changes
|
package/cjs/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
|
|
@@ -636,9 +636,11 @@ function decodeResponseBody(response, responseBodyType) {
|
|
|
636
636
|
|
|
637
637
|
// packages/http-client/src/lib/platform/http-client-response.ts
|
|
638
638
|
var HttpClientResponse = class {
|
|
639
|
-
constructor(response) {
|
|
639
|
+
constructor(response, data) {
|
|
640
640
|
this.response = response;
|
|
641
|
+
this.requestUrl = data?.requestUrl ?? response.url;
|
|
641
642
|
}
|
|
643
|
+
requestUrl;
|
|
642
644
|
get url() {
|
|
643
645
|
return this.response.url;
|
|
644
646
|
}
|
|
@@ -717,6 +719,7 @@ var httpClientResponseErrorSerializer = async (error) => {
|
|
|
717
719
|
type: import_error_handlers.ErrorType.HTTP,
|
|
718
720
|
details: {
|
|
719
721
|
url: error.response.url,
|
|
722
|
+
requestUrl: error.response.requestUrl,
|
|
720
723
|
method: error.requestMethod,
|
|
721
724
|
errorCode,
|
|
722
725
|
responseContentType: getHeaderValue(error.response, "content-type"),
|
|
@@ -750,7 +753,9 @@ var HttpClientResponseError = class extends BaseError {
|
|
|
750
753
|
constructor(response, data) {
|
|
751
754
|
addHttpClientResponseErrorSerializer();
|
|
752
755
|
super(`HTTP Error ${response.status}: ${response.statusText}`);
|
|
753
|
-
this.response = new HttpClientResponse(response
|
|
756
|
+
this.response = new HttpClientResponse(response, {
|
|
757
|
+
requestUrl: data?.requestUrl ?? response.url
|
|
758
|
+
});
|
|
754
759
|
this.requestMethod = data?.requestMethod;
|
|
755
760
|
}
|
|
756
761
|
};
|
|
@@ -799,15 +804,19 @@ var HttpClient = class {
|
|
|
799
804
|
});
|
|
800
805
|
const ok = statusValidator(response.status);
|
|
801
806
|
if (ok) {
|
|
802
|
-
return new HttpClientResponse(response);
|
|
807
|
+
return new HttpClientResponse(response, { requestUrl: url });
|
|
803
808
|
} else {
|
|
804
|
-
throw new HttpClientResponseError(response, {
|
|
809
|
+
throw new HttpClientResponseError(response, {
|
|
810
|
+
requestUrl: url,
|
|
811
|
+
requestMethod: options.method
|
|
812
|
+
});
|
|
805
813
|
}
|
|
806
814
|
}
|
|
807
815
|
};
|
|
808
816
|
var httpClient = new HttpClient();
|
|
809
817
|
|
|
810
818
|
// packages/http-client/src/lib/platform/oauth-http-client.ts
|
|
819
|
+
var TOKEN_EXPIRATION_SAFETY_MARGIN_SECONDS = 1;
|
|
811
820
|
var OAuthToken = class {
|
|
812
821
|
_scope;
|
|
813
822
|
_tokenType;
|
|
@@ -818,7 +827,7 @@ var OAuthToken = class {
|
|
|
818
827
|
this._tokenType = oauthTokenResponse.token_type;
|
|
819
828
|
this._expirationDate = ((expiresIn) => {
|
|
820
829
|
const date = /* @__PURE__ */ new Date();
|
|
821
|
-
date.setSeconds(date.getSeconds() + expiresIn);
|
|
830
|
+
date.setSeconds(date.getSeconds() + expiresIn - TOKEN_EXPIRATION_SAFETY_MARGIN_SECONDS);
|
|
822
831
|
return date;
|
|
823
832
|
})(oauthTokenResponse.expires_in);
|
|
824
833
|
this._accessToken = oauthTokenResponse.access_token;
|
|
@@ -861,7 +870,8 @@ var OAuthHttpClient = class {
|
|
|
861
870
|
...applyContentTypeHeader(options.headers, requestBodyType),
|
|
862
871
|
Authorization: `${this.oauthToken.tokenType} ${this.oauthToken.accessToken}`
|
|
863
872
|
};
|
|
864
|
-
const
|
|
873
|
+
const requestUrl = url.toString();
|
|
874
|
+
const response = await send2(requestUrl, {
|
|
865
875
|
method: options.method,
|
|
866
876
|
signal: options.abortSignal,
|
|
867
877
|
body,
|
|
@@ -869,9 +879,12 @@ var OAuthHttpClient = class {
|
|
|
869
879
|
});
|
|
870
880
|
const ok = statusValidator(response.status);
|
|
871
881
|
if (ok) {
|
|
872
|
-
return new HttpClientResponse(response);
|
|
882
|
+
return new HttpClientResponse(response, { requestUrl });
|
|
873
883
|
} else {
|
|
874
|
-
throw new HttpClientResponseError(response, {
|
|
884
|
+
throw new HttpClientResponseError(response, {
|
|
885
|
+
requestUrl,
|
|
886
|
+
requestMethod: options.method
|
|
887
|
+
});
|
|
875
888
|
}
|
|
876
889
|
}
|
|
877
890
|
async requestToken() {
|