@rizzxdc/baileys 8.0.10 → 8.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 (220) hide show
  1. package/LICENSE +4 -2
  2. package/README.md +107 -245
  3. package/WAProto/index.d.ts +15795 -0
  4. package/WAProto/index.js +25587 -4867
  5. package/lib/Defaults/index.d.ts +147 -0
  6. package/lib/Defaults/index.js +134 -104
  7. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  8. package/lib/Signal/Group/ciphertext-message.js +9 -11
  9. package/lib/Signal/Group/group-session-builder.d.ts +8 -0
  10. package/lib/Signal/Group/group-session-builder.js +5 -8
  11. package/lib/Signal/Group/group_cipher.d.ts +11 -0
  12. package/lib/Signal/Group/group_cipher.js +72 -75
  13. package/lib/Signal/Group/index.d.ts +12 -0
  14. package/lib/Signal/Group/index.js +11 -13
  15. package/lib/Signal/Group/keyhelper.d.ts +7 -0
  16. package/lib/Signal/Group/keyhelper.js +11 -14
  17. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  18. package/lib/Signal/Group/sender-chain-key.js +23 -26
  19. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  20. package/lib/Signal/Group/sender-key-distribution-message.js +58 -61
  21. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  22. package/lib/Signal/Group/sender-key-message.js +61 -64
  23. package/lib/Signal/Group/sender-key-name.d.ts +12 -0
  24. package/lib/Signal/Group/sender-key-name.js +39 -44
  25. package/lib/Signal/Group/sender-key-record.d.ts +13 -0
  26. package/lib/Signal/Group/sender-key-record.js +35 -38
  27. package/lib/Signal/Group/sender-key-state.d.ts +17 -0
  28. package/lib/Signal/Group/sender-key-state.js +76 -79
  29. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  30. package/lib/Signal/Group/sender-message-key.js +23 -26
  31. package/lib/Signal/libsignal.d.ts +55 -0
  32. package/lib/Signal/libsignal.js +414 -308
  33. package/lib/Signal/lid-mapping.d.ts +21 -0
  34. package/lib/Signal/lid-mapping.js +270 -149
  35. package/lib/Socket/Client/index.d.ts +3 -0
  36. package/lib/Socket/Client/index.js +2 -4
  37. package/lib/Socket/Client/types.d.ts +6 -0
  38. package/lib/Socket/Client/types.js +8 -11
  39. package/lib/Socket/Client/websocket.d.ts +13 -0
  40. package/lib/Socket/Client/websocket.js +51 -50
  41. package/lib/Socket/business.d.ts +395 -0
  42. package/lib/Socket/business.js +357 -355
  43. package/lib/Socket/chats.d.ts +137 -0
  44. package/lib/Socket/chats.js +1195 -867
  45. package/lib/Socket/communities.d.ts +562 -0
  46. package/lib/Socket/communities.js +416 -398
  47. package/lib/Socket/dugong.js +8 -1
  48. package/lib/Socket/groups.d.ts +286 -0
  49. package/lib/Socket/groups.js +336 -301
  50. package/lib/Socket/index.d.ts +530 -0
  51. package/lib/Socket/index.js +8 -13
  52. package/lib/Socket/messages-recv.d.ts +334 -0
  53. package/lib/Socket/messages-recv.js +1729 -1121
  54. package/lib/Socket/messages-send.d.ts +330 -0
  55. package/lib/Socket/messages-send.js +684 -462
  56. package/lib/Socket/mex.d.ts +2 -0
  57. package/lib/Socket/mex.js +36 -40
  58. package/lib/Socket/newsletter.d.ts +284 -0
  59. package/lib/Socket/newsletter.js +247 -237
  60. package/lib/Socket/socket.d.ts +61 -0
  61. package/lib/Socket/socket.js +968 -790
  62. package/lib/Store/index.d.ts +4 -0
  63. package/lib/Store/index.js +4 -6
  64. package/lib/Store/make-cache-manager-store.js +2 -2
  65. package/lib/Store/make-in-memory-store.d.ts +63 -0
  66. package/lib/Store/make-in-memory-store.js +414 -284
  67. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  68. package/lib/Store/make-ordered-dictionary.js +75 -76
  69. package/lib/Store/object-repository.d.ts +11 -0
  70. package/lib/Store/object-repository.js +21 -23
  71. package/lib/Types/Auth.d.ts +2 -0
  72. package/lib/Types/Auth.js +0 -2
  73. package/lib/Types/Bussines.d.ts +2 -0
  74. package/lib/Types/Bussines.js +0 -2
  75. package/lib/Types/Call.d.ts +2 -0
  76. package/lib/Types/Call.js +0 -2
  77. package/lib/Types/Chat.d.ts +2 -0
  78. package/lib/Types/Chat.js +5 -7
  79. package/lib/Types/Contact.d.ts +2 -0
  80. package/lib/Types/Contact.js +0 -2
  81. package/lib/Types/Events.d.ts +2 -0
  82. package/lib/Types/Events.js +1 -3
  83. package/lib/Types/GroupMetadata.d.ts +2 -0
  84. package/lib/Types/GroupMetadata.js +0 -2
  85. package/lib/Types/Label.d.ts +3 -0
  86. package/lib/Types/Label.js +21 -22
  87. package/lib/Types/LabelAssociation.d.ts +3 -0
  88. package/lib/Types/LabelAssociation.js +3 -4
  89. package/lib/Types/Message.d.ts +12 -0
  90. package/lib/Types/Message.js +11 -6
  91. package/lib/Types/Mex.d.ts +3 -0
  92. package/lib/Types/Mex.js +38 -0
  93. package/lib/Types/Product.d.ts +2 -0
  94. package/lib/Types/Product.js +0 -2
  95. package/lib/Types/RichType.d.ts +3 -0
  96. package/lib/Types/RichType.js +22 -0
  97. package/lib/Types/Signal.d.ts +2 -0
  98. package/lib/Types/Signal.js +1 -3
  99. package/lib/Types/Socket.d.ts +2 -0
  100. package/lib/Types/Socket.js +1 -4
  101. package/lib/Types/State.d.ts +6 -0
  102. package/lib/Types/State.js +52 -8
  103. package/lib/Types/USync.d.ts +2 -0
  104. package/lib/Types/USync.js +1 -3
  105. package/lib/Types/index.d.ts +14 -0
  106. package/lib/Types/index.js +22 -25
  107. package/lib/Utils/auth-utils.d.ts +58 -0
  108. package/lib/Utils/auth-utils.js +285 -203
  109. package/lib/Utils/browser-utils.d.ts +9 -0
  110. package/lib/Utils/browser-utils.js +21 -19
  111. package/lib/Utils/business.d.ts +50 -0
  112. package/lib/Utils/business.js +206 -209
  113. package/lib/Utils/chat-utils.d.ts +409 -0
  114. package/lib/Utils/chat-utils.js +825 -706
  115. package/lib/Utils/companion-reg-client-utils.d.ts +5 -0
  116. package/lib/Utils/companion-reg-client-utils.js +39 -0
  117. package/lib/Utils/crypto.d.ts +40 -0
  118. package/lib/Utils/crypto.js +88 -101
  119. package/lib/Utils/decode-wa-message.d.ts +84 -0
  120. package/lib/Utils/decode-wa-message.js +287 -238
  121. package/lib/Utils/event-buffer.d.ts +13 -0
  122. package/lib/Utils/event-buffer.js +602 -509
  123. package/lib/Utils/generics.d.ts +64 -0
  124. package/lib/Utils/generics.js +334 -295
  125. package/lib/Utils/history.d.ts +76 -0
  126. package/lib/Utils/history.js +125 -79
  127. package/lib/Utils/identity-change-handler.d.ts +14 -0
  128. package/lib/Utils/identity-change-handler.js +49 -0
  129. package/lib/Utils/index.d.ts +25 -0
  130. package/lib/Utils/index.js +25 -21
  131. package/lib/Utils/link-preview.d.ts +13 -0
  132. package/lib/Utils/link-preview.js +73 -70
  133. package/lib/Utils/logger.d.ts +3 -0
  134. package/lib/Utils/logger.js +1 -4
  135. package/lib/Utils/lt-hash.d.ts +7 -0
  136. package/lib/Utils/lt-hash.js +7 -45
  137. package/lib/Utils/make-mutex.d.ts +7 -0
  138. package/lib/Utils/make-mutex.js +27 -31
  139. package/lib/Utils/message-retry-manager.d.ts +80 -0
  140. package/lib/Utils/message-retry-manager.js +165 -14
  141. package/lib/Utils/messages-media.d.ts +137 -0
  142. package/lib/Utils/messages-media.js +768 -572
  143. package/lib/Utils/messages.d.ts +46 -0
  144. package/lib/Utils/messages.js +1082 -130
  145. package/lib/Utils/noise-handler.d.ts +21 -0
  146. package/lib/Utils/noise-handler.js +191 -135
  147. package/lib/Utils/offline-node-processor.d.ts +10 -0
  148. package/lib/Utils/offline-node-processor.js +39 -0
  149. package/lib/Utils/pre-key-manager.d.ts +26 -0
  150. package/lib/Utils/pre-key-manager.js +96 -76
  151. package/lib/Utils/process-message.d.ts +84 -0
  152. package/lib/Utils/process-message.js +718 -311
  153. package/lib/Utils/reporting-utils.d.ts +13 -0
  154. package/lib/Utils/reporting-utils.js +257 -0
  155. package/lib/Utils/rich-message-utils.d.ts +49 -0
  156. package/lib/Utils/rich-message-utils.js +257 -0
  157. package/lib/Utils/signal.d.ts +83 -0
  158. package/lib/Utils/signal.js +174 -135
  159. package/lib/Utils/stanza-ack.d.ts +17 -0
  160. package/lib/Utils/stanza-ack.js +37 -0
  161. package/lib/Utils/sync-action-utils.d.ts +3 -0
  162. package/lib/Utils/sync-action-utils.js +48 -0
  163. package/lib/Utils/tc-token-utils.d.ts +30 -0
  164. package/lib/Utils/tc-token-utils.js +162 -0
  165. package/lib/Utils/use-multi-file-auth-state.d.ts +11 -0
  166. package/lib/Utils/use-multi-file-auth-state.js +104 -95
  167. package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
  168. package/lib/Utils/use-single-file-auth-state.js +108 -0
  169. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  170. package/lib/Utils/use-sqlite-auth-state.js +108 -0
  171. package/lib/Utils/validate-connection.d.ts +44 -0
  172. package/lib/Utils/validate-connection.js +182 -180
  173. package/lib/WABinary/constants.d.ts +62 -0
  174. package/lib/WABinary/constants.js +1455 -1292
  175. package/lib/WABinary/decode.d.ts +10 -0
  176. package/lib/WABinary/decode.js +249 -228
  177. package/lib/WABinary/encode.d.ts +3 -0
  178. package/lib/WABinary/encode.js +207 -206
  179. package/lib/WABinary/generic-utils.d.ts +77 -0
  180. package/lib/WABinary/generic-utils.js +135 -99
  181. package/lib/WABinary/index.d.ts +6 -0
  182. package/lib/WABinary/index.js +5 -7
  183. package/lib/WABinary/jid-utils.d.ts +29 -0
  184. package/lib/WABinary/jid-utils.js +80 -78
  185. package/lib/WABinary/types.d.ts +2 -0
  186. package/lib/WABinary/types.js +1 -3
  187. package/lib/WAM/BinaryInfo.d.ts +8 -0
  188. package/lib/WAM/BinaryInfo.js +7 -9
  189. package/lib/WAM/constants.d.ts +34927 -0
  190. package/lib/WAM/constants.js +22847 -22848
  191. package/lib/WAM/encode.d.ts +2 -0
  192. package/lib/WAM/encode.js +129 -134
  193. package/lib/WAM/index.d.ts +4 -0
  194. package/lib/WAM/index.js +3 -5
  195. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +37 -0
  196. package/lib/WAUSync/Protocols/USyncContactProtocol.js +48 -27
  197. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  198. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -48
  199. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  200. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -26
  201. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  202. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -35
  203. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  204. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  205. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
  206. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +46 -49
  207. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +15 -0
  208. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +23 -25
  209. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  210. package/lib/WAUSync/Protocols/index.js +5 -6
  211. package/lib/WAUSync/USyncQuery.d.ts +21 -0
  212. package/lib/WAUSync/USyncQuery.js +92 -85
  213. package/lib/WAUSync/USyncUser.d.ts +17 -0
  214. package/lib/WAUSync/USyncUser.js +28 -22
  215. package/lib/WAUSync/index.d.ts +4 -0
  216. package/lib/WAUSync/index.js +3 -5
  217. package/lib/index.d.ts +12 -0
  218. package/lib/index.js +31 -19
  219. package/package.json +12 -6
  220. package/lib/Types/Newsletter.js +0 -33
