@mtkruto/browser 0.119.0 → 0.119.1

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 (127) hide show
  1. package/esm/0_errors.d.ts.map +1 -1
  2. package/esm/0_errors.js +9 -31
  3. package/esm/3_errors.js +2 -12
  4. package/esm/4_errors.js +2 -12
  5. package/esm/_dnt.polyfills.d.ts +0 -99
  6. package/esm/_dnt.polyfills.d.ts.map +1 -1
  7. package/esm/_dnt.polyfills.js +1 -127
  8. package/esm/client/0_abortable_loop.js +26 -39
  9. package/esm/client/0_storage_operations.js +179 -218
  10. package/esm/client/1_client_plain.js +4 -22
  11. package/esm/client/2_account_manager.js +140 -149
  12. package/esm/client/2_bot_info_manager.js +26 -38
  13. package/esm/client/2_business_connection_manager.js +10 -23
  14. package/esm/client/2_client_encrypted.js +198 -215
  15. package/esm/client/2_file_manager.js +255 -262
  16. package/esm/client/2_network_statistics_manager.js +31 -44
  17. package/esm/client/2_payment_manager.js +7 -20
  18. package/esm/client/2_reaction_manager.js +7 -20
  19. package/esm/client/2_translations_manager.js +101 -111
  20. package/esm/client/2_update_manager.js +750 -745
  21. package/esm/client/3_client_encrypted_pool.js +10 -26
  22. package/esm/client/3_message_manager.js +503 -508
  23. package/esm/client/3_video_chat_manager.js +57 -68
  24. package/esm/client/4_callback_query_manager.js +18 -30
  25. package/esm/client/4_chat_list_manager.js +140 -146
  26. package/esm/client/4_chat_manager.js +161 -169
  27. package/esm/client/4_checklist_manager.js +26 -39
  28. package/esm/client/4_context.js +244 -259
  29. package/esm/client/4_forum_manager.js +67 -73
  30. package/esm/client/4_gift_manager.js +22 -35
  31. package/esm/client/4_inline_query_manager.js +16 -28
  32. package/esm/client/4_link_preview_manager.js +6 -19
  33. package/esm/client/4_poll_manager.js +44 -57
  34. package/esm/client/4_story_manager.js +41 -53
  35. package/esm/client/5_composer.js +13 -26
  36. package/esm/client/6_client.js +866 -896
  37. package/esm/client/6_client_dispatcher.js +308 -325
  38. package/esm/client/7_client_worker.js +16 -29
  39. package/esm/connection/1_connection_tcp.js +55 -82
  40. package/esm/connection/1_connection_web_socket.js +75 -91
  41. package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
  42. package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
  43. package/esm/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
  44. package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
  45. package/esm/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
  46. package/esm/session/0_session_state.js +12 -38
  47. package/esm/session/1_session.js +49 -72
  48. package/esm/session/2_session_encrypted.js +422 -420
  49. package/esm/storage/2_storage_indexed_db.js +26 -44
  50. package/esm/storage/2_storage_local_storage.js +3 -16
  51. package/esm/storage/2_storage_memory.js +24 -41
  52. package/esm/storage/2_storage_session_storage.js +3 -16
  53. package/esm/tl/1_tl_reader.d.ts +1 -1
  54. package/esm/tl/1_tl_reader.d.ts.map +1 -1
  55. package/esm/tl/1_tl_reader.js +95 -103
  56. package/esm/tl/1_tl_writer.js +169 -178
  57. package/esm/transport/0_transport.js +1 -8
  58. package/esm/transport/1_transport_abridged.js +11 -24
  59. package/esm/transport/1_transport_intermediate.js +10 -23
  60. package/esm/utilities/0_mutex.js +4 -19
  61. package/esm/utilities/0_part_stream.js +11 -25
  62. package/esm/utilities/1_crypto.js +42 -53
  63. package/esm/utilities/2_queue.js +29 -47
  64. package/package.json +1 -1
  65. package/script/0_errors.d.ts.map +1 -1
  66. package/script/0_errors.js +9 -31
  67. package/script/3_errors.js +2 -12
  68. package/script/4_errors.js +2 -12
  69. package/script/_dnt.polyfills.d.ts +0 -99
  70. package/script/_dnt.polyfills.d.ts.map +1 -1
  71. package/script/_dnt.polyfills.js +0 -128
  72. package/script/client/0_abortable_loop.js +27 -40
  73. package/script/client/0_storage_operations.js +179 -218
  74. package/script/client/1_client_plain.js +4 -22
  75. package/script/client/2_account_manager.js +140 -149
  76. package/script/client/2_bot_info_manager.js +26 -38
  77. package/script/client/2_business_connection_manager.js +10 -23
  78. package/script/client/2_client_encrypted.js +199 -216
  79. package/script/client/2_file_manager.js +255 -262
  80. package/script/client/2_network_statistics_manager.js +32 -45
  81. package/script/client/2_payment_manager.js +7 -20
  82. package/script/client/2_reaction_manager.js +7 -20
  83. package/script/client/2_translations_manager.js +102 -112
  84. package/script/client/2_update_manager.js +750 -745
  85. package/script/client/3_client_encrypted_pool.js +10 -26
  86. package/script/client/3_message_manager.js +503 -508
  87. package/script/client/3_video_chat_manager.js +57 -68
  88. package/script/client/4_callback_query_manager.js +18 -30
  89. package/script/client/4_chat_list_manager.js +140 -146
  90. package/script/client/4_chat_manager.js +161 -169
  91. package/script/client/4_checklist_manager.js +26 -39
  92. package/script/client/4_context.js +244 -259
  93. package/script/client/4_forum_manager.js +67 -73
  94. package/script/client/4_gift_manager.js +22 -35
  95. package/script/client/4_inline_query_manager.js +16 -28
  96. package/script/client/4_link_preview_manager.js +6 -19
  97. package/script/client/4_poll_manager.js +44 -57
  98. package/script/client/4_story_manager.js +41 -53
  99. package/script/client/5_composer.js +13 -26
  100. package/script/client/6_client.js +866 -896
  101. package/script/client/6_client_dispatcher.js +308 -325
  102. package/script/client/7_client_worker.js +16 -29
  103. package/script/connection/1_connection_tcp.js +55 -82
  104. package/script/connection/1_connection_web_socket.js +75 -91
  105. package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
  106. package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
  107. package/script/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
  108. package/script/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
  109. package/script/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
  110. package/script/session/0_session_state.js +12 -38
  111. package/script/session/1_session.js +49 -72
  112. package/script/session/2_session_encrypted.js +423 -421
  113. package/script/storage/2_storage_indexed_db.js +26 -44
  114. package/script/storage/2_storage_local_storage.js +3 -16
  115. package/script/storage/2_storage_memory.js +24 -41
  116. package/script/storage/2_storage_session_storage.js +3 -16
  117. package/script/tl/1_tl_reader.d.ts +1 -1
  118. package/script/tl/1_tl_reader.d.ts.map +1 -1
  119. package/script/tl/1_tl_reader.js +96 -104
  120. package/script/tl/1_tl_writer.js +170 -179
  121. package/script/transport/0_transport.js +1 -8
  122. package/script/transport/1_transport_abridged.js +11 -24
  123. package/script/transport/1_transport_intermediate.js +10 -23
  124. package/script/utilities/0_mutex.js +4 -19
  125. package/script/utilities/0_part_stream.js +11 -25
  126. package/script/utilities/1_crypto.js +43 -54
  127. package/script/utilities/2_queue.js +30 -48
