@mtcute/node 0.16.7 → 0.16.13

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.
Files changed (124) hide show
  1. package/chunks/cjs/BpvQ752Q.js +33 -0
  2. package/chunks/cjs/D7i-4e0W.js +74 -0
  3. package/chunks/cjs/HP2yqAk_.js +79 -0
  4. package/chunks/cjs/package.json +3 -0
  5. package/chunks/es/CKso6cAV.js +75 -0
  6. package/chunks/es/CnOjjhdK.js +29 -0
  7. package/chunks/es/HZgHrOPU.js +69 -0
  8. package/{cjs/client.d.ts → client.d.ts} +3 -4
  9. package/{cjs/common-internals-node → common-internals-node}/platform.d.ts +1 -1
  10. package/index.cjs +449 -0
  11. package/index.d.ts +8 -1
  12. package/index.js +410 -1
  13. package/{cjs/methods → methods}/download-file.d.ts +1 -1
  14. package/{esm/methods → methods}/download-node-stream.d.ts +2 -2
  15. package/methods.cjs +17 -0
  16. package/methods.d.ts +3 -1
  17. package/methods.js +6 -1
  18. package/package.json +49 -33
  19. package/{esm/sqlite → sqlite}/driver.d.ts +2 -3
  20. package/{esm/sqlite → sqlite}/index.d.ts +1 -1
  21. package/sqlite/sqlite.test.d.ts +1 -0
  22. package/{cjs/utils → utils}/crypto.d.ts +1 -2
  23. package/utils/crypto.test.d.ts +1 -0
  24. package/{cjs/utils → utils}/normalize-file.d.ts +1 -1
  25. package/utils/stream-utils.test.d.ts +1 -0
  26. package/{cjs/utils → utils}/tcp.d.ts +4 -5
  27. package/utils/tcp.test.d.ts +1 -0
  28. package/utils.cjs +20 -0
  29. package/utils.d.ts +3 -1
  30. package/utils.js +9 -1
  31. package/{cjs/worker.d.ts → worker.d.ts} +1 -2
  32. package/cjs/client.js +0 -112
  33. package/cjs/client.js.map +0 -1
  34. package/cjs/common-internals-node/exit-hook.js +0 -45
  35. package/cjs/common-internals-node/exit-hook.js.map +0 -1
  36. package/cjs/common-internals-node/logging.js +0 -34
  37. package/cjs/common-internals-node/logging.js.map +0 -1
  38. package/cjs/common-internals-node/platform.js +0 -85
  39. package/cjs/common-internals-node/platform.js.map +0 -1
  40. package/cjs/index.js +0 -31
  41. package/cjs/index.js.map +0 -1
  42. package/cjs/methods/download-file.js +0 -33
  43. package/cjs/methods/download-file.js.map +0 -1
  44. package/cjs/methods/download-node-stream.d.ts +0 -8
  45. package/cjs/methods/download-node-stream.js +0 -14
  46. package/cjs/methods/download-node-stream.js.map +0 -1
  47. package/cjs/methods.js +0 -29
  48. package/cjs/methods.js.map +0 -1
  49. package/cjs/package.json +0 -3
  50. package/cjs/sqlite/driver.d.ts +0 -26
  51. package/cjs/sqlite/driver.js +0 -29
  52. package/cjs/sqlite/driver.js.map +0 -1
  53. package/cjs/sqlite/index.d.ts +0 -8
  54. package/cjs/sqlite/index.js +0 -18
  55. package/cjs/sqlite/index.js.map +0 -1
  56. package/cjs/utils/crypto.js +0 -71
  57. package/cjs/utils/crypto.js.map +0 -1
  58. package/cjs/utils/normalize-file.js +0 -30
  59. package/cjs/utils/normalize-file.js.map +0 -1
  60. package/cjs/utils/stream-utils.js +0 -76
  61. package/cjs/utils/stream-utils.js.map +0 -1
  62. package/cjs/utils/tcp.js +0 -126
  63. package/cjs/utils/tcp.js.map +0 -1
  64. package/cjs/utils/version.js +0 -21
  65. package/cjs/utils/version.js.map +0 -1
  66. package/cjs/utils.js +0 -26
  67. package/cjs/utils.js.map +0 -1
  68. package/cjs/worker.js +0 -48
  69. package/cjs/worker.js.map +0 -1
  70. package/esm/client.d.ts +0 -48
  71. package/esm/client.js +0 -107
  72. package/esm/client.js.map +0 -1
  73. package/esm/common-internals-node/exit-hook.d.ts +0 -1
  74. package/esm/common-internals-node/exit-hook.js +0 -42
  75. package/esm/common-internals-node/exit-hook.js.map +0 -1
  76. package/esm/common-internals-node/logging.d.ts +0 -2
  77. package/esm/common-internals-node/logging.js +0 -31
  78. package/esm/common-internals-node/logging.js.map +0 -1
  79. package/esm/common-internals-node/platform.d.ts +0 -18
  80. package/esm/common-internals-node/platform.js +0 -58
  81. package/esm/common-internals-node/platform.js.map +0 -1
  82. package/esm/index.d.ts +0 -8
  83. package/esm/index.js +0 -9
  84. package/esm/index.js.map +0 -1
  85. package/esm/methods/download-file.d.ts +0 -9
  86. package/esm/methods/download-file.js +0 -30
  87. package/esm/methods/download-file.js.map +0 -1
  88. package/esm/methods/download-node-stream.js +0 -11
  89. package/esm/methods/download-node-stream.js.map +0 -1
  90. package/esm/methods.d.ts +0 -3
  91. package/esm/methods.js +0 -4
  92. package/esm/methods.js.map +0 -1
  93. package/esm/sqlite/driver.js +0 -22
  94. package/esm/sqlite/driver.js.map +0 -1
  95. package/esm/sqlite/index.js +0 -13
  96. package/esm/sqlite/index.js.map +0 -1
  97. package/esm/utils/crypto.d.ts +0 -16
  98. package/esm/utils/crypto.js +0 -69
  99. package/esm/utils/crypto.js.map +0 -1
  100. package/esm/utils/normalize-file.d.ts +0 -6
  101. package/esm/utils/normalize-file.js +0 -27
  102. package/esm/utils/normalize-file.js.map +0 -1
  103. package/esm/utils/stream-utils.d.ts +0 -3
  104. package/esm/utils/stream-utils.js +0 -72
  105. package/esm/utils/stream-utils.js.map +0 -1
  106. package/esm/utils/tcp.d.ts +0 -30
  107. package/esm/utils/tcp.js +0 -118
  108. package/esm/utils/tcp.js.map +0 -1
  109. package/esm/utils/version.d.ts +0 -3
  110. package/esm/utils/version.js +0 -17
  111. package/esm/utils/version.js.map +0 -1
  112. package/esm/utils.d.ts +0 -3
  113. package/esm/utils.js +0 -4
  114. package/esm/utils.js.map +0 -1
  115. package/esm/worker.d.ts +0 -11
  116. package/esm/worker.js +0 -43
  117. package/esm/worker.js.map +0 -1
  118. /package/{cjs/common-internals-node → common-internals-node}/exit-hook.d.ts +0 -0
  119. /package/{cjs/common-internals-node → common-internals-node}/logging.d.ts +0 -0
  120. /package/{cjs/index.d.ts → index.d.cts} +0 -0
  121. /package/{cjs/methods.d.ts → methods.d.cts} +0 -0
  122. /package/{cjs/utils → utils}/stream-utils.d.ts +0 -0
  123. /package/{cjs/utils → utils}/version.d.ts +0 -0
  124. /package/{cjs/utils.d.ts → utils.d.cts} +0 -0
