@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/sqlite/index.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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 core = require("@mtcute/core");
|
|
9
|
+
const driver = require("./driver.cjs");
|
|
10
|
+
class SqliteStorage extends core.BaseSqliteStorage {
|
|
11
|
+
constructor(filename = ":memory:", params) {
|
|
12
|
+
super(new driver.SqliteStorageDriver(filename, params));
|
|
13
|
+
this.filename = filename;
|
|
14
|
+
this.params = params;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.SqliteStorageDriver = driver.SqliteStorageDriver;
|
|
18
|
+
exports.SqliteStorage = SqliteStorage;
|
|
@@ -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
|
+
}
|
package/sqlite/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BaseSqliteStorage } from '@mtcute/core';
|
|
2
1
|
import { SqliteStorageDriverOptions } from './driver.js';
|
|
2
|
+
import { BaseSqliteStorage } from '@mtcute/core';
|
|
3
3
|
export { SqliteStorageDriver } from './driver.js';
|
|
4
4
|
export declare class SqliteStorage extends BaseSqliteStorage {
|
|
5
5
|
readonly filename: string;
|
package/sqlite/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseSqliteStorage } from "@mtcute/core";
|
|
2
|
+
import { SqliteStorageDriver } from "./driver.js";
|
|
3
|
+
class SqliteStorage extends BaseSqliteStorage {
|
|
4
|
+
constructor(filename = ":memory:", params) {
|
|
5
|
+
super(new SqliteStorageDriver(filename, params));
|
|
6
|
+
this.filename = filename;
|
|
7
|
+
this.params = params;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
SqliteStorage,
|
|
12
|
+
SqliteStorageDriver
|
|
13
|
+
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
2
2
|
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
3
|
-
console.warn("[
|
|
4
|
-
console.warn("[
|
|
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
5
|
}
|
|
6
6
|
"use strict";
|
|
7
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
8
|
const node_crypto = require("node:crypto");
|
|
8
9
|
const promises = require("node:fs/promises");
|
|
9
10
|
const node_module = require("node:module");
|
|
@@ -54,7 +55,7 @@ class BaseNodeCryptoProvider extends utils_js.BaseCryptoProvider {
|
|
|
54
55
|
}
|
|
55
56
|
class NodeCryptoProvider extends BaseNodeCryptoProvider {
|
|
56
57
|
async initialize() {
|
|
57
|
-
const require$1 = node_module.createRequire(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.src || new URL("
|
|
58
|
+
const require$1 = node_module.createRequire(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("utils/crypto.cjs", document.baseURI).href);
|
|
58
59
|
const wasmFile = require$1.resolve("@mtcute/wasm/mtcute.wasm");
|
|
59
60
|
const wasm$1 = await promises.readFile(wasmFile);
|
|
60
61
|
wasm.initSync(wasm$1);
|
|
@@ -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
|
+
}
|
|
@@ -3,7 +3,7 @@ import { readFile } from "node:fs/promises";
|
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { deflateSync, gunzipSync } from "node:zlib";
|
|
5
5
|
import { BaseCryptoProvider } from "@mtcute/core/utils.js";
|
|
6
|
-
import { initSync,
|
|
6
|
+
import { initSync, ige256Decrypt, ige256Encrypt } from "@mtcute/wasm";
|
|
7
7
|
class BaseNodeCryptoProvider extends BaseCryptoProvider {
|
|
8
8
|
createAesCtr(key, iv) {
|
|
9
9
|
const cipher = createCipheriv(`aes-${key.length * 8}-ctr`, key, iv);
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
let installed = false;
|
|
9
|
+
let handled = false;
|
|
10
|
+
const callbacks = /* @__PURE__ */ new Set();
|
|
11
|
+
const myHandlers = /* @__PURE__ */ new Map();
|
|
12
|
+
function register(shouldManuallyExit, signal, event) {
|
|
13
|
+
function eventHandler() {
|
|
14
|
+
if (handled) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
handled = true;
|
|
18
|
+
for (const callback of callbacks) {
|
|
19
|
+
callback();
|
|
20
|
+
}
|
|
21
|
+
for (const [event2, handler] of myHandlers) {
|
|
22
|
+
process.off(event2, handler);
|
|
23
|
+
}
|
|
24
|
+
if (shouldManuallyExit) {
|
|
25
|
+
process.kill(process.pid, signal);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
process.on(event, eventHandler);
|
|
29
|
+
myHandlers.set(event, eventHandler);
|
|
30
|
+
}
|
|
31
|
+
function beforeExit(fn) {
|
|
32
|
+
if (typeof process === "undefined") return () => {
|
|
33
|
+
};
|
|
34
|
+
if (!installed) {
|
|
35
|
+
installed = true;
|
|
36
|
+
register(true, 0, "beforeExit");
|
|
37
|
+
register(true, 2, "SIGINT");
|
|
38
|
+
register(true, 15, "SIGTERM");
|
|
39
|
+
register(false, 15, "exit");
|
|
40
|
+
}
|
|
41
|
+
callbacks.add(fn);
|
|
42
|
+
return () => {
|
|
43
|
+
callbacks.delete(fn);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.beforeExit = beforeExit;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function beforeExit(fn: () => void): () => void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
let installed = false;
|
|
2
|
+
let handled = false;
|
|
3
|
+
const callbacks = /* @__PURE__ */ new Set();
|
|
4
|
+
const myHandlers = /* @__PURE__ */ new Map();
|
|
5
|
+
function register(shouldManuallyExit, signal, event) {
|
|
6
|
+
function eventHandler() {
|
|
7
|
+
if (handled) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
handled = true;
|
|
11
|
+
for (const callback of callbacks) {
|
|
12
|
+
callback();
|
|
13
|
+
}
|
|
14
|
+
for (const [event2, handler] of myHandlers) {
|
|
15
|
+
process.off(event2, handler);
|
|
16
|
+
}
|
|
17
|
+
if (shouldManuallyExit) {
|
|
18
|
+
process.kill(process.pid, signal);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
process.on(event, eventHandler);
|
|
22
|
+
myHandlers.set(event, eventHandler);
|
|
23
|
+
}
|
|
24
|
+
function beforeExit(fn) {
|
|
25
|
+
if (typeof process === "undefined") return () => {
|
|
26
|
+
};
|
|
27
|
+
if (!installed) {
|
|
28
|
+
installed = true;
|
|
29
|
+
register(true, 0, "beforeExit");
|
|
30
|
+
register(true, 2, "SIGINT");
|
|
31
|
+
register(true, 15, "SIGTERM");
|
|
32
|
+
register(false, 15, "exit");
|
|
33
|
+
}
|
|
34
|
+
callbacks.add(fn);
|
|
35
|
+
return () => {
|
|
36
|
+
callbacks.delete(fn);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
beforeExit
|
|
41
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
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 isTty = typeof process === "object" && Boolean(process.stdout?.isTTY);
|
|
9
|
+
const BASE_FORMAT = isTty ? "%s [%s] [%s%s\x1B[0m] " : "%s [%s] [%s] ";
|
|
10
|
+
const LEVEL_NAMES = isTty ? [
|
|
11
|
+
"",
|
|
12
|
+
// OFF
|
|
13
|
+
"\x1B[31mERR\x1B[0m",
|
|
14
|
+
"\x1B[33mWRN\x1B[0m",
|
|
15
|
+
"\x1B[34mINF\x1B[0m",
|
|
16
|
+
"\x1B[36mDBG\x1B[0m",
|
|
17
|
+
"\x1B[35mVRB\x1B[0m"
|
|
18
|
+
] : [
|
|
19
|
+
"",
|
|
20
|
+
// OFF
|
|
21
|
+
"ERR",
|
|
22
|
+
"WRN",
|
|
23
|
+
"INF",
|
|
24
|
+
"DBG",
|
|
25
|
+
"VRB"
|
|
26
|
+
];
|
|
27
|
+
const TAG_COLORS = [6, 2, 3, 4, 5, 1].map((i) => `\x1B[3${i};1m`);
|
|
28
|
+
const defaultLoggingHandler = isTty ? (color, level, tag, fmt, args) => {
|
|
29
|
+
console.log(BASE_FORMAT + fmt, (/* @__PURE__ */ new Date()).toISOString(), LEVEL_NAMES[level], TAG_COLORS[color], tag, ...args);
|
|
30
|
+
} : (color, level, tag, fmt, args) => {
|
|
31
|
+
console.log(BASE_FORMAT + fmt, (/* @__PURE__ */ new Date()).toISOString(), LEVEL_NAMES[level], tag, ...args);
|
|
32
|
+
};
|
|
33
|
+
exports.defaultLoggingHandler = defaultLoggingHandler;
|
package/utils/logging.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const isTty = typeof process === "object" && Boolean(process.stdout?.isTTY);
|
|
2
|
+
const BASE_FORMAT = isTty ? "%s [%s] [%s%s\x1B[0m] " : "%s [%s] [%s] ";
|
|
3
|
+
const LEVEL_NAMES = isTty ? [
|
|
4
|
+
"",
|
|
5
|
+
// OFF
|
|
6
|
+
"\x1B[31mERR\x1B[0m",
|
|
7
|
+
"\x1B[33mWRN\x1B[0m",
|
|
8
|
+
"\x1B[34mINF\x1B[0m",
|
|
9
|
+
"\x1B[36mDBG\x1B[0m",
|
|
10
|
+
"\x1B[35mVRB\x1B[0m"
|
|
11
|
+
] : [
|
|
12
|
+
"",
|
|
13
|
+
// OFF
|
|
14
|
+
"ERR",
|
|
15
|
+
"WRN",
|
|
16
|
+
"INF",
|
|
17
|
+
"DBG",
|
|
18
|
+
"VRB"
|
|
19
|
+
];
|
|
20
|
+
const TAG_COLORS = [6, 2, 3, 4, 5, 1].map((i) => `\x1B[3${i};1m`);
|
|
21
|
+
const defaultLoggingHandler = isTty ? (color, level, tag, fmt, args) => {
|
|
22
|
+
console.log(BASE_FORMAT + fmt, (/* @__PURE__ */ new Date()).toISOString(), LEVEL_NAMES[level], TAG_COLORS[color], tag, ...args);
|
|
23
|
+
} : (color, level, tag, fmt, args) => {
|
|
24
|
+
console.log(BASE_FORMAT + fmt, (/* @__PURE__ */ new Date()).toISOString(), LEVEL_NAMES[level], tag, ...args);
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
defaultLoggingHandler
|
|
28
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
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_fs = require("node:fs");
|
|
9
|
+
const promises = require("node:fs/promises");
|
|
10
|
+
const node_path = require("node:path");
|
|
11
|
+
const node_stream = require("node:stream");
|
|
12
|
+
const node = require("@fuman/node");
|
|
13
|
+
async function normalizeFile(file) {
|
|
14
|
+
if (typeof file === "string") {
|
|
15
|
+
file = node_fs.createReadStream(file);
|
|
16
|
+
}
|
|
17
|
+
if (file instanceof node_fs.ReadStream) {
|
|
18
|
+
const fileName = node_path.basename(file.path.toString());
|
|
19
|
+
const fileSize = await promises.stat(file.path.toString()).then((stat2) => stat2.size);
|
|
20
|
+
return {
|
|
21
|
+
file: node.nodeReadableToFuman(file),
|
|
22
|
+
fileName,
|
|
23
|
+
fileSize
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (file instanceof node_stream.Readable) {
|
|
27
|
+
return {
|
|
28
|
+
file: node.nodeReadableToFuman(file)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
exports.normalizeFile = normalizeFile;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createReadStream, ReadStream } from "node:fs";
|
|
2
|
+
import { stat } from "node:fs/promises";
|
|
3
|
+
import { basename } from "node:path";
|
|
4
|
+
import { Readable } from "node:stream";
|
|
5
|
+
import { nodeReadableToFuman } from "@fuman/node";
|
|
6
|
+
async function normalizeFile(file) {
|
|
7
|
+
if (typeof file === "string") {
|
|
8
|
+
file = createReadStream(file);
|
|
9
|
+
}
|
|
10
|
+
if (file instanceof ReadStream) {
|
|
11
|
+
const fileName = basename(file.path.toString());
|
|
12
|
+
const fileSize = await stat(file.path.toString()).then((stat2) => stat2.size);
|
|
13
|
+
return {
|
|
14
|
+
file: nodeReadableToFuman(file),
|
|
15
|
+
fileName,
|
|
16
|
+
fileSize
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (file instanceof Readable) {
|
|
20
|
+
return {
|
|
21
|
+
file: nodeReadableToFuman(file)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
normalizeFile
|
|
28
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
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 os = require("node:os");
|
|
9
|
+
const normalizeFile = require("./normalize-file.cjs");
|
|
10
|
+
const exitHook = require("./exit-hook.cjs");
|
|
11
|
+
const logging = require("./logging.cjs");
|
|
12
|
+
function _interopNamespaceDefault(e) {
|
|
13
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
14
|
+
if (e) {
|
|
15
|
+
for (const k in e) {
|
|
16
|
+
if (k !== "default") {
|
|
17
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: () => e[k]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
n.default = e;
|
|
26
|
+
return Object.freeze(n);
|
|
27
|
+
}
|
|
28
|
+
const os__namespace = /* @__PURE__ */ _interopNamespaceDefault(os);
|
|
29
|
+
class NodePlatform {
|
|
30
|
+
getDeviceModel() {
|
|
31
|
+
return `Node.js/${process.version} (${os__namespace.type()} ${os__namespace.arch()})`;
|
|
32
|
+
}
|
|
33
|
+
getDefaultLogLevel() {
|
|
34
|
+
const envLogLevel = Number.parseInt(process.env.MTCUTE_LOG_LEVEL ?? "");
|
|
35
|
+
if (!Number.isNaN(envLogLevel)) {
|
|
36
|
+
return envLogLevel;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
NodePlatform.prototype.log = logging.defaultLoggingHandler;
|
|
42
|
+
NodePlatform.prototype.beforeExit = exitHook.beforeExit;
|
|
43
|
+
NodePlatform.prototype.normalizeFile = normalizeFile.normalizeFile;
|
|
44
|
+
exports.NodePlatform = NodePlatform;
|
|
@@ -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
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ICorePlatform } from '@mtcute/core
|
|
1
|
+
import { ICorePlatform } from '@mtcute/core';
|
|
2
2
|
import { normalizeFile } from '../utils/normalize-file.js';
|
|
3
3
|
import { beforeExit } from './exit-hook.js';
|
|
4
4
|
import { defaultLoggingHandler } from './logging.js';
|
|
@@ -8,11 +8,4 @@ export declare class NodePlatform implements ICorePlatform {
|
|
|
8
8
|
normalizeFile: typeof normalizeFile;
|
|
9
9
|
getDeviceModel(): string;
|
|
10
10
|
getDefaultLogLevel(): number | null;
|
|
11
|
-
utf8ByteLength(str: string): number;
|
|
12
|
-
utf8Encode(str: string): Uint8Array;
|
|
13
|
-
utf8Decode(buf: Uint8Array): string;
|
|
14
|
-
hexEncode(buf: Uint8Array): string;
|
|
15
|
-
hexDecode(str: string): Uint8Array;
|
|
16
|
-
base64Encode(buf: Uint8Array, url?: boolean): string;
|
|
17
|
-
base64Decode(string: string, url?: boolean): Uint8Array;
|
|
18
11
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as os from "node:os";
|
|
2
|
+
import { normalizeFile } from "./normalize-file.js";
|
|
3
|
+
import { beforeExit } from "./exit-hook.js";
|
|
4
|
+
import { defaultLoggingHandler } from "./logging.js";
|
|
5
|
+
class NodePlatform {
|
|
6
|
+
getDeviceModel() {
|
|
7
|
+
return `Node.js/${process.version} (${os.type()} ${os.arch()})`;
|
|
8
|
+
}
|
|
9
|
+
getDefaultLogLevel() {
|
|
10
|
+
const envLogLevel = Number.parseInt(process.env.MTCUTE_LOG_LEVEL ?? "");
|
|
11
|
+
if (!Number.isNaN(envLogLevel)) {
|
|
12
|
+
return envLogLevel;
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
NodePlatform.prototype.log = defaultLoggingHandler;
|
|
18
|
+
NodePlatform.prototype.beforeExit = beforeExit;
|
|
19
|
+
NodePlatform.prototype.normalizeFile = normalizeFile;
|
|
20
|
+
export {
|
|
21
|
+
NodePlatform
|
|
22
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
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 net = require("@fuman/net");
|
|
9
|
+
const node = require("@fuman/node");
|
|
10
|
+
const core = require("@mtcute/core");
|
|
11
|
+
class HttpProxyTcpTransport {
|
|
12
|
+
constructor(proxy) {
|
|
13
|
+
this.proxy = proxy;
|
|
14
|
+
}
|
|
15
|
+
async connect(dc) {
|
|
16
|
+
let conn;
|
|
17
|
+
if (this.proxy.tls) {
|
|
18
|
+
conn = await node.connectTls({
|
|
19
|
+
address: this.proxy.host,
|
|
20
|
+
port: this.proxy.port,
|
|
21
|
+
extraOptions: this.proxy.tlsOptions
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
conn = await node.connectTcp({
|
|
25
|
+
address: this.proxy.host,
|
|
26
|
+
port: this.proxy.port
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
await net.performHttpProxyHandshake(conn, conn, this.proxy, {
|
|
30
|
+
address: dc.ipAddress,
|
|
31
|
+
port: dc.port
|
|
32
|
+
});
|
|
33
|
+
return conn;
|
|
34
|
+
}
|
|
35
|
+
packetCodec() {
|
|
36
|
+
return new core.IntermediatePacketCodec();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
class SocksProxyTcpTransport {
|
|
40
|
+
constructor(proxy) {
|
|
41
|
+
this.proxy = proxy;
|
|
42
|
+
}
|
|
43
|
+
async connect(dc) {
|
|
44
|
+
const conn = await node.connectTcp({
|
|
45
|
+
address: this.proxy.host,
|
|
46
|
+
port: this.proxy.port
|
|
47
|
+
});
|
|
48
|
+
await net.performSocksHandshake(conn, conn, this.proxy, {
|
|
49
|
+
address: dc.ipAddress,
|
|
50
|
+
port: dc.port
|
|
51
|
+
});
|
|
52
|
+
return conn;
|
|
53
|
+
}
|
|
54
|
+
packetCodec() {
|
|
55
|
+
return new core.IntermediatePacketCodec();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
class MtProxyTcpTransport extends core.BaseMtProxyTransport {
|
|
59
|
+
async _connectTcp(endpoint) {
|
|
60
|
+
return node.connectTcp(endpoint);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
Object.defineProperty(exports, "HttpProxyConnectionError", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: () => net.HttpProxyConnectionError
|
|
66
|
+
});
|
|
67
|
+
Object.defineProperty(exports, "SocksProxyConnectionError", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: () => net.SocksProxyConnectionError
|
|
70
|
+
});
|
|
71
|
+
exports.HttpProxyTcpTransport = HttpProxyTcpTransport;
|
|
72
|
+
exports.MtProxyTcpTransport = MtProxyTcpTransport;
|
|
73
|
+
exports.SocksProxyTcpTransport = SocksProxyTcpTransport;
|
|
@@ -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
|
+
}
|
|
@@ -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/proxies.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { performHttpProxyHandshake, performSocksHandshake } from "@fuman/net";
|
|
2
|
+
import { HttpProxyConnectionError, SocksProxyConnectionError } from "@fuman/net";
|
|
3
|
+
import { connectTls, connectTcp } from "@fuman/node";
|
|
4
|
+
import { IntermediatePacketCodec, BaseMtProxyTransport } from "@mtcute/core";
|
|
5
|
+
class HttpProxyTcpTransport {
|
|
6
|
+
constructor(proxy) {
|
|
7
|
+
this.proxy = proxy;
|
|
8
|
+
}
|
|
9
|
+
async connect(dc) {
|
|
10
|
+
let conn;
|
|
11
|
+
if (this.proxy.tls) {
|
|
12
|
+
conn = await connectTls({
|
|
13
|
+
address: this.proxy.host,
|
|
14
|
+
port: this.proxy.port,
|
|
15
|
+
extraOptions: this.proxy.tlsOptions
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
conn = await connectTcp({
|
|
19
|
+
address: this.proxy.host,
|
|
20
|
+
port: this.proxy.port
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
await performHttpProxyHandshake(conn, conn, this.proxy, {
|
|
24
|
+
address: dc.ipAddress,
|
|
25
|
+
port: dc.port
|
|
26
|
+
});
|
|
27
|
+
return conn;
|
|
28
|
+
}
|
|
29
|
+
packetCodec() {
|
|
30
|
+
return new IntermediatePacketCodec();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
class SocksProxyTcpTransport {
|
|
34
|
+
constructor(proxy) {
|
|
35
|
+
this.proxy = proxy;
|
|
36
|
+
}
|
|
37
|
+
async connect(dc) {
|
|
38
|
+
const conn = await connectTcp({
|
|
39
|
+
address: this.proxy.host,
|
|
40
|
+
port: this.proxy.port
|
|
41
|
+
});
|
|
42
|
+
await performSocksHandshake(conn, conn, this.proxy, {
|
|
43
|
+
address: dc.ipAddress,
|
|
44
|
+
port: dc.port
|
|
45
|
+
});
|
|
46
|
+
return conn;
|
|
47
|
+
}
|
|
48
|
+
packetCodec() {
|
|
49
|
+
return new IntermediatePacketCodec();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
class MtProxyTcpTransport extends BaseMtProxyTransport {
|
|
53
|
+
async _connectTcp(endpoint) {
|
|
54
|
+
return connectTcp(endpoint);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
HttpProxyConnectionError,
|
|
59
|
+
HttpProxyTcpTransport,
|
|
60
|
+
MtProxyTcpTransport,
|
|
61
|
+
SocksProxyConnectionError,
|
|
62
|
+
SocksProxyTcpTransport
|
|
63
|
+
};
|
package/utils/tcp.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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 = require("@fuman/node");
|
|
9
|
+
const core = require("@mtcute/core");
|
|
10
|
+
class TcpTransport {
|
|
11
|
+
connect(dc) {
|
|
12
|
+
return node.connectTcp({ address: dc.ipAddress, port: dc.port });
|
|
13
|
+
}
|
|
14
|
+
packetCodec() {
|
|
15
|
+
return new core.IntermediatePacketCodec();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.TcpTransport = TcpTransport;
|