Skip to content

Commit

Permalink
Merge branch 'main' into feature/identity_deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Dec 10, 2024
2 parents 609d1e9 + bb1852e commit 1c43fed
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
32 changes: 26 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
},
Expand Down
19 changes: 13 additions & 6 deletions src/modules/sse/SseModule.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -21,7 +22,7 @@ export interface SseModuleConfiguration extends ConnectorRuntimeModuleConfigurat
}

export default class SseModule extends ConnectorRuntimeModule<SseModuleConfiguration> {
private eventSource: eventSourceModule | undefined;
private eventSource: EventSource | undefined;

public constructor(runtime: ConnectorRuntime, configuration: ConnectorRuntimeModuleConfiguration, logger: ILogger, connectorMode: ConnectorMode) {
super(runtime, configuration, logger, connectorMode);
Expand Down Expand Up @@ -53,13 +54,19 @@ export default class SseModule extends ConnectorRuntimeModule<SseModuleConfigura

this.logger.info(`Connecting to SSE endpoint: ${sseUrl}`);

const baseOptions = { connect: { rejectUnauthorized: false } };
const proxy = baseUrl.startsWith("https://") ? (process.env.https_proxy ?? process.env.HTTPS_PROXY) : (process.env.http_proxy ?? process.env.HTTP_PROXY);
const token = await this.runtime.getBackboneAuthenticationToken();

const eventSource = new eventSourceModule(sseUrl, {
https: { rejectUnauthorized: true },
proxy: process.env.HTTPS_PROXY ?? process.env.HTTP_PROXY,
headers: { authorization: `Bearer ${token}` }
const eventSource = new EventSource(sseUrl, {
fetch: (url, options) =>
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());
Expand Down
4 changes: 2 additions & 2 deletions src/modules/webhooks/WebhooksModule.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -17,7 +17,7 @@ export default class WebhooksModule extends ConnectorRuntimeModule<WebhooksModul

this.axios = axios.create({
httpAgent: new agentKeepAlive(),
httpsAgent: new AgentKeepAliveHttps({ rejectUnauthorized: !this.configModel.skipTlsCheck }),
httpsAgent: new agentKeepAlive.HttpsAgent({ rejectUnauthorized: !this.configModel.skipTlsCheck }),
validateStatus: () => true,
maxRedirects: 0
});
Expand Down

0 comments on commit 1c43fed

Please sign in to comment.