@@ -17,18 +17,6 @@
17
17
  * You should have received a copy of the GNU Lesser General Public License
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
21
- if (kind === "m") throw new TypeError("Private method is not writable");
22
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
23
- 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");
24
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
25
- };
26
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
27
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
28
- 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");
29
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
30
- };
31
- var _BotInfoManager_instances, _BotInfoManager_c, _BotInfoManager_setMyInfo, _BotInfoManager_getMyInfo;
32
20
  import { Api } from "../2_tl.js";
33
21
  import { botCommandScopeToTlObject } from "../3_types.js";
34
22
  import { peerToChatId } from "../tl/2_telegram.js";
@@ -36,54 +24,59 @@ const botInfoManagerUpdates = [
36
24
  "updateBotCommands",
37
25
  ];
38
26
  export class BotInfoManager {
27
+ #c;
39
28
  constructor(c) {
40
- _BotInfoManager_instances.add(this);
41
- _BotInfoManager_c.set(this, void 0);
42
- __classPrivateFieldSet(this, _BotInfoManager_c, c, "f");
29
+ this.#c = c;
43
30
  }
44
31
  canHandleUpdate(update) {
45
32
  return Api.isOneOf(botInfoManagerUpdates, update);
46
33
  }
34
+ async #setMyInfo(info) {
35
+ await this.#c.invoke({ _: "bots.setBotInfo", ...info });
36
+ }
47
37
  async setMyDescription(params) {
48
- __classPrivateFieldGet(this, _BotInfoManager_c, "f").storage.assertBot("setMyDescription");
49
- await __classPrivateFieldGet(this, _BotInfoManager_instances, "m", _BotInfoManager_setMyInfo).call(this, { description: params?.description, lang_code: params?.languageCode ?? "" });
38
+ this.#c.storage.assertBot("setMyDescription");
39
+ await this.#setMyInfo({ description: params?.description, lang_code: params?.languageCode ?? "" });
50
40
  }
51
41
  async setMyName(params) {
52
- __classPrivateFieldGet(this, _BotInfoManager_c, "f").storage.assertBot("setMyName");
53
- await __classPrivateFieldGet(this, _BotInfoManager_instances, "m", _BotInfoManager_setMyInfo).call(this, { name: params?.name, lang_code: params?.languageCode ?? "" });
42
+ this.#c.storage.assertBot("setMyName");
43
+ await this.#setMyInfo({ name: params?.name, lang_code: params?.languageCode ?? "" });
54
44
  }
55
45
  async setMyShortDescription(params) {
56
- __classPrivateFieldGet(this, _BotInfoManager_c, "f").storage.assertBot("setMyShortDescription");
57
- await __classPrivateFieldGet(this, _BotInfoManager_instances, "m", _BotInfoManager_setMyInfo).call(this, { about: params?.shortDescription, lang_code: params?.languageCode ?? "" });
46
+ this.#c.storage.assertBot("setMyShortDescription");
47
+ await this.#setMyInfo({ about: params?.shortDescription, lang_code: params?.languageCode ?? "" });
48
+ }
49
+ #getMyInfo(languageCode) {
50
+ return this.#c.invoke({ _: "bots.getBotInfo", lang_code: languageCode ?? "" });
58
51
  }
