kage-baileys 3.0.6 → 3.2.4

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 (217) hide show
  1. package/Example/connection.cjs +4 -0
  2. package/README.MD +4726 -48
  3. package/README.md +5941 -0
  4. package/WAProto/WAProto.proto +3395 -415
  5. package/WAProto/compat.cjs +12 -0
  6. package/WAProto/index.d.ts +47104 -19888
  7. package/WAProto/index.js +131979 -57361
  8. package/lib/Addon/http-error.js +43 -0
  9. package/lib/Addon/index.js +32 -0
  10. package/lib/Addon/keyed-db.js +250 -0
  11. package/lib/Addon/link-preview.js +82 -0
  12. package/lib/Defaults/baileys-version.json +3 -0
  13. package/lib/Defaults/connection.js +110 -0
  14. package/lib/Defaults/constants.js +156 -0
  15. package/lib/Defaults/history.js +46 -0
  16. package/lib/Defaults/index.js +230 -0
  17. package/lib/Defaults/media.js +104 -0
  18. package/lib/Defaults/phonenumber-mcc.json +223 -0
  19. package/lib/Defaults/prefix.js +44 -0
  20. package/lib/Extensions/business-advanced.js +382 -0
  21. package/lib/Extensions/business.js +159 -0
  22. package/lib/Extensions/chats-advanced.js +1106 -0
  23. package/lib/Extensions/chats.js +349 -0
  24. package/lib/Extensions/communities-advanced.js +430 -0
  25. package/lib/Extensions/community.js +94 -0
  26. package/lib/Extensions/groups-advanced.js +343 -0
  27. package/lib/Extensions/index.js +30 -0
  28. package/lib/Extensions/messages-recv-advanced.js +1690 -0
  29. package/lib/Extensions/messages-send-advanced.js +622 -0
  30. package/lib/Extensions/messages-send.js +1380 -0
  31. package/lib/Extensions/newsletter-advanced.js +228 -0
  32. package/lib/Extensions/newsletter.js +72 -0
  33. package/lib/Extensions/socket.js +389 -0
  34. package/lib/Modded/message_builder.js +2084 -4
  35. package/lib/Signal/Group/ciphertext-message.js +54 -0
  36. package/lib/Signal/Group/group-session-builder.js +124 -0
  37. package/lib/Signal/Group/group_cipher.js +216 -0
  38. package/lib/Signal/Group/index.js +124 -0
  39. package/lib/Signal/Group/keyhelper.js +108 -0
  40. package/lib/Signal/Group/sender-chain-key.js +83 -0
  41. package/lib/Signal/Group/sender-key-distribution-message.js +157 -0
  42. package/lib/Signal/Group/sender-key-message.js +166 -0
  43. package/lib/Signal/Group/sender-key-name.js +130 -0
  44. package/lib/Signal/Group/sender-key-record.js +113 -0
  45. package/lib/Signal/Group/sender-key-state.js +208 -0
  46. package/lib/Signal/Group/sender-message-key.js +82 -0
  47. package/lib/Signal/libsignal.js +935 -0
  48. package/lib/Signal/lid-mapping.js +545 -1
  49. package/lib/Socket/Client/index.js +60 -0
  50. package/lib/Socket/Client/types.js +51 -0
  51. package/lib/Socket/Client/websocket.js +152 -0
  52. package/lib/Socket/business.js +831 -0
  53. package/lib/Socket/chats.js +2535 -49
  54. package/lib/Socket/communities.js +450 -1
  55. package/lib/Socket/community.js +1022 -0
  56. package/lib/Socket/dugong.js +1 -1
  57. package/lib/Socket/groups.js +747 -0
  58. package/lib/Socket/index.js +60 -2
  59. package/lib/Socket/messages-recv.js +3450 -5
  60. package/lib/Socket/messages-send.js +3123 -0
  61. package/lib/Socket/mex.js +126 -1
  62. package/lib/Socket/newsletter.js +465 -0
  63. package/lib/Socket/socket.js +2217 -1
  64. package/lib/Store/index.js +79 -0
  65. package/lib/Store/make-cache-manager-store.js +186 -0
  66. package/lib/Store/make-in-memory-store.js +878 -0
  67. package/lib/Store/make-ordered-dictionary.js +187 -0
  68. package/lib/Store/object-repository.js +78 -0
  69. package/lib/Types/Auth.js +25 -0
  70. package/lib/Types/Bussines.js +25 -1
  71. package/lib/Types/Call.js +25 -0
  72. package/lib/Types/Chat.js +39 -0
  73. package/lib/Types/Contact.js +25 -0
  74. package/lib/Types/Events.js +25 -0
  75. package/lib/Types/GroupMetadata.js +25 -0
  76. package/lib/Types/Label.js +76 -0
  77. package/lib/Types/LabelAssociation.js +40 -0
  78. package/lib/Types/Message.js +57 -0
  79. package/lib/Types/Mex.js +56 -1
  80. package/lib/Types/MexUpdates.js +46 -0
  81. package/lib/Types/Newsletter.js +56 -0
  82. package/lib/Types/Product.js +25 -0
  83. package/lib/Types/RichType.js +23 -0
  84. package/lib/Types/Signal.js +25 -0
  85. package/lib/Types/Socket.js +25 -0
  86. package/lib/Types/State.js +92 -0
  87. package/lib/Types/USync.js +25 -0
  88. package/lib/Types/index.js +133 -0
  89. package/lib/Utils/auth-utils.js +703 -0
  90. package/lib/Utils/automation-tools.js +51 -16
  91. package/lib/Utils/baileys-event-stream.js +146 -0
  92. package/lib/Utils/browser-utils.js +95 -0
  93. package/lib/Utils/business.js +525 -0
  94. package/lib/Utils/chat-utils.js +1861 -0
  95. package/lib/Utils/companion-reg-client-utils.js +55 -1
  96. package/lib/Utils/crypto.js +355 -0
  97. package/lib/Utils/decode-wa-message.js +709 -0
  98. package/lib/Utils/event-buffer.js +1323 -8
  99. package/lib/Utils/generics.js +945 -1
  100. package/lib/Utils/history.js +266 -0
  101. package/lib/Utils/identity-change-handler.js +62 -1
  102. package/lib/Utils/index.js +114 -0
  103. package/lib/Utils/link-preview.js +179 -0
  104. package/lib/Utils/logger.js +42 -0
  105. package/lib/Utils/lt-hash.js +73 -0
  106. package/lib/Utils/make-mutex.js +104 -0
  107. package/lib/Utils/message-inspector.js +110 -0
  108. package/lib/Utils/message-retry-manager.js +507 -2
  109. package/lib/Utils/messages-media.js +1931 -1
  110. package/lib/Utils/messages.js +3748 -0
  111. package/lib/Utils/noise-handler.js +423 -0
  112. package/lib/Utils/offline-node-processor.js +53 -1
  113. package/lib/Utils/pre-key-manager.js +255 -1
  114. package/lib/Utils/process-message.js +1592 -0
  115. package/lib/Utils/reporting-utils.js +272 -1
  116. package/lib/Utils/rich-message-utils.js +377 -0
  117. package/lib/Utils/rich-messages.js +1 -1
  118. package/lib/Utils/signal.js +437 -0
  119. package/lib/Utils/stanza-ack.js +51 -1
  120. package/lib/Utils/status-refresh.js +37 -0
  121. package/lib/Utils/status-tools.js +4 -2
  122. package/lib/Utils/sync-action-utils.js +63 -1
  123. package/lib/Utils/tc-token-utils.js +185 -1
  124. package/lib/Utils/terminal-banner.js +31 -0
  125. package/lib/Utils/use-multi-file-auth-state.js +271 -0
  126. package/lib/Utils/use-single-file-auth-state.js +108 -0
  127. package/lib/Utils/use-sqlite-auth-state.js +142 -0
  128. package/lib/Utils/validate-connection.js +497 -1
  129. package/lib/Utils/view-once-compat.js +13 -5
  130. package/lib/VoIP/audio-feeder.js +150 -0
  131. package/lib/VoIP/index.js +289 -0
  132. package/lib/VoIP/relay-transport.js +608 -0
  133. package/lib/VoIP/signaling.js +583 -0
  134. package/lib/VoIP/types.js +30 -0
  135. package/lib/VoIP/wasm-engine.js +1261 -2
  136. package/lib/VoIP/worker-bootstrap.js +1090 -2
  137. package/lib/WABinary/constants.js +2805 -0
  138. package/lib/WABinary/decode.js +649 -2
  139. package/lib/WABinary/encode.js +564 -2
  140. package/lib/WABinary/generic-utils.js +401 -0
  141. package/lib/WABinary/index.js +82 -0
  142. package/lib/WABinary/jid-utils.js +290 -0
  143. package/lib/WABinary/types.js +25 -0
  144. package/lib/WAM/BinaryInfo.js +50 -0
  145. package/lib/WAM/constants.js +45747 -0
  146. package/lib/WAM/encode.js +393 -0
  147. package/lib/WAM/index.js +78 -0
  148. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +135 -0
  149. package/lib/WAUSync/Protocols/USyncContactProtocol.js +110 -0
  150. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +142 -0
  151. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +85 -0
  152. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +69 -0
  153. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +107 -0
  154. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +38 -1
  155. package/lib/WAUSync/Protocols/index.js +83 -0
  156. package/lib/WAUSync/USyncQuery.js +241 -2
  157. package/lib/WAUSync/USyncUser.js +86 -0
  158. package/lib/WAUSync/index.js +78 -0
  159. package/lib/assets/wasm/loader.js +1875 -1
  160. package/lib/assets/wasm/worker-modules.js +11047 -1
  161. package/lib/index.d.ts +126 -0
  162. package/lib/index.js +53 -21
  163. package/lib/index.mjs +437 -0
  164. package/licenses/upstream-MIT.txt +22 -0
  165. package/maintenance/api-coverage.json +1642 -0
  166. package/maintenance/archivos-sha256.json +207 -0
  167. package/maintenance/consumer-validation.log +3 -0
  168. package/maintenance/dependency-audit.json +4 -4
  169. package/maintenance/extension-inventory.json +57 -0
  170. package/maintenance/protocol-update.json +1101 -0
  171. package/maintenance/protocol-wire-audit.json +4 -0
  172. package/maintenance/reference-socket-surface.json +209 -0
  173. package/maintenance/resumen-validacion.json +50 -0
  174. package/maintenance/validation.log +2725 -0
  175. package/maintenance/verification.json +566 -0
  176. package/package.json +107 -9
  177. package/scripts/check-imports.cjs +10 -0
  178. package/scripts/check-package.cjs +40 -0
  179. package/scripts/check-syntax.cjs +1 -1
  180. package/scripts/generate-protobuf.cjs +6 -1
  181. package/scripts/generate-public-types.cjs +9 -0
  182. package/scripts/kage-base64-fix.cjs +45 -0
  183. package/scripts/maintenance.cjs +10 -0
  184. package/test/advanced.test.cjs +24 -0
  185. package/test/base64-fix.test.cjs +49 -0
  186. package/test/maintenance.test.cjs +1 -1
  187. package/test/npm-publication.test.cjs +141 -0
  188. package/test/recepcion-reparada.test.cjs +98 -0
  189. package/test/resilience-binary.test.cjs +69 -0
  190. package/test/resilience-transport.test.cjs +34 -0
  191. package/test/types.test.ts +5 -0
  192. package/test/upgrade.test.cjs +104 -0
  193. package/tsconfig.json +20 -0
  194. package/WAProto/p.html +0 -1
  195. package/lib/KageExtra/Modded/message_builder.js +0 -2330
  196. package/lib/KageExtra/VoIP/audio-feeder.js +0 -136
  197. package/lib/KageExtra/VoIP/index.js +0 -282
  198. package/lib/KageExtra/VoIP/relay-transport.js +0 -559
  199. package/lib/KageExtra/VoIP/signaling.js +0 -603
  200. package/lib/KageExtra/VoIP/types.js +0 -17
  201. package/lib/KageExtra/VoIP/wasm-engine.js +0 -1214
  202. package/lib/KageExtra/VoIP/worker-bootstrap.js +0 -1042
  203. package/lib/KageExtra/assets/wasm/loader.js +0 -5
  204. package/lib/KageExtra/assets/wasm/whatsapp.wasm +0 -0
  205. package/lib/KageExtra/assets/wasm/worker-modules.js +0 -273
  206. package/lib/KageExtra/index.js +0 -3
  207. package/lib/KageExtra/package.json +0 -1
  208. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
  209. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
  210. package/maintenance/revision-full-check.txt +0 -1097
  211. package/maintenance/revision-library-tests.tap +0 -1088
  212. package/maintenance/revision-protobuf.txt +0 -5
  213. package/maintenance/revision-syntax.txt +0 -5
  214. package/maintenance/schema-coverage.json +0 -23
  215. package/maintenance/schema-merge.json +0 -30
  216. package/maintenance/validation-node20.txt +0 -191
  217. package/maintenance/validation-node22.txt +0 -237
