@mtcute/core 0.20.0 → 0.20.2

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 (33) hide show
  1. package/highlevel/base.cjs +5 -0
  2. package/highlevel/base.js +5 -0
  3. package/highlevel/methods/premium/get-saved-star-gifts.d.cts +5 -1
  4. package/highlevel/methods/premium/get-saved-star-gifts.d.ts +5 -1
  5. package/highlevel/methods/premium/get-star-gifts.cjs +4 -13
  6. package/highlevel/methods/premium/get-star-gifts.d.cts +3 -2
  7. package/highlevel/methods/premium/get-star-gifts.d.ts +3 -2
  8. package/highlevel/methods/premium/get-star-gifts.js +4 -13
  9. package/highlevel/types/premium/saved-star-gift.cjs +1 -0
  10. package/highlevel/types/premium/saved-star-gift.d.cts +3 -0
  11. package/highlevel/types/premium/saved-star-gift.d.ts +3 -0
  12. package/highlevel/types/premium/saved-star-gift.js +2 -1
  13. package/highlevel/types/premium/stars-gift.cjs +0 -66
  14. package/highlevel/types/premium/stars-gift.d.cts +0 -39
  15. package/highlevel/types/premium/stars-gift.d.ts +0 -39
  16. package/highlevel/types/premium/stars-gift.js +1 -67
  17. package/index.cjs +1 -1
  18. package/index.js +2 -2
  19. package/network/middlewares/bundle.cjs +4 -0
  20. package/network/middlewares/bundle.d.cts +2 -0
  21. package/network/middlewares/bundle.d.ts +2 -0
  22. package/network/middlewares/bundle.js +4 -0
  23. package/network/middlewares/internal-errors.cjs +3 -1
  24. package/network/middlewares/internal-errors.d.cts +4 -0
  25. package/network/middlewares/internal-errors.d.ts +4 -0
  26. package/network/middlewares/internal-errors.js +3 -1
  27. package/network/network-manager.cjs +1 -1
  28. package/network/network-manager.js +1 -1
  29. package/network/persistent-connection.cjs +12 -4
  30. package/network/persistent-connection.js +13 -5
  31. package/network/session-connection.cjs +1 -10
  32. package/network/session-connection.js +1 -10
  33. package/package.json +1 -1
@@ -133,6 +133,11 @@ class BaseTelegramClient {
133
133
  this.mt.network.notifyLoggedOut();
134
134
  this.log.prefix = "[USER n/a] ";
135
135
  await this.storage.self.store(null);
136
+ const primaryDc = this.mt.network.getPrimaryDcId();
137
+ for (const dc of this.mt.network.config.getCached()?.dcOptions ?? []) {
138
+ if (dc.id === primaryDc) continue;
139
+ await this.mt.storage.provider.authKeys.deleteByDc(dc.id);
140
+ }
136
141
  }
