grammy 1.19.0 → 1.19.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 CHANGED
@@ -257,7 +257,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
257
257
  <td align="center" valign="top" width="11.11%"><a href="https://github.com/binamralamsal"><img src="https://avatars.githubusercontent.com/u/61900781?v=4?s=100" width="100px;" alt="Binamra Lamsal"/><br /><sub><b>Binamra Lamsal</b></sub></a><br /><a href="#ideas-binamralamsal" title="Ideas, Planning, & Feedback">🤔</a></td>
258
258
  <td align="center" valign="top" width="11.11%"><a href="https://github.com/gertminov"><img src="https://avatars.githubusercontent.com/u/78727928?v=4?s=100" width="100px;" alt="gertminov"/><br /><sub><b>gertminov</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=gertminov" title="Documentation">📖</a> <a href="#tutorial-gertminov" title="Tutorials">✅</a></td>
259
259
  <td align="center" valign="top" width="11.11%"><a href="https://github.com/amanape"><img src="https://avatars.githubusercontent.com/u/83104063?v=4?s=100" width="100px;" alt="Stephan Psaras"/><br /><sub><b>Stephan Psaras</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Aamanape" title="Bug reports">🐛</a></td>
260
- <td align="center" valign="top" width="11.11%"><a href="https://github.com/shevernitskiy"><img src="https://avatars.githubusercontent.com/u/28886342?v=4?s=100" width="100px;" alt="shevernitskiy"/><br /><sub><b>shevernitskiy</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Ashevernitskiy" title="Bug reports">🐛</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Ashevernitskiy" title="Reviewed Pull Requests">👀</a></td>
260
+ <td align="center" valign="top" width="11.11%"><a href="https://github.com/shevernitskiy"><img src="https://avatars.githubusercontent.com/u/28886342?v=4?s=100" width="100px;" alt="shevernitskiy"/><br /><sub><b>shevernitskiy</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Ashevernitskiy" title="Bug reports">🐛</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Ashevernitskiy" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/grammyjs/grammY/commits?author=shevernitskiy" title="Code">💻</a></td>
261
261
  <td align="center" valign="top" width="11.11%"><a href="https://github.com/mrmaster009"><img src="https://avatars.githubusercontent.com/u/81420490?v=4?s=100" width="100px;" alt="mrmaster009"/><br /><sub><b>mrmaster009</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=mrmaster009" title="Documentation">📖</a></td>
262
262
  <td align="center" valign="top" width="11.11%"><a href="https://lwjerri.dev/"><img src="https://avatars.githubusercontent.com/u/50290430?v=4?s=100" width="100px;" alt="Andrey Zontov"/><br /><sub><b>Andrey Zontov</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3ALWJerri" title="Bug reports">🐛</a> <a href="https://github.com/grammyjs/grammY/commits?author=LWJerri" title="Code">💻</a> <a href="#question-LWJerri" title="Answering Questions">💬</a> <a href="#ideas-LWJerri" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/grammyjs/grammY/commits?author=LWJerri" title="Documentation">📖</a> <a href="#translation-LWJerri" title="Translation">🌍</a></td>
263
263
  <td align="center" valign="top" width="11.11%"><a href="https://github.com/AbbassAlmusawi"><img src="https://avatars.githubusercontent.com/u/73327881?v=4?s=100" width="100px;" alt="Abbass Al-Musawi"/><br /><sub><b>Abbass Al-Musawi</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=AbbassAlmusawi" title="Documentation">📖</a></td>