@@ -95,3 +95,269 @@ const getHistoryMsg = (message) => {
95
95
  return anyHistoryMsg;
96
96
  };
97
97
  exports.getHistoryMsg = getHistoryMsg;
98
+
99
+ // Kage: compatibilidad de API.
100
+ const __kageModule66 = (() => {
101
+ const module = { exports: {} }; const exports = module.exports;
102
+ "use strict"
103
+
104
+ Object.defineProperty(exports, "__esModule", { value: true })
105
+
106
+ const { promisify } = require("util")
107
+ const { inflate } = require("zlib")
108
+ const { proto } = require("../../WAProto")
109
+ const { WAMessageStubType } = require("../Types")
110
+ const { toNumber } = require("./generics")
111
+ const { normalizeMessageContent } = require("./messages")
112
+ const { downloadContentFromMessage } = require("./messages-media")
113
+ const inflatePromise = promisify(inflate)
114
+
115
+ const downloadHistory = async (msg, options) => {
116
+ const stream = await downloadContentFromMessage(msg, 'md-msg-hist', { options })
117
+ const bufferArray = []
118
+ for await (const chunk of stream) {
119
+ bufferArray.push(chunk)
120
+ }
121
+ let buffer = Buffer.concat(bufferArray)
122
+ // decompress buffer
123
+ buffer = await inflatePromise(buffer)
124
+ const syncData = proto.HistorySync.decode(buffer)
125
+ return syncData
126
+ }
127
+
128
+ const processHistoryMessage = (item) => {
129
+ const messages = []
130
+ const contacts = []
131
+ const chats = []
132
+ switch (item.syncType) {
133
+ case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
134
+ case proto.HistorySync.HistorySyncType.RECENT:
135
+ case proto.HistorySync.HistorySyncType.FULL:
136
+ case proto.HistorySync.HistorySyncType.ON_DEMAND:
137
+ for (const chat of item.conversations) {
138
+ contacts.push({
139
+ id: chat.id,
140
+ name: chat.name || undefined,
141
+ lid: chat.lidJid || undefined,
142
+ phoneNumber: chat.pnJid || undefined
143
+ })
144
+ const msgs = chat.messages || []
145
+ delete chat.messages
146
+ for (const item of msgs) {
147
+ const message = item.message
148
+ messages.push(message)
149
+ if (!chat.messages?.length) {
150
+ // keep only the most recent message in the chat array
151
+ chat.messages = [{ message }]
152
+ }
153
+ if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
154
+ chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp)
155
+ }
156
+ if (message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
157
+ || message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB
158
+ && message.messageStubParameters?.[0]) {
159
+ contacts.push({
160
+ id: message.key.participant || message.key.remoteJid,
161
+ verifiedName: message.messageStubParameters?.[0]
162
+ })
163
+ }
164
+ }
165
+ chats.push({ ...chat })
166
+ }
167
+ break
168
+ case proto.HistorySync.HistorySyncType.PUSH_NAME:
169
+ for (const c of item.pushnames) {
170
+ contacts.push({ id: c.id, notify: c.pushname })
171
+ }
172
+ break
173
+ }
174
+ return {
175
+ chats,
176
+ contacts,
177
+ messages,
178
+ syncType: item.syncType,
179
+ progress: item.progress
180
+ }
181
+ }
182
+
183
+ const downloadAndProcessHistorySyncNotification = async (msg, options) => {
184
+ let historyMsg
185
+
186
+ if (msg.initialHistBootstrapInlinePayload) {
187
+ historyMsg = proto.HistorySync.decode(await inflatePromise(msg.initialHistBootstrapInlinePayload))
188
+ }
189
+ else {
190
+ historyMsg = await downloadHistory(msg, options)
191
+ }
192
+
193
+ return processHistoryMessage(historyMsg)
194
+ }
195
+
196
+ const getHistoryMsg = (message) => {
197
+ const normalizedContent = !!message ? normalizeMessageContent(message) : undefined
198
+ const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification
199
+ return anyHistoryMsg
200
+ }
201
+
202
+ module.exports = {
203
+ downloadHistory,
204
+ processHistoryMessage,
205
+ downloadAndProcessHistorySyncNotification,
206
+ getHistoryMsg
207
+ }
208
+ return module.exports;
209
+ })();
210
+ for (const key of Object.keys(__kageModule66)) {
211
+ if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule66[key]});
212
+ }
213
+
214
+ // Kage: funciones avanzadas.
215
+ const __kageModule170 = (() => {
216
+ const module = { exports: {} }; const exports = module.exports;
217
+ "use strict";
218
+ Object.defineProperty(exports, "__esModule", { value: true });
219
+ exports.getHistoryMsg = exports.downloadAndProcessHistorySyncNotification = exports.processHistoryMessage = exports.downloadHistory = void 0;
220
+ const promises_1 = require("node:stream/promises");
221
+ const node_util_1 = require("node:util");
222
+ const node_zlib_1 = require("node:zlib");
223
+ const index_js_1 = require("../../WAProto/index.js");
224
+ const index_js_2 = require("../Types/index.js");
225
+ const index_js_3 = require("../WABinary/index.js");
226
+ const generics_js_1 = require("./generics.js");
227
+ const messages_js_1 = require("./messages.js");
228
+ const messages_media_js_1 = require("./messages-media.js");
229
+ const inflatePromise = (0, node_util_1.promisify)(node_zlib_1.inflate);
230
+ const extractPnFromMessages = (messages) => {
231
+ for (const msgItem of messages) {
232
+ const message = msgItem.message;
233
+ // Only extract from outgoing messages (fromMe: true) in 1:1 chats
234
+ // because userReceipt.userJid is the recipient's JID
235
+ if (!message?.key?.fromMe || !message.userReceipt?.length) {
236
+ continue;
237
+ }
238
+ const userJid = message.userReceipt[0]?.userJid;
239
+ if (userJid && ((0, index_js_3.isPnUser)(userJid) || (0, index_js_3.isHostedPnUser)(userJid))) {
240
+ return userJid;
241
+ }
242
+ }
243
+ return undefined;
244
+ };
245
+ const downloadHistory = async (msg, options) => {
246
+ const stream = await (0, messages_media_js_1.downloadContentFromMessage)(msg, 'md-msg-hist', { options });
247
+ // Pipe decrypted stream directly through zlib inflate
248
+ // This avoids allocating an intermediate buffer for the compressed data
249
+ const inflater = (0, node_zlib_1.createInflate)();
250
+ const chunks = [];
251
+ inflater.on('data', (chunk) => chunks.push(chunk));
252
+ await (0, promises_1.pipeline)(stream, inflater);
253
+ const buffer = Buffer.concat(chunks);
254
+ const syncData = index_js_1.proto.HistorySync.decode(buffer);
255
+ return syncData;
256
+ };
257
+ exports.downloadHistory = downloadHistory;
258
+ const processHistoryMessage = (item, logger) => {
259
+ const messages = [];
260
+ const contacts = [];
261
+ const chats = [];
262
+ const lidPnMappings = [];
263
+ logger?.trace({ progress: item.progress }, 'processing history of type ' + item.syncType?.toString());
264
+ // Extract LID-PN mappings for all sync types
265
+ for (const m of item.phoneNumberToLidMappings || []) {
266
+ if (m.lidJid && m.pnJid) {
267
+ lidPnMappings.push({ lid: m.lidJid, pn: m.pnJid });
268
+ }
269
+ }
270
+ switch (item.syncType) {
271
+ case index_js_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
272
+ case index_js_1.proto.HistorySync.HistorySyncType.RECENT:
273
+ case index_js_1.proto.HistorySync.HistorySyncType.FULL:
274
+ case index_js_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
275
+ for (const chat of item.conversations) {
276
+ contacts.push({
277
+ id: chat.id,
278
+ name: chat.displayName || chat.name || chat.username || undefined,
279
+ username: chat.username || undefined,
280
+ lid: chat.lidJid || chat.accountLid || undefined,
281
+ phoneNumber: chat.pnJid || undefined
282
+ });
283
+ const chatId = chat.id;
284
+ const isLid = (0, index_js_3.isLidUser)(chatId) || (0, index_js_3.isHostedLidUser)(chatId);
285
+ const isPn = (0, index_js_3.isPnUser)(chatId) || (0, index_js_3.isHostedPnUser)(chatId);
286
+ if (isLid && chat.pnJid) {
287
+ lidPnMappings.push({ lid: chatId, pn: chat.pnJid });
288
+ }
289
+ else if (isPn && chat.lidJid) {
290
+ lidPnMappings.push({ lid: chat.lidJid, pn: chatId });
291
+ }
292
+ else if (isLid && !chat.pnJid) {
293
+ // Fallback: extract PN from userReceipt in messages when pnJid is missing
294
+ const pnFromReceipt = extractPnFromMessages(chat.messages || []);
295
+ if (pnFromReceipt) {
296
+ lidPnMappings.push({ lid: chatId, pn: pnFromReceipt });
297
+ }
298
+ }
299
+ const msgs = chat.messages || [];
300
+ delete chat.messages;
301
+ for (const item of msgs) {
302
+ const message = item.message;
303
+ messages.push(message);
304
+ if (!chat.messages?.length) {
305
+ // keep only the most recent message in the chat array
306
+ chat.messages = [{ message }];
307
+ }
308
+ if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
309
+ chat.lastMessageRecvTimestamp = (0, generics_js_1.toNumber)(message.messageTimestamp);
310
+ }
311
+ if ((message.messageStubType === index_js_2.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
312
+ message.messageStubType === index_js_2.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) &&
313
+ message.messageStubParameters?.[0]) {
314
+ contacts.push({
315
+ id: message.key.participant || message.key.remoteJid,
316
+ verifiedName: message.messageStubParameters?.[0]
317
+ });
318
+ }
319
+ }
320
+ chats.push(chat);
321
+ }
322
+ break;
323
+ case index_js_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
324
+ for (const c of item.pushnames) {
325
+ contacts.push({ id: c.id, notify: c.pushname });
326
+ }
327
+ break;
328
+ }
329
+ return {
330
+ chats,
331
+ contacts,
332
+ messages,
333
+ lidPnMappings,
334
+ pastParticipants: item.pastParticipants,
335
+ syncType: item.syncType,
336
+ progress: item.progress
337
+ };
338
+ };
339
+ exports.processHistoryMessage = processHistoryMessage;
340
+ const downloadAndProcessHistorySyncNotification = async (msg, options, logger) => {
341
+ let historyMsg;
342
+ if (msg.initialHistBootstrapInlinePayload) {
343
+ historyMsg = index_js_1.proto.HistorySync.decode(await inflatePromise(msg.initialHistBootstrapInlinePayload));
344
+ }
345
+ else {
346
+ historyMsg = await (0, exports.downloadHistory)(msg, options);
347
+ }
348
+ return (0, exports.processHistoryMessage)(historyMsg, logger);
349
+ };
350
+ exports.downloadAndProcessHistorySyncNotification = downloadAndProcessHistorySyncNotification;
351
+ const getHistoryMsg = (message) => {
352
+ const normalizedContent = !!message ? (0, messages_js_1.normalizeMessageContent)(message) : undefined;
353
+ const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification;
354
+ return anyHistoryMsg;
355
+ };
356
+ exports.getHistoryMsg = getHistoryMsg;
357
+
358
+ return module.exports;
359
+ })();
360
+ for (const key of Object.keys(__kageModule170)) {
361
+ if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule170[key]});
362
+ }
363
+ Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule170, configurable:true});
@@ -46,4 +46,65 @@ var _genericsjs = require('./generics.js');
46
46
  return { action: 'session_refresh_failed', error };
