gramio 0.4.2 → 0.4.4

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/dist/index.cjs CHANGED
@@ -6,10 +6,10 @@ var callbackData = require('@gramio/callback-data');
6
6
  var contexts = require('@gramio/contexts');
7
7
  var files = require('@gramio/files');
8
8
  var format = require('@gramio/format');
9
- var utils = require('./utils-BIdmQNPz.cjs');
9
+ var debug = require('debug');
10
+ var utils = require('./utils-CnG66NLH.cjs');
10
11
  var middlewareIo = require('middleware-io');
11
12
  var keyboards = require('@gramio/keyboards');
12
- require('debug');
13
13
 
14
14
  class Composer {
15
15
  composer = middlewareIo.Composer.builder();
@@ -518,7 +518,7 @@ class Bot {
518
518
  }
519
519
  }
520
520
  async _callApi(method, params = {}) {
521
- const debug$api$method = utils.debug$api.extend(method);
521
+ const debug$api$method = debug(`gramio:api:${method}`);
522
522
  let url = `${this.options.api.baseURL}${this.options.token}/${this.options.api.useTest ? "test/" : ""}${method}`;
523
523
  const reqOptions = {
524
524
  method: "POST",
@@ -1170,6 +1170,7 @@ const frameworks = {
1170
1170
  header: req.headers[SECRET_TOKEN_HEADER.toLowerCase()],
1171
1171
  unauthorized: () => res.writeHead(401).end(WRONG_TOKEN_ERROR)
1172
1172
  }),
1173
+ // TODO: Maybe unify it by 'WebRequest'
1173
1174
  "std/http": (req) => ({
1174
1175
  update: req.json(),
1175
1176
  header: req.headers.get(SECRET_TOKEN_HEADER),
@@ -1181,6 +1182,12 @@ const frameworks = {
1181
1182
  header: req.headers.get(SECRET_TOKEN_HEADER),
1182
1183
  response: () => responseOK,
1183
1184
  unauthorized: () => responseUnauthorized
1185
+ }),
1186
+ Request: (req) => ({
1187
+ update: req.json(),
1188
+ header: req.headers.get(SECRET_TOKEN_HEADER),
1189
+ response: () => responseOK,
1190
+ unauthorized: () => responseUnauthorized
1184
1191
  })
1185
1192
  };
1186
1193
 
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CallbackData } from '@gramio/callback-data';
2
2
  export * from '@gramio/callback-data';
3
- import { Context, UpdateName, ContextType, MaybeArray as MaybeArray$1, BotLike, Attachment } from '@gramio/contexts';
3
+ import { Context, UpdateName, ContextType, BotLike, Attachment } from '@gramio/contexts';
4
4
  export * from '@gramio/contexts';
5
5
  import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramUser, APIMethodParams, APIMethodReturn, SetWebhookParams, TelegramUpdate, TelegramReactionTypeEmojiEmoji, SetMyCommandsParams, TelegramBotCommand } from '@gramio/types';
6
6
  export * from '@gramio/types';
@@ -111,11 +111,11 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
111
111
  /** Composer */
112
112
  composer: Composer;
113
113
  /** Store plugin preRequests hooks */
114
- preRequests: [Hooks.PreRequest<any>, MaybeArray$1<keyof APIMethods> | undefined][];
114
+ preRequests: [Hooks.PreRequest<any>, MaybeArray<keyof APIMethods> | undefined][];
115
115
  /** Store plugin onResponses hooks */
116
- onResponses: [Hooks.OnResponse<any>, MaybeArray$1<keyof APIMethods> | undefined][];
116
+ onResponses: [Hooks.OnResponse<any>, MaybeArray<keyof APIMethods> | undefined][];
117
117
  /** Store plugin onResponseErrors hooks */
118
- onResponseErrors: [Hooks.OnResponseError<any>, MaybeArray$1<keyof APIMethods> | undefined][];
118
+ onResponseErrors: [Hooks.OnResponseError<any>, MaybeArray<keyof APIMethods> | undefined][];
119
119
  /**
120
120
  * Store plugin groups
121
121
  *
@@ -147,11 +147,11 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
147
147
  /** Composer */
148
148
  composer: Composer;
149
149
  /** Store plugin preRequests hooks */
