@mtcute/core 0.22.3 → 0.23.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 +1 -1
- package/client.js +1 -1
- package/highlevel/base.cjs +1 -0
- package/highlevel/base.js +1 -0
- package/highlevel/client.d.cts +7 -3
- package/highlevel/client.d.ts +7 -3
- package/highlevel/methods/auth/send-code.cjs +8 -2
- package/highlevel/methods/auth/send-code.d.cts +4 -2
- package/highlevel/methods/auth/send-code.d.ts +4 -2
- package/highlevel/methods/auth/send-code.js +8 -2
- package/highlevel/methods/auth/start.cjs +6 -1
- package/highlevel/methods/auth/start.d.cts +1 -1
- package/highlevel/methods/auth/start.d.ts +1 -1
- package/highlevel/methods/auth/start.js +6 -1
- package/highlevel/methods/chats/open-chat.cjs +1 -1
- package/highlevel/methods/chats/open-chat.js +1 -1
- package/highlevel/methods/dialogs/find-dialogs.cjs +3 -1
- package/highlevel/methods/dialogs/find-dialogs.js +3 -1
- package/highlevel/methods/dialogs/get-peer-dialogs.cjs +49 -11
- package/highlevel/methods/dialogs/get-peer-dialogs.d.cts +1 -1
- package/highlevel/methods/dialogs/get-peer-dialogs.d.ts +1 -1
- package/highlevel/methods/dialogs/get-peer-dialogs.js +49 -11
- package/highlevel/methods/files/normalize-input-file.d.cts +1 -0
- package/highlevel/methods/files/normalize-input-file.d.ts +1 -0
- package/highlevel/methods/files/normalize-input-media.cjs +13 -6
- package/highlevel/methods/files/normalize-input-media.d.cts +1 -0
- package/highlevel/methods/files/normalize-input-media.d.ts +1 -0
- package/highlevel/methods/files/normalize-input-media.js +13 -6
- package/highlevel/methods/files/upload-file.cjs +6 -3
- package/highlevel/methods/files/upload-file.d.cts +1 -0
- package/highlevel/methods/files/upload-file.d.ts +1 -0
- package/highlevel/methods/files/upload-file.js +6 -3
- package/highlevel/methods/messages/send-common.d.cts +1 -0
- package/highlevel/methods/messages/send-common.d.ts +1 -0
- package/highlevel/methods/messages/send-media-group.cjs +3 -2
- package/highlevel/methods/messages/send-media-group.js +3 -2
- package/highlevel/methods/messages/send-media.cjs +3 -2
- package/highlevel/methods/messages/send-media.js +3 -2
- package/highlevel/methods/messages/send-text.cjs +1 -1
- package/highlevel/methods/messages/send-text.js +1 -1
- package/highlevel/methods/users/resolve-peer-many.cjs +8 -43
- package/highlevel/methods/users/resolve-peer-many.js +9 -44
- package/highlevel/storage/service/peers.cjs +37 -9
- package/highlevel/storage/service/peers.d.cts +4 -0
- package/highlevel/storage/service/peers.d.ts +4 -0
- package/highlevel/storage/service/peers.js +38 -10
- package/highlevel/storage/storage.cjs +3 -0
- package/highlevel/storage/storage.d.cts +1 -0
- package/highlevel/storage/storage.d.ts +1 -0
- package/highlevel/storage/storage.js +3 -0
- package/highlevel/types/conversation.cjs +3 -4
- package/highlevel/types/conversation.js +3 -4
- package/highlevel/types/messages/message-action.cjs +11 -0
- package/highlevel/types/messages/message-action.d.cts +15 -1
- package/highlevel/types/messages/message-action.d.ts +15 -1
- package/highlevel/types/messages/message-action.js +11 -0
- package/highlevel/types/peers/full-user.cjs +8 -0
- package/highlevel/types/peers/full-user.d.cts +4 -0
- package/highlevel/types/peers/full-user.d.ts +4 -0
- package/highlevel/types/peers/full-user.js +8 -0
- package/highlevel/types/peers/peers-index.cjs +10 -0
- package/highlevel/types/peers/peers-index.d.cts +1 -0
- package/highlevel/types/peers/peers-index.d.ts +1 -0
- package/highlevel/types/peers/peers-index.js +10 -0
- package/highlevel/types/premium/business-connection.cjs +3 -3
- package/highlevel/types/premium/business-connection.d.cts +2 -2
- package/highlevel/types/premium/business-connection.d.ts +2 -2
- package/highlevel/types/premium/business-connection.js +3 -3
- package/highlevel/types/premium/saved-star-gift.cjs +2 -2
- package/highlevel/types/premium/saved-star-gift.d.cts +2 -2
- package/highlevel/types/premium/saved-star-gift.d.ts +2 -2
- package/highlevel/types/premium/saved-star-gift.js +2 -2
- package/highlevel/types/premium/stars-gift-unique.cjs +11 -1
- package/highlevel/types/premium/stars-gift-unique.d.cts +7 -1
- package/highlevel/types/premium/stars-gift-unique.d.ts +7 -1
- package/highlevel/types/premium/stars-gift-unique.js +11 -1
- package/highlevel/types/premium/stars-transaction.cjs +4 -0
- package/highlevel/types/premium/stars-transaction.d.cts +2 -0
- package/highlevel/types/premium/stars-transaction.d.ts +2 -0
- package/highlevel/types/premium/stars-transaction.js +4 -0
- package/highlevel/worker/storage.cjs +4 -0
- package/highlevel/worker/storage.d.cts +2 -0
- package/highlevel/worker/storage.d.ts +2 -0
- package/highlevel/worker/storage.js +4 -0
- package/network/middlewares/flood-waiter.cjs +18 -2
- package/network/middlewares/flood-waiter.d.cts +9 -2
- package/network/middlewares/flood-waiter.d.ts +9 -2
- package/network/middlewares/flood-waiter.js +18 -2
- package/network/network-manager.cjs +1 -1
- package/network/network-manager.d.cts +1 -1
- package/network/network-manager.d.ts +1 -1
- package/network/network-manager.js +1 -1
- package/network/session-connection.cjs +3 -1
- package/network/session-connection.js +3 -1
- package/package.json +7 -7
- package/utils/binary/compat.cjs +2 -0
- package/utils/binary/compat.js +2 -0
- package/utils/early-timer.cjs +7 -2
- package/utils/early-timer.js +7 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RpcCallMiddleware } from '../network-manager.js';
|
|
1
|
+
import { RpcCallMiddleware, RpcCallMiddlewareContext } from '../network-manager.js';
|
|
2
2
|
export interface FloodWaiterOptions {
|
|
3
3
|
/**
|
|
4
4
|
* Maximum number of ms to wait when a FLOOD_WAIT_X
|
|
@@ -30,8 +30,15 @@ export interface FloodWaiterOptions {
|
|
|
30
30
|
* If the stored wait time is less than this value,
|
|
31
31
|
* the request will not be delayed
|
|
32
32
|
*
|
|
33
|
-
* @default
|
|
33
|
+
* @default 2_000
|
|
34
34
|
*/
|
|
35
35
|
minStoredWait?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Function that will be called before we are about to wait for `seconds`
|
|
38
|
+
* seconds before retrying the request.
|
|
39
|
+
*
|
|
40
|
+
* @default print a warning to the console, except some methods that often result in flood waits
|
|
41
|
+
*/
|
|
42
|
+
onBeforeWait?: (ctx: RpcCallMiddlewareContext, seconds: number) => void;
|
|
36
43
|
}
|
|
37
44
|
export declare function floodWaiter(options: FloodWaiterOptions): RpcCallMiddleware;
|
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import { combineAbortSignals } from "../../utils/abort-signal.js";
|
|
2
2
|
import { sleepWithAbort } from "../../utils/misc-utils.js";
|
|
3
3
|
import { isTlRpcError } from "../../utils/type-assertions.js";
|
|
4
|
+
const SILENTLY_SLEEP_METHODS = /* @__PURE__ */ new Set([
|
|
5
|
+
"upload.getFile",
|
|
6
|
+
"upload.saveFilePart",
|
|
7
|
+
"upload.saveBigFilePart",
|
|
8
|
+
"updates.getDifference",
|
|
9
|
+
"updates.getChannelDifference"
|
|
10
|
+
]);
|
|
11
|
+
const SILENTLY_SLEEP_THRESHOLD = 5;
|
|
4
12
|
function floodWaiter(options) {
|
|
5
|
-
const {
|
|
13
|
+
const {
|
|
14
|
+
maxWait = 1e4,
|
|
15
|
+
maxRetries = 5,
|
|
16
|
+
store = true,
|
|
17
|
+
minStoredWait = 2e3,
|
|
18
|
+
onBeforeWait
|
|
19
|
+
} = options;
|
|
6
20
|
const storage = /* @__PURE__ */ new Map();
|
|
7
21
|
return async (ctx, next) => {
|
|
8
22
|
const method = ctx.request._;
|
|
@@ -45,7 +59,9 @@ function floodWaiter(options) {
|
|
|
45
59
|
}
|
|
46
60
|
const ms = seconds * 1e3;
|
|
47
61
|
if (ms <= floodSleepThreshold) {
|
|
48
|
-
if (
|
|
62
|
+
if (onBeforeWait) {
|
|
63
|
+
onBeforeWait(ctx, seconds);
|
|
64
|
+
} else if (!(seconds < SILENTLY_SLEEP_THRESHOLD && SILENTLY_SLEEP_METHODS.has(method))) {
|
|
49
65
|
ctx.manager._log.warn("%s resulted in a flood wait, will retry in %d seconds", method, seconds);
|
|
50
66
|
}
|
|
51
67
|
await sleepWithAbort(
|
|
@@ -32,7 +32,7 @@ export interface NetworkManagerParams {
|
|
|
32
32
|
writerMap: TlWriterMap;
|
|
33
33
|
isPremium: boolean;
|
|
34
34
|
emitError: (err: Error) => void;
|
|
35
|
-
onUpdate: (upd: tl.TypeUpdates) => void;
|
|
35
|
+
onUpdate: (upd: tl.TypeUpdates, fromClient: boolean) => void;
|
|
36
36
|
onUsable: () => void;
|
|
37
37
|
onConnecting: () => void;
|
|
38
38
|
onNetworkChanged: (connected: boolean) => void;
|
|
@@ -32,7 +32,7 @@ export interface NetworkManagerParams {
|
|
|
32
32
|
writerMap: TlWriterMap;
|
|
33
33
|
isPremium: boolean;
|
|
34
34
|
emitError: (err: Error) => void;
|
|
35
|
-
onUpdate: (upd: tl.TypeUpdates) => void;
|
|
35
|
+
onUpdate: (upd: tl.TypeUpdates, fromClient: boolean) => void;
|
|
36
36
|
onUsable: () => void;
|
|
37
37
|
onConnecting: () => void;
|
|
38
38
|
onNetworkChanged: (connected: boolean) => void;
|
|
@@ -1151,7 +1151,9 @@ class SessionConnection extends persistentConnection.PersistentConnection {
|
|
|
1151
1151
|
if (now - this._session.lastPingTime > this._pingInterval) {
|
|
1152
1152
|
if (!this._session.lastPingMsgId.isZero()) {
|
|
1153
1153
|
this.log.warn("didn't receive pong for previous ping (msg_id = %l). are we offline?", this._session.lastPingMsgId);
|
|
1154
|
-
this.
|
|
1154
|
+
if (!this._disconnectedManually) {
|
|
1155
|
+
this._resetSession("ping timeout");
|
|
1156
|
+
}
|
|
1155
1157
|
return;
|
|
1156
1158
|
}
|
|
1157
1159
|
pingId = longUtils.randomLong();
|
|
@@ -1144,7 +1144,9 @@ class SessionConnection extends PersistentConnection {
|
|
|
1144
1144
|
if (now - this._session.lastPingTime > this._pingInterval) {
|
|
1145
1145
|
if (!this._session.lastPingMsgId.isZero()) {
|
|
1146
1146
|
this.log.warn("didn't receive pong for previous ping (msg_id = %l). are we offline?", this._session.lastPingMsgId);
|
|
1147
|
-
this.
|
|
1147
|
+
if (!this._disconnectedManually) {
|
|
1148
|
+
this._resetSession("ping timeout");
|
|
1149
|
+
}
|
|
1148
1150
|
return;
|
|
1149
1151
|
}
|
|
1150
1152
|
pingId = randomLong();
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mtcute/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.23.0",
|
|
5
5
|
"description": "Type-safe library for MTProto (Telegram API)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@fuman/io": "0.0.
|
|
10
|
-
"@fuman/net": "0.0.
|
|
11
|
-
"@fuman/utils": "0.0.
|
|
12
|
-
"@mtcute/file-id": "^0.
|
|
13
|
-
"@mtcute/tl": "^
|
|
14
|
-
"@mtcute/tl-runtime": "^0.
|
|
9
|
+
"@fuman/io": "0.0.14",
|
|
10
|
+
"@fuman/net": "0.0.14",
|
|
11
|
+
"@fuman/utils": "0.0.14",
|
|
12
|
+
"@mtcute/file-id": "^0.23.0",
|
|
13
|
+
"@mtcute/tl": "^201.0.0",
|
|
14
|
+
"@mtcute/tl-runtime": "^0.23.0",
|
|
15
15
|
"@types/events": "3.0.0",
|
|
16
16
|
"long": "5.2.3"
|
|
17
17
|
},
|
package/utils/binary/compat.cjs
CHANGED
|
@@ -89,6 +89,8 @@ function mapCompatObject(obj) {
|
|
|
89
89
|
return mapCompatMessageAction(obj);
|
|
90
90
|
case "userFull_layer199":
|
|
91
91
|
return replaceType(dropFields(obj, ["premiumGifts"]), "userFull");
|
|
92
|
+
case "userFull_layer200":
|
|
93
|
+
return replaceType(obj, "userFull");
|
|
92
94
|
case "user_layer199":
|
|
93
95
|
return {
|
|
94
96
|
...obj,
|
package/utils/binary/compat.js
CHANGED
|
@@ -82,6 +82,8 @@ function mapCompatObject(obj) {
|
|
|
82
82
|
return mapCompatMessageAction(obj);
|
|
83
83
|
case "userFull_layer199":
|
|
84
84
|
return replaceType(dropFields(obj, ["premiumGifts"]), "userFull");
|
|
85
|
+
case "userFull_layer200":
|
|
86
|
+
return replaceType(obj, "userFull");
|
|
85
87
|
case "user_layer199":
|
|
86
88
|
return {
|
|
87
89
|
...obj,
|
package/utils/early-timer.cjs
CHANGED
|
@@ -45,8 +45,13 @@ class EarlyTimer {
|
|
|
45
45
|
emitBefore(ts) {
|
|
46
46
|
if (!this._timeoutTs || ts < this._timeoutTs) {
|
|
47
47
|
this.reset();
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
const diff = ts - Date.now();
|
|
49
|
+
if (diff > 0) {
|
|
50
|
+
this._timeout = utils.timers.setTimeout(this.emitNow, diff);
|
|
51
|
+
this._timeoutTs = ts;
|
|
52
|
+
} else {
|
|
53
|
+
this._handler();
|
|
54
|
+
}
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
57
|
/**
|
package/utils/early-timer.js
CHANGED
|
@@ -38,8 +38,13 @@ class EarlyTimer {
|
|
|
38
38
|
emitBefore(ts) {
|
|
39
39
|
if (!this._timeoutTs || ts < this._timeoutTs) {
|
|
40
40
|
this.reset();
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const diff = ts - Date.now();
|
|
42
|
+
if (diff > 0) {
|
|
43
|
+
this._timeout = timers.setTimeout(this.emitNow, diff);
|
|
44
|
+
this._timeoutTs = ts;
|
|
45
|
+
} else {
|
|
46
|
+
this._handler();
|
|
47
|
+
}
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
/**
|