grammy 1.31.0 โ 1.31.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/out/core/client.d.ts +4 -0
- package/out/core/client.js +8 -1
- package/out/web.mjs +7 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -314,6 +314,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
314
314
|
<td align="center" valign="top" width="11.11%"><a href="https://nometa.xyz/"><img src="https://avatars.githubusercontent.com/u/68379695?v=4?s=100" width="100px;" alt="Mased"/><br /><sub><b>Mased</b></sub></a><br /><a href="#translation-MasedMSD" title="Translation">๐</a> <a href="https://github.com/grammyjs/grammY/commits?author=MasedMSD" title="Documentation">๐</a></td>
|
|
315
315
|
<td align="center" valign="top" width="11.11%"><a href="https://github.com/ExposedCat"><img src="https://avatars.githubusercontent.com/u/44642024?v=4?s=100" width="100px;" alt="Artem Prokop"/><br /><sub><b>Artem Prokop</b></sub></a><br /><a href="#userTesting-ExposedCat" title="User Testing">๐</a></td>
|
|
316
316
|
<td align="center" valign="top" width="11.11%"><a href="https://chinoman10.com/"><img src="https://avatars.githubusercontent.com/u/8300763?v=4?s=100" width="100px;" alt="Sรฉrgio Rebelo"/><br /><sub><b>Sรฉrgio Rebelo</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3AChinoman10" title="Reviewed Pull Requests">๐</a></td>
|
|
317
|
+
<td align="center" valign="top" width="11.11%"><a href="https://blog.katsuba.dev"><img src="https://avatars.githubusercontent.com/u/10637135?v=4?s=100" width="100px;" alt="Igor Katsuba"/><br /><sub><b>Igor Katsuba</b></sub></a><br /><a href="#ideas-IKatsuba" title="Ideas, Planning, & Feedback">๐ค</a> <a href="https://github.com/grammyjs/grammY/commits?author=IKatsuba" title="Code">๐ป</a></td>
|
|
317
318
|
</tr>
|
|
318
319
|
</tbody>
|
|
319
320
|
</table>
|
package/out/core/client.d.ts
CHANGED
|
@@ -145,6 +145,10 @@ export interface ApiClientOptions {
|
|
|
145
145
|
* compress: true }` (Node), `{}` (Deno)
|
|
146
146
|
*/
|
|
147
147
|
baseFetchConfig?: Omit<NonNullable<Parameters<typeof fetch>[1]>, "method" | "headers" | "body">;
|
|
148
|
+
/**
|
|
149
|
+
* `fetch` function to use for making HTTP requests. Default: `node-fetch` in Node.js, `fetch` in Deno.
|
|
150
|
+
*/
|
|
151
|
+
fetch?: typeof fetch;
|
|
148
152
|
/**
|
|
149
153
|
* When the network connection is unreliable and some API requests fail
|
|
150
154
|
* because of that, grammY will throw errors that tell you exactly which
|
package/out/core/client.js
CHANGED
|
@@ -46,7 +46,7 @@ class ApiClient {
|
|
|
46
46
|
const sig = controller.signal;
|
|
47
47
|
const options = { ...opts.baseFetchConfig, signal: sig, ...config };
|
|
48
48
|
// Perform fetch call, and handle networking errors
|
|
49
|
-
const successPromise =
|
|
49
|
+
const successPromise = this.fetch(url instanceof URL ? url.href : url, options).catch((0, error_js_1.toHttpError)(method, opts.sensitiveLogs));
|
|
50
50
|
// Those are the three possible outcomes of the fetch call:
|
|
51
51
|
const operations = [successPromise, streamErr.promise, timeout.promise];
|
|
52
52
|
// Wait for result
|
|
@@ -61,6 +61,11 @@ class ApiClient {
|
|
|
61
61
|
};
|
|
62
62
|
const apiRoot = (_a = options.apiRoot) !== null && _a !== void 0 ? _a : "https://api.telegram.org";
|
|
63
63
|
const environment = (_b = options.environment) !== null && _b !== void 0 ? _b : "prod";
|
|
64
|
+
// In an ideal world, `fetch` is independent of the context being called,
|
|
65
|
+
// but in a Cloudflare worker, any context other than global throws an error.
|
|
66
|
+
// That is why we need to call custom fetch or fetch without context.
|
|
67
|
+
const { fetch: customFetch } = options;
|
|
68
|
+
const fetchFn = customFetch !== null && customFetch !== void 0 ? customFetch : shim_node_js_1.fetch;
|
|
64
69
|
this.options = {
|
|
65
70
|
apiRoot,
|
|
66
71
|
environment,
|
|
@@ -72,7 +77,9 @@ class ApiClient {
|
|
|
72
77
|
},
|
|
73
78
|
canUseWebhookReply: (_e = options.canUseWebhookReply) !== null && _e !== void 0 ? _e : (() => false),
|
|
74
79
|
sensitiveLogs: (_f = options.sensitiveLogs) !== null && _f !== void 0 ? _f : false,
|
|
80
|
+
fetch: ((...args) => fetchFn(...args)),
|
|
75
81
|
};
|
|
82
|
+
this.fetch = this.options.fetch;
|
|
76
83
|
if (this.options.apiRoot.endsWith("/")) {
|
|
77
84
|
throw new Error(`Remove the trailing '/' from the 'apiRoot' option (use '${this.options.apiRoot.substring(0, this.options.apiRoot.length - 1)}' instead of '${this.options.apiRoot}')`);
|
|
78
85
|
}
|
package/out/web.mjs
CHANGED
|
@@ -2239,6 +2239,7 @@ class ApiClient {
|
|
|
2239
2239
|
token;
|
|
2240
2240
|
webhookReplyEnvelope;
|
|
2241
2241
|
options;
|
|
2242
|
+
fetch;
|
|
2242
2243
|
hasUsedWebhookReply;
|
|
2243
2244
|
installedTransformers;
|
|
2244
2245
|
constructor(token, options = {}, webhookReplyEnvelope = {}){
|
|
@@ -2275,7 +2276,7 @@ class ApiClient {
|
|
|
2275
2276
|
signal: sig,
|
|
2276
2277
|
...config
|
|
2277
2278
|
};
|
|
2278
|
-
const successPromise = fetch(url instanceof URL ? url.href : url, options).catch(toHttpError(method, opts.sensitiveLogs));
|
|
2279
|
+
const successPromise = this.fetch(url instanceof URL ? url.href : url, options).catch(toHttpError(method, opts.sensitiveLogs));
|
|
2279
2280
|
const operations = [
|
|
2280
2281
|
successPromise,
|
|
2281
2282
|
streamErr.promise,
|
|
@@ -2290,6 +2291,8 @@ class ApiClient {
|
|
|
2290
2291
|
};
|
|
2291
2292
|
const apiRoot = options.apiRoot ?? "https://api.telegram.org";
|
|
2292
2293
|
const environment = options.environment ?? "prod";
|
|
2294
|
+
const { fetch: customFetch } = options;
|
|
2295
|
+
const fetchFn = customFetch ?? fetch;
|
|
2293
2296
|
this.options = {
|
|
2294
2297
|
apiRoot,
|
|
2295
2298
|
environment,
|
|
@@ -2300,8 +2303,10 @@ class ApiClient {
|
|
|
2300
2303
|
...options.baseFetchConfig
|
|
2301
2304
|
},
|
|
2302
2305
|
canUseWebhookReply: options.canUseWebhookReply ?? (()=>false),
|
|
2303
|
-
sensitiveLogs: options.sensitiveLogs ?? false
|
|
2306
|
+
sensitiveLogs: options.sensitiveLogs ?? false,
|
|
2307
|
+
fetch: (...args)=>fetchFn(...args)
|
|
2304
2308
|
};
|
|
2309
|
+
this.fetch = this.options.fetch;
|
|
2305
2310
|
if (this.options.apiRoot.endsWith("/")) {
|
|
2306
2311
|
throw new Error(`Remove the trailing '/' from the 'apiRoot' option (use '${this.options.apiRoot.substring(0, this.options.apiRoot.length - 1)}' instead of '${this.options.apiRoot}')`);
|
|
2307
2312
|
}
|