grammy 1.31.1 → 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.
@@ -11,7 +11,7 @@ function concatTransformer(prev, trans) {
11
11
  }
12
12
  class ApiClient {
13
13
  constructor(token, options = {}, webhookReplyEnvelope = {}) {
14
- var _a, _b, _c, _d, _e, _f, _g;
14
+ var _a, _b, _c, _d, _e, _f;
15
15
  this.token = token;
16
16
  this.webhookReplyEnvelope = webhookReplyEnvelope;
17
17
  this.hasUsedWebhookReply = false;
@@ -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,7 @@ 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,
75
- fetch: (_g = options.fetch) !== null && _g !== void 0 ? _g : shim_node_js_1.fetch,
80
+ fetch: ((...args) => fetchFn(...args)),
76
81
  };
77
82
  this.fetch = this.options.fetch;
78
83
  if (this.options.apiRoot.endsWith("/")) {
package/out/web.mjs CHANGED
@@ -2291,6 +2291,8 @@ class ApiClient {
2291
2291
  };
2292
2292
  const apiRoot = options.apiRoot ?? "https://api.telegram.org";
2293
2293
  const environment = options.environment ?? "prod";
2294
+ const { fetch: customFetch } = options;
2295
+ const fetchFn = customFetch ?? fetch;
2294
2296
  this.options = {
2295
2297
  apiRoot,
2296
2298
  environment,
@@ -2302,7 +2304,7 @@ class ApiClient {
2302
2304
  },
2303
2305
  canUseWebhookReply: options.canUseWebhookReply ?? (()=>false),
2304
2306
  sensitiveLogs: options.sensitiveLogs ?? false,
2305
- fetch: options.fetch ?? fetch
2307
+ fetch: (...args)=>fetchFn(...args)
2306
2308
  };
2307
2309
  this.fetch = this.options.fetch;
2308
2310
  if (this.options.apiRoot.endsWith("/")) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "grammy",
3
3
  "description": "The Telegram Bot Framework.",
4
- "version": "1.31.1",
4
+ "version": "1.31.2",
5
5
  "author": "KnorpelSenf",
6
6
  "license": "MIT",
7
7
  "engines": {