@launchdarkly/js-sdk-common 2.31.0 → 2.32.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 +15 -0
- package/dist/cjs/index.cjs +85 -0
- package/dist/cjs/index.cjs.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/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/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 +85 -0
- 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/EventSender.d.ts +3 -3
- package/dist/esm/internal/events/InputClickEvent.d.ts +1 -1
- package/dist/esm/internal/events/InputCustomEvent.d.ts +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/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/payloadStreamReader.d.ts +3 -3
- 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/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/http.d.ts +2 -2
- package/dist/esm/utils/index.d.ts +12 -12
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { LDMultiKindContext } from './LDMultiKindContext';
|
|
2
|
-
import { LDSingleKindContext } from './LDSingleKindContext';
|
|
3
|
-
import { LDUser } from './LDUser';
|
|
1
|
+
import { LDMultiKindContext } from './LDMultiKindContext.js';
|
|
2
|
+
import { LDSingleKindContext } from './LDSingleKindContext.js';
|
|
3
|
+
import { LDUser } from './LDUser.js';
|
|
4
4
|
/**
|
|
5
5
|
* A LaunchDarkly context object. LaunchDarkly contexts are objects representing users, devices, organizations, and
|
|
6
6
|
* other entities that feature flags serve different variations to according to your flag targeting rules. These data
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './LDContextCommon';
|
|
2
|
-
export * from './LDContextMeta';
|
|
3
|
-
export * from './LDMultiKindContext';
|
|
4
|
-
export * from './LDSingleKindContext';
|
|
5
|
-
export * from './LDUser';
|
|
6
|
-
export * from './LDContext';
|
|
1
|
+
export * from './LDContextCommon.js';
|
|
2
|
+
export * from './LDContextMeta.js';
|
|
3
|
+
export * from './LDMultiKindContext.js';
|
|
4
|
+
export * from './LDSingleKindContext.js';
|
|
5
|
+
export * from './LDUser.js';
|
|
6
|
+
export * from './LDContext.js';
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LDEvaluationReason } from './LDEvaluationReason';
|
|
2
|
-
import { LDFlagValue } from './LDFlagValue';
|
|
1
|
+
import { LDEvaluationReason } from './LDEvaluationReason.js';
|
|
2
|
+
import { LDFlagValue } from './LDFlagValue.js';
|
|
3
3
|
/**
|
|
4
4
|
* An object that combines the result of a feature flag evaluation with information about
|
|
5
5
|
* how it was calculated.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './LDEvaluationDetail';
|
|
2
|
-
export * from './LDEvaluationReason';
|
|
3
|
-
export * from './LDFlagSet';
|
|
4
|
-
export * from './LDFlagValue';
|
|
1
|
+
export * from './LDEvaluationDetail.js';
|
|
2
|
+
export * from './LDEvaluationReason.js';
|
|
3
|
+
export * from './LDFlagSet.js';
|
|
4
|
+
export * from './LDFlagValue.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/api/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './context';
|
|
2
|
-
export * from './logging';
|
|
3
|
-
export * from './data';
|
|
4
|
-
export * from './options';
|
|
5
|
-
export * from './platform';
|
|
6
|
-
export * as subsystem from './subsystem';
|
|
7
|
-
export * from './integrations';
|
|
1
|
+
export * from './context/index.js';
|
|
2
|
+
export * from './logging/index.js';
|
|
3
|
+
export * from './data/index.js';
|
|
4
|
+
export * from './options/index.js';
|
|
5
|
+
export * from './platform/index.js';
|
|
6
|
+
export * as subsystem from './subsystem/index.js';
|
|
7
|
+
export * from './integrations/index.js';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './plugins';
|
|
1
|
+
export * from './plugins.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './BasicLoggerOptions';
|
|
2
|
-
export * from './LDLogger';
|
|
3
|
-
export * from './LDLogLevel';
|
|
1
|
+
export * from './BasicLoggerOptions.js';
|
|
2
|
+
export * from './LDLogger.js';
|
|
3
|
+
export * from './LDLogLevel.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Crypto } from './Crypto';
|
|
2
|
-
import { Encoding } from './Encoding';
|
|
3
|
-
import { Filesystem } from './Filesystem';
|
|
4
|
-
import { Info } from './Info';
|
|
5
|
-
import { Requests } from './Requests';
|
|
6
|
-
import { Storage } from './Storage';
|
|
1
|
+
import { Crypto } from './Crypto.js';
|
|
2
|
+
import { Encoding } from './Encoding.js';
|
|
3
|
+
import { Filesystem } from './Filesystem.js';
|
|
4
|
+
import { Info } from './Info.js';
|
|
5
|
+
import { Requests } from './Requests.js';
|
|
6
|
+
import { Storage } from './Storage.js';
|
|
7
7
|
export interface Platform {
|
|
8
8
|
/**
|
|
9
9
|
* The interface for performing encoding operations.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from './AutoEnv';
|
|
2
|
-
export * from './Crypto';
|
|
3
|
-
export * from './Encoding';
|
|
4
|
-
export * from './EventSource';
|
|
5
|
-
export * from './Filesystem';
|
|
6
|
-
export * from './Info';
|
|
7
|
-
export * from './Platform';
|
|
8
|
-
export * from './Requests';
|
|
9
|
-
export * from './Storage';
|
|
1
|
+
export * from './AutoEnv.js';
|
|
2
|
+
export * from './Crypto.js';
|
|
3
|
+
export * from './Encoding.js';
|
|
4
|
+
export * from './EventSource.js';
|
|
5
|
+
export * from './Filesystem.js';
|
|
6
|
+
export * from './Info.js';
|
|
7
|
+
export * from './Platform.js';
|
|
8
|
+
export * from './Requests.js';
|
|
9
|
+
export * from './Storage.js';
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataSourceState } from './DataSource';
|
|
1
|
+
import { DataSourceState } from './DataSource.js';
|
|
2
2
|
/**
|
|
3
3
|
* Handler that connects the current {@link DataSource} to the {@link CompositeDataSource}. A single
|
|
4
4
|
* {@link CallbackHandler} should only be given to one {@link DataSource}. Use {@link disable()} to
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { DataSource, DataSourceState, LDDataSourceFactory } from './DataSource';
|
|
1
|
+
export { DataSource, DataSourceState, LDDataSourceFactory } from './DataSource.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DataSource, DataSourceState, LDDataSourceFactory } from './DataSystem';
|
|
2
|
-
import LDContextDeduplicator from './LDContextDeduplicator';
|
|
3
|
-
import LDEventProcessor from './LDEventProcessor';
|
|
4
|
-
import LDEventSender, { LDDeliveryStatus, LDEventSenderResult, LDEventType } from './LDEventSender';
|
|
5
|
-
import { LDStreamProcessor } from './LDStreamProcessor';
|
|
1
|
+
import { DataSource, DataSourceState, LDDataSourceFactory } from './DataSystem/index.js';
|
|
2
|
+
import LDContextDeduplicator from './LDContextDeduplicator.js';
|
|
3
|
+
import LDEventProcessor from './LDEventProcessor.js';
|
|
4
|
+
import LDEventSender, { LDDeliveryStatus, LDEventSenderResult, LDEventType } from './LDEventSender.js';
|
|
5
|
+
import { LDStreamProcessor } from './LDStreamProcessor.js';
|
|
6
6
|
export { DataSource, DataSourceState, LDDataSourceFactory, LDEventProcessor, LDContextDeduplicator, LDEventSender, LDDeliveryStatus, LDEventType, LDEventSenderResult, LDStreamProcessor, };
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { LDLogger } from '../api/logging';
|
|
2
|
-
import { DataSource, DataSourceState, LDDataSourceFactory } from '../api/subsystem/DataSystem/DataSource';
|
|
3
|
-
import { Backoff } from './Backoff';
|
|
1
|
+
import { LDLogger } from '../api/logging/index.js';
|
|
2
|
+
import { DataSource, DataSourceState, LDDataSourceFactory } from '../api/subsystem/DataSystem/DataSource.js';
|
|
3
|
+
import { Backoff } from './Backoff.js';
|
|
4
4
|
/**
|
|
5
5
|
* Represents a transition between data sources.
|
|
6
6
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Backoff, DefaultBackoff } from './Backoff';
|
|
2
|
-
import { CompositeDataSource } from './CompositeDataSource';
|
|
3
|
-
import { DataSourceErrorKind } from './DataSourceErrorKinds';
|
|
4
|
-
import { LDFileDataSourceError, LDFlagDeliveryFallbackError, LDPollingError, LDStreamingError, StreamingErrorHandler } from './errors';
|
|
5
|
-
import { createAfterConsecutiveSuccesses, createAfterHealthyFor, createRetryState, forPolling, forStreaming, ResetPolicy, RetryState, RetryStateConfig } from './retry';
|
|
1
|
+
import { Backoff, DefaultBackoff } from './Backoff.js';
|
|
2
|
+
import { CompositeDataSource } from './CompositeDataSource.js';
|
|
3
|
+
import { DataSourceErrorKind } from './DataSourceErrorKinds.js';
|
|
4
|
+
import { LDFileDataSourceError, LDFlagDeliveryFallbackError, LDPollingError, LDStreamingError, StreamingErrorHandler } from './errors.js';
|
|
5
|
+
import { createAfterConsecutiveSuccesses, createAfterHealthyFor, createRetryState, forPolling, forStreaming, ResetPolicy, RetryState, RetryStateConfig } from './retry/index.js';
|
|
6
6
|
export { Backoff, CompositeDataSource, createAfterConsecutiveSuccesses, createAfterHealthyFor, createRetryState, DefaultBackoff, DataSourceErrorKind, forPolling, forStreaming, LDFileDataSourceError, LDFlagDeliveryFallbackError, LDPollingError, LDStreamingError, ResetPolicy, RetryState, RetryStateConfig, StreamingErrorHandler, };
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { LDLogger } from '../../api/logging/LDLogger';
|
|
2
|
-
import { FailureKind } from '../../errors';
|
|
3
|
-
import { ResetPolicy } from './ResetPolicy';
|
|
1
|
+
import { LDLogger } from '../../api/logging/LDLogger.js';
|
|
2
|
+
import { FailureKind } from '../../errors.js';
|
|
3
|
+
import { ResetPolicy } from './ResetPolicy.js';
|
|
4
4
|
/**
|
|
5
5
|
* Configuration for a {@link RetryState}.
|
|
6
6
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createAfterConsecutiveSuccesses, createAfterHealthyFor, ResetPolicy } from './ResetPolicy';
|
|
2
|
-
import { createRetryState, forPolling, forStreaming, RetryState, RetryStateConfig } from './RetryState';
|
|
1
|
+
import { createAfterConsecutiveSuccesses, createAfterHealthyFor, ResetPolicy } from './ResetPolicy.js';
|
|
2
|
+
import { createRetryState, forPolling, forStreaming, RetryState, RetryStateConfig } from './RetryState.js';
|
|
3
3
|
export { createAfterConsecutiveSuccesses, createAfterHealthyFor, createRetryState, forPolling, forStreaming, ResetPolicy, RetryState, RetryStateConfig, };
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import AttributeReference from './AttributeReference';
|
|
2
|
-
import Context from './Context';
|
|
3
|
-
import ContextFilter from './ContextFilter';
|
|
4
|
-
import { Backoff, CompositeDataSource, createAfterConsecutiveSuccesses, createAfterHealthyFor, createRetryState, DataSourceErrorKind, DefaultBackoff, forPolling, forStreaming, LDFileDataSourceError, LDFlagDeliveryFallbackError, LDPollingError, LDStreamingError, ResetPolicy, RetryState, RetryStateConfig, StreamingErrorHandler } from './datasource';
|
|
5
|
-
export * from './api';
|
|
6
|
-
export * from './validators';
|
|
7
|
-
export * from './logging';
|
|
8
|
-
export * from './options';
|
|
9
|
-
export * from './utils';
|
|
10
|
-
export * as internal from './internal';
|
|
11
|
-
export * from './errors';
|
|
1
|
+
import AttributeReference from './AttributeReference.js';
|
|
2
|
+
import Context from './Context.js';
|
|
3
|
+
import ContextFilter from './ContextFilter.js';
|
|
4
|
+
import { Backoff, CompositeDataSource, createAfterConsecutiveSuccesses, createAfterHealthyFor, createRetryState, DataSourceErrorKind, DefaultBackoff, forPolling, forStreaming, LDFileDataSourceError, LDFlagDeliveryFallbackError, LDPollingError, LDStreamingError, ResetPolicy, RetryState, RetryStateConfig, StreamingErrorHandler } from './datasource/index.js';
|
|
5
|
+
export * from './api/index.js';
|
|
6
|
+
export * from './validators.js';
|
|
7
|
+
export * from './logging/index.js';
|
|
8
|
+
export * from './options/index.js';
|
|
9
|
+
export * from './utils/index.js';
|
|
10
|
+
export * as internal from './internal/index.js';
|
|
11
|
+
export * from './errors.js';
|
|
12
12
|
export { AttributeReference, Context, ContextFilter, CompositeDataSource, DataSourceErrorKind, Backoff, DefaultBackoff, LDPollingError, LDStreamingError, StreamingErrorHandler, LDFileDataSourceError, LDFlagDeliveryFallbackError, createAfterConsecutiveSuccesses, createAfterHealthyFor, createRetryState, forPolling, forStreaming, ResetPolicy, RetryState, RetryStateConfig, };
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.mjs
CHANGED
|
@@ -3398,6 +3398,11 @@ function createProtocolHandler(objProcessors, logger) {
|
|
|
3398
3398
|
let protocolState = 'inactive';
|
|
3399
3399
|
let tempType = 'partial';
|
|
3400
3400
|
let tempUpdates = [];
|
|
3401
|
+
// Only kinds with a registered processor are supported. An own-property check keeps
|
|
3402
|
+
// kinds such as 'constructor' from resolving to inherited members.
|
|
3403
|
+
function isSupportedKind(kind) {
|
|
3404
|
+
return Object.prototype.hasOwnProperty.call(objProcessors, kind);
|
|
3405
|
+
}
|
|
3401
3406
|
function processObj(kind, jsonObj) {
|
|
3402
3407
|
return objProcessors[kind]?.(jsonObj);
|
|
3403
3408
|
}
|
|
@@ -3468,6 +3473,12 @@ function createProtocolHandler(objProcessors, logger) {
|
|
|
3468
3473
|
logger?.warn(`Ignoring put-object with missing fields: kind=${data.kind}, key=${data.key}, version=${data.version}`);
|
|
3469
3474
|
return ACTION_NONE;
|
|
3470
3475
|
}
|
|
3476
|
+
// Objects of unsupported kinds are dropped silently so the protocol can add new kinds
|
|
3477
|
+
// without disrupting older SDKs.
|
|
3478
|
+
if (!isSupportedKind(data.kind)) {
|
|
3479
|
+
logger?.debug(`Ignoring put-object with unsupported kind: '${data.kind}'`);
|
|
3480
|
+
return ACTION_NONE;
|
|
3481
|
+
}
|
|
3471
3482
|
const obj = processObj(data.kind, data.object);
|
|
3472
3483
|
if (!obj) {
|
|
3473
3484
|
logger?.warn(`Unable to process object for kind: '${data.kind}'`);
|
|
@@ -3490,6 +3501,10 @@ function createProtocolHandler(objProcessors, logger) {
|
|
|
3490
3501
|
logger?.warn(`Ignoring delete-object with missing fields: kind=${data.kind}, key=${data.key}, version=${data.version}`);
|
|
3491
3502
|
return ACTION_NONE;
|
|
3492
3503
|
}
|
|
3504
|
+
if (!isSupportedKind(data.kind)) {
|
|
3505
|
+
logger?.debug(`Ignoring delete-object with unsupported kind: '${data.kind}'`);
|
|
3506
|
+
return ACTION_NONE;
|
|
3507
|
+
}
|
|
3493
3508
|
tempUpdates.push({
|
|
3494
3509
|
kind: data.kind,
|
|
3495
3510
|
key: data.key,
|
|
@@ -3672,6 +3687,74 @@ class PayloadStreamReader {
|
|
|
3672
3687
|
}
|
|
3673
3688
|
}
|
|
3674
3689
|
|
|
3690
|
+
/**
|
|
3691
|
+
* The most redirect hops one streaming request follows. When a chain exceeds the cap, the last
|
|
3692
|
+
* redirect response goes to the caller as an ordinary non-200 response. The caller's error
|
|
3693
|
+
* handling decides whether to retry.
|
|
3694
|
+
*/
|
|
3695
|
+
const MAX_STREAMING_REDIRECT_HOPS = 5;
|
|
3696
|
+
/**
|
|
3697
|
+
* Resolves the target of a redirect response. The target can be relative, and it resolves
|
|
3698
|
+
* against the URL of the redirected request. Only an `http:` or `https:` target can carry
|
|
3699
|
+
* the stream; any other scheme, a missing or empty `Location`, and an unparsable value all
|
|
3700
|
+
* resolve to `undefined`, and the redirect response then goes to the caller unfollowed.
|
|
3701
|
+
*/
|
|
3702
|
+
function redirectTarget(headers, baseUrl) {
|
|
3703
|
+
const raw = headers.location;
|
|
3704
|
+
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
3705
|
+
if (typeof value !== 'string' || value === '') {
|
|
3706
|
+
return undefined;
|
|
3707
|
+
}
|
|
3708
|
+
try {
|
|
3709
|
+
const resolved = new URL(value, baseUrl);
|
|
3710
|
+
if (resolved.protocol !== 'http:' && resolved.protocol !== 'https:') {
|
|
3711
|
+
return undefined;
|
|
3712
|
+
}
|
|
3713
|
+
return resolved.href;
|
|
3714
|
+
}
|
|
3715
|
+
catch {
|
|
3716
|
+
return undefined;
|
|
3717
|
+
}
|
|
3718
|
+
}
|
|
3719
|
+
/**
|
|
3720
|
+
* Issues a streaming request and follows up to {@link MAX_STREAMING_REDIRECT_HOPS} hops of
|
|
3721
|
+
* `301` and `307` redirects. Each hop calls `doRequest` again with the target URL, so the
|
|
3722
|
+
* request carries the same method, body, and headers to each target, the `Authorization`
|
|
3723
|
+
* header included. A `302` and every other status return to the caller unfollowed.
|
|
3724
|
+
*
|
|
3725
|
+
* The loop holds no state across calls. A reconnect starts from the original URL again and
|
|
3726
|
+
* re-follows the chain.
|
|
3727
|
+
*
|
|
3728
|
+
* @param url The URL of the initial request.
|
|
3729
|
+
* @param doRequest Issues one request and resolves with its response. The caller builds the
|
|
3730
|
+
* options inside it from the given URL, so each hop gets options for its own target.
|
|
3731
|
+
*/
|
|
3732
|
+
async function followStreamingRedirects(url, doRequest) {
|
|
3733
|
+
let currentUrl = url;
|
|
3734
|
+
let res = await doRequest(currentUrl);
|
|
3735
|
+
let hops = 0;
|
|
3736
|
+
while ((res.statusCode === 301 || res.statusCode === 307) && hops < MAX_STREAMING_REDIRECT_HOPS) {
|
|
3737
|
+
const target = redirectTarget(res.headers, currentUrl);
|
|
3738
|
+
if (target === undefined) {
|
|
3739
|
+
return res;
|
|
3740
|
+
}
|
|
3741
|
+
hops += 1;
|
|
3742
|
+
// The destroy releases the skipped redirect response and its connection at once, so a
|
|
3743
|
+
// redirect body that never ends cannot hold a socket for the life of the attempt.
|
|
3744
|
+
try {
|
|
3745
|
+
res.destroy?.();
|
|
3746
|
+
}
|
|
3747
|
+
catch {
|
|
3748
|
+
// A throwing destroy has nothing left to release.
|
|
3749
|
+
}
|
|
3750
|
+
currentUrl = target;
|
|
3751
|
+
// The hops are sequential. The next request cannot start until this response arrives.
|
|
3752
|
+
// eslint-disable-next-line no-await-in-loop
|
|
3753
|
+
res = await doRequest(currentUrl);
|
|
3754
|
+
}
|
|
3755
|
+
return res;
|
|
3756
|
+
}
|
|
3757
|
+
|
|
3675
3758
|
/**
|
|
3676
3759
|
* Wraps the raw headers in the fetch `Headers` shape. Lookups are case-insensitive.
|
|
3677
3760
|
* Multi-value headers are joined with ", ", names that differ only by case merge into one
|
|
@@ -3872,12 +3955,14 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
3872
3955
|
InputCustomEvent: InputCustomEvent,
|
|
3873
3956
|
InputEvalEvent: InputEvalEvent,
|
|
3874
3957
|
InputIdentifyEvent: InputIdentifyEvent,
|
|
3958
|
+
MAX_STREAMING_REDIRECT_HOPS: MAX_STREAMING_REDIRECT_HOPS,
|
|
3875
3959
|
NullEventProcessor: NullEventProcessor,
|
|
3876
3960
|
PayloadProcessor: PayloadProcessor,
|
|
3877
3961
|
PayloadStreamReader: PayloadStreamReader,
|
|
3878
3962
|
canonicalize: canonicalize,
|
|
3879
3963
|
createProtocolHandler: createProtocolHandler,
|
|
3880
3964
|
createStreamingResponse: createStreamingResponse,
|
|
3965
|
+
followStreamingRedirects: followStreamingRedirects,
|
|
3881
3966
|
initMetadataFromHeaders: initMetadataFromHeaders,
|
|
3882
3967
|
isLegacyUser: isLegacyUser,
|
|
3883
3968
|
isMultiKind: isMultiKind,
|