@launchdarkly/js-sdk-common 2.31.0 → 2.32.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 +22 -0
- package/dist/cjs/datasource/CompositeDataSource.d.ts.map +1 -1
- package/dist/cjs/index.cjs +97 -3
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/internal/events/EventProcessor.d.ts.map +1 -1
- package/dist/cjs/internal/events/EventSender.d.ts.map +1 -1
- package/dist/cjs/internal/events/InputCustomEvent.d.ts +2 -2
- package/dist/cjs/internal/events/InputCustomEvent.d.ts.map +1 -1
- package/dist/cjs/internal/events/MultiEventSummarizer.d.ts.map +1 -1
- package/dist/cjs/internal/fdv2/payloadProcessor.d.ts.map +1 -1
- package/dist/cjs/internal/fdv2/payloadStreamReader.d.ts.map +1 -1
- package/dist/cjs/internal/fdv2/protocolHandler.d.ts.map +1 -1
- package/dist/cjs/internal/fetch/followRedirects.d.ts +34 -0
- package/dist/cjs/internal/fetch/followRedirects.d.ts.map +1 -0
- package/dist/cjs/internal/fetch/index.d.ts +1 -0
- package/dist/cjs/internal/fetch/index.d.ts.map +1 -1
- package/dist/cjs/logging/createSafeLogger.d.ts.map +1 -1
- package/dist/cjs/utils/debounce.d.ts +1 -1
- package/dist/cjs/utils/debounce.d.ts.map +1 -1
- package/dist/cjs/utils/deepCompact.d.ts +1 -1
- package/dist/cjs/utils/deepCompact.d.ts.map +1 -1
- package/dist/cjs/utils/http.d.ts.map +1 -1
- package/dist/cjs/utils/isEmptyObject.d.ts.map +1 -1
- package/dist/cjs/utils/sleep.d.ts.map +1 -1
- package/dist/cjs/utils/timedPromise.d.ts.map +1 -1
- package/dist/esm/AttributeReference.d.ts +1 -1
- package/dist/esm/Context.d.ts +2 -2
- package/dist/esm/ContextFilter.d.ts +2 -2
- package/dist/esm/api/context/LDContext.d.ts +3 -3
- package/dist/esm/api/context/LDContextCommon.d.ts +1 -1
- package/dist/esm/api/context/LDMultiKindContext.d.ts +1 -1
- package/dist/esm/api/context/LDSingleKindContext.d.ts +1 -1
- package/dist/esm/api/context/index.d.ts +6 -6
- package/dist/esm/api/data/LDEvaluationDetail.d.ts +2 -2
- package/dist/esm/api/data/LDFlagSet.d.ts +1 -1
- package/dist/esm/api/data/index.d.ts +4 -4
- package/dist/esm/api/index.d.ts +7 -7
- package/dist/esm/api/integrations/index.d.ts +1 -1
- package/dist/esm/api/logging/BasicLoggerOptions.d.ts +1 -1
- package/dist/esm/api/logging/index.d.ts +3 -3
- package/dist/esm/api/options/LDClientContext.d.ts +2 -2
- package/dist/esm/api/options/index.d.ts +1 -1
- package/dist/esm/api/platform/EventSource.d.ts +1 -1
- package/dist/esm/api/platform/Info.d.ts +1 -1
- package/dist/esm/api/platform/Platform.d.ts +6 -6
- package/dist/esm/api/platform/Requests.d.ts +1 -1
- package/dist/esm/api/platform/index.d.ts +9 -9
- package/dist/esm/api/subsystem/DataSystem/CallbackHandler.d.ts +1 -1
- package/dist/esm/api/subsystem/DataSystem/index.d.ts +1 -1
- package/dist/esm/api/subsystem/LDContextDeduplicator.d.ts +1 -1
- package/dist/esm/api/subsystem/LDEventProcessor.d.ts +1 -1
- package/dist/esm/api/subsystem/index.d.ts +5 -5
- package/dist/esm/datasource/CompositeDataSource.d.ts +3 -3
- package/dist/esm/datasource/CompositeDataSource.d.ts.map +1 -1
- package/dist/esm/datasource/errors.d.ts +1 -1
- package/dist/esm/datasource/index.d.ts +5 -5
- package/dist/esm/datasource/retry/RetryState.d.ts +3 -3
- package/dist/esm/datasource/retry/index.d.ts +2 -2
- package/dist/esm/index.d.ts +11 -11
- package/dist/esm/index.mjs +97 -3
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/internal/context/index.d.ts +1 -1
- package/dist/esm/internal/diagnostics/DiagnosticsManager.d.ts +2 -2
- package/dist/esm/internal/diagnostics/index.d.ts +1 -1
- package/dist/esm/internal/evaluation/EventFactoryBase.d.ts +3 -3
- package/dist/esm/internal/evaluation/index.d.ts +2 -2
- package/dist/esm/internal/events/EventProcessor.d.ts +6 -6
- package/dist/esm/internal/events/EventProcessor.d.ts.map +1 -1
- package/dist/esm/internal/events/EventSender.d.ts +3 -3
- package/dist/esm/internal/events/EventSender.d.ts.map +1 -1
- package/dist/esm/internal/events/InputClickEvent.d.ts +1 -1
- package/dist/esm/internal/events/InputCustomEvent.d.ts +3 -3
- package/dist/esm/internal/events/InputCustomEvent.d.ts.map +1 -1
- package/dist/esm/internal/events/InputEvalEvent.d.ts +2 -2
- package/dist/esm/internal/events/InputEvent.d.ts +6 -6
- package/dist/esm/internal/events/InputEventBase.d.ts +1 -1
- package/dist/esm/internal/events/InputIdentifyEvent.d.ts +1 -1
- package/dist/esm/internal/events/InputMigrationEvent.d.ts +1 -1
- package/dist/esm/internal/events/InputPageViewEvent.d.ts +1 -1
- package/dist/esm/internal/events/LDEventSummarizer.d.ts +1 -1
- package/dist/esm/internal/events/MultiEventSummarizer.d.ts +4 -4
- package/dist/esm/internal/events/MultiEventSummarizer.d.ts.map +1 -1
- package/dist/esm/internal/events/NullEventProcessor.d.ts +1 -1
- package/dist/esm/internal/events/guards.d.ts +4 -4
- package/dist/esm/internal/events/index.d.ts +10 -10
- package/dist/esm/internal/fdv2/FDv1PayloadAdaptor.d.ts +1 -1
- package/dist/esm/internal/fdv2/index.d.ts +8 -8
- package/dist/esm/internal/fdv2/payloadProcessor.d.ts +4 -4
- package/dist/esm/internal/fdv2/payloadProcessor.d.ts.map +1 -1
- package/dist/esm/internal/fdv2/payloadStreamReader.d.ts +3 -3
- package/dist/esm/internal/fdv2/payloadStreamReader.d.ts.map +1 -1
- package/dist/esm/internal/fdv2/protocolHandler.d.ts +2 -2
- package/dist/esm/internal/fdv2/protocolHandler.d.ts.map +1 -1
- package/dist/esm/internal/fetch/StreamingResponse.d.ts +1 -1
- package/dist/esm/internal/fetch/followRedirects.d.ts +34 -0
- package/dist/esm/internal/fetch/followRedirects.d.ts.map +1 -0
- package/dist/esm/internal/fetch/index.d.ts +3 -2
- package/dist/esm/internal/fetch/index.d.ts.map +1 -1
- package/dist/esm/internal/fetch/toRequestInit.d.ts +1 -1
- package/dist/esm/internal/index.d.ts +9 -9
- package/dist/esm/internal/json/index.d.ts +1 -1
- package/dist/esm/internal/metadata/index.d.ts +1 -1
- package/dist/esm/internal/plugins/index.d.ts +3 -3
- package/dist/esm/internal/plugins/safeGetHooks.d.ts +2 -2
- package/dist/esm/internal/plugins/safeGetName.d.ts +2 -2
- package/dist/esm/internal/plugins/safeRegisterPlugins.d.ts +2 -2
- package/dist/esm/logging/BasicLogger.d.ts +1 -1
- package/dist/esm/logging/SafeLogger.d.ts +1 -1
- package/dist/esm/logging/createSafeLogger.d.ts +3 -3
- package/dist/esm/logging/createSafeLogger.d.ts.map +1 -1
- package/dist/esm/logging/index.d.ts +3 -3
- package/dist/esm/options/ApplicationTags.d.ts +1 -1
- package/dist/esm/options/ClientContext.d.ts +3 -3
- package/dist/esm/options/index.d.ts +4 -4
- package/dist/esm/utils/cancelableTimedPromise.d.ts +1 -1
- package/dist/esm/utils/debounce.d.ts +1 -1
- package/dist/esm/utils/debounce.d.ts.map +1 -1
- package/dist/esm/utils/deepCompact.d.ts +1 -1
- package/dist/esm/utils/deepCompact.d.ts.map +1 -1
- package/dist/esm/utils/http.d.ts +2 -2
- package/dist/esm/utils/http.d.ts.map +1 -1
- package/dist/esm/utils/index.d.ts +12 -12
- package/dist/esm/utils/isEmptyObject.d.ts.map +1 -1
- package/dist/esm/utils/sleep.d.ts.map +1 -1
- package/dist/esm/utils/timedPromise.d.ts.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@launchdarkly/js-sdk-common` will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).
|
|
4
4
|
|
|
5
|
+
## [2.32.1](https://github.com/launchdarkly/js-core/compare/js-sdk-common-v2.32.0...js-sdk-common-v2.32.1) (2026-11-04)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **js-client-sdk:** better handling for event batches over 64 kb ([3a6c08a](https://github.com/launchdarkly/js-core/commit/3a6c08aa83b99f27dbbf08c6af458c675f1e1723))
|
|
11
|
+
|
|
12
|
+
## [2.32.0](https://github.com/launchdarkly/js-core/compare/js-sdk-common-v2.31.0...js-sdk-common-v2.32.0) (2026-10-27)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* Migrate the Node.js server and client SDKs to @launchdarkly/eventsource through the platform fetch ([10b57b0](https://github.com/launchdarkly/js-core/commit/10b57b01ce348b216fd98e515740bc5d50830017))
|
|
18
|
+
* Verify TLS certificates on streaming connections by default; a stream served by a private CA now requires tlsParams ([10b57b0](https://github.com/launchdarkly/js-core/commit/10b57b01ce348b216fd98e515740bc5d50830017))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* Allow polling and event delivery to connect through a proxy when a private CA is configured ([10b57b0](https://github.com/launchdarkly/js-core/commit/10b57b01ce348b216fd98e515740bc5d50830017))
|
|
24
|
+
* Ignore FDv2 put-object and delete-object events with unsupported kinds ([#2109](https://github.com/launchdarkly/js-core/issues/2109)) ([2729c04](https://github.com/launchdarkly/js-core/commit/2729c046493ba4c84ce0f4abf5be0b369d86c68c))
|
|
25
|
+
* Resolve types under node16/nodenext module resolution ([#2115](https://github.com/launchdarkly/js-core/issues/2115)) ([ca1613c](https://github.com/launchdarkly/js-core/commit/ca1613c20130b9308bafb8c98e0843d8d92fee01))
|
|
26
|
+
|
|
5
27
|
## [2.31.0](https://github.com/launchdarkly/js-core/compare/js-sdk-common-v2.30.0...js-sdk-common-v2.31.0) (2026-10-16)
|
|
6
28
|
|
|
7
29
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompositeDataSource.d.ts","sourceRoot":"","sources":["../../src/datasource/CompositeDataSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EACL,UAAU,EACV,eAAe,EACf,mBAAmB,EACpB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,OAAO,EAAkB,MAAM,WAAW,CAAC;AAOpD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,UAAU,GAAG,SAAS,GAAG,MAAM,CAAC;AAE1E;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;KAChC,CAAC,IAAI,eAAe,CAAC,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,UAAU,CAAA;KAAE;CACxE,CAAC;AAOF;;;GAGG;AACH,qBAAa,mBAAoB,YAAW,UAAU;IA8BlD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,qBAAqB;IAUtC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAtC3B,OAAO,CAAC,gBAAgB,CAAU;IAClC,OAAO,CAAC,cAAc,CAAsC;IAC5D,OAAO,CAAC,cAAc,CAAsC;IAC5D,OAAO,CAAC,kBAAkB,CAAsC;IAKhE,OAAO,CAAC,oBAAoB,CAAkB;IAE9C,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,0BAA0B,CAA6B;IAC/D,OAAO,CAAC,0BAA0B,CAAC,CAAqC;IACxE,OAAO,CAAC,aAAa,CAAsB;IAE3C;;;;;;;OAOG;gBAED,YAAY,EAAE,mBAAmB,EAAE,EACnC,aAAa,EAAE,mBAAmB,EAAE,EACpC,iBAAiB,EAAE,mBAAmB,EAAE,EACvB,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"CompositeDataSource.d.ts","sourceRoot":"","sources":["../../src/datasource/CompositeDataSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EACL,UAAU,EACV,eAAe,EACf,mBAAmB,EACpB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,OAAO,EAAkB,MAAM,WAAW,CAAC;AAOpD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,UAAU,GAAG,SAAS,GAAG,MAAM,CAAC;AAE1E;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;KAChC,CAAC,IAAI,eAAe,CAAC,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,UAAU,CAAA;KAAE;CACxE,CAAC;AAOF;;;GAGG;AACH,qBAAa,mBAAoB,YAAW,UAAU;IA8BlD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,qBAAqB;IAUtC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAtC3B,OAAO,CAAC,gBAAgB,CAAU;IAClC,OAAO,CAAC,cAAc,CAAsC;IAC5D,OAAO,CAAC,cAAc,CAAsC;IAC5D,OAAO,CAAC,kBAAkB,CAAsC;IAKhE,OAAO,CAAC,oBAAoB,CAAkB;IAE9C,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,0BAA0B,CAA6B;IAC/D,OAAO,CAAC,0BAA0B,CAAC,CAAqC;IACxE,OAAO,CAAC,aAAa,CAAsB;IAE3C;;;;;;;OAOG;gBAED,YAAY,EAAE,mBAAmB,EAAE,EACnC,aAAa,EAAE,mBAAmB,EAAE,EACpC,iBAAiB,EAAE,mBAAmB,EAAE,EACvB,OAAO,CAAC,EAAE,QAAQ,YAAA,EAClB,qBAAqB,GAAE,oBASvC,EACgB,QAAQ,GAAE,OAAyC;IAWhE,KAAK,CACT,YAAY,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,EACjD,cAAc,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,GAAG,CAAC,EAAE,GAAG,KAAK,IAAI,EAC5D,cAAc,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,GACxC,OAAO,CAAC,IAAI,CAAC;IAuMV,IAAI;IAMV,OAAO,CAAC,MAAM;IAad;;;;OAIG;IACH,OAAO,CAAC,eAAe;IA0DvB;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IAclC,OAAO,CAAC,iBAAiB,CAcvB;IAEF,OAAO,CAAC,mBAAmB;IAQ3B;;;;;;OAMG;IACH,OAAO,CAAC,gCAAgC;CAgCzC"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -2649,6 +2649,12 @@ class ClientMessages {
|
|
|
2649
2649
|
}
|
|
2650
2650
|
ClientMessages.MissingContextKeyNoEvent = 'Context was unspecified or had no key; event will not be sent';
|
|
2651
2651
|
|
|
2652
|
+
/**
|
|
2653
|
+
* The Fetch Standard caps the total body size of in-flight keepalive requests at 64 KiB. The
|
|
2654
|
+
* body length is in UTF-16 code units, and each code unit is at least one byte, so a body over
|
|
2655
|
+
* this length is always over the cap. A shorter body with non-ASCII text can still be over it.
|
|
2656
|
+
*/
|
|
2657
|
+
const KEEPALIVE_BODY_LIMIT = 64 * 1024;
|
|
2652
2658
|
class EventSender {
|
|
2653
2659
|
constructor(clientContext, baseHeaders) {
|
|
2654
2660
|
const { basicConfiguration, platform } = clientContext;
|
|
@@ -2674,14 +2680,17 @@ class EventSender {
|
|
|
2674
2680
|
}
|
|
2675
2681
|
let error;
|
|
2676
2682
|
try {
|
|
2683
|
+
const body = JSON.stringify(events);
|
|
2677
2684
|
const { status, headers: resHeaders } = await this._requests.fetch(uri, {
|
|
2678
2685
|
headers,
|
|
2679
|
-
body
|
|
2686
|
+
body,
|
|
2680
2687
|
compressBodyIfPossible: true,
|
|
2681
2688
|
method: 'POST',
|
|
2682
2689
|
// When sending events from browser environments the request should be completed even
|
|
2683
|
-
// if the user is navigating away from the page.
|
|
2684
|
-
|
|
2690
|
+
// if the user is navigating away from the page. A browser rejects a keepalive request
|
|
2691
|
+
// with a large body, so a large body is sent without it. The retry is the last attempt,
|
|
2692
|
+
// so it never asks for keepalive. This lets a body the length check missed get through.
|
|
2693
|
+
keepalive: canRetry && body.length <= KEEPALIVE_BODY_LIMIT,
|
|
2685
2694
|
});
|
|
2686
2695
|
const serverDate = Date.parse(resHeaders.get('date') || '');
|
|
2687
2696
|
if (serverDate) {
|
|
@@ -3400,6 +3409,11 @@ function createProtocolHandler(objProcessors, logger) {
|
|
|
3400
3409
|
let protocolState = 'inactive';
|
|
3401
3410
|
let tempType = 'partial';
|
|
3402
3411
|
let tempUpdates = [];
|
|
3412
|
+
// Only kinds with a registered processor are supported. An own-property check keeps
|
|
3413
|
+
// kinds such as 'constructor' from resolving to inherited members.
|
|
3414
|
+
function isSupportedKind(kind) {
|
|
3415
|
+
return Object.prototype.hasOwnProperty.call(objProcessors, kind);
|
|
3416
|
+
}
|
|
3403
3417
|
function processObj(kind, jsonObj) {
|
|
3404
3418
|
return objProcessors[kind]?.(jsonObj);
|
|
3405
3419
|
}
|
|
@@ -3470,6 +3484,12 @@ function createProtocolHandler(objProcessors, logger) {
|
|
|
3470
3484
|
logger?.warn(`Ignoring put-object with missing fields: kind=${data.kind}, key=${data.key}, version=${data.version}`);
|
|
3471
3485
|
return ACTION_NONE;
|
|
3472
3486
|
}
|
|
3487
|
+
// Objects of unsupported kinds are dropped silently so the protocol can add new kinds
|
|
3488
|
+
// without disrupting older SDKs.
|
|
3489
|
+
if (!isSupportedKind(data.kind)) {
|
|
3490
|
+
logger?.debug(`Ignoring put-object with unsupported kind: '${data.kind}'`);
|
|
3491
|
+
return ACTION_NONE;
|
|
3492
|
+
}
|
|
3473
3493
|
const obj = processObj(data.kind, data.object);
|
|
3474
3494
|
if (!obj) {
|
|
3475
3495
|
logger?.warn(`Unable to process object for kind: '${data.kind}'`);
|
|
@@ -3492,6 +3512,10 @@ function createProtocolHandler(objProcessors, logger) {
|
|
|
3492
3512
|
logger?.warn(`Ignoring delete-object with missing fields: kind=${data.kind}, key=${data.key}, version=${data.version}`);
|
|
3493
3513
|
return ACTION_NONE;
|
|
3494
3514
|
}
|
|
3515
|
+
if (!isSupportedKind(data.kind)) {
|
|
3516
|
+
logger?.debug(`Ignoring delete-object with unsupported kind: '${data.kind}'`);
|
|
3517
|
+
return ACTION_NONE;
|
|
3518
|
+
}
|
|
3495
3519
|
tempUpdates.push({
|
|
3496
3520
|
kind: data.kind,
|
|
3497
3521
|
key: data.key,
|
|
@@ -3674,6 +3698,74 @@ class PayloadStreamReader {
|
|
|
3674
3698
|
}
|
|
3675
3699
|
}
|
|
3676
3700
|
|
|
3701
|
+
/**
|
|
3702
|
+
* The most redirect hops one streaming request follows. When a chain exceeds the cap, the last
|
|
3703
|
+
* redirect response goes to the caller as an ordinary non-200 response. The caller's error
|
|
3704
|
+
* handling decides whether to retry.
|
|
3705
|
+
*/
|
|
3706
|
+
const MAX_STREAMING_REDIRECT_HOPS = 5;
|
|
3707
|
+
/**
|
|
3708
|
+
* Resolves the target of a redirect response. The target can be relative, and it resolves
|
|
3709
|
+
* against the URL of the redirected request. Only an `http:` or `https:` target can carry
|
|
3710
|
+
* the stream; any other scheme, a missing or empty `Location`, and an unparsable value all
|
|
3711
|
+
* resolve to `undefined`, and the redirect response then goes to the caller unfollowed.
|
|
3712
|
+
*/
|
|
3713
|
+
function redirectTarget(headers, baseUrl) {
|
|
3714
|
+
const raw = headers.location;
|
|
3715
|
+
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
3716
|
+
if (typeof value !== 'string' || value === '') {
|
|
3717
|
+
return undefined;
|
|
3718
|
+
}
|
|
3719
|
+
try {
|
|
3720
|
+
const resolved = new URL(value, baseUrl);
|
|
3721
|
+
if (resolved.protocol !== 'http:' && resolved.protocol !== 'https:') {
|
|
3722
|
+
return undefined;
|
|
3723
|
+
}
|
|
3724
|
+
return resolved.href;
|
|
3725
|
+
}
|
|
3726
|
+
catch {
|
|
3727
|
+
return undefined;
|
|
3728
|
+
}
|
|
3729
|
+
}
|
|
3730
|
+
/**
|
|
3731
|
+
* Issues a streaming request and follows up to {@link MAX_STREAMING_REDIRECT_HOPS} hops of
|
|
3732
|
+
* `301` and `307` redirects. Each hop calls `doRequest` again with the target URL, so the
|
|
3733
|
+
* request carries the same method, body, and headers to each target, the `Authorization`
|
|
3734
|
+
* header included. A `302` and every other status return to the caller unfollowed.
|
|
3735
|
+
*
|
|
3736
|
+
* The loop holds no state across calls. A reconnect starts from the original URL again and
|
|
3737
|
+
* re-follows the chain.
|
|
3738
|
+
*
|
|
3739
|
+
* @param url The URL of the initial request.
|
|
3740
|
+
* @param doRequest Issues one request and resolves with its response. The caller builds the
|
|
3741
|
+
* options inside it from the given URL, so each hop gets options for its own target.
|
|
3742
|
+
*/
|
|
3743
|
+
async function followStreamingRedirects(url, doRequest) {
|
|
3744
|
+
let currentUrl = url;
|
|
3745
|
+
let res = await doRequest(currentUrl);
|
|
3746
|
+
let hops = 0;
|
|
3747
|
+
while ((res.statusCode === 301 || res.statusCode === 307) && hops < MAX_STREAMING_REDIRECT_HOPS) {
|
|
3748
|
+
const target = redirectTarget(res.headers, currentUrl);
|
|
3749
|
+
if (target === undefined) {
|
|
3750
|
+
return res;
|
|
3751
|
+
}
|
|
3752
|
+
hops += 1;
|
|
3753
|
+
// The destroy releases the skipped redirect response and its connection at once, so a
|
|
3754
|
+
// redirect body that never ends cannot hold a socket for the life of the attempt.
|
|
3755
|
+
try {
|
|
3756
|
+
res.destroy?.();
|
|
3757
|
+
}
|
|
3758
|
+
catch {
|
|
3759
|
+
// A throwing destroy has nothing left to release.
|
|
3760
|
+
}
|
|
3761
|
+
currentUrl = target;
|
|
3762
|
+
// The hops are sequential. The next request cannot start until this response arrives.
|
|
3763
|
+
// eslint-disable-next-line no-await-in-loop
|
|
3764
|
+
res = await doRequest(currentUrl);
|
|
3765
|
+
}
|
|
3766
|
+
return res;
|
|
3767
|
+
}
|
|
3768
|
+
|
|
3677
3769
|
/**
|
|
3678
3770
|
* Wraps the raw headers in the fetch `Headers` shape. Lookups are case-insensitive.
|
|
3679
3771
|
* Multi-value headers are joined with ", ", names that differ only by case merge into one
|
|
@@ -3874,12 +3966,14 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
3874
3966
|
InputCustomEvent: InputCustomEvent,
|
|
3875
3967
|
InputEvalEvent: InputEvalEvent,
|
|
3876
3968
|
InputIdentifyEvent: InputIdentifyEvent,
|
|
3969
|
+
MAX_STREAMING_REDIRECT_HOPS: MAX_STREAMING_REDIRECT_HOPS,
|
|
3877
3970
|
NullEventProcessor: NullEventProcessor,
|
|
3878
3971
|
PayloadProcessor: PayloadProcessor,
|
|
3879
3972
|
PayloadStreamReader: PayloadStreamReader,
|
|
3880
3973
|
canonicalize: canonicalize,
|
|
3881
3974
|
createProtocolHandler: createProtocolHandler,
|
|
3882
3975
|
createStreamingResponse: createStreamingResponse,
|
|
3976
|
+
followStreamingRedirects: followStreamingRedirects,
|
|
3883
3977
|
initMetadataFromHeaders: initMetadataFromHeaders,
|
|
3884
3978
|
isLegacyUser: isLegacyUser,
|
|
3885
3979
|
isMultiKind: isMultiKind,
|