Interface EventSourceInitDict

The options that createEventSource understands.

The first group of fields mirrors the platform's EventSourceInitDict. Each field that the SDK supplies stays required here, to match the platform contract. A caller that calls createEventSource directly can omit each field, because that function's parameter is Partial<...>. A missing field falls back to a default (errorFilter, initialRetryDelayMillis), or the feature stays off (headers, readTimeoutMillis, retryResetIntervalMillis).

Hierarchy

  • EventSourceInitDict

Properties

body?: string
createEventRegistry?: EventListenerRegistryFactory

Creates the listener registry for this instance. The registry stores the listeners registered through addEventListener. When this option is absent, the instance uses the internal Map-backed registry (createDefaultEventRegistry).

A substitute must satisfy EventListenerRegistry. An SDK can supply one that uses a native eventing primitive, such as Node's EventEmitter. A raw EventEmitter throws from emit('error') when error has no listener. An EventEmitter-backed substitute must guard against that case.

The registry is trusted code. It sees every event this instance dispatches, and it controls what its listeners receive.

createEventSource throws a TypeError that names createEventRegistry when this option is not a function, or when the returned value is missing a required EventListenerRegistry method.

This function must return a new registry on each call. createEventSource calls it once per instance. When a factory returns one shared registry for more than one instance, the separate event sources deliver each other's events.

errorFilter: ((err) => boolean)

Type declaration

    • (err): boolean
    • Decides if the client retries a given error. Return false to stop the retries and close the stream. When this field is not set, the client retries I/O errors and HTTP 500, 502, 503, and 504.

      Parameters

      Returns boolean

fetch?: FetchLike

The transport used to open the stream. When absent, the client uses the global fetch.

The client only needs the structural subset declared by FetchLike, so a real fetch implementation satisfies this option without casts. A platform without a suitable global fetch, or one that needs agents, proxies, or TLS configuration, supplies a function with the same shape over its own transport.

headers: {
    [key: string]: string | string[];
}

Type declaration

  • [key: string]: string | string[]
initialRetryDelayMillis: number
jitterRatio?: number

If set, the client decreases each computed retry delay by a random amount. The maximum decrease is this fraction of the delay.

maxBackoffMillis?: number

If set, retry delays grow exponentially up to this limit.

method?: string
readTimeoutMillis: number
retryDelayStrategy?: RetryDelayStrategy

Replaces the built-in retry delay behavior with a caller-supplied strategy.

The client calls nextRetryDelay(currentTimeMillis) when it schedules a reconnect, and it waits for the returned number of milliseconds. The client calls setGoodSince(goodSinceTimeMillis) when the first event of a connection arrives. The client calls setBaseDelay(delayMillis) when the server sends a retry: field. The value reaches the strategy already validated as all ASCII digits and capped at one hour.

When this option is set, it fully replaces the built-in strategy. The tuning options initialRetryDelayMillis, maxBackoffMillis, jitterRatio, and retryResetIntervalMillis have no effect. When this option is absent, the built-in strategy applies and those options work as documented.

An exception a strategy method throws does not stop the stream or the reconnect. The client falls back to the last reconnect interval for the delay, and the exception rethrows later, on a separate microtask.

retryResetIntervalMillis: number
skipDefaultHeaders?: boolean

When true, the request omits the default Cache-Control: no-cache and Accept: text/event-stream headers.

urlBuilder?: (() => string)

Type declaration

    • (): string
    • Returns the URL for the next connection attempt. When set, the client calls this function immediately before each request, including the first. This keeps a query parameter current when the parameter changes between attempts.

      Returns string

withCredentials?: boolean

When true, the client sends credentials (cookies, HTTP authentication) with the request, including a cross-origin request. This flag maps to credentials: 'include' in fetch(). A transport without a credentials concept ignores it.

Generated using TypeDoc