Skip to content

Commit 016f57e

Browse files
authored
Merge pull request #217 from thedanchez/eventsource
feat(node): update eventsource from v2 to v4
2 parents 782234c + a2c6a9b commit 016f57e

File tree

7 files changed

+47
-305
lines changed

7 files changed

+47
-305
lines changed

examples/todo-server-tests/tsconfig.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@
77
"declaration": true,
88
"noEmitOnError": true,
99
"verbatimModuleSyntax": false,
10+
// TODO: Remove DOM here!! The Node SDK should not need DOM types.
11+
"lib": ["ESNext", "DOM"],
1012
"types": ["node"],
1113
"paths": {
12-
"featurehub-javascript-node-sdk": ["../../packages/node/src"]
14+
"featurehub-javascript-client-sdk": ["../../packages/js/src"],
15+
"featurehub-javascript-node-sdk": ["../../packages/node/src"],
16+
/*
17+
This is a workaround to bypass Typescript checking of the cross-sha256 package.
18+
The author of the package improperly exported the source .ts file alongside the js file
19+
*/
20+
"cross-sha256": [
21+
"../../node_modules/.pnpm/[email protected]/node_modules/cross-sha256/index.d.ts"
22+
]
1323
}
1424
},
1525
"include": ["src/**/*", "features/**/*"]

packages/js/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
"cross-sha256": "^1.2.0",
7272
"murmurhash": "^2.0.1",
7373
"netmask": "^2.0.2",
74-
"restify": "^11.1.0",
7574
"semver-compare": "^1.0.0"
7675
},
7776
"engines": {

packages/js/src/featurehub_eventsource.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export declare class EventSource {
1717
readonly readyState: number;
1818
readonly withCredentials: boolean;
1919

20-
onopen: (evt: MessageEvent) => any;
21-
onmessage: (evt: MessageEvent) => any;
22-
onerror: (evt: MessageEvent) => any;
20+
onopen?: ((evt: Event) => void) | null;
21+
onmessage?: ((evt: MessageEvent) => void) | null;
22+
onerror?: ((evt: Event) => void) | null;
2323

2424
constructor(url: string, eventSourceInitDict?: EventSource.EventSourceInitDict);
2525

packages/node/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@
5858
"vite": "7.1.10"
5959
},
6060
"dependencies": {
61-
"eventsource": "^2.0.2",
62-
"featurehub-javascript-client-sdk": "^1.4.0",
63-
"restify": "^11.1.0"
61+
"eventsource": "^4.0.0",
62+
"featurehub-javascript-client-sdk": "workspace:*"
6463
},
6564
"engines": {
6665
"node": ">=20.0.0"

packages/node/src/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable @typescript-eslint/no-require-imports */
1+
import { EventSource } from "eventsource";
22
import {
33
EdgeFeatureHubConfig,
44
type FeatureEnvironmentCollection,
@@ -20,12 +20,10 @@ import {
2020
} from "featurehub-javascript-client-sdk";
2121
import { URL } from "url";
2222

23-
const ES = require("eventsource");
24-
2523
export * from "featurehub-javascript-client-sdk";
2624

2725
FeatureHubEventSourceClient.eventSourceProvider = (url, dict) => {
28-
return new ES(url, dict);
26+
return new EventSource(url, dict);
2927
};
3028

3129
interface PromiseLikeData {

packages/node/tsconfig.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"extends": "featurehub-tsconfig/base.json",
44
"compilerOptions": {
5-
"module": "CommonJS",
6-
"moduleResolution": "node",
75
"declaration": true,
86
"declarationMap": true,
97
"emitDeclarationOnly": true,
108
"noEmitOnError": true,
119
"verbatimModuleSyntax": false,
12-
"types": ["node"]
10+
// TODO: Remove DOM here!! The Node SDK should not need DOM types. We need to define a core JS package
11+
"lib": ["ESNext", "DOM"],
12+
"types": ["node"],
13+
"paths": {
14+
"featurehub-javascript-client-sdk": ["../js/src"],
15+
/*
16+
This is a workaround to bypass Typescript checking of the cross-sha256 package.
17+
The author of the package improperly exported the source .ts file alongside the js file
18+
*/
19+
"cross-sha256": [
20+
"../../node_modules/.pnpm/[email protected]/node_modules/cross-sha256/index.d.ts"
21+
]
22+
}
1323
},
1424
"include": ["**/*.ts", "**/*.tsx"],
1525
"exclude": ["node_modules", "dist"]

0 commit comments

Comments
 (0)