gramio 0.0.3 → 0.0.5

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/bot.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { ApiMethods } from "@gramio/types";
2
+ import "reflect-metadata";
3
+ import { BotOptions } from "./types";
4
+ import { Updates } from "./updates";
5
+ export declare class Bot {
6
+ readonly options: BotOptions;
7
+ readonly api: ApiMethods;
8
+ updates: Updates;
9
+ private _callApi;
10
+ constructor(token: string, options?: Omit<BotOptions, "token">);
11
+ }
12
+ export * from "@gramio/types";
package/dist/bot.js ADDED
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Bot = void 0;
10
+ const files_1 = require("@gramio/files");
11
+ const format_1 = require("@gramio/format");
12
+ const form_data_encoder_1 = require("form-data-encoder");
13
+ const inspectable_1 = require("inspectable");
14
+ require("reflect-metadata");
15
+ const undici_1 = require("undici");
16
+ const apiErrors_1 = require("./apiErrors");
17
+ const updates_1 = require("./updates");
18
+ let Bot = class Bot {
19
+ options = {};
20
+ api = new Proxy({}, {
21
+ get: (_target, method) => (args) => this._callApi(method, args),
22
+ });
23
+ updates = new updates_1.Updates(this);
24
+ async _callApi(method, params = {}) {
25
+ const url = `https://api.telegram.org/bot${this.options.token}/${method}`;
26
+ const reqOptions = {
27
+ method: "POST",
28
+ duplex: "half",
29
+ };
30
+ const formattable = format_1.FormattableMap[method];
31
+ // biome-ignore lint/style/noParameterAssign: mutate formattable
32
+ if (formattable && params)
33
+ params = formattable(params);
34
+ if ((0, files_1.isMediaUpload)(method, params || {})) {
35
+ const formData = await (0, files_1.convertJsonToFormData)(method, params || {});
36
+ const encoder = new form_data_encoder_1.FormDataEncoder(formData);
37
+ reqOptions.body = encoder.encode();
38
+ reqOptions.headers = encoder.headers;
39
+ }
40
+ else {
41
+ reqOptions.headers = {
42
+ "Content-Type": "application/json",
43
+ };
44
+ reqOptions.body = JSON.stringify(params);
45
+ }
46
+ const response = await (0, undici_1.fetch)(url, reqOptions);
47
+ const data = (await response.json());
48
+ if (!data.ok)
49
+ throw new apiErrors_1.APIError({ method, params }, data);
50
+ return data.result;
51
+ }
52
+ constructor(token, options) {
53
+ this.options = { ...options, token };
54
+ }
55
+ };
56
+ exports.Bot = Bot;
57
+ exports.Bot = Bot = __decorate([
58
+ (0, inspectable_1.Inspectable)({
59
+ serialize: () => ({}),
60
+ })
61
+ ], Bot);
package/dist/index.d.ts CHANGED
@@ -1,12 +1,7 @@
1
- import type { ApiMethods } from "@gramio/types";
2
- import "reflect-metadata";
3
- import { BotOptions } from "./types";
4
- import { Updates } from "./updates";
5
- export declare class Bot {
6
- readonly options: BotOptions;
7
- readonly api: ApiMethods;
8
- updates: Updates;
9
- private _callApi;
10
- constructor(token: string, options?: Omit<BotOptions, "token">);
11
- }
1
+ export * from "./bot";
2
+ export * from "./apiErrors";
3
+ export * from "./types";
4
+ export * from "@gramio/contexts";
5
+ export * from "@gramio/files";
6
+ export * from "@gramio/keyboards";
12
7
  export * from "@gramio/types";
package/dist/index.js CHANGED
@@ -10,62 +10,15 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
14
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
17
- return c > 3 && r && Object.defineProperty(target, key, r), r;
18
- };
19
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
15
  };
22
16
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.Bot = void 0;
24
- const files_1 = require("@gramio/files");
25
- const form_data_encoder_1 = require("form-data-encoder");
26
- const inspectable_1 = require("inspectable");
27
- require("reflect-metadata");
28
- const undici_1 = require("undici");
29
- const apiErrors_1 = require("./apiErrors");
30
- const updates_1 = require("./updates");
31
- let Bot = class Bot {
32
- options = {};
33
- api = new Proxy({}, {
34
- get: (_target, method) => (args) => this._callApi(method, args),
35
- });
36
- updates = new updates_1.Updates(this);
37
- async _callApi(method, params = {}) {
38
- const url = `https://api.telegram.org/bot${this.options.token}/${method}`;
39
- const reqOptions = {
40
- method: "POST",
41
- duplex: "half",
42
- };
43
- if ((0, files_1.isMediaUpload)(method, params)) {
44
- const formData = await (0, files_1.convertJsonToFormData)(method, params);
45
- const encoder = new form_data_encoder_1.FormDataEncoder(formData);
46
- reqOptions.body = encoder.encode();
47
- reqOptions.headers = encoder.headers;
48
- }
49
- else {
50
- reqOptions.headers = {
51
- "Content-Type": "application/json",
52
- };
53
- reqOptions.body = JSON.stringify(params);
54
- }
55
- const response = await (0, undici_1.fetch)(url, reqOptions);
56
- const data = (await response.json());
57
- if (!data.ok)
58
- throw new apiErrors_1.APIError({ method, params }, data);
59
- return data.result;
60
- }
61
- constructor(token, options) {
62
- this.options = { ...options, token };
63
- }
64
- };
65
- exports.Bot = Bot;
66
- exports.Bot = Bot = __decorate([
67
- (0, inspectable_1.Inspectable)({
68
- serialize: () => ({}),
69
- })
70
- ], Bot);
17
+ __exportStar(require("./bot"), exports);
18
+ __exportStar(require("./apiErrors"), exports);
19
+ __exportStar(require("./types"), exports);
20
+ __exportStar(require("@gramio/contexts"), exports);
21
+ __exportStar(require("@gramio/files"), exports);
22
+ __exportStar(require("@gramio/keyboards"), exports);
71
23
  __exportStar(require("@gramio/types"), exports);
24
+ __exportStar(require("@gramio/format"), exports);
package/dist/updates.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Context, contextsMappings } from "@gramio/contexts";
2
2
  import type { TelegramUpdate } from "@gramio/types";
3
- import { Bot } from ".";
3
+ import { Bot } from "./bot";
4
4
  import { THandler, UpdateNames } from "./types";
5
5
  export declare class Updates {
6
6
  private readonly bot;
package/dist/updates.js CHANGED
@@ -29,6 +29,7 @@ class Updates {
29
29
  this.offset = data.update_id + 1;
30
30
  try {
31
31
  const context = new contexts_1.contextsMappings[updateType]({
32
+ // @ts-expect-error
32
33
  bot: this.bot,
33
34
  update: data,
34
35
  //TODO: fix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gramio",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "WIP",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -17,6 +17,9 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@gramio/contexts": "^0.0.1",
20
+ "@gramio/files": "^0.0.2",
21
+ "@gramio/format": "^0.0.2",
22
+ "@gramio/keyboards": "^0.1.6",
20
23
  "form-data-encoder": "^4.0.2",
21
24
  "inspectable": "^2.1.0",
22
25
  "middleware-io": "^2.8.1",