47
47
  }
48
48
  } exports.handleIdentityChange = handleIdentityChange;
49
- //# sourceMappingURL=identity-change-handler.js.map
49
+ //#
50
+ // Kage: funciones avanzadas.
51
+ const __kageModule171 = (() => {
52
+ const module = { exports: {} }; const exports = module.exports;
53
+ "use strict";
54
+ Object.defineProperty(exports, "__esModule", { value: true });
55
+ exports.handleIdentityChange = handleIdentityChange;
56
+ const index_js_1 = require("../WABinary/index.js");
57
+ const generics_js_1 = require("./generics.js");
58
+ async function handleIdentityChange(node, ctx) {
59
+ const from = node.attrs.from;
60
+ if (!from) {
61
+ return { action: 'invalid_notification' };
62
+ }
63
+ const identityNode = (0, index_js_1.getBinaryNodeChild)(node, 'identity');
64
+ if (!identityNode) {
65
+ return { action: 'no_identity_node' };
66
+ }
67
+ ctx.logger.info({ jid: from }, 'identity changed');
68
+ const decoded = (0, index_js_1.jidDecode)(from);
69
+ if (decoded?.device && decoded.device !== 0) {
70
+ ctx.logger.debug({ jid: from, device: decoded.device }, 'ignoring identity change from companion device');
71
+ return { action: 'skipped_companion_device', device: decoded.device };
72
+ }
73
+ const isSelfPrimary = ctx.meId && ((0, index_js_1.areJidsSameUser)(from, ctx.meId) || (ctx.meLid && (0, index_js_1.areJidsSameUser)(from, ctx.meLid)));
74
+ if (isSelfPrimary) {
75
+ ctx.logger.info({ jid: from }, 'self primary identity changed');
76
+ return { action: 'skipped_self_primary' };
77
+ }
78
+ if (ctx.debounceCache.get(from)) {
79
+ ctx.logger.debug({ jid: from }, 'skipping identity assert (debounced)');
80
+ return { action: 'debounced' };
81
+ }
82
+ ctx.debounceCache.set(from, true);
83
+ const isOfflineNotification = !(0, generics_js_1.isStringNullOrEmpty)(node.attrs.offline);
84
+ const hasExistingSession = await ctx.validateSession(from);
85
+ if (!hasExistingSession.exists) {
86
+ ctx.logger.debug({ jid: from }, 'no old session, skipping session refresh');
87
+ return { action: 'skipped_no_session' };
88
+ }
89
+ ctx.logger.debug({ jid: from }, 'old session exists, will refresh session');
90
+ if (isOfflineNotification) {
91
+ ctx.logger.debug({ jid: from }, 'skipping session refresh during offline processing');
92
+ return { action: 'skipped_offline' };
93
+ }
94
+ ctx.onBeforeSessionRefresh?.(from);
95
+ try {
96
+ await ctx.assertSessions([from], true);
97
+ return { action: 'session_refreshed' };
98
+ }
99
+ catch (error) {
100
+ ctx.logger.warn({ error, jid: from }, 'failed to assert sessions after identity change');
101
+ return { action: 'session_refresh_failed', error };
102
+ }
103
+ }
104
+
105
+ return module.exports;
106
+ })();
107
+ for (const key of Object.keys(__kageModule171)) {
108
+ if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule171[key]});
109
+ }
110
+ Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule171, configurable:true});
@@ -34,3 +34,117 @@ __exportStar(require("./process-message"), exports);
34
34
  __exportStar(require("./message-retry-manager"), exports);
