@mtcute/core 0.23.2 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.cjs +21 -2
- package/client.js +21 -2
- package/highlevel/base.cjs +15 -3
- package/highlevel/base.d.cts +4 -1
- package/highlevel/base.d.ts +4 -1
- package/highlevel/base.js +15 -3
- package/highlevel/client.d.cts +56 -7
- package/highlevel/client.d.ts +56 -7
- package/highlevel/client.types.d.cts +2 -1
- package/highlevel/client.types.d.ts +2 -1
- package/highlevel/methods/chats/get-chat-event-log.cjs +5 -3
- package/highlevel/methods/chats/get-chat-event-log.js +3 -1
- package/highlevel/methods/files/download-iterable.cjs +1 -1
- package/highlevel/methods/files/download-iterable.js +1 -1
- package/highlevel/methods/premium/_normalize-input-star-gift.cjs +6 -0
- package/highlevel/methods/premium/_normalize-input-star-gift.js +6 -0
- package/highlevel/methods/premium/buy-resale-gift.cjs +30 -0
- package/highlevel/methods/premium/buy-resale-gift.d.cts +13 -0
- package/highlevel/methods/premium/buy-resale-gift.d.ts +13 -0
- package/highlevel/methods/premium/buy-resale-gift.js +25 -0
- package/highlevel/methods/premium/get-resale-star-gifts.cjs +107 -0
- package/highlevel/methods/premium/get-resale-star-gifts.d.cts +45 -0
- package/highlevel/methods/premium/get-resale-star-gifts.d.ts +45 -0
- package/highlevel/methods/premium/get-resale-star-gifts.js +102 -0
- package/highlevel/methods/premium/get-unique-star-gift.cjs +1 -1
- package/highlevel/methods/premium/get-unique-star-gift.js +1 -1
- package/highlevel/methods/premium/set-gift-resale-price.cjs +19 -0
- package/highlevel/methods/premium/set-gift-resale-price.d.cts +9 -0
- package/highlevel/methods/premium/set-gift-resale-price.d.ts +9 -0
- package/highlevel/methods/premium/set-gift-resale-price.js +14 -0
- package/highlevel/methods/premium/transfer-star-gift.cjs +28 -13
- package/highlevel/methods/premium/transfer-star-gift.d.cts +1 -1
- package/highlevel/methods/premium/transfer-star-gift.d.ts +1 -1
- package/highlevel/methods/premium/transfer-star-gift.js +28 -13
- package/highlevel/methods/premium/upgrade-star-gift.cjs +26 -11
- package/highlevel/methods/premium/upgrade-star-gift.js +26 -11
- package/highlevel/methods/users/resolve-peer.cjs +63 -70
- package/highlevel/methods/users/resolve-peer.d.cts +2 -1
- package/highlevel/methods/users/resolve-peer.d.ts +2 -1
- package/highlevel/methods/users/resolve-peer.js +61 -68
- package/highlevel/methods/users/resolve-phone-number.cjs +36 -0
- package/highlevel/methods/users/resolve-phone-number.d.cts +10 -0
- package/highlevel/methods/users/resolve-phone-number.d.ts +10 -0
- package/highlevel/methods/users/resolve-phone-number.js +31 -0
- package/highlevel/methods.d.cts +10 -4
- package/highlevel/methods.d.ts +10 -4
- package/highlevel/types/messages/message-action.cjs +8 -2
- package/highlevel/types/messages/message-action.d.cts +6 -0
- package/highlevel/types/messages/message-action.d.ts +6 -0
- package/highlevel/types/messages/message-action.js +8 -2
- package/highlevel/types/peers/chat-event/actions.cjs +49 -1
- package/highlevel/types/peers/chat-event/actions.d.cts +60 -2
- package/highlevel/types/peers/chat-event/actions.d.ts +60 -2
- package/highlevel/types/peers/chat-event/actions.js +49 -1
- package/highlevel/types/peers/chat-event/filters.cjs +9 -0
- package/highlevel/types/peers/chat-event/filters.js +9 -0
- package/highlevel/types/peers/chat-event/index.cjs +3 -2
- package/highlevel/types/peers/chat-event/index.d.cts +2 -1
- package/highlevel/types/peers/chat-event/index.d.ts +2 -1
- package/highlevel/types/peers/chat-event/index.js +3 -2
- package/highlevel/types/peers/chat.cjs +5 -4
- package/highlevel/types/peers/chat.d.cts +2 -0
- package/highlevel/types/peers/chat.d.ts +2 -0
- package/highlevel/types/peers/chat.js +5 -4
- package/highlevel/types/peers/peer.d.cts +2 -3
- package/highlevel/types/peers/peer.d.ts +2 -3
- package/highlevel/types/peers/user.cjs +1 -4
- package/highlevel/types/peers/user.js +1 -4
- package/highlevel/types/premium/saved-star-gift.cjs +8 -0
- package/highlevel/types/premium/saved-star-gift.d.cts +4 -0
- package/highlevel/types/premium/saved-star-gift.d.ts +4 -0
- package/highlevel/types/premium/saved-star-gift.js +8 -0
- package/highlevel/types/premium/stars-gift-unique.cjs +13 -2
- package/highlevel/types/premium/stars-gift-unique.d.cts +6 -2
- package/highlevel/types/premium/stars-gift-unique.d.ts +6 -2
- package/highlevel/types/premium/stars-gift-unique.js +13 -2
- package/highlevel/types/premium/stars-gift.cjs +11 -1
- package/highlevel/types/premium/stars-gift.d.cts +8 -1
- package/highlevel/types/premium/stars-gift.d.ts +8 -1
- package/highlevel/types/premium/stars-gift.js +11 -1
- package/highlevel/types/premium/stars-transaction.cjs +7 -1
- package/highlevel/types/premium/stars-transaction.d.cts +9 -2
- package/highlevel/types/premium/stars-transaction.d.ts +9 -2
- package/highlevel/types/premium/stars-transaction.js +7 -1
- package/highlevel/types/reactions/emoji-status.cjs +6 -0
- package/highlevel/types/reactions/emoji-status.d.cts +1 -0
- package/highlevel/types/reactions/emoji-status.d.ts +1 -0
- package/highlevel/types/reactions/emoji-status.js +6 -0
- package/highlevel/types/utils.d.cts +4 -0
- package/highlevel/types/utils.d.ts +4 -0
- package/highlevel/updates/manager.cjs +35 -26
- package/highlevel/updates/manager.d.cts +6 -6
- package/highlevel/updates/manager.d.ts +6 -6
- package/highlevel/updates/manager.js +35 -26
- package/highlevel/updates/types.d.cts +6 -6
- package/highlevel/updates/types.d.ts +6 -6
- package/highlevel/utils/misc-utils.cjs +8 -0
- package/highlevel/utils/misc-utils.d.cts +2 -1
- package/highlevel/utils/misc-utils.d.ts +2 -1
- package/highlevel/utils/misc-utils.js +8 -0
- package/highlevel/worker/port.cjs +7 -5
- package/highlevel/worker/port.d.cts +3 -2
- package/highlevel/worker/port.d.ts +3 -2
- package/highlevel/worker/port.js +7 -5
- package/methods.cjs +8 -0
- package/methods.js +8 -0
- package/network/client.cjs +12 -8
- package/network/client.d.cts +4 -1
- package/network/client.d.ts +4 -1
- package/network/client.js +12 -8
- package/network/network-manager.cjs +1 -1
- package/network/network-manager.js +1 -1
- package/network/session-connection.cjs +1 -0
- package/network/session-connection.js +1 -0
- package/package.json +2 -2
- package/utils/binary/compat.cjs +9 -0
- package/utils/binary/compat.js +9 -0
- package/utils/index.d.cts +0 -1
- package/utils/index.d.ts +0 -1
- package/utils/sorted-array.cjs +6 -0
- package/utils/sorted-array.d.cts +2 -0
- package/utils/sorted-array.d.ts +2 -0
- package/utils/sorted-array.js +6 -0
- package/utils.cjs +1 -2
- package/utils.js +2 -3
- package/utils/linked-list.cjs +0 -65
- package/utils/linked-list.d.cts +0 -21
- package/utils/linked-list.d.ts +0 -21
- package/utils/linked-list.js +0 -60
- package/utils/linked-list.test.d.cts +0 -1
- package/utils/linked-list.test.d.ts +0 -1
|
@@ -7,6 +7,12 @@ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WAR
|
|
|
7
7
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
8
|
const resolvePeer = require("../users/resolve-peer.cjs");
|
|
9
9
|
async function _normalizeInputStarGift(client, gift) {
|
|
10
|
+
if (typeof gift === "string") {
|
|
11
|
+
return {
|
|
12
|
+
_: "inputSavedStarGiftSlug",
|
|
13
|
+
slug: gift
|
|
14
|
+
};
|
|
15
|
+
}
|
|
10
16
|
if ("message" in gift) {
|
|
11
17
|
return {
|
|
12
18
|
_: "inputSavedStarGiftUser",
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { resolvePeer } from "../users/resolve-peer.js";
|
|
2
2
|
async function _normalizeInputStarGift(client, gift) {
|
|
3
|
+
if (typeof gift === "string") {
|
|
4
|
+
return {
|
|
5
|
+
_: "inputSavedStarGiftSlug",
|
|
6
|
+
slug: gift
|
|
7
|
+
};
|
|
8
|
+
}
|
|
3
9
|
if ("message" in gift) {
|
|
4
10
|
return {
|
|
5
11
|
_: "inputSavedStarGiftUser",
|
|
@@ -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 support is deprecated and will be removed in 0.25.0. 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 buyResaleGift(client, params) {
|
|
12
|
+
const { slug, recipient, shouldDispatch } = params;
|
|
13
|
+
const invoice = {
|
|
14
|
+
_: "inputInvoiceStarGiftResale",
|
|
15
|
+
slug,
|
|
16
|
+
toId: await resolvePeer.resolvePeer(client, recipient)
|
|
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.buyResaleGift = buyResaleGift;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ITelegramClient } from '../../client.types.js';
|
|
2
|
+
import { InputPeerLike, Message } from '../../types/index.js';
|
|
3
|
+
export declare function buyResaleGift(client: ITelegramClient, params: {
|
|
4
|
+
/** Slug of the star gift to buy */
|
|
5
|
+
slug: string;
|
|
6
|
+
/** ID of the user to buy the gift for */
|
|
7
|
+
recipient: InputPeerLike;
|
|
8
|
+
/**
|
|
9
|
+
* Whether to dispatch the new message event
|
|
10
|
+
* to the client's update handler.
|
|
11
|
+
*/
|
|
12
|
+
shouldDispatch?: true;
|
|
13
|
+
}): Promise<Message | null>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ITelegramClient } from '../../client.types.js';
|
|
2
|
+
import { InputPeerLike, Message } from '../../types/index.js';
|
|
3
|
+
export declare function buyResaleGift(client: ITelegramClient, params: {
|
|
4
|
+
/** Slug of the star gift to buy */
|
|
5
|
+
slug: string;
|
|
6
|
+
/** ID of the user to buy the gift for */
|
|
7
|
+
recipient: InputPeerLike;
|
|
8
|
+
/**
|
|
9
|
+
* Whether to dispatch the new message event
|
|
10
|
+
* to the client's update handler.
|
|
11
|
+
*/
|
|
12
|
+
shouldDispatch?: true;
|
|
13
|
+
}): 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 buyResaleGift(client, params) {
|
|
5
|
+
const { slug, recipient, shouldDispatch } = params;
|
|
6
|
+
const invoice = {
|
|
7
|
+
_: "inputInvoiceStarGiftResale",
|
|
8
|
+
slug,
|
|
9
|
+
toId: await resolvePeer(client, recipient)
|
|
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
|
+
buyResaleGift
|
|
25
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
2
|
+
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
3
|
+
console.warn("[@mtcute/core] CommonJS support is deprecated and will be removed in 0.25.0. 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 longUtils = require("../../../utils/long-utils.cjs");
|
|
11
|
+
const miscUtils = require("../../utils/misc-utils.cjs");
|
|
12
|
+
const starsGiftUnique = require("../../types/premium/stars-gift-unique.cjs");
|
|
13
|
+
const peersIndex = require("../../types/peers/peers-index.cjs");
|
|
14
|
+
function _normalizeResaleAttributes(attrs) {
|
|
15
|
+
if (Array.isArray(attrs)) {
|
|
16
|
+
return attrs;
|
|
17
|
+
}
|
|
18
|
+
const res = [];
|
|
19
|
+
if (attrs.model) {
|
|
20
|
+
if (Array.isArray(attrs.model)) {
|
|
21
|
+
for (const id of attrs.model) {
|
|
22
|
+
res.push({
|
|
23
|
+
_: "starGiftAttributeIdModel",
|
|
24
|
+
documentId: id
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
res.push({
|
|
29
|
+
_: "starGiftAttributeIdModel",
|
|
30
|
+
documentId: attrs.model
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (attrs.pattern) {
|
|
35
|
+
if (Array.isArray(attrs.pattern)) {
|
|
36
|
+
for (const id of attrs.pattern) {
|
|
37
|
+
res.push({
|
|
38
|
+
_: "starGiftAttributeIdPattern",
|
|
39
|
+
documentId: id
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
res.push({
|
|
44
|
+
_: "starGiftAttributeIdPattern",
|
|
45
|
+
documentId: attrs.pattern
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (attrs.backdrop) {
|
|
50
|
+
if (Array.isArray(attrs.backdrop)) {
|
|
51
|
+
for (const id of attrs.backdrop) {
|
|
52
|
+
res.push({
|
|
53
|
+
_: "starGiftAttributeIdBackdrop",
|
|
54
|
+
backdropId: id
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
res.push({
|
|
59
|
+
_: "starGiftAttributeIdBackdrop",
|
|
60
|
+
backdropId: attrs.backdrop
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return res;
|
|
65
|
+
}
|
|
66
|
+
async function getResaleOptions(client, params) {
|
|
67
|
+
const res = await client.call({
|
|
68
|
+
_: "payments.getResaleStarGifts",
|
|
69
|
+
sortByNum: params.sort === "num",
|
|
70
|
+
sortByPrice: params.sort === "price",
|
|
71
|
+
attributesHash: params.attributesHash,
|
|
72
|
+
giftId: params.giftId,
|
|
73
|
+
attributes: params.attributes ? _normalizeResaleAttributes(params.attributes) : void 0,
|
|
74
|
+
offset: params.offset ?? "",
|
|
75
|
+
limit: params.limit ?? 100
|
|
76
|
+
});
|
|
77
|
+
const peers = peersIndex.PeersIndex.from(res);
|
|
78
|
+
const attributes = {
|
|
79
|
+
model: new longUtils.LongMap(),
|
|
80
|
+
pattern: new longUtils.LongMap(),
|
|
81
|
+
backdrop: /* @__PURE__ */ new Map()
|
|
82
|
+
};
|
|
83
|
+
for (const attr of res.attributes ?? []) {
|
|
84
|
+
if (attr._ === "starGiftAttributeModel") {
|
|
85
|
+
attributes.model.set(attr.document.id, new starsGiftUnique.StarGiftUniqueAttribute(attr));
|
|
86
|
+
} else if (attr._ === "starGiftAttributePattern") {
|
|
87
|
+
attributes.pattern.set(attr.document.id, new starsGiftUnique.StarGiftUniqueAttribute(attr));
|
|
88
|
+
} else if (attr._ === "starGiftAttributeBackdrop") {
|
|
89
|
+
attributes.backdrop.set(attr.backdropId, new starsGiftUnique.StarGiftUniqueBackdrop(attr));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return miscUtils.makeArrayPaginatedWithMeta(
|
|
93
|
+
res.gifts.map((it) => {
|
|
94
|
+
utils.assert(it._ === "starGiftUnique");
|
|
95
|
+
return new starsGiftUnique.StarGiftUnique(it, peers);
|
|
96
|
+
}),
|
|
97
|
+
res.count,
|
|
98
|
+
{
|
|
99
|
+
attributes,
|
|
100
|
+
attributesHash: res.attributesHash ?? params.attributesHash ?? Long.ZERO,
|
|
101
|
+
counters: res.counters ?? []
|
|
102
|
+
},
|
|
103
|
+
res.nextOffset
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
exports._normalizeResaleAttributes = _normalizeResaleAttributes;
|
|
107
|
+
exports.getResaleOptions = getResaleOptions;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { tl } from '@mtcute/tl';
|
|
2
|
+
import { ITelegramClient } from '../../client.types.js';
|
|
3
|
+
import { ArrayPaginatedWithMeta, StarGiftUnique, StarGiftUniqueAttribute, StarGiftUniqueBackdrop } from '../../types/index.js';
|
|
4
|
+
import { MaybeArray } from '@fuman/utils';
|
|
5
|
+
import { default as Long } from 'long';
|
|
6
|
+
import { LongMap } from '../../../utils/long-utils.js';
|
|
7
|
+
export interface InputStarGiftAttributeIds {
|
|
8
|
+
model?: MaybeArray<Long>;
|
|
9
|
+
pattern?: MaybeArray<Long>;
|
|
10
|
+
backdrop?: MaybeArray<number>;
|
|
11
|
+
}
|
|
12
|
+
export declare function _normalizeResaleAttributes(attrs: tl.TypeStarGiftAttributeId[] | InputStarGiftAttributeIds): tl.TypeStarGiftAttributeId[];
|
|
13
|
+
export interface ResaleStarGiftsMeta {
|
|
14
|
+
attributes: {
|
|
15
|
+
model: LongMap<StarGiftUniqueAttribute>;
|
|
16
|
+
pattern: LongMap<StarGiftUniqueAttribute>;
|
|
17
|
+
backdrop: Map<number, StarGiftUniqueBackdrop>;
|
|
18
|
+
};
|
|
19
|
+
attributesHash: tl.Long;
|
|
20
|
+
counters: tl.RawStarGiftAttributeCounter[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get a list of star gifts up for resale
|
|
24
|
+
*/
|
|
25
|
+
export declare function getResaleOptions(client: ITelegramClient, params: {
|
|
26
|
+
/** ID of the gift to get resale options for */
|
|
27
|
+
giftId: tl.Long;
|
|
28
|
+
/**
|
|
29
|
+
* Sorting attribute
|
|
30
|
+
*
|
|
31
|
+
* - `price`: Sort by price
|
|
32
|
+
* - `num`: Sort by its unique number
|
|
33
|
+
*/
|
|
34
|
+
sort?: 'price' | 'num';
|
|
35
|
+
/**
|
|
36
|
+
* Hash of the `attributes` field, as returned by the server in the first response
|
|
37
|
+
*/
|
|
38
|
+
attributesHash?: Long;
|
|
39
|
+
/** Attributes to filter for */
|
|
40
|
+
attributes?: tl.TypeStarGiftAttributeId[] | InputStarGiftAttributeIds;
|
|
41
|
+
/** Offset for pagination */
|
|
42
|
+
offset?: string;
|
|
43
|
+
/** Limit for pagination */
|
|
44
|
+
limit?: number;
|
|
45
|
+
}): Promise<ArrayPaginatedWithMeta<StarGiftUnique, string, ResaleStarGiftsMeta>>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { tl } from '@mtcute/tl';
|
|
2
|
+
import { ITelegramClient } from '../../client.types.js';
|
|
3
|
+
import { ArrayPaginatedWithMeta, StarGiftUnique, StarGiftUniqueAttribute, StarGiftUniqueBackdrop } from '../../types/index.js';
|
|
4
|
+
import { MaybeArray } from '@fuman/utils';
|
|
5
|
+
import { default as Long } from 'long';
|
|
6
|
+
import { LongMap } from '../../../utils/long-utils.js';
|
|
7
|
+
export interface InputStarGiftAttributeIds {
|
|
8
|
+
model?: MaybeArray<Long>;
|
|
9
|
+
pattern?: MaybeArray<Long>;
|
|
10
|
+
backdrop?: MaybeArray<number>;
|
|
11
|
+
}
|
|
12
|
+
export declare function _normalizeResaleAttributes(attrs: tl.TypeStarGiftAttributeId[] | InputStarGiftAttributeIds): tl.TypeStarGiftAttributeId[];
|
|
13
|
+
export interface ResaleStarGiftsMeta {
|
|
14
|
+
attributes: {
|
|
15
|
+
model: LongMap<StarGiftUniqueAttribute>;
|
|
16
|
+
pattern: LongMap<StarGiftUniqueAttribute>;
|
|
17
|
+
backdrop: Map<number, StarGiftUniqueBackdrop>;
|
|
18
|
+
};
|
|
19
|
+
attributesHash: tl.Long;
|
|
20
|
+
counters: tl.RawStarGiftAttributeCounter[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get a list of star gifts up for resale
|
|
24
|
+
*/
|
|
25
|
+
export declare function getResaleOptions(client: ITelegramClient, params: {
|
|
26
|
+
/** ID of the gift to get resale options for */
|
|
27
|
+
giftId: tl.Long;
|
|
28
|
+
/**
|
|
29
|
+
* Sorting attribute
|
|
30
|
+
*
|
|
31
|
+
* - `price`: Sort by price
|
|
32
|
+
* - `num`: Sort by its unique number
|
|
33
|
+
*/
|
|
34
|
+
sort?: 'price' | 'num';
|
|
35
|
+
/**
|
|
36
|
+
* Hash of the `attributes` field, as returned by the server in the first response
|
|
37
|
+
*/
|
|
38
|
+
attributesHash?: Long;
|
|
39
|
+
/** Attributes to filter for */
|
|
40
|
+
attributes?: tl.TypeStarGiftAttributeId[] | InputStarGiftAttributeIds;
|
|
41
|
+
/** Offset for pagination */
|
|
42
|
+
offset?: string;
|
|
43
|
+
/** Limit for pagination */
|
|
44
|
+
limit?: number;
|
|
45
|
+
}): Promise<ArrayPaginatedWithMeta<StarGiftUnique, string, ResaleStarGiftsMeta>>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { assert } from "@fuman/utils";
|
|
2
|
+
import Long from "long";
|
|
3
|
+
import { LongMap } from "../../../utils/long-utils.js";
|
|
4
|
+
import { makeArrayPaginatedWithMeta } from "../../utils/misc-utils.js";
|
|
5
|
+
import { StarGiftUniqueAttribute as StarGiftUniqueAttribute$2, StarGiftUniqueBackdrop as StarGiftUniqueBackdrop$1, StarGiftUnique as StarGiftUnique$2 } from "../../types/premium/stars-gift-unique.js";
|
|
6
|
+
import { PeersIndex } from "../../types/peers/peers-index.js";
|
|
7
|
+
function _normalizeResaleAttributes(attrs) {
|
|
8
|
+
if (Array.isArray(attrs)) {
|
|
9
|
+
return attrs;
|
|
10
|
+
}
|
|
11
|
+
const res = [];
|
|
12
|
+
if (attrs.model) {
|
|
13
|
+
if (Array.isArray(attrs.model)) {
|
|
14
|
+
for (const id of attrs.model) {
|
|
15
|
+
res.push({
|
|
16
|
+
_: "starGiftAttributeIdModel",
|
|
17
|
+
documentId: id
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
} else {
|
|
21
|
+
res.push({
|
|
22
|
+
_: "starGiftAttributeIdModel",
|
|
23
|
+
documentId: attrs.model
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (attrs.pattern) {
|
|
28
|
+
if (Array.isArray(attrs.pattern)) {
|
|
29
|
+
for (const id of attrs.pattern) {
|
|
30
|
+
res.push({
|
|
31
|
+
_: "starGiftAttributeIdPattern",
|
|
32
|
+
documentId: id
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
res.push({
|
|
37
|
+
_: "starGiftAttributeIdPattern",
|
|
38
|
+
documentId: attrs.pattern
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (attrs.backdrop) {
|
|
43
|
+
if (Array.isArray(attrs.backdrop)) {
|
|
44
|
+
for (const id of attrs.backdrop) {
|
|
45
|
+
res.push({
|
|
46
|
+
_: "starGiftAttributeIdBackdrop",
|
|
47
|
+
backdropId: id
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
res.push({
|
|
52
|
+
_: "starGiftAttributeIdBackdrop",
|
|
53
|
+
backdropId: attrs.backdrop
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return res;
|
|
58
|
+
}
|
|
59
|
+
async function getResaleOptions(client, params) {
|
|
60
|
+
const res = await client.call({
|
|
61
|
+
_: "payments.getResaleStarGifts",
|
|
62
|
+
sortByNum: params.sort === "num",
|
|
63
|
+
sortByPrice: params.sort === "price",
|
|
64
|
+
attributesHash: params.attributesHash,
|
|
65
|
+
giftId: params.giftId,
|
|
66
|
+
attributes: params.attributes ? _normalizeResaleAttributes(params.attributes) : void 0,
|
|
67
|
+
offset: params.offset ?? "",
|
|
68
|
+
limit: params.limit ?? 100
|
|
69
|
+
});
|
|
70
|
+
const peers = PeersIndex.from(res);
|
|
71
|
+
const attributes = {
|
|
72
|
+
model: new LongMap(),
|
|
73
|
+
pattern: new LongMap(),
|
|
74
|
+
backdrop: /* @__PURE__ */ new Map()
|
|
75
|
+
};
|
|
76
|
+
for (const attr of res.attributes ?? []) {
|
|
77
|
+
if (attr._ === "starGiftAttributeModel") {
|
|
78
|
+
attributes.model.set(attr.document.id, new StarGiftUniqueAttribute$2(attr));
|
|
79
|
+
} else if (attr._ === "starGiftAttributePattern") {
|
|
80
|
+
attributes.pattern.set(attr.document.id, new StarGiftUniqueAttribute$2(attr));
|
|
81
|
+
} else if (attr._ === "starGiftAttributeBackdrop") {
|
|
82
|
+
attributes.backdrop.set(attr.backdropId, new StarGiftUniqueBackdrop$1(attr));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return makeArrayPaginatedWithMeta(
|
|
86
|
+
res.gifts.map((it) => {
|
|
87
|
+
assert(it._ === "starGiftUnique");
|
|
88
|
+
return new StarGiftUnique$2(it, peers);
|
|
89
|
+
}),
|
|
90
|
+
res.count,
|
|
91
|
+
{
|
|
92
|
+
attributes,
|
|
93
|
+
attributesHash: res.attributesHash ?? params.attributesHash ?? Long.ZERO,
|
|
94
|
+
counters: res.counters ?? []
|
|
95
|
+
},
|
|
96
|
+
res.nextOffset
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
export {
|
|
100
|
+
_normalizeResaleAttributes,
|
|
101
|
+
getResaleOptions
|
|
102
|
+
};
|
|
@@ -6,8 +6,8 @@ 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 utils = require("@fuman/utils");
|
|
9
|
-
const starsGiftUnique = require("../../types/premium/stars-gift-unique.cjs");
|
|
10
9
|
const peersIndex = require("../../types/peers/peers-index.cjs");
|
|
10
|
+
const starsGiftUnique = require("../../types/premium/stars-gift-unique.cjs");
|
|
11
11
|
async function getUniqueStarGift(client, slug) {
|
|
12
12
|
const res = await client.call({
|
|
13
13
|
_: "payments.getUniqueStarGift",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assert } from "@fuman/utils";
|
|
2
|
-
import { StarGiftUnique as StarGiftUnique$2 } from "../../types/premium/stars-gift-unique.js";
|
|
3
2
|
import { PeersIndex } from "../../types/peers/peers-index.js";
|
|
3
|
+
import { StarGiftUnique as StarGiftUnique$2 } from "../../types/premium/stars-gift-unique.js";
|
|
4
4
|
async function getUniqueStarGift(client, slug) {
|
|
5
5
|
const res = await client.call({
|
|
6
6
|
_: "payments.getUniqueStarGift",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
2
|
+
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
3
|
+
console.warn("[@mtcute/core] CommonJS support is deprecated and will be removed in 0.25.0. 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
|
+
const _normalizeInputStarGift = require("./_normalize-input-star-gift.cjs");
|
|
10
|
+
async function setResaleStarGiftPrice(client, params) {
|
|
11
|
+
const { gift, price } = params;
|
|
12
|
+
const r = await client.call({
|
|
13
|
+
_: "payments.updateStarGiftPrice",
|
|
14
|
+
stargift: await _normalizeInputStarGift._normalizeInputStarGift(client, gift),
|
|
15
|
+
resellStars: price === null ? Long.ZERO : Long.fromNumber(price)
|
|
16
|
+
});
|
|
17
|
+
client.handleClientUpdate(r);
|
|
18
|
+
}
|
|
19
|
+
exports.setResaleStarGiftPrice = setResaleStarGiftPrice;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ITelegramClient } from '../../client.types.js';
|
|
2
|
+
import { InputStarGift } from '../../types/index.js';
|
|
3
|
+
/** Set resale price for an owned star gift */
|
|
4
|
+
export declare function setResaleStarGiftPrice(client: ITelegramClient, params: {
|
|
5
|
+
/** Star gift to update the price of */
|
|
6
|
+
gift: InputStarGift;
|
|
7
|
+
/** New price of the gift (in stars), or `null` to unlist */
|
|
8
|
+
price: number | null;
|
|
9
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ITelegramClient } from '../../client.types.js';
|
|
2
|
+
import { InputStarGift } from '../../types/index.js';
|
|
3
|
+
/** Set resale price for an owned star gift */
|
|
4
|
+
export declare function setResaleStarGiftPrice(client: ITelegramClient, params: {
|
|
5
|
+
/** Star gift to update the price of */
|
|
6
|
+
gift: InputStarGift;
|
|
7
|
+
/** New price of the gift (in stars), or `null` to unlist */
|
|
8
|
+
price: number | null;
|
|
9
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Long from "long";
|
|
2
|
+
import { _normalizeInputStarGift } from "./_normalize-input-star-gift.js";
|
|
3
|
+
async function setResaleStarGiftPrice(client, params) {
|
|
4
|
+
const { gift, price } = params;
|
|
5
|
+
const r = await client.call({
|
|
6
|
+
_: "payments.updateStarGiftPrice",
|
|
7
|
+
stargift: await _normalizeInputStarGift(client, gift),
|
|
8
|
+
resellStars: price === null ? Long.ZERO : Long.fromNumber(price)
|
|
9
|
+
});
|
|
10
|
+
client.handleClientUpdate(r);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
setResaleStarGiftPrice
|
|
14
|
+
};
|
|
@@ -5,27 +5,42 @@ 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 tl = require("@mtcute/tl");
|
|
8
9
|
const typeAssertions = require("../../../utils/type-assertions.cjs");
|
|
9
10
|
const findInUpdate = require("../messages/find-in-update.cjs");
|
|
10
11
|
const resolvePeer = require("../users/resolve-peer.cjs");
|
|
11
12
|
const _normalizeInputStarGift = require("./_normalize-input-star-gift.cjs");
|
|
12
13
|
async function transferStarGift(client, params) {
|
|
13
|
-
const { gift,
|
|
14
|
+
const { gift, recipient, shouldDispatch } = params;
|
|
14
15
|
const invoice = {
|
|
15
16
|
_: "inputInvoiceStarGiftTransfer",
|
|
16
17
|
stargift: await _normalizeInputStarGift._normalizeInputStarGift(client, gift),
|
|
17
|
-
toId: await resolvePeer.resolvePeer(client,
|
|
18
|
+
toId: await resolvePeer.resolvePeer(client, recipient)
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
let updates;
|
|
21
|
+
try {
|
|
22
|
+
const form = await client.call({
|
|
23
|
+
_: "payments.getPaymentForm",
|
|
24
|
+
invoice
|
|
25
|
+
});
|
|
26
|
+
const res = await client.call({
|
|
27
|
+
_: "payments.sendStarsForm",
|
|
28
|
+
invoice,
|
|
29
|
+
formId: form.formId
|
|
30
|
+
});
|
|
31
|
+
typeAssertions.assertTypeIs("payments.sendStarsForm", res, "payments.paymentResult");
|
|
32
|
+
updates = res.updates;
|
|
33
|
+
} catch (e) {
|
|
34
|
+
if (tl.tl.RpcError.is(e, "NO_PAYMENT_NEEDED")) {
|
|
35
|
+
updates = await client.call({
|
|
36
|
+
_: "payments.transferStarGift",
|
|
37
|
+
stargift: invoice.stargift,
|
|
38
|
+
toId: invoice.toId
|
|
39
|
+
});
|
|
40
|
+
} else {
|
|
41
|
+
throw e;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return findInUpdate._findMessageInUpdate(client, updates, false, !shouldDispatch, true);
|
|
30
45
|
}
|
|
31
46
|
exports.transferStarGift = transferStarGift;
|
|
@@ -15,7 +15,7 @@ export declare function transferStarGift(client: ITelegramClient, params: {
|
|
|
15
15
|
/** Star gift to transfer */
|
|
16
16
|
gift: InputStarGift;
|
|
17
17
|
/** ID of the user to transfer the gift to */
|
|
18
|
-
|
|
18
|
+
recipient: InputPeerLike;
|
|
19
19
|
/**
|
|
20
20
|
* Whether to dispatch the new message event
|
|
21
21
|
* to the client's update handler.
|
|
@@ -15,7 +15,7 @@ export declare function transferStarGift(client: ITelegramClient, params: {
|
|
|
15
15
|
/** Star gift to transfer */
|
|
16
16
|
gift: InputStarGift;
|
|
17
17
|
/** ID of the user to transfer the gift to */
|
|
18
|
-
|
|
18
|
+
recipient: InputPeerLike;
|
|
19
19
|
/**
|
|
20
20
|
* Whether to dispatch the new message event
|
|
21
21
|
* to the client's update handler.
|
|
@@ -1,25 +1,40 @@
|
|
|
1
|
+
import { tl } from "@mtcute/tl";
|
|
1
2
|
import { assertTypeIs } from "../../../utils/type-assertions.js";
|
|
2
3
|
import { _findMessageInUpdate } from "../messages/find-in-update.js";
|
|
3
4
|
import { resolvePeer } from "../users/resolve-peer.js";
|
|
4
5
|
import { _normalizeInputStarGift } from "./_normalize-input-star-gift.js";
|
|
5
6
|
async function transferStarGift(client, params) {
|
|
6
|
-
const { gift,
|
|
7
|
+
const { gift, recipient, shouldDispatch } = params;
|
|
7
8
|
const invoice = {
|
|
8
9
|
_: "inputInvoiceStarGiftTransfer",
|
|
9
10
|
stargift: await _normalizeInputStarGift(client, gift),
|
|
10
|
-
toId: await resolvePeer(client,
|
|
11
|
+
toId: await resolvePeer(client, recipient)
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
let updates;
|
|
14
|
+
try {
|
|
15
|
+
const form = await client.call({
|
|
16
|
+
_: "payments.getPaymentForm",
|
|
17
|
+
invoice
|
|
18
|
+
});
|
|
19
|
+
const res = await client.call({
|
|
20
|
+
_: "payments.sendStarsForm",
|
|
21
|
+
invoice,
|
|
22
|
+
formId: form.formId
|
|
23
|
+
});
|
|
24
|
+
assertTypeIs("payments.sendStarsForm", res, "payments.paymentResult");
|
|
25
|
+
updates = res.updates;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
if (tl.RpcError.is(e, "NO_PAYMENT_NEEDED")) {
|
|
28
|
+
updates = await client.call({
|
|
29
|
+
_: "payments.transferStarGift",
|
|
30
|
+
stargift: invoice.stargift,
|
|
31
|
+
toId: invoice.toId
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
throw e;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return _findMessageInUpdate(client, updates, false, !shouldDispatch, true);
|
|
23
38
|
}
|
|
24
39
|
export {
|
|
25
40
|
transferStarGift
|