Skip to content

Commit 338cf98

Browse files
committed
fix: remove setting max connections to avoid installing undici
1 parent 6eb9673 commit 338cf98

File tree

6 files changed

+30
-47
lines changed

6 files changed

+30
-47
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@
7171
},
7272
"dependencies": {
7373
"@types/jsonwebtoken": "^9.0.3",
74-
"@types/node": "^20.11.24",
74+
"@types/node": "^18.3.0",
7575
"jsonwebtoken": "^9.0.2",
76-
"undici": "^5.29.0",
7776
"uuid": "^9.0.1"
7877
},
7978
"peerDependencies": {

src/BaseApi.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import { v4 as uuidv4 } from 'uuid';
22
import { ApiConfig, RequestMetadata, StreamError } from './types';
33
import { APIError } from './gen/models';
44
import { getRateLimitFromResponseHeader } from './utils/rate-limit';
5-
import { Agent } from 'undici';
65

76
export class BaseApi {
8-
private readonly dispatcher: Agent;
7+
private readonly dispatcher?: RequestInit['dispatcher'];
98

109
constructor(protected readonly apiConfig: ApiConfig) {
1110
this.dispatcher = this.apiConfig.agent;
@@ -27,6 +26,11 @@ export class BaseApi {
2726
});
2827
}
2928

29+
// @ts-expect-error
30+
const undiciGlobalDispatcher =
31+
global[Symbol.for('undici.globalDispatcher.1')];
32+
console.log(undiciGlobalDispatcher);
33+
3034
url += `?${encodedParams}`;
3135
const clientRequestId = uuidv4();
3236
const headers = {
@@ -46,7 +50,6 @@ export class BaseApi {
4650
method,
4751
body: JSON.stringify(body),
4852
headers,
49-
/** @ts-expect-error we get types from DOM here, but we should use node types */
5053
dispatcher: this.dispatcher,
5154
});
5255

src/StreamClient.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ import { StreamChatClient } from './StreamChatClient';
66
import { CallTokenPayload, UserTokenPayload } from './types';
77
import { QueryBannedUsersPayload, UserRequest } from './gen/models';
88
import { StreamModerationClient } from './StreamModerationClient';
9-
import { Agent } from 'undici';
109

1110
export interface StreamClientOptions {
1211
timeout?: number;
1312
basePath?: string;
14-
/** The max number of clients to create. `null` if no limit. Default is 100. Has no effect if `agent` is provided. */
15-
maxConnections?: number | null;
13+
// We use undefined here because RequestInit['dispatcher'] is different between Node versions
1614
/** The [HTTP Agent](https://undici.nodejs.org/#/docs/api/Agent.md) to use. */
17-
agent?: Agent;
15+
agent?: unknown;
1816
}
1917

2018
export class StreamClient extends CommonApi {
@@ -24,7 +22,6 @@ export class StreamClient extends CommonApi {
2422
public readonly options: StreamClientOptions = {};
2523

2624
private static readonly DEFAULT_TIMEOUT = 3000;
27-
private static readonly MAX_CONNECTIONS = 100;
2825

2926
/**
3027
*
@@ -39,39 +36,37 @@ export class StreamClient extends CommonApi {
3936
) {
4037
const token = JWTServerToken(secret);
4138
const timeout = config?.timeout ?? StreamClient.DEFAULT_TIMEOUT;
42-
const agent =
43-
config?.agent ??
44-
new Agent({
45-
connections:
46-
config?.maxConnections === undefined
47-
? StreamClient.MAX_CONNECTIONS
48-
: config.maxConnections,
49-
});
5039
const chatBaseUrl = config?.basePath ?? 'https://chat.stream-io-api.com';
5140
const videoBaseUrl = config?.basePath ?? 'https://video.stream-io-api.com';
52-
super({ apiKey, token, timeout, baseUrl: chatBaseUrl, agent });
41+
super({
42+
apiKey,
43+
token,
44+
timeout,
45+
baseUrl: chatBaseUrl,
46+
agent: config?.agent as RequestInit['dispatcher'],
47+
});
5348

5449
this.video = new StreamVideoClient({
5550
streamClient: this,
5651
apiKey,
5752
token,
5853
timeout,
5954
baseUrl: videoBaseUrl,
60-
agent,
55+
agent: config?.agent as RequestInit['dispatcher'],
6156
});
6257
this.chat = new StreamChatClient({
6358
apiKey,
6459
token,
6560
timeout,
6661
baseUrl: chatBaseUrl,
67-
agent,
62+
agent: config?.agent as RequestInit['dispatcher'],
6863
});
6964
this.moderation = new StreamModerationClient({
7065
apiKey,
7166
token,
7267
timeout,
7368
baseUrl: chatBaseUrl,
74-
agent,
69+
agent: config?.agent as RequestInit['dispatcher'],
7570
});
7671
}
7772

src/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Agent } from 'undici';
2-
31
export type OmitTypeId<T> = Omit<T, 'type' | 'id' | 'connection_id'>;
42

53
export interface ApiConfig {
@@ -8,7 +6,7 @@ export interface ApiConfig {
86
baseUrl: string;
97
/** The timeout for requests in milliseconds. The default is 3000. */
108
timeout: number;
11-
agent: Agent;
9+
agent?: RequestInit['dispatcher'];
1210
}
1311

1412
export interface RequestMetadata {

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"outDir": "./dist",
44
"module": "ES2020",
55
"target": "ES2020",
6-
"lib": ["esnext", "dom"],
6+
"lib": ["esnext"],
77
"noEmitOnError": true,
88
"noImplicitAny": true,
99
"declaration": true,

yarn.lock

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,6 @@
271271
resolved "https://registry.npmjs.org/@eslint/js/-/js-8.54.0.tgz"
272272
integrity sha512-ut5V+D+fOoWPgGGNj83GGjnntO39xDy6DWxO0wb7Jp3DcMX0TfIqdzHF85VTQkerdyGmuuMD9AKAo5KiNlf/AQ==
273273

274-
"@fastify/busboy@^2.0.0":
275-
version "2.1.1"
276-
resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d"
277-
integrity sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==
278-
279274
"@humanwhocodes/config-array@^0.11.13":
280275
version "0.11.13"
281276
resolved "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.13.tgz"
@@ -528,12 +523,12 @@
528523
resolved "https://registry.npmjs.org/@types/node/-/node-20.7.1.tgz"
529524
integrity sha512-LT+OIXpp2kj4E2S/p91BMe+VgGX2+lfO+XTpfXhh+bCk2LkQtHZSub8ewFBMGP5ClysPjTDFa4sMI8Q3n4T0wg==
530525

531-
"@types/node@^20.11.24":
532-
version "20.17.30"
533-
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.17.30.tgz#1d93f656d3b869dbef7b796568ac457606ba58d0"
534-
integrity sha512-7zf4YyHA+jvBNfVrk2Gtvs6x7E8V+YDW05bNfG2XkWDJfYRXrTiP/DsB2zSYTaHX0bGIujTBQdMVAhb+j7mwpg==
526+
"@types/node@^18.3.0":
527+
version "18.19.86"
528+
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.86.tgz#a7e1785289c343155578b9d84a0e3e924deb948b"
529+
integrity sha512-fifKayi175wLyKyc5qUfyENhQ1dCNI1UNjp653d8kuYcPQN5JhX3dGuP/XmvPTg/xRBn1VTLpbmi+H/Mr7tLfQ==
535530
dependencies:
536-
undici-types "~6.19.2"
531+
undici-types "~5.26.4"
537532

538533
"@types/semver@^7.5.0":
539534
version "7.5.6"
@@ -3316,17 +3311,10 @@ unbox-primitive@^1.0.2:
33163311
has-symbols "^1.0.3"
33173312
which-boxed-primitive "^1.0.2"
33183313

3319-
undici-types@~6.19.2:
3320-
version "6.19.8"
3321-
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02"
3322-
integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==
3323-
3324-
undici@^5.29.0:
3325-
version "5.29.0"
3326-
resolved "https://registry.yarnpkg.com/undici/-/undici-5.29.0.tgz#419595449ae3f2cdcba3580a2e8903399bd1f5a3"
3327-
integrity sha512-raqeBD6NQK4SkWhQzeYKd1KmIG6dllBOTt55Rmkt4HtI9mwdWtJljnrXjAFUBLTSN67HWrOIZ3EPF4kjUw80Bg==
3328-
dependencies:
3329-
"@fastify/busboy" "^2.0.0"
3314+
undici-types@~5.26.4:
3315+
version "5.26.5"
3316+
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
3317+
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==
33303318

33313319
universalify@^2.0.0:
33323320
version "2.0.0"

0 commit comments

Comments
 (0)