@vanzxy/baileys 1.4.1 → 1.4.2

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.

Potentially problematic release.


This version of @vanzxy/baileys might be problematic. Click here for more details.

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