137
142
  async notifyChannelOpened(channelId, pts) {
138
143
  return this.updates?.notifyChannelOpened(channelId, pts) ?? false;
package/highlevel/base.js CHANGED
@@ -126,6 +126,11 @@ class BaseTelegramClient {
126
126
  this.mt.network.notifyLoggedOut();
127
127
  this.log.prefix = "[USER n/a] ";
128
128
  await this.storage.self.store(null);
129
+ const primaryDc = this.mt.network.getPrimaryDcId();
130
+ for (const dc of this.mt.network.config.getCached()?.dcOptions ?? []) {
131
+ if (dc.id === primaryDc) continue;
132
+ await this.mt.storage.provider.authKeys.deleteByDc(dc.id);
133
+ }
129
134
  }
130
135
  async notifyChannelOpened(channelId, pts) {
131
136
  return this.updates?.notifyChannelOpened(channelId, pts) ?? false;
@@ -1,7 +1,11 @@
1
1
  import { ITelegramClient } from '../../client.types.js';
2
2
  import { ArrayPaginated, InputPeerLike } from '../../types/index.js';
3
3
  import { SavedStarGift } from '../../types/premium/saved-star-gift.js';
4
- /** Get a list of saved star gifts of a user */
4
+ /**
5
+ * Get a list of saved star gifts of a user/channel
6
+ *
7
+ * Note that filters currently only work for channels
8
+ */
5
9
  export declare function getSavedStarGifts(client: ITelegramClient, params: {
6
10
  /** Peer to get saved gifts from */
7
11
  owner: InputPeerLike;
@@ -1,7 +1,11 @@
1
1
  import { ITelegramClient } from '../../client.types.js';
2
2
  import { ArrayPaginated, InputPeerLike } from '../../types/index.js';
3
3
  import { SavedStarGift } from '../../types/premium/saved-star-gift.js';
4
- /** Get a list of saved star gifts of a user */
4
+ /**
5
+ * Get a list of saved star gifts of a user/channel
6
+ *
7
+ * Note that filters currently only work for channels
8
+ */
5
9
  export declare function getSavedStarGifts(client: ITelegramClient, params: {
6
10
  /** Peer to get saved gifts from */
7
11
  owner: InputPeerLike;
@@ -5,20 +5,11 @@ 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 peersIndex = require("../../types/peers/peers-index.cjs");
9
- const starsGift = require("../../types/premium/stars-gift.cjs");
10
- const miscUtils = require("../../utils/misc-utils.cjs");
11
- const resolvePeer = require("../users/resolve-peer.cjs");
8
+ const getSavedStarGifts = require("./get-saved-star-gifts.cjs");
12
9
  async function getStarGifts(client, userId, params) {
13
- const { offset = "", limit = 100 } = params ?? {};
14
- const res = await client.call({
15
- _: "payments.getUserStarGifts",
16
- userId: await resolvePeer.resolveUser(client, userId),
17
- offset,
18
- limit
10
+ return getSavedStarGifts.getSavedStarGifts(client, {
11
+ owner: userId,
12
+ ...params
19
13
  });
20
- const peers = peersIndex.PeersIndex.from(res);
21
- const gifts = res.gifts.map((gift) => new starsGift.UserStarGift(gift, peers));
22
- return miscUtils.makeArrayPaginated(gifts, res.count, res.nextOffset);
23
14
  }
24
15
  exports.getStarGifts = getStarGifts;
@@ -1,11 +1,12 @@
1
1
  import { ITelegramClient } from '../../client.types.js';
2
+ import { SavedStarGift } from '../../types/index.js';
2
3
  import { InputPeerLike } from '../../types/peers/peer.js';
3
4
  import { ArrayPaginated } from '../../types/utils.js';
4
- import { UserStarGift } from '../../types/premium/stars-gift.js';
5
5
  /**
6
6
  * Get a list of gifts sent to a user.
7
7
  *
8
8
  * @param userId User whose gifts to fetch
9
+ * @deprecated Use {@link getSavedStarGifts} instead
9
10
  * @returns Gifts sent to the user
10
11
  */
11
12
  export declare function getStarGifts(client: ITelegramClient, userId: InputPeerLike, params?: {
@@ -19,4 +20,4 @@ export declare function getStarGifts(client: ITelegramClient, userId: InputPeerL
19
20
  * @default 100
20
21
  */
21
22
  limit?: number;
22
- }): Promise<ArrayPaginated<UserStarGift, string>>;
23
+ }): Promise<ArrayPaginated<SavedStarGift, string>>;
@@ -1,11 +1,12 @@
1
1
  import { ITelegramClient } from '../../client.types.js';
2
+ import { SavedStarGift } from '../../types/index.js';
2
3
  import { InputPeerLike } from '../../types/peers/peer.js';
3
4
  import { ArrayPaginated } from '../../types/utils.js';
4
- import { UserStarGift } from '../../types/premium/stars-gift.js';
5
5
  /**
6
6
  * Get a list of gifts sent to a user.
7
7
  *
8
8
  * @param userId User whose gifts to fetch
9
+ * @deprecated Use {@link getSavedStarGifts} instead
9
10
  * @returns Gifts sent to the user
10
11
  */
11
12
  export declare function getStarGifts(client: ITelegramClient, userId: InputPeerLike, params?: {
@@ -19,4 +20,4 @@ export declare function getStarGifts(client: ITelegramClient, userId: InputPeerL
19
20
  * @default 100
20
21
  */
21
22
  limit?: number;
22
- }): Promise<ArrayPaginated<UserStarGift, string>>;
23
+ }): Promise<ArrayPaginated<SavedStarGift, string>>;
@@ -1,18 +1,9 @@
1
- import { PeersIndex } from "../../types/peers/peers-index.js";
2
- import { UserStarGift as UserStarGift$2 } from "../../types/premium/stars-gift.js";
3
- import { makeArrayPaginated } from "../../utils/misc-utils.js";
4
- import { resolveUser } from "../users/resolve-peer.js";
1
+ import { getSavedStarGifts } from "./get-saved-star-gifts.js";
5
2
  async function getStarGifts(client, userId, params) {
6
- const { offset = "", limit = 100 } = params ?? {};
7
- const res = await client.call({
8
- _: "payments.getUserStarGifts",
9
- userId: await resolveUser(client, userId),
10
- offset,
11
- limit
3
+ return getSavedStarGifts(client, {
4
+ owner: userId,
5
+ ...params
12
6
  });
13
- const peers = PeersIndex.from(res);
14
- const gifts = res.gifts.map((gift) => new UserStarGift$2(gift, peers));
15
- return makeArrayPaginated(gifts, res.count, res.nextOffset);
16
7
  }
17
8
  export {
18
9
  getStarGifts
@@ -78,3 +78,4 @@ class SavedStarGift {
78
78
  const SavedStarGift$1 = /* @__PURE__ */ inspectable.makeInspectable(SavedStarGift);
79
79
  const SavedStarGift$2 = /* @__PURE__ */ memoize.memoizeGetters(SavedStarGift$1, ["sender", "gift"]);
80
80
  exports.SavedStarGift = SavedStarGift$2;
81
+ exports.UserStarGift = SavedStarGift;
@@ -37,3 +37,6 @@ export declare class SavedStarGift {
37
37
  /** Date when the gift can be exported to blockchain */
38
38
  get canExportAt(): Date | null;
39
39
  }
40
+ export {
41
+ /** @deprecated alias for {@link SavedStarGift} */
42
+ SavedStarGift as UserStarGift, };
@@ -37,3 +37,6 @@ export declare class SavedStarGift {
37
37
  /** Date when the gift can be exported to blockchain */
38
38
  get canExportAt(): Date | null;
39
39
  }
40
+ export {
41
+ /** @deprecated alias for {@link SavedStarGift} */
42
+ SavedStarGift as UserStarGift, };
@@ -71,5 +71,6 @@ class SavedStarGift {
71
71
  const SavedStarGift$1 = /* @__PURE__ */ makeInspectable(SavedStarGift);
72
72
  const SavedStarGift$2 = /* @__PURE__ */ memoizeGetters(SavedStarGift$1, ["sender", "gift"]);
73
73
  export {
74
- SavedStarGift$2 as SavedStarGift
74
+ SavedStarGift$2 as SavedStarGift,
75
+ SavedStarGift as UserStarGift
75
76
  };
@@ -5,14 +5,11 @@ 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");
9
8
  const errors = require("../../../types/errors.cjs");
10
9
  const typeAssertions = require("../../../utils/type-assertions.cjs");
11
10
  const inspectable = require("../../utils/inspectable.cjs");
12
11
  const memoize = require("../../utils/memoize.cjs");
13
12
  const documentUtils = require("../media/document-utils.cjs");
14
- const user = require("../peers/user.cjs");
15
- const starsGiftUnique = require("./stars-gift-unique.cjs");
16
13
  class StarGift {
17
14
  constructor(raw) {
18
15
  this.raw = raw;
@@ -82,67 +79,4 @@ class StarGift {
82
79
  }
83
80
  const StarGift$1 = /* @__PURE__ */ inspectable.makeInspectable(StarGift);
84
81
  const StarGift$2 = /* @__PURE__ */ memoize.memoizeGetters(StarGift$1, ["sticker"]);
85
- class UserStarGift {
86
- constructor(raw, peers) {
87
- this.raw = raw;
88
- this.peers = peers;
89
- }
90
- /** Whether the sender chose to appear anonymously */
91
- get nameHidden() {
92
- return this.raw.nameHidden;
93
- }
94
- /** Whether this gift is not visible on the recipient's profile */
95
- get hidden() {
96
- return this.raw.unsaved;
97
- }
98
- get isRefunded() {
99
- return this.raw.refunded;
100
- }
101
- /** Sender of the gift, if available */
102
- get sender() {
103
- return this.raw.fromId ? new user.User(this.peers.user(this.raw.fromId)) : null;
104
- }
105
- /** Message ID where the gift was sent, if available */
106
- get messageId() {
107
- return this.raw.msgId ?? null;
108
- }
109
- /** Date the gift was sent or minted */
110
- get date() {
111
- return new Date(this.raw.date * 1e3);
112
- }
113
- /** Whether the gift can be upgraded to a unique gift */
114
- get canUpgrade() {
115
- return this.raw.canUpgrade;
116
- }
117
- /** Number of stars to upgrade the gift to a unique gift (may be 0) */
118
- get upgradeStars() {
119
- if (!this.raw.canUpgrade) return null;
120
- return this.raw.upgradeStars ?? Long.ZERO;
121
- }
122
- /** The gift itself */
123
- get gift() {
124
- return this.raw.gift._ === "starGift" ? new StarGift(this.raw.gift) : new starsGiftUnique.StarGiftUnique(this.raw.gift, this.peers);
125
- }
126
- /** Text attached to the gift */
127
- get text() {
128
- return this.raw.message ?? null;
129
- }
130
- /**
131
- * If the gift was converted to stars, the amount of stars
132
- * it was converted to
133
- */
134
- get convertStars() {
135
- return this.raw.convertStars ?? null;
136
- }
137
- get canExportAt() {
138
- return this.raw.canExportAt ? new Date(this.raw.canExportAt * 1e3) : null;
139
- }
140
- /** Number of stars this gift can be transferred for */
141
- get transferStars() {
142
- return this.raw.transferStars ?? null;
143
- }
144
- }
145
- const UserStarGift$1 = /* @__PURE__ */ inspectable.makeInspectable(UserStarGift);
146
- const UserStarGift$2 = /* @__PURE__ */ memoize.memoizeGetters(UserStarGift$1, ["sender", "gift"]);
147
82
  exports.StarGift = StarGift$2;
148
- exports.UserStarGift = UserStarGift$2;
@@ -1,11 +1,7 @@
1
1
  import { tl } from '@mtcute/tl';
2
2
  import { Sticker } from '../media/sticker.js';
3
3
  import { Message } from '../messages/message.js';
4
- import { TextWithEntities } from '../misc/entities.js';
5
4
  import { InputPeerLike } from '../peers/peer.js';
6
- import { PeersIndex } from '../peers/peers-index.js';
7
- import { User } from '../peers/user.js';
8
- import { StarGiftUnique } from './stars-gift-unique.js';
9
5
  export type InputStarGift = {
10
6
  /** ID of the message containing the gift */
11
7
  message: number | Message;
@@ -57,38 +53,3 @@ export declare class StarGift {
57
53
  total: number;
58
54
  } | null;
59
55
  }
60
- /**
61
- * Information about a certain user's {@link StarGift}.
62
- */
63
- export declare class UserStarGift {
64
- readonly raw: tl.RawUserStarGift;
65
- readonly peers: PeersIndex;
66
- constructor(raw: tl.RawUserStarGift, peers: PeersIndex);
67
- /** Whether the sender chose to appear anonymously */
68
- get nameHidden(): boolean;
69
- /** Whether this gift is not visible on the recipient's profile */
70
- get hidden(): boolean;
71
- get isRefunded(): boolean;
72
- /** Sender of the gift, if available */
73
- get sender(): User | null;
74
- /** Message ID where the gift was sent, if available */
75
- get messageId(): number | null;
76
- /** Date the gift was sent or minted */
77
- get date(): Date;
78
- /** Whether the gift can be upgraded to a unique gift */
79
- get canUpgrade(): boolean;
80
- /** Number of stars to upgrade the gift to a unique gift (may be 0) */
81
- get upgradeStars(): tl.Long | null;
82
- /** The gift itself */
83
- get gift(): StarGift | StarGiftUnique;
84
- /** Text attached to the gift */
85
- get text(): TextWithEntities | null;
86
- /**
87
- * If the gift was converted to stars, the amount of stars
88
- * it was converted to
89
- */
90
- get convertStars(): tl.Long | null;
91
- get canExportAt(): Date | null;
92
- /** Number of stars this gift can be transferred for */
93
- get transferStars(): tl.Long | null;
94
- }
@@ -1,11 +1,7 @@
1
1
  import { tl } from '@mtcute/tl';
2
2
  import { Sticker } from '../media/sticker.js';
3
3
  import { Message } from '../messages/message.js';
4
- import { TextWithEntities } from '../misc/entities.js';
5
4
  import { InputPeerLike } from '../peers/peer.js';
6
- import { PeersIndex } from '../peers/peers-index.js';
7
- import { User } from '../peers/user.js';
8
- import { StarGiftUnique } from './stars-gift-unique.js';
9
5
  export type InputStarGift = {
10
6
  /** ID of the message containing the gift */
11
7
  message: number | Message;
@@ -57,38 +53,3 @@ export declare class StarGift {
57
53
  total: number;
58
54
  } | null;
59
55
  }
60
- /**
61
- * Information about a certain user's {@link StarGift}.
62
- */
63
- export declare class UserStarGift {
64
- readonly raw: tl.RawUserStarGift;
65
- readonly peers: PeersIndex;
66
- constructor(raw: tl.RawUserStarGift, peers: PeersIndex);
67
- /** Whether the sender chose to appear anonymously */
68
- get nameHidden(): boolean;
69
- /** Whether this gift is not visible on the recipient's profile */
70
- get hidden(): boolean;
71
- get isRefunded(): boolean;
72
- /** Sender of the gift, if available */
73
- get sender(): User | null;
74
- /** Message ID where the gift was sent, if available */
75
- get messageId(): number | null;
76
- /** Date the gift was sent or minted */
77
- get date(): Date;
78
- /** Whether the gift can be upgraded to a unique gift */
79
- get canUpgrade(): boolean;
80
- /** Number of stars to upgrade the gift to a unique gift (may be 0) */
81
- get upgradeStars(): tl.Long | null;
82
- /** The gift itself */
83
- get gift(): StarGift | StarGiftUnique;
84
- /** Text attached to the gift */
85
- get text(): TextWithEntities | null;
86
- /**
87
- * If the gift was converted to stars, the amount of stars
88
- * it was converted to
89
- */
90
- get convertStars(): tl.Long | null;
91
- get canExportAt(): Date | null;
92
- /** Number of stars this gift can be transferred for */
93
- get transferStars(): tl.Long | null;
94
- }
@@ -1,11 +1,8 @@
1
- import Long from "long";
2
1
  import { MtTypeAssertionError } from "../../../types/errors.js";
3
2
  import { assertTypeIs } from "../../../utils/type-assertions.js";
4
3
  import { makeInspectable } from "../../utils/inspectable.js";
5
4
  import { memoizeGetters } from "../../utils/memoize.js";
6
5
  import { parseDocument } from "../media/document-utils.js";
7
- import { User as User$2 } from "../peers/user.js";
8
- import { StarGiftUnique as StarGiftUnique$2 } from "./stars-gift-unique.js";
9
6
  class StarGift {
10
7
  constructor(raw) {
11
8
  this.raw = raw;
@@ -75,69 +72,6 @@ class StarGift {
75
72
  }
76
73
  const StarGift$1 = /* @__PURE__ */ makeInspectable(StarGift);
77
74
  const StarGift$2 = /* @__PURE__ */ memoizeGetters(StarGift$1, ["sticker"]);
78
- class UserStarGift {
79
- constructor(raw, peers) {
80
- this.raw = raw;
81
- this.peers = peers;
82
- }
83
- /** Whether the sender chose to appear anonymously */
84
- get nameHidden() {
85
- return this.raw.nameHidden;
86
- }
87
- /** Whether this gift is not visible on the recipient's profile */
88
- get hidden() {
89
- return this.raw.unsaved;
90
- }
91
- get isRefunded() {
92
- return this.raw.refunded;
93
- }
94
- /** Sender of the gift, if available */
95
- get sender() {
96
- return this.raw.fromId ? new User$2(this.peers.user(this.raw.fromId)) : null;
97
- }
98
- /** Message ID where the gift was sent, if available */
99
- get messageId() {
100
- return this.raw.msgId ?? null;
101
- }
102
- /** Date the gift was sent or minted */
103
- get date() {
104
- return new Date(this.raw.date * 1e3);
105
- }
106
- /** Whether the gift can be upgraded to a unique gift */
107
- get canUpgrade() {
108
- return this.raw.canUpgrade;
109
- }
110
- /** Number of stars to upgrade the gift to a unique gift (may be 0) */
111
- get upgradeStars() {
112
- if (!this.raw.canUpgrade) return null;
113
- return this.raw.upgradeStars ?? Long.ZERO;
114
- }
115
- /** The gift itself */
116
- get gift() {
117
- return this.raw.gift._ === "starGift" ? new StarGift(this.raw.gift) : new StarGiftUnique$2(this.raw.gift, this.peers);
118
- }
119
- /** Text attached to the gift */
120
- get text() {
121
- return this.raw.message ?? null;
122
- }
123
- /**
124
- * If the gift was converted to stars, the amount of stars
125
- * it was converted to
126
- */
127
- get convertStars() {
128
- return this.raw.convertStars ?? null;
129
- }
130
- get canExportAt() {
131
- return this.raw.canExportAt ? new Date(this.raw.canExportAt * 1e3) : null;
132
- }
133
- /** Number of stars this gift can be transferred for */
134
- get transferStars() {
135
- return this.raw.transferStars ?? null;
136
- }
137
- }
138
- const UserStarGift$1 = /* @__PURE__ */ makeInspectable(UserStarGift);
139
- const UserStarGift$2 = /* @__PURE__ */ memoizeGetters(UserStarGift$1, ["sender", "gift"]);
140
75
  export {
141
- StarGift$2 as StarGift,
142
- UserStarGift$2 as UserStarGift
76
+ StarGift$2 as StarGift
143
77
  };
package/index.cjs CHANGED
@@ -256,12 +256,12 @@ exports.BusinessLocation = businessLocation.BusinessLocation;
256
256
  exports.BusinessWorkHours = businessWorkHours.BusinessWorkHours;
257
257
  exports.businessWorkHoursDaysToRaw = businessWorkHours.businessWorkHoursDaysToRaw;
258
258
  exports.SavedStarGift = savedStarGift.SavedStarGift;
259
+ exports.UserStarGift = savedStarGift.UserStarGift;
259
260
  exports.StarGiftUnique = starsGiftUnique.StarGiftUnique;
260
261
  exports.StarGiftUniqueAttribute = starsGiftUnique.StarGiftUniqueAttribute;
261
262
  exports.StarGiftUniqueBackdrop = starsGiftUnique.StarGiftUniqueBackdrop;
262
263
  exports.StarGiftUniqueOriginalDetails = starsGiftUnique.StarGiftUniqueOriginalDetails;
263
264
  exports.StarGift = starsGift.StarGift;
264
- exports.UserStarGift = starsGift.UserStarGift;
265
265
  exports.StarsStatus = starsStatus.StarsStatus;
266
266
  exports.StarsTransaction = starsTransaction.StarsTransaction;
267
267
  exports.EmojiStatus = emojiStatus.EmojiStatus;
package/index.js CHANGED
@@ -82,9 +82,9 @@ import { BusinessConnection } from "./highlevel/types/premium/business-connectio
82
82
  import { BusinessIntro } from "./highlevel/types/premium/business-intro.js";
83
83
  import { BusinessLocation } from "./highlevel/types/premium/business-location.js";
84
84
  import { BusinessWorkHours, businessWorkHoursDaysToRaw } from "./highlevel/types/premium/business-work-hours.js";
85
- import { SavedStarGift } from "./highlevel/types/premium/saved-star-gift.js";
85
+ import { SavedStarGift, UserStarGift } from "./highlevel/types/premium/saved-star-gift.js";
86
86
  import { StarGiftUnique, StarGiftUniqueAttribute, StarGiftUniqueBackdrop, StarGiftUniqueOriginalDetails } from "./highlevel/types/premium/stars-gift-unique.js";
87
- import { StarGift, UserStarGift } from "./highlevel/types/premium/stars-gift.js";
87
+ import { StarGift } from "./highlevel/types/premium/stars-gift.js";
88
88
  import { StarsStatus } from "./highlevel/types/premium/stars-status.js";
89
89
  import { StarsTransaction } from "./highlevel/types/premium/stars-transaction.js";
90
90
  import { EmojiStatus, EmojiStatusCollectible } from "./highlevel/types/reactions/emoji-status.js";
@@ -6,8 +6,12 @@ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WAR
6
6
  "use strict";
7
7
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
8
  const _default = require("./default.cjs");
9
+ const floodWaiter = require("./flood-waiter.cjs");
10
+ const internalErrors = require("./internal-errors.cjs");
9
11
  const onError = require("./on-error.cjs");
10
12
  const onMethod = require("./on-method.cjs");
11
13
  exports.basic = _default.basic;
14
+ exports.floodWaiter = floodWaiter.floodWaiter;
15
+ exports.internalErrorsHandler = internalErrors.internalErrorsHandler;
12
16
  exports.onRpcError = onError.onRpcError;
13
17
  exports.onMethod = onMethod.onMethod;
@@ -1,3 +1,5 @@
1
1
  export * from './default.js';
2
+ export * from './flood-waiter.js';
3
+ export * from './internal-errors.js';
2
4
  export * from './on-error.js';
3
5
  export * from './on-method.js';
@@ -1,3 +1,5 @@
1
1
  export * from './default.js';
2
+ export * from './flood-waiter.js';
3
+ export * from './internal-errors.js';
2
4
  export * from './on-error.js';
3
5
  export * from './on-method.js';
@@ -1,8 +1,12 @@
1
1
  import { basic } from "./default.js";
2
+ import { floodWaiter } from "./flood-waiter.js";
3
+ import { internalErrorsHandler } from "./internal-errors.js";
2
4
  import { onRpcError } from "./on-error.js";
3
5
  import { onMethod } from "./on-method.js";
4
6
  export {
5
7
  basic,
8
+ floodWaiter,
9
+ internalErrorsHandler,
6
10
  onMethod,
7
11
  onRpcError
8
12
  };
@@ -20,13 +20,15 @@ const CLIENT_ERRORS = /* @__PURE__ */ new Set([
20
20
  tl.tl.RpcError.NOT_ACCEPTABLE
21
21
  ]);
22
22
  function internalErrorsHandler(params) {
23
- const { maxRetries = Infinity, waitTime = 1 } = params;
23
+ const { maxRetries = Infinity, waitTime = 1, exceptErrors } = params;
24
+ const exceptErrorsSet = exceptErrors ? new Set(exceptErrors) : void 0;
24
25
  return async (ctx, next) => {
25
26
  const numRetries = ctx.params?.maxRetryCount ?? maxRetries;
26
27
  for (let i = 0; i <= numRetries; i++) {
27
28
  const res = await next(ctx);
28
29
  if (!typeAssertions.isTlRpcError(res)) return res;
29
30
  if (!CLIENT_ERRORS.has(res.errorCode)) {
31
+ if (exceptErrorsSet?.has(res.errorMessage)) return res;
30
32
  if (ctx.params?.throw503 && res.errorCode === -503) {
31
33
  throw new errors.MtTimeoutError();
32
34
  }
@@ -13,5 +13,9 @@ export interface InternalErrorsHandlerOptions {
13
13
  * @default 1
14
14
  */
15
15
  waitTime?: number;
16
+ /**
17
+ * List of internal errors that should not be retried and should be thrown immediately.
18
+ */
19
+ exceptErrors?: string[];
16
20
  }
17
21
  export declare function internalErrorsHandler(params: InternalErrorsHandlerOptions): RpcCallMiddleware;
@@ -13,5 +13,9 @@ export interface InternalErrorsHandlerOptions {
13
13
  * @default 1
14
14
  */
15
15
  waitTime?: number;
16
+ /**
17
+ * List of internal errors that should not be retried and should be thrown immediately.
18
+ */
19
+ exceptErrors?: string[];
16
20
  }
17
21
  export declare function internalErrorsHandler(params: InternalErrorsHandlerOptions): RpcCallMiddleware;
@@ -13,13 +13,15 @@ const CLIENT_ERRORS = /* @__PURE__ */ new Set([
13
13
  tl.RpcError.NOT_ACCEPTABLE
14
14
  ]);
15
15
  function internalErrorsHandler(params) {
16
- const { maxRetries = Infinity, waitTime = 1 } = params;
16
+ const { maxRetries = Infinity, waitTime = 1, exceptErrors } = params;
17
+ const exceptErrorsSet = exceptErrors ? new Set(exceptErrors) : void 0;
17
18
  return async (ctx, next) => {
18
19
  const numRetries = ctx.params?.maxRetryCount ?? maxRetries;
19
20
  for (let i = 0; i <= numRetries; i++) {
20
21
  const res = await next(ctx);
21
22
  if (!isTlRpcError(res)) return res;
22
23
  if (!CLIENT_ERRORS.has(res.errorCode)) {
24
+ if (exceptErrorsSet?.has(res.errorMessage)) return res;
23
25
  if (ctx.params?.throw503 && res.errorCode === -503) {
24
26
  throw new MtTimeoutError();
25
27
  }
@@ -220,7 +220,7 @@ class NetworkManager {
220
220
  _: "initConnection",
221
221
  deviceModel,
222
222
  systemVersion: "1.0",
223
- appVersion: "0.20.0",
223
+ appVersion: "0.20.2",
224
224
  systemLangCode: "en",
225
225
  langPack: "",
226
226
  // "langPacks are for official apps only"
@@ -213,7 +213,7 @@ class NetworkManager {
213
213
  _: "initConnection",
214
214
  deviceModel,
215
215
  systemVersion: "1.0",
216
- appVersion: "0.20.0",
216
+ appVersion: "0.20.2",
217
217
  systemLangCode: "en",
218
218
  langPack: "",
219
219
  // "langPacks are for official apps only"
@@ -94,16 +94,18 @@ class PersistentConnection {
94
94
  }
95
95
  }
96
96
  }
97
- async _onClose() {
97
+ _onClose() {
98
98
  this.log.debug("connection closed");
99
99
  this._updateLogPrefix();
100
100
  this._writer = void 0;
101
101
  this._codec.reset();
102
102
  this.onClosed();
103
103
  }
104
- async _onError(err) {
104
+ _onError(err) {
105
105
  this._updateLogPrefix();
106
- this.handleError(err);
106
+ if (!(err instanceof net.ConnectionClosedError)) {
107
+ this.handleError(err);
108
+ }
107
109
  return "reconnect";
108
110
  }
109
111
  async changeTransport(transport) {
@@ -167,7 +169,13 @@ class PersistentConnection {
167
169
  }
168
170
  if (this._writer) {
169
171
  this._rescheduleInactivity();
170
- await this._writer.write(data);
172
+ try {
173
+ await this._writer.write(data);
174
+ } catch (e) {
175
+ this.log.warn("encountered an error closed while sending, reconnecting: %e", e);
176
+ this._fuman.reconnect(true);
177
+ this._sendOnceConnected.push(data);
178
+ }
171
179
  } else {
172
180
  this._sendOnceConnected.push(data);
173
181
  }
@@ -1,5 +1,5 @@
1
1
  import { FramedReader, FramedWriter } from "@fuman/io";
2
- import { PersistentConnection as PersistentConnection$1 } from "@fuman/net";
2
+ import { PersistentConnection as PersistentConnection$1, ConnectionClosedError } from "@fuman/net";
3
3
  import { Emitter, timers } from "@fuman/utils";
4
4
  let nextConnectionUid = 0;
5
5
  class PersistentConnection {
@@ -87,16 +87,18 @@ class PersistentConnection {
87
87
  }
88
88
  }
89
89
  }
90
- async _onClose() {
90
+ _onClose() {
91
91
  this.log.debug("connection closed");
92
92
  this._updateLogPrefix();
93
93
  this._writer = void 0;
94
94
  this._codec.reset();
95
95
  this.onClosed();
96
96
  }
97
- async _onError(err) {
97
+ _onError(err) {
98
98
  this._updateLogPrefix();
99
- this.handleError(err);
99
+ if (!(err instanceof ConnectionClosedError)) {
100
+ this.handleError(err);
101
+ }
100
102
  return "reconnect";
101
103
  }
102
104
  async changeTransport(transport) {
@@ -160,7 +162,13 @@ class PersistentConnection {
160
162
  }
161
163
  if (this._writer) {
162
164
  this._rescheduleInactivity();
163
- await this._writer.write(data);
165
+ try {
166
+ await this._writer.write(data);
167
+ } catch (e) {
168
+ this.log.warn("encountered an error closed while sending, reconnecting: %e", e);
169
+ this._fuman.reconnect(true);
170
+ this._sendOnceConnected.push(data);
171
+ }
164
172
  } else {
165
173
  this._sendOnceConnected.push(data);
166
174
  }
@@ -1428,16 +1428,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
1428
1428
  rootMsgId
1429
1429
  );
1430
1430
  const enc = this._session.encryptMessage(result);
1431
- const promise = this.send(enc).catch((err) => {
1432
- if (this._destroyed) return;
1433
- this.log.error("error while sending pending messages (root msg_id = %l): %e", rootMsgId, err);
1434
- if (ackMsgIds) {
1435
- this._session.queuedAcks.splice(0, 0, ...ackMsgIds);
1436
- }
1437
- if (rootMsgId) {
1438
- this._onMessageFailed(rootMsgId, "unknown error");
1439
- }
1440
- });
1431
+ const promise = this.send(enc);
1441
1432
  if (this._inactivityPendingFlush && !this._session.hasPendingMessages) {
1442
1433
  void promise.then(() => {
1443
1434
  this.log.debug("pending messages sent, closing connection");
@@ -1421,16 +1421,7 @@ class SessionConnection extends PersistentConnection {
1421
1421
  rootMsgId
1422
1422
  );
1423
1423
  const enc = this._session.encryptMessage(result);
1424
- const promise = this.send(enc).catch((err) => {
1425
- if (this._destroyed) return;
1426
- this.log.error("error while sending pending messages (root msg_id = %l): %e", rootMsgId, err);
1427
- if (ackMsgIds) {
1428
- this._session.queuedAcks.splice(0, 0, ...ackMsgIds);
1429
- }
1430
- if (rootMsgId) {
1431
- this._onMessageFailed(rootMsgId, "unknown error");
1432
- }
1433
- });
1424
+ const promise = this.send(enc);
1434
1425
  if (this._inactivityPendingFlush && !this._session.hasPendingMessages) {
1435
1426
  void promise.then(() => {
1436
1427
  this.log.debug("pending messages sent, closing connection");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mtcute/core",
3
3
  "type": "module",
4
- "version": "0.20.0",
4
+ "version": "0.20.2",
5
5
  "description": "Type-safe library for MTProto (Telegram API)",
6
6
  "license": "MIT",
7
7
  "scripts": {},