59
52
  async getMyDescription(params) {
60
- __classPrivateFieldGet(this, _BotInfoManager_c, "f").storage.assertBot("getMyDescription");
61
- return (await __classPrivateFieldGet(this, _BotInfoManager_instances, "m", _BotInfoManager_getMyInfo).call(this, params?.languageCode)).description;
53
+ this.#c.storage.assertBot("getMyDescription");
54
+ return (await this.#getMyInfo(params?.languageCode)).description;
62
55
  }
63
56
  async getMyName(params) {
64
- __classPrivateFieldGet(this, _BotInfoManager_c, "f").storage.assertBot("getMyName");
65
- return (await __classPrivateFieldGet(this, _BotInfoManager_instances, "m", _BotInfoManager_getMyInfo).call(this, params?.languageCode)).description;
57
+ this.#c.storage.assertBot("getMyName");
58
+ return (await this.#getMyInfo(params?.languageCode)).description;
66
59
  }
67
60
  async getMyShortDescription(params) {
68
- __classPrivateFieldGet(this, _BotInfoManager_c, "f").storage.assertBot("getMyShortDescription");
69
- return (await __classPrivateFieldGet(this, _BotInfoManager_instances, "m", _BotInfoManager_getMyInfo).call(this, params?.languageCode)).about;
61
+ this.#c.storage.assertBot("getMyShortDescription");
62
+ return (await this.#getMyInfo(params?.languageCode)).about;
70
63
  }
71
64
  async getMyCommands(params) {
72
- __classPrivateFieldGet(this, _BotInfoManager_c, "f").storage.assertBot("getMyCommands");
73
- const commands_ = await __classPrivateFieldGet(this, _BotInfoManager_c, "f").invoke({
65
+ this.#c.storage.assertBot("getMyCommands");
66
+ const commands_ = await this.#c.invoke({
74
67
  _: "bots.getBotCommands",
75
68
  lang_code: params?.languageCode ?? "",
76
- scope: await botCommandScopeToTlObject(params?.scope ?? { type: "default" }, __classPrivateFieldGet(this, _BotInfoManager_c, "f").getInputPeer),
69
+ scope: await botCommandScopeToTlObject(params?.scope ?? { type: "default" }, this.#c.getInputPeer),
77
70
  });
78
71
  return commands_.map((v) => ({ command: v.command, description: v.description }));
79
72
  }
80
73
  async setMyCommands(commands, params) {
81
- __classPrivateFieldGet(this, _BotInfoManager_c, "f").storage.assertBot("setMyCommands");
82
- await __classPrivateFieldGet(this, _BotInfoManager_c, "f").invoke({
74
+ this.#c.storage.assertBot("setMyCommands");
75
+ await this.#c.invoke({
83
76
  _: "bots.setBotCommands",
84
77
  commands: commands.map((v) => ({ ...v, _: "botCommand" })),
85
78
  lang_code: params?.languageCode ?? "",
86
- scope: await botCommandScopeToTlObject(params?.scope ?? { type: "default" }, __classPrivateFieldGet(this, _BotInfoManager_c, "f").getInputPeer),
79
+ scope: await botCommandScopeToTlObject(params?.scope ?? { type: "default" }, this.#c.getInputPeer),
87
80
  });
88
81
  }
89
82
  handleUpdate(update) {
@@ -93,8 +86,3 @@ export class BotInfoManager {
93
86
  return { botCommands: { botId, chatId, commands } };
94
87
  }
95
88
  }
96
- _BotInfoManager_c = new WeakMap(), _BotInfoManager_instances = new WeakSet(), _BotInfoManager_setMyInfo = async function _BotInfoManager_setMyInfo(info) {
97
- await __classPrivateFieldGet(this, _BotInfoManager_c, "f").invoke({ _: "bots.setBotInfo", ...info });
98
- }, _BotInfoManager_getMyInfo = function _BotInfoManager_getMyInfo(languageCode) {
99
- return __classPrivateFieldGet(this, _BotInfoManager_c, "f").invoke({ _: "bots.getBotInfo", lang_code: languageCode ?? "" });
100
- };
@@ -17,39 +17,27 @@
17
17
  * You should have received a copy of the GNU Lesser General Public License
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
21
- if (kind === "m") throw new TypeError("Private method is not writable");
22
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
23
- 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");
24
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
25
- };
26
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
27
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
28
- 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");
29
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
30
- };
31
- var _BusinessConnectionManager_c;
32
20
  import { Api } from "../2_tl.js";
33
21
  import { constructBusinessConnection } from "../3_types.js";
34
22
  const businessConnectionManagerUpdates = [
35
23
  "updateBotBusinessConnect",
36
24
  ];
37
25
  export class BusinessConnectionManager {
26
+ #c;
38
27
  constructor(c) {
39
- _BusinessConnectionManager_c.set(this, void 0);
40
- __classPrivateFieldSet(this, _BusinessConnectionManager_c, c, "f");
28
+ this.#c = c;
41
29
  }
42
30
  async getBusinessConnection(id) {
43
- const connection_ = await __classPrivateFieldGet(this, _BusinessConnectionManager_c, "f").messageStorage.getBusinessConnection(id);
31
+ const connection_ = await this.#c.messageStorage.getBusinessConnection(id);
44
32
  if (!connection_) {
45
- const connection_ = await __classPrivateFieldGet(this, _BusinessConnectionManager_c, "f").invoke({ _: "account.getBotBusinessConnection", connection_id: id })
33
+ const connection_ = await this.#c.invoke({ _: "account.getBotBusinessConnection", connection_id: id })
46
34
  .then((v) => Api.as("updates", v))
47
35
  .then((v) => Api.as("updateBotBusinessConnect", v.updates[0]).connection);
48
- await __classPrivateFieldGet(this, _BusinessConnectionManager_c, "f").messageStorage.setBusinessConnection(id, connection_);
49
- return constructBusinessConnection(connection_, __classPrivateFieldGet(this, _BusinessConnectionManager_c, "f").getPeer);
36
+ await this.#c.messageStorage.setBusinessConnection(id, connection_);
37
+ return constructBusinessConnection(connection_, this.#c.getPeer);
50
38
  }
51
39
  else {
52
- return constructBusinessConnection(connection_, __classPrivateFieldGet(this, _BusinessConnectionManager_c, "f").getPeer);
40
+ return constructBusinessConnection(connection_, this.#c.getPeer);
53
41
  }
54
42
  }
55
43
  canHandleUpdate(update) {
@@ -57,13 +45,12 @@ export class BusinessConnectionManager {
57
45
  }
58
46
  async handleUpdate(update) {
59
47
  if (update.connection.disabled) {
60
- await __classPrivateFieldGet(this, _BusinessConnectionManager_c, "f").messageStorage.setBusinessConnection(update.connection.connection_id, null);
48
+ await this.#c.messageStorage.setBusinessConnection(update.connection.connection_id, null);
61
49
  }
62
50
  else {
63
- await __classPrivateFieldGet(this, _BusinessConnectionManager_c, "f").messageStorage.setBusinessConnection(update.connection.connection_id, update.connection);
51
+ await this.#c.messageStorage.setBusinessConnection(update.connection.connection_id, update.connection);
64
52
  }
65
- const businessConnection = constructBusinessConnection(update.connection, __classPrivateFieldGet(this, _BusinessConnectionManager_c, "f").getPeer);
53
+ const businessConnection = constructBusinessConnection(update.connection, this.#c.getPeer);
66
54
  return { businessConnection };
67
55
  }
68
56
  }
69
- _BusinessConnectionManager_c = new WeakMap();
@@ -17,18 +17,7 @@
17
17
  * You should have received a copy of the GNU Lesser General Public License
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
21
- if (kind === "m") throw new TypeError("Private method is not writable");
22
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
23
- 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");
24
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
25
- };
26
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
27
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
28
- 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");
29
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
30
- };
31
- var _ClientEncrypted_instances, _a, _ClientEncrypted_SEND_MAX_TRIES, _ClientEncrypted_AUTH_KEY_CREATION_MAX_TRIES, _ClientEncrypted_L, _ClientEncrypted_plain, _ClientEncrypted_sentRequests, _ClientEncrypted_apiId, _ClientEncrypted_appVersion, _ClientEncrypted_deviceModel, _ClientEncrypted_langCode, _ClientEncrypted_langPack, _ClientEncrypted_systemLangCode, _ClientEncrypted_systemVersion, _ClientEncrypted_disableUpdates, _ClientEncrypted_createAuthKeyPromise, _ClientEncrypted_createAuthKey, _ClientEncrypted_createAuthKeyInner, _ClientEncrypted_connectionInited, _ClientEncrypted_send, _ClientEncrypted_resend, _ClientEncrypted_onUpdate, _ClientEncrypted_onNewServerSalt, _ClientEncrypted_onMessageFailed, _ClientEncrypted_onRpcError, _ClientEncrypted_onRpcResult, _ClientEncrypted_onPong;
20
+ var _a;
32
21
  import { InputError } from "../0_errors.js";
33
22
  import { getLogger } from "../1_utilities.js";
34
23
  import { Api, Mtproto, X } from "../2_tl.js";
@@ -42,61 +31,44 @@ import { ClientPlain } from "./1_client_plain.js";
42
31
  // global ClientEncrypted ID counter for logs
43
32
  let id = 0;
44
33
  export class ClientEncrypted extends ClientAbstract {
34
+ static #SEND_MAX_TRIES = 10;
35
+ static #AUTH_KEY_CREATION_MAX_TRIES = 10;
36
+ handlers = {};
37
+ #L;
38
+ #plain;
39
+ session;
40
+ #sentRequests = new Map();
41
+ #apiId;
42
+ #appVersion;
43
+ #deviceModel;
44
+ #langCode;
45
+ #langPack;
46
+ #systemLangCode;
47
+ #systemVersion;
48
+ #disableUpdates;
45
49
  constructor(dc, apiId, params) {
46
50
  super();
47
- _ClientEncrypted_instances.add(this);
48
- Object.defineProperty(this, "handlers", {
49
- enumerable: true,
50
- configurable: true,
51
- writable: true,
52
- value: {}
53
- });
54
- _ClientEncrypted_L.set(this, void 0);
55
- _ClientEncrypted_plain.set(this, void 0);
56
- Object.defineProperty(this, "session", {
57
- enumerable: true,
58
- configurable: true,
59
- writable: true,
60
- value: void 0
61
- });
62
- _ClientEncrypted_sentRequests.set(this, new Map());
63
- _ClientEncrypted_apiId.set(this, void 0);
64
- _ClientEncrypted_appVersion.set(this, void 0);
65
- _ClientEncrypted_deviceModel.set(this, void 0);
66
- _ClientEncrypted_langCode.set(this, void 0);
67
- _ClientEncrypted_langPack.set(this, void 0);
68
- _ClientEncrypted_systemLangCode.set(this, void 0);
69
- _ClientEncrypted_systemVersion.set(this, void 0);
70
- _ClientEncrypted_disableUpdates.set(this, void 0);
71
- _ClientEncrypted_createAuthKeyPromise.set(this, void 0);
72
- _ClientEncrypted_connectionInited.set(this, false);
73
- Object.defineProperty(this, "lastRequest", {
74
- enumerable: true,
75
- configurable: true,
76
- writable: true,
77
- value: void 0
78
- });
79
- __classPrivateFieldSet(this, _ClientEncrypted_L, getLogger("ClientEncrypted").client(id++), "f");
80
- __classPrivateFieldSet(this, _ClientEncrypted_plain, new ClientPlain(dc, params), "f");
51
+ this.#L = getLogger("ClientEncrypted").client(id++);
52
+ this.#plain = new ClientPlain(dc, params);
81
53
  this.session = new SessionEncrypted(dc, params);
82
- this.session.handlers.onUpdate = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onUpdate).bind(this);
83
- this.session.handlers.onNewServerSalt = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onNewServerSalt).bind(this);
84
- this.session.handlers.onMessageFailed = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onMessageFailed).bind(this);
85
- this.session.handlers.onRpcError = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onRpcError).bind(this);
86
- this.session.handlers.onRpcResult = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onRpcResult).bind(this);
87
- this.session.handlers.onPong = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onPong).bind(this);
88
- __classPrivateFieldSet(this, _ClientEncrypted_apiId, apiId, "f");
89
- __classPrivateFieldSet(this, _ClientEncrypted_appVersion, params?.appVersion ?? APP_VERSION, "f");
90
- __classPrivateFieldSet(this, _ClientEncrypted_deviceModel, params?.deviceModel ?? DEVICE_MODEL, "f");
91
- __classPrivateFieldSet(this, _ClientEncrypted_langCode, params?.langCode ?? LANG_CODE, "f");
92
- __classPrivateFieldSet(this, _ClientEncrypted_langPack, params?.langPack ?? LANG_PACK, "f");
93
- __classPrivateFieldSet(this, _ClientEncrypted_systemLangCode, params?.systemLangCode ?? SYSTEM_LANG_CODE, "f");
94
- __classPrivateFieldSet(this, _ClientEncrypted_systemVersion, params?.systemVersion ?? SYSTEM_VERSION, "f");
95
- __classPrivateFieldSet(this, _ClientEncrypted_disableUpdates, params?.disableUpdates ?? false, "f");
54
+ this.session.handlers.onUpdate = this.#onUpdate.bind(this);
55
+ this.session.handlers.onNewServerSalt = this.#onNewServerSalt.bind(this);
56
+ this.session.handlers.onMessageFailed = this.#onMessageFailed.bind(this);
57
+ this.session.handlers.onRpcError = this.#onRpcError.bind(this);
58
+ this.session.handlers.onRpcResult = this.#onRpcResult.bind(this);
59
+ this.session.handlers.onPong = this.#onPong.bind(this);
60
+ this.#apiId = apiId;
61
+ this.#appVersion = params?.appVersion ?? APP_VERSION;
62
+ this.#deviceModel = params?.deviceModel ?? DEVICE_MODEL;
63
+ this.#langCode = params?.langCode ?? LANG_CODE;
64
+ this.#langPack = params?.langPack ?? LANG_PACK;
65
+ this.#systemLangCode = params?.systemLangCode ?? SYSTEM_LANG_CODE;
66
+ this.#systemVersion = params?.systemVersion ?? SYSTEM_VERSION;
67
+ this.#disableUpdates = params?.disableUpdates ?? false;
96
68
  }
