aunubaileys 1.0.7 → 1.0.9

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 CHANGED
@@ -64,6 +64,14 @@ Everything else is pure upstream. When upstream moves, we rebase the patch layer
64
64
 
65
65
 
66
66
 
67
+ ### 🆕 What's new in 1.0.9 / Baru di 1.0.9
68
+
69
+ - 🪪 **LID identity layer** — WhatsApp is migrating identities from phone numbers to LIDs, and incoming stanzas already carry both forms. AunuBaileys now learns the mapping from live traffic: every socket exposes `sock.aunuLid`, a bidirectional PN <-> LID store with local `getLIDForPN()` / `getPNForLID()` lookups (no extra server queries), LRU capping, and optional JSON persistence. Prefer a standalone store? `makeLIDStore()` is exported from the package root, fully typed.
70
+
71
+ ### 🆕 What's new in 1.0.8 / Baru di 1.0.8
72
+
73
+ - 🩹 **TypeScript declaration fix** — `NEWSLETTER_MEDIA_PATH_MAP` and `BIZ_BOT_SUPPORT_PAYLOAD` were exported from the runtime but missing from `lib/Defaults/index.d.ts`, so TypeScript consumers got compile errors importing them. Both are now properly declared. Found by the RafaelPivots automation, verified against source, no runtime changes.
74
+
67
75
  ### 🆕 What's new in 1.0.7 / Baru di 1.0.7
68
76
 
69
77
  - 🧭 **One canonical repository** — the separate upstream-fork repo was retired (archived by the maintainers); `AunuHost/AunuBaileys-lib` is now the single public home of AunuBaileys, and this README — with badges pointing at the right repo — is the one npm ships.
@@ -49,4 +49,22 @@ export declare const DEFAULT_CACHE_TTLS: {
49
49
  CALL_OFFER: number;
50
50
  USER_DEVICES: number;
51
51
  };
52
- //# sourceMappingURL=index.d.ts.map
52
+ /** AunuBaileys: peta path upload khusus newsletter */
53
+ export declare const NEWSLETTER_MEDIA_PATH_MAP: {
54
+ image: string;
55
+ video: string;
56
+ audio: string;
57
+ document: string;
58
+ sticker: string;
59
+ gif: string;
60
+ ptt: string;
61
+ ptv: string;
62
+ 'music-artwork': string;
63
+ 'sticker-pack': string;
64
+ 'thumbnail-link': string;
65
+ 'waffle-image': string;
66
+ 'waffle-video': string;
67
+ };
68
+ /** AunuBaileys: payload label AI */
69
+ export declare const BIZ_BOT_SUPPORT_PAYLOAD: string;
70
+ //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,7 @@
1
1
  import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
2
2
  import { makeCommunitiesSocket } from './communities.js';
3
3
  import { AunuHandler } from '../Utils/aunu-handler.js';
4
+ import { makeLIDStore } from '../Utils/lid-store.js';
4
5
  // export the last socket layer
