diff --git a/.all-contributorsrc b/.all-contributorsrc index 12447ce2..d1aa0a24 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1465,6 +1465,16 @@ "contributions": [ "review" ] + }, + { + "login": "IKatsuba", + "name": "Igor Katsuba", + "avatar_url": "https://avatars.githubusercontent.com/u/10637135?v=4", + "profile": "https://blog.katsuba.dev", + "contributions": [ + "ideas", + "code" + ] } ] } diff --git a/README.md b/README.md index 4e1727d4..7947cffc 100644 --- a/README.md +++ b/README.md @@ -314,6 +314,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Mased
Mased

🌍 📖 Artem Prokop
Artem Prokop

📓 Sérgio Rebelo
Sérgio Rebelo

👀 + Igor Katsuba
Igor Katsuba

🤔 💻 diff --git a/package.json b/package.json index a0117388..b395ef66 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "grammy", "description": "The Telegram Bot Framework.", - "version": "1.31.0", + "version": "1.31.1", "author": "KnorpelSenf", "license": "MIT", "engines": { diff --git a/src/core/client.ts b/src/core/client.ts index 197f8c30..f707a593 100644 --- a/src/core/client.ts +++ b/src/core/client.ts @@ -205,6 +205,12 @@ export interface ApiClientOptions { NonNullable[1]>, "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 @@ -222,6 +228,8 @@ export interface ApiClientOptions { class ApiClient { private readonly options: Required; + private readonly fetch: typeof fetch; + private hasUsedWebhookReply = false; readonly installedTransformers: Transformer[] = []; @@ -244,7 +252,9 @@ class ApiClient { }, canUseWebhookReply: options.canUseWebhookReply ?? (() => false), sensitiveLogs: options.sensitiveLogs ?? false, + fetch: options.fetch ?? fetch, }; + this.fetch = this.options.fetch; if (this.options.apiRoot.endsWith("/")) { throw new Error( `Remove the trailing '/' from the 'apiRoot' option (use '${ @@ -297,7 +307,7 @@ class ApiClient { const sig = controller.signal; const options = { ...opts.baseFetchConfig, signal: sig, ...config }; // Perform fetch call, and handle networking errors - const successPromise = fetch( + const successPromise = this.fetch( url instanceof URL ? url.href : url, options, ).catch(toHttpError(method, opts.sensitiveLogs)); diff --git a/test/deps.test.ts b/test/deps.test.ts index c799a186..3460db1f 100644 --- a/test/deps.test.ts +++ b/test/deps.test.ts @@ -12,23 +12,7 @@ export { export { afterEach, beforeEach, describe, it } from "jsr:@std/testing/bdd"; export { type Spy, spy, type Stub, stub } from "jsr:@std/testing/mock"; export { assertType, type IsExact } from "jsr:@std/testing/types"; - -/** - * Checks if the actual type `A` is assignable to the expected type `E`, and - * vice versa. - * - * ```ts - * // false because E is not assignable to A - * type P = IsMutuallyAssignable; - * // false because A is not assignable to E - * type Q = IsMutuallyAssignable; - * // true - * type R = IsMutuallyAssignable; - * ``` - */ -export type IsMutuallyAssignable = [E] extends [A] - ? [A] extends [E] ? true : false - : false; +export { type IsMutuallyAssignable } from "jsr:@std/testing/unstable-types"; /** * Collects a potentially async iterator of `Uint8Array` objects into a single