@@ -46,21 +46,22 @@ export interface ReqResHandler {
46
46
  */
47
47
  export type FrameworkAdapter = (...args: any[]) => ReqResHandler;
48
48
  export declare const adapters: {
49
- express: FrameworkAdapter;
50
- koa: FrameworkAdapter;
51
- fastify: FrameworkAdapter;
52
- serveHttp: FrameworkAdapter;
53
- "std/http": FrameworkAdapter;
54
- oak: FrameworkAdapter;
55
- http: FrameworkAdapter;
56
- https: FrameworkAdapter;
57
49
  "aws-lambda": FrameworkAdapter;
58
50
  "aws-lambda-async": FrameworkAdapter;
59
51
  azure: FrameworkAdapter;
60
- "next-js": FrameworkAdapter;
61
- sveltekit: FrameworkAdapter;
62
52
  cloudflare: FrameworkAdapter;
63
53
  "cloudflare-mod": FrameworkAdapter;
54
+ express: FrameworkAdapter;
55
+ fastify: FrameworkAdapter;
64
56
  hono: FrameworkAdapter;
57
+ http: FrameworkAdapter;
58
+ https: FrameworkAdapter;
59
+ koa: FrameworkAdapter;
60
+ "next-js": FrameworkAdapter;
61
+ nhttp: FrameworkAdapter;
62
+ oak: FrameworkAdapter;
63
+ serveHttp: FrameworkAdapter;
64
+ "std/http": FrameworkAdapter;
65
+ sveltekit: FrameworkAdapter;
65
66
  worktop: FrameworkAdapter;
66
67
  };
@@ -13,111 +13,6 @@ const unauthorized = () => new Response('"unauthorized"', {
13
13
  status: 401,
14
14
  statusText: WRONG_TOKEN_ERROR,
15
15
  });
16
- /** express web framework */
17
- const express = (req, res) => ({
18
- update: Promise.resolve(req.body),
19
- header: req.header(SECRET_HEADER),
20
- end: () => res.end(),
21
- respond: (json) => {
22
- res.set("Content-Type", "application/json");
23
- res.send(json);
24
- },
25
- unauthorized: () => {
26
- res.status(401).send(WRONG_TOKEN_ERROR);
27
- },
28
- });
29
- /** koa web framework */
30
- const koa = (ctx) => ({
31
- update: Promise.resolve(ctx.request.body),
32
- header: ctx.get(SECRET_HEADER),
33
- end: () => {
34
- ctx.body = "";
35
- },
36
- respond: (json) => {
37
- ctx.set("Content-Type", "application/json");
38
- ctx.response.body = json;
39
- },
40
- unauthorized: () => {
41
- ctx.status = 401;
42
- },
43
- });
44
- /** fastify web framework */
45
- const fastify = (req, reply) => ({
46
- update: Promise.resolve(req.body),
47
- header: req.headers[SECRET_HEADER_LOWERCASE],
48
- end: () => reply.status(200).send(),
49
- respond: (json) => reply.send(json),
50
- unauthorized: () => reply.code(401).send(WRONG_TOKEN_ERROR),
51
- });
52
- const serveHttp = (requestEvent) => ({
53
- update: requestEvent.request.json(),
54
- header: requestEvent.request.headers.get(SECRET_HEADER) || undefined,
55
- end: () => requestEvent.respondWith(ok()),
56
- respond: (json) => requestEvent.respondWith(okJson(json)),
57
- unauthorized: () => requestEvent.respondWith(unauthorized()),
58
- });
59
- /** std/http web server */
60
- const stdHttp = (req) => {
61
- let resolveResponse;
62
- return {
63
- update: req.json(),
64
- header: req.headers.get(SECRET_HEADER) || undefined,
65
- end: () => {
66
- if (resolveResponse)
67
- resolveResponse(ok());
68
- },
69
- respond: (json) => {
70
- if (resolveResponse)
71
- resolveResponse(okJson(json));
72
- },
73
- unauthorized: () => {
74
- if (resolveResponse)
75
- resolveResponse(unauthorized());
76
- },
77
- handlerReturn: new Promise((resolve) => {
78
- resolveResponse = resolve;
79
- }),
80
- };
81
- };
82
- /** oak web framework */
83
- const oak = (ctx) => ({
84
- update: ctx.request.body({ type: "json" }).value,
85
- header: ctx.request.headers.get(SECRET_HEADER) || undefined,
86
- end: () => {
87
- ctx.response.status = 200;
88
- },
89
- respond: (json) => {
90
- ctx.response.type = "json";
91
- ctx.response.body = json;
92
- },
93
- unauthorized: () => {
94
- ctx.response.status = 401;
95
- },
96
- });
97
- /** Node.js native 'http' and 'https' modules */
98
- const http = (req, res) => {
99
- const secretHeaderFromRequest = req.headers[SECRET_HEADER_LOWERCASE];
100
- return {
101
- update: new Promise((resolve, reject) => {
102
- const chunks = [];
103
- req.on("data", (chunk) => chunks.push(chunk))
104
- .once("end", () => {
105
- // @ts-ignore `Buffer` is Node-only
106
- const raw = Buffer.concat(chunks).toString("utf-8");
107
- resolve(JSON.parse(raw));
108
- })
109
- .once("error", reject);
110
- }),
111
- header: Array.isArray(secretHeaderFromRequest)
112
- ? secretHeaderFromRequest[0]
113
- : secretHeaderFromRequest,
114
- end: () => res.end(),
115
- respond: (json) => res
116
- .writeHead(200, { "Content-Type": "application/json" })
117
- .end(json),
118
- unauthorized: () => res.writeHead(401).end(WRONG_TOKEN_ERROR),
119
- };
120
- };
121
16
  /** AWS lambda serverless functions */
122
17
  const awsLambda = (event, _context, callback) => ({
123
18
  update: JSON.parse(event.body),
@@ -164,37 +59,6 @@ const azure = (context, req) => ({
164
59
  context.res.send(401, WRONG_TOKEN_ERROR);
165
60
  },
166
61
  });
167
- /** Next.js Serverless Functions */
168
- const nextJs = (req, res) => ({
169
- update: Promise.resolve(req.body),
170
- header: req.headers[SECRET_HEADER_LOWERCASE],
171
- end: () => res.end(),
172
- respond: (json) => res.status(200).json(json),
173
- unauthorized: () => res.status(401).send(WRONG_TOKEN_ERROR),
174
- });
175
- /** Sveltekit Serverless Functions */
176
- const sveltekit = ({ request }) => {
177
- let resolveResponse;
178
- return {
179
- update: Promise.resolve(request.json()),
180
- header: request.headers.get(SECRET_HEADER) || undefined,
181
- end: () => {
182
- if (resolveResponse)
183
- resolveResponse(ok());
184
- },
185
- respond: (json) => {
186
- if (resolveResponse)
187
- resolveResponse(okJson(json));
188
- },
189
- unauthorized: () => {
190
- if (resolveResponse)
191
- resolveResponse(unauthorized());
192
- },
193
- handlerReturn: new Promise((resolve) => {
194
- resolveResponse = resolve;
195
- }),
196
- };
197
- };
198
62
  /** Native CloudFlare workers (service worker) */
199
63
  const cloudflare = (event) => {
200
64
  let resolveResponse;
@@ -235,6 +99,27 @@ const cloudflareModule = (request) => {
235
99
  }),
236
100
  };
237
101
  };