5
6
  const makeWASocket = (config) => {
6
7
  const newConfig = {
@@ -14,6 +15,15 @@ const makeWASocket = (config) => {
14
15
  }
15
16
  const sock = makeCommunitiesSocket(newConfig);
16
17
  sock.aunuHandler = new AunuHandler(sock);
18
+ sock.aunuLid = makeLIDStore();
19
+ sock.ev.on('messages.upsert', (upsert) => {
20
+ try {
21
+ sock.aunuLid.learnFromUpsert(upsert);
22
+ }
23
+ catch {
24
+ // identity learning must never break message handling
25
+ }
26
+ });
17
27
  return sock;
18
28
  };
19
29
  export default makeWASocket;
@@ -0,0 +1,32 @@
1
+ import type { WAMessage } from '../Types/index.js';
2
+ export interface LIDStoreOptions {
3
+ /** Maximum PN<->LID pairs kept; least-recently-used pairs are evicted. Default 5000. */
4
+ maxEntries?: number;
5
+ }
6
+ export interface LIDStore {
7
+ /** Store one PN/LID pair. Returns false when either JID is not a user PN JID / LID JID. */
8
+ addPair(pnJid: string, lidJid: string): boolean;
9
+ /** Learn pairs from a message key (senderPn/senderLid, participantPn/participantLid). Returns pairs learned. */
10
+ learnFromKey(key: Record<string, unknown> | undefined): number;
11
+ /** Learn pairs from one message. Returns pairs learned. */
12
+ learnFromMessage(msg: WAMessage | undefined): number;
13
+ /** Learn pairs from a `messages.upsert` payload. Returns pairs learned. */
14
+ learnFromUpsert(upsert: { messages?: WAMessage[] }): number;
15
+ getLIDForPN(pnJid: string): string | undefined;
16
+ getPNForLID(lidJid: string): string | undefined;
17
+ hasPN(pnJid: string): boolean;
18
+ hasLID(lidJid: string): boolean;
19
+ deletePair(jid: string): boolean;
20
+ clear(): void;
21
+ readonly size: number;
22
+ toJSON(): Record<string, string>;
23
+ saveToFile(path: string): void;
24
+ /** Returns the number of pairs loaded; 0 when the file is missing or invalid. */
25
+ loadFromFile(path: string): number;
26
+ }
27
+ /**
28
+ * Create a bidirectional PN <-> LID identity store that learns from
29
+ * live message traffic. Sockets expose an auto-learning instance as
30
+ * `sock.aunuLid`.
31
+ */
32
+ export declare const makeLIDStore: (options?: LIDStoreOptions) => LIDStore;
@@ -0,0 +1,139 @@
1
+ import { readFileSync, writeFileSync } from 'fs';
2
+ import { jidNormalizedUser, isJidUser, isLidUser } from '../WABinary/jid-utils.js';
3
+ /**
4
+ * AunuBaileys LID identity store.
5
+ *
6
+ * WhatsApp is migrating identities from phone-number JIDs
7
+ * (`<number>@s.whatsapp.net`) to LIDs (`<id>@lid`). Incoming message
8
+ * stanzas already carry both forms (`sender_pn`/`sender_lid`,
9
+ * `participant_pn`/`participant_lid`), so this store learns the
10
+ * PN <-> LID pairs from live traffic and answers bidirectional
11
+ * lookups locally — no server round-trip, no extra IQ queries.
12
+ *
13
+ * The socket attaches an auto-learning instance as `sock.aunuLid`.
14
+ * A standalone store can also be created with `makeLIDStore()` and
15
+ * fed manually via `learnFromMessage` / `addPair`.
16
+ */
17
+ export const makeLIDStore = (options = {}) => {
18
+ const maxEntries = options.maxEntries ?? 5000;
19
+ const pnToLid = new Map();
20
+ const lidToPn = new Map();
21
+ const touch = (map, key, value) => {
22
+ // refresh recency for LRU eviction
23
+ map.delete(key);
24
+ map.set(key, value);
25
+ };
26
+ const evictIfNeeded = () => {
27
+ while (pnToLid.size > maxEntries) {
28
+ const oldestPn = pnToLid.keys().next().value;
29
+ const lid = pnToLid.get(oldestPn);
30
+ pnToLid.delete(oldestPn);
31
+ if (lid) {
32
+ lidToPn.delete(lid);
33
+ }
34
+ }
35
+ };
36
+ const addPair = (pnJid, lidJid) => {
37
+ if (!pnJid || !lidJid) {
38
+ return false;
39
+ }
40
+ const pn = jidNormalizedUser(pnJid);
41
+ const lid = jidNormalizedUser(lidJid);
42
+ if (!isJidUser(pn) || !isLidUser(lid)) {
43
+ return false;
44
+ }
45
+ // keep both directions consistent if either side was remapped
46
+ const prevLid = pnToLid.get(pn);
47
+ if (prevLid && prevLid !== lid) {
48
+ lidToPn.delete(prevLid);
49
+ }
50
+ const prevPn = lidToPn.get(lid);
51
+ if (prevPn && prevPn !== pn) {
52
+ pnToLid.delete(prevPn);
53
+ }
54
+ touch(pnToLid, pn, lid);
55
+ touch(lidToPn, lid, pn);
56
+ evictIfNeeded();
57
+ return true;
58
+ };
59
+ const learnFromKey = (key) => {
60
+ if (!key) {
61
+ return 0;
62
+ }
63
+ let learned = 0;
64
+ if (key.senderPn && key.senderLid) {
65
+ learned += addPair(key.senderPn, key.senderLid) ? 1 : 0;
66
+ }
67
+ if (key.participantPn && key.participantLid) {
68
+ learned += addPair(key.participantPn, key.participantLid) ? 1 : 0;
69
+ }
70
+ // a DM chat partner: remoteJid may be the PN while the stanza
71
+ // only carried the sender LID (or the reverse)
72
+ if (key.remoteJid && key.senderLid && isJidUser(key.remoteJid) && !key.fromMe) {
73
+ learned += addPair(key.remoteJid, key.senderLid) ? 1 : 0;
74
+ }
75
+ return learned;
76
+ };
77
+ const learnFromMessage = (msg) => learnFromKey(msg?.key);
78
+ const learnFromUpsert = (upsert) => {
79
+ let learned = 0;
80
+ for (const msg of upsert?.messages ?? []) {
81
+ learned += learnFromMessage(msg);
82
+ }
83
+ return learned;
84
+ };
85
+ const store = {
86
+ addPair,
87
+ learnFromKey,
88
+ learnFromMessage,
89
+ learnFromUpsert,
90
+ getLIDForPN: (pnJid) => (pnJid ? pnToLid.get(jidNormalizedUser(pnJid)) : undefined),
91
+ getPNForLID: (lidJid) => (lidJid ? lidToPn.get(jidNormalizedUser(lidJid)) : undefined),
92
+ hasPN: (pnJid) => (pnJid ? pnToLid.has(jidNormalizedUser(pnJid)) : false),
93
+ hasLID: (lidJid) => (lidJid ? lidToPn.has(jidNormalizedUser(lidJid)) : false),
94
+ deletePair: (jid) => {
95
+ if (!jid) {
96
+ return false;
97
+ }
98
+ const norm = jidNormalizedUser(jid);
99
+ const lid = pnToLid.get(norm);
100
+ if (lid) {
101
+ pnToLid.delete(norm);
102
+ lidToPn.delete(lid);
103
+ return true;
104
+ }
105
+ const pn = lidToPn.get(norm);
106
+ if (pn) {
107
+ lidToPn.delete(norm);
108
+ pnToLid.delete(pn);
109
+ return true;
110
+ }
111
+ return false;
112
+ },
113
+ clear: () => {
114
+ pnToLid.clear();
115
+ lidToPn.clear();
116
+ },
117
+ get size() {
118
+ return pnToLid.size;
119
+ },
120
+ toJSON: () => Object.fromEntries(pnToLid),
121
+ saveToFile: (path) => {
122
+ writeFileSync(path, JSON.stringify(Object.fromEntries(pnToLid)));
123
+ },
124
+ loadFromFile: (path) => {
125
+ try {
126
+ const data = JSON.parse(readFileSync(path, 'utf-8'));
127
+ let loaded = 0;
128
+ for (const [pn, lid] of Object.entries(data)) {
129
+ loaded += addPair(pn, lid) ? 1 : 0;
130
+ }
131
+ return loaded;
132
+ }
133
+ catch {
134
+ return 0;
135
+ }
136
+ }
137
+ };
138
+ return store;
139
+ };
package/lib/index.d.ts CHANGED
@@ -15,3 +15,5 @@ export { processedMessages, initInMemoryKeyStore } from './Utils/fork-compat.js'
15
15
  export { PHONENUMBER_MCC } from './Utils/phonenumber-mcc.js';
16
16
  export * from './Utils/aunu-handler';
17
17
  export * from './Utils/builders';
18
+ export * from './Utils/antiban';
19
+ export * from './Utils/lid-store.js';
package/lib/index.js CHANGED
@@ -14,3 +14,5 @@ export { processedMessages, initInMemoryKeyStore } from './Utils/fork-compat.js'
14
14
  export { PHONENUMBER_MCC } from './Utils/phonenumber-mcc.js';
15
15
  export * from './Utils/aunu-handler.js';
16
16
  export * from './Utils/builders.js';
17
+ export * from './Utils/antiban.js';
18
+ export * from './Utils/lid-store.js';
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "aunubaileys",
3
3
  "type": "module",
4
- "version": "1.0.7",
5
- "description": "AunuBaileys — a WhatsApp Web API for bots that never sleep. Full upstream power with the beloved in-memory store restored and pairing that just works. Forged by AunuCore.",
4
+ "version": "1.0.9",
5
+ "description": "AunuBaileys \u2014 a WhatsApp Web API for bots that never sleep. Full upstream power with the beloved in-memory store restored and pairing that just works. Forged by AunuCore.",
6
6
  "keywords": [
7
7
  "whatsapp",
8
8
  "whatsapp-web",