@mtcute/core 0.27.2 → 0.27.4

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 (139) hide show
  1. package/client.cjs +80 -68
  2. package/client.js +80 -68
  3. package/highlevel/base.cjs +4 -0
  4. package/highlevel/base.d.cts +1 -0
  5. package/highlevel/base.d.ts +1 -0
  6. package/highlevel/base.js +4 -0
  7. package/highlevel/client.d.cts +484 -420
  8. package/highlevel/client.d.ts +484 -420
  9. package/highlevel/methods/files/download-iterable.cjs +4 -0
  10. package/highlevel/methods/files/download-iterable.d.cts +11 -1
  11. package/highlevel/methods/files/download-iterable.d.ts +11 -1
  12. package/highlevel/methods/files/download-iterable.js +4 -0
  13. package/highlevel/methods/files/download-stream.cjs +14 -0
  14. package/highlevel/methods/files/download-stream.d.cts +13 -2
  15. package/highlevel/methods/files/download-stream.d.ts +13 -2
  16. package/highlevel/methods/files/download-stream.js +14 -0
  17. package/highlevel/methods/gifts/get-star-gift-upgrade-options.cjs +30 -0
  18. package/highlevel/methods/gifts/get-star-gift-upgrade-options.d.cts +12 -0
  19. package/highlevel/methods/gifts/get-star-gift-upgrade-options.d.ts +12 -0
  20. package/highlevel/methods/gifts/get-star-gift-upgrade-options.js +25 -0
  21. package/highlevel/methods/gifts/resolve-star-gift-offer.cjs +17 -0
  22. package/highlevel/methods/gifts/resolve-star-gift-offer.d.cts +18 -0
  23. package/highlevel/methods/gifts/resolve-star-gift-offer.d.ts +18 -0
  24. package/highlevel/methods/gifts/resolve-star-gift-offer.js +12 -0
  25. package/highlevel/methods/gifts/send-star-gift-offer.cjs +26 -0
  26. package/highlevel/methods/gifts/send-star-gift-offer.d.cts +26 -0
  27. package/highlevel/methods/gifts/send-star-gift-offer.d.ts +26 -0
  28. package/highlevel/methods/gifts/send-star-gift-offer.js +21 -0
  29. package/highlevel/methods/{premium → gifts}/set-gift-resale-price.cjs +2 -5
  30. package/highlevel/methods/{premium → gifts}/set-gift-resale-price.d.cts +2 -2
  31. package/highlevel/methods/{premium → gifts}/set-gift-resale-price.d.ts +2 -2
  32. package/highlevel/methods/{premium → gifts}/set-gift-resale-price.js +2 -5
  33. package/highlevel/methods/premium/_normalize-stars-amount.cjs +18 -0
  34. package/highlevel/methods/premium/_normalize-stars-amount.d.cts +12 -0
  35. package/highlevel/methods/premium/_normalize-stars-amount.d.ts +12 -0
  36. package/highlevel/methods/premium/_normalize-stars-amount.js +13 -0
  37. package/highlevel/methods.d.cts +23 -18
  38. package/highlevel/methods.d.ts +23 -18
  39. package/highlevel/types/media/document-utils.cjs +1 -1
  40. package/highlevel/types/media/document-utils.js +1 -1
  41. package/highlevel/types/media/voice.cjs +6 -1
  42. package/highlevel/types/media/voice.d.cts +4 -1
  43. package/highlevel/types/media/voice.d.ts +4 -1
  44. package/highlevel/types/media/voice.js +6 -1
  45. package/highlevel/types/messages/message-action.cjs +27 -4
  46. package/highlevel/types/messages/message-action.d.cts +28 -1
  47. package/highlevel/types/messages/message-action.d.ts +28 -1
  48. package/highlevel/types/messages/message-action.js +27 -4
  49. package/highlevel/types/premium/saved-star-gift.cjs +4 -0
  50. package/highlevel/types/premium/saved-star-gift.d.cts +2 -0
  51. package/highlevel/types/premium/saved-star-gift.d.ts +2 -0
  52. package/highlevel/types/premium/saved-star-gift.js +4 -0
  53. package/highlevel/types/premium/star-gift-unique.cjs +8 -0
  54. package/highlevel/types/premium/star-gift-unique.d.cts +4 -0
  55. package/highlevel/types/premium/star-gift-unique.d.ts +4 -0
  56. package/highlevel/types/premium/star-gift-unique.js +8 -0
  57. package/highlevel/types/premium/star-gift.cjs +12 -3
  58. package/highlevel/types/premium/star-gift.d.cts +5 -0
  59. package/highlevel/types/premium/star-gift.d.ts +5 -0
  60. package/highlevel/types/premium/star-gift.js +12 -3
  61. package/highlevel/types/premium/stars-transaction.cjs +6 -0
  62. package/highlevel/types/premium/stars-transaction.d.cts +6 -0
  63. package/highlevel/types/premium/stars-transaction.d.ts +6 -0
  64. package/highlevel/types/premium/stars-transaction.js +6 -0
  65. package/highlevel/updates/manager.cjs +7 -0
  66. package/highlevel/updates/manager.js +7 -0
  67. package/methods.cjs +40 -34
  68. package/methods.js +23 -17
  69. package/network/middlewares/internal-errors.cjs +5 -0
  70. package/network/middlewares/internal-errors.js +5 -0
  71. package/network/network-manager.cjs +1 -1
  72. package/network/network-manager.js +1 -1
  73. package/package.json +2 -2
  74. package/utils/binary/compat.cjs +12 -0
  75. package/utils/binary/compat.js +12 -0
  76. /package/highlevel/methods/{premium → gifts}/_normalize-input-star-gift.cjs +0 -0
  77. /package/highlevel/methods/{premium → gifts}/_normalize-input-star-gift.d.cts +0 -0
  78. /package/highlevel/methods/{premium → gifts}/_normalize-input-star-gift.d.ts +0 -0
  79. /package/highlevel/methods/{premium → gifts}/_normalize-input-star-gift.js +0 -0
  80. /package/highlevel/methods/{premium → gifts}/accept-star-gift.cjs +0 -0
  81. /package/highlevel/methods/{premium → gifts}/accept-star-gift.d.cts +0 -0
  82. /package/highlevel/methods/{premium → gifts}/accept-star-gift.d.ts +0 -0
  83. /package/highlevel/methods/{premium → gifts}/accept-star-gift.js +0 -0
  84. /package/highlevel/methods/{premium → gifts}/buy-resale-gift.cjs +0 -0
  85. /package/highlevel/methods/{premium → gifts}/buy-resale-gift.d.cts +0 -0
  86. /package/highlevel/methods/{premium → gifts}/buy-resale-gift.d.ts +0 -0
  87. /package/highlevel/methods/{premium → gifts}/buy-resale-gift.js +0 -0
  88. /package/highlevel/methods/{premium → gifts}/get-resale-star-gifts.cjs +0 -0
  89. /package/highlevel/methods/{premium → gifts}/get-resale-star-gifts.d.cts +0 -0
  90. /package/highlevel/methods/{premium → gifts}/get-resale-star-gifts.d.ts +0 -0
  91. /package/highlevel/methods/{premium → gifts}/get-resale-star-gifts.js +0 -0
  92. /package/highlevel/methods/{premium → gifts}/get-saved-star-gifts-by-id.cjs +0 -0
  93. /package/highlevel/methods/{premium → gifts}/get-saved-star-gifts-by-id.d.cts +0 -0
  94. /package/highlevel/methods/{premium → gifts}/get-saved-star-gifts-by-id.d.ts +0 -0
  95. /package/highlevel/methods/{premium → gifts}/get-saved-star-gifts-by-id.js +0 -0
  96. /package/highlevel/methods/{premium → gifts}/get-saved-star-gifts.cjs +0 -0
  97. /package/highlevel/methods/{premium → gifts}/get-saved-star-gifts.d.cts +0 -0
  98. /package/highlevel/methods/{premium → gifts}/get-saved-star-gifts.d.ts +0 -0
  99. /package/highlevel/methods/{premium → gifts}/get-saved-star-gifts.js +0 -0
  100. /package/highlevel/methods/{premium → gifts}/get-star-gift-options.cjs +0 -0
  101. /package/highlevel/methods/{premium → gifts}/get-star-gift-options.d.cts +0 -0
  102. /package/highlevel/methods/{premium → gifts}/get-star-gift-options.d.ts +0 -0
  103. /package/highlevel/methods/{premium → gifts}/get-star-gift-options.js +0 -0
  104. /package/highlevel/methods/{premium → gifts}/get-star-gift-value.cjs +0 -0
  105. /package/highlevel/methods/{premium → gifts}/get-star-gift-value.d.cts +0 -0
  106. /package/highlevel/methods/{premium → gifts}/get-star-gift-value.d.ts +0 -0
  107. /package/highlevel/methods/{premium → gifts}/get-star-gift-value.js +0 -0
  108. /package/highlevel/methods/{premium → gifts}/get-star-gift-withdrawal-url.cjs +0 -0
  109. /package/highlevel/methods/{premium → gifts}/get-star-gift-withdrawal-url.d.cts +0 -0
  110. /package/highlevel/methods/{premium → gifts}/get-star-gift-withdrawal-url.d.ts +0 -0
  111. /package/highlevel/methods/{premium → gifts}/get-star-gift-withdrawal-url.js +0 -0
  112. /package/highlevel/methods/{premium → gifts}/get-unique-star-gift.cjs +0 -0
  113. /package/highlevel/methods/{premium → gifts}/get-unique-star-gift.d.cts +0 -0
  114. /package/highlevel/methods/{premium → gifts}/get-unique-star-gift.d.ts +0 -0
  115. /package/highlevel/methods/{premium → gifts}/get-unique-star-gift.js +0 -0
  116. /package/highlevel/methods/{premium → gifts}/iter-saved-star-gifts.cjs +0 -0
  117. /package/highlevel/methods/{premium → gifts}/iter-saved-star-gifts.d.cts +0 -0
  118. /package/highlevel/methods/{premium → gifts}/iter-saved-star-gifts.d.ts +0 -0
  119. /package/highlevel/methods/{premium → gifts}/iter-saved-star-gifts.js +0 -0
  120. /package/highlevel/methods/{premium → gifts}/pin-star-gift.cjs +0 -0
  121. /package/highlevel/methods/{premium → gifts}/pin-star-gift.d.cts +0 -0
  122. /package/highlevel/methods/{premium → gifts}/pin-star-gift.d.ts +0 -0
  123. /package/highlevel/methods/{premium → gifts}/pin-star-gift.js +0 -0
  124. /package/highlevel/methods/{premium → gifts}/prepay-star-gift-upgrade.cjs +0 -0
  125. /package/highlevel/methods/{premium → gifts}/prepay-star-gift-upgrade.d.cts +0 -0
  126. /package/highlevel/methods/{premium → gifts}/prepay-star-gift-upgrade.d.ts +0 -0
  127. /package/highlevel/methods/{premium → gifts}/prepay-star-gift-upgrade.js +0 -0
  128. /package/highlevel/methods/{premium → gifts}/send-star-gift.cjs +0 -0
  129. /package/highlevel/methods/{premium → gifts}/send-star-gift.d.cts +0 -0
  130. /package/highlevel/methods/{premium → gifts}/send-star-gift.d.ts +0 -0
  131. /package/highlevel/methods/{premium → gifts}/send-star-gift.js +0 -0
  132. /package/highlevel/methods/{premium → gifts}/transfer-star-gift.cjs +0 -0
  133. /package/highlevel/methods/{premium → gifts}/transfer-star-gift.d.cts +0 -0
  134. /package/highlevel/methods/{premium → gifts}/transfer-star-gift.d.ts +0 -0
  135. /package/highlevel/methods/{premium → gifts}/transfer-star-gift.js +0 -0
  136. /package/highlevel/methods/{premium → gifts}/upgrade-star-gift.cjs +0 -0
  137. /package/highlevel/methods/{premium → gifts}/upgrade-star-gift.d.cts +0 -0
  138. /package/highlevel/methods/{premium → gifts}/upgrade-star-gift.d.ts +0 -0
  139. /package/highlevel/methods/{premium → gifts}/upgrade-star-gift.js +0 -0