102
+ /** express web framework */
103
+ const express = (req, res) => ({
104
+ update: Promise.resolve(req.body),
105
+ header: req.header(SECRET_HEADER),
106
+ end: () => res.end(),
107
+ respond: (json) => {
108
+ res.set("Content-Type", "application/json");
109
+ res.send(json);
110
+ },
111
+ unauthorized: () => {
112
+ res.status(401).send(WRONG_TOKEN_ERROR);
113
+ },
114
+ });
115
+ /** fastify web framework */
116
+ const fastify = (req, reply) => ({
117
+ update: Promise.resolve(req.body),
118
+ header: req.headers[SECRET_HEADER_LOWERCASE],
119
+ end: () => reply.status(200).send(),
120
+ respond: (json) => reply.send(json),
121
+ unauthorized: () => reply.code(401).send(WRONG_TOKEN_ERROR),
122
+ });
238
123
  /** hono web framework */
239
124
  const hono = (ctx) => {
240
125
  let resolveResponse;
@@ -258,6 +143,130 @@ const hono = (ctx) => {
258
143
  }),
259
144
  };
260
145
  };
146
+ /** Node.js native 'http' and 'https' modules */
147
+ const http = (req, res) => {
148
+ const secretHeaderFromRequest = req.headers[SECRET_HEADER_LOWERCASE];
149
+ return {
150
+ update: new Promise((resolve, reject) => {
151
+ const chunks = [];
152
+ req.on("data", (chunk) => chunks.push(chunk))
153
+ .once("end", () => {
154
+ // @ts-ignore `Buffer` is Node-only
155
+ const raw = Buffer.concat(chunks).toString("utf-8");
156
+ resolve(JSON.parse(raw));
157
+ })
158
+ .once("error", reject);
159
+ }),
160
+ header: Array.isArray(secretHeaderFromRequest)
161
+ ? secretHeaderFromRequest[0]
162
+ : secretHeaderFromRequest,
163
+ end: () => res.end(),
164
+ respond: (json) => res
165
+ .writeHead(200, { "Content-Type": "application/json" })
166
+ .end(json),
167
+ unauthorized: () => res.writeHead(401).end(WRONG_TOKEN_ERROR),
168
+ };
169
+ };
170
+ /** koa web framework */
171
+ const koa = (ctx) => ({
172
+ update: Promise.resolve(ctx.request.body),
173
+ header: ctx.get(SECRET_HEADER),
174
+ end: () => {
175
+ ctx.body = "";
176
+ },
177
+ respond: (json) => {
178
+ ctx.set("Content-Type", "application/json");
179
+ ctx.response.body = json;
180
+ },
181
+ unauthorized: () => {
182
+ ctx.status = 401;
183
+ },
184
+ });
185
+ /** Next.js Serverless Functions */
186
+ const nextJs = (req, res) => ({
187
+ update: Promise.resolve(req.body),
188
+ header: req.headers[SECRET_HEADER_LOWERCASE],
189
+ end: () => res.end(),
190
+ respond: (json) => res.status(200).json(json),
191
+ unauthorized: () => res.status(401).send(WRONG_TOKEN_ERROR),
192
+ });
193
+ /** nhttp web framework */
194
+ const nhttp = (rev) => ({
195
+ update: rev.body,
196
+ header: rev.headers.get(SECRET_HEADER) || undefined,
197
+ end: () => rev.response.sendStatus(200),
198
+ respond: (json) => rev.response.status(200).send(json),
199
+ unauthorized: () => rev.response.status(401).send(WRONG_TOKEN_ERROR),
200
+ });
201
+ /** oak web framework */
202
+ const oak = (ctx) => ({
203
+ update: ctx.request.body({ type: "json" }).value,
204
+ header: ctx.request.headers.get(SECRET_HEADER) || undefined,
205
+ end: () => {
206
+ ctx.response.status = 200;
207
+ },
208
+ respond: (json) => {
209
+ ctx.response.type = "json";
210
+ ctx.response.body = json;
211
+ },
212
+ unauthorized: () => {
213
+ ctx.response.status = 401;
214
+ },
215
+ });
216
+ /** Deno.serve */
217
+ const serveHttp = (requestEvent) => ({
218
+ update: requestEvent.request.json(),
219
+ header: requestEvent.request.headers.get(SECRET_HEADER) || undefined,
220
+ end: () => requestEvent.respondWith(ok()),
221
+ respond: (json) => requestEvent.respondWith(okJson(json)),
222
+ unauthorized: () => requestEvent.respondWith(unauthorized()),
223
+ });
224
+ /** std/http web server */
225
+ const stdHttp = (req) => {
226
+ let resolveResponse;
227
+ return {
228
+ update: req.json(),
229
+ header: req.headers.get(SECRET_HEADER) || undefined,
230
+ end: () => {
231
+ if (resolveResponse)
232
+ resolveResponse(ok());
233
+ },
234
+ respond: (json) => {
235
+ if (resolveResponse)
236
+ resolveResponse(okJson(json));
237
+ },
238
+ unauthorized: () => {
239
+ if (resolveResponse)
240
+ resolveResponse(unauthorized());
241
+ },
242
+ handlerReturn: new Promise((resolve) => {
243
+ resolveResponse = resolve;
244
+ }),
245
+ };
246
+ };
247
+ /** Sveltekit Serverless Functions */
248
+ const sveltekit = ({ request }) => {
249
+ let resolveResponse;
250
+ return {
251
+ update: Promise.resolve(request.json()),
252
+ header: request.headers.get(SECRET_HEADER) || undefined,
253
+ end: () => {
254
+ if (resolveResponse)
255
+ resolveResponse(ok());
256
+ },
257
+ respond: (json) => {
258
+ if (resolveResponse)
259
+ resolveResponse(okJson(json));
260
+ },
261
+ unauthorized: () => {
262
+ if (resolveResponse)
263
+ resolveResponse(unauthorized());
264
+ },
265
+ handlerReturn: new Promise((resolve) => {
266
+ resolveResponse = resolve;
267
+ }),
268
+ };
269
+ };
261
270
  /** worktop CloudFlare workers framework */
