@mtcute/node 0.4.0 → 0.7.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/cjs/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { TelegramClient, TelegramClientOptions, User } from '@mtcute/client';
1
+ import { TelegramClient, TelegramClientOptions, User } from '@mtcute/core';
2
2
  import { SqliteStorage } from '@mtcute/sqlite';
3
- export * from '@mtcute/client';
3
+ export * from '@mtcute/core';
4
4
  export * from '@mtcute/html-parser';
5
5
  export * from '@mtcute/markdown-parser';
6
6
  export { SqliteStorage };
package/cjs/index.js CHANGED
@@ -16,10 +16,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.NodeTelegramClient = exports.SqliteStorage = void 0;
18
18
  const readline_1 = require("readline");
19
- const client_1 = require("@mtcute/client");
19
+ const core_1 = require("@mtcute/core");
20
20
  const sqlite_1 = require("@mtcute/sqlite");
21
21
  Object.defineProperty(exports, "SqliteStorage", { enumerable: true, get: function () { return sqlite_1.SqliteStorage; } });
22
- __exportStar(require("@mtcute/client"), exports);
22
+ __exportStar(require("@mtcute/core"), exports);
23
23
  __exportStar(require("@mtcute/html-parser"), exports);
24
24
  __exportStar(require("@mtcute/markdown-parser"), exports);
25
25
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -37,8 +37,12 @@ catch (e) { }
37
37
  * crypto addon and defaults to SQLite session (unlike `TelegarmClient`,
38
38
  * which defaults to a JSON file on Node).
39
39
  */
