@mtkruto/node 0.1.107 → 0.1.109

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 (83) hide show
  1. package/esm/0_deps.d.ts +1 -1
  2. package/esm/0_deps.js +1 -1
  3. package/esm/4_constants.d.ts +2 -2
  4. package/esm/4_constants.js +3 -3
  5. package/esm/5_client.d.ts +1 -0
  6. package/esm/5_client.js +1 -0
  7. package/esm/client/0_html.js +26 -14
  8. package/esm/client/0_utilities.d.ts +1 -1
  9. package/esm/client/0_utilities.js +1 -2
  10. package/esm/client/1_client_abstract.d.ts +1 -1
  11. package/esm/client/1_client_abstract.js +16 -8
  12. package/esm/client/2_client_plain.d.ts +1 -2
  13. package/esm/client/2_client_plain.js +20 -15
  14. package/esm/client/3_types.d.ts +1 -1
  15. package/esm/client/4_client.d.ts +6 -57
  16. package/esm/client/4_client.js +619 -716
  17. package/esm/connection/1_connection_web_socket.d.ts +1 -9
  18. package/esm/connection/1_connection_web_socket.js +81 -108
  19. package/esm/storage/0_storage.d.ts +3 -2
  20. package/esm/storage/0_storage.js +35 -26
  21. package/esm/storage/0_utilities.d.ts +1 -1
  22. package/esm/storage/0_utilities.js +56 -26
  23. package/esm/storage/1_storage_local_storage.d.ts +1 -1
  24. package/esm/storage/1_storage_session_storage.d.ts +1 -1
  25. package/esm/tl/2_types.d.ts +441 -58
  26. package/esm/tl/2_types.js +1584 -118
  27. package/esm/tl/3_functions.d.ts +113 -16
  28. package/esm/tl/3_functions.js +364 -39
  29. package/esm/transport/1_transport_abridged.d.ts +1 -2
  30. package/esm/transport/1_transport_abridged.js +24 -19
  31. package/esm/transport/1_transport_intermediate.d.ts +1 -2
  32. package/esm/transport/1_transport_intermediate.js +23 -18
  33. package/esm/types/0_color.d.ts +2 -1
  34. package/esm/types/0_color.js +21 -1
  35. package/esm/types/0_message_entity.d.ts +1 -1
  36. package/esm/types/1_chat.js +5 -5
  37. package/esm/types/1_user.js +2 -2
  38. package/esm/types/3_message.js +1 -1
  39. package/esm/utilities/0_base64.js +3 -3
  40. package/esm/utilities/0_queue.d.ts +2 -4
  41. package/esm/utilities/0_queue.js +39 -36
  42. package/package.json +1 -1
  43. package/script/0_deps.d.ts +1 -1
  44. package/script/0_deps.js +3 -3
  45. package/script/4_constants.d.ts +2 -2
  46. package/script/4_constants.js +3 -3
  47. package/script/5_client.d.ts +1 -0
  48. package/script/5_client.js +1 -0
  49. package/script/client/0_html.js +26 -14
  50. package/script/client/0_utilities.d.ts +1 -1
  51. package/script/client/0_utilities.js +1 -2
  52. package/script/client/1_client_abstract.d.ts +1 -1
  53. package/script/client/1_client_abstract.js +16 -8
  54. package/script/client/2_client_plain.d.ts +1 -2
  55. package/script/client/2_client_plain.js +20 -15
  56. package/script/client/3_types.d.ts +1 -1
  57. package/script/client/4_client.d.ts +6 -57
  58. package/script/client/4_client.js +619 -716
  59. package/script/connection/1_connection_web_socket.d.ts +1 -9
  60. package/script/connection/1_connection_web_socket.js +81 -108
  61. package/script/storage/0_storage.d.ts +3 -2
  62. package/script/storage/0_storage.js +35 -26
  63. package/script/storage/0_utilities.d.ts +1 -1
  64. package/script/storage/0_utilities.js +55 -25
  65. package/script/storage/1_storage_local_storage.d.ts +1 -1
  66. package/script/storage/1_storage_session_storage.d.ts +1 -1
  67. package/script/tl/2_types.d.ts +441 -58
  68. package/script/tl/2_types.js +1646 -158
  69. package/script/tl/3_functions.d.ts +113 -16
  70. package/script/tl/3_functions.js +386 -53
  71. package/script/transport/1_transport_abridged.d.ts +1 -2
  72. package/script/transport/1_transport_abridged.js +24 -19
  73. package/script/transport/1_transport_intermediate.d.ts +1 -2
  74. package/script/transport/1_transport_intermediate.js +23 -18
  75. package/script/types/0_color.d.ts +2 -1
  76. package/script/types/0_color.js +24 -3
  77. package/script/types/0_message_entity.d.ts +1 -1
  78. package/script/types/1_chat.js +4 -4
  79. package/script/types/1_user.js +1 -1
  80. package/script/types/3_message.js +1 -1
  81. package/script/utilities/0_base64.js +2 -2
  82. package/script/utilities/0_queue.d.ts +2 -4
  83. package/script/utilities/0_queue.js +39 -36
