@mtcute/node 0.2.0 → 0.3.0

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
@@ -4,7 +4,7 @@
4
4
 
5
5
  All-in-one package for NodeJS. Includes support for native crypto addon
6
6
  (must be installed separately, `@mtcute/crypto-node`), terminal I/O via
7
- `readline` and comes with pre-installed HTML and Markdown parsers.
7
+ `readline` and includes HTML and Markdown parsers.
8
8
 
9
9
  ## Usage
10
10
 
@@ -16,4 +16,8 @@ const tg = new NodeTelegramClient({
16
16
  apiHash: 'abcdef',
17
17
  storage: 'my-account'
18
18
  })
19
+
20
+ tg.run(async (user) => {
21
+ console.log(`✨ logged in as ${user.displayName}`)
22
+ })
19
23
  ```
package/cjs/index.d.ts CHANGED
@@ -1,33 +1,18 @@
1
- import { TelegramClient, TelegramClientOptions } from '@mtcute/client';
1
+ import { TelegramClient, TelegramClientOptions, User } from '@mtcute/client';
2
2
  import { SqliteStorage } from '@mtcute/sqlite';
3
3
  export * from '@mtcute/client';
4
4
  export * from '@mtcute/html-parser';
5
5
  export * from '@mtcute/markdown-parser';
6
6
  export { SqliteStorage };
7
- export interface NodeTelegramClientOptions extends Omit<TelegramClientOptions, 'storage'> {
8
- /**
9
- * Storage to use.
10
- *
11
- * You can pass a file name as a simple string,
12
- * which will be passed directly to `SqliteStorage`
13
- *
14
- * Defaults to SQLite storage in `client.session` file in
15
- * current working directory
16
- */
17
- storage?: TelegramClientOptions['storage'] | string;
18
- }
19
7
  /**
20
8
  * Tiny wrapper over {@link TelegramClient} for usage inside Node JS.
21
9
  *
22
- * This automatically sets the parse modes, native
23
- * crypto addon and defaults to SQLite session.
24
- *
25
- * Documentation for this class only contains the
26
- * difference between {@link TelegramClient} and {@link NodeTelegramClient}.
27
- * For the complete documentation, please refer to {@link TelegramClient}.
10
+ * This class automatically manages native
11
+ * crypto addon and defaults to SQLite session (unlike `TelegarmClient`,
12
+ * which defaults to a JSON file on Node).
28
13
  */
29
14
  export declare class NodeTelegramClient extends TelegramClient {
30
- constructor(opts: NodeTelegramClientOptions);
15
+ constructor(opts: TelegramClientOptions);
31
16
  private _rl?;
32
17
  /**
33
18
  * Tiny wrapper over Node `readline` package
@@ -40,4 +25,6 @@ export declare class NodeTelegramClient extends TelegramClient {
40
25
  */
41
26
  input(text: string): Promise<string>;
42
27
  close(): Promise<void>;
28
+ start(params?: Parameters<TelegramClient['start']>[0]): Promise<User>;
29
+ run(params: Parameters<TelegramClient['start']>[0] | ((user: User) => void | Promise<void>), then?: (user: User) => void | Promise<void>): void;
43
30
  }
package/cjs/index.js CHANGED
@@ -33,12 +33,9 @@ catch (e) { }
33
33
  /**
34
34
  * Tiny wrapper over {@link TelegramClient} for usage inside Node JS.
35
35
  *
36
- * This automatically sets the parse modes, native
37
- * crypto addon and defaults to SQLite session.
38
- *
39
- * Documentation for this class only contains the
40
- * difference between {@link TelegramClient} and {@link NodeTelegramClient}.
41
- * For the complete documentation, please refer to {@link TelegramClient}.
36
+ * This class automatically manages native
37
+ * crypto addon and defaults to SQLite session (unlike `TelegarmClient`,
38
+ * which defaults to a JSON file on Node).
42
39
  */
43
40
  class NodeTelegramClient extends client_1.TelegramClient {
44
41
  constructor(opts) {
@@ -73,6 +70,33 @@ class NodeTelegramClient extends client_1.TelegramClient {
73
70
  this._rl?.close();
74
71
  return super.close();
75
72
  }
73
+ start(params = {}) {
74
+ if (!params.botToken) {
75
+ if (!params.phone)
76
+ params.phone = () => this.input('phone > ');
77
+ if (!params.code)
78
+ params.code = () => this.input('code > ');
79
+ if (!params.password) {
80
+ params.password = () => this.input('2fa password > ');
81
+ }
82
+ }
83
+ return super.start(params).then((user) => {
84
+ if (this._rl) {
85
+ this._rl.close();
86
+ delete this._rl;
87
+ }
88
+ return user;
89
+ });
90
+ }
91
+ run(params, then) {
92
+ if (typeof params === 'function') {
93
+ then = params;
94
+ params = {};
95
+ }
96
+ this.start(params)
97
+ .then(then)
98
+ .catch((err) => this._emitError(err));
99
+ }
76
100
  }
77
101
  exports.NodeTelegramClient = NodeTelegramClient;
78
102
  //# sourceMappingURL=index.js.map
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,uCAAoE;AAEpE,2CAAsE;AACtE,2CAA8C;AAKrC,8FALA,sBAAa,OAKA;AAHtB,iDAA8B;AAC9B,sDAAmC;AACnC,0DAAuC;AAGvC,8DAA8D;AAC9D,IAAI,YAAiB,CAAA;AAErB,IAAI;IACA,GAAG;IACH,2BAA2B;IAC3B,YAAY,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC,wBAAwB,CAAA;CACzE;AAAC,OAAO,CAAC,EAAE,GAAE;AAed;;;;;;;;;GASG;AACH,MAAa,kBAAmB,SAAQ,uBAAc;IAClD,YAAY,IAA+B;QACvC,KAAK,CAAC;YACF,2BAA2B;YAC3B,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,YAAY,EAAE,CAAC,CAAC,CAAC,SAAS;YAC3D,GAAG,IAAI;YACP,OAAO,EACH,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC;gBAC9B,IAAI,sBAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;gBACjC,IAAI,CAAC,OAAO,IAAI,IAAI,sBAAa,CAAC,gBAAgB,CAAC;SAC9D,CAAC,CAAA;IACN,CAAC;IAID;;;;;;;;OAQG;IACH,KAAK,CAAC,IAAY;QACd,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;YACX,IAAI,CAAC,GAAG,GAAG,IAAA,0BAAe,EAAC;gBACvB,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,MAAM,EAAE,OAAO,CAAC,MAAM;aACzB,CAAC,CAAA;SACL;QAED,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAA;IAC9D,CAAC;IAED,KAAK;QACD,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,CAAA;QAEjB,OAAO,KAAK,CAAC,KAAK,EAAE,CAAA;IACxB,CAAC;CACJ;AAxCD,gDAwCC","sourcesContent":["import { createRequire } from 'module'\nimport { createInterface, Interface as RlInterface } from 'readline'\n\nimport { TelegramClient, TelegramClientOptions } from '@mtcute/client'\nimport { SqliteStorage } from '@mtcute/sqlite'\n\nexport * from '@mtcute/client'\nexport * from '@mtcute/html-parser'\nexport * from '@mtcute/markdown-parser'\nexport { SqliteStorage }\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nlet nativeCrypto: any\n\ntry {\n // \n // eslint-disable-next-line\n nativeCrypto = require('@mtcute/crypto-node').NodeNativeCryptoProvider\n} catch (e) {}\n\nexport interface NodeTelegramClientOptions extends Omit<TelegramClientOptions, 'storage'> {\n /**\n * Storage to use.\n *\n * You can pass a file name as a simple string,\n * which will be passed directly to `SqliteStorage`\n *\n * Defaults to SQLite storage in `client.session` file in\n * current working directory\n */\n storage?: TelegramClientOptions['storage'] | string\n}\n\n/**\n * Tiny wrapper over {@link TelegramClient} for usage inside Node JS.\n *\n * This automatically sets the parse modes, native\n * crypto addon and defaults to SQLite session.\n *\n * Documentation for this class only contains the\n * difference between {@link TelegramClient} and {@link NodeTelegramClient}.\n * For the complete documentation, please refer to {@link TelegramClient}.\n */\nexport class NodeTelegramClient extends TelegramClient {\n constructor(opts: NodeTelegramClientOptions) {\n super({\n // eslint-disable-next-line\n crypto: nativeCrypto ? () => new nativeCrypto() : undefined,\n ...opts,\n storage:\n typeof opts.storage === 'string' ?\n new SqliteStorage(opts.storage) :\n opts.storage ?? new SqliteStorage('client.session'),\n })\n }\n\n private _rl?: RlInterface\n\n /**\n * Tiny wrapper over Node `readline` package\n * for simpler user input for `.run()` method.\n *\n * Associated `readline` interface is closed\n * after `run()` returns, or with the client.\n *\n * @param text Text of the question\n */\n input(text: string): Promise<string> {\n if (!this._rl) {\n this._rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n })\n }\n\n return new Promise((res) => this._rl?.question(text, res))\n }\n\n close(): Promise<void> {\n this._rl?.close()\n\n return super.close()\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,uCAAoE;AAEpE,2CAA4E;AAC5E,2CAA8C;AAKrC,8FALA,sBAAa,OAKA;AAHtB,iDAA8B;AAC9B,sDAAmC;AACnC,0DAAuC;AAGvC,8DAA8D;AAC9D,IAAI,YAAiB,CAAA;AAErB,IAAI;IACA,GAAG;IACH,2BAA2B;IAC3B,YAAY,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC,wBAAwB,CAAA;CACzE;AAAC,OAAO,CAAC,EAAE,GAAE;AAEd;;;;;;GAMG;AACH,MAAa,kBAAmB,SAAQ,uBAAc;IAClD,YAAY,IAA2B;QACnC,KAAK,CAAC;YACF,2BAA2B;YAC3B,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,YAAY,EAAE,CAAC,CAAC,CAAC,SAAS;YAC3D,GAAG,IAAI;YACP,OAAO,EACH,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC;gBAC9B,IAAI,sBAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;gBACjC,IAAI,CAAC,OAAO,IAAI,IAAI,sBAAa,CAAC,gBAAgB,CAAC;SAC9D,CAAC,CAAA;IACN,CAAC;IAID;;;;;;;;OAQG;IACH,KAAK,CAAC,IAAY;QACd,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;YACX,IAAI,CAAC,GAAG,GAAG,IAAA,0BAAe,EAAC;gBACvB,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,MAAM,EAAE,OAAO,CAAC,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IAAI,CAAC,IAAI,CAAC;aACV,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAA;IAC7C,CAAC;CACJ;AA1ED,gDA0EC","sourcesContent":["import { createRequire } from 'module'\nimport { createInterface, Interface as RlInterface } from 'readline'\n\nimport { TelegramClient, TelegramClientOptions, User } from '@mtcute/client'\nimport { SqliteStorage } from '@mtcute/sqlite'\n\nexport * from '@mtcute/client'\nexport * from '@mtcute/html-parser'\nexport * from '@mtcute/markdown-parser'\nexport { SqliteStorage }\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nlet nativeCrypto: any\n\ntry {\n // \n // eslint-disable-next-line\n nativeCrypto = require('@mtcute/crypto-node').NodeNativeCryptoProvider\n} catch (e) {}\n\n/**\n * Tiny wrapper over {@link TelegramClient} for usage inside Node JS.\n *\n * This class automatically manages native\n * crypto addon and defaults to SQLite session (unlike `TelegarmClient`,\n * which defaults to a JSON file on Node).\n */\nexport class NodeTelegramClient extends TelegramClient {\n constructor(opts: TelegramClientOptions) {\n super({\n // eslint-disable-next-line\n crypto: nativeCrypto ? () => new nativeCrypto() : undefined,\n ...opts,\n storage:\n typeof opts.storage === 'string' ?\n new SqliteStorage(opts.storage) :\n opts.storage ?? new SqliteStorage('client.session'),\n })\n }\n\n private _rl?: RlInterface\n\n /**\n * Tiny wrapper over Node `readline` package\n * for simpler user input for `.run()` method.\n *\n * Associated `readline` interface is closed\n * after `run()` returns, or with the client.\n *\n * @param text Text of the question\n */\n input(text: string): Promise<string> {\n if (!this._rl) {\n this._rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n })\n }\n\n return new Promise((res) => this._rl?.question(text, res))\n }\n\n close(): Promise<void> {\n this._rl?.close()\n\n return super.close()\n }\n\n start(params: Parameters<TelegramClient['start']>[0] = {}): Promise<User> {\n if (!params.botToken) {\n if (!params.phone) params.phone = () => this.input('phone > ')\n if (!params.code) params.code = () => this.input('code > ')\n\n if (!params.password) {\n params.password = () => this.input('2fa password > ')\n }\n }\n\n return super.start(params).then((user) => {\n if (this._rl) {\n this._rl.close()\n delete this._rl\n }\n\n return user\n })\n }\n\n run(\n params: Parameters<TelegramClient['start']>[0] | ((user: User) => void | Promise<void>),\n then?: (user: User) => void | Promise<void>,\n ): void {\n if (typeof params === 'function') {\n then = params\n params = {}\n }\n\n this.start(params)\n .then(then)\n .catch((err) => this._emitError(err))\n }\n}\n"]}
package/esm/index.d.ts CHANGED
@@ -1,33 +1,18 @@
1
- import { TelegramClient, TelegramClientOptions } from '@mtcute/client';
1
+ import { TelegramClient, TelegramClientOptions, User } from '@mtcute/client';
2
2
  import { SqliteStorage } from '@mtcute/sqlite';
3
3
  export * from '@mtcute/client';
4
4
  export * from '@mtcute/html-parser';
5
5
  export * from '@mtcute/markdown-parser';
6
6
  export { SqliteStorage };
7
- export interface NodeTelegramClientOptions extends Omit<TelegramClientOptions, 'storage'> {
8
- /**
9
- * Storage to use.
10
- *
11
- * You can pass a file name as a simple string,
12
- * which will be passed directly to `SqliteStorage`
13
- *
14
- * Defaults to SQLite storage in `client.session` file in
15
- * current working directory
16
- */
17
- storage?: TelegramClientOptions['storage'] | string;
18
- }
19
7
  /**
20
8
  * Tiny wrapper over {@link TelegramClient} for usage inside Node JS.
21
9
  *
22
- * This automatically sets the parse modes, native
23
- * crypto addon and defaults to SQLite session.
24
- *
25
- * Documentation for this class only contains the
26
- * difference between {@link TelegramClient} and {@link NodeTelegramClient}.
27
- * For the complete documentation, please refer to {@link TelegramClient}.
10
+ * This class automatically manages native
11
+ * crypto addon and defaults to SQLite session (unlike `TelegarmClient`,
12
+ * which defaults to a JSON file on Node).
28
13
  */
29
14
  export declare class NodeTelegramClient extends TelegramClient {
30
- constructor(opts: NodeTelegramClientOptions);
15
+ constructor(opts: TelegramClientOptions);
31
16
  private _rl?;
32
17
  /**
33
18
  * Tiny wrapper over Node `readline` package
@@ -40,4 +25,6 @@ export declare class NodeTelegramClient extends TelegramClient {
40
25
  */
41
26
  input(text: string): Promise<string>;
42
27
  close(): Promise<void>;
28
+ start(params?: Parameters<TelegramClient['start']>[0]): Promise<User>;
29
+ run(params: Parameters<TelegramClient['start']>[0] | ((user: User) => void | Promise<void>), then?: (user: User) => void | Promise<void>): void;
43
30
  }
package/esm/index.js CHANGED
@@ -19,12 +19,9 @@ catch (e) { }
19
19
  /**
20
20
  * Tiny wrapper over {@link TelegramClient} for usage inside Node JS.
21
21
  *
22
- * This automatically sets the parse modes, native
23
- * crypto addon and defaults to SQLite session.
24
- *
25
- * Documentation for this class only contains the
26
- * difference between {@link TelegramClient} and {@link NodeTelegramClient}.
27
- * For the complete documentation, please refer to {@link TelegramClient}.
22
+ * This class automatically manages native
23
+ * crypto addon and defaults to SQLite session (unlike `TelegarmClient`,
24
+ * which defaults to a JSON file on Node).
28
25
  */
29
26
  export class NodeTelegramClient extends TelegramClient {
30
27
  constructor(opts) {
@@ -59,5 +56,32 @@ export class NodeTelegramClient extends TelegramClient {
59
56
  this._rl?.close();
60
57
  return super.close();
61
58
  }
59
+ start(params = {}) {
60
+ if (!params.botToken) {
61
+ if (!params.phone)
62
+ params.phone = () => this.input('phone > ');
63
+ if (!params.code)
64
+ params.code = () => this.input('code > ');
65
+ if (!params.password) {
66
+ params.password = () => this.input('2fa password > ');
67
+ }
68
+ }
69
+ return super.start(params).then((user) => {
70
+ if (this._rl) {
71
+ this._rl.close();
72
+ delete this._rl;
73
+ }
74
+ return user;
75
+ });
76
+ }
77
+ run(params, then) {
78
+ if (typeof params === 'function') {
79
+ then = params;
80
+ params = {};
81
+ }
82
+ this.start(params)
83
+ .then(then)
84
+ .catch((err) => this._emitError(err));
85
+ }
62
86
  }
63
87
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AACtC,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O,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAA;IAC9D,CAAC;IAED,KAAK;QACD,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,CAAA;QAEjB,OAAO,KAAK,CAAC,KAAK,EAAE,CAAA;IACxB,CAAC;CACJ","sourcesContent":["import { createRequire } from 'module'\nimport { createInterface, Interface as RlInterface } from 'readline'\n\nimport { TelegramClient, TelegramClientOptions } from '@mtcute/client'\nimport { SqliteStorage } from '@mtcute/sqlite'\n\nexport * from '@mtcute/client'\nexport * from '@mtcute/html-parser'\nexport * from '@mtcute/markdown-parser'\nexport { SqliteStorage }\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nlet nativeCrypto: any\n\ntry {\n // @only-if-esm\n const require = createRequire(import.meta.url)\n // @/only-if-esm\n // eslint-disable-next-line\n nativeCrypto = require('@mtcute/crypto-node').NodeNativeCryptoProvider\n} catch (e) {}\n\nexport interface NodeTelegramClientOptions extends Omit<TelegramClientOptions, 'storage'> {\n /**\n * Storage to use.\n *\n * You can pass a file name as a simple string,\n * which will be passed directly to `SqliteStorage`\n *\n * Defaults to SQLite storage in `client.session` file in\n * current working directory\n */\n storage?: TelegramClientOptions['storage'] | string\n}\n\n/**\n * Tiny wrapper over {@link TelegramClient} for usage inside Node JS.\n *\n * This automatically sets the parse modes, native\n * crypto addon and defaults to SQLite session.\n *\n * Documentation for this class only contains the\n * difference between {@link TelegramClient} and {@link NodeTelegramClient}.\n * For the complete documentation, please refer to {@link TelegramClient}.\n */\nexport class NodeTelegramClient extends TelegramClient {\n constructor(opts: NodeTelegramClientOptions) {\n super({\n // eslint-disable-next-line\n crypto: nativeCrypto ? () => new nativeCrypto() : undefined,\n ...opts,\n storage:\n typeof opts.storage === 'string' ?\n new SqliteStorage(opts.storage) :\n opts.storage ?? new SqliteStorage('client.session'),\n })\n }\n\n private _rl?: RlInterface\n\n /**\n * Tiny wrapper over Node `readline` package\n * for simpler user input for `.run()` method.\n *\n * Associated `readline` interface is closed\n * after `run()` returns, or with the client.\n *\n * @param text Text of the question\n */\n input(text: string): Promise<string> {\n if (!this._rl) {\n this._rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n })\n }\n\n return new Promise((res) => this._rl?.question(text, res))\n }\n\n close(): Promise<void> {\n this._rl?.close()\n\n return super.close()\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,eAAe,EAA4B,MAAM,UAAU,CAAA;AAEpE,OAAO,EAAE,cAAc,EAA+B,MAAM,gBAAgB,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE9C,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,yBAAyB,CAAA;AACvC,OAAO,EAAE,aAAa,EAAE,CAAA;AAExB,8DAA8D;AAC9D,IAAI,YAAiB,CAAA;AAErB,IAAI;IACA,eAAe;IACf,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC9C,gBAAgB;IAChB,2BAA2B;IAC3B,YAAY,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC,wBAAwB,CAAA;CACzE;AAAC,OAAO,CAAC,EAAE,GAAE;AAEd;;;;;;GAMG;AACH,MAAM,OAAO,kBAAmB,SAAQ,cAAc;IAClD,YAAY,IAA2B;QACnC,KAAK,CAAC;YACF,2BAA2B;YAC3B,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,YAAY,EAAE,CAAC,CAAC,CAAC,SAAS;YAC3D,GAAG,IAAI;YACP,OAAO,EACH,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC;gBAC9B,IA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gBACV,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;gBAChB,OAAO,IAAI,CAAC,GAAG,CAAA;aAClB;YAED,OAAO,IAAI,CAAA;QACf,CAAC,CAAC,CAAA;IACN,CAAC;IAED,GAAG,CACC,MAAuF,EACvF,IAA2C;QAE3C,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE;YAC9B,IAAI,GAAG,MAAM,CAAA;YACb,MAAM,GAAG,EAAE,CAAA;SACd;QAED,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;aACb,IAAI,CAAC,IAAI,CAAC;aACV,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAA;IAC7C,CAAC;CACJ","sourcesContent":["import { createRequire } from 'module'\nimport { createInterface, Interface as RlInterface } from 'readline'\n\nimport { TelegramClient, TelegramClientOptions, User } from '@mtcute/client'\nimport { SqliteStorage } from '@mtcute/sqlite'\n\nexport * from '@mtcute/client'\nexport * from '@mtcute/html-parser'\nexport * from '@mtcute/markdown-parser'\nexport { SqliteStorage }\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nlet nativeCrypto: any\n\ntry {\n // @only-if-esm\n const require = createRequire(import.meta.url)\n // @/only-if-esm\n // eslint-disable-next-line\n nativeCrypto = require('@mtcute/crypto-node').NodeNativeCryptoProvider\n} catch (e) {}\n\n/**\n * Tiny wrapper over {@link TelegramClient} for usage inside Node JS.\n *\n * This class automatically manages native\n * crypto addon and defaults to SQLite session (unlike `TelegarmClient`,\n * which defaults to a JSON file on Node).\n */\nexport class NodeTelegramClient extends TelegramClient {\n constructor(opts: TelegramClientOptions) {\n super({\n // eslint-disable-next-line\n crypto: nativeCrypto ? () => new nativeCrypto() : undefined,\n ...opts,\n storage:\n typeof opts.storage === 'string' ?\n new SqliteStorage(opts.storage) :\n opts.storage ?? new SqliteStorage('client.session'),\n })\n }\n\n private _rl?: RlInterface\n\n /**\n * Tiny wrapper over Node `readline` package\n * for simpler user input for `.run()` method.\n *\n * Associated `readline` interface is closed\n * after `run()` returns, or with the client.\n *\n * @param text Text of the question\n */\n input(text: string): Promise<string> {\n if (!this._rl) {\n this._rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n })\n }\n\n return new Promise((res) => this._rl?.question(text, res))\n }\n\n close(): Promise<void> {\n this._rl?.close()\n\n return super.close()\n }\n\n start(params: Parameters<TelegramClient['start']>[0] = {}): Promise<User> {\n if (!params.botToken) {\n if (!params.phone) params.phone = () => this.input('phone > ')\n if (!params.code) params.code = () => this.input('code > ')\n\n if (!params.password) {\n params.password = () => this.input('2fa password > ')\n }\n }\n\n return super.start(params).then((user) => {\n if (this._rl) {\n this._rl.close()\n delete this._rl\n }\n\n return user\n })\n }\n\n run(\n params: Parameters<TelegramClient['start']>[0] | ((user: User) => void | Promise<void>),\n then?: (user: User) => void | Promise<void>,\n ): void {\n if (typeof params === 'function') {\n then = params\n params = {}\n }\n\n this.start(params)\n .then(then)\n .catch((err) => this._emitError(err))\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mtcute/node",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Meta-package for Node JS",
5
5
  "author": "Alina Sireneva <alina@tei.su>",
6
6
  "license": "MIT",
@@ -8,10 +8,10 @@
8
8
  "type": "module",
9
9
  "scripts": {},
10
10
  "dependencies": {
11
- "@mtcute/client": "^0.2.0",
12
- "@mtcute/sqlite": "^0.2.0",
13
- "@mtcute/markdown-parser": "^0.2.0",
14
- "@mtcute/html-parser": "^0.2.0"
11
+ "@mtcute/client": "^0.3.0",
12
+ "@mtcute/sqlite": "^0.3.0",
13
+ "@mtcute/markdown-parser": "^0.3.0",
14
+ "@mtcute/html-parser": "^0.3.0"
15
15
  },
16
16
  "module": "esm/index.js",
17
17
  "exports": {