40
- class NodeTelegramClient extends client_1.TelegramClient {
40
+ class NodeTelegramClient extends core_1.TelegramClient {
41
41
  constructor(opts) {
42
+ if ('client' in opts) {
43
+ super(opts);
44
+ return;
45
+ }
42
46
  super({
43
47
  // eslint-disable-next-line
44
48
  crypto: nativeCrypto ? () => new nativeCrypto() : undefined,
@@ -95,7 +99,7 @@ class NodeTelegramClient extends client_1.TelegramClient {
95
99
  }
96
100
  this.start(params)
97
101
  .then(then)
98
- .catch((err) => this._emitError(err));
102
+ .catch((err) => this.emitError(err));
99
103
  }
100
104
  }
101
105
  exports.NodeTelegramClient = NodeTelegramClient;
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
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,MAAM;aACzB,CAAC,CAAA;SACL;QAED,OAAO,I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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"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,uCAAoE;AAEpE,uCAA0E;AAC1E,2CAA8C;AAKrC,8FALA,sBAAa,OAKA;AAHtB,+CAA4B;AAC5B,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,qBAAc;IAClD,YAAY,IAA2B;QACnC,IAAI,QAAQ,IAAI,IAAI,EAAE;YAClB,KAAK,CAAC,IAAI,CAAC,CAAA;YAEX,OAAM;SACT;QAED,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,CAA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M,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,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;IAC5C,CAAC;CACJ;AAhFD,gDAgFC","sourcesContent":["import { createRequire } from 'module'\nimport { createInterface, Interface as RlInterface } from 'readline'\n\nimport { TelegramClient, TelegramClientOptions, User } from '@mtcute/core'\nimport { SqliteStorage } from '@mtcute/sqlite'\n\nexport * from '@mtcute/core'\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 if ('client' in opts) {\n super(opts)\n\n return\n }\n\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/cjs/utils.d.ts CHANGED
@@ -1 +1 @@
1
- export * from '@mtcute/client/utils.js';
1
+ export * from '@mtcute/core/utils.js';
package/cjs/utils.js CHANGED
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("@mtcute/client/utils.js"), exports);
17
+ __exportStar(require("@mtcute/core/utils.js"), exports);
18
18
  //# sourceMappingURL=utils.js.map
package/cjs/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAuC","sourcesContent":["export * from '@mtcute/client/utils.js'\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAqC","sourcesContent":["export * from '@mtcute/core/utils.js'\n"]}
package/esm/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { TelegramClient, TelegramClientOptions, User } from '@mtcute/client';
1
+ import { TelegramClient, TelegramClientOptions, User } from '@mtcute/core';
2
2
  import { SqliteStorage } from '@mtcute/sqlite';
3
- export * from '@mtcute/client';
3
+ export * from '@mtcute/core';
4
4
  export * from '@mtcute/html-parser';
5
5
  export * from '@mtcute/markdown-parser';
6
6
  export { SqliteStorage };
package/esm/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { createRequire } from 'module';
2
2
  import { createInterface } from 'readline';
3
- import { TelegramClient } from '@mtcute/client';
3
+ import { TelegramClient } from '@mtcute/core';
4
4
  import { SqliteStorage } from '@mtcute/sqlite';
5
- export * from '@mtcute/client';
5
+ export * from '@mtcute/core';
6
6
  export * from '@mtcute/html-parser';
7
7
  export * from '@mtcute/markdown-parser';
8
8
  export { SqliteStorage };
@@ -25,6 +25,10 @@ catch (e) { }
25
25
  */
26
26
  export class NodeTelegramClient extends TelegramClient {
27
27
  constructor(opts) {
28
+ if ('client' in opts) {
29
+ super(opts);
30
+ return;
31
+ }
28
32
  super({
29
33
  // eslint-disable-next-line
30
34
  crypto: nativeCrypto ? () => new nativeCrypto() : undefined,
@@ -81,7 +85,7 @@ export class NodeTelegramClient extends TelegramClient {
81
85
  }
82
86
  this.start(params)
83
87
  .then(then)
84
- .catch((err) => this._emitError(err));
88
+ .catch((err) => this.emitError(err));
85
89
  }
86
90
  }
87
91
  //# 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,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,E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SAAiD,EAAE;QACrD,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;YAClB,IAAI,CAAC,MAAM,CAAC,KAAK;gBAAE,MAAM,CAAC,KAAK,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;YAC9D,IAAI,CAAC,MAAM,CAAC,IAAI;gBAAE,MAAM,CAAC,IAAI,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;YAE3D,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;gBAClB,MAAM,CAAC,QAAQ,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAA;aACxD;SACJ;QAED,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;YACrC,IAAI,IAAI,CAAC,GAAG,EAAE;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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,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,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;IAC5C,CAAC;CACJ","sourcesContent":["import { createRequire } from 'module'\nimport { createInterface, Interface as RlInterface } from 'readline'\n\nimport { TelegramClient, TelegramClientOptions, User } from '@mtcute/core'\nimport { SqliteStorage } from '@mtcute/sqlite'\n\nexport * from '@mtcute/core'\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 if ('client' in opts) {\n super(opts)\n\n return\n }\n\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/utils.d.ts CHANGED
@@ -1 +1 @@
1
- export * from '@mtcute/client/utils.js';
1
+ export * from '@mtcute/core/utils.js';
package/esm/utils.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from '@mtcute/client/utils.js';
1
+ export * from '@mtcute/core/utils.js';
2
2
  //# sourceMappingURL=utils.js.map
package/esm/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../utils.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA","sourcesContent":["export * from '@mtcute/client/utils.js'\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../utils.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA","sourcesContent":["export * from '@mtcute/core/utils.js'\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mtcute/node",
3
- "version": "0.4.0",
3
+ "version": "0.7.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.4.0",
12
- "@mtcute/sqlite": "^0.4.0",
13
- "@mtcute/markdown-parser": "^0.4.0",
14
- "@mtcute/html-parser": "^0.4.0"
11
+ "@mtcute/core": "^0.7.0",
12
+ "@mtcute/sqlite": "^0.7.0",
13
+ "@mtcute/markdown-parser": "^0.7.0",
14
+ "@mtcute/html-parser": "^0.7.0"
15
15
  },
16
16
  "module": "esm/index.js",
17
17
  "exports": {