150
- preRequests: [Hooks.PreRequest<any>, MaybeArray$1<keyof APIMethods> | undefined][];
150
+ preRequests: [Hooks.PreRequest<any>, MaybeArray<keyof APIMethods> | undefined][];
151
151
  /** Store plugin onResponses hooks */
152
- onResponses: [Hooks.OnResponse<any>, MaybeArray$1<keyof APIMethods> | undefined][];
152
+ onResponses: [Hooks.OnResponse<any>, MaybeArray<keyof APIMethods> | undefined][];
153
153
  /** Store plugin onResponseErrors hooks */
154
- onResponseErrors: [Hooks.OnResponseError<any>, MaybeArray$1<keyof APIMethods> | undefined][];
154
+ onResponseErrors: [Hooks.OnResponseError<any>, MaybeArray<keyof APIMethods> | undefined][];
155
155
  /**
156
156
  * Store plugin groups
157
157
  *
@@ -203,7 +203,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
203
203
  derive<Handler extends Hooks.Derive<Context<BotLike> & Derives["global"]>>(handler: Handler): Plugin<Errors, Derives & {
204
204
  global: Awaited<ReturnType<Handler>>;
205
205
  }>;
206
- derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<BotLike, Update> & Derives["global"] & Derives[Update]>>(updateName: MaybeArray$1<Update>, handler: Handler): Plugin<Errors, Derives & {
206
+ derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<BotLike, Update> & Derives["global"] & Derives[Update]>>(updateName: MaybeArray<Update>, handler: Handler): Plugin<Errors, Derives & {
207
207
  [K in Update]: Awaited<ReturnType<Handler>>;
208
208
  }>;
209
209
  decorate<Value extends Record<string, any>>(value: Value): Plugin<Errors, Derives & {
@@ -217,7 +217,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
217
217
  };
218
218
  }>;
219
219
  /** Register handler to one or many Updates */
220
- on<T extends UpdateName>(updateName: MaybeArray$1<T>, handler: Handler<ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
220
+ on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
221
221
  /** Register handler to any Updates */
222
222
  use(handler: Handler<Context<BotLike> & Derives["global"]>): this;
223
223
  /**
@@ -240,21 +240,21 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
240
240
  *
241
241
  * [Documentation](https://gramio.dev/hooks/pre-request.html)
242
242
  * */
243
- preRequest<Methods extends keyof APIMethods, Handler extends Hooks.PreRequest<Methods>>(methods: MaybeArray$1<Methods>, handler: Handler): this;
243
+ preRequest<Methods extends keyof APIMethods, Handler extends Hooks.PreRequest<Methods>>(methods: MaybeArray<Methods>, handler: Handler): this;
244
244
  preRequest(handler: Hooks.PreRequest): this;
245
245
  /**
246
246
  * This hook called when API return successful response
247
247
  *
248
248
  * [Documentation](https://gramio.dev/hooks/on-response.html)
249
249
  * */
250
- onResponse<Methods extends keyof APIMethods, Handler extends Hooks.OnResponse<Methods>>(methods: MaybeArray$1<Methods>, handler: Handler): this;
250
+ onResponse<Methods extends keyof APIMethods, Handler extends Hooks.OnResponse<Methods>>(methods: MaybeArray<Methods>, handler: Handler): this;
251
251
  onResponse(handler: Hooks.OnResponse): this;
252
252
  /**
253
253
  * This hook called when API return an error
254
254
  *
255
255
  * [Documentation](https://gramio.dev/hooks/on-response-error.html)
256
256
  * */
257
- onResponseError<Methods extends keyof APIMethods, Handler extends Hooks.OnResponseError<Methods>>(methods: MaybeArray$1<Methods>, handler: Handler): this;
257
+ onResponseError<Methods extends keyof APIMethods, Handler extends Hooks.OnResponseError<Methods>>(methods: MaybeArray<Methods>, handler: Handler): this;
258
258
  onResponseError(handler: Hooks.OnResponseError): this;
259
259
  /**
260
260
  * This hook called when the bot is `started`.
@@ -307,7 +307,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
307
307
  * })
308
308
  * ```
309
309
  */
310
- onError<T extends UpdateName>(updateName: MaybeArray$1<T>, handler: Hooks.OnError<Errors, ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
310
+ onError<T extends UpdateName>(updateName: MaybeArray<T>, handler: Hooks.OnError<Errors, ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
311
311
  onError(handler: Hooks.OnError<Errors, Context<BotLike> & Derives["global"]>): this;
312
312
  /**
313
313
  * ! ** At the moment, it can only pick up types** */
@@ -1050,6 +1050,12 @@ declare const frameworks: {
1050
1050
  response: () => Response;
1051
1051
  unauthorized: () => Response;
1052
1052
  };
1053
+ Request: (req: any) => {
1054
+ update: any;
1055
+ header: any;
1056
+ response: () => Response;
1057
+ unauthorized: () => Response;
1058
+ };
1053
1059
  };
1054
1060
 
1055
1061
  /** Union type of webhook handlers name */
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CallbackData } from '@gramio/callback-data';
2
2
  export * from '@gramio/callback-data';
3
- import { Context, UpdateName, ContextType, MaybeArray as MaybeArray$1, BotLike, Attachment } from '@gramio/contexts';
3
+ import { Context, UpdateName, ContextType, BotLike, Attachment } from '@gramio/contexts';
4
4
  export * from '@gramio/contexts';
5
5
  import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramUser, APIMethodParams, APIMethodReturn, SetWebhookParams, TelegramUpdate, TelegramReactionTypeEmojiEmoji, SetMyCommandsParams, TelegramBotCommand } from '@gramio/types';
