@adriangalilea/utils 0.17.1 → 0.19.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/README.md +9 -9
- package/dist/bot/access-control.d.ts.map +1 -1
- package/dist/bot/access-control.js +62 -45
- package/dist/bot/access-control.js.map +1 -1
- package/dist/bot/callbacks.d.ts +89 -0
- package/dist/bot/callbacks.d.ts.map +1 -0
- package/dist/bot/callbacks.js +128 -0
- package/dist/bot/callbacks.js.map +1 -0
- package/dist/bot/ctx.d.ts +219 -0
- package/dist/bot/ctx.d.ts.map +1 -0
- package/dist/bot/ctx.js +52 -0
- package/dist/bot/ctx.js.map +1 -0
- package/dist/bot/index.d.ts +4 -0
- package/dist/bot/index.d.ts.map +1 -1
- package/dist/bot/index.js +4 -0
- package/dist/bot/index.js.map +1 -1
- package/dist/bot/kit.d.ts +93 -41
- package/dist/bot/kit.d.ts.map +1 -1
- package/dist/bot/kit.js +153 -30
- package/dist/bot/kit.js.map +1 -1
- package/dist/bot/menu.d.ts +31 -11
- package/dist/bot/menu.d.ts.map +1 -1
- package/dist/bot/menu.js +34 -9
- package/dist/bot/menu.js.map +1 -1
- package/dist/bot/payments/callbacks.d.ts +28 -0
- package/dist/bot/payments/callbacks.d.ts.map +1 -0
- package/dist/bot/payments/callbacks.js +102 -0
- package/dist/bot/payments/callbacks.js.map +1 -0
- package/dist/bot/payments/commands.d.ts +26 -0
- package/dist/bot/payments/commands.d.ts.map +1 -0
- package/dist/bot/payments/commands.js +41 -0
- package/dist/bot/payments/commands.js.map +1 -0
- package/dist/bot/payments/config.d.ts +30 -0
- package/dist/bot/payments/config.d.ts.map +1 -0
- package/dist/bot/payments/config.js +166 -0
- package/dist/bot/payments/config.js.map +1 -0
- package/dist/bot/payments/derive.d.ts +75 -0
- package/dist/bot/payments/derive.d.ts.map +1 -0
- package/dist/bot/payments/derive.js +151 -0
- package/dist/bot/payments/derive.js.map +1 -0
- package/dist/bot/payments/handlers.d.ts +113 -0
- package/dist/bot/payments/handlers.d.ts.map +1 -0
- package/dist/bot/payments/handlers.js +284 -0
- package/dist/bot/payments/handlers.js.map +1 -0
- package/dist/bot/payments/index.d.ts +17 -0
- package/dist/bot/payments/index.d.ts.map +1 -0
- package/dist/bot/payments/index.js +14 -0
- package/dist/bot/payments/index.js.map +1 -0
- package/dist/bot/payments/invoice.d.ts +101 -0
- package/dist/bot/payments/invoice.d.ts.map +1 -0
- package/dist/bot/payments/invoice.js +213 -0
- package/dist/bot/payments/invoice.js.map +1 -0
- package/dist/bot/payments/menu-item.d.ts +41 -0
- package/dist/bot/payments/menu-item.d.ts.map +1 -0
- package/dist/bot/payments/menu-item.js +259 -0
- package/dist/bot/payments/menu-item.js.map +1 -0
- package/dist/bot/payments/payload.d.ts +42 -0
- package/dist/bot/payments/payload.d.ts.map +1 -0
- package/dist/bot/payments/payload.js +69 -0
- package/dist/bot/payments/payload.js.map +1 -0
- package/dist/bot/payments/payouts.d.ts +88 -0
- package/dist/bot/payments/payouts.d.ts.map +1 -0
- package/dist/bot/payments/payouts.js +133 -0
- package/dist/bot/payments/payouts.js.map +1 -0
- package/dist/bot/payments/plugin.d.ts +271 -0
- package/dist/bot/payments/plugin.d.ts.map +1 -0
- package/dist/bot/payments/plugin.js +141 -0
- package/dist/bot/payments/plugin.js.map +1 -0
- package/dist/bot/payments/refund.d.ts +124 -0
- package/dist/bot/payments/refund.d.ts.map +1 -0
- package/dist/bot/payments/refund.js +308 -0
- package/dist/bot/payments/refund.js.map +1 -0
- package/dist/bot/payments/schemas.d.ts +58 -0
- package/dist/bot/payments/schemas.d.ts.map +1 -0
- package/dist/bot/payments/schemas.js +55 -0
- package/dist/bot/payments/schemas.js.map +1 -0
- package/dist/bot/payments/state.d.ts +90 -0
- package/dist/bot/payments/state.d.ts.map +1 -0
- package/dist/bot/payments/state.js +149 -0
- package/dist/bot/payments/state.js.map +1 -0
- package/dist/bot/payments/stores.d.ts +44 -0
- package/dist/bot/payments/stores.d.ts.map +1 -0
- package/dist/bot/payments/stores.js +39 -0
- package/dist/bot/payments/stores.js.map +1 -0
- package/dist/bot/payments/types.d.ts +299 -0
- package/dist/bot/payments/types.d.ts.map +1 -0
- package/dist/bot/payments/types.js +39 -0
- package/dist/bot/payments/types.js.map +1 -0
- package/dist/bot/payments/waiver.d.ts +81 -0
- package/dist/bot/payments/waiver.d.ts.map +1 -0
- package/dist/bot/payments/waiver.js +145 -0
- package/dist/bot/payments/waiver.js.map +1 -0
- package/dist/bot/storage.d.ts +154 -0
- package/dist/bot/storage.d.ts.map +1 -0
- package/dist/bot/storage.js +222 -0
- package/dist/bot/storage.js.map +1 -0
- package/package.json +24 -3
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invoice payload codec. Telegram echoes the `invoice_payload` string
|
|
3
|
+
* back on `pre_checkout_query` and `successful_payment`; we use it to
|
|
4
|
+
* recover the `(productKey, userId)` pair that the in-flight purchase
|
|
5
|
+
* refers to.
|
|
6
|
+
*
|
|
7
|
+
* Constraints from Telegram:
|
|
8
|
+
* - Max 128 bytes.
|
|
9
|
+
* - Must be a string (we use printable ASCII).
|
|
10
|
+
*
|
|
11
|
+
* Format: `${productKey}|${userId}`
|
|
12
|
+
*
|
|
13
|
+
* The `|` delimiter is unambiguous because productKey is one of:
|
|
14
|
+
* - `vip.${number}` — only digits and `.`
|
|
15
|
+
* - `credits.${number}` — only digits and `.`
|
|
16
|
+
* - `perks.${key}` — key restricted to `/^[a-z][a-z0-9_]*$/i`
|
|
17
|
+
* by `config.ts` validation
|
|
18
|
+
*
|
|
19
|
+
* None of those contain `|`, so the first `|` is always the delimiter.
|
|
20
|
+
* Worst case length is ~`perks.${64-char-key}|${20-digit-int}` ≈ 90 bytes
|
|
21
|
+
* — comfortably under the 128-byte cap. We assert the length to fail
|
|
22
|
+
* loud if the cap is ever approached.
|
|
23
|
+
*/
|
|
24
|
+
import { panic } from "../../offensive.js";
|
|
25
|
+
const MAX_PAYLOAD_BYTES = 128;
|
|
26
|
+
/**
|
|
27
|
+
* Build the `invoice_payload` string for a `sendInvoice` call. Throws
|
|
28
|
+
* `Panic` if the result would exceed Telegram's 128-byte cap — that's
|
|
29
|
+
* either a bad productKey or a userId out of bounds, both of which are
|
|
30
|
+
* bugs we want to scream about.
|
|
31
|
+
*/
|
|
32
|
+
export const encodePayload = (productKey, userId) => {
|
|
33
|
+
if (!productKey.length) {
|
|
34
|
+
panic("bot/payments/payload: encodePayload called with empty productKey");
|
|
35
|
+
}
|
|
36
|
+
if (!Number.isInteger(userId) || userId <= 0) {
|
|
37
|
+
panic(`bot/payments/payload: encodePayload userId must be positive integer (got ${userId})`);
|
|
38
|
+
}
|
|
39
|
+
const payload = `${productKey}|${userId}`;
|
|
40
|
+
// ASCII-only by construction (productKey shape + decimal digits), so
|
|
41
|
+
// .length === byte length. Cheap check.
|
|
42
|
+
if (payload.length > MAX_PAYLOAD_BYTES) {
|
|
43
|
+
panic(`bot/payments/payload: encoded payload ${payload.length}B exceeds Telegram's ` +
|
|
44
|
+
`${MAX_PAYLOAD_BYTES}B cap. productKey="${productKey}" userId=${userId}`);
|
|
45
|
+
}
|
|
46
|
+
return payload;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Decode the `invoice_payload` Telegram echoes back. Returns `undefined`
|
|
50
|
+
* (NOT throws) on malformed input — Telegram could in principle deliver
|
|
51
|
+
* a payload from a different bot version, and we want the pre_checkout
|
|
52
|
+
* handler to be able to reject it gracefully rather than crashing.
|
|
53
|
+
*/
|
|
54
|
+
export const decodePayload = (payload) => {
|
|
55
|
+
if (typeof payload !== "string" || payload.length === 0)
|
|
56
|
+
return undefined;
|
|
57
|
+
const idx = payload.indexOf("|");
|
|
58
|
+
if (idx <= 0 || idx === payload.length - 1)
|
|
59
|
+
return undefined;
|
|
60
|
+
const productKey = payload.slice(0, idx);
|
|
61
|
+
const userIdStr = payload.slice(idx + 1);
|
|
62
|
+
if (!/^\d+$/.test(userIdStr))
|
|
63
|
+
return undefined;
|
|
64
|
+
const userId = Number.parseInt(userIdStr, 10);
|
|
65
|
+
if (!Number.isInteger(userId) || userId <= 0)
|
|
66
|
+
return undefined;
|
|
67
|
+
return { productKey, userId };
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=payload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload.js","sourceRoot":"","sources":["../../../src/bot/payments/payload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAO9B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,UAAkB,EAAE,MAAc,EAAU,EAAE;IAC3E,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;QACxB,KAAK,CAAC,kEAAkE,CAAC,CAAC;IAC3E,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QAC9C,KAAK,CACJ,4EAA4E,MAAM,GAAG,CACrF,CAAC;IACH,CAAC;IACD,MAAM,OAAO,GAAG,GAAG,UAAU,IAAI,MAAM,EAAE,CAAC;IAC1C,qEAAqE;IACrE,wCAAwC;IACxC,IAAI,OAAO,CAAC,MAAM,GAAG,iBAAiB,EAAE,CAAC;QACxC,KAAK,CACJ,yCAAyC,OAAO,CAAC,MAAM,uBAAuB;YAC7E,GAAG,iBAAiB,sBAAsB,UAAU,YAAY,MAAM,EAAE,CACzE,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAe,EAA8B,EAAE;IAC5E,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC1E,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,KAAK,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IAC7D,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACzC,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IACzC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC;QAAE,OAAO,SAAS,CAAC;IAC/C,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;AAC/B,CAAC,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fragment payout ledger — the bot author's accounting surface.
|
|
3
|
+
*
|
|
4
|
+
* Fragment Corp redeems your accumulated XTR balance into TON paid to
|
|
5
|
+
* the configured wallet. That payout is the **income event** for
|
|
6
|
+
* Spanish autónomo IRPF purposes (CLAUDE.md §4); the per-charge log on
|
|
7
|
+
* Telegram's side is informational. We persist each payout you receive
|
|
8
|
+
* here, optionally tagged with the Spanish factura number, and provide
|
|
9
|
+
* an `export()` helper that joins charges falling in the payout's time
|
|
10
|
+
* window — that's what your gestor needs.
|
|
11
|
+
*
|
|
12
|
+
* Calling pattern (called by the bot author, NOT from inside an event
|
|
13
|
+
* handler):
|
|
14
|
+
*
|
|
15
|
+
* import { Bot } from 'gramio'
|
|
16
|
+
* const bot = new Bot(token); await bot.start()
|
|
17
|
+
*
|
|
18
|
+
* // After confirming a Fragment payout to your TON wallet:
|
|
19
|
+
* await payments.payouts.record(bot, {
|
|
20
|
+
* ton: 12.34,
|
|
21
|
+
* eurAtReceipt: 47.20,
|
|
22
|
+
* fromMs: Date.parse('2026-05-01'),
|
|
23
|
+
* toMs: Date.parse('2026-06-01'),
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* // For the monthly gestor export:
|
|
27
|
+
* const data = await payments.payouts.exportForUsers(bot, userIds, {
|
|
28
|
+
* from: Date.parse('2026-05-01'),
|
|
29
|
+
* to: Date.parse('2026-06-01'),
|
|
30
|
+
* })
|
|
31
|
+
*
|
|
32
|
+
* Fragment doesn't tag payouts with specific charges, so the join is
|
|
33
|
+
* **time-windowed**: payouts get `{ fromMs, toMs }` and the export
|
|
34
|
+
* pulls every `ChargeRecord` whose `receivedAt` falls inside.
|
|
35
|
+
*/
|
|
36
|
+
import type { AnyBot } from "gramio";
|
|
37
|
+
import type { PaymentsStores } from "./stores.js";
|
|
38
|
+
import type { ChargeRecord, PayoutRecord } from "./types.js";
|
|
39
|
+
export type RecordPayoutInput = {
|
|
40
|
+
/** Amount of TON received from Fragment. */
|
|
41
|
+
ton: number;
|
|
42
|
+
/** EUR value at receipt time (snapshot — exchange rates move). */
|
|
43
|
+
eurAtReceipt: number;
|
|
44
|
+
/** Window covered by this payout, lower bound (ms since epoch). */
|
|
45
|
+
fromMs: number;
|
|
46
|
+
/** Window covered by this payout, upper bound (ms since epoch). */
|
|
47
|
+
toMs: number;
|
|
48
|
+
/** Optional Spanish factura number issued for this payout. */
|
|
49
|
+
facturaNumber?: string;
|
|
50
|
+
/** Override the auto-generated batchId. Default: `payout_${toMs}`. */
|
|
51
|
+
batchId?: string;
|
|
52
|
+
};
|
|
53
|
+
export declare const recordPayout: (bot: AnyBot, stores: PaymentsStores, input: RecordPayoutInput) => Promise<PayoutRecord>;
|
|
54
|
+
export declare const listPayouts: (bot: AnyBot, stores: PaymentsStores) => Promise<PayoutRecord[]>;
|
|
55
|
+
export type ExportInput = {
|
|
56
|
+
/** Window lower bound, ms since epoch. */
|
|
57
|
+
from: number;
|
|
58
|
+
/** Window upper bound, ms since epoch. */
|
|
59
|
+
to: number;
|
|
60
|
+
};
|
|
61
|
+
export type ExportResult = {
|
|
62
|
+
payouts: PayoutRecord[];
|
|
63
|
+
charges: ChargeRecord[];
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Build the payout-only dataset for a time window. Returns every
|
|
67
|
+
* `PayoutRecord` whose `[fromMs, toMs]` overlaps the requested window.
|
|
68
|
+
*
|
|
69
|
+
* The `charges` field is intentionally empty — without a global charge
|
|
70
|
+
* index (v2 TODO) we can't enumerate every user's charges from one
|
|
71
|
+
* call. Use `exportPayoutsForUsers` with an explicit user-id list.
|
|
72
|
+
*/
|
|
73
|
+
export declare const exportPayouts: (bot: AnyBot, stores: PaymentsStores, input: ExportInput) => Promise<ExportResult>;
|
|
74
|
+
/**
|
|
75
|
+
* Same as `exportPayouts` but with an explicit user-id list to scan.
|
|
76
|
+
* Pulls every NON-refunded `ChargeRecord` whose `receivedAt` falls in
|
|
77
|
+
* the requested window, joined by time rather than payout identity
|
|
78
|
+
* (Fragment doesn't expose that mapping).
|
|
79
|
+
*/
|
|
80
|
+
export declare const exportPayoutsForUsers: (bot: AnyBot, stores: PaymentsStores, userIds: ReadonlyArray<number>, input: ExportInput) => Promise<ExportResult>;
|
|
81
|
+
export type PayoutsApi = {
|
|
82
|
+
record: (bot: AnyBot, input: RecordPayoutInput) => Promise<PayoutRecord>;
|
|
83
|
+
list: (bot: AnyBot) => Promise<PayoutRecord[]>;
|
|
84
|
+
export: (bot: AnyBot, input: ExportInput) => Promise<ExportResult>;
|
|
85
|
+
exportForUsers: (bot: AnyBot, userIds: ReadonlyArray<number>, input: ExportInput) => Promise<ExportResult>;
|
|
86
|
+
};
|
|
87
|
+
export declare const buildPayoutsApi: (stores: PaymentsStores) => PayoutsApi;
|
|
88
|
+
//# sourceMappingUR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ACtB,OAAO,WAAW,KAChB,OAAO,CAAC,YAAY,CAWtB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GACjC,KAAK,MAAM,EACX,QAAQ,cAAc,EACtB,SAAS,aAAa,CAAC,MAAM,CAAC,EAC9B,OAAO,WAAW,KAChB,OAAO,CAAC,YAAY,CAqBtB,CAAC;AAIF,MAAM,MAAM,UAAU,GAAG;IACxB,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IACzE,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAC/C,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IACnE,cAAc,EAAE,CACf,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,EAC9B,KAAK,EAAE,WAAW,KACd,OAAO,CAAC,YAAY,CAAC,CAAC;CAC3B,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,QAAQ,cAAc,KAAG,UAMvD,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fragment payout ledger — the bot author's accounting surface.
|
|
3
|
+
*
|
|
4
|
+
* Fragment Corp redeems your accumulated XTR balance into TON paid to
|
|
5
|
+
* the configured wallet. That payout is the **income event** for
|
|
6
|
+
* Spanish autónomo IRPF purposes (CLAUDE.md §4); the per-charge log on
|
|
7
|
+
* Telegram's side is informational. We persist each payout you receive
|
|
8
|
+
* here, optionally tagged with the Spanish factura number, and provide
|
|
9
|
+
* an `export()` helper that joins charges falling in the payout's time
|
|
10
|
+
* window — that's what your gestor needs.
|
|
11
|
+
*
|
|
12
|
+
* Calling pattern (called by the bot author, NOT from inside an event
|
|
13
|
+
* handler):
|
|
14
|
+
*
|
|
15
|
+
* import { Bot } from 'gramio'
|
|
16
|
+
* const bot = new Bot(token); await bot.start()
|
|
17
|
+
*
|
|
18
|
+
* // After confirming a Fragment payout to your TON wallet:
|
|
19
|
+
* await payments.payouts.record(bot, {
|
|
20
|
+
* ton: 12.34,
|
|
21
|
+
* eurAtReceipt: 47.20,
|
|
22
|
+
* fromMs: Date.parse('2026-05-01'),
|
|
23
|
+
* toMs: Date.parse('2026-06-01'),
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* // For the monthly gestor export:
|
|
27
|
+
* const data = await payments.payouts.exportForUsers(bot, userIds, {
|
|
28
|
+
* from: Date.parse('2026-05-01'),
|
|
29
|
+
* to: Date.parse('2026-06-01'),
|
|
30
|
+
* })
|
|
31
|
+
*
|
|
32
|
+
* Fragment doesn't tag payouts with specific charges, so the join is
|
|
33
|
+
* **time-windowed**: payouts get `{ fromMs, toMs }` and the export
|
|
34
|
+
* pulls every `ChargeRecord` whose `receivedAt` falls inside.
|
|
35
|
+
*/
|
|
36
|
+
import { panic } from "../../offensive.js";
|
|
37
|
+
// ─── adapter for the offline-call shape ────────────────────────────
|
|
38
|
+
/**
|
|
39
|
+
* Construct the `BotIdCtx` shape `bot/storage` needs when called outside
|
|
40
|
+
* an event (just `{ bot: { info: bot.info } }`). Mirrors the
|
|
41
|
+
* `simulateAccessRequest` pattern in `access-control.ts`.
|
|
42
|
+
*
|
|
43
|
+
* Throws if the bot's `info` isn't populated yet — usually because the
|
|
44
|
+
* caller forgot to `await bot.start()` (or `bot.init()`) first.
|
|
45
|
+
*/
|
|
46
|
+
const ctxFor = (bot) => {
|
|
47
|
+
const info = bot.info;
|
|
48
|
+
if (!info) {
|
|
49
|
+
panic("bot/payments/payouts: bot.info is undefined — call bot.start() (or bot.init()) first");
|
|
50
|
+
}
|
|
51
|
+
return { bot: { info } };
|
|
52
|
+
};
|
|
53
|
+
const buildPayoutRecord = (input) => {
|
|
54
|
+
if (input.ton <= 0)
|
|
55
|
+
panic(`bot/payments/payouts: ton must be positive (got ${input.ton})`);
|
|
56
|
+
if (input.eurAtReceipt < 0)
|
|
57
|
+
panic(`bot/payments/payouts: eurAtReceipt must be >= 0 (got ${input.eurAtReceipt})`);
|
|
58
|
+
if (input.fromMs >= input.toMs)
|
|
59
|
+
panic(`bot/payments/payouts: fromMs must be < toMs (got ${input.fromMs} / ${input.toMs})`);
|
|
60
|
+
const batchId = input.batchId ?? `payout_${input.toMs}`;
|
|
61
|
+
return {
|
|
62
|
+
batchId,
|
|
63
|
+
fromMs: input.fromMs,
|
|
64
|
+
toMs: input.toMs,
|
|
65
|
+
tonAmount: input.ton,
|
|
66
|
+
eurAtReceipt: input.eurAtReceipt,
|
|
67
|
+
recordedAt: Date.now(),
|
|
68
|
+
facturaNumber: input.facturaNumber,
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
export const recordPayout = async (bot, stores, input) => {
|
|
72
|
+
const ctx = ctxFor(bot);
|
|
73
|
+
const record = buildPayoutRecord(input);
|
|
74
|
+
await stores.payouts.set(ctx, record.batchId, record);
|
|
75
|
+
await stores.payoutsIndex.prepend(ctx, record.batchId);
|
|
76
|
+
return record;
|
|
77
|
+
};
|
|
78
|
+
export const listPayouts = async (bot, stores) => {
|
|
79
|
+
const ctx = ctxFor(bot);
|
|
80
|
+
const ids = await stores.payoutsIndex.list(ctx);
|
|
81
|
+
const records = await Promise.all(ids.map((id) => stores.payouts.get(ctx, id)));
|
|
82
|
+
return records.filter((r) => r !== undefined);
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Build the payout-only dataset for a time window. Returns every
|
|
86
|
+
* `PayoutRecord` whose `[fromMs, toMs]` overlaps the requested window.
|
|
87
|
+
*
|
|
88
|
+
* The `charges` field is intentionally empty — without a global charge
|
|
89
|
+
* index (v2 TODO) we can't enumerate every user's charges from one
|
|
90
|
+
* call. Use `exportPayoutsForUsers` with an explicit user-id list.
|
|
91
|
+
*/
|
|
92
|
+
export const exportPayouts = async (bot, stores, input) => {
|
|
93
|
+
if (input.from >= input.to) {
|
|
94
|
+
panic(`bot/payments/payouts: export from must be < to (got ${input.from} / ${input.to})`);
|
|
95
|
+
}
|
|
96
|
+
const allPayouts = await listPayouts(bot, stores);
|
|
97
|
+
const payouts = allPayouts.filter((p) => !(p.toMs < input.from || p.fromMs > input.to));
|
|
98
|
+
return { payouts, charges: [] };
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Same as `exportPayouts` but with an explicit user-id list to scan.
|
|
102
|
+
* Pulls every NON-refunded `ChargeRecord` whose `receivedAt` falls in
|
|
103
|
+
* the requested window, joined by time rather than payout identity
|
|
104
|
+
* (Fragment doesn't expose that mapping).
|
|
105
|
+
*/
|
|
106
|
+
export const exportPayoutsForUsers = async (bot, stores, userIds, input) => {
|
|
107
|
+
const ctx = ctxFor(bot);
|
|
108
|
+
const allPayouts = await listPayouts(bot, stores);
|
|
109
|
+
const payouts = allPayouts.filter((p) => !(p.toMs < input.from || p.fromMs > input.to));
|
|
110
|
+
const allCharges = [];
|
|
111
|
+
for (const userId of userIds) {
|
|
112
|
+
const chargeIds = await stores.userCharges(userId).list(ctx);
|
|
113
|
+
for (const cid of chargeIds) {
|
|
114
|
+
const c = await stores.charges.get(ctx, cid);
|
|
115
|
+
if (!c)
|
|
116
|
+
continue;
|
|
117
|
+
if (c.paysupportState === "refunded")
|
|
118
|
+
continue;
|
|
119
|
+
if (c.receivedAt >= input.from && c.receivedAt <= input.to) {
|
|
120
|
+
allCharges.push(c);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
allCharges.sort((a, b) => a.receivedAt - b.receivedAt);
|
|
125
|
+
return { payouts, charges: allCharges };
|
|
126
|
+
};
|
|
127
|
+
export const buildPayoutsApi = (stores) => ({
|
|
128
|
+
record: (bot, input) => recordPayout(bot, stores, input),
|
|
129
|
+
list: (bot) => listPayouts(bot, stores),
|
|
130
|
+
export: (bot, input) => exportPayouts(bot, stores, input),
|
|
131
|
+
exportForUsers: (bot, userIds, input) => exportPayoutsForUsers(bot, stores, userIds, input),
|
|
132
|
+
});
|
|
133
|
+
//# sourceMappingURL=payouts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payouts.js","sourceRoot":"","sources":["../../../src/bot/payments/payouts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAIH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAI3C,sEAAsE;AAEtE;;;;;;;GAOG;AACH,MAAM,MAAM,GAAG,CAAC,GAAW,EAAqC,EAAE;IACjE,MAAM,IAAI,GAAI,GAA4C,CAAC,IAAI,CAAC;IAChE,IAAI,CAAC,IAAI,EAAE,CAAC;QACX,KAAK,CACJ,sFAAsF,CACtF,CAAC;IACH,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC;AAC1B,CAAC,CAAC;AAmBF,MAAM,iBAAiB,GAAG,CAAC,KAAwB,EAAgB,EAAE;IACpE,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC;QACjB,KAAK,CAAC,mDAAmD,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC;IACxE,IAAI,KAAK,CAAC,YAAY,GAAG,CAAC;QACzB,KAAK,CACJ,wDAAwD,KAAK,CAAC,YAAY,GAAG,CAC7E,CAAC;IACH,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI;QAC7B,KAAK,CACJ,oDAAoD,KAAK,CAAC,MAAM,MAAM,KAAK,CAAC,IAAI,GAAG,CACnF,CAAC;IACH,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,UAAU,KAAK,CAAC,IAAI,EAAE,CAAC;IACxD,OAAO;QACN,OAAO;QACP,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,SAAS,EAAE,KAAK,CAAC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` § plugin file
|
|
6
|
+
* convention. Every handler body lives in its concern-specific
|
|
7
|
+
* neighbour (`derive.ts` / `handlers.ts` / `callbacks.ts` /
|
|
8
|
+
* `commands.ts` / `refund.ts`); this file's job is to stitch them
|
|
9
|
+
* into a `Plugin` chain.
|
|
10
|
+
*
|
|
11
|
+
* What gets wired:
|
|
12
|
+
*
|
|
13
|
+
* - `ctx.payments.*` surface via `.derive()` → `derive.ts`
|
|
14
|
+
* - `pre_checkout_query` handler → `handlers.ts`
|
|
15
|
+
* - `successful_payment` (dedicated event) → `handlers.ts`
|
|
16
|
+
* - Waiver consent / cancel callbacks → `callbacks.ts` + `waiver.ts`
|
|
17
|
+
* - Refund request / approve / deny / close → `callbacks.ts` + `refund.ts`
|
|
18
|
+
* - `/paysupport` slash command → `commands.ts`
|
|
19
|
+
*
|
|
20
|
+
* Returned alongside the plugin: `menuItem` (drop-in for `botMenu`),
|
|
21
|
+
* `payouts` (Fragment ledger), `admin` (read helpers for custom
|
|
22
|
+
* admin commands), and `onFulfilled` (event hook registration).
|
|
23
|
+
*
|
|
24
|
+
* See `CLAUDE.md` in this folder for the design rationale and flows.
|
|
25
|
+
*/
|
|
26
|
+
import type { session } from "@gramio/session";
|
|
27
|
+
import type { Storage } from "@gramio/storage";
|
|
28
|
+
import { type DeriveDefinitions, Plugin } from "gramio";
|
|
29
|
+
import { buildCatalog } from "./config.js";
|
|
30
|
+
import { type PaymentsDerived } from "./derive.js";
|
|
31
|
+
import { buildPaymentsMenuItem } from "./menu-item.js";
|
|
32
|
+
import { type PayoutsApi } from "./payouts.js";
|
|
33
|
+
import { type PaymentsStores } from "./stores.js";
|
|
34
|
+
import type { AtLeastKey, BotPaymentsConfig, ChargeRecord, FulfillmentEvent, PaymentsSession, ProductKey, TierKey } from "./types.js";
|
|
35
|
+
type SessionLike = {
|
|
36
|
+
pay?: PaymentsSession;
|
|
37
|
+
language?: string;
|
|
38
|
+
};
|
|
39
|
+
type PaySessionPluginRef = ReturnType<typeof session<SessionLike, "session">>;
|
|
40
|
+
type TierFn<Cfg extends BotPaymentsConfig<string>> = (() => TierKey<Cfg>) & {
|
|
41
|
+
level: () => number;
|
|
42
|
+
/**
|
|
43
|
+
* Resolved display label of the current rung in `ctx.session.language`,
|
|
44
|
+
* or `undefined` on free tier. Named `label` (not `name`) because
|
|
45
|
+
* `Function.prototype.name` is read-only in strict mode and we attach
|
|
46
|
+
* this onto a callable.
|
|
47
|
+
*/
|
|
48
|
+
label: () => string | undefined;
|
|
49
|
+
};
|
|
50
|
+
export type PaymentsCtx<Cfg extends BotPaymentsConfig<string>> = {
|
|
51
|
+
atLeast: (id: AtLeastKey<Cfg>) => boolean;
|
|
52
|
+
tier: TierFn<Cfg>;
|
|
53
|
+
has: (perkId: string) => boolean;
|
|
54
|
+
credits: PaymentsDerived["credits"];
|
|
55
|
+
require: (id: AtLeastKey<Cfg>, opts?: {
|
|
56
|
+
feature?: {
|
|
57
|
+
en: string;
|
|
58
|
+
es: string;
|
|
59
|
+
} | string;
|
|
60
|
+
}) => Promise<boolean>;
|
|
61
|
+
invoice: (productKey: ProductKey<Cfg>) => Promise<"invoice_sent" | "waiver_prompt_sent" | "unknown_product">;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Admin-side read helpers exposed on `payments.admin.*`. Bot authors
|
|
65
|
+
* use these when writing custom admin commands (e.g. `/refunds`) that
|
|
66
|
+
* bypass the user-initiated refund-request flow. ctx only needs
|
|
67
|
+
* `.bot.info.id` for namespacing — pass any real gramio ctx or a
|
|
68
|
+
* synthetic `{ bot: { info: bot.info } }` for offline scripts.
|
|
69
|
+
*/
|
|
70
|
+
export type PaymentsAdmin = {
|
|
71
|
+
/** Every non-pruned charge for a user, newest-first. */
|
|
72
|
+
listCharges: (ctx: {
|
|
73
|
+
bot: {
|
|
74
|
+
info: {
|
|
75
|
+
id: number;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
}, userId: number) => Promise<ReadonlyArray<ChargeRecord>>;
|
|
79
|
+
/** One charge by id; `undefined` if not found. */
|
|
80
|
+
getCharge: (ctx: {
|
|
81
|
+
bot: {
|
|
82
|
+
info: {
|
|
83
|
+
id: number;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
}, chargeId: string) => Promise<ChargeRecord | undefined>;
|
|
87
|
+
};
|
|
88
|
+
export type BotPaymentsResult<Cfg extends BotPaymentsConfig<string>> = {
|
|
89
|
+
plugin: ReturnType<typeof buildPlugin>;
|
|
90
|
+
menuItem: ReturnType<typeof buildPaymentsMenuItem>;
|
|
91
|
+
payouts: PayoutsApi;
|
|
92
|
+
admin: PaymentsAdmin;
|
|
93
|
+
onFulfilled: (productKey: ProductKey<Cfg> | "*", handler: (event: FulfillmentEvent, ctx: unknown) => void) => void;
|
|
94
|
+
};
|
|
95
|
+
export type BotPaymentsOptions<Cfg extends BotPaymentsConfig<string>> = Cfg & {
|
|
96
|
+
/** Shared session plugin. Required — see CLAUDE.md §"Storage layout". */
|
|
97
|
+
session: PaySessionPluginRef;
|
|
98
|
+
/**
|
|
99
|
+
* Storage backend for the global ledger (charges, payouts, refunds,
|
|
100
|
+
* idempotency). MUST be the same instance backing `session`.
|
|
101
|
+
*/
|
|
102
|
+
storage: Storage;
|
|
103
|
+
};
|
|
104
|
+
declare const buildPlugin: (args: {
|
|
105
|
+
cfg: BotPaymentsConfig<string>;
|
|
106
|
+
catalog: ReturnType<typeof buildCatalog>;
|
|
107
|
+
sessionPlugin: PaySessionPluginRef;
|
|
108
|
+
storage: Storage;
|
|
109
|
+
stores: PaymentsStores;
|
|
110
|
+
onFulfilledMap: Map<string, Array<(event: FulfillmentEvent, ctx: unknown) => void>>;
|
|
111
|
+
}) => Plugin<Record<string, never>, DeriveDefinitions & {
|
|
112
|
+
global: {
|
|
113
|
+
payments: PaymentsCtx<BotPaymentsConfig<string>>;
|
|
114
|
+
};
|
|
115
|
+
} & {
|
|
116
|
+
message: {
|
|
117
|
+
session: SessionLike & {
|
|
118
|
+
$clear: () => Promise<void>;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
channel_post: {
|
|
122
|
+
session: SessionLike & {
|
|
123
|
+
$clear: () => Promise<void>;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
inline_query: {
|
|
127
|
+
session: SessionLike & {
|
|
128
|
+
$clear: () => Promise<void>;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
chosen_inline_result: {
|
|
132
|
+
session: SessionLike & {
|
|
133
|
+
$clear: () => Promise<void>;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
callback_query: {
|
|
137
|
+
session: SessionLike & {
|
|
138
|
+
$clear: () => Promise<void>;
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
shipping_query: {
|
|
142
|
+
session: SessionLike & {
|
|
143
|
+
$clear: () => Promise<void>;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
pre_checkout_query: {
|
|
147
|
+
session: SessionLike & {
|
|
148
|
+
$clear: () => Promise<void>;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
poll_answer: {
|
|
152
|
+
session: SessionLike & {
|
|
153
|
+
$clear: () => Promise<void>;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
chat_join_request: {
|
|
157
|
+
session: SessionLike & {
|
|
158
|
+
$clear: () => Promise<void>;
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
new_chat_members: {
|
|
162
|
+
session: SessionLike & {
|
|
163
|
+
$clear: () => Promise<void>;
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
new_chat_title: {
|
|
167
|
+
session: SessionLike & {
|
|
168
|
+
$clear: () => Promise<void>;
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
new_chat_photo: {
|
|
172
|
+
session: SessionLike & {
|
|
173
|
+
$clear: () => Promise<void>;
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
delete_chat_photo: {
|
|
177
|
+
session: SessionLike & {
|
|
178
|
+
$clear: () => Promise<void>;
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
group_chat_created: {
|
|
182
|
+
session: SessionLike & {
|
|
183
|
+
$clear: () => Promise<void>;
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
message_auto_delete_timer_changed: {
|
|
187
|
+
session: SessionLike & {
|
|
188
|
+
$clear: () => Promise<void>;
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
migrate_to_chat_id: {
|
|
192
|
+
session: SessionLike & {
|
|
193
|
+
$clear: () => Promise<void>;
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
migrate_from_chat_id: {
|
|
197
|
+
session: SessionLike & {
|
|
198
|
+
$clear: () => Promise<void>;
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
pinned_message: {
|
|
202
|
+
session: SessionLike & {
|
|
203
|
+
$clear: () => Promise<void>;
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
invoice: {
|
|
207
|
+
session: SessionLike & {
|
|
208
|
+
$clear: () => Promise<void>;
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
successful_payment: {
|
|
212
|
+
session: SessionLike & {
|
|
213
|
+
$clear: () => Promise<void>;
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
chat_shared: {
|
|
217
|
+
session: SessionLike & {
|
|
218
|
+
$clear: () => Promise<void>;
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
proximity_alert_triggered: {
|
|
222
|
+
session: SessionLike & {
|
|
223
|
+
$clear: () => Promise<void>;
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
video_chat_scheduled: {
|
|
227
|
+
session: SessionLike & {
|
|
228
|
+
$clear: () => Promise<void>;
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
video_chat_started: {
|
|
232
|
+
session: SessionLike & {
|
|
233
|
+
$clear: () => Promise<void>;
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
video_chat_ended: {
|
|
237
|
+
session: SessionLike & {
|
|
238
|
+
$clear: () => Promise<void>;
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
video_chat_participants_invited: {
|
|
242
|
+
session: SessionLike & {
|
|
243
|
+
$clear: () => Promise<void>;
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
web_app_data: {
|
|
247
|
+
session: SessionLike & {
|
|
248
|
+
$clear: () => Promise<void>;
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
location: {
|
|
252
|
+
session: SessionLike & {
|
|
253
|
+
$clear: () => Promise<void>;
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
passport_data: {
|
|
257
|
+
session: SessionLike & {
|
|
258
|
+
$clear: () => Promise<void>;
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
} & {
|
|
262
|
+
message: {
|
|
263
|
+
payments: PaymentsCtx<BotPaymentsConfig<string>>;
|
|
264
|
+
};
|
|
265
|
+
callback_query: {
|
|
266
|
+
payments: PaymentsCtx<BotPaymentsConfig<string>>;
|
|
267
|
+
};
|
|
268
|
+
}, {}>;
|
|
269
|
+
export declare const botPayments: <const Cfg extends BotPaymentsConfig<string>>(opts: BotPaymentsOptions<Cfg>) => BotPaymentsResult<Cfg>;
|
|
270
|
+
export {};
|
|
271
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/bot/payments/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAUxD,OAAO,EAAE,YAAY,E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