35
35
  __exportStar(require("./browser-utils"), exports);
36
36
  Object.assign(exports, require('./event-message'));
37
+
38
+ // Kage: compatibilidad de API.
39
+ const __kageModule67 = (() => {
40
+ const module = { exports: {} }; const exports = module.exports;
41
+ "use strict"
42
+
43
+ const __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
44
+ if (k2 === undefined) k2 = k
45
+
46
+ let desc = Object.getOwnPropertyDescriptor(m, k)
47
+
48
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
49
+ desc = {
50
+ enumerable: true,
51
+ get: function() {
52
+ return m[k]
53
+ }
54
+ }
55
+ }
56
+
57
+ Object.defineProperty(o, k2, desc)
58
+
59
+ }) : (function(o, m, k, k2) {
60
+ if (k2 === undefined) k2 = k
61
+ o[k2] = m[k]
62
+ }
63
+ ))
64
+
65
+ const __exportStar = (this && this.__exportStar) || function(m, exports) {
66
+ for (var p in m) {
67
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
68
+ __createBinding(exports, m, p)
69
+ }
70
+ }
71
+ }
72
+
73
+ Object.defineProperty(exports, "__esModule", {
74
+ value: true
75
+ })
76
+
77
+ __exportStar(require("./generics"), exports)
78
+ __exportStar(require("./decode-wa-message"), exports)
79
+ __exportStar(require("./messages"), exports)
80
+ __exportStar(require("./messages-media"), exports)
81
+ __exportStar(require("./message-retry-manager"), exports)
82
+ __exportStar(require("./validate-connection"), exports)
83
+ __exportStar(require("./crypto"), exports)
84
+ __exportStar(require("./signal"), exports)
85
+ __exportStar(require("./noise-handler"), exports)
86
+ __exportStar(require("./history"), exports)
87
+ __exportStar(require("./chat-utils"), exports)
88
+ __exportStar(require("./lt-hash"), exports)
89
+ __exportStar(require("./auth-utils"), exports)
90
+ __exportStar(require("./browser-utils"), exports)
91
+ __exportStar(require("./use-multi-file-auth-state"), exports)
92
+ __exportStar(require("./link-preview"), exports)
93
+ __exportStar(require("./event-buffer"), exports)
94
+ __exportStar(require("./process-message"), exports)
95
+ return module.exports;
96
+ })();
97
+ for (const key of Object.keys(__kageModule67)) {
98
+ if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule67[key]});
99
+ }
100
+
101
+ // Kage: funciones avanzadas.
102
+ const __kageModule172 = (() => {
103
+ const module = { exports: {} }; const exports = module.exports;
104
+ "use strict";
105
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
106
+ if (k2 === undefined) k2 = k;
107
+ var desc = Object.getOwnPropertyDescriptor(m, k);
108
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
109
+ desc = { enumerable: true, get: function() { return m[k]; } };
110
+ }
111
+ Object.defineProperty(o, k2, desc);
112
+ }) : (function(o, m, k, k2) {
113
+ if (k2 === undefined) k2 = k;
114
+ o[k2] = m[k];
115
+ }));
116
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
117
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
118
+ };
119
+ Object.defineProperty(exports, "__esModule", { value: true });
120
+ __exportStar(require("./generics.js"), exports);
121
+ __exportStar(require("./decode-wa-message.js"), exports);
122
+ __exportStar(require("./messages.js"), exports);
123
+ __exportStar(require("./messages-media.js"), exports);
124
+ __exportStar(require("./validate-connection.js"), exports);
125
+ __exportStar(require("./crypto.js"), exports);
126
+ __exportStar(require("./signal.js"), exports);
127
+ __exportStar(require("./noise-handler.js"), exports);
128
+ __exportStar(require("./history.js"), exports);
129
+ __exportStar(require("./chat-utils.js"), exports);
130
+ __exportStar(require("./lt-hash.js"), exports);
131
+ __exportStar(require("./auth-utils.js"), exports);
132
+ __exportStar(require("./use-multi-file-auth-state.js"), exports);
133
+ __exportStar(require("./use-single-file-auth-state.js"), exports);
134
+ __exportStar(require("./use-sqlite-auth-state.js"), exports);
135
+ __exportStar(require("./link-preview.js"), exports);
136
+ __exportStar(require("./event-buffer.js"), exports);
137
+ __exportStar(require("./process-message.js"), exports);
138
+ __exportStar(require("./rich-message-utils.js"), exports);
139
+ __exportStar(require("./message-retry-manager.js"), exports);
140
+ __exportStar(require("./browser-utils.js"), exports);
141
+ __exportStar(require("./companion-reg-client-utils.js"), exports);
142
+ __exportStar(require("./identity-change-handler.js"), exports);
143
+ __exportStar(require("./stanza-ack.js"), exports);
144
+
145
+ return module.exports;
146
+ })();
147
+ for (const key of Object.keys(__kageModule172)) {
148
+ if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule172[key]});
149
+ }
150
+ Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule172, configurable:true});
@@ -124,3 +124,182 @@ const getUrlInfo = async (text, opts = {
124
124
  }
125
125
  };
