@mtcute/core 0.29.4 → 0.29.5

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 (64) hide show
  1. package/highlevel/base.cjs +0 -1
  2. package/highlevel/base.js +0 -1
  3. package/highlevel/methods/chats/get-creator-after-leave.cjs +4 -14
  4. package/highlevel/methods/chats/get-creator-after-leave.js +5 -15
  5. package/highlevel/methods/files/normalize-input-media.cjs +16 -14
  6. package/highlevel/methods/files/normalize-input-media.js +16 -14
  7. package/highlevel/methods/messages/close-poll.cjs +2 -1
  8. package/highlevel/methods/messages/close-poll.js +2 -1
  9. package/highlevel/methods/messages/send-vote.cjs +3 -1
  10. package/highlevel/methods/messages/send-vote.js +4 -2
  11. package/highlevel/storage/service/peers.cjs +1 -0
  12. package/highlevel/storage/service/peers.js +1 -0
  13. package/highlevel/types/media/input-media/types.d.cts +10 -13
  14. package/highlevel/types/media/input-media/types.d.ts +10 -13
  15. package/highlevel/types/media/poll.cjs +4 -1
  16. package/highlevel/types/media/poll.d.cts +2 -2
  17. package/highlevel/types/media/poll.d.ts +2 -2
  18. package/highlevel/types/media/poll.js +4 -1
  19. package/highlevel/types/messages/dialog.cjs +4 -0
  20. package/highlevel/types/messages/dialog.d.cts +2 -0
  21. package/highlevel/types/messages/dialog.d.ts +2 -0
  22. package/highlevel/types/messages/dialog.js +4 -0
  23. package/highlevel/types/messages/message-action.cjs +18 -0
  24. package/highlevel/types/messages/message-action.d.cts +19 -1
  25. package/highlevel/types/messages/message-action.d.ts +19 -1
  26. package/highlevel/types/messages/message-action.js +18 -0
  27. package/highlevel/types/peers/forum-topic.cjs +4 -0
  28. package/highlevel/types/peers/forum-topic.d.cts +2 -0
  29. package/highlevel/types/peers/forum-topic.d.ts +2 -0
  30. package/highlevel/types/peers/forum-topic.js +4 -0
  31. package/highlevel/types/peers/full-user.cjs +8 -0
  32. package/highlevel/types/peers/full-user.d.cts +4 -0
  33. package/highlevel/types/peers/full-user.d.ts +4 -0
  34. package/highlevel/types/peers/full-user.js +8 -0
  35. package/highlevel/types/peers/user.cjs +4 -0
  36. package/highlevel/types/peers/user.d.cts +2 -0
  37. package/highlevel/types/peers/user.d.ts +2 -0
  38. package/highlevel/types/peers/user.js +4 -0
  39. package/highlevel/types/updates/poll-update.cjs +8 -2
  40. package/highlevel/types/updates/poll-update.js +8 -2
  41. package/highlevel/updates/manager.cjs +7 -0
  42. package/highlevel/updates/manager.js +7 -0
  43. package/highlevel/worker/worker.cjs +6 -1
  44. package/highlevel/worker/worker.d.cts +2 -1
  45. package/highlevel/worker/worker.d.ts +2 -1
  46. package/highlevel/worker/worker.js +6 -1
  47. package/network/middlewares/flood-waiter.cjs +2 -1
  48. package/network/middlewares/flood-waiter.js +2 -1
  49. package/network/network-manager.cjs +1 -1
  50. package/network/network-manager.js +1 -1
  51. package/package.json +1 -1
  52. package/tl/api-schema.json +1 -1
  53. package/tl/binary/reader.cjs +86 -39
  54. package/tl/binary/reader.js +86 -39
  55. package/tl/binary/writer.cjs +308 -32
  56. package/tl/binary/writer.js +308 -32
  57. package/tl/compat/reader.cjs +34 -0
  58. package/tl/compat/reader.js +34 -0
  59. package/tl/index.d.cts +295 -25
  60. package/tl/index.d.ts +295 -25
  61. package/tl/inner-tl.cjs +16 -8
  62. package/tl/inner-tl.js +16 -8
  63. package/utils/binary/compat.cjs +41 -0
  64. package/utils/binary/compat.js +41 -0