@@ -0,0 +1,76 @@
1
+ export function downloadHistory(msg: any, options: any): Promise<proto.HistorySync>;
2
+ export function processHistoryMessage(item: any, logger: any): {
3
+ chats: any[];
4
+ contacts: ({
5
+ id: any;
6
+ name: any;
7
+ username: any;
8
+ lid: any;
9
+ phoneNumber: any;
10
+ verifiedName?: undefined;
11
+ notify?: undefined;
12
+ } | {
13
+ id: any;
14
+ verifiedName: any;
15
+ name?: undefined;
16
+ username?: undefined;
17
+ lid?: undefined;
18
+ phoneNumber?: undefined;
19
+ notify?: undefined;
20
+ } | {
21
+ id: any;
22
+ notify: any;
23
+ name?: undefined;
24
+ username?: undefined;
25
+ lid?: undefined;
26
+ phoneNumber?: undefined;
27
+ verifiedName?: undefined;
28
+ })[];
29
+ messages: any[];
30
+ lidPnMappings: {
31
+ lid: any;
32
+ pn: any;
33
+ }[];
34
+ pastParticipants: any;
35
+ syncType: any;
36
+ progress: any;
37
+ };
38
+ export function downloadAndProcessHistorySyncNotification(msg: any, options: any, logger: any): Promise<{
39
+ chats: any[];
40
+ contacts: ({
41
+ id: any;
42
+ name: any;
43
+ username: any;
44
+ lid: any;
45
+ phoneNumber: any;
46
+ verifiedName?: undefined;
47
+ notify?: undefined;
48
+ } | {
49
+ id: any;
50
+ verifiedName: any;
51
+ name?: undefined;
52
+ username?: undefined;
53
+ lid?: undefined;
54
+ phoneNumber?: undefined;
55
+ notify?: undefined;
56
+ } | {
57
+ id: any;
58
+ notify: any;
59
+ name?: undefined;
60
+ username?: undefined;
61
+ lid?: undefined;
62
+ phoneNumber?: undefined;
63
+ verifiedName?: undefined;
64
+ })[];
65
+ messages: any[];
66
+ lidPnMappings: {
67
+ lid: any;
68
+ pn: any;
69
+ }[];
70
+ pastParticipants: any;
71
+ syncType: any;
72
+ progress: any;
73
+ }>;
74
+ export function getHistoryMsg(message: any): any;
75
+ import { proto } from '../../WAProto/index.js';
76
+ //# sourceMappingURL=history.d.ts.map
@@ -1,87 +1,133 @@
1
- //=======================================================//
2
- import { downloadContentFromMessage } from "./messages-media.js";
3
- import { normalizeMessageContent } from "./messages.js";
4
- import { WAMessageStubType } from "../Types/index.js";
5
- import { proto } from "../../WAProto/index.js";
6
- import { toNumber } from "./generics.js";
7
- import { promisify } from "util";
8
- import { inflate } from "zlib";
9
- //=======================================================//
1
+ import { pipeline } from 'stream/promises';
2
+ import { promisify } from 'util';
3
+ import { createInflate, inflate } from 'zlib';
4
+ import { proto } from '../../WAProto/index.js';
5
+ import { WAMessageStubType } from '../Types/index.js';
6
+ import { isHostedLidUser, isHostedPnUser, isLidUser, isPnUser } from '../WABinary/index.js';
7
+ import { toNumber } from './generics.js';
8
+ import { normalizeMessageContent } from './messages.js';
9
+ import { downloadContentFromMessage } from './messages-media.js';
10
10
  const inflatePromise = promisify(inflate);
