@mtcute/core 0.25.7 → 0.26.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.
Files changed (118) hide show
  1. package/client.cjs +20 -11
  2. package/client.js +23 -14
  3. package/highlevel/client.d.cts +80 -64
  4. package/highlevel/client.d.ts +80 -64
  5. package/highlevel/methods/files/normalize-input-media.cjs +13 -4
  6. package/highlevel/methods/files/normalize-input-media.js +13 -4
  7. package/highlevel/methods/forums/toggle-forum.cjs +0 -10
  8. package/highlevel/methods/forums/toggle-forum.d.cts +0 -10
  9. package/highlevel/methods/forums/toggle-forum.d.ts +0 -10
  10. package/highlevel/methods/forums/toggle-forum.js +0 -10
  11. package/highlevel/methods/premium/buy-resale-gift.cjs +3 -2
  12. package/highlevel/methods/premium/buy-resale-gift.d.cts +2 -0
  13. package/highlevel/methods/premium/buy-resale-gift.d.ts +2 -0
  14. package/highlevel/methods/premium/buy-resale-gift.js +3 -2
  15. package/highlevel/methods/premium/get-resale-star-gifts.cjs +2 -2
  16. package/highlevel/methods/premium/get-resale-star-gifts.d.cts +1 -1
  17. package/highlevel/methods/premium/get-resale-star-gifts.d.ts +1 -1
  18. package/highlevel/methods/premium/get-resale-star-gifts.js +2 -2
  19. package/highlevel/methods/premium/get-saved-star-gifts.cjs +2 -1
  20. package/highlevel/methods/premium/get-saved-star-gifts.d.cts +4 -2
  21. package/highlevel/methods/premium/get-saved-star-gifts.d.ts +4 -2
  22. package/highlevel/methods/premium/get-saved-star-gifts.js +2 -1
  23. package/highlevel/methods/{auth/run.cjs → premium/get-star-gift-value.cjs} +8 -5
  24. package/highlevel/methods/premium/get-star-gift-value.d.cts +9 -0
  25. package/highlevel/methods/premium/get-star-gift-value.d.ts +9 -0
  26. package/highlevel/methods/premium/get-star-gift-value.js +11 -0
  27. package/highlevel/methods/premium/get-stars-transactions.cjs +3 -2
  28. package/highlevel/methods/premium/get-stars-transactions.d.cts +2 -0
  29. package/highlevel/methods/premium/get-stars-transactions.d.ts +2 -0
  30. package/highlevel/methods/premium/get-stars-transactions.js +3 -2
  31. package/highlevel/methods/premium/iter-saved-star-gifts.cjs +15 -10
  32. package/highlevel/methods/premium/iter-saved-star-gifts.d.cts +13 -19
  33. package/highlevel/methods/premium/iter-saved-star-gifts.d.ts +13 -19
  34. package/highlevel/methods/premium/iter-saved-star-gifts.js +15 -10
  35. package/highlevel/methods/premium/prepay-star-gift-upgrade.cjs +30 -0
  36. package/highlevel/methods/premium/prepay-star-gift-upgrade.d.cts +23 -0
  37. package/highlevel/methods/premium/prepay-star-gift-upgrade.d.ts +23 -0
  38. package/highlevel/methods/premium/prepay-star-gift-upgrade.js +25 -0
  39. package/highlevel/methods/stickers/delete-sticker-from-set.d.cts +2 -4
  40. package/highlevel/methods/stickers/delete-sticker-from-set.d.ts +2 -4
  41. package/highlevel/methods/stickers/move-sticker-in-set.d.cts +2 -4
  42. package/highlevel/methods/stickers/move-sticker-in-set.d.ts +2 -4
  43. package/highlevel/methods/stickers/replace-sticker-in-set.d.cts +2 -4
  44. package/highlevel/methods/stickers/replace-sticker-in-set.d.ts +2 -4
  45. package/highlevel/methods/users/get-saved-music.cjs +38 -0
  46. package/highlevel/methods/users/get-saved-music.d.cts +13 -0
  47. package/highlevel/methods/users/get-saved-music.d.ts +13 -0
  48. package/highlevel/methods/users/get-saved-music.js +33 -0
  49. package/highlevel/methods/users/save-music-to-profile.cjs +57 -0
  50. package/highlevel/methods/users/save-music-to-profile.d.cts +19 -0
  51. package/highlevel/methods/users/save-music-to-profile.d.ts +19 -0
  52. package/highlevel/methods/users/save-music-to-profile.js +52 -0
  53. package/highlevel/methods/users/set-emoji-status.cjs +0 -8
  54. package/highlevel/methods/users/set-emoji-status.d.cts +0 -11
  55. package/highlevel/methods/users/set-emoji-status.d.ts +0 -11
  56. package/highlevel/methods/users/set-emoji-status.js +1 -9
  57. package/highlevel/methods.d.cts +6 -4
  58. package/highlevel/methods.d.ts +6 -4
  59. package/highlevel/types/files/utils.d.cts +7 -0
  60. package/highlevel/types/files/utils.d.ts +7 -0
  61. package/highlevel/types/media/document.d.cts +1 -1
  62. package/highlevel/types/media/document.d.ts +1 -1
  63. package/highlevel/types/messages/message-action.cjs +43 -21
  64. package/highlevel/types/messages/message-action.d.cts +58 -17
  65. package/highlevel/types/messages/message-action.d.ts +58 -17
  66. package/highlevel/types/messages/message-action.js +43 -21
  67. package/highlevel/types/peers/chat.cjs +5 -1
  68. package/highlevel/types/peers/chat.d.cts +5 -1
  69. package/highlevel/types/peers/chat.d.ts +5 -1
  70. package/highlevel/types/peers/chat.js +5 -1
  71. package/highlevel/types/peers/full-chat.cjs +4 -0
  72. package/highlevel/types/peers/full-chat.d.cts +2 -0
  73. package/highlevel/types/peers/full-chat.d.ts +2 -0
  74. package/highlevel/types/peers/full-chat.js +4 -0
  75. package/highlevel/types/peers/full-user.cjs +10 -1
  76. package/highlevel/types/peers/full-user.d.cts +3 -0
  77. package/highlevel/types/peers/full-user.d.ts +3 -0
  78. package/highlevel/types/peers/full-user.js +10 -1
  79. package/highlevel/types/premium/index.d.cts +1 -0
  80. package/highlevel/types/premium/index.d.ts +1 -0
  81. package/highlevel/types/premium/saved-star-gift.cjs +6 -0
  82. package/highlevel/types/premium/saved-star-gift.d.cts +4 -0
  83. package/highlevel/types/premium/saved-star-gift.d.ts +4 -0
  84. package/highlevel/types/premium/saved-star-gift.js +6 -0
  85. package/highlevel/types/premium/star-gift-value.cjs +65 -0
  86. package/highlevel/types/premium/star-gift-value.d.cts +41 -0
  87. package/highlevel/types/premium/star-gift-value.d.ts +41 -0
  88. package/highlevel/types/premium/star-gift-value.js +60 -0
  89. package/highlevel/types/premium/stars-gift-unique.cjs +10 -3
  90. package/highlevel/types/premium/stars-gift-unique.d.cts +1 -1
  91. package/highlevel/types/premium/stars-gift-unique.d.ts +1 -1
  92. package/highlevel/types/premium/stars-gift-unique.js +10 -3
  93. package/highlevel/types/premium/stars-transaction.cjs +9 -0
  94. package/highlevel/types/premium/stars-transaction.d.cts +10 -0
  95. package/highlevel/types/premium/stars-transaction.d.ts +10 -0
  96. package/highlevel/types/premium/stars-transaction.js +9 -0
  97. package/index.cjs +2 -0
  98. package/index.js +2 -0
  99. package/methods.cjs +10 -5
  100. package/methods.js +13 -8
  101. package/network/mtproto-session.cjs +1 -0
  102. package/network/mtproto-session.d.cts +1 -0
  103. package/network/mtproto-session.d.ts +1 -0
  104. package/network/mtproto-session.js +1 -0
  105. package/network/network-manager.cjs +1 -1
  106. package/network/network-manager.js +1 -1
  107. package/network/session-connection.cjs +27 -10
  108. package/network/session-connection.d.cts +1 -0
  109. package/network/session-connection.d.ts +1 -0
  110. package/network/session-connection.js +27 -10
  111. package/package.json +2 -2
  112. package/utils/binary/compat.cjs +35 -4
  113. package/utils/binary/compat.js +35 -4
  114. package/utils/binary/serialization.d.cts +3 -3
  115. package/utils/binary/serialization.d.ts +3 -3
  116. package/highlevel/methods/auth/run.d.cts +0 -16
  117. package/highlevel/methods/auth/run.d.ts +0 -16
  118. package/highlevel/methods/auth/run.js +0 -8
