From 8f868cb09e9b080d451b4777363f62946308bc37 Mon Sep 17 00:00:00 2001 From: Zita Szupera Date: Mon, 7 Apr 2025 18:09:53 +0200 Subject: [PATCH] fix: remove setting max connections to avoid installing undici --- package.json | 3 +-- src/BaseApi.ts | 4 +--- src/StreamClient.ts | 29 ++++++++++++----------------- src/types.ts | 4 +--- tsconfig.json | 2 +- yarn.lock | 30 +++++++++--------------------- 6 files changed, 25 insertions(+), 47 deletions(-) diff --git a/package.json b/package.json index 4333bdb..e587d0e 100644 --- a/package.json +++ b/package.json @@ -71,9 +71,8 @@ }, "dependencies": { "@types/jsonwebtoken": "^9.0.3", - "@types/node": "^20.11.24", + "@types/node": "^18.3.0", "jsonwebtoken": "^9.0.2", - "undici": "^5.29.0", "uuid": "^9.0.1" }, "peerDependencies": { diff --git a/src/BaseApi.ts b/src/BaseApi.ts index 691c3dd..6206507 100644 --- a/src/BaseApi.ts +++ b/src/BaseApi.ts @@ -2,10 +2,9 @@ import { v4 as uuidv4 } from 'uuid'; import { ApiConfig, RequestMetadata, StreamError } from './types'; import { APIError } from './gen/models'; import { getRateLimitFromResponseHeader } from './utils/rate-limit'; -import { Agent } from 'undici'; export class BaseApi { - private readonly dispatcher: Agent; + private readonly dispatcher?: RequestInit['dispatcher']; constructor(protected readonly apiConfig: ApiConfig) { this.dispatcher = this.apiConfig.agent; @@ -46,7 +45,6 @@ export class BaseApi { method, body: JSON.stringify(body), headers, - /** @ts-expect-error we get types from DOM here, but we should use node types */ dispatcher: this.dispatcher, }); diff --git a/src/StreamClient.ts b/src/StreamClient.ts index 6313e22..8600ebb 100644 --- a/src/StreamClient.ts +++ b/src/StreamClient.ts @@ -6,15 +6,13 @@ import { StreamChatClient } from './StreamChatClient'; import { CallTokenPayload, UserTokenPayload } from './types'; import { QueryBannedUsersPayload, UserRequest } from './gen/models'; import { StreamModerationClient } from './StreamModerationClient'; -import { Agent } from 'undici'; export interface StreamClientOptions { timeout?: number; basePath?: string; - /** The max number of clients to create. `null` if no limit. Default is 100. Has no effect if `agent` is provided. */ - maxConnections?: number | null; + // We use unknown here because RequestInit['dispatcher'] is different between Node versions /** The [HTTP Agent](https://undici.nodejs.org/#/docs/api/Agent.md) to use. */ - agent?: Agent; + agent?: unknown; } export class StreamClient extends CommonApi { @@ -24,7 +22,6 @@ export class StreamClient extends CommonApi { public readonly options: StreamClientOptions = {}; private static readonly DEFAULT_TIMEOUT = 3000; - private static readonly MAX_CONNECTIONS = 100; /** * @@ -39,17 +36,15 @@ export class StreamClient extends CommonApi { ) { const token = JWTServerToken(secret); const timeout = config?.timeout ?? StreamClient.DEFAULT_TIMEOUT; - const agent = - config?.agent ?? - new Agent({ - connections: - config?.maxConnections === undefined - ? StreamClient.MAX_CONNECTIONS - : config.maxConnections, - }); const chatBaseUrl = config?.basePath ?? 'https://chat.stream-io-api.com'; const videoBaseUrl = config?.basePath ?? 'https://video.stream-io-api.com'; - super({ apiKey, token, timeout, baseUrl: chatBaseUrl, agent }); + super({ + apiKey, + token, + timeout, + baseUrl: chatBaseUrl, + agent: config?.agent as RequestInit['dispatcher'], + }); this.video = new StreamVideoClient({ streamClient: this, @@ -57,21 +52,21 @@ export class StreamClient extends CommonApi { token, timeout, baseUrl: videoBaseUrl, - agent, + agent: config?.agent as RequestInit['dispatcher'], }); this.chat = new StreamChatClient({ apiKey, token, timeout, baseUrl: chatBaseUrl, - agent, + agent: config?.agent as RequestInit['dispatcher'], }); this.moderation = new StreamModerationClient({ apiKey, token, timeout, baseUrl: chatBaseUrl, - agent, + agent: config?.agent as RequestInit['dispatcher'], }); } diff --git a/src/types.ts b/src/types.ts index 701a79e..7e93e14 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,3 @@ -import { Agent } from 'undici'; - export type OmitTypeId = Omit; export interface ApiConfig { @@ -8,7 +6,7 @@ export interface ApiConfig { baseUrl: string; /** The timeout for requests in milliseconds. The default is 3000. */ timeout: number; - agent: Agent; + agent?: RequestInit['dispatcher']; } export interface RequestMetadata { diff --git a/tsconfig.json b/tsconfig.json index a4ff2ab..41ba1f8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "outDir": "./dist", "module": "ES2020", "target": "ES2020", - "lib": ["esnext", "dom"], + "lib": ["esnext"], "noEmitOnError": true, "noImplicitAny": true, "declaration": true, diff --git a/yarn.lock b/yarn.lock index c32a03e..1125744 100644 --- a/yarn.lock +++ b/yarn.lock @@ -271,11 +271,6 @@ resolved "https://registry.npmjs.org/@eslint/js/-/js-8.54.0.tgz" integrity sha512-ut5V+D+fOoWPgGGNj83GGjnntO39xDy6DWxO0wb7Jp3DcMX0TfIqdzHF85VTQkerdyGmuuMD9AKAo5KiNlf/AQ== -"@fastify/busboy@^2.0.0": - version "2.1.1" - resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d" - integrity sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA== - "@humanwhocodes/config-array@^0.11.13": version "0.11.13" resolved "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.13.tgz" @@ -528,12 +523,12 @@ resolved "https://registry.npmjs.org/@types/node/-/node-20.7.1.tgz" integrity sha512-LT+OIXpp2kj4E2S/p91BMe+VgGX2+lfO+XTpfXhh+bCk2LkQtHZSub8ewFBMGP5ClysPjTDFa4sMI8Q3n4T0wg== -"@types/node@^20.11.24": - version "20.17.30" - resolved "https://registry.yarnpkg.com/@types/node/-/node-20.17.30.tgz#1d93f656d3b869dbef7b796568ac457606ba58d0" - integrity sha512-7zf4YyHA+jvBNfVrk2Gtvs6x7E8V+YDW05bNfG2XkWDJfYRXrTiP/DsB2zSYTaHX0bGIujTBQdMVAhb+j7mwpg== +"@types/node@^18.3.0": + version "18.19.86" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.86.tgz#a7e1785289c343155578b9d84a0e3e924deb948b" + integrity sha512-fifKayi175wLyKyc5qUfyENhQ1dCNI1UNjp653d8kuYcPQN5JhX3dGuP/XmvPTg/xRBn1VTLpbmi+H/Mr7tLfQ== dependencies: - undici-types "~6.19.2" + undici-types "~5.26.4" "@types/semver@^7.5.0": version "7.5.6" @@ -3316,17 +3311,10 @@ unbox-primitive@^1.0.2: has-symbols "^1.0.3" which-boxed-primitive "^1.0.2" -undici-types@~6.19.2: - version "6.19.8" - resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02" - integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw== - -undici@^5.29.0: - version "5.29.0" - resolved "https://registry.yarnpkg.com/undici/-/undici-5.29.0.tgz#419595449ae3f2cdcba3580a2e8903399bd1f5a3" - integrity sha512-raqeBD6NQK4SkWhQzeYKd1KmIG6dllBOTt55Rmkt4HtI9mwdWtJljnrXjAFUBLTSN67HWrOIZ3EPF4kjUw80Bg== - dependencies: - "@fastify/busboy" "^2.0.0" +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== universalify@^2.0.0: version "2.0.0"