@@ -1,4 +1,16 @@
1
1
  "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _ClientAbstract_dc;
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.ClientAbstract = void 0;
4
16
  const _0_deps_js_1 = require("../0_deps.js");
@@ -30,12 +42,7 @@ class ClientAbstract {
30
42
  writable: true,
31
43
  value: void 0
32
44
  });
33
- Object.defineProperty(this, "dc", {
34
- enumerable: true,
35
- configurable: true,
36
- writable: true,
37
- value: void 0
38
- });
45
+ _ClientAbstract_dc.set(this, void 0);
39
46
  Object.defineProperty(this, "stateChangeHandler", {
40
47
  enumerable: true,
41
48
  configurable: true,
@@ -54,13 +61,13 @@ class ClientAbstract {
54
61
  }
55
62
  // MaybePromise since `Client` has to deal with `Storage.set()`
56
63
  setDc(dc) {
57
- this.dc = dc;
64
+ __classPrivateFieldSet(this, _ClientAbstract_dc, dc, "f");
58
65
  }
59
66
  get connected() {
60
67
  return this.transport === undefined ? false : this.transport.connection.connected;
61
68
  }
62
69
  async connect() {
63
- this.transport = this.transportProvider({ dc: this.dc ?? this.initialDc, cdn: this.cdn });
70
+ this.transport = this.transportProvider({ dc: __classPrivateFieldGet(this, _ClientAbstract_dc, "f") ?? this.initialDc, cdn: this.cdn });
64
71
  this.transport.connection.stateChangeHandler = this.stateChangeHandler;
65
72
  await (0, _0_deps_js_1.initTgCrypto)();
66
73
  await this.transport.connection.open();
@@ -82,3 +89,4 @@ class ClientAbstract {
82
89
  }
83
90
  }
84
91
  exports.ClientAbstract = ClientAbstract;
92
+ _ClientAbstract_dc = new WeakMap();
@@ -8,8 +8,7 @@ export interface ClientPlainParams extends ClientAbstractParams {
8
8
  publicKeys?: PublicKeys;
9
9
  }
10
10
  export declare class ClientPlain extends ClientAbstract {
11
- private readonly publicKeys;
12
- private lastMsgId;
11
+ #private;
13
12
  constructor(params?: ClientPlainParams);
14
13
  invoke<T extends functions.Function<unknown>>(function_: T): Promise<T["__R"]>;
15
14
  createAuthKey(): Promise<{
@@ -1,4 +1,16 @@
1
1
  "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _ClientPlain_publicKeys, _ClientPlain_lastMsgId;
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.ClientPlain = void 0;
4
16
  const _0_deps_js_1 = require("../0_deps.js");
@@ -11,25 +23,15 @@ const d = (0, _0_deps_js_1.debug)("ClientPlain/createAuthKey");
11
23
  class ClientPlain extends _1_client_abstract_js_1.ClientAbstract {
12
24
  constructor(params) {
13
25
  super(params);
14
- Object.defineProperty(this, "publicKeys", {
15
- enumerable: true,
16
- configurable: true,
17
- writable: true,
18
- value: void 0
19
- });
20
- Object.defineProperty(this, "lastMsgId", {
21
- enumerable: true,
22
- configurable: true,
23
- writable: true,
24
- value: 0n
25
- });
26
- this.publicKeys = params?.publicKeys ?? _4_constants_js_1.PUBLIC_KEYS;
26
+ _ClientPlain_publicKeys.set(this, void 0);
27
+ _ClientPlain_lastMsgId.set(this, 0n);
28
+ __classPrivateFieldSet(this, _ClientPlain_publicKeys, params?.publicKeys ?? _4_constants_js_1.PUBLIC_KEYS, "f");
27
29
  }
28
30
  async invoke(function_) {
29
31
  if (!this.transport) {
30
32
  throw new Error("Not connected");
31
33
  }
32
- const msgId = this.lastMsgId = (0, _0_message_js_1.getMessageId)(this.lastMsgId);
34
+ const msgId = __classPrivateFieldSet(this, _ClientPlain_lastMsgId, (0, _0_message_js_1.getMessageId)(__classPrivateFieldGet(this, _ClientPlain_lastMsgId, "f")), "f");
33
35
  await this.transport.transport.send((0, _0_message_js_1.packUnencryptedMessage)(function_[_2_tl_js_1.serialize](), msgId));
34
36
  const buffer = await this.transport.transport.receive();
35
37
  if (buffer.length == 4) {
@@ -63,14 +65,16 @@ class ClientPlain extends _1_client_abstract_js_1.ClientAbstract {
63
65
  (0, _1_utilities_js_1.UNREACHABLE)();
64
66
  }
65
67
  const pq_ = (0, _1_utilities_js_1.bigIntFromBuffer)(resPq.pq, false, false);
68
+ d("pq=%d", pq_);
66
69
  const [p_, q_] = (0, _0_deps_js_1.factorize)(pq_);
67
70
  d("factorized pq");
71
+ d("p=%d, q=%d", p_, q_);
68
72
  const p = (0, _1_utilities_js_1.bufferFromBigInt)(p_, 4, false, false);
69
73
  const q = (0, _1_utilities_js_1.bufferFromBigInt)(q_, 4, false, false);
70
74
  let publicKeyFingerprint;
71
75
  let publicKey;
72
76
  for (const fingerprint of resPq.serverPublicKeyFingerprints) {
73
- const maybePublicKey = this.publicKeys.find(([k]) => (k == fingerprint));
77
+ const maybePublicKey = __classPrivateFieldGet(this, _ClientPlain_publicKeys, "f").find(([k]) => (k == fingerprint));
74
78
  if (maybePublicKey) {
75
79
  publicKeyFingerprint = fingerprint;
76
80
  publicKey = maybePublicKey[1];
@@ -141,3 +145,4 @@ class ClientPlain extends _1_client_abstract_js_1.ClientAbstract {
141
145
  }
142
146
  }
143
147
  exports.ClientPlain = ClientPlain;
148
+ _ClientPlain_publicKeys = new WeakMap(), _ClientPlain_lastMsgId = new WeakMap();
@@ -3,7 +3,7 @@ import { functions, types } from "../2_tl.js";
3
3
  import { BotCommandScope, CallbackQuery, ChatID, ForceReply, InlineKeyboardMarkup, InlineQuery, InlineQueryResultButton, Message, MessageEntity, ReplyKeyboardMarkup, ReplyKeyboardRemove } from "../3_types.js";
4
4
  import { With } from "./0_utilities.js";
5
5
  import { ClientPlainParams } from "./2_client_plain.js";
6
- export type ParseMode = "HTML" | null;
6
+ import { ParseMode } from "../3_types.js";
7
7
  export interface ClientParams extends ClientPlainParams {
8
8
  /**
9
9
  * A parse mode to use when the `parseMode` parameter is not specified when sending or editing messages. Defauls to `ParseMode.None`.
@@ -2,11 +2,11 @@ import { MaybePromise } from "../1_utilities.js";
2
2
  import { functions, ReadObject, types } from "../2_tl.js";
3
3
  import { Storage } from "../3_storage.js";
4
4
  import { DC } from "../3_transport.js";
5
- import { BotCommand, ChatAction, ChatID, InlineQueryResult, Message, User } from "../3_types.js";
5
+ import { BotCommand, ChatAction, ChatID, InlineQueryResult, Message, ParseMode, User } from "../3_types.js";
6
6
  import { Migrate } from "../4_errors.js";
7
7
  import { With } from "./0_utilities.js";
8
8
  import { ClientAbstract } from "./1_client_abstract.js";
9
- import { AnswerCallbackQueryParams, AnswerInlineQueryParams, AuthorizeUserParams, ClientParams, DownloadParams, EditMessageParams, FilterableUpdates, FilterUpdate, ForwardMessagesParams, GetMyCommandsParams, Handler, ParseMode, SendMessagesParams, SendPollParams, SetMyCommandsParams, Update, UploadParams } from "./3_types.js";
9
+ import { AnswerCallbackQueryParams, AnswerInlineQueryParams, AuthorizeUserParams, ClientParams, DownloadParams, EditMessageParams, FilterableUpdates, FilterUpdate, ForwardMessagesParams, GetMyCommandsParams, Handler, SendMessagesParams, SendPollParams, SetMyCommandsParams, Update, UploadParams } from "./3_types.js";
10
10
  declare const getEntity: unique symbol;
11
11
  declare const getStickerSetName: unique symbol;
12
12
  export declare const handleMigrationError: unique symbol;
@@ -15,15 +15,9 @@ export declare const restartAuth: unique symbol;
15
15
  export declare class ConnectionError extends Error {
16
16
  }
17
17
  export declare class Client extends ClientAbstract {
18
+ #private;
18
19
  readonly apiId: number | null;
19
20
  readonly apiHash: string | null;
20
- private auth;
21
- private sessionId;
22
- private state;
23
- private promises;
24
- private toAcknowledge;
25
- private updateState?;
26
- private readonly errorHandler?;
27
21
  readonly storage: Storage;
28
22
  readonly parseMode: ParseMode;
29
23
  readonly appVersion: string;
@@ -32,8 +26,6 @@ export declare class Client extends ClientAbstract {
32
26
  readonly langPack: string;
33
27
  readonly systemLangCode: string;
34
28
  readonly systemVersion: string;
35
- private readonly publicKeys?;
36
- private readonly autoStart;
37
29
  /**
38
30
  * Constructs the client.
39
31
  *
@@ -42,10 +34,7 @@ export declare class Client extends ClientAbstract {
42
34
  * @param apiHash App's API hash from [my.telegram.org/apps](https://my.telegram.org/apps). Defaults to empty string (unset).
43
35
  */
44
36
  constructor(storage: Storage | null, apiId?: number | null, apiHash?: string | null, params?: ClientParams);
45
- private propagateConnectionState;
46
- private lastPropagatedConnectionState;
47
37
  protected stateChangeHandler: (connected: boolean) => void;
48
- private storageInited;
49
38
  /**
50
39
  * Sets the DC and resets the auth key stored in the session provider
51
40
  * if the stored DC was not the same as the `dc` parameter.
@@ -53,25 +42,14 @@ export declare class Client extends ClientAbstract {
53
42
  * @param dc The DC to change to.
54
43
  */
55
44
  setDc(dc: DC): Promise<void>;
56
- private setAuth;
57
- private connectMutex;
58
45
  /**
59
46
  * Loads the session if `setDc` was not called, initializes and connnects
60
47
  * a `ClientPlain` to generate auth key if there was none, and connects the client.
61
48
  * Before establishing the connection, the session is saved.
62
49
  */
63
50
  connect(): Promise<void>;
64
- private assertUser;
65
- private assertBot;
66
- private fetchState;
67
51
  [handleMigrationError](err: Migrate): Promise<void>;
68
- private connectionInited;
69
52
  disconnect(): Promise<void>;
70
- private initConnection;
71
- private lastPropagatedAuthorizationState;
72
- private propagateAuthorizationState;
73
- private selfId;
74
- private getSelfId;
75
53
  /**
76
54
  * Calls [initConnection](1) and authorizes the client with one of the following:
77
55
  *
@@ -91,14 +69,9 @@ export declare class Client extends ClientAbstract {
91
69
  */
92
70
  authorize(params?: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
93
71
  /**
94
- * Same as calling `.connect()` followed by `.authorize(params)`.
72
+ * Same as calling `.connect()` followed by `.authorize(params)` if the session didn't have an auth key.
95
73
  */
96
74
  start(params?: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
97
- private receiveLoop;
98
- private pingLoop;
99
- private pingLoopStarted;
100
- private autoStarted;
101
- private lastMsgId;
102
75
  /**
103
76
  * Invokes a function waiting and returning its reply if the second parameter is not `true`. Requires the client
104
77
  * to be connected.
@@ -111,27 +84,13 @@ export declare class Client extends ClientAbstract {
111
84
  * Alias for `invoke` with its second parameter being `true`.
112
85
  */
113
86
  send<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<void>;
114
- private processChats;
115
- private processUsers;
116
- private handleUpdateQueue;
117
- private processUpdatesQueue;
118
- private checkGap;
119
- private checkChannelGap;
120
- private processUpdates;
121
- private setUpdateStateDate;
122
- private getLocalState;
123
- private recoverUpdateGap;
124
- private recoverChannelUpdateGap;
125
- private getUserAccessHash;
126
- private getChannelAccessHash;
87
+ checkGap(pts: number, ptsCount: number, assertNoGap: boolean): Promise<void>;
88
+ getUserAccessHash(userId: bigint): Promise<bigint>;
127
89
  getInputPeer(id: ChatID): Promise<types.InputPeerChat | types.InputPeerUser | types.InputPeerChannel>;
128
- private getInputPeerInner;
129
90
  private [getEntity];
130
91
  private [getEntity];
131
92
  private [getEntity];
132
93
  processResult(result: ReadObject): Promise<void>;
133
- private updatesToMessages;
134
- private resolveSendAs;
135
94
  /**
136
95
  * Send a text message.
137
96
  *
@@ -141,7 +100,6 @@ export declare class Client extends ClientAbstract {
141
100
  * @returns The sent text message.
142
101
  */
143
102
  sendMessage(chatId: ChatID, text: string, params?: SendMessagesParams): Promise<With<Message, "text">>;
144
- private parseText;
145
103
  /**
146
104
  * Edit a message's text.
147
105
  *
@@ -152,7 +110,6 @@ export declare class Client extends ClientAbstract {
152
110
  * @returns The edited text message.
153
111
  */
154
112
  editMessageText(chatId: ChatID, messageId: number, text: string, params?: EditMessageParams): Promise<With<Message, "text">>;
155
- private getMessagesInner;
156
113
  /**
157
114
  * Retrieve multiple messages.
158
115
  *
@@ -178,7 +135,6 @@ export declare class Client extends ClientAbstract {
178
135
  * @returns The retrieved message.
179
136
  */
180
137
  getMessage(chatId: ChatID, messageId: number): Promise<Omit<Message, "replyToMessage"> | null>;
181
- private downloadInner;
182
138
  /**
183
139
  * Download a file.
184
140
  *
@@ -219,7 +175,6 @@ export declare class Client extends ClientAbstract {
219
175
  * @method
220
176
  */
221
177
  getMe(): Promise<User>;
222
- private handleUpdate;
223
178
  /**
224
179
  * Answer a callback query. Bot-only.
225
180
  *
@@ -227,9 +182,6 @@ export declare class Client extends ClientAbstract {
227
182
  * @param id ID of the callback query to answer.
228
183
  */
229
184
  answerCallbackQuery(id: string, params?: AnswerCallbackQueryParams): Promise<void>;
230
- private usernameResolver;
231
- private constructReplyMarkup;
232
- private static assertMsgHas;
233
185
  /**
234
186
  * Send a poll.
235
187
  *
@@ -277,13 +229,11 @@ export declare class Client extends ClientAbstract {
277
229
  * @param results The results to answer with.
278
230
  */
279
231
  answerInlineQuery(id: string, results: InlineQueryResult[], params?: AnswerInlineQueryParams): Promise<void>;
280
- private handle;
281
232
  use(handler: Handler): void;
282
233
  branch(predicate: (upd: Update) => MaybePromise<boolean>, trueHandler: Handler, falseHandler: Handler): void;
283
234
  filter<D extends Update>(predicate: (update: Update) => update is D, handler: Handler<D>): void;
284
235
  filter(predicate: (update: Update) => MaybePromise<boolean>, handler: Handler): void;
285
236
  on<T extends keyof Update, F extends keyof NonNullable<Update[T]>>(filter: T extends FilterableUpdates ? T | [T, F, ...F[]] : T, handler: Handler<FilterUpdate<Update, T, F>>): void;
286
- private setMyInfo;
287
237
  /**
288
238
  * Set the bot's description in the given language. Bot-only.
289
239
  *
@@ -311,7 +261,6 @@ export declare class Client extends ClientAbstract {
311
261
  shortDescription?: string;
312
262
  languageCode?: string;
313
263
  }): Promise<void>;
314
- private getMyInfo;
315
264
  /**
316
265
  * Get the bot's description in the given language. Bot-only.
317
266
  *