6
6
  export * from '@gramio/types';
@@ -111,11 +111,11 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
111
111
  /** Composer */
112
112
  composer: Composer;
113
113
  /** Store plugin preRequests hooks */
114
- preRequests: [Hooks.PreRequest<any>, MaybeArray$1<keyof APIMethods> | undefined][];
114
+ preRequests: [Hooks.PreRequest<any>, MaybeArray<keyof APIMethods> | undefined][];
115
115
  /** Store plugin onResponses hooks */
116
- onResponses: [Hooks.OnResponse<any>, MaybeArray$1<keyof APIMethods> | undefined][];
116
+ onResponses: [Hooks.OnResponse<any>, MaybeArray<keyof APIMethods> | undefined][];
117
117
  /** Store plugin onResponseErrors hooks */
118
- onResponseErrors: [Hooks.OnResponseError<any>, MaybeArray$1<keyof APIMethods> | undefined][];
118
+ onResponseErrors: [Hooks.OnResponseError<any>, MaybeArray<keyof APIMethods> | undefined][];
119
119
  /**
120
120
  * Store plugin groups
121
121
  *
@@ -147,11 +147,11 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
147
147
  /** Composer */
148
148
  composer: Composer;
149
149
  /** Store plugin preRequests hooks */
150
- preRequests: [Hooks.PreRequest<any>, MaybeArray$1<keyof APIMethods> | undefined][];
150
+ preRequests: [Hooks.PreRequest<any>, MaybeArray<keyof APIMethods> | undefined][];
151
151
  /** Store plugin onResponses hooks */
152
- onResponses: [Hooks.OnResponse<any>, MaybeArray$1<keyof APIMethods> | undefined][];
152
+ onResponses: [Hooks.OnResponse<any>, MaybeArray<keyof APIMethods> | undefined][];
153
153
  /** Store plugin onResponseErrors hooks */
154
- onResponseErrors: [Hooks.OnResponseError<any>, MaybeArray$1<keyof APIMethods> | undefined][];
154
+ onResponseErrors: [Hooks.OnResponseError<any>, MaybeArray<keyof APIMethods> | undefined][];
155
155
  /**
156
156
  * Store plugin groups
157
157
  *
@@ -203,7 +203,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
203
203
  derive<Handler extends Hooks.Derive<Context<BotLike> & Derives["global"]>>(handler: Handler): Plugin<Errors, Derives & {
204
204
  global: Awaited<ReturnType<Handler>>;
205
205
  }>;
206
- derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<BotLike, Update> & Derives["global"] & Derives[Update]>>(updateName: MaybeArray$1<Update>, handler: Handler): Plugin<Errors, Derives & {
206
+ derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<BotLike, Update> & Derives["global"] & Derives[Update]>>(updateName: MaybeArray<Update>, handler: Handler): Plugin<Errors, Derives & {
207
207
  [K in Update]: Awaited<ReturnType<Handler>>;
208
208
  }>;
209
209
  decorate<Value extends Record<string, any>>(value: Value): Plugin<Errors, Derives & {
@@ -217,7 +217,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
217
217
  };
218
218
  }>;
219
219
  /** Register handler to one or many Updates */