126
126
  exports.getUrlInfo = getUrlInfo;
127
+
128
+ // Kage: compatibilidad de API.
129
+ const __kageModule68 = (() => {
130
+ const module = { exports: {} }; const exports = module.exports;
131
+ "use strict"
132
+
133
+ Object.defineProperty(exports, "__esModule", { value: true })
134
+
135
+ const { unfurl } = require('unfurl.js')
136
+ const { prepareWAMessageMedia } = require("./messages")
137
+ const {
138
+ getHttpStream,
139
+ extractImageThumb
140
+ } = require("./messages-media")
141
+ const THUMBNAIL_WIDTH_PX = 192
142
+
143
+ /** Fetches an image and generates a thumbnail for it */
144
+ const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
145
+ const stream = await getHttpStream(url, fetchOpts)
146
+ const result = await extractImageThumb(stream, thumbnailWidth)
147
+ return result
148
+ }
149
+
150
+ /**
151
+ * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
152
+ * Return undefined if the fetch failed or no URL was found
153
+ * @param text first matched URL in text
154
+ * @returns the URL info required to generate link preview
155
+ */
156
+ const getUrlInfo = async (text, opts = { thumbnailWidth: THUMBNAIL_WIDTH_PX, fetchOpts: { timeout: 3000 } }) => {
157
+ try {
158
+ let previewLink = text
159
+
160
+ if (!text.startsWith('https://') && !text.startsWith('http://')) {
161
+ previewLink = 'https://' + previewLink
162
+ }
163
+
164
+ const { open_graph: info } = await unfurl(previewLink, {
165
+ ...opts.fetchOpts,
166
+ oembed: false,
167
+ compress: true,
168
+ size: 0,
169
+ follow: 50
170
+ })
171
+
172
+ if (info && 'title' in info && info.title) {
173
+ const image = info.images?.[0]?.url
174
+ const urlInfo = {
175
+ 'canonical-url': info.url,
176
+ 'matched-text': text,
177
+ title: info.title,
178
+ description: info.description,
179
+ originalThumbnailUrl: image
180
+ }
181
+
182
+ if (opts.uploadImage) {
183
+ const { imageMessage } = await prepareWAMessageMedia({ image: { url: image } }, {
184
+ upload: opts.uploadImage,
185
+ mediaTypeOverride: 'thumbnail-link',
186
+ options: opts.fetchOpts
187
+ })
188
+
189
+ urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined
190
+ urlInfo.highQualityThumbnail = imageMessage || undefined
191
+ }
192
+ else {
193
+ try {
194
+ urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined
195
+ }
196
+ catch (error) {
197
+ opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail')
198
+ }
199
+ }
200
+ return urlInfo
201
+ }
202
+ }
203
+ catch (error) {
204
+ if (!error.message.includes('receive a valid')) {
205
+ throw error
206
+ }
207
+ }
208
+ }
209
+
210
+ module.exports = {
211
+ getUrlInfo
212
+ }
213
+ return module.exports;
214
+ })();
215
+ for (const key of Object.keys(__kageModule68)) {
216
+ if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule68[key]});
217
+ }
218
+
219
+ // Kage: funciones avanzadas.
220
+ const __kageModule173 = (() => {
221
+ const module = { exports: {} }; const exports = module.exports;
222
+ "use strict";
223
+ Object.defineProperty(exports, "__esModule", { value: true });
224
+ exports.getUrlInfo = void 0;
225
+ const index_js_1 = require("../Addon/index.js");
226
+ const messages_js_1 = require("./messages.js");
227
+ const messages_media_js_1 = require("./messages-media.js");
228
+ const URL_PROTOCOL_REGEX = /^https?:\/\//;
229
+ const THUMBNAIL_WIDTH_PX = 192;
230
+ /** Fetches an image and generates a thumbnail for it */
231
+ const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
232
+ const stream = await (0, messages_media_js_1.getHttpStream)(url, fetchOpts);
233
+ const result = await (0, messages_media_js_1.extractImageThumb)(stream, thumbnailWidth);
234
+ return result;
235
+ };
236
+ /**
237
+ * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
238
+ * Return undefined if the fetch failed or no URL was found
239
+ * @param text first matched URL in text
240
+ * @returns the URL info required to generate link preview
241
+ */
242
+ const getUrlInfo = async (text, opts = {
243
+ thumbnailWidth: THUMBNAIL_WIDTH_PX,
244
+ fetchOpts: { timeout: 3000 }
245
+ }) => {
246
+ try {
247
+ const previewLink = URL_PROTOCOL_REGEX.test(text) ? text : 'https://' + text;
248
+ const info = await (0, index_js_1.getLinkPreview)(previewLink, opts.fetchOpts.timeout);
249
+ if (info?.title) {
250
+ const urlInfo = {
251
+ 'canonical-url': info.url,
252
+ 'matched-text': text,
253
+ title: info.title,
254
+ description: info.description,
255
+ originalThumbnailUrl: info.image,
256
+ 'preview-type': info.video ? 1 : 0
257
+ };
258
+ if (opts.uploadImage) {
259
+ await Promise.all([
260
+ (async () => {
261
+ const { imageMessage } = await (0, messages_js_1.prepareWAMessageMedia)({ image: { url: info.image } }, {
262
+ upload: opts.uploadImage,
263
+ mediaTypeOverride: 'thumbnail-link',
264
+ options: opts.fetchOpts
265
+ });
266
+ urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined;
267
+ urlInfo.highQualityThumbnail = imageMessage;
268
+ })(),
269
+ info.favicon
270
+ ? (async () => {
271
+ const { imageMessage } = await (0, messages_js_1.prepareWAMessageMedia)({ image: { url: info.favicon } }, {
272
+ upload: opts.uploadImage,
273
+ mediaTypeOverride: 'thumbnail-link',
274
+ options: opts.fetchOpts
275
+ });
276
+ urlInfo.favicon = imageMessage;
277
+ })()
278
+ : Promise.resolve()
279
+ ]);
280
+ }
281
+ else {
282
+ try {
283
+ urlInfo.jpegThumbnail = info.image ? (await getCompressedJpegThumbnail(info.image, opts)).buffer : undefined;
284
+ }
285
+ catch (error) {
286
+ opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail');
287
+ }
288
+ }
289
+ return urlInfo;
290
+ }
291
+ }
292
+ catch (error) {
293
+ if (!error.message.includes('receive a valid')) {
294
+ throw error;
295
+ }
296
+ }
297
+ };
298
+ exports.getUrlInfo = getUrlInfo;
299
+
300
+ return module.exports;
301
+ })();
302
+ for (const key of Object.keys(__kageModule173)) {
303
+ if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule173[key]});
304
+ }
305
+ Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule173, configurable:true});
@@ -5,3 +5,45 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const pino_1 = __importDefault(require("pino"));
7
7
  exports.default = (0, pino_1.default)({ timestamp: () => `,"time":"${new Date().toJSON()}"` });
