@dynatrace-sdk/http-client 1.3.0 → 1.4.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 CHANGED
@@ -1,7 +1,20 @@
1
- # http-client
1
+ # @dynatrace-sdk/http-client
2
2
 
3
3
  @dynatrace-sdk/http-client
4
4
 
5
+ ## 1.4.0
6
+
7
+ ### Minor Changes
8
+
9
+ - Add safety margin token expiration time. (APPDEV-11345)
10
+
11
+ ## 1.3.1
12
+
13
+ ### Patch Changes
14
+
15
+ - Fix JSDoc annotations.
16
+ - The errorCode field in serialized error details is now set using proper errorCode from response instead of status code.
17
+
5
18
  ## 1.3.0
6
19
 
7
20
  ### Minor Changes
package/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2023-2024 Dynatrace LLC
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
@@ -684,7 +684,7 @@ async function parseResponse(response) {
684
684
  return {
685
685
  message: getMessageFromObject(jsonBody.error) || getMessageFromObject(jsonBody) || consumedBody.substring(0, 100),
686
686
  body: jsonBody,
687
- errorCode: jsonBody.error?.code,
687
+ errorCode: jsonBody.error?.details?.errorCode,
688
688
  errorRef: jsonBody.error?.details?.errorRef,
689
689
  traceId: jsonBody.error?.details?.traceId
690
690
  };
@@ -808,6 +808,7 @@ var HttpClient = class {
808
808
  var httpClient = new HttpClient();
809
809
 
810
810
  // packages/http-client/src/lib/platform/oauth-http-client.ts
811
+ var TOKEN_EXPIRATION_SAFETY_MARGIN_SECONDS = 1;
811
812
  var OAuthToken = class {
812
813
  _scope;
813
814
  _tokenType;
@@ -818,7 +819,7 @@ var OAuthToken = class {
818
819
  this._tokenType = oauthTokenResponse.token_type;
819
820
  this._expirationDate = ((expiresIn) => {
820
821
  const date = /* @__PURE__ */ new Date();
821
- date.setSeconds(date.getSeconds() + expiresIn);
822
+ date.setSeconds(date.getSeconds() + expiresIn - TOKEN_EXPIRATION_SAFETY_MARGIN_SECONDS);
822
823
  return date;
823
824
  })(oauthTokenResponse.expires_in);
824
825
  this._accessToken = oauthTokenResponse.access_token;
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.3.0" target="_blank" rel="noopener noreferrer">v1.3.0</a>
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>
19
19
  </div>
20
20
  </div>
21
21
 
@@ -54,11 +54,6 @@ npm install @dynatrace-sdk/http-client
54
54
  | Name | Type | Description |
55
55
  | --- | --- | --- |
56
56
  |cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)| |
57
- |message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
58
- |name<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
59
- |stack|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
60
- |prepareStackTrace|Object|Optional override for formatting stack traces |
61
- |stackTraceLimit<sup>*required</sup>|[number](https://developer.mozilla.org/en-US/docs/Glossary/Number)| |
62
57
 
63
58
 
64
59
  ### PlatformBinary
@@ -99,6 +94,14 @@ Returns the binary data in a form that conforms to the specified type.
99
94
 
100
95
 
101
96
 
97
+ #### Throws
98
+
99
+ | Error Type | Error Message |
100
+ |---|---|
101
+ |DataTypeError|Data does not conform to the specified type.|
102
+ |UnsupportedOperationError|Type is not supported by the platform.|
103
+
104
+
102
105
 
103
106
 
104
107
  </div>
@@ -133,6 +136,7 @@ Returns the binary data in a form that conforms to the specified type.
133
136
 
134
137
 
135
138
 
139
+
136
140
  </div>
137
141
 
138
142
 
@@ -165,6 +169,7 @@ Returns the binary data in a form that conforms to the specified type.
165
169
 
166
170
 
167
171
 
172
+
168
173
  </div>
169
174
 
170
175
 
@@ -197,6 +202,7 @@ Returns the binary data in a form that conforms to the specified type.
197
202
 
198
203
 
199
204
 
205
+
200
206
  </div>
201
207
 
202
208
 
@@ -230,11 +236,7 @@ Returns the binary data in a form that conforms to the specified type.
230
236
  | Name | Type | Description |
231
237
  | --- | --- | --- |
232
238
  |cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
233
- |message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
234
239
  |name<sup>*required</sup>|"DataTypeError"|The error name. |
235
- |stack|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
236
- |prepareStackTrace|Object|Optional override for formatting stack traces |
237
- |stackTraceLimit<sup>*required</sup>|[number](https://developer.mozilla.org/en-US/docs/Glossary/Number)| |
238
240
 
239
241
 
240
242
  ### PlatformHttpClient
@@ -273,70 +275,6 @@ Currently, only the requests to the Platform Services and the Serverless Functio
273
275
 
274
276
 
275
277
 
276
- ##### _setBaseURL
277
-
278
- <div class="padding-bottom--md">
279
- <strong>_setBaseURL(baseUrl): void</strong>
280
-
281
- <div class="padding-left--md">
282
-
283
- Sets HTTP Client Instance baseUrl param to the incoming value `baseUrl`.
284
-
285
-
286
-
287
- </div>
288
-
289
-
290
- #### Parameters
291
-
292
- | Name | Type | Description |
293
- | --- | --- | --- |
294
- |baseUrl<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|Base URL used in the request path. |
295
-
296
-
297
-
298
-
299
-
300
-
301
-
302
- </div>
303
-
304
-
305
-
306
-
307
-
308
- ##### _setDefaultHeaders
309
-
310
- <div class="padding-bottom--md">
311
- <strong>_setDefaultHeaders(defaultHeaders): void</strong>
312
-
313
- <div class="padding-left--md">
314
-
315
- Sets HTTP Client Instance defaultHeaders param to the incoming value `defaultHeaders`.
316
-
317
-
318
-
319
- </div>
320
-
321
-
322
- #### Parameters
323
-
324
- | Name | Type | Description |
325
- | --- | --- | --- |
326
- |defaultHeaders<sup>*required</sup>|[Headers](#headers)|HTTP Headers to be used in outgoing requests. |
327
-
328
-
329
-
330
-
331
-
332
-
333
-
334
- </div>
335
-
336
-
337
-
338
-
339
-
340
278
  ##### send
341
279
 
342
280
  <div class="padding-bottom--md">
@@ -368,7 +306,10 @@ when one of the following situations happen:
368
306
 
369
307
  #### Returns
370
308
 
371
- Promise&amp;lt;HttpClientResponse&amp;gt; A promise that resolves with the response object or rejects with an error.
309
+ | Description |
310
+ |---|
311
+ |Promise&lt;HttpClientResponse&gt; A promise that resolves with the response object or rejects with an error.|
312
+
372
313
 
373
314
 
374
315
 
@@ -405,11 +346,7 @@ Represents a situation when the request was aborted.
405
346
  | Name | Type | Description |
406
347
  | --- | --- | --- |
407
348
  |cause<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
408
- |message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
409
349
  |name<sup>*required</sup>|"AbortError"|The error name. |
410
- |stack|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
411
- |prepareStackTrace|Object|Optional override for formatting stack traces |
412
- |stackTraceLimit<sup>*required</sup>|[number](https://developer.mozilla.org/en-US/docs/Glossary/Number)| |
413
350
 
414
351
 
415
352
  ### PlatformHttpClientRequestError
@@ -439,11 +376,7 @@ Represents a situation when the request is invalid and cannot be sent.
439
376
  | Name | Type | Description |
440
377
  | --- | --- | --- |
441
378
  |cause<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
442
- |message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
443
379
  |name<sup>*required</sup>|"RequestError"|The error name. |
444
- |stack|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
445
- |prepareStackTrace|Object|Optional override for formatting stack traces |
446
- |stackTraceLimit<sup>*required</sup>|[number](https://developer.mozilla.org/en-US/docs/Glossary/Number)| |
447
380
 
448
381
 
449
382
  ### PlatformHttpClientResponse
@@ -520,6 +453,14 @@ Returns the response body in a form that conforms to the specified response body
520
453
 
521
454
 
522
455
 
456
+ #### Throws
457
+
458
+ | Error Type | Error Message |
459
+ |---|---|
460
+ |DataTypeError|Response body does not conform to the specified response body type.|
461
+ |UnsupportedOperationError|Response body type is not supported by the platform.|
462
+
463
+
523
464
 
524
465
 
525
466
  </div>
@@ -541,7 +482,7 @@ Represents a situation when the response status is considered invalid by the sta
541
482
  | Name | Type |
542
483
  | --- | --- |
543
484
  |response<sup>*required</sup>|Response|
544
- |data|Object|
485
+ |data|\{ requestMethod \}|
545
486
  |data.requestMethod|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
546
487
 
547
488
 
@@ -556,13 +497,9 @@ Represents a situation when the response status is considered invalid by the sta
556
497
  | Name | Type | Description |
557
498
  | --- | --- | --- |
558
499
  |cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
559
- |message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
560
500
  |name<sup>*required</sup>|"ResponseError"|The error name. |
561
501
  |requestMethod|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
562
502
  |response<sup>*required</sup>|[HttpClientResponse](#httpclientresponse)|The response. |
563
- |stack|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
564
- |prepareStackTrace|Object|Optional override for formatting stack traces |
565
- |stackTraceLimit<sup>*required</sup>|[number](https://developer.mozilla.org/en-US/docs/Glossary/Number)| |
566
503
 
567
504
 
568
505
  ### PlatformUnsupportedOperationError
@@ -593,47 +530,54 @@ Represents a situation when the response status is considered invalid by the sta
593
530
  | Name | Type | Description |
594
531
  | --- | --- | --- |
595
532
  |cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
596
- |message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
597
533
  |name<sup>*required</sup>|"UnsupportedOperationError"|The error name. |
598
- |stack|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
599
- |prepareStackTrace|Object|Optional override for formatting stack traces |
600
- |stackTraceLimit<sup>*required</sup>|[number](https://developer.mozilla.org/en-US/docs/Glossary/Number)| |
601
534
 
602
535
 
603
- ### _OAuthHttpClient
604
- DO NOT USE - internal use only.
536
+ ## Functions
605
537
 
606
538
 
607
- #### Constructors
608
539
 
609
- ##### new _OAuthHttpClient(config)
540
+ ### isHttpClientAbortError
610
541
 
542
+ <div class="padding-bottom--md">
543
+ <strong>isHttpClientAbortError(e): </strong>
611
544
 
545
+ <div class="padding-left--md">
612
546
 
613
- #### Properties
547
+
548
+
549
+
550
+
551
+ </div>
552
+
553
+
554
+ #### Parameters
614
555
 
615
556
  | Name | Type |
616
557
  | --- | --- |
617
- |oauthToken|OAuthToken|
558
+ |e<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
559
+
618
560
 
619
- #### Methods
620
561
 
621
562
 
622
563
 
623
- ##### send
564
+
565
+
566
+
567
+ </div>
568
+
569
+
570
+
571
+
572
+
573
+ ### isHttpClientNetworkError
624
574
 
625
575
  <div class="padding-bottom--md">
626
- <strong>send(options): Promise&lt;[HttpClientResponse](#httpclientresponse)&gt;</strong>
576
+ <strong>isHttpClientNetworkError(e): </strong>
627
577
 
628
578
  <div class="padding-left--md">
629
579
 
630
- Sends an http request as configured by the `options`.
631
- Returns a promise that resolves with a response object for successful requests or rejects with an appropriate error
632
- when one of the following situations happen:
633
- - `DataTypeError` - request body does not conform to the specified request body type,
634
- - `HttpClientRequestError` - request cannot be sent (e.g. due to network error or invalid request),
635
- - `HttpClientResponseError` - response status is considered invalid by the status validator,
636
- - `HttpClientAbortError` - request was aborted.
580
+
637
581
 
638
582
 
639
583
 
@@ -642,26 +586,126 @@ when one of the following situations happen:
642
586
 
643
587
  #### Parameters
644
588
 
645
- | Name | Type | Description |
646
- | --- | --- | --- |
647
- |options<sup>*required</sup>|[HttpClientRequestOptions](#httpclientrequestoptions)&lt;T&gt;|Options used to configure the request. |
589
+ | Name | Type |
590
+ | --- | --- |
591
+ |e<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
592
+
593
+
594
+
595
+
596
+
597
+
598
+
599
+
600
+ </div>
601
+
602
+
603
+
604
+
605
+
606
+ ### isHttpClientRequestError
607
+
608
+ <div class="padding-bottom--md">
609
+ <strong>isHttpClientRequestError(e): </strong>
610
+
611
+ <div class="padding-left--md">
612
+
613
+
614
+
615
+
616
+
617
+ </div>
618
+
619
+
620
+ #### Parameters
621
+
622
+ | Name | Type |
623
+ | --- | --- |
624
+ |e<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
648
625
 
649
626
 
650
627
 
651
628
 
652
- #### Returns
653
629
 
654
- Promise&amp;lt;HttpClientResponse&amp;gt; A promise that resolves with the response object or rejects with an error.
655
630
 
656
631
 
657
632
 
633
+ </div>
634
+
635
+
636
+
637
+
638
+
639
+ ### isHttpClientResponseError
640
+
641
+ <div class="padding-bottom--md">
642
+ <strong>isHttpClientResponseError(e): </strong>
643
+
644
+ <div class="padding-left--md">
645
+
646
+
647
+
648
+
649
+
650
+ </div>
651
+
652
+
653
+ #### Parameters
654
+
655
+ | Name | Type |
656
+ | --- | --- |
657
+ |e<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
658
+
659
+
660
+
661
+
662
+
663
+
664
+
665
+
666
+ </div>
667
+
668
+
669
+
670
+ ## Constants
671
+
672
+ ### PlatformAbortController
673
+ <div class="padding-left--md">
674
+
675
+
676
+
677
+ </div>
678
+
679
+ <div class="padding-left--md">
680
+ () => [AbortController](#abortcontroller)
658
681
 
659
682
  </div>
660
683
 
684
+ ### PlatformAbortSignal
685
+ <div class="padding-left--md">
661
686
 
662
687
 
663
688
 
664
- ## Interfaces
689
+ </div>
690
+
691
+ <div class="padding-left--md">
692
+ () => AbortSignal
693
+
694
+ </div>
695
+
696
+ ### httpClient
697
+ <div class="padding-left--md">
698
+
699
+
700
+
701
+ </div>
702
+
703
+ <div class="padding-left--md">
704
+ [HttpClient](#httpclient)
705
+
706
+ </div>
707
+
708
+ ## Types
665
709
 
666
710
  ### AbortController
667
711
  Represents a controller object that allows to abort one or more requests as and when desired.
@@ -695,6 +739,7 @@ Aborts a request before it has completed.
695
739
 
696
740
 
697
741
 
742
+
698
743
  </div>
699
744
 
700
745
 
@@ -709,9 +754,7 @@ Aborts a request before it has completed.
709
754
  | Name | Type |
710
755
  | --- | --- |
711
756
  |cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
712
- |message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
713
757
  |name<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
714
- |stack|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
715
758
 
716
759
 
717
760
  ### Binary
@@ -746,6 +789,14 @@ Returns the binary data in a form that conforms to the specified type.
746
789
 
747
790
 
748
791
 
792
+ #### Throws
793
+
794
+ | Error Type | Error Message |
795
+ |---|---|
796
+ |DataTypeError|Data does not conform to the specified type.|
797
+ |UnsupportedOperationError|Type is not supported by the platform.|
798
+
799
+
749
800
 
750
801
 
751
802
  </div>
@@ -792,9 +843,7 @@ Represents an binary field.
792
843
  | Name | Type | Description |
793
844
  | --- | --- | --- |
794
845
  |cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
795
- |message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
796
846
  |name<sup>*required</sup>|"DataTypeError"|The error name. |
797
- |stack|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
798
847
 
799
848
 
800
849
  ### Headers
@@ -843,7 +892,10 @@ when one of the following situations happen:
843
892
 
844
893
  #### Returns
845
894
 
846
- Promise&amp;lt;HttpClientResponse&amp;gt; A promise that resolves with the response object or rejects with an error.
895
+ | Description |
896
+ |---|
897
+ |Promise&lt;HttpClientResponse&gt; A promise that resolves with the response object or rejects with an error.|
898
+
847
899
 
848
900
 
849
901
 
@@ -862,9 +914,7 @@ Represents a situation when the request was aborted.
862
914
  | Name | Type | Description |
863
915
  | --- | --- | --- |
864
916
  |cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
865
- |message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
866
917
  |name<sup>*required</sup>|"AbortError"|The error name. |
867
- |stack|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
868
918
 
869
919
 
870
920
  ### HttpClientNetworkError
@@ -876,9 +926,7 @@ Represents a situation when a network error occurred.
876
926
  | Name | Type | Description |
877
927
  | --- | --- | --- |
878
928
  |cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
879
- |message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
880
929
  |name<sup>*required</sup>|"NetworkError"|The error name. |
881
- |stack|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
882
930
 
883
931
 
884
932
  ### HttpClientRequestError
@@ -890,9 +938,7 @@ Represents a situation when the request is invalid and cannot be sent.
890
938
  | Name | Type | Description |
891
939
  | --- | --- | --- |
892
940
  |cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
893
- |message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
894
941
  |name<sup>*required</sup>|"RequestError"|The error name. |
895
- |stack|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
896
942
 
897
943
 
898
944
  ### HttpClientRequestOptions
@@ -952,6 +998,14 @@ Returns the response body in a form that conforms to the specified response body
952
998
 
953
999
 
954
1000
 
1001
+ #### Throws
1002
+
1003
+ | Error Type | Error Message |
1004
+ |---|---|
1005
+ |DataTypeError|Response body does not conform to the specified response body type.|
1006
+ |UnsupportedOperationError|Response body type is not supported by the platform.|
1007
+
1008
+
955
1009
 
956
1010
 
957
1011
  </div>
@@ -968,10 +1022,8 @@ Represents a situation when the response status is considered invalid by the sta
968
1022
  | Name | Type | Description |
969
1023
  | --- | --- | --- |
970
1024
  |cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
971
- |message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
972
1025
  |name<sup>*required</sup>|"ResponseError"|The error name. |
973
1026
  |response<sup>*required</sup>|[HttpClientResponse](#httpclientresponse)|The response. |
974
- |stack|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
975
1027
 
976
1028
 
977
1029
  ### JsonFormDataRequestField
@@ -1029,191 +1081,6 @@ Represents a plain text field. No filename and content type is set.
1029
1081
  | Name | Type | Description |
1030
1082
  | --- | --- | --- |
1031
1083
  |cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause. |
1032
- |message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
1033
1084
  |name<sup>*required</sup>|"UnsupportedOperationError"|The error name. |
1034
- |stack|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
1035
-
1036
-
1037
- ### _OAuthHttpClientConfig
1038
- DO NOT USE - internal use only.
1039
-
1040
-
1041
- #### Properties
1042
-
1043
- | Name | Type |
1044
- | --- | --- |
1045
- |authUrl<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
1046
- |clientId<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
1047
- |environmentUrl<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
1048
- |scopes<sup>*required</sup>|Array&lt;[string](https://developer.mozilla.org/en-US/docs/Glossary/String)&gt;|
1049
- |secret<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
1050
-
1051
-
1052
- ## Variables
1053
-
1054
- <div class="padding-left--md padding-bottom--md">
1055
- <strong>PlatformAbortController</strong>: Object
1056
- <div class="padding-left--md">
1057
-
1058
-
1059
-
1060
- </div>
1061
-
1062
-
1063
-
1064
- </div>
1065
-
1066
- <div class="padding-left--md padding-bottom--md">
1067
- <strong>PlatformAbortSignal</strong>: Object
1068
- <div class="padding-left--md">
1069
-
1070
-
1071
-
1072
- </div>
1073
-
1074
-
1075
-
1076
- </div>
1077
-
1078
- <div class="padding-left--md padding-bottom--md">
1079
- <strong>httpClient</strong>: [HttpClient](#httpclient)
1080
- <div class="padding-left--md">
1081
-
1082
-
1083
-
1084
- </div>
1085
-
1086
-
1087
-
1088
- </div>
1089
-
1090
- ## Functions
1091
-
1092
-
1093
-
1094
- ### isHttpClientAbortError
1095
-
1096
- <div class="padding-bottom--md">
1097
- <strong>isHttpClientAbortError(e): </strong>
1098
-
1099
- <div class="padding-left--md">
1100
-
1101
-
1102
-
1103
-
1104
-
1105
- </div>
1106
-
1107
-
1108
- #### Parameters
1109
-
1110
- | Name | Type |
1111
- | --- | --- |
1112
- |e<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
1113
-
1114
-
1115
-
1116
-
1117
-
1118
-
1119
-
1120
- </div>
1121
-
1122
-
1123
-
1124
-
1125
-
1126
- ### isHttpClientNetworkError
1127
-
1128
- <div class="padding-bottom--md">
1129
- <strong>isHttpClientNetworkError(e): </strong>
1130
-
1131
- <div class="padding-left--md">
1132
-
1133
-
1134
-
1135
-
1136
-
1137
- </div>
1138
-
1139
-
1140
- #### Parameters
1141
-
1142
- | Name | Type |
1143
- | --- | --- |
1144
- |e<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
1145
-
1146
-
1147
-
1148
-
1149
-
1150
-
1151
-
1152
- </div>
1153
-
1154
-
1155
-
1156
-
1157
-
1158
- ### isHttpClientRequestError
1159
-
1160
- <div class="padding-bottom--md">
1161
- <strong>isHttpClientRequestError(e): </strong>
1162
-
1163
- <div class="padding-left--md">
1164
-
1165
-
1166
-
1167
-
1168
-
1169
- </div>
1170
-
1171
-
1172
- #### Parameters
1173
-
1174
- | Name | Type |
1175
- | --- | --- |
1176
- |e<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
1177
-
1178
-
1179
-
1180
-
1181
-
1182
-
1183
-
1184
- </div>
1185
-
1186
-
1187
-
1188
-
1189
-
1190
- ### isHttpClientResponseError
1191
-
1192
- <div class="padding-bottom--md">
1193
- <strong>isHttpClientResponseError(e): </strong>
1194
-
1195
- <div class="padding-left--md">
1196
-
1197
-
1198
-
1199
-
1200
-
1201
- </div>
1202
-
1203
-
1204
- #### Parameters
1205
-
1206
- | Name | Type |
1207
- | --- | --- |
1208
- |e<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
1209
-
1210
-
1211
-
1212
-
1213
-
1214
-
1215
-
1216
- </div>
1217
-
1218
1085
 
1219
1086
 
package/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2023-2024 Dynatrace LLC
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
@@ -647,7 +647,7 @@ async function parseResponse(response) {
647
647
  return {
648
648
  message: getMessageFromObject(jsonBody.error) || getMessageFromObject(jsonBody) || consumedBody.substring(0, 100),
649
649
  body: jsonBody,
650
- errorCode: jsonBody.error?.code,
650
+ errorCode: jsonBody.error?.details?.errorCode,
651
651
  errorRef: jsonBody.error?.details?.errorRef,
652
652
  traceId: jsonBody.error?.details?.traceId
653
653
  };
@@ -771,6 +771,7 @@ var HttpClient = class {
771
771
  var httpClient = new HttpClient();
772
772
 
773
773
  // packages/http-client/src/lib/platform/oauth-http-client.ts
774
+ var TOKEN_EXPIRATION_SAFETY_MARGIN_SECONDS = 1;
774
775
  var OAuthToken = class {
775
776
  _scope;
776
777
  _tokenType;
@@ -781,7 +782,7 @@ var OAuthToken = class {
781
782
  this._tokenType = oauthTokenResponse.token_type;
782
783
  this._expirationDate = ((expiresIn) => {
783
784
  const date = /* @__PURE__ */ new Date();
784
- date.setSeconds(date.getSeconds() + expiresIn);
785
+ date.setSeconds(date.getSeconds() + expiresIn - TOKEN_EXPIRATION_SAFETY_MARGIN_SECONDS);
785
786
  return date;
786
787
  })(oauthTokenResponse.expires_in);
787
788
  this._accessToken = oauthTokenResponse.access_token;
package/package.json CHANGED
@@ -1,12 +1,10 @@
1
1
  {
2
2
  "name": "@dynatrace-sdk/http-client",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
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
+ }
@@ -8,8 +8,8 @@ export interface Binary {
8
8
  *
9
9
  * @param type The type of the data.
10
10
  * Can be `text`, `json`, `array-buffer`, `blob`, `readable-stream`, `buffer` or `stream`.
11
- * @throws DataTypeError when the data does not conform to the specified type.
12
- * @throws UnsupportedOperationError when the type is not supported by the platform.
11
+ * @throws {DataTypeError} Data does not conform to the specified type.
12
+ * @throws {UnsupportedOperationError} Type is not supported by the platform.
13
13
  */
14
14
  get<T extends keyof DataTypes>(type: T): DataTypes[T];
15
15
  }
@@ -26,8 +26,8 @@ export interface HttpClientResponse {
26
26
  * @param responseBodyType The type of the response body.
27
27
  * Can be `text`, `json`, `binary`, `form-data`, `array-buffer`, `blob`, `readable-stream`, `buffer` or `stream`.
28
28
  * The default response body type is `json`.
29
- * @throws DataTypeError when the response body does not conform to the specified response body type.
30
- * @throws UnsupportedOperationError when the response body type is not supported by the platform.
29
+ * @throws {DataTypeError} Response body does not conform to the specified response body type.
30
+ * @throws {UnsupportedOperationError} Response body type is not supported by the platform.
31
31
  */
32
32
  body<T extends keyof ResponseBodyTypes = 'json'>(responseBodyType?: T): ResponseBodyTypes[T];
33
33
  }