@langitdeveloper/baileys 2.2.4 → 2.2.5

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.
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * TC (Trusted Contact) token helpers.
5
+ *
6
+ * File ini sebelumnya HILANG dari lib (di-require di messages-send.js tapi ga pernah dibikin),
7
+ * bikin proses crash instant pas start ("Cannot find module '../Utils/tc-token-utils'").
8
+ *
9
+ * Semua pemanggil fungsi-fungsi ini di messages-send.js udah dibungkus try/catch, jadi kalo
10
+ * logic di sini meleset/gagal, efeknya cuma "kirim tanpa tctoken" - BUKAN crash. Implementasi
11
+ * di bawah sengaja dibikin konservatif (aman & simpel) drpd nebak detail wire-format IQ result
12
+ * WA yang ga kekonfirm, biar resiko rendah.
13
+ */
14
+ const TC_TOKEN_TTL_SECONDS = 30 * 24 * 60 * 60; // 30 hari, tebakan aman - token dianggap basi kalo lebih lama dari ini
15
+ const TC_TOKEN_REISSUE_INTERVAL_SECONDS = 7 * 24 * 60 * 60; // 7 hari - jangan reissue token tiap kirim pesan
16
+ function nowSeconds() {
17
+ return Math.floor(Date.now() / 1000);
18
+ }
19
+ /** cek apakah tctoken yg tersimpan udah kadaluarsa berdasarkan timestamp-nya */
20
+ function isTcTokenExpired(timestamp) {
21
+ if (!timestamp) {
22
+ return true;
23
+ }
24
+ const ts = Number(timestamp);
25
+ if (!Number.isFinite(ts) || ts <= 0) {
26
+ return true;
27
+ }
28
+ return (nowSeconds() - ts) > TC_TOKEN_TTL_SECONDS;
29
+ }
30
+ /** cek apakah perlu issue token baru ke kontak ini (biar ga spam issue tiap kirim pesan) */
31
+ function shouldSendNewTcToken(senderTimestamp) {
32
+ if (!senderTimestamp) {
33
+ return true;
34
+ }
35
+ const ts = Number(senderTimestamp);
36
+ if (!Number.isFinite(ts) || ts <= 0) {
37
+ return true;
38
+ }
39
+ return (nowSeconds() - ts) > TC_TOKEN_REISSUE_INTERVAL_SECONDS;
40
+ }
41
+ /** tentuin jid mana yg dipake sbg key penyimpanan tctoken (prefer LID kalo ada mapping-nya) */
42
+ async function resolveTcTokenJid(jid, getLIDForPN) {
43
+ try {
44
+ if (typeof getLIDForPN === 'function') {
45
+ const lid = await getLIDForPN(jid);
46
+ if (lid) {
47
+ return lid;
48
+ }
49
+ }
50
+ }
51
+ catch (_a) {
52
+ // biarin fallback ke jid asli
53
+ }
54
+ return jid;
55
+ }
56
+ /** tentuin jid mana yg dituju pas issue token baru (lid atau pn, tergantung server props) */
57
+ async function resolveIssuanceJid(jid, preferLid, getLIDForPN, getPNForLID) {
58
+ try {
59
+ if (preferLid && typeof getLIDForPN === 'function') {
60
+ const lid = await getLIDForPN(jid);
61
+ if (lid) {
62
+ return lid;
63
+ }
64
+ }
65
+ if (!preferLid && typeof getPNForLID === 'function') {
66
+ const pn = await getPNForLID(jid);
67
+ if (pn) {
68
+ return pn;
69
+ }
70
+ }
71
+ }
72
+ catch (_a) {
73
+ // biarin fallback ke jid asli
74
+ }
75
+ return jid;
76
+ }
77
+ /** parse hasil IQ dari issuePrivacyTokens jadi entry token per-jid, konservatif - return {} kalo shape ga dikenal */
78
+ async function storeTcTokensFromIqResult({ result, fallbackJid, keys, getLIDForPN }) {
79
+ var _a, _b, _c;
80
+ try {
81
+ const token = (_c = (_b = (_a = result === null || result === void 0 ? void 0 : result.content) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.content) !== null && _c !== void 0 ? _c : null;
82
+ if (!token || !fallbackJid) {
83
+ return {};
84
+ }
85
+ const jidKey = await resolveTcTokenJid(fallbackJid, getLIDForPN);
86
+ const entry = {
87
+ [jidKey]: {
88
+ token: Buffer.isBuffer(token) ? token : Buffer.from(token),
89
+ timestamp: nowSeconds(),
90
+ senderTimestamp: nowSeconds()
91
+ }
92
+ };
93
+ if (keys === null || keys === void 0 ? void 0 : keys.set) {
94
+ await keys.set({ tctoken: entry });
95
+ }
96
+ return entry;
97
+ }
98
+ catch (_d) {
99
+ // ga dikenal formatnya / gagal parse - aman, cuma berarti token ga ke-simpen
100
+ return {};
101
+ }
102
+ }
103
+ /** gabungin entry tctoken yg udah ada di store dgn yg baru buat ditulis ulang via keys.set */
104
+ async function buildMergedTcTokenIndexWrite(keys, jids) {
105
+ var _a;
106
+ const merged = {};
107
+ try {
108
+ const existing = await (keys === null || keys === void 0 ? void 0 : keys.get('tctoken', jids));
109
+ for (const jid of jids) {
110
+ if ((_a = existing === null || existing === void 0 ? void 0 : existing[jid]) === null || _a === void 0 ? void 0 : _a.token) {
111
+ merged[jid] = existing[jid];
112
+ }
113
+ }
114
+ }
115
+ catch (_b) {
116
+ // kalo gagal baca existing, ya udah return apa adanya (bisa kosong)
117
+ }
118
+ return merged;
119
+ }
120
+ exports.isTcTokenExpired = isTcTokenExpired;
121
+ exports.shouldSendNewTcToken = shouldSendNewTcToken;
122
+ exports.resolveTcTokenJid = resolveTcTokenJid;
123
+ exports.resolveIssuanceJid = resolveIssuanceJid;
124
+ exports.storeTcTokensFromIqResult = storeTcTokensFromIqResult;
125
+ exports.buildMergedTcTokenIndexWrite = buildMergedTcTokenIndexWrite;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langitdeveloper/baileys",
3
- "version": "2.2.4",
3
+ "version": "2.2.5",
4
4
  "description": "WhatsApp API Modification By Langit",
5
5
  "keywords": [
6
6
  "whatsapp",