@dynatrace-sdk/http-client 1.4.0 → 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.
Files changed (47) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/cjs/index.js +19 -7
  3. package/docs/DOCS.md +14 -10
  4. package/esm/index.js +19 -7
  5. package/package.json +1 -1
  6. package/types/index.d.ts +617 -1
  7. package/types/packages/http-client/src/index.d.ts +0 -2
  8. package/types/packages/http-client/src/lib/platform/abort-controller.d.ts +0 -6
  9. package/types/packages/http-client/src/lib/platform/abort-signal.d.ts +0 -6
  10. package/types/packages/http-client/src/lib/platform/apply-content-type-header.d.ts +0 -2
  11. package/types/packages/http-client/src/lib/platform/base-error.d.ts +0 -5
  12. package/types/packages/http-client/src/lib/platform/binary.d.ts +0 -13
  13. package/types/packages/http-client/src/lib/platform/data-type-error.d.ts +0 -6
  14. package/types/packages/http-client/src/lib/platform/decode-form-data.d.ts +0 -48
  15. package/types/packages/http-client/src/lib/platform/decode-response-body.d.ts +0 -3
  16. package/types/packages/http-client/src/lib/platform/default-status-validator.d.ts +0 -2
  17. package/types/packages/http-client/src/lib/platform/encode-request-body.d.ts +0 -2
  18. package/types/packages/http-client/src/lib/platform/http-client-abort-error.d.ts +0 -7
  19. package/types/packages/http-client/src/lib/platform/http-client-request-error.d.ts +0 -7
  20. package/types/packages/http-client/src/lib/platform/http-client-response-error-serializer.d.ts +0 -3
  21. package/types/packages/http-client/src/lib/platform/http-client-response-error.d.ts +0 -11
  22. package/types/packages/http-client/src/lib/platform/http-client-response.d.ts +0 -10
  23. package/types/packages/http-client/src/lib/platform/http-client.d.ts +0 -24
  24. package/types/packages/http-client/src/lib/platform/index.d.ts +0 -12
  25. package/types/packages/http-client/src/lib/platform/oauth-http-client.d.ts +0 -41
  26. package/types/packages/http-client/src/lib/platform/unsupported-operation-error.d.ts +0 -6
  27. package/types/packages/http-client/src/lib/types/abort-controller.d.ts +0 -14
  28. package/types/packages/http-client/src/lib/types/abort-signal.d.ts +0 -18
  29. package/types/packages/http-client/src/lib/types/base-error.d.ts +0 -4
  30. package/types/packages/http-client/src/lib/types/binary.d.ts +0 -15
  31. package/types/packages/http-client/src/lib/types/data-type-error.d.ts +0 -14
  32. package/types/packages/http-client/src/lib/types/data-types.d.ts +0 -36
  33. package/types/packages/http-client/src/lib/types/form-data-request-body.d.ts +0 -83
  34. package/types/packages/http-client/src/lib/types/form-data-response-body.d.ts +0 -15
  35. package/types/packages/http-client/src/lib/types/headers.d.ts +0 -6
  36. package/types/packages/http-client/src/lib/types/http-client-abort-error.d.ts +0 -15
  37. package/types/packages/http-client/src/lib/types/http-client-network-error.d.ts +0 -15
  38. package/types/packages/http-client/src/lib/types/http-client-request-error.d.ts +0 -15
  39. package/types/packages/http-client/src/lib/types/http-client-request-options.d.ts +0 -42
  40. package/types/packages/http-client/src/lib/types/http-client-response-error.d.ts +0 -20
  41. package/types/packages/http-client/src/lib/types/http-client-response.d.ts +0 -33
  42. package/types/packages/http-client/src/lib/types/http-client.d.ts +0 -24
  43. package/types/packages/http-client/src/lib/types/index.d.ts +0 -20
  44. package/types/packages/http-client/src/lib/types/request-body-types.d.ts +0 -26
  45. package/types/packages/http-client/src/lib/types/response-body-types.d.ts +0 -46
  46. package/types/packages/http-client/src/lib/types/status-validator.d.ts +0 -7
  47. package/types/packages/http-client/src/lib/types/unsupported-operation-error.d.ts +0 -14
package/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
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
+
5
21
  ## 1.4.0
6
22
 
7
23
  ### Minor Changes
package/cjs/index.js CHANGED
@@ -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,9 +804,12 @@ 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, { requestMethod: options.method });
809
+ throw new HttpClientResponseError(response, {
810
+ requestUrl: url,
811
+ requestMethod: options.method
812
+ });
805
813
  }
806
814
  }
807
815
  };
@@ -862,7 +870,8 @@ var OAuthHttpClient = class {
862
870
  ...applyContentTypeHeader(options.headers, requestBodyType),
863
871
  Authorization: `${this.oauthToken.tokenType} ${this.oauthToken.accessToken}`
864
872
  };