@@ -8,7 +8,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
8
  const starsStatus = require("../../types/premium/stars-status.cjs");
9
9
  const resolvePeer = require("../users/resolve-peer.cjs");
10
10
  async function getStarsTransactions(client, peerId, params) {
11
- const { direction, sort, subscriptionId, offset = "", limit = 100 } = params ?? {};
11
+ const { direction, sort, subscriptionId, offset = "", limit = 100, ton } = params ?? {};
12
12
  const res = await client.call({
13
13
  _: "payments.getStarsTransactions",
14
14
  peer: await resolvePeer.resolvePeer(client, peerId),
@@ -17,7 +17,8 @@ async function getStarsTransactions(client, peerId, params) {
17
17
  outbound: direction === "outgoing",
18
18
  inbound: direction === "incoming",
19
19
  ascending: sort === "asc",
20
- subscriptionId
20
+ subscriptionId,
21
+ ton
21
22
  });
22
23
  return new starsStatus.StarsStatus(res);
23
24
  }
@@ -25,6 +25,8 @@ export declare function getStarsTransactions(client: ITelegramClient, peerId: In
25
25
  subscriptionId?: string;
26
26
  /** Pagination offset */
27
27
  offset?: string;
28
+ /** Whether to return transactions made in TON */
29
+ ton?: boolean;
28
30
  /**
29
31
  * Pagination limit
30
32
  *
@@ -25,6 +25,8 @@ export declare function getStarsTransactions(client: ITelegramClient, peerId: In
25
25
  subscriptionId?: string;
26
26
  /** Pagination offset */
27
27
  offset?: string;
28
+ /** Whether to return transactions made in TON */
29
+ ton?: boolean;
28
30
  /**
29
31
  * Pagination limit
30
32
  *
@@ -1,7 +1,7 @@
1
1
  import { StarsStatus as StarsStatus$2 } from "../../types/premium/stars-status.js";
2
2
  import { resolvePeer } from "../users/resolve-peer.js";
3
3
  async function getStarsTransactions(client, peerId, params) {
4
- const { direction, sort, subscriptionId, offset = "", limit = 100 } = params ?? {};
4
+ const { direction, sort, subscriptionId, offset = "", limit = 100, ton } = params ?? {};
5
5
  const res = await client.call({
6
6
  _: "payments.getStarsTransactions",
7
7
  peer: await resolvePeer(client, peerId),
@@ -10,7 +10,8 @@ async function getStarsTransactions(client, peerId, params) {
10
10
  outbound: direction === "outgoing",
11
11
  inbound: direction === "incoming",
12
12
  ascending: sort === "asc",
13
- subscriptionId
13
+ subscriptionId,
14
+ ton
14
15
  });
15
16
  return new StarsStatus$2(res);
16
17
  }
@@ -9,25 +9,30 @@ const savedStarGift = require("../../types/premium/saved-star-gift.cjs");
9
9
  const resolvePeer = require("../users/resolve-peer.cjs");
10
10
  const peersIndex = require("../../types/peers/peers-index.cjs");
11
11
  async function* iterSavedStarGifts(client, params) {
12
- const owner = await resolvePeer.resolvePeer(client, params.owner);
13
- let offset = "";
12
+ const {
13
+ owner,
14
+ offset: offsetInitial = "",
15
+ chunkSize = 100,
16
+ limit = Infinity,
17
+ ...rest
18
+ } = params;
19
+ const ownerPeer = await resolvePeer.resolvePeer(client, owner);
20
+ let offset = offsetInitial;
21
+ let current = 0;
14
22
  while (true) {
15
23
  const res = await client.call({
16
24
  _: "payments.getSavedStarGifts",
17
- peer: owner,
18
- excludeUnsaved: params.excludeUnsaved,
19
- excludeSaved: params.excludeSaved,
20
- excludeUnlimited: params.excludeUnlimited,
21
- excludeLimited: params.excludeLimited,
22
- excludeUnique: params.excludeUnique,
23
- sortByValue: params.sortByValue,
25
+ peer: ownerPeer,
24
26
  offset,
25
- limit: params.limit ?? 100
27
+ limit: Math.min(chunkSize, limit - current),
28
+ ...rest
26
29
  });
27
30
  const peers = peersIndex.PeersIndex.from(res);
28
31
  yield* res.gifts.map((it) => new savedStarGift.SavedStarGift(it, peers));
29
32
  if (!res.nextOffset) break;
30
33
  offset = res.nextOffset;
34
+ current += res.gifts.length;
35
+ if (current >= limit) break;
31
36
  }
32
37
  }
33
38
  exports.iterSavedStarGifts = iterSavedStarGifts;
@@ -1,27 +1,21 @@
1
1
  import { ITelegramClient } from '../../client.types.js';
2
- import { InputPeerLike } from '../../types/index.js';
2
+ import { getSavedStarGifts } from './get-saved-star-gifts.js';
3
3
  import { SavedStarGift } from '../../types/premium/saved-star-gift.js';
4
4
  /**
5
5
  * Iterate over saved star gifts of a user,
6
6
  * wrapper over {@link getSavedStarGifts}
7
7
  */
8
- export declare function iterSavedStarGifts(client: ITelegramClient, params: {
9
- /** Peer to get saved gifts from */
10
- owner: InputPeerLike;
11
- /** Whether to exclude unsaved gifts */
12
- excludeUnsaved?: boolean;
13
- /** Whether to exclude saved gifts */
14
- excludeSaved?: boolean;
15
- /** Whether to exclude gifts with unlimited availability */
16
- excludeUnlimited?: boolean;
17
- /** Whether to exclude gifts with limited availability */
18
- excludeLimited?: boolean;
19
- /** Whether to exclude unique gifts */
20
- excludeUnique?: boolean;
21
- /** Whether to sort by value */
22
- sortByValue?: boolean;
23
- /** Offset for pagination */
24
- offset?: string;
25
- /** Limit for pagination */
8
+ export declare function iterSavedStarGifts(client: ITelegramClient, params: Parameters<typeof getSavedStarGifts>[1] & {
9
+ /**
10
+ * Number of gifts to fetch per request
11
+ *
12
+ * @default 100
13
+ */
14
+ chunkSize?: number;
15
+ /**
16
+ * Total number of gifts to fetch
17
+ *
18
+ * @default Infinity
19
+ */
26
20
  limit?: number;
27
21
  }): AsyncIterableIterator<SavedStarGift>;
@@ -1,27 +1,21 @@
1
1
  import { ITelegramClient } from '../../client.types.js';
2
- import { InputPeerLike } from '../../types/index.js';
2
+ import { getSavedStarGifts } from './get-saved-star-gifts.js';
3
3
  import { SavedStarGift } from '../../types/premium/saved-star-gift.js';
4
4
  /**
5
5
  * Iterate over saved star gifts of a user,
6
6
  * wrapper over {@link getSavedStarGifts}
7
7
  */
8
- export declare function iterSavedStarGifts(client: ITelegramClient, params: {
9
- /** Peer to get saved gifts from */
10
- owner: InputPeerLike;
11
- /** Whether to exclude unsaved gifts */
12
- excludeUnsaved?: boolean;
13
- /** Whether to exclude saved gifts */
14
- excludeSaved?: boolean;
15
- /** Whether to exclude gifts with unlimited availability */
16
- excludeUnlimited?: boolean;
17
- /** Whether to exclude gifts with limited availability */
18
- excludeLimited?: boolean;
19
- /** Whether to exclude unique gifts */
20
- excludeUnique?: boolean;
21
- /** Whether to sort by value */
22
- sortByValue?: boolean;
23
- /** Offset for pagination */
24
- offset?: string;
25
- /** Limit for pagination */
8
+ export declare function iterSavedStarGifts(client: ITelegramClient, params: Parameters<typeof getSavedStarGifts>[1] & {
9
+ /**
10
+ * Number of gifts to fetch per request
11
+ *
12
+ * @default 100
13
+ */
14
+ chunkSize?: number;
15
+ /**
16
+ * Total number of gifts to fetch
17
+ *
18
+ * @default Infinity
19
+ */
26
20
  limit?: number;
27
21
  }): AsyncIterableIterator<SavedStarGift>;
@@ -2,25 +2,30 @@ import { SavedStarGift as SavedStarGift$2 } from "../../types/premium/saved-star
2
2
  import { resolvePeer } from "../users/resolve-peer.js";
3
3
  import { PeersIndex } from "../../types/peers/peers-index.js";
4
4
  async function* iterSavedStarGifts(client, params) {
5
- const owner = await resolvePeer(client, params.owner);
6
- let offset = "";
5
+ const {
6
+ owner,
7
+ offset: offsetInitial = "",
8
+ chunkSize = 100,
9
+ limit = Infinity,
10
+ ...rest
11
+ } = params;
12
+ const ownerPeer = await resolvePeer(client, owner);
13
+ let offset = offsetInitial;
14
+ let current = 0;
7
15
  while (true) {
8
16
  const res = await client.call({
9
17
  _: "payments.getSavedStarGifts",
10
- peer: owner,
11
- excludeUnsaved: params.excludeUnsaved,
12
- excludeSaved: params.excludeSaved,
13
- excludeUnlimited: params.excludeUnlimited,
14
- excludeLimited: params.excludeLimited,
15
- excludeUnique: params.excludeUnique,
16
- sortByValue: params.sortByValue,
18
+ peer: ownerPeer,
17
19
  offset,
18
- limit: params.limit ?? 100
20
+ limit: Math.min(chunkSize, limit - current),
21
+ ...rest
19
22
  });
20
23
  const peers = PeersIndex.from(res);
21
24
  yield* res.gifts.map((it) => new SavedStarGift$2(it, peers));
22
25
  if (!res.nextOffset) break;
23
26
  offset = res.nextOffset;
27
+ current += res.gifts.length;
28
+ if (current >= limit) break;
24
29
  }
25
30
  }
26
31
  export {
@@ -0,0 +1,30 @@
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 typeAssertions = require("../../../utils/type-assertions.cjs");
9
+ const findInUpdate = require("../messages/find-in-update.cjs");
10
+ const resolvePeer = require("../users/resolve-peer.cjs");
11
+ async function prepayStarGiftUpgrade(client, params) {
12
+ const { peer, hash, shouldDispatch } = params;
13
+ const invoice = {
14
+ _: "inputInvoiceStarGiftPrepaidUpgrade",
15
+ peer: await resolvePeer.resolvePeer(client, peer),
16
+ hash
17
+ };
18
+ const form = await client.call({
19
+ _: "payments.getPaymentForm",
20
+ invoice
21
+ });
22
+ const res = await client.call({
23
+ _: "payments.sendStarsForm",
24
+ invoice,
25
+ formId: form.formId
26
+ });
27
+ typeAssertions.assertTypeIs("payments.sendStarsForm", res, "payments.paymentResult");
28
+ return findInUpdate._findMessageInUpdate(client, res.updates, false, !shouldDispatch, true);
29
+ }
30
+ exports.prepayStarGiftUpgrade = prepayStarGiftUpgrade;
@@ -0,0 +1,23 @@
1
+ import { ITelegramClient } from '../../client.types.js';
2
+ import { InputPeerLike } from '../../types/index.js';
3
+ import { Message } from '../../types/messages/message.js';
4
+ /**
5
+ * Pay for other user's star gift upgrade.
6
+ *
7
+ * > **Note**: this method is not indended to be used by full-fledged clients,
8
+ * > as this method hides the actual invoice and payment form from the user.
9
+ * > For GUI clients, you should refer to the method's source code and
10
+ * > present the payment form to the user.
11
+ *
12
+ * @returns Service message about the payment for the upgrade, if one was generated.
13
+ */
14
+ export declare function prepayStarGiftUpgrade(client: ITelegramClient, params: {
15
+ peer: InputPeerLike;
16
+ /** Prepaid upgrade hash, taken from `SavedStarGift.prepaidUpgradeHash` */
17
+ hash: string;
18
+ /**
19
+ * Whether to dispatch the new message event
20
+ * to the client's update handler.
21
+ */
22
+ shouldDispatch?: true;
23
+ }): Promise<Message | null>;
@@ -0,0 +1,23 @@
1
+ import { ITelegramClient } from '../../client.types.js';
2
+ import { InputPeerLike } from '../../types/index.js';
3
+ import { Message } from '../../types/messages/message.js';
4
+ /**
5
+ * Pay for other user's star gift upgrade.
6
+ *
7
+ * > **Note**: this method is not indended to be used by full-fledged clients,
8
+ * > as this method hides the actual invoice and payment form from the user.
9
+ * > For GUI clients, you should refer to the method's source code and
10
+ * > present the payment form to the user.
11
+ *
12
+ * @returns Service message about the payment for the upgrade, if one was generated.
13
+ */
14
+ export declare function prepayStarGiftUpgrade(client: ITelegramClient, params: {
15
+ peer: InputPeerLike;
16
+ /** Prepaid upgrade hash, taken from `SavedStarGift.prepaidUpgradeHash` */
17
+ hash: string;
18
+ /**
19
+ * Whether to dispatch the new message event
20
+ * to the client's update handler.
21
+ */
22
+ shouldDispatch?: true;
23
+ }): Promise<Message | null>;
@@ -0,0 +1,25 @@
1
+ import { assertTypeIs } from "../../../utils/type-assertions.js";
2
+ import { _findMessageInUpdate } from "../messages/find-in-update.js";
3
+ import { resolvePeer } from "../users/resolve-peer.js";
4
+ async function prepayStarGiftUpgrade(client, params) {
5
+ const { peer, hash, shouldDispatch } = params;
6
+ const invoice = {
7
+ _: "inputInvoiceStarGiftPrepaidUpgrade",
8
+ peer: await resolvePeer(client, peer),
9
+ hash
10
+ };
11
+ const form = await client.call({
12
+ _: "payments.getPaymentForm",
13
+ invoice
14
+ });
15
+ const res = await client.call({
16
+ _: "payments.sendStarsForm",
17
+ invoice,
18
+ formId: form.formId
19
+ });
20
+ assertTypeIs("payments.sendStarsForm", res, "payments.paymentResult");
21
+ return _findMessageInUpdate(client, res.updates, false, !shouldDispatch, true);
22
+ }
23
+ export {
24
+ prepayStarGiftUpgrade
25
+ };
@@ -1,7 +1,5 @@
1
- import { tl } from '@mtcute/tl';
2
1
  import { ITelegramClient } from '../../client.types.js';
3
- import { tdFileId } from '@mtcute/file-id';
4
- import { StickerSet } from '../../types/index.js';
2
+ import { InputDocumentId, StickerSet } from '../../types/index.js';
5
3
  /**
6
4
  * Delete a sticker from a sticker set
7
5
  *
@@ -12,4 +10,4 @@ import { StickerSet } from '../../types/index.js';
12
10
  * TL object representing a sticker to be removed
13
11
  * @returns Modfiied sticker set
14
12
  */
15
- export declare function deleteStickerFromSet(client: ITelegramClient, sticker: string | tdFileId.RawFullRemoteFileLocation | tl.TypeInputDocument): Promise<StickerSet>;
13
+ export declare function deleteStickerFromSet(client: ITelegramClient, sticker: InputDocumentId): Promise<StickerSet>;
@@ -1,7 +1,5 @@
1
- import { tl } from '@mtcute/tl';
2
1
  import { ITelegramClient } from '../../client.types.js';
3
- import { tdFileId } from '@mtcute/file-id';
4
- import { StickerSet } from '../../types/index.js';
2
+ import { InputDocumentId, StickerSet } from '../../types/index.js';
5
3
  /**
6
4
  * Delete a sticker from a sticker set
7
5
  *
@@ -12,4 +10,4 @@ import { StickerSet } from '../../types/index.js';
12
10
  * TL object representing a sticker to be removed
13
11
  * @returns Modfiied sticker set
14
12
  */
15
- export declare function deleteStickerFromSet(client: ITelegramClient, sticker: string | tdFileId.RawFullRemoteFileLocation | tl.TypeInputDocument): Promise<StickerSet>;
13
+ export declare function deleteStickerFromSet(client: ITelegramClient, sticker: InputDocumentId): Promise<StickerSet>;
@@ -1,7 +1,5 @@
1
- import { tl } from '@mtcute/tl';
2
1
  import { ITelegramClient } from '../../client.types.js';
3
- import { tdFileId } from '@mtcute/file-id';
4
- import { StickerSet } from '../../types/index.js';
2
+ import { InputDocumentId, StickerSet } from '../../types/index.js';
5
3
  /**
6
4
  * Move a sticker in a sticker set
7
5
  * to another position
@@ -14,4 +12,4 @@ import { StickerSet } from '../../types/index.js';
14
12
  * @param position New sticker position (starting from 0)
15
13
  * @returns Modified sticker set
16
14
  */
17
- export declare function moveStickerInSet(client: ITelegramClient, sticker: string | tdFileId.RawFullRemoteFileLocation | tl.TypeInputDocument, position: number): Promise<StickerSet>;
15
+ export declare function moveStickerInSet(client: ITelegramClient, sticker: InputDocumentId, position: number): Promise<StickerSet>;
@@ -1,7 +1,5 @@
1
- import { tl } from '@mtcute/tl';
2
1
  import { ITelegramClient } from '../../client.types.js';
3
- import { tdFileId } from '@mtcute/file-id';
4
- import { StickerSet } from '../../types/index.js';
2
+ import { InputDocumentId, StickerSet } from '../../types/index.js';
5
3
  /**
6
4
  * Move a sticker in a sticker set
7
5
  * to another position
@@ -14,4 +12,4 @@ import { StickerSet } from '../../types/index.js';
14
12
  * @param position New sticker position (starting from 0)
15
13
  * @returns Modified sticker set
16
14
  */
17
- export declare function moveStickerInSet(client: ITelegramClient, sticker: string | tdFileId.RawFullRemoteFileLocation | tl.TypeInputDocument, position: number): Promise<StickerSet>;
15
+ export declare function moveStickerInSet(client: ITelegramClient, sticker: InputDocumentId, position: number): Promise<StickerSet>;
@@ -1,7 +1,5 @@
1
- import { tl } from '@mtcute/tl';
2
1
  import { ITelegramClient } from '../../client.types.js';
3
- import { InputStickerSetItem, StickerSet } from '../../types/index.js';
4
- import { tdFileId } from '@mtcute/file-id';
2
+ import { InputDocumentId, InputStickerSetItem, StickerSet } from '../../types/index.js';
5
3
  /**
6
4
  * Replace a sticker in a sticker set with another sticker
7
5
  *
@@ -13,7 +11,7 @@ import { tdFileId } from '@mtcute/file-id';
13
11
  * @param newSticker New sticker to replace the old one with
14
12
  * @returns Modfiied sticker set
15
13
  */
16
- export declare function replaceStickerInSet(client: ITelegramClient, sticker: string | tdFileId.RawFullRemoteFileLocation | tl.TypeInputDocument, newSticker: InputStickerSetItem, params?: {
14
+ export declare function replaceStickerInSet(client: ITelegramClient, sticker: InputDocumentId, newSticker: InputStickerSetItem, params?: {
17
15
  /**
18
16
  * Upload progress callback
19
17
  *
@@ -1,7 +1,5 @@
1
- import { tl } from '@mtcute/tl';
2
1
  import { ITelegramClient } from '../../client.types.js';
3
- import { InputStickerSetItem, StickerSet } from '../../types/index.js';
4
- import { tdFileId } from '@mtcute/file-id';
2
+ import { InputDocumentId, InputStickerSetItem, StickerSet } from '../../types/index.js';
5
3
  /**
6
4
  * Replace a sticker in a sticker set with another sticker
7
5
  *
@@ -13,7 +11,7 @@ import { tdFileId } from '@mtcute/file-id';
13
11
  * @param newSticker New sticker to replace the old one with
14
12
  * @returns Modfiied sticker set
15
13
  */
16
- export declare function replaceStickerInSet(client: ITelegramClient, sticker: string | tdFileId.RawFullRemoteFileLocation | tl.TypeInputDocument, newSticker: InputStickerSetItem, params?: {
14
+ export declare function replaceStickerInSet(client: ITelegramClient, sticker: InputDocumentId, newSticker: InputStickerSetItem, params?: {
17
15
  /**
18
16
  * Upload progress callback
19
17
  *
@@ -0,0 +1,38 @@
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 utils = require("@fuman/utils");
9
+ const Long = require("long");
10
+ const typeAssertions = require("../../../utils/type-assertions.cjs");
11
+ const documentUtils = require("../../types/media/document-utils.cjs");
12
+ const resolvePeer = require("./resolve-peer.cjs");
13
+ const miscUtils = require("../../utils/misc-utils.cjs");
14
+ async function getSavedMusic(client, params) {
15
+ const res = await client.call({
16
+ _: "users.getSavedMusic",
17
+ id: await resolvePeer.resolveUser(client, params.userId),
18
+ offset: params.offset ?? 0,
19
+ limit: params.limit ?? 100,
20
+ hash: Long.ZERO
21
+ });
22
+ typeAssertions.assertTypeIsNot("getSavedMusic", res, "users.savedMusicNotModified");
23
+ const files = [];
24
+ for (const file of res.documents) {
25
+ typeAssertions.assertTypeIs("getSavedMusic", file, "document");
26
+ const doc = documentUtils.parseDocument(file);
27
+ utils.assert(doc.type === "audio");
28
+ files.push(doc);
29
+ }
30
+ let nextOffset = (params.offset ?? 0) + files.length;
31
+ if (nextOffset >= res.count) nextOffset = void 0;
32
+ return miscUtils.makeArrayPaginated(
33
+ files,
34
+ res.count ?? files.length,
35
+ nextOffset
36
+ );
37
+ }
38
+ exports.getSavedMusic = getSavedMusic;
@@ -0,0 +1,13 @@
1
+ import { ITelegramClient } from '../../client.types.js';
2
+ import { ArrayPaginated, Audio, InputPeerLike } from '../../types/index.js';
3
+ /**
4
+ * Get music files saved to the user's profile
5
+ */
6
+ export declare function getSavedMusic(client: ITelegramClient, params: {
7
+ /** User ID, username, phone number, `"me"` or `"self"` */
8
+ userId: InputPeerLike;
9
+ /** Offset for pagination */
10
+ offset?: number;
11
+ /** Limit for pagination */
12
+ limit?: number;
13
+ }): Promise<ArrayPaginated<Audio, number>>;
@@ -0,0 +1,13 @@
1
+ import { ITelegramClient } from '../../client.types.js';
2
+ import { ArrayPaginated, Audio, InputPeerLike } from '../../types/index.js';
3
+ /**
4
+ * Get music files saved to the user's profile
5
+ */
6
+ export declare function getSavedMusic(client: ITelegramClient, params: {
7
+ /** User ID, username, phone number, `"me"` or `"self"` */
8
+ userId: InputPeerLike;
9
+ /** Offset for pagination */
10
+ offset?: number;
11
+ /** Limit for pagination */
12
+ limit?: number;
13
+ }): Promise<ArrayPaginated<Audio, number>>;
@@ -0,0 +1,33 @@
1
+ import { assert } from "@fuman/utils";
2
+ import Long from "long";
3
+ import { assertTypeIsNot, assertTypeIs } from "../../../utils/type-assertions.js";
4
+ import { parseDocument } from "../../types/media/document-utils.js";
5
+ import { resolveUser } from "./resolve-peer.js";
6
+ import { makeArrayPaginated } from "../../utils/misc-utils.js";
7
+ async function getSavedMusic(client, params) {
8
+ const res = await client.call({
9
+ _: "users.getSavedMusic",
10
+ id: await resolveUser(client, params.userId),
11
+ offset: params.offset ?? 0,
12
+ limit: params.limit ?? 100,
13
+ hash: Long.ZERO
14
+ });
15
+ assertTypeIsNot("getSavedMusic", res, "users.savedMusicNotModified");
16
+ const files = [];
17
+ for (const file of res.documents) {
18
+ assertTypeIs("getSavedMusic", file, "document");
19
+ const doc = parseDocument(file);
20
+ assert(doc.type === "audio");
21
+ files.push(doc);
22
+ }
23
+ let nextOffset = (params.offset ?? 0) + files.length;
24
+ if (nextOffset >= res.count) nextOffset = void 0;
25
+ return makeArrayPaginated(
26
+ files,
27
+ res.count ?? files.length,
28
+ nextOffset
29
+ );
30
+ }
31
+ export {
32
+ getSavedMusic
33
+ };
@@ -0,0 +1,57 @@
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 utils = require("@fuman/utils");
9
+ const fileId = require("@mtcute/file-id");
10
+ const tl = require("@mtcute/tl");
11
+ const typeAssertions = require("../../../utils/type-assertions.cjs");
12
+ const convertFileId = require("../../utils/convert-file-id.cjs");
13
+ const normalizeInputMedia = require("../files/normalize-input-media.cjs");
14
+ async function saveMusicToProfile(client, params) {
15
+ let after = params.after;
16
+ if (fileId.tdFileId.isFileIdLike(after)) {
17
+ after = convertFileId.fileIdToInputDocument(after);
18
+ }
19
+ let audio = params.audio;
20
+ if (fileId.tdFileId.isFileIdLike(audio)) {
21
+ audio = {
22
+ type: "audio",
23
+ file: audio
24
+ };
25
+ }
26
+ let audioId;
27
+ if (tl.tl.isAnyInputDocument(audio)) {
28
+ audioId = audio;
29
+ } else {
30
+ const media = await normalizeInputMedia._normalizeInputMedia(client, audio, {
31
+ progressCallback: params.progressCallback,
32
+ uploadPeer: { _: "inputPeerSelf" }
33
+ }, true);
34
+ utils.assert(media._ === "inputMediaDocument");
35
+ audioId = media.id;
36
+ }
37
+ const res = await client.call({
38
+ _: "account.saveMusic",
39
+ id: audioId,
40
+ afterId: after
41
+ });
42
+ typeAssertions.assertTrue("account.saveMusic", res);
43
+ }
44
+ async function unsaveMusicFromProfile(client, params) {
45
+ let audio = params.audio;
46
+ if (fileId.tdFileId.isFileIdLike(audio)) {
47
+ audio = convertFileId.fileIdToInputDocument(audio);
48
+ }
49
+ const res = await client.call({
50
+ _: "account.saveMusic",
51
+ id: audio,
52
+ unsave: true
53
+ });
54
+ typeAssertions.assertTrue("account.saveMusic", res);
55
+ }
56
+ exports.saveMusicToProfile = saveMusicToProfile;
57
+ exports.unsaveMusicFromProfile = unsaveMusicFromProfile;
@@ -0,0 +1,19 @@
1
+ import { ITelegramClient } from '../../client.types.js';
2
+ import { InputDocumentId, InputMediaAudio } from '../../types/index.js';
3
+ export declare function saveMusicToProfile(client: ITelegramClient, params: {
4
+ /** Audio file to save (or its ID) */
5
+ audio: InputMediaAudio | InputDocumentId;
6
+ /** Optionally, document ID after which we should insert the music */
7
+ after?: InputDocumentId;
8
+ /**
9
+ * Upload progress callback
10
+ *
11
+ * @param uploaded Number of bytes uploaded
12
+ * @param total Total file size
13
+ */
14
+ progressCallback?: (uploaded: number, total: number) => void;
15
+ }): Promise<void>;
16
+ export declare function unsaveMusicFromProfile(client: ITelegramClient, params: {
17
+ /** ID of the Audio file to unsave */
18
+ audio: InputDocumentId;
19
+ }): Promise<void>;
@@ -0,0 +1,19 @@
1
+ import { ITelegramClient } from '../../client.types.js';
2
+ import { InputDocumentId, InputMediaAudio } from '../../types/index.js';
3
+ export declare function saveMusicToProfile(client: ITelegramClient, params: {
4
+ /** Audio file to save (or its ID) */
5
+ audio: InputMediaAudio | InputDocumentId;
6
+ /** Optionally, document ID after which we should insert the music */
7
+ after?: InputDocumentId;
8
+ /**
9
+ * Upload progress callback
10
+ *
11
+ * @param uploaded Number of bytes uploaded
12
+ * @param total Total file size
13
+ */
14
+ progressCallback?: (uploaded: number, total: number) => void;
15
+ }): Promise<void>;
16
+ export declare function unsaveMusicFromProfile(client: ITelegramClient, params: {
17
+ /** ID of the Audio file to unsave */
18
+ audio: InputDocumentId;
19
+ }): Promise<void>;