diff --git a/package-lock.json b/package-lock.json index 86292c02..67094e04 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,7 @@ "compression": "1.7.5", "correlation-id": "^5.2.0", "cors": "2.8.5", - "eventsource": "^2.0.2", + "eventsource": "^3.0.1", "express": "4.21.2", "helmet": "8.0.0", "json-stringify-safe": "5.0.1", @@ -37,6 +37,7 @@ "redis": "^4.7.0", "reflect-metadata": "0.2.2", "swagger-ui-express": "5.0.1", + "undici": "^7.1.0", "yamljs": "0.3.0", "yargs": "^17.7.2" }, @@ -5998,12 +5999,22 @@ } }, "node_modules/eventsource": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-2.0.2.tgz", - "integrity": "sha512-IzUmBGPR3+oUG9dUeXynyNmf91/3zUSJg1lCktzKw47OXuhco54U3r9B7O4XX+Rb1Itm9OZ2b0RkTs10bICOxA==", - "license": "MIT", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-3.0.1.tgz", + "integrity": "sha512-tyGtsrTc9fi+N5qFU6G2MLjcBbsdCOQ/QE9Cc96Mt6q02YkQrIJGOaNMg6qiXRJDzxecN7BntJYNRE/j0OIhMQ==", + "dependencies": { + "eventsource-parser": "^3.0.0" + }, "engines": { - "node": ">=12.0.0" + "node": ">=18.0.0" + } + }, + "node_modules/eventsource-parser": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.0.0.tgz", + "integrity": "sha512-T1C0XCUimhxVQzW4zFipdx0SficT651NnkR0ZSH3yQwh+mFMdLfgjABVi4YtMTtaL4s168593DaoaRLMqryavA==", + "engines": { + "node": ">=18.0.0" } }, "node_modules/execa": { @@ -13207,6 +13218,15 @@ "dev": true, "license": "MIT" }, + "node_modules/undici": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-7.1.0.tgz", + "integrity": "sha512-3+mdX2R31khuLCm2mKExSlMdJsfol7bJkIMH80tdXA74W34rT1jKemUTlYR7WY3TqsV4wfOgpatWmmB2Jl1+5g==", + "license": "MIT", + "engines": { + "node": ">=20.18.1" + } + }, "node_modules/undici-types": { "version": "6.20.0", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz", diff --git a/package.json b/package.json index e495bbbb..47298a03 100644 --- a/package.json +++ b/package.json @@ -92,7 +92,7 @@ "compression": "1.7.5", "correlation-id": "^5.2.0", "cors": "2.8.5", - "eventsource": "^2.0.2", + "eventsource": "^3.0.1", "express": "4.21.2", "helmet": "8.0.0", "json-stringify-safe": "5.0.1", @@ -104,6 +104,7 @@ "redis": "^4.7.0", "reflect-metadata": "0.2.2", "swagger-ui-express": "5.0.1", + "undici": "^7.1.0", "yamljs": "0.3.0", "yargs": "^17.7.2" }, diff --git a/src/modules/sse/SseModule.ts b/src/modules/sse/SseModule.ts index 8c50cb1d..abb4137d 100644 --- a/src/modules/sse/SseModule.ts +++ b/src/modules/sse/SseModule.ts @@ -1,6 +1,7 @@ import { ILogger } from "@js-soft/logging-abstractions"; import correlator from "correlation-id"; -import eventSourceModule from "eventsource"; +import { EventSource } from "eventsource"; +import { Agent, fetch, ProxyAgent } from "undici"; import { ConnectorMode } from "../../ConnectorMode"; import { ConnectorRuntime } from "../../ConnectorRuntime"; import { ConnectorRuntimeModule, ConnectorRuntimeModuleConfiguration } from "../../ConnectorRuntimeModule"; @@ -21,7 +22,7 @@ export interface SseModuleConfiguration extends ConnectorRuntimeModuleConfigurat } export default class SseModule extends ConnectorRuntimeModule { - private eventSource: eventSourceModule | undefined; + private eventSource: EventSource | undefined; public constructor(runtime: ConnectorRuntime, configuration: ConnectorRuntimeModuleConfiguration, logger: ILogger, connectorMode: ConnectorMode) { super(runtime, configuration, logger, connectorMode); @@ -53,13 +54,19 @@ export default class SseModule extends ConnectorRuntimeModule + fetch(url, { + ...options, + dispatcher: proxy ? new ProxyAgent({ ...baseOptions, uri: proxy }) : new Agent(baseOptions), + headers: { ...options?.headers, authorization: `Bearer ${token}` } + }) }); + this.eventSource = eventSource; eventSource.addEventListener("ExternalEventCreated", async () => await this.runSync()); diff --git a/src/modules/webhooks/WebhooksModule.ts b/src/modules/webhooks/WebhooksModule.ts index dba33829..05ae0953 100644 --- a/src/modules/webhooks/WebhooksModule.ts +++ b/src/modules/webhooks/WebhooksModule.ts @@ -1,6 +1,6 @@ import { Event, DataEvent as tsUtilsDataEvent } from "@js-soft/ts-utils"; import { DataEvent } from "@nmshd/runtime"; -import agentKeepAlive, { HttpsAgent as AgentKeepAliveHttps } from "agentkeepalive"; +import agentKeepAlive from "agentkeepalive"; import axios, { AxiosInstance } from "axios"; import correlator from "correlation-id"; import { ConnectorRuntimeModule } from "../../ConnectorRuntimeModule"; @@ -17,7 +17,7 @@ export default class WebhooksModule extends ConnectorRuntimeModule true, maxRedirects: 0 });