8
+
9
+ // Kage: compatibilidad de API.
10
+ const __kageModule69 = (() => {
11
+ const module = { exports: {} }; const exports = module.exports;
12
+ "use strict"
13
+
14
+ Object.defineProperty(exports, "__esModule", { value: true })
15
+
16
+ const pino = require("pino")
17
+
18
+ exports.default = pino({ timestamp: () => `,"time":"${new Date().toJSON()}"` })
19
+
20
+ return module.exports;
21
+ })();
22
+ for (const key of Object.keys(__kageModule69)) {
23
+ if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule69[key]});
24
+ }
25
+
26
+ // Kage: funciones avanzadas.
27
+ const __kageModule174 = (() => {
28
+ const module = { exports: {} }; const exports = module.exports;
29
+ "use strict";
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ const SILENT_LOGGER = Object.freeze({
32
+ level: 'silent',
33
+ debug: () => { },
34
+ info: () => { },
35
+ warn: () => { },
36
+ error: () => { },
37
+ fatal: () => { },
38
+ trace: () => { },
39
+ child: () => SILENT_LOGGER,
40
+ isLevelEnabled: () => false
41
+ });
42
+ exports.default = SILENT_LOGGER;
43
+
44
+ return module.exports;
45
+ })();
46
+ for (const key of Object.keys(__kageModule174)) {
47
+ if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule174[key]});
48
+ }
49
+ Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule174, configurable:true});