262
271
  const worktop = (req, res) => ({
263
272
  update: Promise.resolve(req.body.json()),
@@ -266,23 +275,24 @@ const worktop = (req, res) => ({
266
275
  respond: (json) => res.send(200, json),
267
276
  unauthorized: () => res.send(401, WRONG_TOKEN_ERROR),
268
277
  });
269
- // Please open a PR if you want to add another adapter
278
+ // Please open a pull request if you want to add another adapter
270
279
  exports.adapters = {
271
- express,
272
- koa,
273
- fastify,
274
- serveHttp,
275
- "std/http": stdHttp,
276
- oak,
277
- http,
278
- https: http,
279
280
  "aws-lambda": awsLambda,
280
281
  "aws-lambda-async": awsLambdaAsync,
281
282
  azure,
282
- "next-js": nextJs,
283
- sveltekit,
284
283
  cloudflare,
285
284
  "cloudflare-mod": cloudflareModule,
285
+ express,
286
+ fastify,
286
287
  hono,
288
+ http,
289
+ https: http,
290
+ koa,
291
+ "next-js": nextJs,
292
+ nhttp,
293
+ oak,
294
+ serveHttp,
295
+ "std/http": stdHttp,
296
+ sveltekit,
287
297
  worktop,
288
298
  };
@@ -19,6 +19,8 @@ class ApiClient {
19
19
  this.call = async (method, p, signal) => {
20
20
  const payload = p !== null && p !== void 0 ? p : {};
21
21
  debug(`Calling ${method}`);
22
+ if (signal !== undefined)
23
+ validateSignal(method, payload, signal);
22
24
  // General config
23
25
  const opts = this.options;
24
26
  const formDataRequired = (0, payload_js_1.requiresFormDataUpload)(payload);
@@ -177,4 +179,27 @@ function createAbortControllerFromSignal(signal) {
177
179
  sig.addEventListener("abort", abort);
178
180
  return { abort, signal: abortController.signal };
179
181
  }
182
+ function validateSignal(method, payload, signal) {
183
+ // We use a very simple heuristic to check for AbortSignal instances
184
+ // in order to avoid doing a runtime-specific version of `instanceof`.
185
+ if (typeof (signal === null || signal === void 0 ? void 0 : signal.addEventListener) === "function") {
186
+ return;
187
+ }
188
+ let payload0 = JSON.stringify(payload);
189
+ if (payload0.length > 20) {
190
+ payload0 = payload0.substring(0, 16) + " ...";
191
+ }
192
+ let payload1 = JSON.stringify(signal);
193
+ if (payload1.length > 20) {
194
+ payload1 = payload1.substring(0, 16) + " ...";
195
+ }
196
+ throw new Error(`Incorrect abort signal instance found! \
197
+ You passed two payloads to '${method}' but you should merge \
198
+ the second one containing '${payload1}' into the first one \
199
+ containing '${payload0}'! If you are using context shortcuts, \
200
+ you may want to use a method on 'ctx.api' instead.
201
+
202
+ If you want to prevent such mistakes in the future, \
203
+ consider using TypeScript. https://www.typescriptlang.org/`);
204
+ }
180
205
  const shim_node_js_1 = require("./../shim.node.js");
package/out/web.mjs CHANGED
@@ -1581,7 +1581,16 @@ browser$1.log;
1581
1581
  browser$1.save;
1582
1582
  browser$1.storage;
1583
1583
  browser$1.useColors;
1584
- const itrToStream = (itr)=>ReadableStream.from(itr);
1584
+ const itrToStream = (itr)=>{
1585
+ const it = itr[Symbol.asyncIterator]();
1586
+ return new ReadableStream({
1587
+ async pull (controller) {
1588
+ const chunk = await it.next();
1589
+ if (chunk.done) controller.close();
1590
+ else controller.enqueue(chunk.value);
1591
+ }
1592
+ });
1593
+ };
1585
1594
  const baseFetchConfig = (_apiRoot)=>({});
1586
1595
  const defaultAdapter = "cloudflare";
1587
1596
  class GrammyError extends Error {
@@ -1892,6 +1901,7 @@ class ApiClient {
1892
1901
  this.call = async (method, p, signal)=>{
1893
1902
  const payload = p ?? {};
1894
1903
  debug(`Calling ${method}`);
1904
+ if (signal !== undefined) validateSignal(method, payload, signal);
1895
1905
  const opts = this.options;
1896
1906
  const formDataRequired = requiresFormDataUpload(payload);
1897
1907
  if (this.webhookReplyEnvelope.send !== undefined && !this.hasUsedWebhookReply && !formDataRequired && opts.canUseWebhookReply(method)) {
@@ -2036,6 +2046,27 @@ function createAbortControllerFromSignal(signal) {
2036
2046
  signal: abortController.signal
2037
2047
  };
2038
2048
  }
2049
+ function validateSignal(method, payload, signal) {
2050
+ if (typeof signal?.addEventListener === "function") {
2051
+ return;
2052
+ }
2053
+ let payload0 = JSON.stringify(payload);
2054
+ if (payload0.length > 20) {
2055
+ payload0 = payload0.substring(0, 16) + " ...";
2056
+ }
2057
+ let payload1 = JSON.stringify(signal);
2058
+ if (payload1.length > 20) {
2059
+ payload1 = payload1.substring(0, 16) + " ...";
2060
+ }
2061
+ throw new Error(`Incorrect abort signal instance found! \
2062
+ You passed two payloads to '${method}' but you should merge \
2063
+ the second one containing '${payload1}' into the first one \
2064
+ containing '${payload0}'! If you are using context shortcuts, \
2065
+ you may want to use a method on 'ctx.api' instead.
2066
+
2067
+ If you want to prevent such mistakes in the future, \
2068
+ consider using TypeScript. https://www.typescriptlang.org/`);
2069
+ }
2039
2070
  class Api {
2040
2071
  raw;
2041
2072
  config;
@@ -4120,99 +4151,6 @@ const unauthorized = ()=>new Response('"unauthorized"', {
4120
4151
  status: 401,
4121
4152
  statusText: WRONG_TOKEN_ERROR
4122
4153
  });
4123
- const express = (req, res)=>({
4124
- update: Promise.resolve(req.body),
4125
- header: req.header(SECRET_HEADER),
4126
- end: ()=>res.end(),
4127
- respond: (json)=>{
4128
- res.set("Content-Type", "application/json");
4129
- res.send(json);
4130
- },
4131
- unauthorized: ()=>{
4132
- res.status(401).send(WRONG_TOKEN_ERROR);
4133
- }
4134
- });
4135
- const koa = (ctx)=>({
4136
- update: Promise.resolve(ctx.request.body),
4137
- header: ctx.get(SECRET_HEADER),
4138
- end: ()=>{
4139
- ctx.body = "";
4140
- },
4141
- respond: (json)=>{
4142
- ctx.set("Content-Type", "application/json");
4143
- ctx.response.body = json;
4144
- },
4145
- unauthorized: ()=>{
4146
- ctx.status = 401;
4147
- }
4148
- });
4149
- const fastify = (req, reply)=>({
4150
- update: Promise.resolve(req.body),
4151
- header: req.headers[SECRET_HEADER_LOWERCASE],
4152
- end: ()=>reply.status(200).send(),
4153
- respond: (json)=>reply.send(json),
4154
- unauthorized: ()=>reply.code(401).send(WRONG_TOKEN_ERROR)
4155
- });
4156
- const serveHttp = (requestEvent)=>({
4157
- update: requestEvent.request.json(),
4158
- header: requestEvent.request.headers.get(SECRET_HEADER) || undefined,
4159
- end: ()=>requestEvent.respondWith(ok()),
4160
- respond: (json)=>requestEvent.respondWith(okJson(json)),
4161
- unauthorized: ()=>requestEvent.respondWith(unauthorized())
4162
- });
4163
- const stdHttp = (req)=>{
4164
- let resolveResponse;
4165
- return {
4166
- update: req.json(),
4167
- header: req.headers.get(SECRET_HEADER) || undefined,
4168
- end: ()=>{
4169
- if (resolveResponse) resolveResponse(ok());
4170
- },
4171
- respond: (json)=>{
4172
- if (resolveResponse) resolveResponse(okJson(json));
4173
- },
4174
- unauthorized: ()=>{
4175
- if (resolveResponse) resolveResponse(unauthorized());
4176
- },
4177
- handlerReturn: new Promise((resolve)=>{
4178
- resolveResponse = resolve;
4179
- })
4180
- };
4181
- };
4182
- const oak = (ctx)=>({
4183
- update: ctx.request.body({
4184
- type: "json"
4185
- }).value,
4186
- header: ctx.request.headers.get(SECRET_HEADER) || undefined,
4187
- end: ()=>{
4188
- ctx.response.status = 200;
4189
- },
4190
- respond: (json)=>{
4191
- ctx.response.type = "json";
4192
- ctx.response.body = json;
4193
- },
4194
- unauthorized: ()=>{
4195
- ctx.response.status = 401;
4196
- }
4197
- });
4198
- const http = (req, res)=>{
4199
- const secretHeaderFromRequest = req.headers[SECRET_HEADER_LOWERCASE];
4200
- return {
4201
- update: new Promise((resolve, reject)=>{
4202
- const chunks = [];
4203
- req.on("data", (chunk)=>chunks.push(chunk)).once("end", ()=>{
4204
- const raw = Buffer.concat(chunks).toString("utf-8");
4205
- resolve(JSON.parse(raw));
4206
- }).once("error", reject);
4207
- }),
4208
- header: Array.isArray(secretHeaderFromRequest) ? secretHeaderFromRequest[0] : secretHeaderFromRequest,
4209
- end: ()=>res.end(),
4210
- respond: (json)=>res.writeHead(200, {
4211
- "Content-Type": "application/json"
4212
- }).end(json),
4213
- unauthorized: ()=>res.writeHead(401).end(WRONG_TOKEN_ERROR)
4214
- };
4215
- };
4216
4154
  const awsLambda = (event, _context, callback)=>({
4217
4155
  update: JSON.parse(event.body),
4218
4156
  header: event.headers[SECRET_HEADER],
@@ -4268,32 +4206,6 @@ const azure = (context, req)=>({
4268
4206
  context.res.send(401, WRONG_TOKEN_ERROR);
4269
4207
  }
4270
4208
  });
4271
- const nextJs = (req, res)=>({
4272
- update: Promise.resolve(req.body),
4273
- header: req.headers[SECRET_HEADER_LOWERCASE],
4274
- end: ()=>res.end(),
4275
- respond: (json)=>res.status(200).json(json),
4276
- unauthorized: ()=>res.status(401).send(WRONG_TOKEN_ERROR)
4277
- });
4278
- const sveltekit = ({ request })=>{
4279
- let resolveResponse;
4280
- return {
4281
- update: Promise.resolve(request.json()),
4282
- header: request.headers.get(SECRET_HEADER) || undefined,
4283
- end: ()=>{
4284
- if (resolveResponse) resolveResponse(ok());
4285
- },
4286
- respond: (json)=>{
4287
- if (resolveResponse) resolveResponse(okJson(json));
4288
- },
4289
- unauthorized: ()=>{
4290
- if (resolveResponse) resolveResponse(unauthorized());
4291
- },
4292
- handlerReturn: new Promise((resolve)=>{
4293
- resolveResponse = resolve;
4294
- })
4295
- };
4296
- };
4297
4209
  const cloudflare = (event)=>{
4298
4210
  let resolveResponse;
4299
4211
  event.respondWith(new Promise((resolve)=>{
@@ -4332,6 +4244,25 @@ const cloudflareModule = (request)=>{
4332
4244
  })
4333
4245
  };
4334
4246
  };
4247
+ const express = (req, res)=>({
4248
+ update: Promise.resolve(req.body),
4249
+ header: req.header(SECRET_HEADER),
4250
+ end: ()=>res.end(),
4251
+ respond: (json)=>{
4252
+ res.set("Content-Type", "application/json");
4253
+ res.send(json);
4254
+ },
4255
+ unauthorized: ()=>{
4256
+ res.status(401).send(WRONG_TOKEN_ERROR);
4257
+ }
4258
+ });
4259
+ const fastify = (req, reply)=>({
4260
+ update: Promise.resolve(req.body),
4261
+ header: req.headers[SECRET_HEADER_LOWERCASE],
4262
+ end: ()=>reply.status(200).send(),
4263
+ respond: (json)=>reply.send(json),
4264
+ unauthorized: ()=>reply.code(401).send(WRONG_TOKEN_ERROR)
4265
+ });
4335
4266
  const hono = (ctx)=>{
4336
4267
  let resolveResponse;
4337
4268
  return {
@@ -4354,6 +4285,113 @@ const hono = (ctx)=>{
4354
4285
  })
4355
4286
  };
4356
4287
  };
4288
+ const http = (req, res)=>{
4289
+ const secretHeaderFromRequest = req.headers[SECRET_HEADER_LOWERCASE];
4290
+ return {
4291
+ update: new Promise((resolve, reject)=>{
4292
+ const chunks = [];
4293
+ req.on("data", (chunk)=>chunks.push(chunk)).once("end", ()=>{
4294
+ const raw = Buffer.concat(chunks).toString("utf-8");
4295
+ resolve(JSON.parse(raw));
4296
+ }).once("error", reject);
4297
+ }),
4298
+ header: Array.isArray(secretHeaderFromRequest) ? secretHeaderFromRequest[0] : secretHeaderFromRequest,
4299
+ end: ()=>res.end(),
4300
+ respond: (json)=>res.writeHead(200, {
4301
+ "Content-Type": "application/json"
4302
+ }).end(json),
4303
+ unauthorized: ()=>res.writeHead(401).end(WRONG_TOKEN_ERROR)
4304
+ };
4305
+ };
4306
+ const koa = (ctx)=>({
4307
+ update: Promise.resolve(ctx.request.body),
4308
+ header: ctx.get(SECRET_HEADER),
4309
+ end: ()=>{
4310
+ ctx.body = "";
4311
+ },
4312
+ respond: (json)=>{
4313
+ ctx.set("Content-Type", "application/json");
4314
+ ctx.response.body = json;
4315
+ },
4316
+ unauthorized: ()=>{
4317
+ ctx.status = 401;
4318
+ }
4319
+ });
4320
+ const nextJs = (req, res)=>({
4321
+ update: Promise.resolve(req.body),
4322
+ header: req.headers[SECRET_HEADER_LOWERCASE],
4323
+ end: ()=>res.end(),
4324
+ respond: (json)=>res.status(200).json(json),
4325
+ unauthorized: ()=>res.status(401).send(WRONG_TOKEN_ERROR)
4326
+ });
4327
+ const nhttp = (rev)=>({
4328
+ update: rev.body,
4329
+ header: rev.headers.get(SECRET_HEADER) || undefined,
4330
+ end: ()=>rev.response.sendStatus(200),
4331
+ respond: (json)=>rev.response.status(200).send(json),
4332
+ unauthorized: ()=>rev.response.status(401).send(WRONG_TOKEN_ERROR)
4333
+ });
4334
+ const oak = (ctx)=>({
4335
+ update: ctx.request.body({
4336
+ type: "json"
4337
+ }).value,
4338
+ header: ctx.request.headers.get(SECRET_HEADER) || undefined,
4339
+ end: ()=>{
4340
+ ctx.response.status = 200;
4341
+ },
4342
+ respond: (json)=>{
4343
+ ctx.response.type = "json";
4344
+ ctx.response.body = json;
4345
+ },
4346
+ unauthorized: ()=>{
4347
+ ctx.response.status = 401;
4348
+ }
4349
+ });
4350
+ const serveHttp = (requestEvent)=>({
4351
+ update: requestEvent.request.json(),
4352
+ header: requestEvent.request.headers.get(SECRET_HEADER) || undefined,
4353
+ end: ()=>requestEvent.respondWith(ok()),
4354
+ respond: (json)=>requestEvent.respondWith(okJson(json)),
4355
+ unauthorized: ()=>requestEvent.respondWith(unauthorized())
4356
+ });
4357
+ const stdHttp = (req)=>{
4358
+ let resolveResponse;
4359
+ return {
4360
+ update: req.json(),
4361
+ header: req.headers.get(SECRET_HEADER) || undefined,
4362
+ end: ()=>{
4363
+ if (resolveResponse) resolveResponse(ok());
4364
+ },
4365
+ respond: (json)=>{
4366
+ if (resolveResponse) resolveResponse(okJson(json));
4367
+ },
4368
+ unauthorized: ()=>{
4369
+ if (resolveResponse) resolveResponse(unauthorized());
4370
+ },
4371
+ handlerReturn: new Promise((resolve)=>{
4372
+ resolveResponse = resolve;
4373
+ })
4374
+ };
4375
+ };
4376
+ const sveltekit = ({ request })=>{
4377
+ let resolveResponse;
4378
+ return {
4379
+ update: Promise.resolve(request.json()),
4380
+ header: request.headers.get(SECRET_HEADER) || undefined,
4381
+ end: ()=>{
4382
+ if (resolveResponse) resolveResponse(ok());
4383
+ },
4384
+ respond: (json)=>{
4385
+ if (resolveResponse) resolveResponse(okJson(json));
4386
+ },
4387
+ unauthorized: ()=>{
4388
+ if (resolveResponse) resolveResponse(unauthorized());
4389
+ },
4390
+ handlerReturn: new Promise((resolve)=>{
4391
+ resolveResponse = resolve;
4392
+ })
4393
+ };
4394
+ };
4357
4395
  const worktop = (req, res)=>({
4358
4396
  update: Promise.resolve(req.body.json()),
4359
4397
  header: req.headers.get(SECRET_HEADER),
@@ -4362,22 +4400,23 @@ const worktop = (req, res)=>({
4362
4400
  unauthorized: ()=>res.send(401, WRONG_TOKEN_ERROR)
4363
4401
  });
4364
4402
  const adapters = {
4365
- express,
4366
- koa,
4367
- fastify,
4368
- serveHttp,
4369
- "std/http": stdHttp,
4370
- oak,
4371
- http,
4372
- https: http,
4373
4403
  "aws-lambda": awsLambda,
4374
4404
  "aws-lambda-async": awsLambdaAsync,
4375
4405
  azure,
4376
- "next-js": nextJs,
4377
- sveltekit,
4378
4406
  cloudflare,
4379
4407
  "cloudflare-mod": cloudflareModule,
4408
+ express,
4409
+ fastify,
4380
4410
  hono,
4411
+ http,
4412
+ https: http,
4413
+ koa,
4414
+ "next-js": nextJs,
4415
+ nhttp,
4416
+ oak,
4417
+ serveHttp,
4418
+ "std/http": stdHttp,
4419
+ sveltekit,
4381
4420
  worktop
4382
4421
  };
4383
4422
  const debugErr1 = browser$1("grammy:error");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "grammy",
3
3
  "description": "The Telegram Bot Framework.",
4
- "version": "1.19.0",
4
+ "version": "1.19.2",
5
5
  "author": "KnorpelSenf",
6
6
  "license": "MIT",
7
7
  "engines": {