diff --git a/src/core/client.ts b/src/core/client.ts index 6c99bb6a..a8dc8790 100644 --- a/src/core/client.ts +++ b/src/core/client.ts @@ -208,11 +208,6 @@ export interface ApiClientOptions { "method" | "headers" | "body" >; - /** - * `fetch` function to use for making HTTP requests. Default: `node-fetch` in Node.js, `fetch` in Deno. - */ - fetch?: typeof fetch; - /** * When the network connection is unreliable and some API requests fail * because of that, grammY will throw errors that tell you exactly which @@ -230,8 +225,6 @@ export interface ApiClientOptions { class ApiClient { private readonly options: Required; - private readonly fetch: typeof fetch; - private hasUsedWebhookReply = false; readonly installedTransformers: Transformer[] = []; @@ -244,12 +237,6 @@ class ApiClient { const apiRoot = options.apiRoot ?? "https://api.telegram.org"; const environment = options.environment ?? "prod"; - // In an ideal world, `fetch` is independent of the context being called, - // but in a Cloudflare worker, any context other than global throws an error. - // That is why we need to call custom fetch or fetch without context. - const { fetch: customFetch } = options; - const fetchFn = customFetch ?? fetch; - this.options = { apiRoot, environment, @@ -261,11 +248,7 @@ class ApiClient { }, canUseWebhookReply: options.canUseWebhookReply ?? (() => false), sensitiveLogs: options.sensitiveLogs ?? false, - fetch: - ((...args: Parameters) => - fetchFn(...args)) as typeof fetch, }; - this.fetch = this.options.fetch; if (this.options.apiRoot.endsWith("/")) { throw new Error( `Remove the trailing '/' from the 'apiRoot' option (use '${ @@ -318,7 +301,7 @@ class ApiClient { const sig = controller.signal; const options = { ...opts.baseFetchConfig, signal: sig, ...config }; // Perform fetch call, and handle networking errors - const successPromise = this.fetch(url, options) + const successPromise = fetch(url, options) .catch(toHttpError(method, opts.sensitiveLogs)); // Those are the three possible outcomes of the fetch call: const operations = [successPromise, streamErr.promise, timeout.promise]; diff --git a/src/shim.node.ts b/src/shim.node.ts deleted file mode 100644 index 9823864b..00000000 --- a/src/shim.node.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { AbortController, type AbortSignal } from "abort-controller"; -export { default as fetch } from "node-fetch";