97
69
  async connect() {
98
70
  if (!this.authKey.length) {
99
- await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_createAuthKey).call(this);
71
+ await this.#createAuthKey();
100
72
  }
101
73
  await super.connect();
102
74
  }
@@ -104,187 +76,198 @@ export class ClientEncrypted extends ClientAbstract {
104
76
  super.disconnect();
105
77
  this.lastRequest = undefined;
106
78
  }
107
- get authKey() {
108
- return this.session.authKey;
109
- }
110
- async setAuthKey(authKey) {
111
- await this.session.setAuthKey(authKey);
112
- }
113
- async invoke(function_) {
114
- const messageId = await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_send).call(this, function_);
115
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").debug("sent", function_._, "with msg_id", messageId);
116
- const sentRequest = { call: function_, promiseWithResolvers: Promise.withResolvers() };
117
- __classPrivateFieldGet(this, _ClientEncrypted_sentRequests, "f").set(messageId, sentRequest);
118
- return await sentRequest.promiseWithResolvers.promise;
79
+ #createAuthKeyPromise;
80
+ #createAuthKey() {
81
+ return this.#createAuthKeyPromise ??= this.#createAuthKeyInner().finally(() => {
82
+ this.#createAuthKeyPromise = undefined;
83
+ });
119
84
  }