865
- const response = await send2(url.toString(), {
873
+ const requestUrl = url.toString();
874
+ const response = await send2(requestUrl, {
866
875
  method: options.method,
867
876
  signal: options.abortSignal,
868
877
  body,
@@ -870,9 +879,12 @@ var OAuthHttpClient = class {
870
879
  });
871
880
  const ok = statusValidator(response.status);
872
881
  if (ok) {
873
- return new HttpClientResponse(response);
882
+ return new HttpClientResponse(response, { requestUrl });
874
883
  } else {
875
- throw new HttpClientResponseError(response, { requestMethod: options.method });
884
+ throw new HttpClientResponseError(response, {
885
+ requestUrl,
886
+ requestMethod: options.method
887
+ });
876
888
  }
877
889
  }
878
890
  async requestToken() {
package/docs/DOCS.md CHANGED
@@ -4,8 +4,6 @@ description: An environment agnostic (browser/deno vs nodejs) abstraction layer
4
4
  ---
5
5
 
6
6
 
7
- # @dynatrace-sdk/http-client
8
-
9
7
  An environment agnostic (browser/deno vs nodejs) abstraction layer for making HTTP calls.
10
8
 
11
9
  import NpmLogo from '@site/static/img/npm-logo.png';
@@ -15,7 +13,7 @@ import NpmLogo from '@site/static/img/npm-logo.png';
15
13
  <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
14
  </div>
17
15
  <div class="col" style={{textAlign: 'right'}}>
18
- <a href="https://www.npmjs.com/package/@dynatrace-sdk/http-client/v/1.4.0" target="_blank" rel="noopener noreferrer">v1.4.0</a>
16
+ <a href="https://www.npmjs.com/package/@dynatrace-sdk/http-client/v/1.5.1" target="_blank" rel="noopener noreferrer">v1.5.1</a>
19
17
  </div>
20
18
  </div>
21
19
 
@@ -385,7 +383,7 @@ Represents the response to a request.
385
383
 
386
384
  #### Constructors
387
385
 
388
- ##### new PlatformHttpClientResponse(response)
386
+ ##### new PlatformHttpClientResponse(response,data?)
389
387
  <div class="padding-left--md">
390
388
 
391
389
  #### Parameters
@@ -393,6 +391,8 @@ Represents the response to a request.
393
391
  | Name | Type |
394
392
  | --- | --- |
395
393
  |response<sup>*required</sup>|Response|
394
+ |data|\{ requestUrl \}|
395
+ |data.requestUrl<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
396
396
 
397
397
 
398
398
 
@@ -403,9 +403,10 @@ Represents the response to a request.
403
403
 
404
404
  #### Properties
405
405
 
406
- | Name | Type |
407
- | --- | --- |
408
- |response<sup>*required</sup>|Response|
406
+ | Name | Type | Description |
407
+ | --- | --- | --- |
408
+ |requestUrl<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The URL that was originally requested, before any redirects were followed. |
409
+ |response<sup>*required</sup>|Response| |
409
410
 
410
411
  #### Accessors
411
412
 
@@ -422,7 +423,8 @@ The status message corresponding to the status code.
422
423
 
423
424
 
424
425
  ##### url
425
- The URL of the response.
426
+ The URL of the response. May differ from `requestUrl` if the request was
427
+ redirected.
426
428
 
427
429
 
428
430
  #### Methods
@@ -482,8 +484,9 @@ Represents a situation when the response status is considered invalid by the sta
482
484
  | Name | Type |
483
485
  | --- | --- |
484
486
  |response<sup>*required</sup>|Response|
485
- |data|\{ requestMethod \}|
487
+ |data|\{ requestMethod, requestUrl \}|
486
488
  |data.requestMethod|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
489
+ |data.requestUrl|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
487
490
 
488
491
 
489
492
 
@@ -966,9 +969,10 @@ Represents the response to a request.
966
969
  | Name | Type | Description |
967
970
  | --- | --- | --- |
968
971
  |headers<sup>*required</sup>|[Headers](#headers)|The response headers. |
972
+ |requestUrl<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The URL that was originally requested, before any redirects were followed. |
969
973
  |status<sup>*required</sup>|[number](https://developer.mozilla.org/en-US/docs/Glossary/Number)|The status code of the response. |
970
974
  |statusText<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The status message corresponding to the status code. |
971
- |url<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The URL of the response. |
975
+ |url<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|<p>The URL of the response. May differ from <code>requestUrl</code> if the request was redirected.</p> |
972
976
 
973
977
  #### Methods
974
978
 
package/esm/index.js CHANGED
@@ -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,9 +767,12 @@ 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, { requestMethod: options.method });
772
+ throw new HttpClientResponseError(response, {
773
+ requestUrl: url,
774
+ requestMethod: options.method
775
+ });
768
776
  }
769
777
  }
770
778
  };
@@ -825,7 +833,8 @@ var OAuthHttpClient = class {
825
833
  ...applyContentTypeHeader(options.headers, requestBodyType),
826
834
  Authorization: `${this.oauthToken.tokenType} ${this.oauthToken.accessToken}`
827
835
  };
828
- const response = await send2(url.toString(), {
836
+ const requestUrl = url.toString();
837
+ const response = await send2(requestUrl, {
829
838
  method: options.method,
830
839
  signal: options.abortSignal,
831
840
  body,
@@ -833,9 +842,12 @@ var OAuthHttpClient = class {
833
842
  });
834
843
  const ok = statusValidator(response.status);
835
844
  if (ok) {
836
- return new HttpClientResponse(response);
845
+ return new HttpClientResponse(response, { requestUrl });
837
846
  } else {
838
- throw new HttpClientResponseError(response, { requestMethod: options.method });
847
+ throw new HttpClientResponseError(response, {
848
+ requestUrl,
849
+ requestMethod: options.method
850
+ });
839
851
  }
840
852
  }
841
853
  async requestToken() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynatrace-sdk/http-client",
3
- "version": "1.4.0",
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
6
  "dependencies": { "@dynatrace-sdk/error-handlers": "^1.2.0" },