package/index.js CHANGED
@@ -1 +1,410 @@
1
- export * from './esm/index.js'
1
+ import { createInterface } from "node:readline";
2
+ import { BaseTelegramClient as BaseTelegramClient$1, TelegramClient as TelegramClient$1 } from "@mtcute/core/client.js";
3
+ import { setPlatform } from "@mtcute/core/platform.js";
4
+ import * as os from "node:os";
5
+ import { createReadStream, ReadStream } from "node:fs";
6
+ import { stat } from "node:fs/promises";
7
+ import { basename } from "node:path";
8
+ import { Readable } from "node:stream";
9
+ import { nodeStreamToWeb } from "./chunks/es/CKso6cAV.js";
10
+ import { downloadToFile, downloadAsNodeStream } from "./chunks/es/CnOjjhdK.js";
11
+ import { BaseSqliteStorageDriver, BaseSqliteStorage, TransportState, MtcuteError, IntermediatePacketCodec } from "@mtcute/core";
12
+ export * from "@mtcute/core";
13
+ import sqlite3 from "better-sqlite3";
14
+ import { NodeCryptoProvider } from "./chunks/es/HZgHrOPU.js";
15
+ import EventEmitter from "node:events";
16
+ import { connect } from "node:net";
17
+ import { parentPort, Worker } from "node:worker_threads";
18
+ import { TelegramWorker as TelegramWorker$1, TelegramWorkerPort as TelegramWorkerPort$1 } from "@mtcute/core/worker.js";
19
+ export * from "@mtcute/html-parser";
20
+ export * from "@mtcute/markdown-parser";
21
+ async function normalizeFile(file) {
22
+ if (typeof file === "string") {
23
+ file = createReadStream(file);
24
+ }
25
+ if (file instanceof ReadStream) {
26
+ const fileName = basename(file.path.toString());
27
+ const fileSize = await stat(file.path.toString()).then((stat2) => stat2.size);
28
+ return {
29
+ file: nodeStreamToWeb(file),
30
+ fileName,
31
+ fileSize
32
+ };
33
+ }
34
+ if (file instanceof Readable) {
35
+ return {
36
+ file: nodeStreamToWeb(file)
37
+ };
38
+ }
39
+ return null;
40
+ }
41
+ let installed = false;
42
+ let handled = false;
43
+ const callbacks = /* @__PURE__ */ new Set();
44
+ const myHandlers = /* @__PURE__ */ new Map();
45
+ function register(shouldManuallyExit, signal, event) {
46
+ function eventHandler() {
47
+ if (handled) {
48
+ return;
49
+ }
50
+ handled = true;
51
+ for (const callback of callbacks) {
52
+ callback();
53
+ }
54
+ for (const [event2, handler] of myHandlers) {
55
+ process.off(event2, handler);
56
+ }
57
+ if (shouldManuallyExit) {
58
+ process.kill(process.pid, signal);
59
+ }
60
+ }
61
+ process.on(event, eventHandler);
62
+ myHandlers.set(event, eventHandler);
63
+ }
64
+ function beforeExit(fn) {
65
+ if (typeof process === "undefined") return () => {
66
+ };
67
+ if (!installed) {
68
+ installed = true;
69
+ register(true, 0, "beforeExit");
70
+ register(true, 2, "SIGINT");
71
+ register(true, 15, "SIGTERM");
72
+ register(false, 15, "exit");
73
+ }
74
+ callbacks.add(fn);
75
+ return () => {
76
+ callbacks.delete(fn);
77
+ };
78
+ }
79
+ const isTty = typeof process === "object" && Boolean(process.stdout?.isTTY);
80
+ const BASE_FORMAT = isTty ? "%s [%s] [%s%s\x1B[0m] " : "%s [%s] [%s] ";
81
+ const LEVEL_NAMES = isTty ? [
82
+ "",
83
+ // OFF
84
+ "\x1B[31mERR\x1B[0m",
85
+ "\x1B[33mWRN\x1B[0m",
86
+ "\x1B[34mINF\x1B[0m",
87
+ "\x1B[36mDBG\x1B[0m",
88
+ "\x1B[35mVRB\x1B[0m"
89
+ ] : [
90
+ "",
91
+ // OFF
92
+ "ERR",
93
+ "WRN",
94
+ "INF",
95
+ "DBG",
96
+ "VRB"
97
+ ];
98
+ const TAG_COLORS = [6, 2, 3, 4, 5, 1].map((i) => `\x1B[3${i};1m`);
99
+ const defaultLoggingHandler = isTty ? (color, level, tag, fmt, args) => {
100
+ console.log(BASE_FORMAT + fmt, (/* @__PURE__ */ new Date()).toISOString(), LEVEL_NAMES[level], TAG_COLORS[color], tag, ...args);
101
+ } : (color, level, tag, fmt, args) => {
102
+ console.log(BASE_FORMAT + fmt, (/* @__PURE__ */ new Date()).toISOString(), LEVEL_NAMES[level], tag, ...args);
103
+ };
104
+ const BUFFER_BASE64_URL_AVAILABLE = typeof Buffer.isEncoding === "function" && Buffer.isEncoding("base64url");
105
+ const toBuffer = (buf) => Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
106
+ class NodePlatform {
107
+ getDeviceModel() {
108
+ return `Node.js/${process.version} (${os.type()} ${os.arch()})`;
109
+ }
110
+ getDefaultLogLevel() {
111
+ const envLogLevel = Number.parseInt(process.env.MTCUTE_LOG_LEVEL ?? "");
112
+ if (!Number.isNaN(envLogLevel)) {
113
+ return envLogLevel;
114
+ }
115
+ return null;
116
+ }
117
+ // ITlPlatform
118
+ utf8ByteLength(str) {
119
+ return Buffer.byteLength(str, "utf8");
120
+ }
121
+ utf8Encode(str) {
122
+ return Buffer.from(str, "utf8");
123
+ }
124
+ utf8Decode(buf) {
125
+ return toBuffer(buf).toString("utf8");
126
+ }
127
+ hexEncode(buf) {
128
+ return toBuffer(buf).toString("hex");
129
+ }
130
+ hexDecode(str) {
131
+ return Buffer.from(str, "hex");
132
+ }
133
+ base64Encode(buf, url = false) {
134
+ const nodeBuffer = toBuffer(buf);
135
+ if (url && BUFFER_BASE64_URL_AVAILABLE) return nodeBuffer.toString("base64url");
136
+ const str = nodeBuffer.toString("base64");
137
+ if (url) return str.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
138
+ return str;
139
+ }
140
+ base64Decode(string, url = false) {
141
+ if (url && BUFFER_BASE64_URL_AVAILABLE) {
142
+ return Buffer.from(string, "base64url");
143
+ }
144
+ if (url) {
145
+ string = string.replace(/-/g, "+").replace(/_/g, "/");
146
+ while (string.length % 4) string += "=";
147
+ }
148
+ return Buffer.from(string, "base64");
149
+ }
150
+ }
151
+ NodePlatform.prototype.log = defaultLoggingHandler;
152
+ NodePlatform.prototype.beforeExit = beforeExit;
153
+ NodePlatform.prototype.normalizeFile = normalizeFile;
154
+ class SqliteStorageDriver extends BaseSqliteStorageDriver {
155
+ constructor(filename = ":memory:", params) {
156
+ super();
157
+ this.filename = filename;
158
+ this.params = params;
159
+ }
160
+ _createDatabase() {
161
+ const db = sqlite3(this.filename, {
162
+ ...this.params?.options,
163
+ verbose: this._log.mgr.level >= 5 ? this._log.verbose : void 0
164
+ });
165
+ if (!this.params?.disableWal) {
166
+ db.pragma("journal_mode = WAL");
167
+ }
168
+ return db;
169
+ }
170
+ }
171
+ class SqliteStorage extends BaseSqliteStorage {
172
+ constructor(filename = ":memory:", params) {
173
+ super(new SqliteStorageDriver(filename, params));
174
+ this.filename = filename;
175
+ this.params = params;
176
+ }
177
+ }
178
+ class BaseTcpTransport extends EventEmitter {
179
+ _currentDc = null;
180
+ _state = TransportState.Idle;
181
+ _socket = null;
182
+ _crypto;
183
+ log;
184
+ packetCodecInitialized = false;
185
+ _updateLogPrefix() {
186
+ if (this._currentDc) {
187
+ this.log.prefix = `[TCP:${this._currentDc.ipAddress}:${this._currentDc.port}] `;
188
+ } else {
189
+ this.log.prefix = "[TCP:disconnected] ";
190
+ }
191
+ }
192
+ setup(crypto, log) {
193
+ this._crypto = crypto;
194
+ this.log = log.create("tcp");
195
+ this._updateLogPrefix();
196
+ }
197
+ state() {
198
+ return this._state;
199
+ }
200
+ currentDc() {
201
+ return this._currentDc;
202
+ }
203
+ // eslint-disable-next-line unused-imports/no-unused-vars
204
+ connect(dc, testMode) {
205
+ if (this._state !== TransportState.Idle) {
206
+ throw new MtcuteError("Transport is not IDLE");
207
+ }
208
+ if (!this.packetCodecInitialized) {
209
+ this._packetCodec.setup?.(this._crypto, this.log);
210
+ this._packetCodec.on("error", (err) => this.emit("error", err));
211
+ this._packetCodec.on("packet", (buf) => this.emit("message", buf));
212
+ this.packetCodecInitialized = true;
213
+ }
214
+ this._state = TransportState.Connecting;
215
+ this._currentDc = dc;
216
+ this._updateLogPrefix();
217
+ this.log.debug("connecting to %j", dc);
218
+ this._socket = connect(dc.port, dc.ipAddress, this.handleConnect.bind(this));
219
+ this._socket.on("data", (data) => {
220
+ this._packetCodec.feed(data);
221
+ });
222
+ this._socket.on("error", this.handleError.bind(this));
223
+ this._socket.on("close", this.close.bind(this));
224
+ }
225
+ close() {
226
+ if (this._state === TransportState.Idle) return;
227
+ this.log.info("connection closed");
228
+ this._state = TransportState.Idle;
229
+ this._socket.removeAllListeners();
230
+ this._socket.destroy();
231
+ this._socket = null;
232
+ this._currentDc = null;
233
+ this._packetCodec.reset();
234
+ this.emit("close");
235
+ }
236
+ handleError(error) {
237
+ this.log.error("error: %s", error.stack);
238
+ if (this.listenerCount("error") > 0) {
239
+ this.emit("error", error);
240
+ }
241
+ }
242
+ handleConnect() {
243
+ this.log.info("connected");
244
+ Promise.resolve(this._packetCodec.tag()).then((initialMessage) => {
245
+ if (initialMessage.length) {
246
+ this._socket.write(initialMessage, (err) => {
247
+ if (err) {
248
+ this.log.error("failed to write initial message: %s", err.stack);
249
+ this.emit("error");
250
+ this.close();
251
+ } else {
252
+ this._state = TransportState.Ready;
253
+ this.emit("ready");
254
+ }
255
+ });
256
+ } else {
257
+ this._state = TransportState.Ready;
258
+ this.emit("ready");
259
+ }
260
+ }).catch((err) => this.emit("error", err));
261
+ }
262
+ async send(bytes) {
263
+ const framed = await this._packetCodec.encode(bytes);
264
+ if (this._state !== TransportState.Ready) {
265
+ throw new MtcuteError("Transport is not READY");
266
+ }
267
+ return new Promise((resolve, reject) => {
268
+ this._socket.write(framed, (error) => {
269
+ if (error) {
270
+ reject(error);
271
+ } else {
272
+ resolve();
273
+ }
274
+ });
275
+ });
276
+ }
277
+ }
278
+ class TcpTransport extends BaseTcpTransport {
279
+ _packetCodec = new IntermediatePacketCodec();
280
+ }
281
+ let nativeCrypto;
282
+ try {
283
+ nativeCrypto = (await import("@mtcute/crypto-node")).NodeNativeCryptoProvider;
284
+ } catch {
285
+ }
286
+ class BaseTelegramClient extends BaseTelegramClient$1 {
287
+ constructor(opts) {
288
+ if (!opts.platformless) setPlatform(new NodePlatform());
289
+ super({
290
+ // eslint-disable-next-line
291
+ crypto: nativeCrypto ? new nativeCrypto() : new NodeCryptoProvider(),
292
+ transport: () => new TcpTransport(),
293
+ ...opts,
294
+ storage: typeof opts.storage === "string" ? new SqliteStorage(opts.storage) : opts.storage ?? new SqliteStorage("client.session")
295
+ });
296
+ }
297
+ }
298
+ class TelegramClient extends TelegramClient$1 {
299
+ constructor(opts) {
300
+ if ("client" in opts) {
301
+ super(opts);
302
+ return;
303
+ }
304
+ super({
305
+ client: new BaseTelegramClient(opts),
306
+ disableUpdates: opts.disableUpdates,
307
+ skipConversationUpdates: opts.skipConversationUpdates,
308
+ updates: opts.updates
309
+ });
310
+ }
311
+ _rl;
312
+ /**
313
+ * Tiny wrapper over Node `readline` package
314
+ * for simpler user input for `.start()` method.
315
+ *
316
+ * Associated `readline` interface is closed
317
+ * after `start()` returns, or with the client.
318
+ *
319
+ * @param text Text of the question
320
+ */
321
+ input(text) {
322
+ if (!this._rl) {
323
+ this._rl = createInterface({
324
+ input: process.stdin,
325
+ output: process.stdout
326
+ });
327
+ }
328
+ return new Promise((res) => this._rl?.question(text, res));
329
+ }
330
+ close() {
331
+ this._rl?.close();
332
+ return super.close();
333
+ }
334
+ start(params = {}) {
335
+ if (!params.botToken) {
336
+ if (!params.phone) params.phone = () => this.input("phone > ");
337
+ if (!params.code) params.code = () => this.input("code > ");
338
+ if (!params.password) {
339
+ params.password = () => this.input("2fa password > ");
340
+ }
341
+ }
342
+ return super.start(params).then((user) => {
343
+ if (this._rl) {
344
+ this._rl.close();
345
+ delete this._rl;
346
+ }
347
+ return user;
348
+ });
349
+ }
350
+ run(params, then) {
351
+ if (typeof params === "function") {
352
+ then = params;
353
+ params = {};
354
+ }
355
+ this.start(params).then(then).catch((err) => this.emitError(err));
356
+ }
357
+ downloadToFile(filename, location, params) {
358
+ return downloadToFile(this, filename, location, params);
359
+ }
360
+ downloadAsNodeStream(location, params) {
361
+ return downloadAsNodeStream(this, location, params);
362
+ }
363
+ }
364
+ let _registered = false;
365
+ class TelegramWorker extends TelegramWorker$1 {
366
+ registerWorker(handler) {
367
+ if (!parentPort) {
368
+ throw new Error("TelegramWorker must be created from a worker thread");
369
+ }
370
+ if (_registered) {
371
+ throw new Error("TelegramWorker must be created only once");
372
+ }
373
+ _registered = true;
374
+ const port = parentPort;
375
+ const respond = port.postMessage.bind(port);
376
+ parentPort.on("message", (message) => handler(message, respond));
377
+ return respond;
378
+ }
379
+ }
380
+ class TelegramWorkerPort extends TelegramWorkerPort$1 {
381
+ constructor(options) {
382
+ setPlatform(new NodePlatform());
383
+ super(options);
384
+ this.options = options;
385
+ }
386
+ connectToWorker(worker, handler) {
387
+ if (!(worker instanceof Worker)) {
388
+ throw new TypeError("Only worker_threads are supported");
389
+ }
390
+ const send = worker.postMessage.bind(worker);
391
+ worker.on("message", handler);
392
+ return [
393
+ send,
394
+ () => {
395
+ worker.off("message", handler);
396
+ }
397
+ ];
398
+ }
399
+ }
400
+ export {
401
+ BaseTcpTransport,
402
+ BaseTelegramClient,
403
+ NodePlatform,
404
+ SqliteStorage,
405
+ SqliteStorageDriver,
406
+ TcpTransport,
407
+ TelegramClient,
408
+ TelegramWorker,
409
+ TelegramWorkerPort
410
+ };
@@ -1,4 +1,4 @@
1
- import type { FileDownloadLocation, FileDownloadParameters, ITelegramClient } from '@mtcute/core';
1
+ import { FileDownloadLocation, FileDownloadParameters, ITelegramClient } from '@mtcute/core';
2
2
  /**
3
3
  * Download a remote file to a local file (only for NodeJS).
4
4
  * Promise will resolve once the download is complete.
@@ -1,5 +1,5 @@
1
- import type { Readable } from 'node:stream';
2
- import type { FileDownloadLocation, FileDownloadParameters, ITelegramClient } from '@mtcute/core';
1
+ import { Readable } from 'node:stream';
2
+ import { FileDownloadLocation, FileDownloadParameters, ITelegramClient } from '@mtcute/core';
3
3
  /**
4
4
  * Download a remote file as a Node.js Readable stream.
5
5
  *
package/methods.cjs ADDED
@@ -0,0 +1,17 @@
1
+ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
+ globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
+ console.warn("[@mtcute/node] CommonJS support is deprecated and will be removed soon. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[@mtcute/node] 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 downloadNodeStream = require("./chunks/cjs/BpvQ752Q.js");
9
+ const methods_js = require("@mtcute/core/methods.js");
10
+ exports.downloadAsNodeStream = downloadNodeStream.downloadAsNodeStream;
11
+ exports.downloadToFile = downloadNodeStream.downloadToFile;
12
+ Object.keys(methods_js).forEach((k) => {
13
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
14
+ enumerable: true,
15
+ get: () => methods_js[k]
16
+ });
17
+ });
package/methods.d.ts CHANGED
@@ -1 +1,3 @@
1
- export * from './esm/methods.js'
1
+ export { downloadToFile } from './methods/download-file.js';
2
+ export { downloadAsNodeStream } from './methods/download-node-stream.js';
3
+ export * from '@mtcute/core/methods.js';
package/methods.js CHANGED
@@ -1 +1,6 @@
1
- export * from './esm/methods.js'
1
+ import { downloadAsNodeStream, downloadToFile } from "./chunks/es/CnOjjhdK.js";
2
+ export * from "@mtcute/core/methods.js";
3
+ export {
4
+ downloadAsNodeStream,
5
+ downloadToFile
6
+ };
package/package.json CHANGED
@@ -1,38 +1,54 @@
1
1
  {
2
- "name": "@mtcute/node",
3
- "type": "module",
4
- "version": "0.16.7",
5
- "description": "Meta-package for Node.js",
6
- "author": "alina sireneva <alina@tei.su>",
7
- "license": "MIT",
8
- "sideEffects": false,
9
- "exports": {
10
- ".": {
11
- "import": "./esm/index.js",
12
- "require": "./cjs/index.js"
2
+ "name": "@mtcute/node",
3
+ "type": "module",
4
+ "version": "0.16.13",
5
+ "description": "Meta-package for Node.js",
6
+ "author": "alina sireneva <alina@tei.su>",
7
+ "license": "MIT",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./index.d.ts",
13
+ "default": "./index.js"
14
+ },
15
+ "require": {
16
+ "types": "./index.d.cts",
17
+ "default": "./index.cjs"
18
+ }
19
+ },
20
+ "./utils.js": {
21
+ "import": {
22
+ "types": "./utils.d.ts",
23
+ "default": "./utils.js"
24
+ },
25
+ "require": {
26
+ "types": "./utils.d.cts",
27
+ "default": "./utils.cjs"
28
+ }
29
+ },
30
+ "./methods.js": {
31
+ "import": {
32
+ "types": "./methods.d.ts",
33
+ "default": "./methods.js"
34
+ },
35
+ "require": {
36
+ "types": "./methods.d.cts",
37
+ "default": "./methods.cjs"
38
+ }
39
+ }
13
40
  },
14
- "./utils.js": {
15
- "import": "./esm/utils.js",
16
- "require": "./cjs/utils.js"
41
+ "scripts": {},
42
+ "dependencies": {
43
+ "@mtcute/core": "^0.16.13",
44
+ "@mtcute/html-parser": "^0.16.9",
45
+ "@mtcute/markdown-parser": "^0.16.9",
46
+ "@mtcute/wasm": "^0.16.11",
47
+ "better-sqlite3": "11.3.0"
17
48
  },
18
- "./methods.js": {
19
- "import": "./esm/methods.js",
20
- "require": "./cjs/methods.js"
49
+ "homepage": "https://mtcute.dev",
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "https://github.com/mtcute/mtcute"
21
53
  }
22
- },
23
- "scripts": {},
24
- "dependencies": {
25
- "@mtcute/core": "^0.16.7",
26
- "@mtcute/html-parser": "^0.16.7",
27
- "@mtcute/markdown-parser": "^0.16.7",
28
- "@mtcute/wasm": "^0.16.7",
29
- "better-sqlite3": "9.5.0"
30
- },
31
- "main": "cjs/index.js",
32
- "module": "esm/index.js",
33
- "homepage": "https://mtcute.dev",
34
- "repository": {
35
- "type": "git",
36
- "url": "https://github.com/mtcute/mtcute"
37
- }
38
54
  }
@@ -1,6 +1,5 @@
1
- import type { Options } from 'better-sqlite3';
2
- import type { ISqliteDatabase } from '@mtcute/core';
3
- import { BaseSqliteStorageDriver } from '@mtcute/core';
1
+ import { Options } from 'better-sqlite3';
2
+ import { ISqliteDatabase, BaseSqliteStorageDriver } from '@mtcute/core';
4
3
  export interface SqliteStorageDriverOptions {
5
4
  /**
6
5
  * By default, WAL mode is enabled, which
@@ -1,5 +1,5 @@
1
1
  import { BaseSqliteStorage } from '@mtcute/core';
2
- import type { SqliteStorageDriverOptions } from './driver.js';
2
+ import { SqliteStorageDriverOptions } from './driver.js';
3
3
  export { SqliteStorageDriver } from './driver.js';
4
4
  export declare class SqliteStorage extends BaseSqliteStorage {
5
5
  readonly filename: string;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,4 @@
1
- import type { IAesCtr, ICryptoProvider, IEncryptionScheme } from '@mtcute/core/utils.js';
2
- import { BaseCryptoProvider } from '@mtcute/core/utils.js';
1
+ import { IAesCtr, ICryptoProvider, IEncryptionScheme, BaseCryptoProvider } from '@mtcute/core/utils.js';
3
2
  export declare abstract class BaseNodeCryptoProvider extends BaseCryptoProvider {
4
3
  createAesCtr(key: Uint8Array, iv: Uint8Array): IAesCtr;
5
4
  pbkdf2(password: Uint8Array, salt: Uint8Array, iterations: number, keylen?: number, algo?: string): Promise<Uint8Array>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import type { UploadFileLike } from '@mtcute/core';
1
+ import { UploadFileLike } from '@mtcute/core';
2
2
  export declare function normalizeFile(file: UploadFileLike): Promise<{
3
3
  file: UploadFileLike;
4
4
  fileName?: string | undefined;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,7 @@
1
- import EventEmitter from 'node:events';
2
- import type { Socket } from 'node:net';
3
- import type { IPacketCodec, ITelegramTransport } from '@mtcute/core';
4
- import { IntermediatePacketCodec, TransportState } from '@mtcute/core';
5
- import type { BasicDcOption, ICryptoProvider, Logger } from '@mtcute/core/utils.js';
1
+ import { default as EventEmitter } from 'node:events';
2
+ import { Socket } from 'node:net';
3
+ import { IPacketCodec, ITelegramTransport, IntermediatePacketCodec, TransportState } from '@mtcute/core';
4
+ import { BasicDcOption, ICryptoProvider, Logger } from '@mtcute/core/utils.js';
6
5
  /**
7
6
  * Base for TCP transports.
8
7
  * Subclasses must provide packet codec in `_packetCodec` property
@@ -0,0 +1 @@
1
+ export {};
package/utils.cjs ADDED
@@ -0,0 +1,20 @@
1
+ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
+ globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
+ console.warn("[@mtcute/node] CommonJS support is deprecated and will be removed soon. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[@mtcute/node] 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 crypto = require("./chunks/cjs/D7i-4e0W.js");
9
+ const streamUtils = require("./chunks/cjs/HP2yqAk_.js");
10
+ const utils_js = require("@mtcute/core/utils.js");
11
+ exports.BaseNodeCryptoProvider = crypto.BaseNodeCryptoProvider;
12
+ exports.NodeCryptoProvider = crypto.NodeCryptoProvider;
13
+ exports.nodeStreamToWeb = streamUtils.nodeStreamToWeb;
14
+ exports.webStreamToNode = streamUtils.webStreamToNode;
15
+ Object.keys(utils_js).forEach((k) => {
16
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
17
+ enumerable: true,
18
+ get: () => utils_js[k]
19
+ });
20
+ });
package/utils.d.ts CHANGED
@@ -1 +1,3 @@
1
- export * from './esm/utils.js'
1
+ export * from './utils/crypto.js';
2
+ export * from './utils/stream-utils.js';
3
+ export * from '@mtcute/core/utils.js';
package/utils.js CHANGED
@@ -1 +1,9 @@
1
- export * from './esm/utils.js'
1
+ import { BaseNodeCryptoProvider, NodeCryptoProvider } from "./chunks/es/HZgHrOPU.js";
2
+ import { nodeStreamToWeb, webStreamToNode } from "./chunks/es/CKso6cAV.js";
3
+ export * from "@mtcute/core/utils.js";
4
+ export {
5
+ BaseNodeCryptoProvider,
6
+ NodeCryptoProvider,
7
+ nodeStreamToWeb,
8
+ webStreamToNode
9
+ };
@@ -1,5 +1,4 @@
1
- import type { ClientMessageHandler, RespondFn, SendFn, SomeWorker, TelegramWorkerOptions, TelegramWorkerPortOptions, WorkerCustomMethods, WorkerMessageHandler } from '@mtcute/core/worker.js';
2
- import { TelegramWorker as TelegramWorkerBase, TelegramWorkerPort as TelegramWorkerPortBase } from '@mtcute/core/worker.js';
1
+ import { ClientMessageHandler, RespondFn, SendFn, SomeWorker, TelegramWorkerOptions, TelegramWorkerPortOptions, WorkerCustomMethods, WorkerMessageHandler, TelegramWorker as TelegramWorkerBase, TelegramWorkerPort as TelegramWorkerPortBase } from '@mtcute/core/worker.js';
3
2
  export type { TelegramWorkerOptions, TelegramWorkerPortOptions, WorkerCustomMethods };
4
3
  export declare class TelegramWorker<T extends WorkerCustomMethods> extends TelegramWorkerBase<T> {
5
4
  registerWorker(handler: WorkerMessageHandler): RespondFn;