120
- }
121
- _a = ClientEncrypted, _ClientEncrypted_L = new WeakMap(), _ClientEncrypted_plain = new WeakMap(), _ClientEncrypted_sentRequests = new WeakMap(), _ClientEncrypted_apiId = new WeakMap(), _ClientEncrypted_appVersion = new WeakMap(), _ClientEncrypted_deviceModel = new WeakMap(), _ClientEncrypted_langCode = new WeakMap(), _ClientEncrypted_langPack = new WeakMap(), _ClientEncrypted_systemLangCode = new WeakMap(), _ClientEncrypted_systemVersion = new WeakMap(), _ClientEncrypted_disableUpdates = new WeakMap(), _ClientEncrypted_createAuthKeyPromise = new WeakMap(), _ClientEncrypted_connectionInited = new WeakMap(), _ClientEncrypted_instances = new WeakSet(), _ClientEncrypted_createAuthKey = function _ClientEncrypted_createAuthKey() {
122
- return __classPrivateFieldSet(this, _ClientEncrypted_createAuthKeyPromise, __classPrivateFieldGet(this, _ClientEncrypted_createAuthKeyPromise, "f") ?? __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_createAuthKeyInner).call(this).finally(() => {
123
- __classPrivateFieldSet(this, _ClientEncrypted_createAuthKeyPromise, undefined, "f");
124
- }), "f");
125
- }, _ClientEncrypted_createAuthKeyInner = async function _ClientEncrypted_createAuthKeyInner() {
126
- let lastErr;
127
- let errored = false;
128
- for (let i = 0; i < __classPrivateFieldGet(_a, _a, "f", _ClientEncrypted_AUTH_KEY_CREATION_MAX_TRIES); ++i) {
129
- try {
130
- await __classPrivateFieldGet(this, _ClientEncrypted_plain, "f").connect();
131
- const [authKey, serverSalt] = await __classPrivateFieldGet(this, _ClientEncrypted_plain, "f").createAuthKey();
132
- await this.setAuthKey(authKey);
133
- this.serverSalt = serverSalt;
134
- errored = false;
135
- break;
136
- }
137
- catch (err) {
138
- errored = true;
139
- lastErr = err;
140
- if (this.isDisconnected) {
85
+ async #createAuthKeyInner() {
86
+ let lastErr;
87
+ let errored = false;
88
+ for (let i = 0; i < _a.#AUTH_KEY_CREATION_MAX_TRIES; ++i) {
89
+ try {
90
+ await this.#plain.connect();
91
+ const [authKey, serverSalt] = await this.#plain.createAuthKey();
92
+ await this.setAuthKey(authKey);
93
+ this.serverSalt = serverSalt;
94
+ errored = false;
141
95
  break;
142
96
  }
143
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("failed to create auth key:", err);
97
+ catch (err) {
98
+ errored = true;
99
+ lastErr = err;
100
+ if (this.isDisconnected) {
101
+ break;
102
+ }
103
+ this.#L.error("failed to create auth key:", err);
104
+ }
105
+ finally {
106
+ this.#plain.disconnect();
107
+ }
144
108
  }
145
- finally {
146
- __classPrivateFieldGet(this, _ClientEncrypted_plain, "f").disconnect();
109
+ if (errored) {
110
+ throw lastErr;
147
111
  }
148
112
  }
149
- if (errored) {
150
- throw lastErr;
113
+ get authKey() {
114
+ return this.session.authKey;
151
115
  }
152
- }, _ClientEncrypted_send = async function _ClientEncrypted_send(function_) {
153
- this.lastRequest = new Date();
154
- let body;
155
- if (Mtproto.is("ping", function_)) {
156
- body = Mtproto.serializeObject(function_);
116
+ async setAuthKey(authKey) {
117
+ await this.session.setAuthKey(authKey);
157
118
  }
158
- else {
159
- if (__classPrivateFieldGet(this, _ClientEncrypted_disableUpdates, "f") && !isCdnFunction(function_)) {
160
- function_ = { _: "invokeWithoutUpdates", query: function_ };
119
+ #connectionInited = false;
120
+ lastRequest;
121
+ async #send(function_) {
122
+ this.lastRequest = new Date();
123
+ let body;
124
+ if (Mtproto.is("ping", function_)) {
125
+ body = Mtproto.serializeObject(function_);
161
126
  }
162
- if (!__classPrivateFieldGet(this, _ClientEncrypted_connectionInited, "f")) {
163
- if (!__classPrivateFieldGet(this, _ClientEncrypted_apiId, "f")) {
164
- throw new InputError("apiId not set");
127
+ else {
128
+ if (this.#disableUpdates && !isCdnFunction(function_)) {
129
+ function_ = { _: "invokeWithoutUpdates", query: function_ };
165
130
  }
166
- function_ = {
167
- _: "initConnection",
168
- api_id: __classPrivateFieldGet(this, _ClientEncrypted_apiId, "f"),
169
- app_version: __classPrivateFieldGet(this, _ClientEncrypted_appVersion, "f"),
170
- device_model: __classPrivateFieldGet(this, _ClientEncrypted_deviceModel, "f"),
171
- lang_code: __classPrivateFieldGet(this, _ClientEncrypted_langCode, "f"),
172
- lang_pack: __classPrivateFieldGet(this, _ClientEncrypted_langPack, "f"),
173
- query: {
174
- _: "invokeWithLayer",
175
- layer: Api.LAYER,
176
- query: function_,
177
- },
178
- system_lang_code: __classPrivateFieldGet(this, _ClientEncrypted_systemLangCode, "f"),
179
- system_version: __classPrivateFieldGet(this, _ClientEncrypted_systemVersion, "f"),
180
- };
181
- }
182
- body = Api.serializeObject(function_);
183
- }
184
- let lastErr;
185
- for (let i = 0; i < __classPrivateFieldGet(_a, _a, "f", _ClientEncrypted_SEND_MAX_TRIES); ++i) {
186
- let errored = false;
187
- try {
188
- return await this.session.send(body);
189
- }
190
- catch (err) {
191
- errored = true;
192
- lastErr = err;
193
- if (this.isDisconnected) {
194
- break;
131
+ if (!this.#connectionInited) {
132
+ if (!this.#apiId) {
133
+ throw new InputError("apiId not set");
134
+ }
135
+ function_ = {
136
+ _: "initConnection",
137
+ api_id: this.#apiId,
138
+ app_version: this.#appVersion,
139
+ device_model: this.#deviceModel,
140
+ lang_code: this.#langCode,
141
+ lang_pack: this.#langPack,
142
+ query: {
143
+ _: "invokeWithLayer",
144
+ layer: Api.LAYER,
145
+ query: function_,
146
+ },
147
+ system_lang_code: this.#systemLangCode,
148
+ system_version: this.#systemVersion,
149
+ };
195
150
  }
196
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("send failed:", err);
151
+ body = Api.serializeObject(function_);
197
152
  }
198
- finally {
199
- if (!errored) {
200
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").debug("invoked", repr(function_));
201
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").out(function_);
153
+ let lastErr;
154
+ for (let i = 0; i < _a.#SEND_MAX_TRIES; ++i) {
155
+ let errored = false;
156
+ try {
157
+ return await this.session.send(body);
158
+ }
159
+ catch (err) {
160
+ errored = true;
161
+ lastErr = err;
162
+ if (this.isDisconnected) {
163
+ break;
164
+ }
165
+ this.#L.error("send failed:", err);
166
+ }
167
+ finally {
168
+ if (!errored) {
169
+ this.#L.debug("invoked", repr(function_));
170
+ this.#L.out(function_);
171
+ }
202
172
  }
203
173
  }
174
+ throw new Error(`Failed to invoke function after ${_a.#SEND_MAX_TRIES} tries.`, { cause: lastErr });
204
175
  }
205
- throw new Error(`Failed to invoke function after ${__classPrivateFieldGet(_a, _a, "f", _ClientEncrypted_SEND_MAX_TRIES)} tries.`, { cause: lastErr });
206
- }, _ClientEncrypted_resend = async function _ClientEncrypted_resend(request) {
207
- try {
208
- const messageId = await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_send).call(this, request.call);
209
- __classPrivateFieldGet(this, _ClientEncrypted_sentRequests, "f").set(messageId, request);
210
- }
211
- catch (err) {
212
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("rejecting message because of resend error:", err);
213
- request.promiseWithResolvers.reject(err);
214
- }
215
- }, _ClientEncrypted_onUpdate = async function _ClientEncrypted_onUpdate(body) {
216
- let type;
217
- try {
218
- type = await Api.deserializeType(X, body);
219
- }
220
- catch (err) {
221
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("failed to deserialize update:", err);
222
- this.handlers.onDeserializationError?.();
223
- return;
224
- }
225
- if (Api.isOfEnum("Update", type) || Api.isOfEnum("Updates", type)) {
226
- this.handlers.onUpdate?.(type);
227
- }
228
- else {
229
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").warning("received unknown type:", repr(type));
230
- }
231
- }, _ClientEncrypted_onNewServerSalt = function _ClientEncrypted_onNewServerSalt(serverSalt) {
232
- this.handlers.onNewServerSalt?.(serverSalt);
233
- }, _ClientEncrypted_onMessageFailed = async function _ClientEncrypted_onMessageFailed(msgId, error) {
234
- const request = __classPrivateFieldGet(this, _ClientEncrypted_sentRequests, "f").get(msgId);
235
- if (request) {
236
- __classPrivateFieldGet(this, _ClientEncrypted_sentRequests, "f").delete(msgId);
237
- if (error instanceof SessionError) {
238
- await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_resend).call(this, request);
176
+ async #resend(request) {
177
+ try {
178
+ const messageId = await this.#send(request.call);
179
+ this.#sentRequests.set(messageId, request);
239
180
  }
240
- else {
241
- request.promiseWithResolvers.reject(error);
181
+ catch (err) {
182
+ this.#L.error("rejecting message because of resend error:", err);
183
+ request.promiseWithResolvers.reject(err);
242
184
  }
243
185
  }
244
- }, _ClientEncrypted_onRpcError = async function _ClientEncrypted_onRpcError(msgId, error) {
245
- const request = __classPrivateFieldGet(this, _ClientEncrypted_sentRequests, "f").get(msgId);
246
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").debug("received rpc_error with req_msg_id =", msgId, "for", request === undefined ? "unknown" : "known", "request");
247
- if (request) {
248
- __classPrivateFieldGet(this, _ClientEncrypted_sentRequests, "f").delete(msgId);
249
- const reason = constructTelegramError(error, request.call);
250
- if (reason instanceof ConnectionNotInited) {
251
- __classPrivateFieldSet(this, _ClientEncrypted_connectionInited, false, "f");
252
- await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_resend).call(this, request);
253
- }
254
- else {
255
- request.promiseWithResolvers.reject(constructTelegramError(error, request.call));
256
- }
186
+ async invoke(function_) {
187
+ const messageId = await this.#send(function_);
188
+ this.#L.debug("sent", function_._, "with msg_id", messageId);
189
+ const sentRequest = { call: function_, promiseWithResolvers: Promise.withResolvers() };
190
+ this.#sentRequests.set(messageId, sentRequest);
191
+ return await sentRequest.promiseWithResolvers.promise;
257
192
  }
258
- }, _ClientEncrypted_onRpcResult = async function _ClientEncrypted_onRpcResult(msgId, body) {
259
- const sentRequest = __classPrivateFieldGet(this, _ClientEncrypted_sentRequests, "f").get(msgId);
260
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").debug("received rpc_result with req_msg_id =", msgId, "for", sentRequest === undefined ? "unknown" : "known", "request");
261
- if (sentRequest) {
193
+ async #onUpdate(body) {
262
194
  let type;
263
195
  try {
264
- type = await Api.deserializeType(Api.mustGetReturnType(sentRequest.call._), body);
265
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").in(type);
266
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").debug("received rpc_result", repr(type));
267
- sentRequest.promiseWithResolvers.resolve(type);
196
+ type = await Api.deserializeType(X, body);
268
197
  }
269
198
  catch (err) {
270
- sentRequest.promiseWithResolvers.reject(err);
271
- __classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("failed to deserialize rpc_result body:", err);
199
+ this.#L.error("failed to deserialize update:", err);
272
200
  this.handlers.onDeserializationError?.();
273
201
  return;
274
202
  }
275
- finally {
276
- __classPrivateFieldGet(this, _ClientEncrypted_sentRequests, "f").delete(msgId);
203
+ if (Api.isOfEnum("Update", type) || Api.isOfEnum("Updates", type)) {
204
+ this.handlers.onUpdate?.(type);
205
+ }
206
+ else {
207
+ this.#L.warning("received unknown type:", repr(type));
277
208
  }
278
209
  }
279
- if (!__classPrivateFieldGet(this, _ClientEncrypted_connectionInited, "f")) {
280
- __classPrivateFieldSet(this, _ClientEncrypted_connectionInited, true, "f");
210
+ #onNewServerSalt(serverSalt) {
211
+ this.handlers.onNewServerSalt?.(serverSalt);
281
212
  }
282
- }, _ClientEncrypted_onPong = function _ClientEncrypted_onPong(pong) {
283
- const sentRequest = __classPrivateFieldGet(this, _ClientEncrypted_sentRequests, "f").get(pong.msg_id);
284
- if (sentRequest) {
285
- sentRequest.promiseWithResolvers.resolve(pong);
286
- __classPrivateFieldGet(this, _ClientEncrypted_sentRequests, "f").delete(pong.msg_id);
213
+ async #onMessageFailed(msgId, error) {
214
+ const request = this.#sentRequests.get(msgId);
215
+ if (request) {
216
+ this.#sentRequests.delete(msgId);
217
+ if (error instanceof SessionError) {
218
+ await this.#resend(request);
219
+ }
220
+ else {
221
+ request.promiseWithResolvers.reject(error);
222
+ }
223
+ }
224
+ }
225
+ async #onRpcError(msgId, error) {
226
+ const request = this.#sentRequests.get(msgId);
227
+ this.#L.debug("received rpc_error with req_msg_id =", msgId, "for", request === undefined ? "unknown" : "known", "request");
228
+ if (request) {
229
+ this.#sentRequests.delete(msgId);
230
+ const reason = constructTelegramError(error, request.call);
231
+ if (reason instanceof ConnectionNotInited) {
232
+ this.#connectionInited = false;
233
+ await this.#resend(request);
234
+ }
235
+ else {
236
+ request.promiseWithResolvers.reject(constructTelegramError(error, request.call));
237
+ }
238
+ }
239
+ }
240
+ async #onRpcResult(msgId, body) {
241
+ const sentRequest = this.#sentRequests.get(msgId);
242
+ this.#L.debug("received rpc_result with req_msg_id =", msgId, "for", sentRequest === undefined ? "unknown" : "known", "request");
243
+ if (sentRequest) {
244
+ let type;
245
+ try {
246
+ type = await Api.deserializeType(Api.mustGetReturnType(sentRequest.call._), body);
247
+ this.#L.in(type);
248
+ this.#L.debug("received rpc_result", repr(type));
249
+ sentRequest.promiseWithResolvers.resolve(type);
250
+ }
251
+ catch (err) {
252
+ sentRequest.promiseWithResolvers.reject(err);
253
+ this.#L.error("failed to deserialize rpc_result body:", err);
254
+ this.handlers.onDeserializationError?.();
255
+ return;
256
+ }
257
+ finally {
258
+ this.#sentRequests.delete(msgId);
259
+ }
260
+ }
261
+ if (!this.#connectionInited) {
262
+ this.#connectionInited = true;
263
+ }
264
+ }
265
+ #onPong(pong) {
266
+ const sentRequest = this.#sentRequests.get(pong.msg_id);
267
+ if (sentRequest) {
268
+ sentRequest.promiseWithResolvers.resolve(pong);
269
+ this.#sentRequests.delete(pong.msg_id);
270
+ }
287
271
  }
288
- };
289
- _ClientEncrypted_SEND_MAX_TRIES = { value: 10 };
290
- _ClientEncrypted_AUTH_KEY_CREATION_MAX_TRIES = { value: 10 };
272
+ }
273
+ _a = ClientEncrypted;