@itsliaaa/baileys 0.1.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.
Files changed (103) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +1078 -0
  3. package/WAProto/index.js +100441 -0
  4. package/engine-requirements.js +10 -0
  5. package/lib/Defaults/index.js +144 -0
  6. package/lib/Signal/Group/ciphertext-message.js +11 -0
  7. package/lib/Signal/Group/group-session-builder.js +29 -0
  8. package/lib/Signal/Group/group_cipher.js +81 -0
  9. package/lib/Signal/Group/index.js +11 -0
  10. package/lib/Signal/Group/keyhelper.js +17 -0
  11. package/lib/Signal/Group/sender-chain-key.js +25 -0
  12. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  13. package/lib/Signal/Group/sender-key-message.js +65 -0
  14. package/lib/Signal/Group/sender-key-name.js +47 -0
  15. package/lib/Signal/Group/sender-key-record.js +40 -0
  16. package/lib/Signal/Group/sender-key-state.js +83 -0
  17. package/lib/Signal/Group/sender-message-key.js +25 -0
  18. package/lib/Signal/libsignal.js +402 -0
  19. package/lib/Signal/lid-mapping.js +270 -0
  20. package/lib/Socket/Client/index.js +2 -0
  21. package/lib/Socket/Client/types.js +10 -0
  22. package/lib/Socket/Client/websocket.js +53 -0
  23. package/lib/Socket/business.js +378 -0
  24. package/lib/Socket/chats.js +1048 -0
  25. package/lib/Socket/communities.js +430 -0
  26. package/lib/Socket/groups.js +328 -0
  27. package/lib/Socket/index.js +11 -0
  28. package/lib/Socket/messages-recv.js +1442 -0
  29. package/lib/Socket/messages-send.js +1153 -0
  30. package/lib/Socket/mex.js +41 -0
  31. package/lib/Socket/newsletter.js +227 -0
  32. package/lib/Socket/socket.js +936 -0
  33. package/lib/Store/index.js +3 -0
  34. package/lib/Store/make-in-memory-store.js +421 -0
  35. package/lib/Store/make-ordered-dictionary.js +78 -0
  36. package/lib/Store/object-repository.js +23 -0
  37. package/lib/Types/Auth.js +1 -0
  38. package/lib/Types/Bussines.js +1 -0
  39. package/lib/Types/Call.js +1 -0
  40. package/lib/Types/Chat.js +7 -0
  41. package/lib/Types/Contact.js +1 -0
  42. package/lib/Types/Events.js +1 -0
  43. package/lib/Types/GroupMetadata.js +1 -0
  44. package/lib/Types/Label.js +24 -0
  45. package/lib/Types/LabelAssociation.js +6 -0
  46. package/lib/Types/Message.js +17 -0
  47. package/lib/Types/Newsletter.js +33 -0
  48. package/lib/Types/Product.js +1 -0
  49. package/lib/Types/Signal.js +1 -0
  50. package/lib/Types/Socket.js +2 -0
  51. package/lib/Types/State.js +12 -0
  52. package/lib/Types/USync.js +1 -0
  53. package/lib/Types/index.js +25 -0
  54. package/lib/Utils/auth-utils.js +289 -0
  55. package/lib/Utils/browser-utils.js +28 -0
  56. package/lib/Utils/business.js +230 -0
  57. package/lib/Utils/chat-utils.js +811 -0
  58. package/lib/Utils/crypto.js +117 -0
  59. package/lib/Utils/decode-wa-message.js +282 -0
  60. package/lib/Utils/event-buffer.js +573 -0
  61. package/lib/Utils/generics.js +385 -0
  62. package/lib/Utils/history.js +130 -0
  63. package/lib/Utils/identity-change-handler.js +48 -0
  64. package/lib/Utils/index.js +19 -0
  65. package/lib/Utils/link-preview.js +84 -0
  66. package/lib/Utils/logger.js +2 -0
  67. package/lib/Utils/lt-hash.js +7 -0
  68. package/lib/Utils/make-mutex.js +32 -0
  69. package/lib/Utils/message-retry-manager.js +224 -0
  70. package/lib/Utils/messages-media.js +789 -0
  71. package/lib/Utils/messages.js +1832 -0
  72. package/lib/Utils/noise-handler.js +200 -0
  73. package/lib/Utils/pre-key-manager.js +105 -0
  74. package/lib/Utils/process-message.js +527 -0
  75. package/lib/Utils/reporting-utils.js +257 -0
  76. package/lib/Utils/signal.js +158 -0
  77. package/lib/Utils/sync-action-utils.js +47 -0
  78. package/lib/Utils/tc-token-utils.js +17 -0
  79. package/lib/Utils/use-multi-file-auth-state.js +120 -0
  80. package/lib/Utils/validate-connection.js +206 -0
  81. package/lib/WABinary/constants.js +1300 -0
  82. package/lib/WABinary/decode.js +261 -0
  83. package/lib/WABinary/encode.js +219 -0
  84. package/lib/WABinary/generic-utils.js +197 -0
  85. package/lib/WABinary/index.js +5 -0
  86. package/lib/WABinary/jid-utils.js +95 -0
  87. package/lib/WABinary/types.js +1 -0
  88. package/lib/WAM/BinaryInfo.js +9 -0
  89. package/lib/WAM/constants.js +22852 -0
  90. package/lib/WAM/encode.js +149 -0
  91. package/lib/WAM/index.js +3 -0
  92. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -0
  93. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
  94. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  95. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  96. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  97. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  98. package/lib/WAUSync/Protocols/index.js +4 -0
  99. package/lib/WAUSync/USyncQuery.js +93 -0
  100. package/lib/WAUSync/USyncUser.js +22 -0
  101. package/lib/WAUSync/index.js +3 -0
  102. package/lib/index.js +11 -0
  103. package/package.json +72 -0
