@mtcute/node 0.18.0-rc.5 → 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.d.cts +40 -0
- package/index.d.cts +9 -0
- package/methods/download-file.d.cts +9 -0
- package/methods/download-node-stream.d.cts +8 -0
- package/methods.d.cts +3 -0
- package/package.json +15 -15
- package/sqlite/driver.d.cts +25 -0
- package/sqlite/index.d.cts +8 -0
- package/sqlite/sqlite.test.d.cts +1 -0
- package/utils/crypto.d.cts +15 -0
- package/utils/crypto.test.d.cts +1 -0
- package/utils/exit-hook.d.cts +1 -0
- package/utils/logging.d.cts +2 -0
- package/utils/normalize-file.d.cts +6 -0
- package/utils/platform.d.cts +11 -0
- package/utils/proxies.d.cts +34 -0
- package/utils/tcp.d.cts +7 -0
- package/utils.d.cts +2 -0
- package/worker.d.cts +12 -0
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/index.d.cts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './client.js';
|
|
2
|
+
export * from './sqlite/index.js';
|
|
3
|
+
export * from './utils/platform.js';
|
|
4
|
+
export * from './utils/proxies.js';
|
|
5
|
+
export * from './utils/tcp.js';
|
|
6
|
+
export * from './worker.js';
|
|
7
|
+
export * from '@mtcute/core';
|
|
8
|
+
export * from '@mtcute/html-parser';
|
|
9
|
+
export * from '@mtcute/markdown-parser';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FileDownloadLocation, FileDownloadParameters, ITelegramClient } from '@mtcute/core';
|
|
2
|
+
/**
|
|
3
|
+
* Download a remote file to a local file (only for NodeJS).
|
|
4
|
+
* Promise will resolve once the download is complete.
|
|
5
|
+
*
|
|
6
|
+
* @param filename Local file name to which the remote file will be downloaded
|
|
7
|
+
* @param params File download parameters
|
|
8
|
+
*/
|
|
9
|
+
export declare function downloadToFile(client: ITelegramClient, filename: string, location: FileDownloadLocation, params?: FileDownloadParameters): Promise<void>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FileDownloadLocation, FileDownloadParameters, ITelegramClient } from '@mtcute/core';
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
3
|
+
/**
|
|
4
|
+
* Download a remote file as a Node.js Readable stream.
|
|
5
|
+
*
|
|
6
|
+
* @param params File download parameters
|
|
7
|
+
*/
|
|
8
|
+
export declare function downloadAsNodeStream(client: ITelegramClient, location: FileDownloadLocation, params?: FileDownloadParameters): Readable;
|
package/methods.d.cts
ADDED
package/package.json
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mtcute/node",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.18.0
|
|
4
|
+
"version": "0.18.0",
|
|
5
5
|
"description": "Meta-package for Node.js",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"homepage": "https://mtcute.dev",
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/mtcute/mtcute.git"
|
|
11
|
-
},
|
|
12
|
-
"scripts": {},
|
|
13
7
|
"dependencies": {
|
|
14
|
-
"@mtcute/core": "0.18.0
|
|
15
|
-
"@mtcute/html-parser": "0.18.0
|
|
16
|
-
"@mtcute/markdown-parser": "0.18.0
|
|
17
|
-
"@mtcute/wasm": "0.18.0
|
|
18
|
-
"@fuman/utils": "0.0.
|
|
19
|
-
"@fuman/net": "0.0.
|
|
20
|
-
"@fuman/node": "0.0.
|
|
8
|
+
"@mtcute/core": "^0.18.0",
|
|
9
|
+
"@mtcute/html-parser": "^0.18.0",
|
|
10
|
+
"@mtcute/markdown-parser": "^0.18.0",
|
|
11
|
+
"@mtcute/wasm": "^0.18.0",
|
|
12
|
+
"@fuman/utils": "0.0.4",
|
|
13
|
+
"@fuman/net": "0.0.4",
|
|
14
|
+
"@fuman/node": "0.0.4",
|
|
21
15
|
"better-sqlite3": "11.3.0"
|
|
22
16
|
},
|
|
23
17
|
"exports": {
|
|
@@ -53,5 +47,11 @@
|
|
|
53
47
|
}
|
|
54
48
|
},
|
|
55
49
|
"author": "alina sireneva <alina@tei.su>",
|
|
56
|
-
"sideEffects": false
|
|
50
|
+
"sideEffects": false,
|
|
51
|
+
"homepage": "https://mtcute.dev",
|
|
52
|
+
"repository": {
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "git+https://github.com/mtcute/mtcute.git"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {}
|
|
57
57
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ISqliteDatabase, BaseSqliteStorageDriver } from '@mtcute/core';
|
|
2
|
+
import { Options } from 'better-sqlite3';
|
|
3
|
+
export interface SqliteStorageDriverOptions {
|
|
4
|
+
/**
|
|
5
|
+
* By default, WAL mode is enabled, which
|
|
6
|
+
* significantly improves performance.
|
|
7
|
+
* [Learn more](https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/performance.md)
|
|
8
|
+
*
|
|
9
|
+
* However, you might encounter some issues,
|
|
10
|
+
* and if you do, you can disable WAL by passing `true`
|
|
11
|
+
*
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
disableWal?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Additional options to pass to `better-sqlite3`
|
|
17
|
+
*/
|
|
18
|
+
options?: Options;
|
|
19
|
+
}
|
|
20
|
+
export declare class SqliteStorageDriver extends BaseSqliteStorageDriver {
|
|
21
|
+
readonly filename: string;
|
|
22
|
+
readonly params?: SqliteStorageDriverOptions | undefined;
|
|
23
|
+
constructor(filename?: string, params?: SqliteStorageDriverOptions | undefined);
|
|
24
|
+
_createDatabase(): ISqliteDatabase;
|
|
25
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SqliteStorageDriverOptions } from './driver.js';
|
|
2
|
+
import { BaseSqliteStorage } from '@mtcute/core';
|
|
3
|
+
export { SqliteStorageDriver } from './driver.js';
|
|
4
|
+
export declare class SqliteStorage extends BaseSqliteStorage {
|
|
5
|
+
readonly filename: string;
|
|
6
|
+
readonly params?: SqliteStorageDriverOptions | undefined;
|
|
7
|
+
constructor(filename?: string, params?: SqliteStorageDriverOptions | undefined);
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IAesCtr, ICryptoProvider, IEncryptionScheme, BaseCryptoProvider } from '@mtcute/core/utils.js';
|
|
2
|
+
export declare abstract class BaseNodeCryptoProvider extends BaseCryptoProvider {
|
|
3
|
+
createAesCtr(key: Uint8Array, iv: Uint8Array): IAesCtr;
|
|
4
|
+
pbkdf2(password: Uint8Array, salt: Uint8Array, iterations: number, keylen?: number, algo?: string): Promise<Uint8Array>;
|
|
5
|
+
sha1(data: Uint8Array): Uint8Array;
|
|
6
|
+
sha256(data: Uint8Array): Uint8Array;
|
|
7
|
+
hmacSha256(data: Uint8Array, key: Uint8Array): Uint8Array;
|
|
8
|
+
gzip(data: Uint8Array, maxSize: number): Uint8Array | null;
|
|
9
|
+
gunzip(data: Uint8Array): Uint8Array;
|
|
10
|
+
randomFill(buf: Uint8Array): void;
|
|
11
|
+
}
|
|
12
|
+
export declare class NodeCryptoProvider extends BaseNodeCryptoProvider implements ICryptoProvider {
|
|
13
|
+
initialize(): Promise<void>;
|
|
14
|
+
createAesIge(key: Uint8Array, iv: Uint8Array): IEncryptionScheme;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function beforeExit(fn: () => void): () => void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ICorePlatform } from '@mtcute/core';
|
|
2
|
+
import { normalizeFile } from '../utils/normalize-file.js';
|
|
3
|
+
import { beforeExit } from './exit-hook.js';
|
|
4
|
+
import { defaultLoggingHandler } from './logging.js';
|
|
5
|
+
export declare class NodePlatform implements ICorePlatform {
|
|
6
|
+
log: typeof defaultLoggingHandler;
|
|
7
|
+
beforeExit: typeof beforeExit;
|
|
8
|
+
normalizeFile: typeof normalizeFile;
|
|
9
|
+
getDeviceModel(): string;
|
|
10
|
+
getDefaultLogLevel(): number | null;
|
|
11
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { HttpProxySettings as FumanHttpProxySettings, ITcpConnection, SocksProxySettings, TcpEndpoint } from '@fuman/net';
|
|
2
|
+
import { BasicDcOption } from '@mtcute/core/utils.js';
|
|
3
|
+
import { SecureContextOptions } from 'node:tls';
|
|
4
|
+
import { BaseMtProxyTransport, IntermediatePacketCodec, ITelegramConnection, TelegramTransport } from '@mtcute/core';
|
|
5
|
+
export type { SocksProxySettings } from '@fuman/net';
|
|
6
|
+
export { HttpProxyConnectionError, SocksProxyConnectionError } from '@fuman/net';
|
|
7
|
+
export type { MtProxySettings } from '@mtcute/core';
|
|
8
|
+
export interface HttpProxySettings extends FumanHttpProxySettings {
|
|
9
|
+
/**
|
|
10
|
+
* Whether this is a HTTPS proxy (by default it is regular HTTP).
|
|
11
|
+
*/
|
|
12
|
+
tls?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Additional TLS options, used if `tls = true`.
|
|
15
|
+
* Can contain stuff like custom certificate, host,
|
|
16
|
+
* or whatever.
|
|
17
|
+
*/
|
|
18
|
+
tlsOptions?: SecureContextOptions;
|
|
19
|
+
}
|
|
20
|
+
export declare class HttpProxyTcpTransport implements TelegramTransport {
|
|
21
|
+
readonly proxy: HttpProxySettings;
|
|
22
|
+
constructor(proxy: HttpProxySettings);
|
|
23
|
+
connect(dc: BasicDcOption): Promise<ITelegramConnection>;
|
|
24
|
+
packetCodec(): IntermediatePacketCodec;
|
|
25
|
+
}
|
|
26
|
+
export declare class SocksProxyTcpTransport implements TelegramTransport {
|
|
27
|
+
readonly proxy: SocksProxySettings;
|
|
28
|
+
constructor(proxy: SocksProxySettings);
|
|
29
|
+
connect(dc: BasicDcOption): Promise<ITelegramConnection>;
|
|
30
|
+
packetCodec(): IntermediatePacketCodec;
|
|
31
|
+
}
|
|
32
|
+
export declare class MtProxyTcpTransport extends BaseMtProxyTransport {
|
|
33
|
+
_connectTcp(endpoint: TcpEndpoint): Promise<ITcpConnection>;
|
|
34
|
+
}
|
package/utils/tcp.d.cts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ITcpConnection } from '@fuman/net';
|
|
2
|
+
import { TelegramTransport, IntermediatePacketCodec } from '@mtcute/core';
|
|
3
|
+
import { BasicDcOption } from '@mtcute/core/utils.js';
|
|
4
|
+
export declare class TcpTransport implements TelegramTransport {
|
|
5
|
+
connect(dc: BasicDcOption): Promise<ITcpConnection>;
|
|
6
|
+
packetCodec(): IntermediatePacketCodec;
|
|
7
|
+
}
|
package/utils.d.cts
ADDED
package/worker.d.cts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ClientMessageHandler, RespondFn, SendFn, SomeWorker, TelegramWorkerOptions, WorkerCustomMethods, WorkerMessageHandler, TelegramWorker as TelegramWorkerBase, TelegramWorkerPort as TelegramWorkerPortBase } from '@mtcute/core/worker.js';
|
|
2
|
+
export type { TelegramWorkerOptions, WorkerCustomMethods };
|
|
3
|
+
export interface TelegramWorkerPortOptions {
|
|
4
|
+
worker: SomeWorker;
|
|
5
|
+
}
|
|
6
|
+
export declare class TelegramWorker<T extends WorkerCustomMethods> extends TelegramWorkerBase<T> {
|
|
7
|
+
registerWorker(handler: WorkerMessageHandler): RespondFn;
|
|
8
|
+
}
|
|
9
|
+
export declare class TelegramWorkerPort<T extends WorkerCustomMethods> extends TelegramWorkerPortBase<T> {
|
|
10
|
+
constructor(options: TelegramWorkerPortOptions);
|
|
11
|
+
connectToWorker(worker: SomeWorker, handler: ClientMessageHandler): [SendFn, () => void];
|
|
12
|
+
}
|