@@ -121,6 +121,10 @@ async function* downloadAsIterable(client, input, params) {
121
121
  if (ended) {
122
122
  return;
123
123
  }
124
+ const throttlePromise = params?.throttle?.(chunkSize);
125
+ if (throttlePromise) {
126
+ await throttlePromise;
127
+ }
124
128
  try {
125
129
  result = await client.call(
126
130
  {
@@ -1,3 +1,4 @@
1
+ import { MaybePromise } from '@fuman/utils';
1
2
  import { ITelegramClient } from '../../client.types.js';
2
3
  import { FileDownloadLocation, FileDownloadParameters } from '../../types/index.js';
3
4
  import { tl } from '@mtcute/tl';
@@ -13,4 +14,13 @@ export declare function _normalizeFileDownloadLocation(client: ITelegramClient,
13
14
  *
14
15
  * @param params Download parameters
15
16
  */
16
- export declare function downloadAsIterable(client: ITelegramClient, input: FileDownloadLocation, params?: FileDownloadParameters): AsyncIterableIterator<Uint8Array>;
17
+ export declare function downloadAsIterable(client: ITelegramClient, input: FileDownloadLocation, params?: FileDownloadParameters & {
18
+ /**
19
+ * A function to apply backpressure to the download.
20
+ *
21
+ * If the consumer isn't keeping up, the function is supposed to return a promise that resolves when the consumer is ready to receive more data.
22
+ *
23
+ * Note that this function will likely get called multiple times simultaneously, since the download is parallelized.
24
+ */
25
+ throttle?: (chunkSize: number) => MaybePromise<void>;
26
+ }): AsyncIterableIterator<Uint8Array>;
@@ -1,3 +1,4 @@
1
+ import { MaybePromise } from '@fuman/utils';
1
2
  import { ITelegramClient } from '../../client.types.js';
2
3
  import { FileDownloadLocation, FileDownloadParameters } from '../../types/index.js';
3
4
  import { tl } from '@mtcute/tl';
@@ -13,4 +14,13 @@ export declare function _normalizeFileDownloadLocation(client: ITelegramClient,
13
14
  *
14
15
  * @param params Download parameters
15
16
  */
16
- export declare function downloadAsIterable(client: ITelegramClient, input: FileDownloadLocation, params?: FileDownloadParameters): AsyncIterableIterator<Uint8Array>;
17
+ export declare function downloadAsIterable(client: ITelegramClient, input: FileDownloadLocation, params?: FileDownloadParameters & {
18
+ /**
19
+ * A function to apply backpressure to the download.
20
+ *
21
+ * If the consumer isn't keeping up, the function is supposed to return a promise that resolves when the consumer is ready to receive more data.
22
+ *
23
+ * Note that this function will likely get called multiple times simultaneously, since the download is parallelized.
24
+ */
25
+ throttle?: (chunkSize: number) => MaybePromise<void>;
26
+ }): AsyncIterableIterator<Uint8Array>;
@@ -114,6 +114,10 @@ async function* downloadAsIterable(client, input, params) {
114
114
  if (ended) {
115
115
  return;
116
116
  }
117
+ const throttlePromise = params?.throttle?.(chunkSize);
118
+ if (throttlePromise) {
119
+ await throttlePromise;
120
+ }
117
121
  try {
118
122
  result = await client.call(
119
123
  {
@@ -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 utils = require("@fuman/utils");
8
9
  const downloadIterable = require("./download-iterable.cjs");
9
10
  const fileLocation = require("../../types/files/file-location.cjs");
10
11
  function downloadAsStream(client, location, params) {
@@ -23,18 +24,31 @@ function downloadAsStream(client, location, params) {
23
24
  cancel.abort();
24
25
  });
25
26
  }
27
+ const backpressureCv = new utils.ConditionVariable();
26
28
  return new ReadableStream({
27
29
  start(controller) {
28
30
  (async () => {
31
+ const params_ = params ?? {};
32
+ params_.throttle = () => {
33
+ if (controller.desiredSize != null && controller.desiredSize <= 0) {
34
+ return backpressureCv.wait();
35
+ }
36
+ };
29
37
  for await (const chunk of downloadIterable.downloadAsIterable(client, location, params)) {
30
38
  controller.enqueue(chunk);
31
39
  }
32
40
  controller.close();
33
41
  })().catch((e) => controller.error(e));
34
42
  },
43
+ pull() {
44
+ backpressureCv.notify();
45
+ },
35
46
  cancel() {
36
47
  cancel.abort();
37
48
  }
49
+ }, {
50
+ highWaterMark: params?.highWaterMark,
51
+ size: (chunk) => chunk?.length ?? 0
38
52
  });
39
53
  }
40
54
  exports.downloadAsStream = downloadAsStream;
@@ -1,9 +1,20 @@
1
1
  import { ITelegramClient } from '../../client.types.js';
2
2
  import { FileDownloadLocation, FileDownloadParameters } from '../../types/index.js';
3
3
  /**
4
- * Download a file and return it as a `@fuman/io` stream,
4
+ * Download a file and return it as a Web Stream,
5
5
  * streaming file contents.
6
6
  *
7
7
  * @param params File download parameters
8
8
  */
9
- export declare function downloadAsStream(client: ITelegramClient, location: FileDownloadLocation, params?: FileDownloadParameters): ReadableStream<Uint8Array>;
9
+ export declare function downloadAsStream(client: ITelegramClient, location: FileDownloadLocation, params?: FileDownloadParameters & {
10
+ /**
11
+ * If passed, the maximum number of bytes that can be buffered in the stream.
12
+ *
13
+ * If the consumer isn't keeping up, the stream will pause until the buffer is below this limit.
14
+ *
15
+ * Note that this parameter is not guaranteed to be strictly the maximum number of bytes
16
+ * buffered at once, since the underlying download is parallelized, and is treated merely as a hint.
17
+ * The actual number of bytes buffered at once can be as much as `partSize * numWorkers`
18
+ */
19
+ highWaterMark?: number;
20
+ }): ReadableStream<Uint8Array>;
@@ -1,9 +1,20 @@
1
1
  import { ITelegramClient } from '../../client.types.js';
2
2
  import { FileDownloadLocation, FileDownloadParameters } from '../../types/index.js';
3
3
  /**
4
- * Download a file and return it as a `@fuman/io` stream,
4
+ * Download a file and return it as a Web Stream,
5
5
  * streaming file contents.
6
6
  *
7
7
  * @param params File download parameters
8
8
  */
9
- export declare function downloadAsStream(client: ITelegramClient, location: FileDownloadLocation, params?: FileDownloadParameters): ReadableStream<Uint8Array>;
9
+ export declare function downloadAsStream(client: ITelegramClient, location: FileDownloadLocation, params?: FileDownloadParameters & {
10
+ /**
11
+ * If passed, the maximum number of bytes that can be buffered in the stream.
12
+ *
13
+ * If the consumer isn't keeping up, the stream will pause until the buffer is below this limit.
14
+ *
15
+ * Note that this parameter is not guaranteed to be strictly the maximum number of bytes
16
+ * buffered at once, since the underlying download is parallelized, and is treated merely as a hint.
17
+ * The actual number of bytes buffered at once can be as much as `partSize * numWorkers`
18
+ */
19
+ highWaterMark?: number;
20
+ }): ReadableStream<Uint8Array>;
@@ -1,3 +1,4 @@
1
+ import { ConditionVariable } from "@fuman/utils";
1
2
  import { downloadAsIterable } from "./download-iterable.js";
2
3
  import { FileLocation as FileLocation$1 } from "../../types/files/file-location.js";
3
4
  function downloadAsStream(client, location, params) {
@@ -16,18 +17,31 @@ function downloadAsStream(client, location, params) {
16
17
  cancel.abort();
17
18
  });
18
19
  }
20
+ const backpressureCv = new ConditionVariable();
19
21
  return new ReadableStream({
20
22
  start(controller) {
21
23
  (async () => {
24
+ const params_ = params ?? {};
25
+ params_.throttle = () => {
26
+ if (controller.desiredSize != null && controller.desiredSize <= 0) {
27
+ return backpressureCv.wait();
28
+ }
29
+ };
22
30
  for await (const chunk of downloadAsIterable(client, location, params)) {
23
31
  controller.enqueue(chunk);
24
32
  }
25
33
  controller.close();
26
34
  })().catch((e) => controller.error(e));
27
35
  },
36
+ pull() {
37
+ backpressureCv.notify();
38
+ },
28
39
  cancel() {
29
40
  cancel.abort();
30
41
  }
42
+ }, {
43
+ highWaterMark: params?.highWaterMark,
44
+ size: (chunk) => chunk?.length ?? 0
31
45
  });
32
46
  }
33
47
  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 starGiftUnique = require("../../types/premium/star-gift-unique.cjs");
9
+ async function getStarGiftUpgradeOptions(client, giftId) {
10
+ const res = await client.call({
11
+ _: "payments.getStarGiftUpgradeAttributes",
12
+ giftId
13
+ });
14
+ const ret = {
15
+ models: [],
16
+ patterns: [],
17
+ backdrops: []
18
+ };
19
+ for (const attr of res.attributes) {
20
+ if (attr._ === "starGiftAttributeModel") {
21
+ ret.models.push(new starGiftUnique.StarGiftUniqueAttribute(attr));
22
+ } else if (attr._ === "starGiftAttributePattern") {
23
+ ret.patterns.push(new starGiftUnique.StarGiftUniqueAttribute(attr));
24
+ } else if (attr._ === "starGiftAttributeBackdrop") {
25
+ ret.backdrops.push(new starGiftUnique.StarGiftUniqueBackdrop(attr));
26
+ }
27
+ }
28
+ return ret;
29
+ }
30
+ exports.getStarGiftUpgradeOptions = getStarGiftUpgradeOptions;
@@ -0,0 +1,12 @@
1
+ import { tl } from '@mtcute/tl';
2
+ import { ITelegramClient } from '../../client.types.js';
3
+ import { StarGiftUniqueAttribute, StarGiftUniqueBackdrop } from '../../types/index.js';
4
+ export interface StarGiftUpgradeOptions {
5
+ models: StarGiftUniqueAttribute[];
6
+ patterns: StarGiftUniqueAttribute[];
7
+ backdrops: StarGiftUniqueBackdrop[];
8
+ }
9
+ /**
10
+ * Get a list of all possible attributes when upgrading a given star gift
11
+ */
12
+ export declare function getStarGiftUpgradeOptions(client: ITelegramClient, giftId: tl.Long): Promise<StarGiftUpgradeOptions>;
@@ -0,0 +1,12 @@
1
+ import { tl } from '@mtcute/tl';
2
+ import { ITelegramClient } from '../../client.types.js';
3
+ import { StarGiftUniqueAttribute, StarGiftUniqueBackdrop } from '../../types/index.js';
4
+ export interface StarGiftUpgradeOptions {
5
+ models: StarGiftUniqueAttribute[];
6
+ patterns: StarGiftUniqueAttribute[];
7
+ backdrops: StarGiftUniqueBackdrop[];
8
+ }
9
+ /**
10
+ * Get a list of all possible attributes when upgrading a given star gift
11
+ */
12
+ export declare function getStarGiftUpgradeOptions(client: ITelegramClient, giftId: tl.Long): Promise<StarGiftUpgradeOptions>;
@@ -0,0 +1,25 @@
1
+ import { StarGiftUniqueAttribute as StarGiftUniqueAttribute$2, StarGiftUniqueBackdrop as StarGiftUniqueBackdrop$1 } from "../../types/premium/star-gift-unique.js";
2
+ async function getStarGiftUpgradeOptions(client, giftId) {
3
+ const res = await client.call({
4
+ _: "payments.getStarGiftUpgradeAttributes",
5
+ giftId
6
+ });
7
+ const ret = {
8
+ models: [],
9
+ patterns: [],
10
+ backdrops: []
11
+ };
12
+ for (const attr of res.attributes) {
13
+ if (attr._ === "starGiftAttributeModel") {
14
+ ret.models.push(new StarGiftUniqueAttribute$2(attr));
15
+ } else if (attr._ === "starGiftAttributePattern") {
16
+ ret.patterns.push(new StarGiftUniqueAttribute$2(attr));
17
+ } else if (attr._ === "starGiftAttributeBackdrop") {
18
+ ret.backdrops.push(new StarGiftUniqueBackdrop$1(attr));
19
+ }
20
+ }
21
+ return ret;
22
+ }
23
+ export {
24
+ getStarGiftUpgradeOptions
25
+ };
@@ -0,0 +1,17 @@
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 findInUpdate = require("../messages/find-in-update.cjs");
9
+ async function resolveStarGiftOffer(client, options) {
10
+ const { message, shouldDispatch } = options;
11
+ const res = await client.call({
12
+ _: "payments.resolveStarGiftOffer",
13
+ offerMsgId: message
14
+ });
15
+ return findInUpdate._findMessageInUpdate(client, res, false, !shouldDispatch, false);
16
+ }
17
+ exports.resolveStarGiftOffer = resolveStarGiftOffer;
@@ -0,0 +1,18 @@
1
+ import { ITelegramClient } from '../../client.types.js';
2
+ import { Message } from '../../types/index.js';
3
+ /**
4
+ * Accept or decline a purchase offer for a star gift
5
+ *
6
+ * @returns The generated service message
7
+ */
8
+ export declare function resolveStarGiftOffer(client: ITelegramClient, options: {
9
+ /** ID of the message containing the offer */
10
+ message: number;
11
+ /** Whether to accept or decline the offer */
12
+ action: 'accept' | 'decline';
13
+ /**
14
+ * Whether to dispatch the new message event
15
+ * to the client's update handler.
16
+ */
17
+ shouldDispatch?: true;
18
+ }): Promise<Message>;
@@ -0,0 +1,18 @@
1
+ import { ITelegramClient } from '../../client.types.js';
2
+ import { Message } from '../../types/index.js';
3
+ /**
4
+ * Accept or decline a purchase offer for a star gift
5
+ *
6
+ * @returns The generated service message
7
+ */
8
+ export declare function resolveStarGiftOffer(client: ITelegramClient, options: {
9
+ /** ID of the message containing the offer */
10
+ message: number;
11
+ /** Whether to accept or decline the offer */
12
+ action: 'accept' | 'decline';
13
+ /**
14
+ * Whether to dispatch the new message event
15
+ * to the client's update handler.
16
+ */
17
+ shouldDispatch?: true;
18
+ }): Promise<Message>;
@@ -0,0 +1,12 @@
1
+ import { _findMessageInUpdate } from "../messages/find-in-update.js";
2
+ async function resolveStarGiftOffer(client, options) {
3
+ const { message, shouldDispatch } = options;
4
+ const res = await client.call({
5
+ _: "payments.resolveStarGiftOffer",
6
+ offerMsgId: message
7
+ });
8
+ return _findMessageInUpdate(client, res, false, !shouldDispatch, false);
9
+ }
10
+ export {
11
+ resolveStarGiftOffer
12
+ };
@@ -0,0 +1,26 @@
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 longUtils = require("../../../utils/long-utils.cjs");
9
+ const findInUpdate = require("../messages/find-in-update.cjs");
10
+ const _normalizeStarsAmount = require("../premium/_normalize-stars-amount.cjs");
11
+ const resolvePeer = require("../users/resolve-peer.cjs");
12
+ async function sendStarGiftOffer(client, params) {
13
+ const { peerId, slug, price, duration, allowPaidMessages, shouldDispatch } = params;
14
+ const randomId = longUtils.randomLong();
15
+ const res = await client.call({
16
+ _: "payments.sendStarGiftOffer",
17
+ peer: await resolvePeer.resolvePeer(client, peerId),
18
+ slug,
19
+ price: _normalizeStarsAmount._normalizeStarsAmount(price),
20
+ duration,
21
+ randomId,
22
+ allowPaidStars: allowPaidMessages
23
+ });
24
+ return findInUpdate._findMessageInUpdate(client, res, false, !shouldDispatch, false, randomId);
25
+ }
26
+ exports.sendStarGiftOffer = sendStarGiftOffer;
@@ -0,0 +1,26 @@
1
+ import { tl } from '@mtcute/tl';
2
+ import { ITelegramClient } from '../../client.types.js';
3
+ import { InputPeerLike, Message } from '../../types/index.js';
4
+ import { InputStarsAmount } from '../premium/_normalize-stars-amount.js';
5
+ /**
6
+ * Create a purchase offer for a unique star gift
7
+ * @param client
8
+ * @param params
9
+ */
10
+ export declare function sendStarGiftOffer(client: ITelegramClient, params: {
11
+ /** ID of the peer to send the offer to */
12
+ peerId: InputPeerLike;
13
+ /** Slug of the star gift to create an offer for */
14
+ slug: string;
15
+ /** Amount of stars to offer */
16
+ price: InputStarsAmount;
17
+ /** Duration of the offer in seconds */
18
+ duration: number;
19
+ /** When the recipient has paid messages enabled, the maximum number of stars that you are willing to spend */
20
+ allowPaidMessages?: tl.Long;
21
+ /**
22
+ * Whether to dispatch the new message event
23
+ * to the client's update handler.
24
+ */
25
+ shouldDispatch?: true;
26
+ }): Promise<Message>;
@@ -0,0 +1,26 @@
1
+ import { tl } from '@mtcute/tl';
2
+ import { ITelegramClient } from '../../client.types.js';
3
+ import { InputPeerLike, Message } from '../../types/index.js';
4
+ import { InputStarsAmount } from '../premium/_normalize-stars-amount.js';
5
+ /**
6
+ * Create a purchase offer for a unique star gift
7
+ * @param client
8
+ * @param params
9
+ */
10
+ export declare function sendStarGiftOffer(client: ITelegramClient, params: {
11
+ /** ID of the peer to send the offer to */
12
+ peerId: InputPeerLike;
13
+ /** Slug of the star gift to create an offer for */
14
+ slug: string;
15
+ /** Amount of stars to offer */
16
+ price: InputStarsAmount;
17
+ /** Duration of the offer in seconds */
18
+ duration: number;
19
+ /** When the recipient has paid messages enabled, the maximum number of stars that you are willing to spend */
20
+ allowPaidMessages?: tl.Long;
21
+ /**
22
+ * Whether to dispatch the new message event
23
+ * to the client's update handler.
24
+ */
25
+ shouldDispatch?: true;
26
+ }): Promise<Message>;
@@ -0,0 +1,21 @@
1
+ import { randomLong } from "../../../utils/long-utils.js";
2
+ import { _findMessageInUpdate } from "../messages/find-in-update.js";
3
+ import { _normalizeStarsAmount } from "../premium/_normalize-stars-amount.js";
4
+ import { resolvePeer } from "../users/resolve-peer.js";
5
+ async function sendStarGiftOffer(client, params) {
6
+ const { peerId, slug, price, duration, allowPaidMessages, shouldDispatch } = params;
7
+ const randomId = randomLong();
8
+ const res = await client.call({
9
+ _: "payments.sendStarGiftOffer",
10
+ peer: await resolvePeer(client, peerId),
11
+ slug,
12
+ price: _normalizeStarsAmount(price),
13
+ duration,
14
+ randomId,
15
+ allowPaidStars: allowPaidMessages
16
+ });
17
+ return _findMessageInUpdate(client, res, false, !shouldDispatch, false, randomId);
18
+ }
19
+ export {
20
+ sendStarGiftOffer
21
+ };
@@ -6,18 +6,15 @@ 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 Long = require("long");
9
+ const _normalizeStarsAmount = require("../premium/_normalize-stars-amount.cjs");
9
10
  const _normalizeInputStarGift = require("./_normalize-input-star-gift.cjs");
10
11
  async function setResaleStarGiftPrice(client, params) {
11
12
  const { gift, price } = params;
12
13
  let starsAmount;
13
14
  if (price === null) {
14
15
  starsAmount = { _: "starsAmount", amount: Long.ZERO, nanos: 0 };
15
- } else if (typeof price === "number") {
16
- starsAmount = { _: "starsAmount", amount: Long.fromNumber(price), nanos: 0 };
17
- } else if (Long.isLong(price)) {
18
- starsAmount = { _: "starsAmount", amount: price, nanos: 0 };
19
16
  } else {
20
- starsAmount = price;
17
+ starsAmount = _normalizeStarsAmount._normalizeStarsAmount(price);
21
18
  }
22
19
  const r = await client.call({
23
20
  _: "payments.updateStarGiftPrice",
@@ -1,6 +1,6 @@
1
- import { tl } from '@mtcute/tl';
2
1
  import { ITelegramClient } from '../../client.types.js';
3
2
  import { InputStarGift } from '../../types/index.js';
3
+ import { InputStarsAmount } from '../premium/_normalize-stars-amount.js';
4
4
  /** Set resale price for an owned star gift */
5
5
  export declare function setResaleStarGiftPrice(client: ITelegramClient, params: {
6
6
  /** Star gift to update the price of */
@@ -8,5 +8,5 @@ export declare function setResaleStarGiftPrice(client: ITelegramClient, params:
8
8
  /**
9
9
  * New price of the gift (in stars), or `null` to unlist
10
10
  */
11
- price: tl.Long | number | tl.TypeStarsAmount | null;
11
+ price: InputStarsAmount | null;
12
12
  }): Promise<void>;
@@ -1,6 +1,6 @@
1
- import { tl } from '@mtcute/tl';
2
1
  import { ITelegramClient } from '../../client.types.js';
3
2
  import { InputStarGift } from '../../types/index.js';
3
+ import { InputStarsAmount } from '../premium/_normalize-stars-amount.js';
4
4
  /** Set resale price for an owned star gift */
5
5
  export declare function setResaleStarGiftPrice(client: ITelegramClient, params: {
6
6
  /** Star gift to update the price of */
@@ -8,5 +8,5 @@ export declare function setResaleStarGiftPrice(client: ITelegramClient, params:
8
8
  /**
9
9
  * New price of the gift (in stars), or `null` to unlist
10
10
  */
11
- price: tl.Long | number | tl.TypeStarsAmount | null;
11
+ price: InputStarsAmount | null;
12
12
  }): Promise<void>;
@@ -1,16 +1,13 @@
1
1
  import Long from "long";
2
+ import { _normalizeStarsAmount } from "../premium/_normalize-stars-amount.js";
2
3
  import { _normalizeInputStarGift } from "./_normalize-input-star-gift.js";
3
4
  async function setResaleStarGiftPrice(client, params) {
4
5
  const { gift, price } = params;
5
6
  let starsAmount;
6
7
  if (price === null) {
7
8
  starsAmount = { _: "starsAmount", amount: Long.ZERO, nanos: 0 };
8
- } else if (typeof price === "number") {
9
- starsAmount = { _: "starsAmount", amount: Long.fromNumber(price), nanos: 0 };
10
- } else if (Long.isLong(price)) {
11
- starsAmount = { _: "starsAmount", amount: price, nanos: 0 };
12
9
  } else {
13
- starsAmount = price;
10
+ starsAmount = _normalizeStarsAmount(price);
14
11
  }
15
12
  const r = await client.call({
16
13
  _: "payments.updateStarGiftPrice",
@@ -0,0 +1,18 @@
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 Long = require("long");
9
+ function _normalizeStarsAmount(amount) {
10
+ if (typeof amount === "number") {
11
+ return { _: "starsAmount", amount: Long.fromNumber(amount), nanos: 0 };
12
+ } else if (Long.isLong(amount)) {
13
+ return { _: "starsAmount", amount, nanos: 0 };
14
+ } else {
15
+ return amount;
16
+ }
17
+ }
18
+ exports._normalizeStarsAmount = _normalizeStarsAmount;
@@ -0,0 +1,12 @@
1
+ import { tl } from '@mtcute/tl';
2
+ /**
3
+ * Defines a number of stars or a TON amount:
4
+ *
5
+ * - `number` and `Long` are considered as the exact number of stars.
6
+ * - Fractional stars should be passed explicitly as `{ _: 'starsAmount', ... }` (though i'm not sure if any methods accept that)
7
+ * - TON amounts and should be passed explicitly as `{ _: 'starsAmountTon', ... }`
8
+ *
9
+ * @exported
10
+ */
11
+ export type InputStarsAmount = tl.Long | number | tl.TypeStarsAmount;
12
+ export declare function _normalizeStarsAmount(amount: InputStarsAmount): tl.TypeStarsAmount;
@@ -0,0 +1,12 @@
1
+ import { tl } from '@mtcute/tl';
2
+ /**
3
+ * Defines a number of stars or a TON amount:
4
+ *
5
+ * - `number` and `Long` are considered as the exact number of stars.
6
+ * - Fractional stars should be passed explicitly as `{ _: 'starsAmount', ... }` (though i'm not sure if any methods accept that)
7
+ * - TON amounts and should be passed explicitly as `{ _: 'starsAmountTon', ... }`
8
+ *
9
+ * @exported
10
+ */
11
+ export type InputStarsAmount = tl.Long | number | tl.TypeStarsAmount;
12
+ export declare function _normalizeStarsAmount(amount: InputStarsAmount): tl.TypeStarsAmount;
@@ -0,0 +1,13 @@
1
+ import Long from "long";
2
+ function _normalizeStarsAmount(amount) {
3
+ if (typeof amount === "number") {
4
+ return { _: "starsAmount", amount: Long.fromNumber(amount), nanos: 0 };
5
+ } else if (Long.isLong(amount)) {
6
+ return { _: "starsAmount", amount, nanos: 0 };
7
+ } else {
8
+ return amount;
9
+ }
10
+ }
11
+ export {
12
+ _normalizeStarsAmount
13
+ };