diff --git a/package.json b/package.json index a6c50fd0..4452de68 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ }, "devDependencies": { "@sinonjs/fake-timers": "14.0.0", - "@types/eventsource": "1.1.15", "@types/node": "22.10.2", "@types/sinonjs__fake-timers": "8.1.5", "@types/ws": "8.5.13", diff --git a/src/adapter/types.ts b/src/adapter/types.ts index ad2971d2..1bde1959 100644 --- a/src/adapter/types.ts +++ b/src/adapter/types.ts @@ -1,4 +1,4 @@ -import type EventSource from 'eventsource' +import { EventSource } from 'eventsource' import Redis from 'ioredis' import { Cache } from '../cache' import { AdapterConfig, BaseAdapterSettings, SettingsDefinitionMap } from '../config' diff --git a/src/transports/sse.ts b/src/transports/sse.ts index ffcea000..c8861ee3 100644 --- a/src/transports/sse.ts +++ b/src/transports/sse.ts @@ -1,5 +1,5 @@ import { AxiosRequestConfig } from 'axios' -import EventSource from 'eventsource' +import { EventSource } from 'eventsource' import { EndpointContext } from '../adapter' import { calculateHttpRequestKey } from '../cache' import { makeLogger, sleep } from '../util' @@ -13,7 +13,7 @@ const logger = makeLogger('SSETransport') export interface SSEConfig { url: string - eventSourceInitDict?: EventSource.EventSourceInitDict + headers?: Record } /** @@ -103,7 +103,13 @@ export class SseTransport extends StreamingTrans logger.debug('No established connection and new subscriptions available, connecting to SSE') const sseConfig = this.config.prepareSSEConnectionConfig(subscriptions.new, context) this.providerDataStreamEstablished = Date.now() - this.sseConnection = new this.EventSource(sseConfig.url, sseConfig.eventSourceInitDict) + this.sseConnection = new this.EventSource(sseConfig.url, { + fetch: (input, init) => + fetch(input, { + ...init, + headers: { ...init?.headers, ...sseConfig.headers }, + }), + }) const eventHandlerGenerator = (listener: (typeof this.config.eventListeners)[0]) => { return (e: MessageEvent) => { diff --git a/tsconfig.json b/tsconfig.json index 53a4c043..958d757e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,7 +20,8 @@ "noImplicitThis": true, "noPropertyAccessFromIndexSignature": true, "noUnusedLocals": true, - "strict": true + "strict": true, + "skipLibCheck": true }, "exclude": ["src/**/test/**/*"], "include": ["./src/**/*"] diff --git a/yarn.lock b/yarn.lock index c8693357..c8d8bb05 100644 --- a/yarn.lock +++ b/yarn.lock @@ -326,11 +326,6 @@ resolved "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz" integrity sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw== -"@types/eventsource@1.1.15": - version "1.1.15" - resolved "https://registry.npmjs.org/@types/eventsource/-/eventsource-1.1.15.tgz" - integrity sha512-XQmGcbnxUNa06HR3VBVkc9+A2Vpi9ZyLJcdS5dwaQQ/4ZMWFO+5c90FnMUpbtMZwB/FChoYHwuVg8TvkECacTA== - "@types/hast@^3.0.4": version "3.0.4" resolved "https://registry.npmjs.org/@types/hast/-/hast-3.0.4.tgz"