@mtcute/node 0.17.0 → 0.18.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/client.cjs +101 -0
- package/client.d.cts +40 -0
- package/client.d.ts +2 -9
- package/client.js +96 -0
- package/index.cjs +29 -423
- package/index.d.cts +2 -1
- package/index.d.ts +2 -1
- package/index.js +13 -397
- package/{chunks/cjs/BpvQ752Q.js → methods/download-file.cjs} +3 -7
- package/methods/download-file.d.cts +9 -0
- package/{chunks/es/CnOjjhdK.js → methods/download-file.js} +1 -6
- package/methods/download-node-stream.cjs +13 -0
- package/methods/download-node-stream.d.cts +8 -0
- package/methods/download-node-stream.d.ts +1 -1
- package/methods/download-node-stream.js +8 -0
- package/methods.cjs +5 -4
- package/methods.js +2 -1
- package/package.json +16 -13
- package/sqlite/driver.cjs +27 -0
- package/sqlite/driver.d.cts +25 -0
- package/sqlite/driver.d.ts +1 -1
- package/sqlite/driver.js +22 -0
- package/sqlite/index.cjs +18 -0
- package/sqlite/index.d.cts +8 -0
- package/sqlite/index.d.ts +1 -1
- package/sqlite/index.js +13 -0
- package/{chunks/cjs/D7i-4e0W.js → utils/crypto.cjs} +4 -3
- package/utils/crypto.d.cts +15 -0
- package/{chunks/es/HZgHrOPU.js → utils/crypto.js} +1 -1
- package/utils/exit-hook.cjs +46 -0
- package/utils/exit-hook.d.ts +1 -0
- package/utils/exit-hook.js +41 -0
- package/utils/logging.cjs +33 -0
- package/utils/logging.d.ts +2 -0
- package/utils/logging.js +28 -0
- package/utils/normalize-file.cjs +33 -0
- package/utils/normalize-file.d.cts +6 -0
- package/utils/normalize-file.js +28 -0
- package/utils/platform.cjs +44 -0
- package/utils/platform.d.cts +11 -0
- package/{common-internals-node → utils}/platform.d.ts +1 -8
- package/utils/platform.js +22 -0
- package/utils/proxies.cjs +73 -0
- package/utils/proxies.d.cts +34 -0
- package/utils/proxies.d.ts +34 -0
- package/utils/proxies.js +63 -0
- package/utils/tcp.cjs +18 -0
- package/utils/tcp.d.cts +7 -0
- package/utils/tcp.d.ts +6 -28
- package/utils/tcp.js +13 -0
- package/utils.cjs +3 -6
- package/utils.d.cts +0 -1
- package/utils.d.ts +0 -1
- package/utils.js +2 -5
- package/worker.cjs +49 -0
- package/worker.d.cts +12 -0
- package/worker.d.ts +5 -3
- package/worker.js +44 -0
- package/chunks/cjs/HP2yqAk_.js +0 -79
- package/chunks/cjs/package.json +0 -3
- package/chunks/es/CKso6cAV.js +0 -75
- package/utils/stream-utils.d.ts +0 -3
- package/utils/version.d.ts +0 -3
- /package/{utils/stream-utils.test.d.ts → sqlite/sqlite.test.d.cts} +0 -0
- /package/utils/{tcp.test.d.ts → crypto.test.d.cts} +0 -0
- /package/{common-internals-node/exit-hook.d.ts → utils/exit-hook.d.cts} +0 -0
- /package/{common-internals-node/logging.d.ts → utils/logging.d.cts} +0 -0
package/client.cjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
2
|
+
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
3
|
+
console.warn("[mtcute-workspace] CommonJS support is deprecated and will be removed in 0.20.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
|
|
4
|
+
console.warn("[mtcute-workspace] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
|
|
5
|
+
}
|
|
6
|
+
"use strict";
|
|
7
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
+
const node_readline = require("node:readline");
|
|
9
|
+
const utils = require("@fuman/utils");
|
|
10
|
+
const client_js = require("@mtcute/core/client.js");
|
|
11
|
+
const downloadFile = require("./methods/download-file.cjs");
|
|
12
|
+
const downloadNodeStream = require("./methods/download-node-stream.cjs");
|
|
13
|
+
const index = require("./sqlite/index.cjs");
|
|
14
|
+
const crypto = require("./utils/crypto.cjs");
|
|
15
|
+
const platform = require("./utils/platform.cjs");
|
|
16
|
+
const tcp = require("./utils/tcp.cjs");
|
|
17
|
+
let nativeCrypto;
|
|
18
|
+
try {
|
|
19
|
+
nativeCrypto = require("@mtcute/crypto-node").NodeNativeCryptoProvider;
|
|
20
|
+
} catch {
|
|
21
|
+
}
|
|
22
|
+
class BaseTelegramClient extends client_js.BaseTelegramClient {
|
|
23
|
+
constructor(opts) {
|
|
24
|
+
super({
|
|
25
|
+
// eslint-disable-next-line
|
|
26
|
+
crypto: nativeCrypto ? new nativeCrypto() : new crypto.NodeCryptoProvider(),
|
|
27
|
+
transport: new tcp.TcpTransport(),
|
|
28
|
+
platform: new platform.NodePlatform(),
|
|
29
|
+
...opts,
|
|
30
|
+
storage: typeof opts.storage === "string" ? new index.SqliteStorage(opts.storage) : opts.storage ?? new index.SqliteStorage("client.session")
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class TelegramClient extends client_js.TelegramClient {
|
|
35
|
+
constructor(opts) {
|
|
36
|
+
if ("client" in opts) {
|
|
37
|
+
super(opts);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
super({
|
|
41
|
+
client: new BaseTelegramClient(opts),
|
|
42
|
+
disableUpdates: opts.disableUpdates,
|
|
43
|
+
skipConversationUpdates: opts.skipConversationUpdates,
|
|
44
|
+
updates: opts.updates
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
_rl;
|
|
48
|
+
/**
|
|
49
|
+
* Tiny wrapper over Node `readline` package
|
|
50
|
+
* for simpler user input for `.start()` method.
|
|
51
|
+
*
|
|
52
|
+
* Associated `readline` interface is closed
|
|
53
|
+
* after `start()` returns, or with the client.
|
|
54
|
+
*
|
|
55
|
+
* @param text Text of the question
|
|
56
|
+
*/
|
|
57
|
+
input(text) {
|
|
58
|
+
if (!this._rl) {
|
|
59
|
+
this._rl = node_readline.createInterface({
|
|
60
|
+
input: process.stdin,
|
|
61
|
+
output: process.stdout
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return new Promise((res) => this._rl?.question(text, res));
|
|
65
|
+
}
|
|
66
|
+
close() {
|
|
67
|
+
this._rl?.close();
|
|
68
|
+
return super.close();
|
|
69
|
+
}
|
|
70
|
+
start(params = {}) {
|
|
71
|
+
if (!params.botToken) {
|
|
72
|
+
if (!params.phone) params.phone = () => this.input("phone > ");
|
|
73
|
+
if (!params.code) params.code = () => this.input("code > ");
|
|
74
|
+
if (!params.password) {
|
|
75
|
+
params.password = () => this.input("2fa password > ");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return super.start(params).then((user) => {
|
|
79
|
+
if (this._rl) {
|
|
80
|
+
this._rl.close();
|
|
81
|
+
delete this._rl;
|
|
82
|
+
}
|
|
83
|
+
return user;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
run(params, then) {
|
|
87
|
+
if (typeof params === "function") {
|
|
88
|
+
then = params;
|
|
89
|
+
params = {};
|
|
90
|
+
}
|
|
91
|
+
this.start(params).then(then).catch((err) => this.onError.emit(utils.unknownToError(err)));
|
|
92
|
+
}
|
|
93
|
+
downloadToFile(filename, location, params) {
|
|
94
|
+
return downloadFile.downloadToFile(this, filename, location, params);
|
|
95
|
+
}
|
|
96
|
+
downloadAsNodeStream(location, params) {
|
|
97
|
+
return downloadNodeStream.downloadAsNodeStream(this, location, params);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.BaseTelegramClient = BaseTelegramClient;
|
|
101
|
+
exports.TelegramClient = TelegramClient;
|
package/client.d.cts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { FileDownloadLocation, FileDownloadParameters, ITelegramStorageProvider, PartialOnly, User } from '@mtcute/core';
|
|
2
|
+
import { BaseTelegramClientOptions as BaseTelegramClientOptionsBase, TelegramClientOptions, BaseTelegramClient as BaseTelegramClientBase, TelegramClient as TelegramClientBase } from '@mtcute/core/client.js';
|
|
3
|
+
import { Readable } from 'node:stream';
|
|
4
|
+
export type { TelegramClientOptions };
|
|
5
|
+
export interface BaseTelegramClientOptions extends PartialOnly<Omit<BaseTelegramClientOptionsBase, 'storage'>, 'transport' | 'crypto' | 'platform'> {
|
|
6
|
+
/**
|
|
7
|
+
* Storage to use for this client.
|
|
8
|
+
*
|
|
9
|
+
* If a string is passed, it will be used as
|
|
10
|
+
* a name for an SQLite database file.
|
|
11
|
+
*
|
|
12
|
+
* @default `"client.session"`
|
|
13
|
+
*/
|
|
14
|
+
storage?: string | ITelegramStorageProvider;
|
|
15
|
+
}
|
|
16
|
+
export declare class BaseTelegramClient extends BaseTelegramClientBase {
|
|
17
|
+
constructor(opts: BaseTelegramClientOptions);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Telegram client for use in Node.js
|
|
21
|
+
*/
|
|
22
|
+
export declare class TelegramClient extends TelegramClientBase {
|
|
23
|
+
constructor(opts: TelegramClientOptions);
|
|
24
|
+
private _rl?;
|
|
25
|
+
/**
|
|
26
|
+
* Tiny wrapper over Node `readline` package
|
|
27
|
+
* for simpler user input for `.start()` method.
|
|
28
|
+
*
|
|
29
|
+
* Associated `readline` interface is closed
|
|
30
|
+
* after `start()` returns, or with the client.
|
|
31
|
+
*
|
|
32
|
+
* @param text Text of the question
|
|
33
|
+
*/
|
|
34
|
+
input(text: string): Promise<string>;
|
|
35
|
+
close(): Promise<void>;
|
|
36
|
+
start(params?: Parameters<TelegramClientBase['start']>[0]): Promise<User>;
|
|
37
|
+
run(params: Parameters<TelegramClient['start']>[0] | ((user: User) => void | Promise<void>), then?: (user: User) => void | Promise<void>): void;
|
|
38
|
+
downloadToFile(filename: string, location: FileDownloadLocation, params?: FileDownloadParameters | undefined): Promise<void>;
|
|
39
|
+
downloadAsNodeStream(location: FileDownloadLocation, params?: FileDownloadParameters | undefined): Readable;
|
|
40
|
+
}
|
package/client.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Readable } from 'node:stream';
|
|
2
1
|
import { FileDownloadLocation, FileDownloadParameters, ITelegramStorageProvider, PartialOnly, User } from '@mtcute/core';
|
|
3
2
|
import { BaseTelegramClientOptions as BaseTelegramClientOptionsBase, TelegramClientOptions, BaseTelegramClient as BaseTelegramClientBase, TelegramClient as TelegramClientBase } from '@mtcute/core/client.js';
|
|
3
|
+
import { Readable } from 'node:stream';
|
|
4
4
|
export type { TelegramClientOptions };
|
|
5
|
-
export interface BaseTelegramClientOptions extends PartialOnly<Omit<BaseTelegramClientOptionsBase, 'storage'>, 'transport' | 'crypto'> {
|
|
5
|
+
export interface BaseTelegramClientOptions extends PartialOnly<Omit<BaseTelegramClientOptionsBase, 'storage'>, 'transport' | 'crypto' | 'platform'> {
|
|
6
6
|
/**
|
|
7
7
|
* Storage to use for this client.
|
|
8
8
|
*
|
|
@@ -12,13 +12,6 @@ export interface BaseTelegramClientOptions extends PartialOnly<Omit<BaseTelegram
|
|
|
12
12
|
* @default `"client.session"`
|
|
13
13
|
*/
|
|
14
14
|
storage?: string | ITelegramStorageProvider;
|
|
15
|
-
/**
|
|
16
|
-
* **ADVANCED USE ONLY**
|
|
17
|
-
*
|
|
18
|
-
* Whether to not set up the platform.
|
|
19
|
-
* This is useful if you call `setPlatform` yourself.
|
|
20
|
-
*/
|
|
21
|
-
platformless?: boolean;
|
|
22
15
|
}
|
|
23
16
|
export declare class BaseTelegramClient extends BaseTelegramClientBase {
|
|
24
17
|
constructor(opts: BaseTelegramClientOptions);
|
package/client.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { createInterface } from "node:readline";
|
|
2
|
+
import { unknownToError } from "@fuman/utils";
|
|
3
|
+
import { BaseTelegramClient as BaseTelegramClient$1, TelegramClient as TelegramClient$1 } from "@mtcute/core/client.js";
|
|
4
|
+
import { downloadToFile } from "./methods/download-file.js";
|
|
5
|
+
import { downloadAsNodeStream } from "./methods/download-node-stream.js";
|
|
6
|
+
import { SqliteStorage } from "./sqlite/index.js";
|
|
7
|
+
import { NodeCryptoProvider } from "./utils/crypto.js";
|
|
8
|
+
import { NodePlatform } from "./utils/platform.js";
|
|
9
|
+
import { TcpTransport } from "./utils/tcp.js";
|
|
10
|
+
let nativeCrypto;
|
|
11
|
+
try {
|
|
12
|
+
nativeCrypto = (await import("@mtcute/crypto-node")).NodeNativeCryptoProvider;
|
|
13
|
+
} catch {
|
|
14
|
+
}
|
|
15
|
+
class BaseTelegramClient extends BaseTelegramClient$1 {
|
|
16
|
+
constructor(opts) {
|
|
17
|
+
super({
|
|
18
|
+
// eslint-disable-next-line
|
|
19
|
+
crypto: nativeCrypto ? new nativeCrypto() : new NodeCryptoProvider(),
|
|
20
|
+
transport: new TcpTransport(),
|
|
21
|
+
platform: new NodePlatform(),
|
|
22
|
+
...opts,
|
|
23
|
+
storage: typeof opts.storage === "string" ? new SqliteStorage(opts.storage) : opts.storage ?? new SqliteStorage("client.session")
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
class TelegramClient extends TelegramClient$1 {
|
|
28
|
+
constructor(opts) {
|
|
29
|
+
if ("client" in opts) {
|
|
30
|
+
super(opts);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
super({
|
|
34
|
+
client: new BaseTelegramClient(opts),
|
|
35
|
+
disableUpdates: opts.disableUpdates,
|
|
36
|
+
skipConversationUpdates: opts.skipConversationUpdates,
|
|
37
|
+
updates: opts.updates
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
_rl;
|
|
41
|
+
/**
|
|
42
|
+
* Tiny wrapper over Node `readline` package
|
|
43
|
+
* for simpler user input for `.start()` method.
|
|
44
|
+
*
|
|
45
|
+
* Associated `readline` interface is closed
|
|
46
|
+
* after `start()` returns, or with the client.
|
|
47
|
+
*
|
|
48
|
+
* @param text Text of the question
|
|
49
|
+
*/
|
|
50
|
+
input(text) {
|
|
51
|
+
if (!this._rl) {
|
|
52
|
+
this._rl = createInterface({
|
|
53
|
+
input: process.stdin,
|
|
54
|
+
output: process.stdout
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return new Promise((res) => this._rl?.question(text, res));
|
|
58
|
+
}
|
|
59
|
+
close() {
|
|
60
|
+
this._rl?.close();
|
|
61
|
+
return super.close();
|
|
62
|
+
}
|
|
63
|
+
start(params = {}) {
|
|
64
|
+
if (!params.botToken) {
|
|
65
|
+
if (!params.phone) params.phone = () => this.input("phone > ");
|
|
66
|
+
if (!params.code) params.code = () => this.input("code > ");
|
|
67
|
+
if (!params.password) {
|
|
68
|
+
params.password = () => this.input("2fa password > ");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return super.start(params).then((user) => {
|
|
72
|
+
if (this._rl) {
|
|
73
|
+
this._rl.close();
|
|
74
|
+
delete this._rl;
|
|
75
|
+
}
|
|
76
|
+
return user;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
run(params, then) {
|
|
80
|
+
if (typeof params === "function") {
|
|
81
|
+
then = params;
|
|
82
|
+
params = {};
|
|
83
|
+
}
|
|
84
|
+
this.start(params).then(then).catch((err) => this.onError.emit(unknownToError(err)));
|
|
85
|
+
}
|
|
86
|
+
downloadToFile(filename, location, params) {
|
|
87
|
+
return downloadToFile(this, filename, location, params);
|
|
88
|
+
}
|
|
89
|
+
downloadAsNodeStream(location, params) {
|
|
90
|
+
return downloadAsNodeStream(this, location, params);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
BaseTelegramClient,
|
|
95
|
+
TelegramClient
|
|
96
|
+
};
|