@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.
Files changed (93) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/index.cjs +85 -0
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs/internal/fdv2/protocolHandler.d.ts.map +1 -1
  5. package/dist/cjs/internal/fetch/followRedirects.d.ts +34 -0
  6. package/dist/cjs/internal/fetch/followRedirects.d.ts.map +1 -0
  7. package/dist/cjs/internal/fetch/index.d.ts +1 -0
  8. package/dist/cjs/internal/fetch/index.d.ts.map +1 -1
  9. package/dist/esm/AttributeReference.d.ts +1 -1
  10. package/dist/esm/Context.d.ts +2 -2
  11. package/dist/esm/ContextFilter.d.ts +2 -2
  12. package/dist/esm/api/context/LDContext.d.ts +3 -3
  13. package/dist/esm/api/context/LDContextCommon.d.ts +1 -1
  14. package/dist/esm/api/context/LDMultiKindContext.d.ts +1 -1
  15. package/dist/esm/api/context/LDSingleKindContext.d.ts +1 -1
  16. package/dist/esm/api/context/index.d.ts +6 -6
  17. package/dist/esm/api/data/LDEvaluationDetail.d.ts +2 -2
  18. package/dist/esm/api/data/LDFlagSet.d.ts +1 -1
  19. package/dist/esm/api/data/index.d.ts +4 -4
  20. package/dist/esm/api/index.d.ts +7 -7
  21. package/dist/esm/api/integrations/index.d.ts +1 -1
  22. package/dist/esm/api/logging/BasicLoggerOptions.d.ts +1 -1
  23. package/dist/esm/api/logging/index.d.ts +3 -3
  24. package/dist/esm/api/options/LDClientContext.d.ts +2 -2
  25. package/dist/esm/api/options/index.d.ts +1 -1
  26. package/dist/esm/api/platform/EventSource.d.ts +1 -1
  27. package/dist/esm/api/platform/Info.d.ts +1 -1
  28. package/dist/esm/api/platform/Platform.d.ts +6 -6
  29. package/dist/esm/api/platform/Requests.d.ts +1 -1
  30. package/dist/esm/api/platform/index.d.ts +9 -9
  31. package/dist/esm/api/subsystem/DataSystem/CallbackHandler.d.ts +1 -1
  32. package/dist/esm/api/subsystem/DataSystem/index.d.ts +1 -1
  33. package/dist/esm/api/subsystem/LDContextDeduplicator.d.ts +1 -1
  34. package/dist/esm/api/subsystem/LDEventProcessor.d.ts +1 -1
  35. package/dist/esm/api/subsystem/index.d.ts +5 -5
  36. package/dist/esm/datasource/CompositeDataSource.d.ts +3 -3
  37. package/dist/esm/datasource/errors.d.ts +1 -1
  38. package/dist/esm/datasource/index.d.ts +5 -5
  39. package/dist/esm/datasource/retry/RetryState.d.ts +3 -3
  40. package/dist/esm/datasource/retry/index.d.ts +2 -2
  41. package/dist/esm/index.d.ts +11 -11
  42. package/dist/esm/index.mjs +85 -0
  43. package/dist/esm/index.mjs.map +1 -1
  44. package/dist/esm/internal/context/index.d.ts +1 -1
  45. package/dist/esm/internal/diagnostics/DiagnosticsManager.d.ts +2 -2
  46. package/dist/esm/internal/diagnostics/index.d.ts +1 -1
  47. package/dist/esm/internal/evaluation/EventFactoryBase.d.ts +3 -3
  48. package/dist/esm/internal/evaluation/index.d.ts +2 -2
  49. package/dist/esm/internal/events/EventProcessor.d.ts +6 -6
  50. package/dist/esm/internal/events/EventSender.d.ts +3 -3
  51. package/dist/esm/internal/events/InputClickEvent.d.ts +1 -1
  52. package/dist/esm/internal/events/InputCustomEvent.d.ts +1 -1
  53. package/dist/esm/internal/events/InputEvalEvent.d.ts +2 -2
  54. package/dist/esm/internal/events/InputEvent.d.ts +6 -6
  55. package/dist/esm/internal/events/InputEventBase.d.ts +1 -1
  56. package/dist/esm/internal/events/InputIdentifyEvent.d.ts +1 -1
  57. package/dist/esm/internal/events/InputMigrationEvent.d.ts +1 -1
  58. package/dist/esm/internal/events/InputPageViewEvent.d.ts +1 -1
  59. package/dist/esm/internal/events/LDEventSummarizer.d.ts +1 -1
  60. package/dist/esm/internal/events/MultiEventSummarizer.d.ts +4 -4
  61. package/dist/esm/internal/events/NullEventProcessor.d.ts +1 -1
  62. package/dist/esm/internal/events/guards.d.ts +4 -4
  63. package/dist/esm/internal/events/index.d.ts +10 -10
  64. package/dist/esm/internal/fdv2/FDv1PayloadAdaptor.d.ts +1 -1
  65. package/dist/esm/internal/fdv2/index.d.ts +8 -8
  66. package/dist/esm/internal/fdv2/payloadProcessor.d.ts +4 -4
  67. package/dist/esm/internal/fdv2/payloadStreamReader.d.ts +3 -3
  68. package/dist/esm/internal/fdv2/protocolHandler.d.ts +2 -2
  69. package/dist/esm/internal/fdv2/protocolHandler.d.ts.map +1 -1
  70. package/dist/esm/internal/fetch/StreamingResponse.d.ts +1 -1
  71. package/dist/esm/internal/fetch/followRedirects.d.ts +34 -0
  72. package/dist/esm/internal/fetch/followRedirects.d.ts.map +1 -0
  73. package/dist/esm/internal/fetch/index.d.ts +3 -2
  74. package/dist/esm/internal/fetch/index.d.ts.map +1 -1
  75. package/dist/esm/internal/fetch/toRequestInit.d.ts +1 -1
  76. package/dist/esm/internal/index.d.ts +9 -9
  77. package/dist/esm/internal/json/index.d.ts +1 -1
  78. package/dist/esm/internal/metadata/index.d.ts +1 -1
  79. package/dist/esm/internal/plugins/index.d.ts +3 -3
  80. package/dist/esm/internal/plugins/safeGetHooks.d.ts +2 -2
  81. package/dist/esm/internal/plugins/safeGetName.d.ts +2 -2
  82. package/dist/esm/internal/plugins/safeRegisterPlugins.d.ts +2 -2
  83. package/dist/esm/logging/BasicLogger.d.ts +1 -1
  84. package/dist/esm/logging/SafeLogger.d.ts +1 -1
  85. package/dist/esm/logging/createSafeLogger.d.ts +3 -3
  86. package/dist/esm/logging/index.d.ts +3 -3
  87. package/dist/esm/options/ApplicationTags.d.ts +1 -1
  88. package/dist/esm/options/ClientContext.d.ts +3 -3
  89. package/dist/esm/options/index.d.ts +4 -4
  90. package/dist/esm/utils/cancelableTimedPromise.d.ts +1 -1
  91. package/dist/esm/utils/http.d.ts +2 -2
  92. package/dist/esm/utils/index.d.ts +12 -12
  93. 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,4 +1,4 @@
