@mtkruto/node 0.1.600 → 0.1.701
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/esm/4_errors.js +2 -4
- package/esm/5_client.d.ts +1 -1
- package/esm/5_client.js +1 -1
- package/esm/client/0_params.d.ts +5 -1
- package/esm/client/0_storage_operations.d.ts +182 -0
- package/esm/client/0_storage_operations.js +611 -0
- package/esm/client/1_composer.d.ts +2 -0
- package/esm/client/1_composer.js +28 -0
- package/{script/client/0_types.d.ts → esm/client/1_types.d.ts} +3 -3
- package/{script/client/1_account_manager.d.ts → esm/client/2_account_manager.d.ts} +1 -1
- package/{script/client/1_bot_info_manager.d.ts → esm/client/2_bot_info_manager.d.ts} +1 -1
- package/esm/client/{1_business_connection_manager.d.ts → 2_business_connection_manager.d.ts} +1 -1
- package/{script/client/1_file_manager.d.ts → esm/client/2_file_manager.d.ts} +1 -1
- package/esm/client/{1_file_manager.js → 2_file_manager.js} +5 -3
- package/esm/client/{1_network_statistics_manager.d.ts → 2_network_statistics_manager.d.ts} +1 -1
- package/{script/client/1_reaction_manager.d.ts → esm/client/2_reaction_manager.d.ts} +1 -1
- package/{script/client/1_update_manager.d.ts → esm/client/2_update_manager.d.ts} +1 -1
- package/{script/client/2_message_manager.d.ts → esm/client/3_message_manager.d.ts} +2 -2
- package/esm/client/{2_video_chat_manager.d.ts → 3_video_chat_manager.d.ts} +2 -2
- package/{script/client/3_callback_query_manager.d.ts → esm/client/4_callback_query_manager.d.ts} +2 -2
- package/{script/client/3_chat_list_manager.d.ts → esm/client/4_chat_list_manager.d.ts} +3 -3
- package/{script/client/3_inline_query_manager.d.ts → esm/client/4_inline_query_manager.d.ts} +2 -2
- package/esm/client/{3_story_manager.d.ts → 4_story_manager.d.ts} +3 -3
- package/{script/client/4_client.d.ts → esm/client/5_client.d.ts} +39 -29
- package/esm/client/{4_client.js → 5_client.js} +83 -73
- package/esm/connection/0_connection.d.ts +6 -15
- package/esm/connection/0_connection.js +1 -38
- package/esm/connection/1_connection_web_socket.d.ts +3 -2
- package/esm/connection/1_connection_web_socket.js +7 -3
- package/esm/mod.d.ts +1 -1
- package/esm/mod.js +1 -1
- package/esm/storage/0_storage.d.ts +9 -159
- package/esm/storage/0_storage.js +1 -563
- package/esm/storage/2_storage_indexed_db.d.ts +3 -2
- package/esm/storage/2_storage_indexed_db.js +9 -8
- package/esm/storage/2_storage_local_storage.d.ts +3 -2
- package/esm/storage/2_storage_local_storage.js +5 -4
- package/esm/storage/2_storage_memory.d.ts +4 -4
- package/esm/storage/2_storage_memory.js +12 -19
- package/esm/storage/2_storage_session_storage.d.ts +2 -1
- package/esm/storage/2_storage_session_storage.js +5 -4
- package/esm/types/0_id.d.ts +1 -1
- package/package.json +1 -1
- package/script/4_errors.js +2 -4
- package/script/5_client.d.ts +1 -1
- package/script/5_client.js +1 -1
- package/script/client/0_params.d.ts +5 -1
- package/script/client/0_storage_operations.d.ts +182 -0
- package/script/client/0_storage_operations.js +615 -0
- package/script/client/1_composer.d.ts +2 -0
- package/script/client/1_composer.js +28 -0
- package/{esm/client/0_types.d.ts → script/client/1_types.d.ts} +3 -3
- package/{esm/client/1_account_manager.d.ts → script/client/2_account_manager.d.ts} +1 -1
- package/{esm/client/1_bot_info_manager.d.ts → script/client/2_bot_info_manager.d.ts} +1 -1
- package/script/client/{1_business_connection_manager.d.ts → 2_business_connection_manager.d.ts} +1 -1
- package/{esm/client/1_file_manager.d.ts → script/client/2_file_manager.d.ts} +1 -1
- package/script/client/{1_file_manager.js → 2_file_manager.js} +4 -2
- package/script/client/{1_network_statistics_manager.d.ts → 2_network_statistics_manager.d.ts} +1 -1
- package/{esm/client/1_reaction_manager.d.ts → script/client/2_reaction_manager.d.ts} +1 -1
- package/{esm/client/1_update_manager.d.ts → script/client/2_update_manager.d.ts} +1 -1
- package/{esm/client/2_message_manager.d.ts → script/client/3_message_manager.d.ts} +2 -2
- package/script/client/{2_video_chat_manager.d.ts → 3_video_chat_manager.d.ts} +2 -2
- package/{esm/client/3_callback_query_manager.d.ts → script/client/4_callback_query_manager.d.ts} +2 -2
- package/{esm/client/3_chat_list_manager.d.ts → script/client/4_chat_list_manager.d.ts} +3 -3
- package/{esm/client/3_inline_query_manager.d.ts → script/client/4_inline_query_manager.d.ts} +2 -2
- package/script/client/{3_story_manager.d.ts → 4_story_manager.d.ts} +3 -3
- package/{esm/client/4_client.d.ts → script/client/5_client.d.ts} +39 -29
- package/script/client/{4_client.js → 5_client.js} +105 -95
- package/script/connection/0_connection.d.ts +6 -15
- package/script/connection/0_connection.js +0 -41
- package/script/connection/1_connection_web_socket.d.ts +3 -2
- package/script/connection/1_connection_web_socket.js +7 -3
- package/script/mod.d.ts +1 -1
- package/script/mod.js +1 -1
- package/script/storage/0_storage.d.ts +9 -159
- package/script/storage/0_storage.js +0 -565
- package/script/storage/2_storage_indexed_db.d.ts +3 -2
- package/script/storage/2_storage_indexed_db.js +9 -8
- package/script/storage/2_storage_local_storage.d.ts +3 -2
- package/script/storage/2_storage_local_storage.js +5 -4
- package/script/storage/2_storage_memory.d.ts +4 -4
- package/script/storage/2_storage_memory.js +12 -19
- package/script/storage/2_storage_session_storage.d.ts +2 -1
- package/script/storage/2_storage_session_storage.js +5 -4
- package/script/types/0_id.d.ts +1 -1
- /package/esm/{3_storage.d.ts → 2_storage.d.ts} +0 -0
- /package/esm/{3_storage.js → 2_storage.js} +0 -0
- /package/esm/client/{0_types.js → 1_types.js} +0 -0
- /package/esm/client/{1_account_manager.js → 2_account_manager.js} +0 -0
- /package/esm/client/{1_bot_info_manager.js → 2_bot_info_manager.js} +0 -0
- /package/esm/client/{1_business_connection_manager.js → 2_business_connection_manager.js} +0 -0
- /package/esm/client/{1_network_statistics_manager.js → 2_network_statistics_manager.js} +0 -0
- /package/esm/client/{1_reaction_manager.js → 2_reaction_manager.js} +0 -0
- /package/esm/client/{1_update_manager.js → 2_update_manager.js} +0 -0
- /package/esm/client/{2_message_manager.js → 3_message_manager.js} +0 -0
- /package/esm/client/{2_video_chat_manager.js → 3_video_chat_manager.js} +0 -0
- /package/esm/client/{3_callback_query_manager.js → 4_callback_query_manager.js} +0 -0
- /package/esm/client/{3_chat_list_manager.js → 4_chat_list_manager.js} +0 -0
- /package/esm/client/{3_inline_query_manager.js → 4_inline_query_manager.js} +0 -0
- /package/esm/client/{3_story_manager.js → 4_story_manager.js} +0 -0
- /package/script/{3_storage.d.ts → 2_storage.d.ts} +0 -0
- /package/script/{3_storage.js → 2_storage.js} +0 -0
- /package/script/client/{0_types.js → 1_types.js} +0 -0
- /package/script/client/{1_account_manager.js → 2_account_manager.js} +0 -0
- /package/script/client/{1_bot_info_manager.js → 2_bot_info_manager.js} +0 -0
- /package/script/client/{1_business_connection_manager.js → 2_business_connection_manager.js} +0 -0
- /package/script/client/{1_network_statistics_manager.js → 2_network_statistics_manager.js} +0 -0
- /package/script/client/{1_reaction_manager.js → 2_reaction_manager.js} +0 -0
- /package/script/client/{1_update_manager.js → 2_update_manager.js} +0 -0
- /package/script/client/{2_message_manager.js → 3_message_manager.js} +0 -0
- /package/script/client/{2_video_chat_manager.js → 3_video_chat_manager.js} +0 -0
- /package/script/client/{3_callback_query_manager.js → 4_callback_query_manager.js} +0 -0
- /package/script/client/{3_chat_list_manager.js → 4_chat_list_manager.js} +0 -0
- /package/script/client/{3_inline_query_manager.js → 4_inline_query_manager.js} +0 -0
- /package/script/client/{3_story_manager.js → 4_story_manager.js} +0 -0
|
@@ -28,33 +28,35 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
28
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
29
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
30
30
|
};
|
|
31
|
-
var _Client_instances, _a, _Client_client, _Client_guaranteeUpdateDelivery, _Client_updateManager, _Client_networkStatisticsManager, _Client_botInfoManager, _Client_fileManager, _Client_reactionManager, _Client_videoChatManager, _Client_businessConnectionManager, _Client_messageManager, _Client_storyManager, _Client_callbackQueryManager, _Client_inlineQueryManager, _Client_chatListManager, _Client_accountManager, _Client_parseMode, _Client_publicKeys, _Client_ignoreOutgoing,
|
|
31
|
+
var _Client_instances, _a, _Client_client, _Client_guaranteeUpdateDelivery, _Client_updateManager, _Client_networkStatisticsManager, _Client_botInfoManager, _Client_fileManager, _Client_reactionManager, _Client_videoChatManager, _Client_businessConnectionManager, _Client_messageManager, _Client_storyManager, _Client_callbackQueryManager, _Client_inlineQueryManager, _Client_chatListManager, _Client_accountManager, _Client_storage_, _Client_messageStorage_, _Client_parseMode, _Client_apiId, _Client_apiHash, _Client_publicKeys, _Client_ignoreOutgoing, _Client_persistCache, _Client_LsignIn, _Client_LpingLoop, _Client_LhandleMigrationError, _Client_L$initConncetion, _Client_namespaceProxies, _Client_getApiId, _Client_getCdnConnectionPool, _Client_getCdnConnection, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_stateChangeHandler, _Client_storageInited, _Client_initStorage, _Client_connectionInited, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_getSelfId, _Client_pingLoopStarted, _Client_pingLoopAbortController, _Client_pingInterval, _Client_lastUpdates, _Client_startPingLoop, _Client_pingLoop, _Client_invoke, _Client_handleInvokeError, _Client_getUserAccessHash, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_handleCtxUpdate, _Client_queueHandleCtxUpdate, _Client_handleUpdate, _Client_lastGetMe, _Client_getMe;
|
|
32
32
|
import { unreachable } from "../0_deps.js";
|
|
33
33
|
import { AccessError, InputError } from "../0_errors.js";
|
|
34
34
|
import { cleanObject, drop, getLogger, getRandomId, minute, mustPrompt, mustPromptOneOf, second, ZERO_CHANNEL_ID } from "../1_utilities.js";
|
|
35
35
|
import { as, chatIdToPeerId, functions, getChatIdPeerType, name, peerToChatId, types } from "../2_tl.js";
|
|
36
|
-
import { StorageMemory } from "../
|
|
36
|
+
import { StorageMemory } from "../2_storage.js";
|
|
37
37
|
import { constructUser } from "../3_types.js";
|
|
38
38
|
import { APP_VERSION, DEVICE_MODEL, LANG_CODE, LANG_PACK, LAYER, MAX_CHANNEL_ID, MAX_CHAT_ID, SYSTEM_LANG_CODE, SYSTEM_VERSION, USERNAME_TTL } from "../4_constants.js";
|
|
39
39
|
import { AuthKeyUnregistered, ConnectionNotInited, FloodWait, Migrate, PasswordHashInvalid, PhoneNumberInvalid, SessionPasswordNeeded } from "../4_errors.js";
|
|
40
40
|
import { checkPassword } from "./0_password.js";
|
|
41
41
|
import { getUsername, isMtprotoFunction, resolve } from "./0_utilities.js";
|
|
42
|
-
import { AccountManager } from "./
|
|
43
|
-
import { BotInfoManager } from "./
|
|
44
|
-
import { BusinessConnectionManager } from "./
|
|
42
|
+
import { AccountManager } from "./2_account_manager.js";
|
|
43
|
+
import { BotInfoManager } from "./2_bot_info_manager.js";
|
|
44
|
+
import { BusinessConnectionManager } from "./2_business_connection_manager.js";
|
|
45
45
|
import { ClientEncrypted } from "./1_client_encrypted.js";
|
|
46
46
|
import { ClientPlain } from "./1_client_plain.js";
|
|
47
47
|
import { Composer as Composer_ } from "./1_composer.js";
|
|
48
|
-
import { FileManager } from "./
|
|
49
|
-
import { NetworkStatisticsManager } from "./
|
|
50
|
-
import { ReactionManager } from "./
|
|
51
|
-
import { UpdateManager } from "./
|
|
52
|
-
import { MessageManager } from "./
|
|
53
|
-
import { CallbackQueryManager } from "./
|
|
54
|
-
import { ChatListManager } from "./
|
|
55
|
-
import { InlineQueryManager } from "./
|
|
56
|
-
import { StoryManager } from "./
|
|
57
|
-
import { VideoChatManager } from "./
|
|
48
|
+
import { FileManager } from "./2_file_manager.js";
|
|
49
|
+
import { NetworkStatisticsManager } from "./2_network_statistics_manager.js";
|
|
50
|
+
import { ReactionManager } from "./2_reaction_manager.js";
|
|
51
|
+
import { UpdateManager } from "./2_update_manager.js";
|
|
52
|
+
import { MessageManager } from "./3_message_manager.js";
|
|
53
|
+
import { CallbackQueryManager } from "./4_callback_query_manager.js";
|
|
54
|
+
import { ChatListManager } from "./4_chat_list_manager.js";
|
|
55
|
+
import { InlineQueryManager } from "./4_inline_query_manager.js";
|
|
56
|
+
import { StoryManager } from "./4_story_manager.js";
|
|
57
|
+
import { VideoChatManager } from "./3_video_chat_manager.js";
|
|
58
|
+
import { StorageOperations } from "./0_storage_operations.js";
|
|
59
|
+
import { PhoneCodeInvalid } from "../4_errors.js";
|
|
58
60
|
export class Composer extends Composer_ {
|
|
59
61
|
}
|
|
60
62
|
function skipInvoke() {
|
|
@@ -77,21 +79,9 @@ export class Client extends Composer {
|
|
|
77
79
|
* @param apiId App's API ID from [my.telegram.org](https://my.telegram.org/apps). Defaults to 0 (unset).
|
|
78
80
|
* @param apiHash App's API hash from [my.telegram.org/apps](https://my.telegram.org/apps). Defaults to empty string (unset).
|
|
79
81
|
*/
|
|
80
|
-
constructor(
|
|
82
|
+
constructor(params) {
|
|
81
83
|
super();
|
|
82
84
|
_Client_instances.add(this);
|
|
83
|
-
Object.defineProperty(this, "apiId", {
|
|
84
|
-
enumerable: true,
|
|
85
|
-
configurable: true,
|
|
86
|
-
writable: true,
|
|
87
|
-
value: apiId
|
|
88
|
-
});
|
|
89
|
-
Object.defineProperty(this, "apiHash", {
|
|
90
|
-
enumerable: true,
|
|
91
|
-
configurable: true,
|
|
92
|
-
writable: true,
|
|
93
|
-
value: apiHash
|
|
94
|
-
});
|
|
95
85
|
_Client_client.set(this, void 0);
|
|
96
86
|
_Client_guaranteeUpdateDelivery.set(this, void 0);
|
|
97
87
|
_Client_updateManager.set(this, void 0);
|
|
@@ -107,6 +97,8 @@ export class Client extends Composer {
|
|
|
107
97
|
_Client_inlineQueryManager.set(this, void 0);
|
|
108
98
|
_Client_chatListManager.set(this, void 0);
|
|
109
99
|
_Client_accountManager.set(this, void 0);
|
|
100
|
+
_Client_storage_.set(this, void 0);
|
|
101
|
+
_Client_messageStorage_.set(this, void 0);
|
|
110
102
|
Object.defineProperty(this, "storage", {
|
|
111
103
|
enumerable: true,
|
|
112
104
|
configurable: true,
|
|
@@ -120,6 +112,8 @@ export class Client extends Composer {
|
|
|
120
112
|
value: void 0
|
|
121
113
|
});
|
|
122
114
|
_Client_parseMode.set(this, void 0);
|
|
115
|
+
_Client_apiId.set(this, void 0);
|
|
116
|
+
_Client_apiHash.set(this, void 0);
|
|
123
117
|
Object.defineProperty(this, "appVersion", {
|
|
124
118
|
enumerable: true,
|
|
125
119
|
configurable: true,
|
|
@@ -158,8 +152,8 @@ export class Client extends Composer {
|
|
|
158
152
|
});
|
|
159
153
|
_Client_publicKeys.set(this, void 0);
|
|
160
154
|
_Client_ignoreOutgoing.set(this, void 0);
|
|
161
|
-
|
|
162
|
-
|
|
155
|
+
_Client_persistCache.set(this, void 0);
|
|
156
|
+
_Client_LsignIn.set(this, void 0);
|
|
163
157
|
_Client_LpingLoop.set(this, void 0);
|
|
164
158
|
_Client_LhandleMigrationError.set(this, void 0);
|
|
165
159
|
_Client_L$initConncetion.set(this, void 0);
|
|
@@ -260,9 +254,9 @@ export class Client extends Composer {
|
|
|
260
254
|
}
|
|
261
255
|
unreachable();
|
|
262
256
|
};
|
|
263
|
-
const chat_ = "messageReactions" in update ? update.messageReactions.chat : "messageReactionCount" in update ? update.messageReactionCount.chat : undefined;
|
|
257
|
+
const chat_ = "messageReactions" in update ? update.messageReactions.chat : "messageReactionCount" in update ? update.messageReactionCount.chat : "chatMember" in update ? update.chatMember.chat : undefined;
|
|
264
258
|
const chat = chat_ ?? msg?.chat;
|
|
265
|
-
const from = "callbackQuery" in update ? update.callbackQuery.from : "inlineQuery" in update ? update.inlineQuery.from : "message" in update ? update.message.from : "editedMessage" in update ? update.editedMessage?.from : undefined;
|
|
259
|
+
const from = "callbackQuery" in update ? update.callbackQuery.from : "inlineQuery" in update ? update.inlineQuery.from : "message" in update ? update.message.from : "editedMessage" in update ? update.editedMessage?.from : "chatMember" in update ? update.chatMember.from : "messageReactions" in update ? update.messageReactions.user : undefined;
|
|
266
260
|
const senderChat = msg?.senderChat;
|
|
267
261
|
const getReplyToMessageId = (quote, chatId, messageId) => {
|
|
268
262
|
const isPrivate = chatId > 0;
|
|
@@ -638,14 +632,18 @@ export class Client extends Composer {
|
|
|
638
632
|
}
|
|
639
633
|
},
|
|
640
634
|
};
|
|
641
|
-
this
|
|
642
|
-
__classPrivateFieldSet(this,
|
|
643
|
-
|
|
644
|
-
|
|
635
|
+
__classPrivateFieldSet(this, _Client_apiId, params?.apiId ?? 0, "f");
|
|
636
|
+
__classPrivateFieldSet(this, _Client_apiHash, params?.apiHash ?? "", "f");
|
|
637
|
+
__classPrivateFieldSet(this, _Client_storage_, params?.storage || new StorageMemory(), "f");
|
|
638
|
+
__classPrivateFieldSet(this, _Client_persistCache, params?.persistCache ?? false, "f");
|
|
639
|
+
if (!__classPrivateFieldGet(this, _Client_persistCache, "f")) {
|
|
640
|
+
__classPrivateFieldSet(this, _Client_messageStorage_, new StorageMemory(), "f");
|
|
645
641
|
}
|
|
646
642
|
else {
|
|
647
|
-
this
|
|
643
|
+
__classPrivateFieldSet(this, _Client_messageStorage_, __classPrivateFieldGet(this, _Client_storage_, "f"), "f");
|
|
648
644
|
}
|
|
645
|
+
this.storage = new StorageOperations(__classPrivateFieldGet(this, _Client_storage_, "f"));
|
|
646
|
+
this.messageStorage = new StorageOperations(__classPrivateFieldGet(this, _Client_messageStorage_, "f"));
|
|
649
647
|
__classPrivateFieldSet(this, _Client_parseMode, params?.parseMode ?? null, "f");
|
|
650
648
|
this.appVersion = params?.appVersion ?? APP_VERSION;
|
|
651
649
|
this.deviceModel = params?.deviceModel ?? DEVICE_MODEL;
|
|
@@ -660,7 +658,7 @@ export class Client extends Composer {
|
|
|
660
658
|
}
|
|
661
659
|
__classPrivateFieldSet(this, _Client_guaranteeUpdateDelivery, params?.guaranteeUpdateDelivery ?? false, "f");
|
|
662
660
|
const L = getLogger("Client").client(id++);
|
|
663
|
-
__classPrivateFieldSet(this,
|
|
661
|
+
__classPrivateFieldSet(this, _Client_LsignIn, L.branch("signIn"), "f");
|
|
664
662
|
__classPrivateFieldSet(this, _Client_LpingLoop, L.branch("pingLoop"), "f");
|
|
665
663
|
__classPrivateFieldSet(this, _Client_LhandleMigrationError, L.branch("[handleMigrationError]"), "f");
|
|
666
664
|
__classPrivateFieldSet(this, _Client_L$initConncetion, L.branch("#initConnection"), "f");
|
|
@@ -814,10 +812,10 @@ export class Client extends Composer {
|
|
|
814
812
|
}
|
|
815
813
|
await this.connect();
|
|
816
814
|
}
|
|
817
|
-
async [(_Client_client = new WeakMap(), _Client_guaranteeUpdateDelivery = new WeakMap(), _Client_updateManager = new WeakMap(), _Client_networkStatisticsManager = new WeakMap(), _Client_botInfoManager = new WeakMap(), _Client_fileManager = new WeakMap(), _Client_reactionManager = new WeakMap(), _Client_videoChatManager = new WeakMap(), _Client_businessConnectionManager = new WeakMap(), _Client_messageManager = new WeakMap(), _Client_storyManager = new WeakMap(), _Client_callbackQueryManager = new WeakMap(), _Client_inlineQueryManager = new WeakMap(), _Client_chatListManager = new WeakMap(), _Client_accountManager = new WeakMap(), _Client_parseMode = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_ignoreOutgoing = new WeakMap(),
|
|
818
|
-
const apiId = this
|
|
815
|
+
async [(_Client_client = new WeakMap(), _Client_guaranteeUpdateDelivery = new WeakMap(), _Client_updateManager = new WeakMap(), _Client_networkStatisticsManager = new WeakMap(), _Client_botInfoManager = new WeakMap(), _Client_fileManager = new WeakMap(), _Client_reactionManager = new WeakMap(), _Client_videoChatManager = new WeakMap(), _Client_businessConnectionManager = new WeakMap(), _Client_messageManager = new WeakMap(), _Client_storyManager = new WeakMap(), _Client_callbackQueryManager = new WeakMap(), _Client_inlineQueryManager = new WeakMap(), _Client_chatListManager = new WeakMap(), _Client_accountManager = new WeakMap(), _Client_storage_ = new WeakMap(), _Client_messageStorage_ = new WeakMap(), _Client_parseMode = new WeakMap(), _Client_apiId = new WeakMap(), _Client_apiHash = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_ignoreOutgoing = new WeakMap(), _Client_persistCache = new WeakMap(), _Client_LsignIn = new WeakMap(), _Client_LpingLoop = new WeakMap(), _Client_LhandleMigrationError = new WeakMap(), _Client_L$initConncetion = new WeakMap(), _Client_namespaceProxies = new WeakMap(), _Client_constructContext = new WeakMap(), _Client_lastPropagatedConnectionState = new WeakMap(), _Client_stateChangeHandler = new WeakMap(), _Client_storageInited = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_pingLoopStarted = new WeakMap(), _Client_pingLoopAbortController = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_lastUpdates = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_instances = new WeakSet(), _Client_getApiId = async function _Client_getApiId() {
|
|
816
|
+
const apiId = __classPrivateFieldGet(this, _Client_apiId, "f") || await this.storage.getApiId();
|
|
819
817
|
if (!apiId) {
|
|
820
|
-
throw new
|
|
818
|
+
throw new InputError("apiId not set");
|
|
821
819
|
}
|
|
822
820
|
return apiId;
|
|
823
821
|
}, _Client_getCdnConnectionPool = function _Client_getCdnConnectionPool(connectionCount, dcId) {
|
|
@@ -846,7 +844,11 @@ export class Client extends Composer {
|
|
|
846
844
|
},
|
|
847
845
|
};
|
|
848
846
|
}, _Client_getCdnConnection = function _Client_getCdnConnection(dcId) {
|
|
849
|
-
const
|
|
847
|
+
const provider = this.storage.provider;
|
|
848
|
+
const client = new _a({
|
|
849
|
+
storage: (!dcId || dcId == __classPrivateFieldGet(this, _Client_client, "f").dcId) ? provider : provider.branch(`download_client_${dcId}`),
|
|
850
|
+
apiId: __classPrivateFieldGet(this, _Client_apiId, "f"),
|
|
851
|
+
apiHash: __classPrivateFieldGet(this, _Client_apiHash, "f"),
|
|
850
852
|
transportProvider: __classPrivateFieldGet(this, _Client_client, "f").transportProvider,
|
|
851
853
|
appVersion: this.appVersion,
|
|
852
854
|
deviceModel: this.deviceModel,
|
|
@@ -911,25 +913,19 @@ export class Client extends Composer {
|
|
|
911
913
|
__classPrivateFieldGet(this, _Client_pingLoopAbortController, "f")?.abort();
|
|
912
914
|
}
|
|
913
915
|
/**
|
|
914
|
-
*
|
|
915
|
-
*
|
|
916
|
-
* - Bot token (`string`)
|
|
917
|
-
* - User authorization handlers (`AuthorizeUserParams`)
|
|
918
|
-
*
|
|
919
|
-
* if the current auth key doesn't throw AUTH_KEY_UNREGISTERED when calling [updates.getState](1).
|
|
916
|
+
* Signs in using the provided parameters if not already signed in.
|
|
917
|
+
* If no parameters are provided, the credentials will be prompted in runtime.
|
|
920
918
|
*
|
|
921
919
|
* Notes:
|
|
922
920
|
* 1. Requires the `apiId` and `apiHash` paramters to be passed when constructing the client.
|
|
923
|
-
*
|
|
924
|
-
*
|
|
925
|
-
* [1]: https://core.telegram.org/method/updates.getState
|
|
921
|
+
* 3. Reconnects the client to the appropriate DC in case of MIGRATE_X errors.
|
|
926
922
|
*/
|
|
927
|
-
async
|
|
923
|
+
async signIn(params) {
|
|
928
924
|
try {
|
|
929
|
-
await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("
|
|
925
|
+
await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("signIn");
|
|
930
926
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
|
|
931
|
-
drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("
|
|
932
|
-
__classPrivateFieldGet(this,
|
|
927
|
+
drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("signIn"));
|
|
928
|
+
__classPrivateFieldGet(this, _Client_LsignIn, "f").debug("already signed in");
|
|
933
929
|
return;
|
|
934
930
|
}
|
|
935
931
|
catch (err) {
|
|
@@ -938,23 +934,23 @@ export class Client extends Composer {
|
|
|
938
934
|
}
|
|
939
935
|
}
|
|
940
936
|
const apiId = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getApiId).call(this);
|
|
941
|
-
if (!this
|
|
942
|
-
throw new
|
|
937
|
+
if (!__classPrivateFieldGet(this, _Client_apiHash, "f")) {
|
|
938
|
+
throw new InputError("apiHash not set");
|
|
943
939
|
}
|
|
944
940
|
if (typeof params === "undefined") {
|
|
945
941
|
const loginType = mustPromptOneOf("Do you want to login as bot [b] or user [u]?", ["b", "u"]);
|
|
946
942
|
if (loginType == "b") {
|
|
947
|
-
params = mustPrompt("Bot token:");
|
|
943
|
+
params = { botToken: mustPrompt("Bot token:") };
|
|
948
944
|
}
|
|
949
945
|
else {
|
|
950
946
|
params = { phone: () => mustPrompt("Phone number:"), code: () => mustPrompt("Verification code:"), password: () => mustPrompt("Password:") };
|
|
951
947
|
}
|
|
952
948
|
}
|
|
953
|
-
__classPrivateFieldGet(this,
|
|
954
|
-
if (
|
|
949
|
+
__classPrivateFieldGet(this, _Client_LsignIn, "f").debug("authorizing with", typeof params === "string" ? "bot token" : params instanceof types.auth.ExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
|
|
950
|
+
if (params && "botToken" in params) {
|
|
955
951
|
while (true) {
|
|
956
952
|
try {
|
|
957
|
-
const auth = await this.api.auth.importBotAuthorization({ api_id: apiId, api_hash: this
|
|
953
|
+
const auth = await this.api.auth.importBotAuthorization({ api_id: apiId, api_hash: __classPrivateFieldGet(this, _Client_apiHash, "f"), bot_auth_token: params.botToken, flags: 0 });
|
|
958
954
|
await this.storage.setAccountId(Number(auth[as](types.auth.Authorization).user.id));
|
|
959
955
|
await this.storage.setAccountType("bot");
|
|
960
956
|
break;
|
|
@@ -969,7 +965,7 @@ export class Client extends Composer {
|
|
|
969
965
|
}
|
|
970
966
|
}
|
|
971
967
|
}
|
|
972
|
-
__classPrivateFieldGet(this,
|
|
968
|
+
__classPrivateFieldGet(this, _Client_LsignIn, "f").debug("authorized as bot");
|
|
973
969
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
|
|
974
970
|
await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("authorize");
|
|
975
971
|
return;
|
|
@@ -983,8 +979,8 @@ export class Client extends Composer {
|
|
|
983
979
|
phone = typeof params.phone === "string" ? params.phone : await params.phone();
|
|
984
980
|
const sendCode = () => this.api.auth.sendCode({
|
|
985
981
|
phone_number: phone,
|
|
986
|
-
api_id: this
|
|
987
|
-
api_hash: this
|
|
982
|
+
api_id: __classPrivateFieldGet(this, _Client_apiId, "f"),
|
|
983
|
+
api_hash: __classPrivateFieldGet(this, _Client_apiHash, "f"),
|
|
988
984
|
settings: new types.CodeSettings(),
|
|
989
985
|
}).then((v) => v[as](types.auth.SentCode));
|
|
990
986
|
try {
|
|
@@ -1010,7 +1006,7 @@ export class Client extends Composer {
|
|
|
1010
1006
|
}
|
|
1011
1007
|
}
|
|
1012
1008
|
}
|
|
1013
|
-
__classPrivateFieldGet(this,
|
|
1009
|
+
__classPrivateFieldGet(this, _Client_LsignIn, "f").debug("verification code sent");
|
|
1014
1010
|
let err;
|
|
1015
1011
|
code: while (true) {
|
|
1016
1012
|
const code = typeof params.code === "string" ? params.code : await params.code();
|
|
@@ -1022,13 +1018,13 @@ export class Client extends Composer {
|
|
|
1022
1018
|
});
|
|
1023
1019
|
await this.storage.setAccountId(Number(auth[as](types.auth.Authorization).user.id));
|
|
1024
1020
|
await this.storage.setAccountType("user");
|
|
1025
|
-
__classPrivateFieldGet(this,
|
|
1021
|
+
__classPrivateFieldGet(this, _Client_LsignIn, "f").debug("signed in as user");
|
|
1026
1022
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
|
|
1027
|
-
await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("
|
|
1023
|
+
await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("signIn");
|
|
1028
1024
|
return;
|
|
1029
1025
|
}
|
|
1030
1026
|
catch (err_) {
|
|
1031
|
-
if (err_ instanceof
|
|
1027
|
+
if (err_ instanceof PhoneCodeInvalid) {
|
|
1032
1028
|
continue code;
|
|
1033
1029
|
}
|
|
1034
1030
|
else {
|
|
@@ -1051,9 +1047,9 @@ export class Client extends Composer {
|
|
|
1051
1047
|
const auth = await this.api.auth.checkPassword({ password: input });
|
|
1052
1048
|
await this.storage.setAccountId(Number(auth[as](types.auth.Authorization).user.id));
|
|
1053
1049
|
await this.storage.setAccountType("user");
|
|
1054
|
-
__classPrivateFieldGet(this,
|
|
1050
|
+
__classPrivateFieldGet(this, _Client_LsignIn, "f").debug("signed in as user");
|
|
1055
1051
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
|
|
1056
|
-
await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("
|
|
1052
|
+
await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("signIn");
|
|
1057
1053
|
return;
|
|
1058
1054
|
}
|
|
1059
1055
|
catch (err) {
|
|
@@ -1076,12 +1072,26 @@ export class Client extends Composer {
|
|
|
1076
1072
|
}
|
|
1077
1073
|
}
|
|
1078
1074
|
}
|
|
1075
|
+
async signOut() {
|
|
1076
|
+
try {
|
|
1077
|
+
await Promise.all([
|
|
1078
|
+
this.storage.reset(),
|
|
1079
|
+
this.api.auth.logOut().then(() => {
|
|
1080
|
+
__classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, false);
|
|
1081
|
+
}),
|
|
1082
|
+
]);
|
|
1083
|
+
}
|
|
1084
|
+
finally {
|
|
1085
|
+
__classPrivateFieldSet(this, _Client_lastGetMe, null, "f");
|
|
1086
|
+
await this.reconnect();
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1079
1089
|
/**
|
|
1080
|
-
* Same as calling `.connect()` followed by `.
|
|
1090
|
+
* Same as calling `.connect()` followed by `.signIn(params)`.
|
|
1081
1091
|
*/
|
|
1082
1092
|
async start(params) {
|
|
1083
1093
|
await this.connect();
|
|
1084
|
-
await this.
|
|
1094
|
+
await this.signIn(params);
|
|
1085
1095
|
}
|
|
1086
1096
|
/**
|
|
1087
1097
|
* Alias for `invoke` with its second parameter being `true`.
|
|
@@ -1090,7 +1100,7 @@ export class Client extends Composer {
|
|
|
1090
1100
|
return this.invoke(function_, true);
|
|
1091
1101
|
}
|
|
1092
1102
|
exportAuthString() {
|
|
1093
|
-
return this.storage.exportAuthString(this
|
|
1103
|
+
return this.storage.exportAuthString(__classPrivateFieldGet(this, _Client_apiId, "f"));
|
|
1094
1104
|
}
|
|
1095
1105
|
async importAuthString(authString) {
|
|
1096
1106
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initStorage).call(this);
|
|
@@ -18,24 +18,15 @@
|
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
20
|
import { MaybePromise } from "../1_utilities.js";
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
export interface Connection {
|
|
22
|
+
get connected(): boolean;
|
|
23
23
|
stateChangeHandler?: (connected: boolean) => void;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
open(): MaybePromise<void>;
|
|
25
|
+
write(p: Uint8Array): MaybePromise<void>;
|
|
26
|
+
close(): MaybePromise<void>;
|
|
27
27
|
callback?: {
|
|
28
28
|
read(count: number): void;
|
|
29
29
|
write(count: number): void;
|
|
30
30
|
};
|
|
31
|
+
read(p: Uint8Array): MaybePromise<void>;
|
|
31
32
|
}
|
|
32
|
-
export declare abstract class ConnectionUnframed extends Foundation {
|
|
33
|
-
readonly type: "framed";
|
|
34
|
-
abstract read(p: Uint8Array): MaybePromise<void>;
|
|
35
|
-
}
|
|
36
|
-
export declare abstract class ConnectionFramed extends Foundation {
|
|
37
|
-
readonly type: "framed";
|
|
38
|
-
abstract read(): MaybePromise<Uint8Array>;
|
|
39
|
-
}
|
|
40
|
-
export type Connection = ConnectionUnframed | ConnectionFramed;
|
|
41
|
-
export {};
|
|
@@ -17,41 +17,4 @@
|
|
|
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
|
-
|
|
21
|
-
constructor() {
|
|
22
|
-
Object.defineProperty(this, "stateChangeHandler", {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
writable: true,
|
|
26
|
-
value: void 0
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(this, "callback", {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
configurable: true,
|
|
31
|
-
writable: true,
|
|
32
|
-
value: void 0
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
export class ConnectionUnframed extends Foundation {
|
|
37
|
-
constructor() {
|
|
38
|
-
super(...arguments);
|
|
39
|
-
Object.defineProperty(this, "type", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
configurable: true,
|
|
42
|
-
writable: true,
|
|
43
|
-
value: "framed"
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export class ConnectionFramed extends Foundation {
|
|
48
|
-
constructor() {
|
|
49
|
-
super(...arguments);
|
|
50
|
-
Object.defineProperty(this, "type", {
|
|
51
|
-
enumerable: true,
|
|
52
|
-
configurable: true,
|
|
53
|
-
writable: true,
|
|
54
|
-
value: "framed"
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
20
|
+
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class ConnectionWebSocket
|
|
1
|
+
import { Connection } from "./0_connection.js";
|
|
2
|
+
export declare class ConnectionWebSocket implements Connection {
|
|
3
3
|
#private;
|
|
4
4
|
private readonly url;
|
|
5
|
+
stateChangeHandler?: Connection["stateChangeHandler"];
|
|
5
6
|
constructor(url: string | URL);
|
|
6
7
|
get connected(): boolean;
|
|
7
8
|
open(): Promise<void>;
|
|
@@ -32,12 +32,10 @@ var _ConnectionWebSocket_instances, _ConnectionWebSocket_webSocket, _ConnectionW
|
|
|
32
32
|
import * as dntShim from "../_dnt.shims.js";
|
|
33
33
|
import { concat, unreachable } from "../0_deps.js";
|
|
34
34
|
import { getLogger, Mutex } from "../1_utilities.js";
|
|
35
|
-
import { ConnectionUnframed } from "./0_connection.js";
|
|
36
35
|
const L = getLogger("ConnectionWebSocket");
|
|
37
36
|
const errConnectionNotOpen = new Error("Connection not open");
|
|
38
|
-
export class ConnectionWebSocket
|
|
37
|
+
export class ConnectionWebSocket {
|
|
39
38
|
constructor(url) {
|
|
40
|
-
super();
|
|
41
39
|
_ConnectionWebSocket_instances.add(this);
|
|
42
40
|
Object.defineProperty(this, "url", {
|
|
43
41
|
enumerable: true,
|
|
@@ -50,6 +48,12 @@ export class ConnectionWebSocket extends ConnectionUnframed {
|
|
|
50
48
|
_ConnectionWebSocket_wMutex.set(this, new Mutex());
|
|
51
49
|
_ConnectionWebSocket_buffer.set(this, new Uint8Array());
|
|
52
50
|
_ConnectionWebSocket_nextResolve.set(this, null);
|
|
51
|
+
Object.defineProperty(this, "stateChangeHandler", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
value: void 0
|
|
56
|
+
});
|
|
53
57
|
_ConnectionWebSocket_wasConnected.set(this, false);
|
|
54
58
|
_ConnectionWebSocket_isConnecting.set(this, false);
|
|
55
59
|
_ConnectionWebSocket_connectionError.set(this, null);
|
package/esm/mod.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export * from "./0_errors.js";
|
|
|
21
21
|
export { getColorFromPeerId, getColorName, getRandomId, type LoggingProvider, setLoggingProvider, setLogVerbosity } from "./1_utilities.js";
|
|
22
22
|
export { checkPassword } from "./client/0_password.js";
|
|
23
23
|
export * from "./2_connection.js";
|
|
24
|
-
export * from "./
|
|
24
|
+
export * from "./2_storage.js";
|
|
25
25
|
export * from "./3_transport.js";
|
|
26
26
|
export * from "./2_tl.js";
|
|
27
27
|
export * from "./3_types.js";
|
package/esm/mod.js
CHANGED
|
@@ -21,7 +21,7 @@ export * from "./0_errors.js";
|
|
|
21
21
|
export { getColorFromPeerId, getColorName, getRandomId, setLoggingProvider, setLogVerbosity } from "./1_utilities.js";
|
|
22
22
|
export { checkPassword } from "./client/0_password.js";
|
|
23
23
|
export * from "./2_connection.js";
|
|
24
|
-
export * from "./
|
|
24
|
+
export * from "./2_storage.js";
|
|
25
25
|
export * from "./3_transport.js";
|
|
26
26
|
export * from "./2_tl.js";
|
|
27
27
|
export * from "./3_types.js";
|