@mtcute/core 0.27.8 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.cjs +4 -0
- package/client.js +4 -0
- package/highlevel/client.d.cts +8 -0
- package/highlevel/client.d.ts +8 -0
- package/highlevel/methods/chats/get-creator-after-leave.cjs +18 -0
- package/highlevel/methods/chats/get-creator-after-leave.d.cts +9 -0
- package/highlevel/methods/chats/get-creator-after-leave.d.ts +9 -0
- package/highlevel/methods/chats/get-creator-after-leave.js +13 -0
- package/highlevel/methods/dialogs/iter-dialogs.cjs +4 -0
- package/highlevel/methods/dialogs/iter-dialogs.js +4 -0
- package/highlevel/methods/files/download-iterable.cjs +17 -6
- package/highlevel/methods/files/download-iterable.js +17 -6
- package/highlevel/methods/gifts/get-resale-star-gifts.cjs +2 -1
- package/highlevel/methods/gifts/get-resale-star-gifts.d.cts +2 -0
- package/highlevel/methods/gifts/get-resale-star-gifts.d.ts +2 -0
- package/highlevel/methods/gifts/get-resale-star-gifts.js +2 -1
- package/highlevel/methods.d.cts +1 -0
- package/highlevel/methods.d.ts +1 -0
- package/highlevel/types/bots/keyboards/factories.cjs +26 -18
- package/highlevel/types/bots/keyboards/factories.d.cts +34 -10
- package/highlevel/types/bots/keyboards/factories.d.ts +34 -10
- package/highlevel/types/bots/keyboards/factories.js +26 -18
- package/highlevel/types/messages/message-action.cjs +18 -0
- package/highlevel/types/messages/message-action.d.cts +20 -1
- package/highlevel/types/messages/message-action.d.ts +20 -1
- package/highlevel/types/messages/message-action.js +18 -0
- package/highlevel/types/peers/chat.cjs +1 -1
- package/highlevel/types/peers/chat.js +1 -1
- package/highlevel/types/peers/user.cjs +3 -0
- package/highlevel/types/peers/user.d.cts +1 -0
- package/highlevel/types/peers/user.d.ts +1 -0
- package/highlevel/types/peers/user.js +3 -0
- package/highlevel/types/premium/saved-star-gift.cjs +4 -0
- package/highlevel/types/premium/saved-star-gift.d.cts +2 -0
- package/highlevel/types/premium/saved-star-gift.d.ts +2 -0
- package/highlevel/types/premium/saved-star-gift.js +4 -0
- package/highlevel/types/premium/star-gift-unique.cjs +43 -4
- package/highlevel/types/premium/star-gift-unique.d.cts +18 -4
- package/highlevel/types/premium/star-gift-unique.d.ts +18 -4
- package/highlevel/types/premium/star-gift-unique.js +43 -4
- package/highlevel/updates/manager.cjs +11 -0
- package/highlevel/updates/manager.d.cts +2 -1
- package/highlevel/updates/manager.d.ts +2 -1
- package/highlevel/updates/manager.js +12 -1
- package/index.cjs +2 -0
- package/index.js +2 -0
- package/methods.cjs +2 -0
- package/methods.js +2 -0
- package/network/network-manager.cjs +1 -1
- package/network/network-manager.js +1 -1
- package/network/server-salt.cjs +2 -7
- package/network/server-salt.js +2 -7
- package/network/transports/index.d.cts +1 -0
- package/network/transports/index.d.ts +1 -0
- package/network/transports/proxy.cjs +46 -0
- package/network/transports/proxy.d.cts +10 -0
- package/network/transports/proxy.d.ts +10 -0
- package/network/transports/proxy.js +41 -0
- package/network/transports/proxy.test.d.cts +1 -0
- package/network/transports/proxy.test.d.ts +1 -0
- package/package.json +2 -2
- package/utils/binary/compat.cjs +105 -4
- package/utils/binary/compat.js +105 -4
|
@@ -64,6 +64,10 @@ class UpdatesManager {
|
|
|
64
64
|
// channel id or 0 => pts
|
|
65
65
|
noDispatchPts = /* @__PURE__ */ new Map();
|
|
66
66
|
noDispatchQts = /* @__PURE__ */ new Set();
|
|
67
|
+
// message IDs from common message box that were dispatched recently,
|
|
68
|
+
// used to deduplicate messages from getDifference.newMessages that may have
|
|
69
|
+
// already been processed via regular pts-ordered updates
|
|
70
|
+
_recentlyDispatchedCommonMsgs = new utils.LruSet(100);
|
|
67
71
|
lock = new utils.AsyncLock();
|
|
68
72
|
// rpsIncoming?: RpsMeter
|
|
69
73
|
// rpsProcessing?: RpsMeter
|
|
@@ -777,6 +781,10 @@ class UpdatesManager {
|
|
|
777
781
|
diff.newMessages.forEach((message) => {
|
|
778
782
|
log.debug("processing message %d in %j (%s) from common diff", message.id, message.peerId, message._);
|
|
779
783
|
if (message._ === "messageEmpty") return;
|
|
784
|
+
if (this._recentlyDispatchedCommonMsgs.has(message.id)) {
|
|
785
|
+
log.debug("skipping message %d from common diff because it was already dispatched", message.id);
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
780
788
|
pendingUnorderedUpdates.pushBack(utils$2.toPendingUpdate(utils$2.messageToUpdate(message), peers, true));
|
|
781
789
|
});
|
|
782
790
|
diff.otherUpdates.forEach((upd) => {
|
|
@@ -984,6 +992,9 @@ class UpdatesManager {
|
|
|
984
992
|
}
|
|
985
993
|
}
|
|
986
994
|
log.debug("dispatching %s (postponed = %s)", upd._, postponed);
|
|
995
|
+
if (upd._ === "updateNewMessage" && upd.message._ !== "messageEmpty") {
|
|
996
|
+
this._recentlyDispatchedCommonMsgs.add(upd.message.id);
|
|
997
|
+
}
|
|
987
998
|
client.onRawUpdate.emit(new types.RawUpdateInfo(upd, pending.peers));
|
|
988
999
|
}
|
|
989
1000
|
async _loop() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Logger, EarlyTimer, SortedArray } from '../../utils/index.js';
|
|
2
2
|
import { BaseTelegramClient } from '../base.js';
|
|
3
3
|
import { PendingUpdate, PendingUpdateContainer, UpdatesManagerParams } from './types.js';
|
|
4
|
-
import { AsyncLock, ConditionVariable, Deque, timers } from '@fuman/utils';
|
|
4
|
+
import { AsyncLock, ConditionVariable, Deque, LruSet, timers } from '@fuman/utils';
|
|
5
5
|
import { tl } from '@mtcute/tl';
|
|
6
6
|
import { PeersIndex } from '../types/peers/peers-index.js';
|
|
7
7
|
export declare class UpdatesManager {
|
|
@@ -21,6 +21,7 @@ export declare class UpdatesManager {
|
|
|
21
21
|
noDispatchMsg: Map<number, Set<number>>;
|
|
22
22
|
noDispatchPts: Map<number, Set<number>>;
|
|
23
23
|
noDispatchQts: Set<number>;
|
|
24
|
+
_recentlyDispatchedCommonMsgs: LruSet<number>;
|
|
24
25
|
lock: AsyncLock;
|
|
25
26
|
pts?: number;
|
|
26
27
|
qts?: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Logger, EarlyTimer, SortedArray } from '../../utils/index.js';
|
|
2
2
|
import { BaseTelegramClient } from '../base.js';
|
|
3
3
|
import { PendingUpdate, PendingUpdateContainer, UpdatesManagerParams } from './types.js';
|
|
4
|
-
import { AsyncLock, ConditionVariable, Deque, timers } from '@fuman/utils';
|
|
4
|
+
import { AsyncLock, ConditionVariable, Deque, LruSet, timers } from '@fuman/utils';
|
|
5
5
|
import { tl } from '@mtcute/tl';
|
|
6
6
|
import { PeersIndex } from '../types/peers/peers-index.js';
|
|
7
7
|
export declare class UpdatesManager {
|
|
@@ -21,6 +21,7 @@ export declare class UpdatesManager {
|
|
|
21
21
|
noDispatchMsg: Map<number, Set<number>>;
|
|
22
22
|
noDispatchPts: Map<number, Set<number>>;
|
|
23
23
|
noDispatchQts: Set<number>;
|
|
24
|
+
_recentlyDispatchedCommonMsgs: LruSet<number>;
|
|
24
25
|
lock: AsyncLock;
|
|
25
26
|
pts?: number;
|
|
26
27
|
qts?: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConditionVariable, Deque, AsyncLock, unknownToError, timers } from "@fuman/utils";
|
|
1
|
+
import { ConditionVariable, Deque, LruSet, AsyncLock, unknownToError, timers } from "@fuman/utils";
|
|
2
2
|
import { tl } from "@mtcute/tl";
|
|
3
3
|
import Long from "long";
|
|
4
4
|
import { MtArgumentError } from "../../types/errors.js";
|
|
@@ -57,6 +57,10 @@ class UpdatesManager {
|
|
|
57
57
|
// channel id or 0 => pts
|
|
58
58
|
noDispatchPts = /* @__PURE__ */ new Map();
|
|
59
59
|
noDispatchQts = /* @__PURE__ */ new Set();
|
|
60
|
+
// message IDs from common message box that were dispatched recently,
|
|
61
|
+
// used to deduplicate messages from getDifference.newMessages that may have
|
|
62
|
+
// already been processed via regular pts-ordered updates
|
|
63
|
+
_recentlyDispatchedCommonMsgs = new LruSet(100);
|
|
60
64
|
lock = new AsyncLock();
|
|
61
65
|
// rpsIncoming?: RpsMeter
|
|
62
66
|
// rpsProcessing?: RpsMeter
|
|
@@ -770,6 +774,10 @@ class UpdatesManager {
|
|
|
770
774
|
diff.newMessages.forEach((message) => {
|
|
771
775
|
log.debug("processing message %d in %j (%s) from common diff", message.id, message.peerId, message._);
|
|
772
776
|
if (message._ === "messageEmpty") return;
|
|
777
|
+
if (this._recentlyDispatchedCommonMsgs.has(message.id)) {
|
|
778
|
+
log.debug("skipping message %d from common diff because it was already dispatched", message.id);
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
773
781
|
pendingUnorderedUpdates.pushBack(toPendingUpdate(messageToUpdate(message), peers, true));
|
|
774
782
|
});
|
|
775
783
|
diff.otherUpdates.forEach((upd) => {
|
|
@@ -977,6 +985,9 @@ class UpdatesManager {
|
|
|
977
985
|
}
|
|
978
986
|
}
|
|
979
987
|
log.debug("dispatching %s (postponed = %s)", upd._, postponed);
|
|
988
|
+
if (upd._ === "updateNewMessage" && upd.message._ !== "messageEmpty") {
|
|
989
|
+
this._recentlyDispatchedCommonMsgs.add(upd.message.id);
|
|
990
|
+
}
|
|
980
991
|
client.onRawUpdate.emit(new RawUpdateInfo(upd, pending.peers));
|
|
981
992
|
}
|
|
982
993
|
async _loop() {
|
package/index.cjs
CHANGED
|
@@ -145,6 +145,7 @@ const sessionConnection = require("./network/session-connection.cjs");
|
|
|
145
145
|
const abstract = require("./network/transports/abstract.cjs");
|
|
146
146
|
const intermediate = require("./network/transports/intermediate.cjs");
|
|
147
147
|
const obfuscated = require("./network/transports/obfuscated.cjs");
|
|
148
|
+
const proxy = require("./network/transports/proxy.cjs");
|
|
148
149
|
const driver = require("./storage/driver.cjs");
|
|
149
150
|
const driver$1 = require("./storage/memory/driver.cjs");
|
|
150
151
|
const authKeys = require("./storage/memory/repository/auth-keys.cjs");
|
|
@@ -334,6 +335,7 @@ exports.TransportError = abstract.TransportError;
|
|
|
334
335
|
exports.IntermediatePacketCodec = intermediate.IntermediatePacketCodec;
|
|
335
336
|
exports.PaddedIntermediatePacketCodec = intermediate.PaddedIntermediatePacketCodec;
|
|
336
337
|
exports.ObfuscatedPacketCodec = obfuscated.ObfuscatedPacketCodec;
|
|
338
|
+
exports.createProxyTransportFactory = proxy.createProxyTransportFactory;
|
|
337
339
|
exports.BaseStorageDriver = driver.BaseStorageDriver;
|
|
338
340
|
exports.MemoryStorageDriver = driver$1.MemoryStorageDriver;
|
|
339
341
|
exports.MemoryAuthKeysRepository = authKeys.MemoryAuthKeysRepository;
|
package/index.js
CHANGED
|
@@ -138,6 +138,7 @@ import { SessionConnection } from "./network/session-connection.js";
|
|
|
138
138
|
import { TransportError } from "./network/transports/abstract.js";
|
|
139
139
|
import { IntermediatePacketCodec, PaddedIntermediatePacketCodec } from "./network/transports/intermediate.js";
|
|
140
140
|
import { ObfuscatedPacketCodec } from "./network/transports/obfuscated.js";
|
|
141
|
+
import { createProxyTransportFactory } from "./network/transports/proxy.js";
|
|
141
142
|
import { BaseStorageDriver } from "./storage/driver.js";
|
|
142
143
|
import { MemoryStorageDriver } from "./storage/memory/driver.js";
|
|
143
144
|
import { MemoryAuthKeysRepository } from "./storage/memory/repository/auth-keys.js";
|
|
@@ -323,6 +324,7 @@ export {
|
|
|
323
324
|
_storyInteractiveElementFromTl,
|
|
324
325
|
assertNever,
|
|
325
326
|
businessWorkHoursDaysToRaw,
|
|
327
|
+
createProxyTransportFactory,
|
|
326
328
|
getAllPeersFrom,
|
|
327
329
|
getBarePeerId,
|
|
328
330
|
getBasicPeerType,
|
package/methods.cjs
CHANGED
|
@@ -52,6 +52,7 @@ const getChatMember = require("./highlevel/methods/chats/get-chat-member.cjs");
|
|
|
52
52
|
const getChatMembers = require("./highlevel/methods/chats/get-chat-members.cjs");
|
|
53
53
|
const getChatPreview = require("./highlevel/methods/chats/get-chat-preview.cjs");
|
|
54
54
|
const getChat = require("./highlevel/methods/chats/get-chat.cjs");
|
|
55
|
+
const getCreatorAfterLeave = require("./highlevel/methods/chats/get-creator-after-leave.cjs");
|
|
55
56
|
const getFullChat = require("./highlevel/methods/chats/get-full-chat.cjs");
|
|
56
57
|
const getFullUser = require("./highlevel/methods/chats/get-full-user.cjs");
|
|
57
58
|
const getMessageAuthor = require("./highlevel/methods/chats/get-message-author.cjs");
|
|
@@ -331,6 +332,7 @@ exports.getChatMember = getChatMember.getChatMember;
|
|
|
331
332
|
exports.getChatMembers = getChatMembers.getChatMembers;
|
|
332
333
|
exports.getChatPreview = getChatPreview.getChatPreview;
|
|
333
334
|
exports.getChat = getChat.getChat;
|
|
335
|
+
exports.getCreatorAfterLeave = getCreatorAfterLeave.getCreatorAfterLeave;
|
|
334
336
|
exports.getFullChat = getFullChat.getFullChat;
|
|
335
337
|
exports.getFullUser = getFullUser.getFullUser;
|
|
336
338
|
exports.getMessageAuthor = getMessageAuthor.getMessageAuthor;
|
package/methods.js
CHANGED
|
@@ -45,6 +45,7 @@ import { getChatMember } from "./highlevel/methods/chats/get-chat-member.js";
|
|
|
45
45
|
import { getChatMembers } from "./highlevel/methods/chats/get-chat-members.js";
|
|
46
46
|
import { getChatPreview } from "./highlevel/methods/chats/get-chat-preview.js";
|
|
47
47
|
import { getChat } from "./highlevel/methods/chats/get-chat.js";
|
|
48
|
+
import { getCreatorAfterLeave } from "./highlevel/methods/chats/get-creator-after-leave.js";
|
|
48
49
|
import { getFullChat } from "./highlevel/methods/chats/get-full-chat.js";
|
|
49
50
|
import { getFullUser } from "./highlevel/methods/chats/get-full-user.js";
|
|
50
51
|
import { getMessageAuthor } from "./highlevel/methods/chats/get-message-author.js";
|
|
@@ -371,6 +372,7 @@ export {
|
|
|
371
372
|
getCollectibleInfo,
|
|
372
373
|
getCommonChats,
|
|
373
374
|
getContacts,
|
|
375
|
+
getCreatorAfterLeave,
|
|
374
376
|
getCustomEmojis,
|
|
375
377
|
getCustomEmojisFromMessages,
|
|
376
378
|
getDiscussionMessage,
|
package/network/server-salt.cjs
CHANGED
|
@@ -17,16 +17,11 @@ class ServerSaltManager {
|
|
|
17
17
|
setFutureSalts(salts) {
|
|
18
18
|
this._futureSalts = salts;
|
|
19
19
|
const now = Date.now() / 1e3;
|
|
20
|
-
while (salts.length > 0 &&
|
|
20
|
+
while (salts.length > 0 && salts[0].validSince <= now) {
|
|
21
21
|
this.currentSalt = salts[0].salt;
|
|
22
22
|
this._futureSalts.shift();
|
|
23
23
|
}
|
|
24
|
-
if (
|
|
25
|
-
this.currentSalt = salts[0].salt;
|
|
26
|
-
this._futureSalts.shift();
|
|
27
|
-
}
|
|
28
|
-
if (!this._futureSalts.length) ;
|
|
29
|
-
else {
|
|
24
|
+
if (this._futureSalts.length) {
|
|
30
25
|
this._scheduleReplace(this._futureSalts[0]);
|
|
31
26
|
}
|
|
32
27
|
}
|
package/network/server-salt.js
CHANGED
|
@@ -10,16 +10,11 @@ class ServerSaltManager {
|
|
|
10
10
|
setFutureSalts(salts) {
|
|
11
11
|
this._futureSalts = salts;
|
|
12
12
|
const now = Date.now() / 1e3;
|
|
13
|
-
while (salts.length > 0 &&
|
|
13
|
+
while (salts.length > 0 && salts[0].validSince <= now) {
|
|
14
14
|
this.currentSalt = salts[0].salt;
|
|
15
15
|
this._futureSalts.shift();
|
|
16
16
|
}
|
|
17
|
-
if (
|
|
18
|
-
this.currentSalt = salts[0].salt;
|
|
19
|
-
this._futureSalts.shift();
|
|
20
|
-
}
|
|
21
|
-
if (!this._futureSalts.length) ;
|
|
22
|
-
else {
|
|
17
|
+
if (this._futureSalts.length) {
|
|
23
18
|
this._scheduleReplace(this._futureSalts[0]);
|
|
24
19
|
}
|
|
25
20
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
2
|
+
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
3
|
+
console.warn("[@mtcute/core] CommonJS bundles are deprecated. They will be removed completely in one of the upcoming releases. No support is provided for CommonJS users. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
|
|
4
|
+
console.warn("[@mtcute/core] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
|
|
5
|
+
}
|
|
6
|
+
"use strict";
|
|
7
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
+
const errors = require("../../types/errors.cjs");
|
|
9
|
+
const proxy = require("../../utils/links/proxy.cjs");
|
|
10
|
+
function createProxyTransportFactory(options) {
|
|
11
|
+
const { SocksProxyTcpTransport, MtProxyTcpTransport, HttpProxyTcpTransport } = options;
|
|
12
|
+
return (url) => {
|
|
13
|
+
const obj = new URL(url);
|
|
14
|
+
if (SocksProxyTcpTransport != null && (obj.protocol === "socks4:" || obj.protocol === "socks5:")) {
|
|
15
|
+
return new SocksProxyTcpTransport({
|
|
16
|
+
version: obj.protocol === "socks4:" ? 4 : 5,
|
|
17
|
+
host: obj.hostname,
|
|
18
|
+
port: Number(obj.port) || 1080,
|
|
19
|
+
user: obj.username,
|
|
20
|
+
password: obj.password
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (MtProxyTcpTransport != null) {
|
|
24
|
+
const mtproxy = proxy.mtproxy.parse(url);
|
|
25
|
+
if (mtproxy) {
|
|
26
|
+
return new MtProxyTcpTransport({
|
|
27
|
+
host: mtproxy.server,
|
|
28
|
+
port: mtproxy.port,
|
|
29
|
+
secret: mtproxy.secret
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (HttpProxyTcpTransport && (obj.protocol === "http:" || obj.protocol === "https:")) {
|
|
34
|
+
return new HttpProxyTcpTransport({
|
|
35
|
+
tls: obj.protocol === "https:",
|
|
36
|
+
host: obj.hostname,
|
|
37
|
+
port: Number(obj.port) || (obj.protocol === "https:" ? 443 : 80),
|
|
38
|
+
user: obj.username,
|
|
39
|
+
password: obj.password
|
|
40
|
+
});
|
|
41
|
+
} else {
|
|
42
|
+
throw new errors.MtArgumentError(`Unsupported proxy protocol: ${obj.protocol}`);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.createProxyTransportFactory = createProxyTransportFactory;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HttpProxySettings, SocksProxySettings } from '@fuman/net';
|
|
2
|
+
import { MtProxySettings } from '../mtproxy/index.js';
|
|
3
|
+
import { TelegramTransport } from './abstract.js';
|
|
4
|
+
export declare function createProxyTransportFactory(options: {
|
|
5
|
+
SocksProxyTcpTransport?: new (options: SocksProxySettings) => TelegramTransport;
|
|
6
|
+
MtProxyTcpTransport?: new (options: MtProxySettings) => TelegramTransport;
|
|
7
|
+
HttpProxyTcpTransport?: new (options: HttpProxySettings & {
|
|
8
|
+
tls?: boolean;
|
|
9
|
+
}) => TelegramTransport;
|
|
10
|
+
}): (url: string) => TelegramTransport;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HttpProxySettings, SocksProxySettings } from '@fuman/net';
|
|
2
|
+
import { MtProxySettings } from '../mtproxy/index.js';
|
|
3
|
+
import { TelegramTransport } from './abstract.js';
|
|
4
|
+
export declare function createProxyTransportFactory(options: {
|
|
5
|
+
SocksProxyTcpTransport?: new (options: SocksProxySettings) => TelegramTransport;
|
|
6
|
+
MtProxyTcpTransport?: new (options: MtProxySettings) => TelegramTransport;
|
|
7
|
+
HttpProxyTcpTransport?: new (options: HttpProxySettings & {
|
|
8
|
+
tls?: boolean;
|
|
9
|
+
}) => TelegramTransport;
|
|
10
|
+
}): (url: string) => TelegramTransport;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { MtArgumentError } from "../../types/errors.js";
|
|
2
|
+
import { mtproxy } from "../../utils/links/proxy.js";
|
|
3
|
+
function createProxyTransportFactory(options) {
|
|
4
|
+
const { SocksProxyTcpTransport, MtProxyTcpTransport, HttpProxyTcpTransport } = options;
|
|
5
|
+
return (url) => {
|
|
6
|
+
const obj = new URL(url);
|
|
7
|
+
if (SocksProxyTcpTransport != null && (obj.protocol === "socks4:" || obj.protocol === "socks5:")) {
|
|
8
|
+
return new SocksProxyTcpTransport({
|
|
9
|
+
version: obj.protocol === "socks4:" ? 4 : 5,
|
|
10
|
+
host: obj.hostname,
|
|
11
|
+
port: Number(obj.port) || 1080,
|
|
12
|
+
user: obj.username,
|
|
13
|
+
password: obj.password
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (MtProxyTcpTransport != null) {
|
|
17
|
+
const mtproxy$1 = mtproxy.parse(url);
|
|
18
|
+
if (mtproxy$1) {
|
|
19
|
+
return new MtProxyTcpTransport({
|
|
20
|
+
host: mtproxy$1.server,
|
|
21
|
+
port: mtproxy$1.port,
|
|
22
|
+
secret: mtproxy$1.secret
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (HttpProxyTcpTransport && (obj.protocol === "http:" || obj.protocol === "https:")) {
|
|
27
|
+
return new HttpProxyTcpTransport({
|
|
28
|
+
tls: obj.protocol === "https:",
|
|
29
|
+
host: obj.hostname,
|
|
30
|
+
port: Number(obj.port) || (obj.protocol === "https:" ? 443 : 80),
|
|
31
|
+
user: obj.username,
|
|
32
|
+
password: obj.password
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
throw new MtArgumentError(`Unsupported proxy protocol: ${obj.protocol}`);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
createProxyTransportFactory
|
|
41
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mtcute/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.28.0",
|
|
5
5
|
"description": "Type-safe library for MTProto (Telegram API)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {},
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"@fuman/net": "0.0.19",
|
|
11
11
|
"@fuman/utils": "0.0.19",
|
|
12
12
|
"@mtcute/file-id": "^0.27.8",
|
|
13
|
-
"@mtcute/tl": "^
|
|
13
|
+
"@mtcute/tl": "^222.0.0",
|
|
14
14
|
"@mtcute/tl-runtime": "^0.24.3",
|
|
15
15
|
"@types/events": "3.0.0",
|
|
16
16
|
"long": "5.2.3"
|
package/utils/binary/compat.cjs
CHANGED
|
@@ -22,6 +22,30 @@ function dropFields(obj, fields) {
|
|
|
22
22
|
}
|
|
23
23
|
return obj;
|
|
24
24
|
}
|
|
25
|
+
function mapCompatStarGiftAttribute(obj) {
|
|
26
|
+
switch (obj._) {
|
|
27
|
+
case "starGiftAttributeBackdrop_layer221":
|
|
28
|
+
return {
|
|
29
|
+
...dropFields(obj, ["rarityPermille"]),
|
|
30
|
+
_: "starGiftAttributeBackdrop",
|
|
31
|
+
rarity: { _: "starGiftAttributeRarity", permille: obj.rarityPermille }
|
|
32
|
+
};
|
|
33
|
+
case "starGiftAttributePattern_layer221":
|
|
34
|
+
return {
|
|
35
|
+
...dropFields(obj, ["rarityPermille"]),
|
|
36
|
+
_: "starGiftAttributePattern",
|
|
37
|
+
rarity: { _: "starGiftAttributeRarity", permille: obj.rarityPermille }
|
|
38
|
+
};
|
|
39
|
+
case "starGiftAttributeModel_layer221":
|
|
40
|
+
return {
|
|
41
|
+
...dropFields(obj, ["rarityPermille"]),
|
|
42
|
+
_: "starGiftAttributeModel",
|
|
43
|
+
rarity: { _: "starGiftAttributeRarity", permille: obj.rarityPermille }
|
|
44
|
+
};
|
|
45
|
+
default:
|
|
46
|
+
return obj;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
25
49
|
function mapCompatStarGift(obj) {
|
|
26
50
|
switch (obj._) {
|
|
27
51
|
case "starGiftUnique_layer197":
|
|
@@ -29,7 +53,8 @@ function mapCompatStarGift(obj) {
|
|
|
29
53
|
...obj,
|
|
30
54
|
_: "starGiftUnique",
|
|
31
55
|
giftId: Long.ZERO,
|
|
32
|
-
ownerId: obj.ownerId ? { _: "peerUser", userId: obj.ownerId } : void 0
|
|
56
|
+
ownerId: obj.ownerId ? { _: "peerUser", userId: obj.ownerId } : void 0,
|
|
57
|
+
attributes: obj.attributes.map(mapCompatStarGiftAttribute)
|
|
33
58
|
};
|
|
34
59
|
case "starGiftUnique_layer198":
|
|
35
60
|
case "starGiftUnique_layer202":
|
|
@@ -37,13 +62,15 @@ function mapCompatStarGift(obj) {
|
|
|
37
62
|
return {
|
|
38
63
|
...obj,
|
|
39
64
|
_: "starGiftUnique",
|
|
40
|
-
giftId: Long.ZERO
|
|
65
|
+
giftId: Long.ZERO,
|
|
66
|
+
attributes: obj.attributes.map(mapCompatStarGiftAttribute)
|
|
41
67
|
};
|
|
42
68
|
case "starGiftUnique_layer210":
|
|
43
69
|
return {
|
|
44
70
|
...obj,
|
|
45
71
|
_: "starGiftUnique",
|
|
46
72
|
giftId: Long.ZERO,
|
|
73
|
+
attributes: obj.attributes.map(mapCompatStarGiftAttribute),
|
|
47
74
|
resellAmount: obj.resellStars ? [{
|
|
48
75
|
_: "starsAmount",
|
|
49
76
|
amount: obj.resellStars,
|
|
@@ -54,11 +81,17 @@ function mapCompatStarGift(obj) {
|
|
|
54
81
|
return {
|
|
55
82
|
...obj,
|
|
56
83
|
_: "starGiftUnique",
|
|
57
|
-
giftId: Long.ZERO
|
|
84
|
+
giftId: Long.ZERO,
|
|
85
|
+
attributes: obj.attributes.map(mapCompatStarGiftAttribute)
|
|
58
86
|
};
|
|
59
87
|
case "starGiftUnique_layer214":
|
|
60
88
|
case "starGiftUnique_layer218":
|
|
61
|
-
|
|
89
|
+
case "starGiftUnique_layer221":
|
|
90
|
+
return {
|
|
91
|
+
...obj,
|
|
92
|
+
_: "starGiftUnique",
|
|
93
|
+
attributes: obj.attributes.map(mapCompatStarGiftAttribute)
|
|
94
|
+
};
|
|
62
95
|
case "starGift_layer202":
|
|
63
96
|
case "starGift_layer206":
|
|
64
97
|
case "starGift_layer209":
|
|
@@ -103,6 +136,7 @@ function mapCompatMessageAction(obj) {
|
|
|
103
136
|
case "messageActionStarGiftUnique_layer197":
|
|
104
137
|
case "messageActionStarGiftUnique_layer202":
|
|
105
138
|
case "messageActionStarGiftUnique_layer214":
|
|
139
|
+
case "messageActionStarGiftUnique_layer221":
|
|
106
140
|
return {
|
|
107
141
|
...obj,
|
|
108
142
|
_: "messageActionStarGiftUnique",
|
|
@@ -189,6 +223,48 @@ function mapCompatMessage(obj) {
|
|
|
189
223
|
return obj;
|
|
190
224
|
}
|
|
191
225
|
}
|
|
226
|
+
function mapCompatKeyboardButton(obj) {
|
|
227
|
+
switch (obj._) {
|
|
228
|
+
case "keyboardButton_layer221":
|
|
229
|
+
return replaceType(obj, "keyboardButton");
|
|
230
|
+
case "keyboardButtonUrl_layer221":
|
|
231
|
+
return replaceType(obj, "keyboardButtonUrl");
|
|
232
|
+
case "keyboardButtonCallback_layer221":
|
|
233
|
+
return replaceType(obj, "keyboardButtonCallback");
|
|
234
|
+
case "keyboardButtonRequestPhone_layer221":
|
|
235
|
+
return replaceType(obj, "keyboardButtonRequestPhone");
|
|
236
|
+
case "keyboardButtonRequestGeoLocation_layer221":
|
|
237
|
+
return replaceType(obj, "keyboardButtonRequestGeoLocation");
|
|
238
|
+
case "keyboardButtonSwitchInline_layer221":
|
|
239
|
+
return replaceType(obj, "keyboardButtonSwitchInline");
|
|
240
|
+
case "keyboardButtonGame_layer221":
|
|
241
|
+
return replaceType(obj, "keyboardButtonGame");
|
|
242
|
+
case "keyboardButtonBuy_layer221":
|
|
243
|
+
return replaceType(obj, "keyboardButtonBuy");
|
|
244
|
+
case "keyboardButtonUrlAuth_layer221":
|
|
245
|
+
return replaceType(obj, "keyboardButtonUrlAuth");
|
|
246
|
+
case "inputKeyboardButtonUrlAuth_layer221":
|
|
247
|
+
return replaceType(obj, "inputKeyboardButtonUrlAuth");
|
|
248
|
+
case "keyboardButtonRequestPoll_layer221":
|
|
249
|
+
return replaceType(obj, "keyboardButtonRequestPoll");
|
|
250
|
+
case "inputKeyboardButtonUserProfile_layer221":
|
|
251
|
+
return replaceType(obj, "inputKeyboardButtonUserProfile");
|
|
252
|
+
case "keyboardButtonUserProfile_layer221":
|
|
253
|
+
return replaceType(obj, "keyboardButtonUserProfile");
|
|
254
|
+
case "keyboardButtonWebView_layer221":
|
|
255
|
+
return replaceType(obj, "keyboardButtonWebView");
|
|
256
|
+
case "keyboardButtonSimpleWebView_layer221":
|
|
257
|
+
return replaceType(obj, "keyboardButtonSimpleWebView");
|
|
258
|
+
case "keyboardButtonRequestPeer_layer221":
|
|
259
|
+
return replaceType(obj, "keyboardButtonRequestPeer");
|
|
260
|
+
case "inputKeyboardButtonRequestPeer_layer221":
|
|
261
|
+
return replaceType(obj, "inputKeyboardButtonRequestPeer");
|
|
262
|
+
case "keyboardButtonCopy_layer221":
|
|
263
|
+
return replaceType(obj, "keyboardButtonCopy");
|
|
264
|
+
default:
|
|
265
|
+
return obj;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
192
268
|
function mapCompatObject(obj) {
|
|
193
269
|
switch (obj._) {
|
|
194
270
|
case "starGiftUnique_layer197":
|
|
@@ -199,6 +275,7 @@ function mapCompatObject(obj) {
|
|
|
199
275
|
case "starGiftUnique_layer211":
|
|
200
276
|
case "starGiftUnique_layer214":
|
|
201
277
|
case "starGiftUnique_layer218":
|
|
278
|
+
case "starGiftUnique_layer221":
|
|
202
279
|
case "starGift_layer202":
|
|
203
280
|
case "starGift_layer206":
|
|
204
281
|
case "starGift_layer209":
|
|
@@ -227,6 +304,7 @@ function mapCompatObject(obj) {
|
|
|
227
304
|
case "messageActionGiftPremium_layer216":
|
|
228
305
|
case "messageActionStarGift_layer216":
|
|
229
306
|
case "messageActionStarGift_layer218":
|
|
307
|
+
case "messageActionStarGiftUnique_layer221":
|
|
230
308
|
return mapCompatMessageAction(obj);
|
|
231
309
|
case "userFull_layer199":
|
|
232
310
|
return replaceType(dropFields(obj, ["premiumGifts"]), "userFull");
|
|
@@ -286,6 +364,29 @@ function mapCompatObject(obj) {
|
|
|
286
364
|
gift: mapCompatStarGift(obj.gift),
|
|
287
365
|
endDate: obj.endDate
|
|
288
366
|
};
|
|
367
|
+
case "starGiftAttributeBackdrop_layer221":
|
|
368
|
+
case "starGiftAttributePattern_layer221":
|
|
369
|
+
case "starGiftAttributeModel_layer221":
|
|
370
|
+
return mapCompatStarGiftAttribute(obj);
|
|
371
|
+
case "keyboardButton_layer221":
|
|
372
|
+
case "keyboardButtonUrl_layer221":
|
|
373
|
+
case "keyboardButtonCallback_layer221":
|
|
374
|
+
case "keyboardButtonRequestPhone_layer221":
|
|
375
|
+
case "keyboardButtonRequestGeoLocation_layer221":
|
|
376
|
+
case "keyboardButtonSwitchInline_layer221":
|
|
377
|
+
case "keyboardButtonGame_layer221":
|
|
378
|
+
case "keyboardButtonBuy_layer221":
|
|
379
|
+
case "keyboardButtonUrlAuth_layer221":
|
|
380
|
+
case "inputKeyboardButtonUrlAuth_layer221":
|
|
381
|
+
case "keyboardButtonRequestPoll_layer221":
|
|
382
|
+
case "inputKeyboardButtonUserProfile_layer221":
|
|
383
|
+
case "keyboardButtonUserProfile_layer221":
|
|
384
|
+
case "keyboardButtonWebView_layer221":
|
|
385
|
+
case "keyboardButtonSimpleWebView_layer221":
|
|
386
|
+
case "keyboardButtonRequestPeer_layer221":
|
|
387
|
+
case "inputKeyboardButtonRequestPeer_layer221":
|
|
388
|
+
case "keyboardButtonCopy_layer221":
|
|
389
|
+
return mapCompatKeyboardButton(obj);
|
|
289
390
|
default:
|
|
290
391
|
return obj;
|
|
291
392
|
}
|