11
+ const extractPnFromMessages = (messages) => {
12
+ for (const msgItem of messages) {
13
+ const message = msgItem.message;
14
+ // Only extract from outgoing messages (fromMe: true) in 1:1 chats
15
+ // because userReceipt.userJid is the recipient's JID
16
+ if (!message?.key?.fromMe || !message.userReceipt?.length) {
17
+ continue;
18
+ }
19
+ const userJid = message.userReceipt[0]?.userJid;
20
+ if (userJid && (isPnUser(userJid) || isHostedPnUser(userJid))) {
21
+ return userJid;
22
+ }
23
+ }
24
+ return undefined;
25
+ };
11
26
  export const downloadHistory = async (msg, options) => {
12
- const stream = await downloadContentFromMessage(msg, "md-msg-hist", { options });
13
- const bufferArray = [];
14
- for await (const chunk of stream) {
15
- bufferArray.push(chunk);
16
- }
17
- let buffer = Buffer.concat(bufferArray);
18
- buffer = await inflatePromise(buffer);
19
- const syncData = proto.HistorySync.decode(buffer);
20
- return syncData;
27
+ const stream = await downloadContentFromMessage(msg, 'md-msg-hist', { options });
28
+ // Pipe decrypted stream directly through zlib inflate
29
+ // This avoids allocating an intermediate buffer for the compressed data
30
+ const inflater = createInflate();
31
+ const chunks = [];
32
+ inflater.on('data', (chunk) => chunks.push(chunk));
33
+ await pipeline(stream, inflater);
34
+ const buffer = Buffer.concat(chunks);
35
+ const syncData = proto.HistorySync.decode(buffer);
36
+ return syncData;
21
37
  };