@@ -213,6 +213,14 @@ class FullUser extends user.User {
213
213
  get contentProtectionIncoming() {
214
214
  return this.full.noforwardsPeerEnabled;
215
215
  }
216
+ /** Whether this user has been flagged by the server as a security risk due to using an unofficial app */
217
+ get unofficialSecurityRisk() {
218
+ return this.full.unofficialSecurityRisk;
219
+ }
220
+ /** Bot that manages this bot, if any */
221
+ get botManager() {
222
+ return this.full.botManagerId ? new user.User(this.peers.user(this.full.botManagerId)) : null;
223
+ }
216
224
  /** Whether the "Gifts" tab should be shown */
217
225
  get showGifts() {
218
226
  return this.full.displayGiftsButton;
@@ -123,6 +123,10 @@ export declare class FullUser extends User {
123
123
  * i.e. our incoming messages from this user will be `noforwards`.
124
124
  */
125
125
  get contentProtectionIncoming(): boolean;
126
+ /** Whether this user has been flagged by the server as a security risk due to using an unofficial app */
127
+ get unofficialSecurityRisk(): boolean;
128
+ /** Bot that manages this bot, if any */
129
+ get botManager(): User | null;
126
130
  /** Whether the "Gifts" tab should be shown */
127
131
  get showGifts(): boolean;
128
132
  /** Information about the user's gift receive settings */
@@ -123,6 +123,10 @@ export declare class FullUser extends User {
123
123
  * i.e. our incoming messages from this user will be `noforwards`.
124
124
  */
125
125
  get contentProtectionIncoming(): boolean;
126
+ /** Whether this user has been flagged by the server as a security risk due to using an unofficial app */
127
+ get unofficialSecurityRisk(): boolean;
128
+ /** Bot that manages this bot, if any */
129
+ get botManager(): User | null;
126
130
  /** Whether the "Gifts" tab should be shown */
127
131
  get showGifts(): boolean;
128
132
  /** Information about the user's gift receive settings */
@@ -206,6 +206,14 @@ class FullUser extends User$2 {
206
206
  get contentProtectionIncoming() {
207
207
  return this.full.noforwardsPeerEnabled;
208
208
  }
209
+ /** Whether this user has been flagged by the server as a security risk due to using an unofficial app */
210
+ get unofficialSecurityRisk() {
211
+ return this.full.unofficialSecurityRisk;
212
+ }
213
+ /** Bot that manages this bot, if any */
214
+ get botManager() {
215
+ return this.full.botManagerId ? new User$2(this.peers.user(this.full.botManagerId)) : null;
216
+ }
209
217
  /** Whether the "Gifts" tab should be shown */
210
218
  get showGifts() {
211
219
  return this.full.displayGiftsButton;
@@ -114,6 +114,10 @@ class User {
114
114
  get canBotManageForumTopics() {
115
115
  return this.raw.botForumCanManageTopics;
116
116
  }
117
+ /** Whether this bot can manage other bots */
118
+ get canBotManageBots() {
119
+ return this.raw.botCanManageBots;
120
+ }
117
121
  /** Whether this user has been verified by Telegram */
118
122
  get isVerified() {
119
123
  return this.raw.verified;
@@ -85,6 +85,8 @@ export declare class User {
85
85
  /** Whether this bot is forum-like (i.e. supports threads) */
86
86
  get isBotWithForumView(): boolean;
87
87
  get canBotManageForumTopics(): boolean;
88
+ /** Whether this bot can manage other bots */
89
+ get canBotManageBots(): boolean;
88
90
  /** Whether this user has been verified by Telegram */
89
91
  get isVerified(): boolean;
90
92
  /**
@@ -85,6 +85,8 @@ export declare class User {
85
85
  /** Whether this bot is forum-like (i.e. supports threads) */
86
86
  get isBotWithForumView(): boolean;
87
87
  get canBotManageForumTopics(): boolean;
88
+ /** Whether this bot can manage other bots */
89
+ get canBotManageBots(): boolean;
88
90
  /** Whether this user has been verified by Telegram */
89
91
  get isVerified(): boolean;
90
92
  /**
@@ -107,6 +107,10 @@ class User {
107
107
  get canBotManageForumTopics() {
108
108
  return this.raw.botForumCanManageTopics;
109
109
  }
110
+ /** Whether this bot can manage other bots */
111
+ get canBotManageBots() {
112
+ return this.raw.botCanManageBots;
113
+ }
110
114
  /** Whether this user has been verified by Telegram */
111
115
  get isVerified() {
112
116
  return this.raw.verified;
@@ -5,6 +5,7 @@ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WAR
5
5
  }
6
6
  "use strict";
7
7
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ const Long = require("long");
8
9
  const memoize = require("../../utils/memoize.cjs");
9
10
  const poll = require("../media/poll.cjs");
10
11
  const inspectable = require("../../utils/inspectable.cjs");
@@ -49,9 +50,14 @@ class PollUpdate {
49
50
  question: { _: "textWithEntities", text: "", entities: [] },
50
51
  answers: this.raw.results.results?.map((res) => ({
51
52
  _: "pollAnswer",
52
- text: { _: "textWithEntities", text: "", entities: [] },
53
+ text: {
54
+ _: "textWithEntities",
55
+ text: "",
56
+ entities: []
57
+ },
53
58
  option: res.option
54
- })) ?? []
59
+ })) ?? [],
60
+ hash: Long.ZERO
55
61
  };
56
62
  }
57
63
  return new poll.Poll(poll$1, this._peers, this.raw.results);
@@ -1,3 +1,4 @@
1
+ import Long from "long";
1
2
  import { memoizeGetters } from "../../utils/memoize.js";
2
3
  import { Poll as Poll$2 } from "../media/poll.js";
3
4
  import { makeInspectable } from "../../utils/inspectable.js";
@@ -42,9 +43,14 @@ class PollUpdate {
42
43
  question: { _: "textWithEntities", text: "", entities: [] },
43
44
  answers: this.raw.results.results?.map((res) => ({
44
45
  _: "pollAnswer",
45
- text: { _: "textWithEntities", text: "", entities: [] },
46
+ text: {
47
+ _: "textWithEntities",
48
+ text: "",
49
+ entities: []
50
+ },
46
51
  option: res.option
47
- })) ?? []
52
+ })) ?? [],
53
+ hash: Long.ZERO
48
54
  };
49
55
  }
50
56
  return new Poll$2(poll, this._peers, this.raw.results);
@@ -29,6 +29,7 @@ class UpdatesManager {
29
29
  throw new errors.MtArgumentError("Updates must be enabled to use updates manager");
30
30
  }
31
31
  this._onKeepAlive = this._onKeepAlive.bind(this);
32
+ this.handleUpdate = this.handleUpdate.bind(this);
32
33
  this.postponedTimer.onTimeout(() => {
33
34
  this.hasTimedoutPostponed = true;
34
35
  this.updatesLoopCv.notify();
@@ -140,6 +141,7 @@ class UpdatesManager {
140
141
  await this._fetchUpdatesState();
141
142
  }
142
143
  this.updatesLoopActive = true;
144
+ this.client.onServerUpdate.add(this.handleUpdate);
143
145
  utils.timers.clearInterval(this.keepAliveInterval);
144
146
  this.keepAliveInterval = utils.timers.setInterval(this._onKeepAlive, KEEP_ALIVE_INTERVAL);
145
147
  this._loop().catch((err) => this.client.onError.emit(utils.unknownToError(err)));
@@ -161,12 +163,16 @@ class UpdatesManager {
161
163
  }
162
164
  this.channelDiffTimeouts.clear();
163
165
  this.updatesLoopActive = false;
166
+ this.client.onServerUpdate.remove(this.handleUpdate);
164
167
  this.pendingUpdateContainers.clear();
165
168
  this.pendingUnorderedUpdates.clear();
166
169
  this.pendingPtsUpdates.clear();
167
170
  this.pendingQtsUpdates.clear();
168
171
  this.pendingPtsUpdatesPostponed.clear();
169
172
  this.pendingQtsUpdatesPostponed.clear();
173
+ this.noDispatchMsg.clear();
174
+ this.noDispatchPts.clear();
175
+ this.noDispatchQts.clear();
170
176
  this.postponedTimer.reset();
171
177
  this.updatesLoopCv.notify();
172
178
  }
@@ -188,6 +194,7 @@ class UpdatesManager {
188
194
  this.handleUpdate(UPDATES_TOO_LONG);
189
195
  }
190
196
  handleClientUpdate(update, noDispatch = true) {
197
+ if (!this.updatesLoopActive) return;
191
198
  if (noDispatch && this.noDispatchEnabled) {
192
199
  this._addToNoDispatchIndex(update);
193
200
  }
@@ -22,6 +22,7 @@ class UpdatesManager {
22
22
  throw new MtArgumentError("Updates must be enabled to use updates manager");
23
23
  }
24
24
  this._onKeepAlive = this._onKeepAlive.bind(this);
25
+ this.handleUpdate = this.handleUpdate.bind(this);
25
26
  this.postponedTimer.onTimeout(() => {
26
27
  this.hasTimedoutPostponed = true;
27
28
  this.updatesLoopCv.notify();
@@ -133,6 +134,7 @@ class UpdatesManager {
133
134
  await this._fetchUpdatesState();
134
135
  }
135
136
  this.updatesLoopActive = true;
137
+ this.client.onServerUpdate.add(this.handleUpdate);
136
138
  timers.clearInterval(this.keepAliveInterval);
137
139
  this.keepAliveInterval = timers.setInterval(this._onKeepAlive, KEEP_ALIVE_INTERVAL);
138
140
  this._loop().catch((err) => this.client.onError.emit(unknownToError(err)));
@@ -154,12 +156,16 @@ class UpdatesManager {
154
156
  }
155
157
  this.channelDiffTimeouts.clear();
156
158
  this.updatesLoopActive = false;
159
+ this.client.onServerUpdate.remove(this.handleUpdate);
157
160
  this.pendingUpdateContainers.clear();
158
161
  this.pendingUnorderedUpdates.clear();
159
162
  this.pendingPtsUpdates.clear();
160
163
  this.pendingQtsUpdates.clear();
161
164
  this.pendingPtsUpdatesPostponed.clear();
162
165
  this.pendingQtsUpdatesPostponed.clear();
166
+ this.noDispatchMsg.clear();
167
+ this.noDispatchPts.clear();
168
+ this.noDispatchQts.clear();
163
169
  this.postponedTimer.reset();
164
170
  this.updatesLoopCv.notify();
165
171
  }
@@ -181,6 +187,7 @@ class UpdatesManager {
181
187
  this.handleUpdate(UPDATES_TOO_LONG);
182
188
  }
183
189
  handleClientUpdate(update, noDispatch = true) {
190
+ if (!this.updatesLoopActive) return;
184
191
  if (noDispatch && this.noDispatchEnabled) {
185
192
  this._addToNoDispatchIndex(update);
186
193
  }
@@ -185,7 +185,12 @@ class TelegramWorker {
185
185
  }
186
186
  if (!wasActive && !hadLastSeen && !pending) return;
187
187
  if (this.activeConnections.size !== 0) return;
188
- switch (this.params.onLastDisconnected ?? "nothing") {
188
+ let onLastDisconnected = this.params.onLastDisconnected ?? "nothing";
189
+ if (typeof onLastDisconnected === "function") {
190
+ onLastDisconnected = onLastDisconnected();
191
+ return;
192
+ }
193
+ switch (onLastDisconnected) {
189
194
  case "nothing":
190
195
  return;
191
196
  case "disconnect":
@@ -10,10 +10,11 @@ export interface TelegramWorkerOptions<T extends WorkerCustomMethods> {
10
10
  * - `destroy`: destroy the client, terminating the worker
11
11
  * - `disconnect`: disconnect the client, but keep the worker running until `forceDestroy` is called
12
12
  * - `nothing`: do nothing, lifecycle is managed manually
13
+ * - function: call this function when the last connection is closed, then execute the action returned by the function
13
14
  *
14
15
  * @default 'nothing'
15
16
  */
16
- onLastDisconnected?: 'destroy' | 'disconnect' | 'nothing';
17
+ onLastDisconnected?: 'destroy' | 'disconnect' | 'nothing' | (() => 'destroy' | 'disconnect' | 'nothing');
17
18
  /** additional custom methods to expose */
18
19
  customMethods?: T;
19
20
  }
@@ -10,10 +10,11 @@ export interface TelegramWorkerOptions<T extends WorkerCustomMethods> {
10
10
  * - `destroy`: destroy the client, terminating the worker
11
11
  * - `disconnect`: disconnect the client, but keep the worker running until `forceDestroy` is called
12
12
  * - `nothing`: do nothing, lifecycle is managed manually
13
+ * - function: call this function when the last connection is closed, then execute the action returned by the function
13
14
  *
14
15
  * @default 'nothing'
15
16
  */
16
- onLastDisconnected?: 'destroy' | 'disconnect' | 'nothing';
17
+ onLastDisconnected?: 'destroy' | 'disconnect' | 'nothing' | (() => 'destroy' | 'disconnect' | 'nothing');
17
18
  /** additional custom methods to expose */
18
19
  customMethods?: T;
19
20
  }
@@ -178,7 +178,12 @@ class TelegramWorker {
178
178
  }
179
179
  if (!wasActive && !hadLastSeen && !pending) return;
180
180
  if (this.activeConnections.size !== 0) return;
181
- switch (this.params.onLastDisconnected ?? "nothing") {
181
+ let onLastDisconnected = this.params.onLastDisconnected ?? "nothing";
182
+ if (typeof onLastDisconnected === "function") {
183
+ onLastDisconnected = onLastDisconnected();
184
+ return;
185
+ }
186
+ switch (onLastDisconnected) {
182
187
  case "nothing":
183
188
  return;
184
189
  case "disconnect":
@@ -29,6 +29,7 @@ function floodWaiter(options) {
29
29
  const method = ctx.request._;
30
30
  const storedWaitUntil = store ? storage.get(method) : void 0;
31
31
  const floodSleepThreshold = ctx.params?.floodSleepThreshold ?? maxWait;
32
+ const numRetries = ctx.params?.maxRetryCount ?? maxRetries;
32
33
  if (storedWaitUntil !== void 0) {
33
34
  const delta = storedWaitUntil - performance.now();
34
35
  if (delta <= minStoredWait) {
@@ -45,7 +46,7 @@ function floodWaiter(options) {
45
46
  }
46
47
  }
47
48
  let lastError;
48
- for (let i = 0; i <= maxRetries; i++) {
49
+ for (let i = 0; i <= numRetries; i++) {
49
50
  const res = await next(ctx);
50
51
  if (!typeAssertions.isTlRpcError(res)) {
51
52
  return res;
@@ -22,6 +22,7 @@ function floodWaiter(options) {
22
22
  const method = ctx.request._;
23
23
  const storedWaitUntil = store ? storage.get(method) : void 0;
24
24
  const floodSleepThreshold = ctx.params?.floodSleepThreshold ?? maxWait;
25
+ const numRetries = ctx.params?.maxRetryCount ?? maxRetries;
25
26
  if (storedWaitUntil !== void 0) {
26
27
  const delta = storedWaitUntil - performance.now();
27
28
  if (delta <= minStoredWait) {
@@ -38,7 +39,7 @@ function floodWaiter(options) {
38
39
  }
39
40
  }
40
41
  let lastError;
41
- for (let i = 0; i <= maxRetries; i++) {
42
+ for (let i = 0; i <= numRetries; i++) {
42
43
  const res = await next(ctx);
43
44
  if (!isTlRpcError(res)) {
44
45
  return res;
@@ -226,7 +226,7 @@ class NetworkManager {
226
226
  _: "initConnection",
227
227
  deviceModel,
228
228
  systemVersion: "1.0",
229
- appVersion: "0.29.4",
229
+ appVersion: "0.29.5",
230
230
  systemLangCode: "en",
231
231
  langPack: "",
232
232
  // "langPacks are for official apps only"
@@ -219,7 +219,7 @@ class NetworkManager {
219
219
  _: "initConnection",
220
220
  deviceModel,
221
221
  systemVersion: "1.0",
222
- appVersion: "0.29.4",
222
+ appVersion: "0.29.5",
223
223
  systemLangCode: "en",
224
224
  langPack: "",
225
225
  // "langPacks are for official apps only"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mtcute/core",
3
3
  "type": "module",
4
- "version": "0.29.4",
4
+ "version": "0.29.5",
5
5
  "description": "Type-safe library for MTProto (Telegram API)",
6
6
  "license": "MIT",
7
7
  "scripts": {},