grammy 1.19.1 → 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
  };
package/out/web.mjs CHANGED
@@ -4151,99 +4151,6 @@ const unauthorized = ()=>new Response('"unauthorized"', {
4151
4151
  status: 401,
4152
4152
  statusText: WRONG_TOKEN_ERROR
4153
4153
  });
4154
- const express = (req, res)=>({
4155
- update: Promise.resolve(req.body),
4156
- header: req.header(SECRET_HEADER),
4157
- end: ()=>res.end(),
4158
- respond: (json)=>{
4159
- res.set("Content-Type", "application/json");
4160
- res.send(json);
4161
- },
4162
- unauthorized: ()=>{
4163
- res.status(401).send(WRONG_TOKEN_ERROR);
4164
- }
4165
- });
4166
- const koa = (ctx)=>({
4167
- update: Promise.resolve(ctx.request.body),
4168
- header: ctx.get(SECRET_HEADER),
4169
- end: ()=>{
4170
- ctx.body = "";
4171
- },
4172
- respond: (json)=>{
4173
- ctx.set("Content-Type", "application/json");
4174
- ctx.response.body = json;
4175
- },
4176
- unauthorized: ()=>{
4177
- ctx.status = 401;
4178
- }
4179
- });
4180
- const fastify = (req, reply)=>({
4181
- update: Promise.resolve(req.body),
4182
- header: req.headers[SECRET_HEADER_LOWERCASE],
4183
- end: ()=>reply.status(200).send(),
4184
- respond: (json)=>reply.send(json),
4185
- unauthorized: ()=>reply.code(401).send(WRONG_TOKEN_ERROR)
4186
- });
4187
- const serveHttp = (requestEvent)=>({
4188
- update: requestEvent.request.json(),
4189
- header: requestEvent.request.headers.get(SECRET_HEADER) || undefined,
4190
- end: ()=>requestEvent.respondWith(ok()),
4191
- respond: (json)=>requestEvent.respondWith(okJson(json)),
4192
- unauthorized: ()=>requestEvent.respondWith(unauthorized())
4193
- });
4194
- const stdHttp = (req)=>{
4195
- let resolveResponse;
4196
- return {
4197
- update: req.json(),
4198
- header: req.headers.get(SECRET_HEADER) || undefined,
4199
- end: ()=>{
4200
- if (resolveResponse) resolveResponse(ok());
4201
- },
4202
- respond: (json)=>{
4203
- if (resolveResponse) resolveResponse(okJson(json));
4204
- },
4205
- unauthorized: ()=>{
4206
- if (resolveResponse) resolveResponse(unauthorized());
4207
- },
4208
- handlerReturn: new Promise((resolve)=>{
4209
- resolveResponse = resolve;
4210
- })
4211
- };
4212
- };
4213
- const oak = (ctx)=>({
4214
- update: ctx.request.body({
4215
- type: "json"
4216
- }).value,
4217
- header: ctx.request.headers.get(SECRET_HEADER) || undefined,
4218
- end: ()=>{
4219
- ctx.response.status = 200;
4220
- },
4221
- respond: (json)=>{
4222
- ctx.response.type = "json";
4223
- ctx.response.body = json;
4224
- },
4225
- unauthorized: ()=>{
4226
- ctx.response.status = 401;
4227
- }
4228
- });
4229
- const http = (req, res)=>{
4230
- const secretHeaderFromRequest = req.headers[SECRET_HEADER_LOWERCASE];
4231
- return {
4232
- update: new Promise((resolve, reject)=>{
4233
- const chunks = [];
4234
- req.on("data", (chunk)=>chunks.push(chunk)).once("end", ()=>{
4235
- const raw = Buffer.concat(chunks).toString("utf-8");
4236
- resolve(JSON.parse(raw));
4237
- }).once("error", reject);
4238
- }),
4239
- header: Array.isArray(secretHeaderFromRequest) ? secretHeaderFromRequest[0] : secretHeaderFromRequest,
4240
- end: ()=>res.end(),
4241
- respond: (json)=>res.writeHead(200, {
4242
- "Content-Type": "application/json"
4243
- }).end(json),
4244
- unauthorized: ()=>res.writeHead(401).end(WRONG_TOKEN_ERROR)
4245
- };
4246
- };
4247
4154
  const awsLambda = (event, _context, callback)=>({
4248
4155
  update: JSON.parse(event.body),
4249
4156
  header: event.headers[SECRET_HEADER],
@@ -4299,32 +4206,6 @@ const azure = (context, req)=>({
4299
4206
  context.res.send(401, WRONG_TOKEN_ERROR);
4300
4207
  }
4301
4208
  });
4302
- const nextJs = (req, res)=>({
4303
- update: Promise.resolve(req.body),
4304
- header: req.headers[SECRET_HEADER_LOWERCASE],
4305
- end: ()=>res.end(),
4306
- respond: (json)=>res.status(200).json(json),
4307
- unauthorized: ()=>res.status(401).send(WRONG_TOKEN_ERROR)
4308
- });
4309
- const sveltekit = ({ request })=>{
4310
- let resolveResponse;
4311
- return {
4312
- update: Promise.resolve(request.json()),
4313
- header: request.headers.get(SECRET_HEADER) || undefined,
4314
- end: ()=>{
4315
- if (resolveResponse) resolveResponse(ok());
4316
- },
4317
- respond: (json)=>{
4318
- if (resolveResponse) resolveResponse(okJson(json));
4319
- },
4320
- unauthorized: ()=>{
4321
- if (resolveResponse) resolveResponse(unauthorized());
4322
- },
4323
- handlerReturn: new Promise((resolve)=>{
4324
- resolveResponse = resolve;
4325
- })
4326
- };
4327
- };
4328
4209
  const cloudflare = (event)=>{
4329
4210
  let resolveResponse;
4330
4211
  event.respondWith(new Promise((resolve)=>{
@@ -4363,6 +4244,25 @@ const cloudflareModule = (request)=>{
4363
4244
  })
4364
4245
  };
4365
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
+ });
4366
4266
  const hono = (ctx)=>{
4367
4267
  let resolveResponse;
4368
4268
  return {
@@ -4385,6 +4285,113 @@ const hono = (ctx)=>{
4385
4285
  })
4386
4286
  };
4387
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
+ };
4388
4395
  const worktop = (req, res)=>({
4389
4396
  update: Promise.resolve(req.body.json()),
4390
4397
  header: req.headers.get(SECRET_HEADER),
@@ -4393,22 +4400,23 @@ const worktop = (req, res)=>({
4393
4400
  unauthorized: ()=>res.send(401, WRONG_TOKEN_ERROR)
4394
4401
  });
4395
4402
  const adapters = {
4396
- express,
4397
- koa,
4398
- fastify,
4399
- serveHttp,
4400
- "std/http": stdHttp,
4401
- oak,
4402
- http,
4403
- https: http,
4404
4403
  "aws-lambda": awsLambda,
4405
4404
  "aws-lambda-async": awsLambdaAsync,
4406
4405
  azure,
4407
- "next-js": nextJs,
4408
- sveltekit,
4409
4406
  cloudflare,
4410
4407
  "cloudflare-mod": cloudflareModule,
4408
+ express,
4409
+ fastify,
4411
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,
4412
4420
  worktop
4413
4421
  };
4414
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.1",
4
+ "version": "1.19.2",
5
5
  "author": "KnorpelSenf",
6
6
  "license": "MIT",
7
7
  "engines": {