22
- //=======================================================//
23
- export const processHistoryMessage = (item) => {
24
- const messages = [];
25
- const contacts = [];
26
- const chats = [];
27
- switch (item.syncType) {
28
- case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
29
- case proto.HistorySync.HistorySyncType.RECENT:
30
- case proto.HistorySync.HistorySyncType.FULL:
31
- case proto.HistorySync.HistorySyncType.ON_DEMAND:
32
- for (const chat of item.conversations) {
33
- contacts.push({
34
- id: chat.id,
35
- name: chat.name || undefined,
36
- lid: chat.lidJid || undefined,
37
- phoneNumber: chat.pnJid || undefined
38
- });
39
- const msgs = chat.messages || [];
40
- delete chat.messages;
41
- for (const item of msgs) {
42
- const message = item.message;
43
- messages.push(message);
44
- if (!chat.messages?.length) {
45
- chat.messages = [{ message }];
46
- }
47
- if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
48
- chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp);
49
- }
50
- if ((message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
51
- message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) &&
52
- message.messageStubParameters?.[0]) {
53
- contacts.push({
54
- id: message.key.participant || message.key.remoteJid,
55
- verifiedName: message.messageStubParameters?.[0]
56
- });
57
- }
38
+ export const processHistoryMessage = (item, logger) => {
39
+ const messages = [];
40
+ const contacts = [];
41
+ const chats = [];
42
+ const lidPnMappings = [];
43
+ logger?.trace({ progress: item.progress }, 'processing history of type ' + item.syncType?.toString());
44
+ // Extract LID-PN mappings for all sync types
45
+ for (const m of item.phoneNumberToLidMappings || []) {
46
+ if (m.lidJid && m.pnJid) {
47
+ lidPnMappings.push({ lid: m.lidJid, pn: m.pnJid });
58
48
  }
59
- chats.push({ ...chat });
60
- }
61
- break;
62
- case proto.HistorySync.HistorySyncType.PUSH_NAME:
63
- for (const c of item.pushnames) {
64
- contacts.push({ id: c.id, notify: c.pushname });
65
- }
66
- break;
67
- }
68
- return {
69
- chats,
70
- contacts,
71
- messages,
72
- syncType: item.syncType,
73
- progress: item.progress
74
- };
49
+ }
50
+ switch (item.syncType) {
51
+ case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
52
+ case proto.HistorySync.HistorySyncType.RECENT:
53
+ case proto.HistorySync.HistorySyncType.FULL:
54
+ case proto.HistorySync.HistorySyncType.ON_DEMAND:
55
+ for (const chat of item.conversations) {
56
+ contacts.push({
57
+ id: chat.id,
58
+ name: chat.displayName || chat.name || chat.username || undefined,
59
+ username: chat.username || undefined,
60
+ lid: chat.lidJid || chat.accountLid || undefined,
61
+ phoneNumber: chat.pnJid || undefined
62
+ });
63
+ const chatId = chat.id;
64
+ const isLid = isLidUser(chatId) || isHostedLidUser(chatId);
65
+ const isPn = isPnUser(chatId) || isHostedPnUser(chatId);
66
+ if (isLid && chat.pnJid) {
67
+ lidPnMappings.push({ lid: chatId, pn: chat.pnJid });
68
+ }
69
+ else if (isPn && chat.lidJid) {
70
+ lidPnMappings.push({ lid: chat.lidJid, pn: chatId });
71
+ }
72
+ else if (isLid && !chat.pnJid) {
73
+ // Fallback: extract PN from userReceipt in messages when pnJid is missing
74
+ const pnFromReceipt = extractPnFromMessages(chat.messages || []);
75
+ if (pnFromReceipt) {
76
+ lidPnMappings.push({ lid: chatId, pn: pnFromReceipt });
77
+ }
78
+ }
79
+ const msgs = chat.messages || [];
80
+ delete chat.messages;
81
+ for (const item of msgs) {
82
+ const message = item.message;
83
+ messages.push(message);
84
+ if (!chat.messages?.length) {
85
+ // keep only the most recent message in the chat array
86
+ chat.messages = [{ message }];
87
+ }
88
+ if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
89
+ chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp);
90
+ }
91
+ if ((message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
92
+ message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) &&
93
+ message.messageStubParameters?.[0]) {
94
+ contacts.push({
95
+ id: message.key.participant || message.key.remoteJid,
96
+ verifiedName: message.messageStubParameters?.[0]
97
+ });
98
+ }
99
+ }
100
+ chats.push(chat);
101
+ }
102
+ break;
103
+ case proto.HistorySync.HistorySyncType.PUSH_NAME:
104
+ for (const c of item.pushnames) {
105
+ contacts.push({ id: c.id, notify: c.pushname });
106
+ }
107
+ break;
108
+ }
109
+ return {
110
+ chats,
111
+ contacts,
112
+ messages,
113
+ lidPnMappings,
114
+ pastParticipants: item.pastParticipants,
115
+ syncType: item.syncType,
116
+ progress: item.progress
117
+ };
75
118
  };