220
- on<T extends UpdateName>(updateName: MaybeArray$1<T>, handler: Handler<ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
220
+ on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
221
221
  /** Register handler to any Updates */
222
222
  use(handler: Handler<Context<BotLike> & Derives["global"]>): this;
223
223
  /**
@@ -240,21 +240,21 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
240
240
  *
241
241
  * [Documentation](https://gramio.dev/hooks/pre-request.html)
242
242
  * */
243
- preRequest<Methods extends keyof APIMethods, Handler extends Hooks.PreRequest<Methods>>(methods: MaybeArray$1<Methods>, handler: Handler): this;
243
+ preRequest<Methods extends keyof APIMethods, Handler extends Hooks.PreRequest<Methods>>(methods: MaybeArray<Methods>, handler: Handler): this;
244
244
  preRequest(handler: Hooks.PreRequest): this;
245
245
  /**
246
246
  * This hook called when API return successful response
247
247
  *
248
248
  * [Documentation](https://gramio.dev/hooks/on-response.html)
249
249
  * */
250
- onResponse<Methods extends keyof APIMethods, Handler extends Hooks.OnResponse<Methods>>(methods: MaybeArray$1<Methods>, handler: Handler): this;
250
+ onResponse<Methods extends keyof APIMethods, Handler extends Hooks.OnResponse<Methods>>(methods: MaybeArray<Methods>, handler: Handler): this;
251
251
  onResponse(handler: Hooks.OnResponse): this;
252
252
  /**
253
253
  * This hook called when API return an error
254
254
  *
255
255
  * [Documentation](https://gramio.dev/hooks/on-response-error.html)
256
256
  * */
257
- onResponseError<Methods extends keyof APIMethods, Handler extends Hooks.OnResponseError<Methods>>(methods: MaybeArray$1<Methods>, handler: Handler): this;
257
+ onResponseError<Methods extends keyof APIMethods, Handler extends Hooks.OnResponseError<Methods>>(methods: MaybeArray<Methods>, handler: Handler): this;
258
258
  onResponseError(handler: Hooks.OnResponseError): this;
259
259
  /**
260
260
  * This hook called when the bot is `started`.
@@ -307,7 +307,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
307
307
  * })
308
308
  * ```
309
309
  */
310
- onError<T extends UpdateName>(updateName: MaybeArray$1<T>, handler: Hooks.OnError<Errors, ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
310
+ onError<T extends UpdateName>(updateName: MaybeArray<T>, handler: Hooks.OnError<Errors, ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
311
311
  onError(handler: Hooks.OnError<Errors, Context<BotLike> & Derives["global"]>): this;
312
312
  /**
313
313
  * ! ** At the moment, it can only pick up types** */
@@ -1050,6 +1050,12 @@ declare const frameworks: {
1050
1050
  response: () => Response;
1051
1051
  unauthorized: () => Response;
1052
1052
  };
1053
+ Request: (req: any) => {
1054
+ update: any;
1055
+ header: any;
1056
+ response: () => Response;
1057
+ unauthorized: () => Response;
1058
+ };
1053
1059
  };
1054
1060
 
1055
1061
  /** Union type of webhook handlers name */
package/dist/index.js CHANGED
@@ -8,10 +8,10 @@ import { isMediaUpload, convertJsonToFormData, extractFilesToFormData } from '@g
8
8
  export * from '@gramio/files';
9
9
  import { FormattableMap } from '@gramio/format';
10
10
  export * from '@gramio/format';
11
- import { E as ErrorKind, s as sleep, w as withRetries, T as TelegramError, d as debug$updates, a as debug$api, I as IS_BUN, b as simplifyObject } from './utils-CV4fnsQV.js';
11
+ import debug from 'debug';
12
+ import { E as ErrorKind, s as sleep, w as withRetries, T as TelegramError, d as debug$updates, I as IS_BUN, a as simplifyObject } from './utils-CJlBu70R.js';
12
13
  import { Composer as Composer$1, noopNext } from 'middleware-io';
13
14
  export * from '@gramio/keyboards';
14
- import 'debug';
15
15
 
16
16
  class Composer {
17
17
  composer = Composer$1.builder();
@@ -520,7 +520,7 @@ class Bot {
520
520
  }
521
521
  }
522
522
  async _callApi(method, params = {}) {
523
- const debug$api$method = debug$api.extend(method);
523
+ const debug$api$method = debug(`gramio:api:${method}`);
524
524
  let url = `${this.options.api.baseURL}${this.options.token}/${this.options.api.useTest ? "test/" : ""}${method}`;
525
525
  const reqOptions = {
526
526
  method: "POST",
@@ -1172,6 +1172,7 @@ const frameworks = {
1172
1172
  header: req.headers[SECRET_TOKEN_HEADER.toLowerCase()],
1173
1173
  unauthorized: () => res.writeHead(401).end(WRONG_TOKEN_ERROR)
1174
1174
  }),
1175
+ // TODO: Maybe unify it by 'WebRequest'
1175
1176
  "std/http": (req) => ({
1176
1177
  update: req.json(),
1177
1178
  header: req.headers.get(SECRET_TOKEN_HEADER),
@@ -1183,6 +1184,12 @@ const frameworks = {
1183
1184
  header: req.headers.get(SECRET_TOKEN_HEADER),
1184
1185
  response: () => responseOK,
1185
1186
  unauthorized: () => responseUnauthorized
1187
+ }),
1188
+ Request: (req) => ({
1189
+ update: req.json(),
1190
+ header: req.headers.get(SECRET_TOKEN_HEADER),
1191
+ response: () => responseOK,
1192
+ unauthorized: () => responseUnauthorized
1186
1193
  })
1187
1194
  };
1188
1195
 
@@ -40,9 +40,8 @@ function simplifyObject(obj) {
40
40
  return result;
41
41
  }
42
42
  const IS_BUN = typeof Bun !== "undefined";
43
- const $debugger = debug("gramio");
44
- const debug$api = $debugger.extend("api");
45
- const debug$updates = $debugger.extend("updates");
43
+ debug("gramio:api");
44
+ const debug$updates = debug("gramio:updates");
46
45
 
47
46
  async function suppressError(fn) {
48
47
  try {
@@ -67,4 +66,4 @@ async function withRetries(resultPromise) {
67
66
  return result;
68
67
  }
69
68
 
70
- export { ErrorKind as E, IS_BUN as I, TelegramError as T, debug$api as a, simplifyObject as b, debug$updates as d, sleep as s, withRetries as w };
69
+ export { ErrorKind as E, IS_BUN as I, TelegramError as T, simplifyObject as a, debug$updates as d, sleep as s, withRetries as w };
@@ -42,9 +42,8 @@ function simplifyObject(obj) {
42
42
  return result;
43
43
  }
44
44
  const IS_BUN = typeof Bun !== "undefined";
45
- const $debugger = debug("gramio");
46
- const debug$api = $debugger.extend("api");
47
- const debug$updates = $debugger.extend("updates");
45
+ debug("gramio:api");
46
+ const debug$updates = debug("gramio:updates");
48
47
 
49
48
  async function suppressError(fn) {
50
49
  try {
@@ -72,7 +71,6 @@ async function withRetries(resultPromise) {
72
71
  exports.ErrorKind = ErrorKind;
73
72
  exports.IS_BUN = IS_BUN;
74
73
  exports.TelegramError = TelegramError;
75
- exports.debug$api = debug$api;
76
74
  exports.debug$updates = debug$updates;
77
75
  exports.simplifyObject = simplifyObject;
78
76
  exports.sleep = sleep;
package/dist/utils.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var utils = require('./utils-BIdmQNPz.cjs');
3
+ var utils = require('./utils-CnG66NLH.cjs');
4
4
  require('debug');
5
5
 
6
6
 
package/dist/utils.js CHANGED
@@ -1,2 +1,2 @@
1
- export { w as withRetries } from './utils-CV4fnsQV.js';
1
+ export { w as withRetries } from './utils-CJlBu70R.js';
2
2
  import 'debug';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gramio",
3
3
  "type": "module",
4
- "version": "0.4.2",
4
+ "version": "0.4.4",
5
5
  "description": "Powerful, extensible and really type-safe Telegram Bot API framework",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",