@@ -0,0 +1,3 @@
1
+ export * from './make-in-memory-store.js';
2
+ export * from './make-ordered-dictionary.js';
3
+ export * from './object-repository.js';
@@ -0,0 +1,421 @@
1
+ /**
2
+ * Lia@Note 03-02-26
3
+ * --- [WIP]
4
+ * Manually converted to ESM and modified by me
5
+ * Originally based on @whiskeysockets/baileys v6.7.16
6
+ * Minor adjustments for compatibility with baileys v7 (⁠つ⁠≧⁠▽⁠≦⁠)⁠つ
7
+ */
8
+ import keyedDB from '@adiwajshing/keyed-db';
9
+ import { writeFileSync, readFileSync, existsSync } from 'fs';
10
+ import { WAProto } from '../Types/index.js';
11
+ import { LabelAssociationType } from '../Types/LabelAssociation.js';
12
+ import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
13
+ import { md5, toNumber, updateMessageWithReceipt, updateMessageWithReaction } from '../Utils/index.js';
14
+ import { jidDecode, jidNormalizedUser } from '../WABinary/index.js';
15
+ import { makeOrderedDictionary } from './make-ordered-dictionary.js';
16
+ import { ObjectRepository } from './object-repository.js';
17
+ export const waChatKey = (pin) => ({
18
+ key: (c) => (pin ? (c.pinned ? '1' : '0') : '') + (c.archived ? '0' : '1') + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') + c.id,
19
+ compare: (k1, k2) => k2.localeCompare(k1)
20
+ });
21
+ export const waMessageID = (m) => m.key.id || '';
22
+ export const waLabelAssociationKey = {
23
+ key: (la) => (la.type === LabelAssociationType.Chat ? la.chatId + la.labelId : la.chatId + la.messageId + la.labelId),
24
+ compare: (k1, k2) => k2.localeCompare(k1)
25
+ };
26
+ const makeMessagesDictionary = () => makeOrderedDictionary(waMessageID);
27
+ export const makeInMemoryStore = (config = {}) => {
28
+ const socket = config.socket;
29
+ const chatKey = config.chatKey || waChatKey(true);
30
+ const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey;
31
+ const logger = config.logger || DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
32
+ const KeyedDB = keyedDB?.default ?? keyedDB; // Lia@Note 03-02-26 --- Handle CJS ↔ ESM default export differences ⊂⁠(⁠・⁠ω⁠・⁠*⁠⊂⁠)
33
+ const chats = new KeyedDB(chatKey, c => c.id);
34
+ const messages = {};
35
+ const contacts = {};
36
+ const groupMetadata = {};
37
+ const presences = {};
38
+ const state = { connection: 'close' };
39
+ const labels = new ObjectRepository();
40
+ const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key);
41
+ const assertMessageList = (jid) => {
42
+ if (!messages[jid]) {
43
+ messages[jid] = makeMessagesDictionary();
44
+ }
45
+ return messages[jid];
46
+ };
47
+ const contactsUpsert = (newContacts) => {
48
+ const oldContacts = new Set(Object.keys(contacts));
49
+ for (const contact of newContacts) {
50
+ oldContacts.delete(contact.id);
51
+ contacts[contact.id] = Object.assign(contacts[contact.id] || {}, contact);
52
+ }
53
+ return oldContacts;
54
+ };
55
+ const labelsUpsert = (newLabels) => {
56
+ for (const label of newLabels) {
57
+ labels.upsertById(label.id, label);
58
+ }
59
+ };
60
+ /**
61
+ * binds to a BaileysEventEmitter.
62
+ * It listens to all events and constructs a state that you can query accurate data from.
63
+ * Eg. can use the store to fetch chats, contacts, messages etc.
64
+ * @param ev typically the event emitter from the socket connection
65
+ */
66
+ const bind = (ev) => {
67
+ ev.on('connection.update', update => {
68
+ Object.assign(state, update);
69
+ });
70
+ ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
71
+ if (syncType === WAProto.HistorySync.HistorySyncType.ON_DEMAND) {
72
+ return; // FOR NOW,
73
+ //TODO: HANDLE
74
+ }
75
+ if (isLatest) {
76
+ chats.clear();
77
+ for (const id in messages) {
78
+ delete messages[id];
79
+ }
80
+ }
81
+ const chatsAdded = chats.insertIfAbsent(...newChats).length;
82
+ logger.debug({ chatsAdded }, 'synced chats');
83
+ const oldContacts = contactsUpsert(newContacts);
84
+ if (isLatest) {
85
+ for (const jid of oldContacts) {
86
+ delete contacts[jid];
87
+ }
88
+ }
89
+ logger.debug({ deletedContacts: isLatest ? oldContacts.size : 0, newContacts }, 'synced contacts');
90
+ for (const msg of newMessages) {
91
+ const jid = msg.key.remoteJidAlt || msg.key.remoteJid;
92
+ const list = assertMessageList(jid);
93
+ list.upsert(msg, 'prepend');
94
+ }
95
+ logger.debug({ messages: newMessages.length }, 'synced messages');
96
+ });
97
+ ev.on('contacts.upsert', contacts => {
98
+ contactsUpsert(contacts);
99
+ });
100
+ ev.on('contacts.update', async (updates) => {
101
+ var _a;
102
+ for (const update of updates) {
103
+ let contact;
104
+ if (contacts[update.id]) {
105
+ contact = contacts[update.id];
106
+ }
107
+ else {
108
+ const contactHashes = await Promise.all(Object.keys(contacts).map(async (contactId) => {
109
+ const { user } = jidDecode(contactId);
110
+ return [contactId, (await md5(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)];
111
+ }));
112
+ contact = contacts[((_a = contactHashes.find(([, b]) => b === update.id)) === null || _a === void 0 ? void 0 : _a[0]) || '']; // find contact by attrs.hash, when user is not saved as a contact
113
+ }
114
+ if (contact) {
115
+ if (update.imgUrl === 'changed') {
116
+ contact.imgUrl = socket ? await (socket === null || socket === void 0 ? void 0 : socket.profilePictureUrl(contact.id)) : undefined;
117
+ }
118
+ else if (update.imgUrl === 'removed') {
119
+ delete contact.imgUrl;
120
+ }
121
+ }
122
+ else {
123
+ return logger.debug({ update }, 'got update for non-existant contact');
124
+ }
125
+ Object.assign(contacts[contact.id], contact);
126
+ }
127
+ });
128
+ ev.on('chats.upsert', newChats => {
129
+ chats.upsert(...newChats);
130
+ });
131
+ ev.on('chats.update', updates => {
132
+ for (let update of updates) {
133
+ const result = chats.update(update.id, chat => {
134
+ if (update.unreadCount > 0) {
135
+ update = { ...update };
136
+ update.unreadCount = (chat.unreadCount || 0) + update.unreadCount;
137
+ }
138
+ Object.assign(chat, update);
139
+ });
140
+ if (!result) {
141
+ logger.debug({ update }, 'got update for non-existant chat');
142
+ }
143
+ }
144
+ });
145
+ ev.on('labels.edit', (label) => {
146
+ if (label.deleted) {
147
+ return labels.deleteById(label.id);
148
+ }
149
+ // WhatsApp can store only up to 20 labels
150
+ if (labels.count() < 20) {
151
+ return labels.upsertById(label.id, label);
152
+ }
153
+ logger.error('Labels count exceed');
154
+ });
155
+ ev.on('labels.association', ({ type, association }) => {
156
+ switch (type) {
157
+ case 'add':
158
+ labelAssociations.upsert(association);
159
+ break;
160
+ case 'remove':
161
+ labelAssociations.delete(association);
162
+ break;
163
+ default:
164
+ console.error(`unknown operation type [${type}]`);
165
+ }
166
+ });
167
+ ev.on('presence.update', ({ id, presences: update }) => {
168
+ presences[id] = presences[id] || {};
169
+ Object.assign(presences[id], update);
170
+ });
171
+ ev.on('chats.delete', deletions => {
172
+ for (const item of deletions) {
173
+ if (chats.get(item)) {
174
+ chats.deleteById(item);
175
+ }
176
+ }
177
+ });
178
+ ev.on('messages.upsert', ({ messages: newMessages, type }) => {
179
+ switch (type) {
180
+ case 'append':
181
+ case 'notify':
182
+ for (const msg of newMessages) {
183
+ const jid = jidNormalizedUser(msg.key.remoteJidAlt || msg.key.remoteJid);
184
+ const list = assertMessageList(jid);
185
+ list.upsert(msg, 'append');
186
+ if (type === 'notify' && !chats.get(jid)) {
187
+ ev.emit('chats.upsert', [
188
+ {
189
+ id: jid,
190
+ conversationTimestamp: toNumber(msg.messageTimestamp),
191
+ unreadCount: 1
192
+ }
193
+ ]);
194
+ }
195
+ }
196
+ break;
197
+ }
198
+ });
199
+ ev.on('messages.update', updates => {
200
+ var _a;
201
+ for (const { update, key } of updates) {
202
+ const list = assertMessageList(jidNormalizedUser(key.remoteJid));
203
+ if (update === null || update === void 0 ? void 0 : update.status) {
204
+ const listStatus = (_a = list.get(key.id)) === null || _a === void 0 ? void 0 : _a.status;
205
+ if (listStatus && (update === null || update === void 0 ? void 0 : update.status) <= listStatus) {
206
+ logger.debug({ update, storedStatus: listStatus }, 'status stored newer then update');
207
+ delete update.status;
208
+ logger.debug({ update }, 'new update object');
209
+ }
210
+ }
211
+ const result = list.updateAssign(key.id, update);
212
+ if (!result) {
213
+ logger.debug({ update }, 'got update for non-existent message');
214
+ }
215
+ }
216
+ });
217
+ ev.on('messages.delete', item => {
218
+ if ('all' in item) {
219
+ const list = messages[item.jid];
220
+ list === null || list === void 0 ? void 0 : list.clear();
221
+ }
222
+ else {
223
+ const jid = item.keys[0].remoteJidAlt || item.keys[0].remoteJid;
224
+ const list = messages[jid];
225
+ if (list) {
226
+ const idSet = new Set(item.keys.map(k => k.id));
227
+ list.filter(m => !idSet.has(m.key.id));
228
+ }
229
+ }
230
+ });
231
+ ev.on('groups.update', updates => {
232
+ for (const update of updates) {
233
+ const id = update.id;
234
+ if (groupMetadata[id]) {
235
+ Object.assign(groupMetadata[id], update);
236
+ }
237
+ else {
238
+ logger.debug({ update }, 'got update for non-existant group metadata');
239
+ }
240
+ }
241
+ });
242
+ ev.on('group-participants.update', ({ id, participants, action }) => {
243
+ const metadata = groupMetadata[id];
244
+ if (metadata) {
245
+ switch (action) {
246
+ case 'add':
247
+ metadata.participants.push(...participants.map(participant => ({ id: participant.id, phoneNumber: participant.phoneNumber, admin: participant.admin })));
248
+ break;
249
+ case 'demote':
250
+ case 'promote':
251
+ for (const participant of metadata.participants) {
252
+ for (const participantData of participants) {
253
+ if (participantData.id === participant.id || participantData.phoneNumber === participant.phoneNumber) {
254
+ participant.admin = action === 'promote' && 'admin';
255
+ }
256
+ }
257
+ }
258
+ break;
259
+ case 'remove':
260
+ const removeSet = new Set();
261
+ for (const p of participants) {
262
+ if (p.id)
263
+ removeSet.add(p.id);
264
+ if (p.phoneNumber)
265
+ removeSet.add(p.phoneNumber);
266
+ }
267
+ metadata.participants = metadata.participants.reduce((acc, p) => {
268
+ if (!removeSet.has(p.id) && !removeSet.has(p.phoneNumber))
269
+ acc.push(p);
270
+ return acc;
271
+ }, []);
272
+ break;
273
+ }
274
+ }
275
+ });
276
+ ev.on('message-receipt.update', updates => {
277
+ for (const { key, receipt } of updates) {
278
+ const obj = messages[key.remoteJidAlt || key.remoteJid];
279
+ const msg = obj === null || obj === void 0 ? void 0 : obj.get(key.id);
280
+ if (msg) {
281
+ updateMessageWithReceipt(msg, receipt);
282
+ }
283
+ }
284
+ });
285
+ ev.on('messages.reaction', (reactions) => {
286
+ for (const { key, reaction } of reactions) {
287
+ const obj = messages[key.remoteJidAlt || key.remoteJid];
288
+ const msg = obj === null || obj === void 0 ? void 0 : obj.get(key.id);
289
+ if (msg) {
290
+ updateMessageWithReaction(msg, reaction);
291
+ }
292
+ }
293
+ });
294
+ };
295
+ const toJSON = () => ({
296
+ chats,
297
+ contacts,
298
+ messages,
299
+ labels,
300
+ labelAssociations
301
+ });
302
+ const fromJSON = (json) => {
303
+ chats.upsert(...json.chats);
304
+ labelAssociations.upsert(...json.labelAssociations || []);
305
+ contactsUpsert(Object.values(json.contacts));
306
+ labelsUpsert(Object.values(json.labels || {}));
307
+ for (const jid in json.messages) {
308
+ const list = assertMessageList(jid);
309
+ for (const msg of json.messages[jid]) {
310
+ list.upsert(WAProto.WebMessageInfo.fromObject(msg), 'append');
311
+ }
312
+ }
313
+ };
314
+ return {
315
+ chats,
316
+ contacts,
317
+ messages,
318
+ groupMetadata,
319
+ state,
320
+ presences,
321
+ labels,
322
+ labelAssociations,
323
+ bind,
324
+ /** loads messages from the store, if not found -- uses the legacy connection */
325
+ loadMessages: async (jid, count, cursor) => {
326
+ const list = assertMessageList(jid);
327
+ const mode = !cursor || 'before' in cursor ? 'before' : 'after';
328
+ const cursorKey = !!cursor ? ('before' in cursor ? cursor.before : cursor.after) : undefined;
329
+ const cursorValue = cursorKey ? list.get(cursorKey.id) : undefined;
330
+ let messages;
331
+ if (list && mode === 'before' && (!cursorKey || cursorValue)) {
332
+ if (cursorValue) {
333
+ const msgIdx = list.array.findIndex(m => m.key.id === (cursorKey === null || cursorKey === void 0 ? void 0 : cursorKey.id));
334
+ messages = list.array.slice(0, msgIdx);
335
+ }
336
+ else {
337
+ messages = list.array;
338
+ }
339
+ const diff = count - messages.length;
340
+ if (diff < 0) {
341
+ messages = messages.slice(-count); // get the last X messages
342
+ }
343
+ }
344
+ else {
345
+ messages = [];
346
+ }
347
+ return messages;
348
+ },
349
+ /**
350
+ * Get all available labels for profile
351
+ *
352
+ * Keep in mind that the list is formed from predefined tags and tags
353
+ * that were "caught" during their editing.
354
+ */
355
+ getLabels: () => {
356
+ return labels;
357
+ },
358
+ /**
359
+ * Get labels for chat
360
+ *
361
+ * @returns Label IDs
362
+ **/
363
+ getChatLabels: (chatId) => {
364
+ return labelAssociations.filter((la) => la.chatId === chatId).all();
365
+ },
366
+ /**
367
+ * Get labels for message
368
+ *
369
+ * @returns Label IDs
370
+ **/
371
+ getMessageLabels: (messageId) => {
372
+ const associations = labelAssociations
373
+ .filter((la) => la.messageId === messageId)
374
+ .all();
375
+ return associations.map(({ labelId }) => labelId);
376
+ },
377
+ loadMessage: async (jid, id) => { var _a; return (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.get(id); },
378
+ mostRecentMessage: async (jid) => {
379
+ var _a;
380
+ const message = (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.array.slice(-1)[0];
381
+ return message;
382
+ },
383
+ fetchImageUrl: async (jid, sock) => {
384
+ const contact = contacts[jid];
385
+ if (!contact) {
386
+ return sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid);
387
+ }
388
+ if (typeof contact.imgUrl === 'undefined') {
389
+ contact.imgUrl = await (sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid));
390
+ }
391
+ return contact.imgUrl;
392
+ },
393
+ fetchGroupMetadata: async (jid, sock) => {
394
+ if (!groupMetadata[jid]) {
395
+ const metadata = await (sock === null || sock === void 0 ? void 0 : sock.groupMetadata(jid));
396
+ if (metadata) {
397
+ groupMetadata[jid] = metadata;
398
+ }
399
+ }
400
+ return groupMetadata[jid];
401
+ },
402
+ fetchMessageReceipts: async ({ remoteJid, id }) => {
403
+ const list = messages[remoteJid];
404
+ const msg = list === null || list === void 0 ? void 0 : list.get(id);
405
+ return msg === null || msg === void 0 ? void 0 : msg.userReceipt;
406
+ },
407
+ toJSON,
408
+ fromJSON,
409
+ writeToFile: (path) => {
410
+ writeFileSync(path, JSON.stringify(toJSON()));
411
+ },
412
+ readFromFile: (path) => {
413
+ if (existsSync(path)) {
414
+ logger.debug({ path }, 'reading from file');
415
+ const jsonStr = readFileSync(path, { encoding: 'utf-8' });
416
+ const json = JSON.parse(jsonStr);
417
+ fromJSON(json);
418
+ }
419
+ }
420
+ };
421
+ };
@@ -0,0 +1,78 @@
1
+ export function makeOrderedDictionary(idGetter) {
2
+ const array = [];
3
+ const dict = {};
4
+ const get = (id) => dict[id];
5
+ const update = (item) => {
6
+ const id = idGetter(item);
7
+ const idx = array.findIndex(i => idGetter(i) === id);
8
+ if (idx >= 0) {
9
+ array[idx] = item;
10
+ dict[id] = item;
11
+ }
12
+ return false;
13
+ };
14
+ const upsert = (item, mode) => {
15
+ const id = idGetter(item);
16
+ if (get(id)) {
17
+ update(item);
18
+ }
19
+ else {
20
+ if (mode === 'append') {
21
+ array.push(item);
22
+ }
23
+ else {
24
+ array.splice(0, 0, item);
25
+ }
26
+ dict[id] = item;
27
+ }
28
+ };
29
+ const remove = (item) => {
30
+ const id = idGetter(item);
31
+ const idx = array.findIndex(i => idGetter(i) === id);
32
+ if (idx >= 0) {
33
+ array.splice(idx, 1);
34
+ delete dict[id];
35
+ return true;
36
+ }
37
+ return false;
38
+ };
39
+ return {
40
+ array,
41
+ get,
42
+ upsert,
43
+ update,
44
+ remove,
45
+ updateAssign: (id, update) => {
46
+ const item = get(id);
47
+ if (item) {
48
+ Object.assign(item, update);
49
+ delete dict[id];
50
+ dict[idGetter(item)] = item;
51
+ return true;
52
+ }
53
+ return false;
54
+ },
55
+ clear: () => {
56
+ array.splice(0, array.length);
57
+ for (const key of Object.keys(dict)) {
58
+ delete dict[key];
59
+ }
60
+ },
61
+ filter: (contain) => {
62
+ let i = 0;
63
+ while (i < array.length) {
64
+ if (!contain(array[i])) {
65
+ delete dict[idGetter(array[i])];
66
+ array.splice(i, 1);
67
+ }
68
+ else {
69
+ i += 1;
70
+ }
71
+ }
72
+ },
73
+ toJSON: () => array,
74
+ fromJSON: (newItems) => {
75
+ array.splice(0, array.length, ...newItems);
76
+ }
77
+ };
78
+ }
@@ -0,0 +1,23 @@
1
+ export class ObjectRepository {
2
+ constructor(entities = {}) {
3
+ this.entityMap = new Map(Object.entries(entities));
4
+ }
5
+ findById(id) {
6
+ return this.entityMap.get(id);
7
+ }
8
+ findAll() {
9
+ return Array.from(this.entityMap.values());
10
+ }
11
+ upsertById(id, entity) {
12
+ return this.entityMap.set(id, { ...entity });
13
+ }
14
+ deleteById(id) {
15
+ return this.entityMap.delete(id);
16
+ }
17
+ count() {
18
+ return this.entityMap.size;
19
+ }
20
+ toJSON() {
21
+ return this.findAll();
22
+ }
23
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ export const ALL_WA_PATCH_NAMES = [
2
+ 'critical_block',
3
+ 'critical_unblock_low',
4
+ 'regular_high',
5
+ 'regular_low',
6
+ 'regular'
7
+ ];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ import { proto } from '../../WAProto/index.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ /** WhatsApp has 20 predefined colors */
2
+ export var LabelColor;
3
+ (function (LabelColor) {
4
+ LabelColor[LabelColor["Color1"] = 0] = "Color1";
5
+ LabelColor[LabelColor["Color2"] = 1] = "Color2";
6
+ LabelColor[LabelColor["Color3"] = 2] = "Color3";
7
+ LabelColor[LabelColor["Color4"] = 3] = "Color4";
8
+ LabelColor[LabelColor["Color5"] = 4] = "Color5";
9
+ LabelColor[LabelColor["Color6"] = 5] = "Color6";
10
+ LabelColor[LabelColor["Color7"] = 6] = "Color7";
11
+ LabelColor[LabelColor["Color8"] = 7] = "Color8";
12
+ LabelColor[LabelColor["Color9"] = 8] = "Color9";
13
+ LabelColor[LabelColor["Color10"] = 9] = "Color10";
14
+ LabelColor[LabelColor["Color11"] = 10] = "Color11";
15
+ LabelColor[LabelColor["Color12"] = 11] = "Color12";
16
+ LabelColor[LabelColor["Color13"] = 12] = "Color13";
17
+ LabelColor[LabelColor["Color14"] = 13] = "Color14";
18
+ LabelColor[LabelColor["Color15"] = 14] = "Color15";
19
+ LabelColor[LabelColor["Color16"] = 15] = "Color16";
20
+ LabelColor[LabelColor["Color17"] = 16] = "Color17";
21
+ LabelColor[LabelColor["Color18"] = 17] = "Color18";
22
+ LabelColor[LabelColor["Color19"] = 18] = "Color19";
23
+ LabelColor[LabelColor["Color20"] = 19] = "Color20";
24
+ })(LabelColor || (LabelColor = {}));
@@ -0,0 +1,6 @@
1
+ /** Association type */
2
+ export var LabelAssociationType;
3
+ (function (LabelAssociationType) {
4
+ LabelAssociationType["Chat"] = "label_jid";
5
+ LabelAssociationType["Message"] = "label_message";
6
+ })(LabelAssociationType || (LabelAssociationType = {}));
@@ -0,0 +1,17 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ // export the WAMessage Prototypes
3
+ export { proto as WAProto };
4
+ // Lia@Changes 03-02-26 --- Add exported message-related enum types from proto.Message
5
+ export const AssociationType = proto.MessageAssociation.AssociationType;
6
+ export const ButtonHeaderType = proto.Message.ButtonsMessage.HeaderType;
7
+ export const ButtonType = proto.Message.ButtonsMessage.Button.Type;
8
+ export const CarouselCardType = proto.Message.InteractiveMessage.CarouselMessage.CarouselCardType;
9
+ export const ListType = proto.Message.ListMessage.ListType;
10
+ export const ProtocolType = proto.Message.ProtocolMessage.Type;
11
+ export const WAMessageStubType = proto.WebMessageInfo.StubType;
12
+ export const WAMessageStatus = proto.WebMessageInfo.Status;
13
+ export var WAMessageAddressingMode;
14
+ (function (WAMessageAddressingMode) {
15
+ WAMessageAddressingMode["PN"] = "pn";
16
+ WAMessageAddressingMode["LID"] = "lid";
17
+ })(WAMessageAddressingMode || (WAMessageAddressingMode = {}));
@@ -0,0 +1,33 @@
1
+ export var XWAPaths;
2
+ (function (XWAPaths) {
3
+ XWAPaths["xwa2_newsletter_create"] = "xwa2_newsletter_create";
4
+ XWAPaths["xwa2_newsletter_subscribers"] = "xwa2_newsletter_subscribers";
5
+ XWAPaths["xwa2_newsletter_subscribed"] = "xwa2_newsletter_subscribed";
6
+ XWAPaths["xwa2_newsletter_view"] = "xwa2_newsletter_view";
7
+ XWAPaths["xwa2_newsletter_metadata"] = "xwa2_newsletter";
8
+ XWAPaths["xwa2_newsletter_admin_count"] = "xwa2_newsletter_admin";
9
+ XWAPaths["xwa2_newsletter_mute_v2"] = "xwa2_newsletter_mute_v2";
10
+ XWAPaths["xwa2_newsletter_unmute_v2"] = "xwa2_newsletter_unmute_v2";
11
+ XWAPaths["xwa2_newsletter_follow"] = "xwa2_newsletter_follow";
12
+ XWAPaths["xwa2_newsletter_unfollow"] = "xwa2_newsletter_unfollow";
13
+ XWAPaths["xwa2_newsletter_change_owner"] = "xwa2_newsletter_change_owner";
14
+ XWAPaths["xwa2_newsletter_demote"] = "xwa2_newsletter_demote";
15
+ XWAPaths["xwa2_newsletter_delete_v2"] = "xwa2_newsletter_delete_v2";
16
+ })(XWAPaths || (XWAPaths = {}));
17
+ export var QueryIds;
18
+ (function (QueryIds) {
19
+ QueryIds["CREATE"] = "8823471724422422";
20
+ QueryIds["UPDATE_METADATA"] = "24250201037901610";
21
+ QueryIds["METADATA"] = "6563316087068696";
22
+ QueryIds["JOB_MUTATION"] = "7150902998257522";
23
+ QueryIds["SUBSCRIBERS"] = "9783111038412085";
24
+ QueryIds["SUBSCRIBED"] = "6388546374527196";
25
+ QueryIds["FOLLOW"] = "7871414976211147";
26
+ QueryIds["UNFOLLOW"] = "7238632346214362";
27
+ QueryIds["MUTE"] = "29766401636284406";
28
+ QueryIds["UNMUTE"] = "9864994326891137";
29
+ QueryIds["ADMIN_COUNT"] = "7130823597031706";
30
+ QueryIds["CHANGE_OWNER"] = "7341777602580933";
31
+ QueryIds["DEMOTE"] = "6551828931592903";
32
+ QueryIds["DELETE"] = "30062808666639665";
33
+ })(QueryIds || (QueryIds = {}));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ import { proto } from '../../WAProto/index.js';
@@ -0,0 +1,2 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import {} from './Message.js';
@@ -0,0 +1,12 @@
1
+ import { Boom } from '@hapi/boom';
2
+ export var SyncState;
3
+ (function (SyncState) {
4
+ /** The socket is connecting, but we haven't received pending notifications yet. */
5
+ SyncState[SyncState["Connecting"] = 0] = "Connecting";
6
+ /** Pending notifications received. Buffering events until we decide whether to sync or not. */
7
+ SyncState[SyncState["AwaitingInitialSync"] = 1] = "AwaitingInitialSync";
8
+ /** The initial app state sync (history, etc.) is in progress. Buffering continues. */
9
+ SyncState[SyncState["Syncing"] = 2] = "Syncing";
10
+ /** Initial sync is complete, or was skipped. The socket is fully operational and events are processed in real-time. */
11
+ SyncState[SyncState["Online"] = 3] = "Online";
12
+ })(SyncState || (SyncState = {}));
@@ -0,0 +1 @@
1
+ import { USyncUser } from '../WAUSync/index.js';