76
- //=======================================================//
77
- export const downloadAndProcessHistorySyncNotification = async (msg, options) => {
78
- const historyMsg = await downloadHistory(msg, options);
79
- return processHistoryMessage(historyMsg);
119
+ export const downloadAndProcessHistorySyncNotification = async (msg, options, logger) => {
120
+ let historyMsg;
121
+ if (msg.initialHistBootstrapInlinePayload) {
122
+ historyMsg = proto.HistorySync.decode(await inflatePromise(msg.initialHistBootstrapInlinePayload));
123
+ }
124
+ else {
125
+ historyMsg = await downloadHistory(msg, options);
126
+ }
127
+ return processHistoryMessage(historyMsg, logger);
80
128
  };
81
- //=======================================================//
82
129
  export const getHistoryMsg = (message) => {
83
- const normalizedContent = !!message ? normalizeMessageContent(message) : undefined;
84
- const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification;
85
- return anyHistoryMsg;
130
+ const normalizedContent = !!message ? normalizeMessageContent(message) : undefined;
131
+ const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification;
132
+ return anyHistoryMsg;
86
133
  };
87
- //=======================================================//
@@ -0,0 +1,14 @@
1
+ export function handleIdentityChange(node: any, ctx: any): Promise<{
2
+ action: string;
3
+ device?: undefined;
4
+ error?: undefined;
5
+ } | {
6
+ action: string;
7
+ device: number;
8
+ error?: undefined;
9
+ } | {
10
+ action: string;
11
+ error: unknown;
12
+ device?: undefined;
13
+ }>;
14
+ //# sourceMappingURL=identity-change-handler.d.ts.map
@@ -0,0 +1,49 @@
1
+ import NodeCache from '@cacheable/node-cache';
2
+ import { areJidsSameUser, getBinaryNodeChild, jidDecode } from '../WABinary/index.js';
3
+ import { isStringNullOrEmpty } from './generics.js';
4
+ export async function handleIdentityChange(node, ctx) {
5
+ const from = node.attrs.from;
6
+ if (!from) {
7
+ return { action: 'invalid_notification' };
8
+ }
9
+ const identityNode = getBinaryNodeChild(node, 'identity');
10
+ if (!identityNode) {
11
+ return { action: 'no_identity_node' };
12
+ }
13
+ ctx.logger.info({ jid: from }, 'identity changed');
14
+ const decoded = jidDecode(from);
15
+ if (decoded?.device && decoded.device !== 0) {
16
+ ctx.logger.debug({ jid: from, device: decoded.device }, 'ignoring identity change from companion device');
17
+ return { action: 'skipped_companion_device', device: decoded.device };
18
+ }
19
+ const isSelfPrimary = ctx.meId && (areJidsSameUser(from, ctx.meId) || (ctx.meLid && areJidsSameUser(from, ctx.meLid)));
20
+ if (isSelfPrimary) {
21
+ ctx.logger.info({ jid: from }, 'self primary identity changed');
22
+ return { action: 'skipped_self_primary' };
23
+ }
24
+ if (ctx.debounceCache.get(from)) {
25
+ ctx.logger.debug({ jid: from }, 'skipping identity assert (debounced)');
26
+ return { action: 'debounced' };
27
+ }
28
+ ctx.debounceCache.set(from, true);
29
+ const isOfflineNotification = !isStringNullOrEmpty(node.attrs.offline);
30
+ const hasExistingSession = await ctx.validateSession(from);
31
+ if (!hasExistingSession.exists) {
32
+ ctx.logger.debug({ jid: from }, 'no old session, skipping session refresh');
33
+ return { action: 'skipped_no_session' };
34
+ }
35
+ ctx.logger.debug({ jid: from }, 'old session exists, will refresh session');
36
+ if (isOfflineNotification) {
37
+ ctx.logger.debug({ jid: from }, 'skipping session refresh during offline processing');
38
+ return { action: 'skipped_offline' };
39
+ }
40
+ ctx.onBeforeSessionRefresh?.(from);
41
+ try {
42
+ await ctx.assertSessions([from], true);
43
+ return { action: 'session_refreshed' };
44
+ }
45
+ catch (error) {
46
+ ctx.logger.warn({ error, jid: from }, 'failed to assert sessions after identity change');
47
+ return { action: 'session_refresh_failed', error };
48
+ }
49
+ }
@@ -0,0 +1,25 @@
1
+ export * from "./generics.js";
2
+ export * from "./decode-wa-message.js";
3
+ export * from "./messages.js";
4
+ export * from "./messages-media.js";
5
+ export * from "./validate-connection.js";
6
+ export * from "./crypto.js";
7
+ export * from "./signal.js";
8
+ export * from "./noise-handler.js";
9
+ export * from "./history.js";
10
+ export * from "./chat-utils.js";
11
+ export * from "./lt-hash.js";
12
+ export * from "./auth-utils.js";
13
+ export * from "./use-multi-file-auth-state.js";
14
+ export * from "./use-single-file-auth-state.js";
15
+ export * from "./use-sqlite-auth-state.js";
16
+ export * from "./link-preview.js";
17
+ export * from "./event-buffer.js";
18
+ export * from "./process-message.js";
19
+ export * from "./rich-message-utils.js";
20
+ export * from "./message-retry-manager.js";
21
+ export * from "./browser-utils.js";
22
+ export * from "./companion-reg-client-utils.js";
23
+ export * from "./identity-change-handler.js";
24
+ export * from "./stanza-ack.js";
25
+ //# sourceMappingURL=index.d.ts.map
@@ -1,21 +1,25 @@
1
- //=======================================================//
2
- export * from "./use-multi-file-auth-state.js";
3
- export * from "./message-retry-manager.js";
4
- export * from "./baileys-event-stream.js";
5
- export * from "./validate-connection.js";
6
- export * from "./decode-wa-message.js";
7
- export * from "./process-message.js";
8
- export * from "./messages-media.js";
9
- export * from "./noise-handler.js";
10
- export * from "./browser-utils.js";
11
- export * from "./link-preview.js";
12
- export * from "./event-buffer.js";
13
- export * from "./auth-utils.js";
14
- export * from "./chat-utils.js";
15
- export * from "./generics.js";
16
- export * from "./messages.js";
17
- export * from "./history.js";
18
- export * from "./lt-hash.js";
19
- export * from "./crypto.js";
20
- export * from "./signal.js";
21
- //=======================================================//
1
+ export * from './generics.js';
2
+ export * from './decode-wa-message.js';
3
+ export * from './messages.js';
4
+ export * from './messages-media.js';
5
+ export * from './validate-connection.js';
6
+ export * from './crypto.js';
7
+ export * from './signal.js';
8
+ export * from './noise-handler.js';
9
+ export * from './history.js';
10
+ export * from './chat-utils.js';
11
+ export * from './lt-hash.js';
12
+ export * from './auth-utils.js';
13
+ export * from './use-multi-file-auth-state.js';
14
+ export * from './use-single-file-auth-state.js';
15
+ export * from './use-sqlite-auth-state.js';
16
+ export * from './link-preview.js';
17
+ export * from './event-buffer.js';
18
+ export * from './process-message.js';
19
+ export * from './rich-message-utils.js';
20
+ export * from './message-retry-manager.js';
21
+ export * from './browser-utils.js';
22
+ export * from './companion-reg-client-utils.js';
23
+ export * from './identity-change-handler.js';
24
+ export * from './stanza-ack.js';
25
+ export * from './baileys-event-stream.js';
@@ -0,0 +1,13 @@
1
+ export function getUrlInfo(text: any, opts?: {
2
+ thumbnailWidth: number;
3
+ fetchOpts: {
4
+ timeout: number;
5
+ };
6
+ }): Promise<{
7
+ 'canonical-url': any;
8
+ 'matched-text': any;
9
+ title: any;
10
+ description: any;
11
+ originalThumbnailUrl: any;
12
+ } | undefined>;
13
+ //# sourceMappingURL=link-preview.d.ts.map
@@ -1,81 +1,84 @@
1
- //=======================================================//
2
- import { extractImageThumb, getHttpStream } from "./messages-media.js";
3
- import { prepareWAMessageMedia } from "./messages.js";
4
- //=======================================================//
1
+ import { prepareWAMessageMedia } from './messages.js';
2
+ import { extractImageThumb, getHttpStream } from './messages-media.js';
5
3
  const THUMBNAIL_WIDTH_PX = 192;
6
- //=======================================================//
4
+ /** Fetches an image and generates a thumbnail for it */
7
5
  const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
8
- const stream = await getHttpStream(url, fetchOpts);
9
- const result = await extractImageThumb(stream, thumbnailWidth);
10
- return result;
6
+ const stream = await getHttpStream(url, fetchOpts);
7
+ const result = await extractImageThumb(stream, thumbnailWidth);
8
+ return result;
11
9
  };