1
- import { LDContextMeta } from './LDContextMeta';
1
+ import { LDContextMeta } from './LDContextMeta.js';
2
2
  /**
3
3
  * Common attributes shared by the various context types.
4
4
  */
@@ -1,4 +1,4 @@
1
- import { LDContextCommon } from './LDContextCommon';
1
+ import { LDContextCommon } from './LDContextCommon.js';
2
2
  /**
3
3
  * A context which represents multiple kinds. Each kind having its own key and attributes.
4
4
  *
@@ -1,4 +1,4 @@
1
- import { LDContextCommon } from './LDContextCommon';
1
+ import { LDContextCommon } from './LDContextCommon.js';
2
2
  /**
3
3
  * A context which represents a single kind.
4
4
  *
@@ -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,4 +1,4 @@
1
- import { LDFlagValue } from './LDFlagValue';
1
+ import { LDFlagValue } from './LDFlagValue.js';
2
2
  /**
3
3
  * A map of feature flags from their keys to their values.
4
4
  */
@@ -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
@@ -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
- import { LDLogLevel } from './LDLogLevel';
1
+ import { LDLogLevel } from './LDLogLevel.js';
2
2
  /**
3
3
  * Configuration for {@link basicLogger}.
4
4
  */
@@ -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,5 +1,5 @@
1
- import { LDLogger } from '../logging';
2
- import { Platform } from '../platform';
1
+ import { LDLogger } from '../logging/index.js';
2
+ import { Platform } from '../platform/index.js';
3
3
  /**
4
4
  * Specifies the base service URIs used by SDK components.
5
5
  */
@@ -1,3 +1,3 @@
1
- import { LDClientContext } from './LDClientContext';
1
+ import { LDClientContext } from './LDClientContext.js';
2
2
  export { LDClientContext };
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import type { HttpErrorResponse } from './Requests';
1
+ import type { HttpErrorResponse } from './Requests.js';
2
2
  export type EventName = string;
3
3
  export type EventListener = (event?: {
4
4
  data?: any;
@@ -1,4 +1,4 @@
1
- import type { LDApplication, LDDevice } from './AutoEnv';
1
+ import type { LDApplication, LDDevice } from './AutoEnv.js';
2
2
  /**
3
3
  * Information about the platform of the SDK and the environment it is executing.
4
4
  */
@@ -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,4 +1,4 @@
1
- import type { EventSource, EventSourceInitDict } from './EventSource';
1
+ import type { EventSource, EventSourceInitDict } from './EventSource.js';
2
2
  /**
3
3
  * Interface for headers that are part of a fetch response.
4
4
  */
@@ -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,4 +1,4 @@
1
- import Context from '../../Context';
1
+ import Context from '../../Context.js';
2
2
  /**
3
3
  * Interface for a strategy for removing duplicate contexts from the event stream.
4
4
  * Client side event processors do not do this de-duplication, so the implementation
@@ -1,4 +1,4 @@
1
- import InputEvent from '../../internal/events/InputEvent';
1
+ import InputEvent from '../../internal/events/InputEvent.js';
2
2
  export default interface LDEventProcessor {
3
3
  close(): void;
4
4
  flush(): Promise<void>;
@@ -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,4 +1,4 @@
1
- import { DataSourceErrorKind } from './DataSourceErrorKinds';
1
+ import { DataSourceErrorKind } from './DataSourceErrorKinds.js';
2
2
  export declare class LDFileDataSourceError extends Error {
3
3
  constructor(message: string);
4
4
  }
@@ -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
@@ -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
@@ -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,