12
- //=======================================================//
10
+ /**
11
+ * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
12
+ * Return undefined if the fetch failed or no URL was found
13
+ * @param text first matched URL in text
14
+ * @returns the URL info required to generate link preview
15
+ */
13
16
  export const getUrlInfo = async (text, opts = {
14
- thumbnailWidth: THUMBNAIL_WIDTH_PX,
15
- fetchOpts: { timeout: 3000 }
17
+ thumbnailWidth: THUMBNAIL_WIDTH_PX,
18
+ fetchOpts: { timeout: 3000 }
16
19
  }) => {
17
- try {
18
- const retries = 0;
19
- const maxRetry = 5;
20
- const { getLinkPreview } = await import("link-preview-js");
21
- let previewLink = text;
22
- if (!text.startsWith("https://") && !text.startsWith("http://")) {
23
- previewLink = "https://" + previewLink;
24
- }
25
- const info = await getLinkPreview(previewLink, {
26
- ...opts.fetchOpts,
27
- followRedirects: "follow",
28
- handleRedirects: (baseURL, forwardedURL) => {
29
- const urlObj = new URL(baseURL);
30
- const forwardedURLObj = new URL(forwardedURL);
31
- if (retries >= maxRetry) {
32
- return false;
33
- }
34
- if (forwardedURLObj.hostname === urlObj.hostname ||
35
- forwardedURLObj.hostname === "www." + urlObj.hostname ||
36
- "www." + forwardedURLObj.hostname === urlObj.hostname) {
37
- retries + 1;
38
- return true;
39
- }
40
- else {
41
- return false;
20
+ try {
21
+ // retries
22
+ let retries = 0;
23
+ const maxRetry = 5;
24
+ const { getLinkPreview } = await import('link-preview-js');
25
+ let previewLink = text;
26
+ if (!text.startsWith('https://') && !text.startsWith('http://')) {
27
+ previewLink = 'https://' + previewLink;
42
28
  }
43
- },
44
- headers: opts.fetchOpts?.headers
45
- });
46
- if (info && "title" in info && info.title) {
47
- const [image] = info.images;
48
- const urlInfo = {
49
- "canonical-url": info.url,
50
- "matched-text": text,
51
- title: info.title,
52
- description: info.description,
53
- originalThumbnailUrl: image
54
- };
55
- if (opts.uploadImage) {
56
- const { imageMessage } = await prepareWAMessageMedia({ image: { url: image } }, {
57
- upload: opts.uploadImage,
58
- mediaTypeOverride: "thumbnail-link",
59
- options: opts.fetchOpts
29
+ const info = await getLinkPreview(previewLink, {
30
+ ...opts.fetchOpts,
31
+ followRedirects: 'follow',
32
+ handleRedirects: (baseURL, forwardedURL) => {
33
+ const urlObj = new URL(baseURL);
34
+ const forwardedURLObj = new URL(forwardedURL);
35
+ if (retries >= maxRetry) {
36
+ return false;
37
+ }
38
+ if (forwardedURLObj.hostname === urlObj.hostname ||
39
+ forwardedURLObj.hostname === 'www.' + urlObj.hostname ||
40
+ 'www.' + forwardedURLObj.hostname === urlObj.hostname) {
41
+ retries += 1;
42
+ return true;
43
+ }
44
+ else {
45
+ return false;
46
+ }
47
+ },
48
+ headers: opts.fetchOpts?.headers
60
49
  });
61
- urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined;
62
- urlInfo.highQualityThumbnail = imageMessage || undefined;
63
- }
64
- else {
65
- try {
66
- urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined;
50
+ if (info && 'title' in info && info.title) {
51
+ const [image] = info.images;
52
+ const urlInfo = {
53
+ 'canonical-url': info.url,
54
+ 'matched-text': text,
55
+ title: info.title,
56
+ description: info.description,
57
+ originalThumbnailUrl: image
58
+ };
59
+ if (opts.uploadImage) {
60
+ const { imageMessage } = await prepareWAMessageMedia({ image: { url: image } }, {
61
+ upload: opts.uploadImage,
62
+ mediaTypeOverride: 'thumbnail-link',
63
+ options: opts.fetchOpts
64
+ });
65
+ urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined;
66
+ urlInfo.highQualityThumbnail = imageMessage || undefined;
67
+ }
68
+ else {
69
+ try {
70
+ urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined;
71
+ }
72
+ catch (error) {
73
+ opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail');
74
+ }
75
+ }
76
+ return urlInfo;
67
77
  }
68
- catch (error) {
69
- opts.logger?.debug({ err: error.stack, url: previewLink }, "error in generating thumbnail");
70
- }
71
- }
72
- return urlInfo;
73
78
  }
74
- }
75
- catch (error) {
76
- if (!error.message.includes("receive a valid")) {
77
- throw error;
79
+ catch (error) {
80
+ if (!error.message.includes('receive a valid')) {
81
+ throw error;
82
+ }
78
83
  }
79
- }
80
84
  };
81
- //=======================================================//
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+ export default _default;
3
+ //# sourceMappingURL=logger.d.ts.map
@@ -1,5 +1,2 @@
1
- //=======================================================//
2
- import P from "pino";
3
- //=======================================================//
1
+ import P from 'pino';
4
2
  export default P({ timestamp: () => `,"time":"${new Date().toJSON()}"` });
5
- //=======================================================//
@@ -0,0 +1,7 @@
1
+ /**
2
+ * LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
3
+ * over a series of mutations. You can add/remove mutations and it'll return a hash equal to
4
+ * if the same series of mutations was made sequentially.
5
+ */
6
+ export const LT_HASH_ANTI_TAMPERING: any;
7
+ //# sourceMappingURL=lt-hash.d.ts.map