@pontalabs/baileys 1.0.6 → 1.0.8

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 (185) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +839 -267
  3. package/WAProto/GenerateStatics.sh +4 -3
  4. package/WAProto/WAProto.proto +511 -1215
  5. package/WAProto/index.d.ts +55 -14017
  6. package/WAProto/index.js +29 -97689
  7. package/lib/Defaults/index.d.ts +74 -72
  8. package/lib/Defaults/index.js +108 -94
  9. package/lib/Signal/Group/ciphertext-message.d.ts +7 -8
  10. package/lib/Signal/Group/ciphertext-message.js +16 -9
  11. package/lib/Signal/Group/group-session-builder.d.ts +13 -11
  12. package/lib/Signal/Group/group-session-builder.js +61 -19
  13. package/lib/Signal/Group/group_cipher.d.ts +16 -14
  14. package/lib/Signal/Group/group_cipher.js +70 -41
  15. package/lib/Signal/Group/index.d.ts +11 -12
  16. package/lib/Signal/Group/index.js +61 -12
  17. package/lib/Signal/Group/keyhelper.d.ts +14 -9
  18. package/lib/Signal/Group/keyhelper.js +58 -10
  19. package/lib/Signal/Group/sender-chain-key.d.ts +13 -13
  20. package/lib/Signal/Group/sender-chain-key.js +34 -13
  21. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -16
  22. package/lib/Signal/Group/sender-key-distribution-message.js +36 -28
  23. package/lib/Signal/Group/sender-key-message.d.ts +18 -18
  24. package/lib/Signal/Group/sender-key-message.js +45 -38
  25. package/lib/Signal/Group/sender-key-name.d.ts +15 -14
  26. package/lib/Signal/Group/sender-key-name.js +31 -20
  27. package/lib/Signal/Group/sender-key-record.d.ts +25 -24
  28. package/lib/Signal/Group/sender-key-record.js +35 -18
  29. package/lib/Signal/Group/sender-key-state.d.ts +34 -29
  30. package/lib/Signal/Group/sender-key-state.js +100 -37
  31. package/lib/Signal/Group/sender-message-key.d.ts +10 -11
  32. package/lib/Signal/Group/sender-message-key.js +22 -15
  33. package/lib/Signal/libsignal.d.ts +8 -5
  34. package/lib/Signal/libsignal.js +142 -288
  35. package/lib/Signal/lid-mapping.d.ts +28 -23
  36. package/lib/Signal/lid-mapping.js +184 -277
  37. package/lib/Socket/Client/index.d.ts +2 -3
  38. package/lib/Socket/Client/index.js +22 -3
  39. package/lib/Socket/Client/types.d.ts +15 -15
  40. package/lib/Socket/Client/types.js +15 -8
  41. package/lib/Socket/Client/websocket.d.ts +12 -12
  42. package/lib/Socket/Client/websocket.js +37 -29
  43. package/lib/Socket/business.d.ts +178 -208
  44. package/lib/Socket/business.js +127 -91
  45. package/lib/Socket/chats.d.ts +93 -120
  46. package/lib/Socket/chats.js +652 -727
  47. package/lib/Socket/community.js +10 -2
  48. package/lib/Socket/groups.d.ts +111 -143
  49. package/lib/Socket/groups.js +186 -165
  50. package/lib/Socket/index.d.ts +183 -252
  51. package/lib/Socket/index.js +18 -38
  52. package/lib/Socket/messages-recv.d.ts +167 -196
  53. package/lib/Socket/messages-recv.js +1567 -1443
  54. package/lib/Socket/messages-send.d.ts +158 -192
  55. package/lib/Socket/messages-send.js +1208 -1102
  56. package/lib/Socket/newsletter.d.ts +138 -163
  57. package/lib/Socket/newsletter.js +249 -153
  58. package/lib/Socket/socket.d.ts +36 -50
  59. package/lib/Socket/socket.js +820 -749
  60. package/lib/Store/index.d.ts +4 -4
  61. package/lib/Store/index.js +24 -4
  62. package/lib/Store/make-in-memory-store.d.ts +104 -44
  63. package/lib/Store/make-in-memory-store.js +213 -199
  64. package/lib/Store/make-ordered-dictionary.d.ts +12 -13
  65. package/lib/Store/make-ordered-dictionary.js +45 -38
  66. package/lib/Store/object-repository.d.ts +10 -11
  67. package/lib/Store/object-repository.js +16 -9
  68. package/lib/Types/Auth.d.ts +97 -93
  69. package/lib/Types/Auth.js +3 -2
  70. package/lib/Types/Bussines.js +3 -2
  71. package/lib/Types/Call.d.ts +13 -14
  72. package/lib/Types/Call.js +3 -2
  73. package/lib/Types/Chat.d.ts +97 -78
  74. package/lib/Types/Chat.js +9 -8
  75. package/lib/Types/Contact.d.ts +9 -12
  76. package/lib/Types/Contact.js +3 -2
  77. package/lib/Types/Events.d.ts +176 -206
  78. package/lib/Types/Events.js +3 -2
  79. package/lib/Types/GroupMetadata.d.ts +48 -53
  80. package/lib/Types/GroupMetadata.js +3 -2
  81. package/lib/Types/Label.d.ts +14 -13
  82. package/lib/Types/Label.js +30 -24
  83. package/lib/Types/LabelAssociation.d.ts +20 -15
  84. package/lib/Types/LabelAssociation.js +12 -6
  85. package/lib/Types/Message.d.ts +412 -248
  86. package/lib/Types/Message.js +19 -17
  87. package/lib/Types/Product.d.ts +71 -58
  88. package/lib/Types/Product.js +3 -2
  89. package/lib/Types/Signal.d.ts +82 -71
  90. package/lib/Types/Signal.js +3 -2
  91. package/lib/Types/Socket.d.ts +81 -76
  92. package/lib/Types/Socket.js +3 -3
  93. package/lib/Types/State.d.ts +19 -75
  94. package/lib/Types/State.js +14 -56
  95. package/lib/Types/USync.d.ts +8 -8
  96. package/lib/Types/USync.js +3 -2
  97. package/lib/Types/index.d.ts +62 -47
  98. package/lib/Types/index.js +50 -26
  99. package/lib/Utils/auth-utils.d.ts +10 -13
  100. package/lib/Utils/auth-utils.js +472 -213
  101. package/lib/Utils/business.d.ts +20 -14
  102. package/lib/Utils/business.js +134 -110
  103. package/lib/Utils/chat-utils.d.ts +70 -88
  104. package/lib/Utils/chat-utils.js +403 -466
  105. package/lib/Utils/crypto.d.ts +46 -27
  106. package/lib/Utils/crypto.js +188 -117
  107. package/lib/Utils/decode-wa-message.d.ts +45 -58
  108. package/lib/Utils/decode-wa-message.js +311 -212
  109. package/lib/Utils/event-buffer.d.ts +17 -14
  110. package/lib/Utils/event-buffer.js +296 -321
  111. package/lib/Utils/generics.d.ts +92 -66
  112. package/lib/Utils/generics.js +436 -270
  113. package/lib/Utils/history.d.ts +23 -24
  114. package/lib/Utils/history.js +76 -106
  115. package/lib/Utils/index.d.ts +21 -24
  116. package/lib/Utils/index.js +41 -24
  117. package/lib/Utils/link-preview.d.ts +14 -12
  118. package/lib/Utils/link-preview.js +75 -40
  119. package/lib/Utils/logger.d.ts +11 -10
  120. package/lib/Utils/logger.js +7 -3
  121. package/lib/Utils/lt-hash.d.ts +14 -8
  122. package/lib/Utils/lt-hash.js +53 -3
  123. package/lib/Utils/make-mutex.d.ts +7 -7
  124. package/lib/Utils/make-mutex.js +44 -28
  125. package/lib/Utils/message-retry-manager.d.ts +88 -115
  126. package/lib/Utils/message-retry-manager.js +160 -265
  127. package/lib/Utils/messages-media.d.ts +107 -105
  128. package/lib/Utils/messages-media.js +619 -548
  129. package/lib/Utils/messages.d.ts +66 -52
  130. package/lib/Utils/messages.js +1558 -1730
  131. package/lib/Utils/noise-handler.d.ts +18 -18
  132. package/lib/Utils/noise-handler.js +130 -176
  133. package/lib/Utils/process-message.d.ts +32 -43
  134. package/lib/Utils/process-message.js +282 -484
  135. package/lib/Utils/rich-message-utils.js +724 -1220
  136. package/lib/Utils/signal.d.ts +32 -37
  137. package/lib/Utils/signal.js +105 -140
  138. package/lib/Utils/use-multi-file-auth-state.d.ts +5 -5
  139. package/lib/Utils/use-multi-file-auth-state.js +120 -70
  140. package/lib/Utils/use-single-file-auth-state.d.ts +13 -11
  141. package/lib/Utils/use-single-file-auth-state.js +66 -92
  142. package/lib/Utils/validate-connection.d.ts +13 -11
  143. package/lib/Utils/validate-connection.js +113 -128
  144. package/lib/WABinary/constants.d.ts +27 -25
  145. package/lib/WABinary/constants.js +1292 -1451
  146. package/lib/WABinary/decode.d.ts +9 -7
  147. package/lib/WABinary/decode.js +189 -163
  148. package/lib/WABinary/encode.d.ts +3 -3
  149. package/lib/WABinary/encode.js +155 -110
  150. package/lib/WABinary/generic-utils.d.ts +27 -14
  151. package/lib/WABinary/generic-utils.js +105 -177
  152. package/lib/WABinary/index.d.ts +5 -6
  153. package/lib/WABinary/index.js +25 -6
  154. package/lib/WABinary/jid-utils.d.ts +54 -41
  155. package/lib/WABinary/jid-utils.js +152 -83
  156. package/lib/WABinary/types.d.ts +13 -10
  157. package/lib/WABinary/types.js +3 -2
  158. package/lib/WAM/BinaryInfo.d.ts +15 -8
  159. package/lib/WAM/BinaryInfo.js +14 -7
  160. package/lib/WAM/constants.d.ts +37 -30
  161. package/lib/WAM/constants.js +11983 -19465
  162. package/lib/WAM/encode.d.ts +3 -3
  163. package/lib/WAM/encode.js +109 -95
  164. package/lib/WAM/index.d.ts +3 -4
  165. package/lib/WAM/index.js +23 -4
  166. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
  167. package/lib/WAUSync/Protocols/USyncContactProtocol.js +21 -37
  168. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -19
  169. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +26 -18
  170. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -11
  171. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +20 -12
  172. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -11
  173. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +24 -16
  174. package/lib/WAUSync/Protocols/index.d.ts +6 -6
  175. package/lib/WAUSync/Protocols/index.js +26 -6
  176. package/lib/WAUSync/USyncQuery.d.ts +28 -27
  177. package/lib/WAUSync/USyncQuery.js +62 -68
  178. package/lib/WAUSync/USyncUser.d.ts +10 -15
  179. package/lib/WAUSync/USyncUser.js +19 -20
  180. package/lib/WAUSync/index.d.ts +3 -4
  181. package/lib/WAUSync/index.js +23 -4
  182. package/lib/index.d.ts +12 -11
  183. package/lib/index.js +39 -12
  184. package/package.json +43 -87
  185. package/engine-requirements.js +0 -10
@@ -1,24 +1,23 @@
1
- import { proto } from '../../WAProto/index.js';
2
- import type { Chat, Contact, LIDMapping, WAMessage } from '../Types/index.js';
3
- import type { ILogger } from './logger.js';
4
- export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: RequestInit) => Promise<proto.HistorySync>;
5
- export declare const processHistoryMessage: (item: proto.IHistorySync, logger?: ILogger) => {
6
- chats: Chat[];
7
- contacts: Contact[];
8
- messages: WAMessage[];
9
- lidPnMappings: LIDMapping[];
10
- pastParticipants: proto.IPastParticipants[] | null | undefined;
11
- syncType: proto.HistorySync.HistorySyncType | null | undefined;
12
- progress: number | null | undefined;
13
- };
14
- export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: RequestInit, logger?: ILogger) => Promise<{
15
- chats: Chat[];
16
- contacts: Contact[];
17
- messages: WAMessage[];
18
- lidPnMappings: LIDMapping[];
19
- pastParticipants: proto.IPastParticipants[] | null | undefined;
20
- syncType: proto.HistorySync.HistorySyncType | null | undefined;
21
- progress: number | null | undefined;
22
- }>;
23
- export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification;
24
- //# sourceMappingURL=history.d.ts.map
1
+ import { AxiosRequestConfig } from 'axios'
2
+ import { proto } from '../../WAProto'
3
+ import { Chat, Contact } from '../Types'
4
+
5
+ export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<proto.HistorySync>
6
+
7
+ export declare const processHistoryMessage: (item: proto.IHistorySync) => {
8
+ chats: Chat[]
9
+ contacts: Contact[]
10
+ messages: proto.IWebMessageInfo[]
11
+ syncType: proto.HistorySync.HistorySyncType
12
+ progress: number | null | undefined
13
+ }
14
+
15
+ export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<{
16
+ chats: Chat[]
17
+ contacts: Contact[]
18
+ messages: proto.IWebMessageInfo[]
19
+ syncType: proto.HistorySync.HistorySyncType
20
+ progress: number | null | undefined
21
+ }>
22
+
23
+ export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined
@@ -1,134 +1,104 @@
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
- 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
- };
26
- export const downloadHistory = async (msg, options) => {
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;
37
- };
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 });
48
- }
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
4
+
5
+ const util_1 = require("util")
6
+ const zlib_1 = require("zlib")
7
+ const WAProto_1 = require("../../WAProto")
8
+ const Types_1 = require("../Types")
9
+ const WABinary_1 = require("../WABinary")
10
+ const generics_1 = require("./generics")
11
+ const messages_1 = require("./messages")
12
+ const messages_media_1 = require("./messages-media")
13
+ const inflatePromise = util_1.promisify(zlib_1.inflate)
14
+
15
+ const downloadHistory = async (msg, options) => {
16
+ const stream = await messages_media_1.downloadContentFromMessage(msg, 'md-msg-hist', { options })
17
+ const bufferArray = []
18
+ for await (const chunk of stream) {
19
+ bufferArray.push(chunk)
49
20
  }
21
+ let buffer = Buffer.concat(bufferArray)
22
+ // decompress buffer
23
+ buffer = await inflatePromise(buffer)
24
+ const syncData = WAProto_1.proto.HistorySync.decode(buffer)
25
+ return syncData
26
+ }
27
+
28
+ const processHistoryMessage = (item) => {
29
+ const messages = []
30
+ const contacts = []
31
+ const chats = []
50
32
  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:
33
+ case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
34
+ case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
35
+ case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
36
+ case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
55
37
  for (const chat of item.conversations) {
56
38
  contacts.push({
57
39
  id: chat.id,
58
- name: chat.displayName || chat.name || chat.username || undefined,
59
- username: chat.username || undefined,
60
- lid: chat.lidJid || chat.accountLid || undefined,
40
+ name: chat.name || undefined,
41
+ lid: chat.lidJid || undefined,
61
42
  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;
43
+ })
44
+ const msgs = chat.messages || []
45
+ delete chat.messages
81
46
  for (const item of msgs) {
82
- const message = item.message;
83
- messages.push(message);
47
+ const message = item.message
48
+ messages.push(message)
84
49
  if (!chat.messages?.length) {
85
50
  // keep only the most recent message in the chat array
86
- chat.messages = [{ message }];
51
+ chat.messages = [{ message }]
87
52
  }
88
53
  if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
89
- chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp);
54
+ chat.lastMessageRecvTimestamp = generics_1.toNumber(message.messageTimestamp)
90
55
  }
91
- if ((message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
92
- message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) &&
93
- message.messageStubParameters?.[0]) {
56
+ if (message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
57
+ || message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB
58
+ && message.messageStubParameters?.[0]) {
94
59
  contacts.push({
95
60
  id: message.key.participant || message.key.remoteJid,
96
61
  verifiedName: message.messageStubParameters?.[0]
97
- });
62
+ })
98
63
  }
99
64
  }
100
- chats.push(chat);
65
+ chats.push({ ...chat })
101
66
  }
102
- break;
103
- case proto.HistorySync.HistorySyncType.PUSH_NAME:
67
+ break
68
+ case WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
104
69
  for (const c of item.pushnames) {
105
- contacts.push({ id: c.id, notify: c.pushname });
70
+ contacts.push({
71
+ id: c.id,
72
+ name: c.name || undefined,
73
+ lid: c.lidJid || undefined,
74
+ jid: WABinary_1.isJidUser(c.id) ? c.id : undefined
75
+ })
106
76
  }
107
- break;
77
+ break
108
78
  }
109
79
  return {
110
80
  chats,
111
81
  contacts,
112
82
  messages,
113
- lidPnMappings,
114
- pastParticipants: item.pastParticipants,
115
83
  syncType: item.syncType,
116
84
  progress: item.progress
117
- };
118
- };
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
85
  }
127
- return processHistoryMessage(historyMsg, logger);
128
- };
129
- export const getHistoryMsg = (message) => {
130
- const normalizedContent = !!message ? normalizeMessageContent(message) : undefined;
131
- const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification;
132
- return anyHistoryMsg;
133
- };
134
- //# sourceMappingURL=history.js.map
86
+ }
87
+
88
+ const downloadAndProcessHistorySyncNotification = async (msg, options) => {
89
+ const historyMsg = await downloadHistory(msg, options)
90
+ return processHistoryMessage(historyMsg)
91
+ }
92
+
93
+ const getHistoryMsg = (message) => {
94
+ const normalizedContent = !!message ? messages_1.normalizeMessageContent(message) : undefined
95
+ const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification
96
+ return anyHistoryMsg
97
+ }
98
+
99
+ module.exports = {
100
+ downloadHistory,
101
+ processHistoryMessage,
102
+ downloadAndProcessHistorySyncNotification,
103
+ getHistoryMsg
104
+ }
@@ -1,24 +1,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 "./link-preview.js";
16
- export * from "./event-buffer.js";
17
- export * from "./process-message.js";
18
- export * from "./rich-message-utils.js";
19
- export * from "./message-retry-manager.js";
20
- export * from "./browser-utils.js";
21
- export * from "./companion-reg-client-utils.js";
22
- export * from "./identity-change-handler.js";
23
- export * from "./stanza-ack.js";
24
- //# sourceMappingURL=index.d.ts.map
1
+ export * from './generics'
2
+ export * from './decode-wa-message'
3
+ export * from './messages'
4
+ export * from './messages-media'
5
+ export * from './message-retry-manager'
6
+ export * from './validate-connection'
7
+ export * from './crypto'
8
+ export * from './signal'
9
+ export * from './noise-handler'
10
+ export * from './history'
11
+ export * from './chat-utils'
12
+ export * from './lt-hash'
13
+ export * from './auth-utils'
14
+ export * from './baileys-event-stream'
15
+ export * from './use-mongo-file-auth-state'
16
+ export * from './use-single-file-auth-state'
17
+ export * from './use-multi-file-auth-state'
18
+ export * from './link-preview'
19
+ export * from './event-buffer'
20
+ export * from './process-message'
21
+ export * from './signal-housekeeping'
@@ -1,24 +1,41 @@
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 './link-preview.js';
16
- export * from './event-buffer.js';
17
- export * from './process-message.js';
18
- export * from './rich-message-utils.js';
19
- export * from './message-retry-manager.js';
20
- export * from './browser-utils.js';
21
- export * from './companion-reg-client-utils.js';
22
- export * from './identity-change-handler.js';
23
- export * from './stanza-ack.js';
24
- //# sourceMappingURL=index.js.map
1
+ "use strict"
2
+
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k
5
+ var desc = Object.getOwnPropertyDescriptor(m, k)
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k] } }
8
+ }
9
+ Object.defineProperty(o, k2, desc)
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k
12
+ o[k2] = m[k]
13
+ }))
14
+
15
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
17
+ }
18
+
19
+ Object.defineProperty(exports, "__esModule", { value: true })
20
+
21
+ __exportStar(require("./generics"), exports)
22
+ __exportStar(require("./decode-wa-message"), exports)
23
+ __exportStar(require("./messages"), exports)
24
+ __exportStar(require("./messages-media"), exports)
25
+ __exportStar(require("./message-retry-manager"), exports)
26
+ __exportStar(require("./validate-connection"), exports)
27
+ __exportStar(require("./crypto"), exports)
28
+ __exportStar(require("./signal"), exports)
29
+ __exportStar(require("./noise-handler"), exports)
30
+ __exportStar(require("./history"), exports)
31
+ __exportStar(require("./chat-utils"), exports)
32
+ __exportStar(require("./lt-hash"), exports)
33
+ __exportStar(require("./auth-utils"), exports)
34
+ __exportStar(require("./baileys-event-stream"), exports)
35
+ __exportStar(require("./use-mongo-file-auth-state"), exports)
36
+ __exportStar(require("./use-single-file-auth-state"), exports)
37
+ __exportStar(require("./use-multi-file-auth-state"), exports)
38
+ __exportStar(require("./link-preview"), exports)
39
+ __exportStar(require("./event-buffer"), exports)
40
+ __exportStar(require("./process-message"), exports)
41
+ __exportStar(require("./signal-housekeeping"), exports)
@@ -1,21 +1,23 @@
1
- import type { WAMediaUploadFunction, WAUrlInfo } from '../Types/index.js';
2
- import type { ILogger } from './logger.js';
1
+ import { AxiosRequestConfig } from 'axios'
2
+ import { WAMediaUploadFunction, WAUrlInfo } from '../Types'
3
+ import { ILogger } from './logger'
4
+
3
5
  export type URLGenerationOptions = {
4
- thumbnailWidth: number;
6
+ thumbnailWidth: number
5
7
  fetchOpts: {
6
8
  /** Timeout in ms */
7
- timeout: number;
8
- proxyUrl?: string;
9
- headers?: HeadersInit;
10
- };
11
- uploadImage?: WAMediaUploadFunction;
12
- logger?: ILogger;
13
- };
9
+ timeout: number
10
+ proxyUrl?: string
11
+ headers?: AxiosRequestConfig<{}>['headers']
12
+ }
13
+ uploadImage?: WAMediaUploadFunction
14
+ logger?: ILogger
15
+ }
16
+
14
17
  /**
15
18
  * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
16
19
  * Return undefined if the fetch failed or no URL was found
17
20
  * @param text first matched URL in text
18
21
  * @returns the URL info required to generate link preview
19
22
  */
20
- export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined>;
21
- //# sourceMappingURL=link-preview.d.ts.map
23
+ export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined>
@@ -1,85 +1,120 @@
1
- import { prepareWAMessageMedia } from './messages.js';
2
- import { extractImageThumb, getHttpStream } from './messages-media.js';
3
- const THUMBNAIL_WIDTH_PX = 192;
1
+ "use strict"
2
+
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k
5
+ var desc = Object.getOwnPropertyDescriptor(m, k)
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k] } }
8
+ }
9
+ Object.defineProperty(o, k2, desc)
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k
12
+ o[k2] = m[k]
13
+ }))
14
+
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v })
17
+ }) : function(o, v) {
18
+ o["default"] = v
19
+ })
20
+
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod
23
+ var result = {}
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
25
+ __setModuleDefault(result, mod)
26
+ return result
27
+ }
28
+
29
+ Object.defineProperty(exports, "__esModule", { value: true })
30
+
31
+ const messages_1 = require("./messages")
32
+ const messages_media_1 = require("./messages-media")
33
+ const THUMBNAIL_WIDTH_PX = 192
34
+
4
35
  /** Fetches an image and generates a thumbnail for it */
5
36
  const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
6
- const stream = await getHttpStream(url, fetchOpts);
7
- const result = await extractImageThumb(stream, thumbnailWidth);
8
- return result;
9
- };
37
+ const stream = await messages_media_1.getHttpStream(url, fetchOpts)
38
+ const result = await messages_media_1.extractImageThumb(stream, thumbnailWidth)
39
+ return result
40
+ }
41
+
10
42
  /**
11
43
  * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
12
44
  * Return undefined if the fetch failed or no URL was found
13
45
  * @param text first matched URL in text
14
46
  * @returns the URL info required to generate link preview
15
47
  */
16
- export const getUrlInfo = async (text, opts = {
17
- thumbnailWidth: THUMBNAIL_WIDTH_PX,
18
- fetchOpts: { timeout: 3000 }
19
- }) => {
48
+ const getUrlInfo = async (text, opts = { thumbnailWidth: THUMBNAIL_WIDTH_PX, fetchOpts: { timeout: 3000 }}) => {
20
49
  try {
21
- // retries
22
- let retries = 0;
23
- const maxRetry = 5;
24
- const { getLinkPreview } = await import('link-preview-js');
25
- let previewLink = text;
50
+ const retries = 0
51
+ const maxRetry = 5
52
+ const { getLinkPreview } = await Promise.resolve().then(() => __importStar(require('link-preview-js')))
53
+ let previewLink = text
26
54
  if (!text.startsWith('https://') && !text.startsWith('http://')) {
27
- previewLink = 'https://' + previewLink;
55
+ previewLink = 'https://' + previewLink
28
56
  }
29
57
  const info = await getLinkPreview(previewLink, {
30
58
  ...opts.fetchOpts,
31
59
  followRedirects: 'follow',
32
60
  handleRedirects: (baseURL, forwardedURL) => {
33
- const urlObj = new URL(baseURL);
34
- const forwardedURLObj = new URL(forwardedURL);
61
+ const urlObj = new URL(baseURL)
62
+ const forwardedURLObj = new URL(forwardedURL)
35
63
  if (retries >= maxRetry) {
36
- return false;
64
+ return false
37
65
  }
38
- if (forwardedURLObj.hostname === urlObj.hostname ||
39
- forwardedURLObj.hostname === 'www.' + urlObj.hostname ||
40
- 'www.' + forwardedURLObj.hostname === urlObj.hostname) {
41
- retries += 1;
42
- return true;
66
+ if (forwardedURLObj.hostname === urlObj.hostname
67
+ || forwardedURLObj.hostname === 'www.' + urlObj.hostname
68
+ || 'www.' + forwardedURLObj.hostname === urlObj.hostname) {
69
+ retries + 1
70
+ return true
43
71
  }
44
72
  else {
45
- return false;
73
+ return false
46
74
  }
47
75
  },
48
- headers: opts.fetchOpts?.headers
49
- });
76
+ headers: opts.fetchOpts
77
+ })
50
78
  if (info && 'title' in info && info.title) {
51
- const [image] = info.images;
79
+ const [image] = info.images
52
80
  const urlInfo = {
53
81
  'canonical-url': info.url,
54
82
  'matched-text': text,
55
83
  title: info.title,
56
84
  description: info.description,
57
85
  originalThumbnailUrl: image
58
- };
86
+ }
59
87
  if (opts.uploadImage) {
60
- const { imageMessage } = await prepareWAMessageMedia({ image: { url: image } }, {
88
+ const { imageMessage } = await messages_1.prepareWAMessageMedia({ image: { url: image } }, {
61
89
  upload: opts.uploadImage,
62
90
  mediaTypeOverride: 'thumbnail-link',
63
91
  options: opts.fetchOpts
64
- });
65
- urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined;
66
- urlInfo.highQualityThumbnail = imageMessage || undefined;
92
+ })
93
+ urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail
94
+ ? Buffer.from(imageMessage.jpegThumbnail)
95
+ : undefined
96
+ urlInfo.highQualityThumbnail = imageMessage || undefined
67
97
  }
68
98
  else {
69
99
  try {
70
- urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined;
100
+ urlInfo.jpegThumbnail = image
101
+ ? (await getCompressedJpegThumbnail(image, opts)).buffer
102
+ : undefined
71
103
  }
72
104
  catch (error) {
73
- opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail');
105
+ opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail')
74
106
  }
75
107
  }
76
- return urlInfo;
108
+ return urlInfo
77
109
  }
78
110
  }
79
111
  catch (error) {
80
112
  if (!error.message.includes('receive a valid')) {
81
- throw error;
113
+ throw error
82
114
  }
83
115
  }
84
- };
85
- //# sourceMappingURL=link-preview.js.map
116
+ }
117
+
118
+ module.exports = {
119
+ getUrlInfo
120
+ }
@@ -1,12 +1,13 @@
1
1
  export interface ILogger {
2
- level: string;
3
- child(obj: Record<string, unknown>): ILogger;
4
- trace(obj: unknown, msg?: string): void;
5
- debug(obj: unknown, msg?: string): void;
6
- info(obj: unknown, msg?: string): void;
7
- warn(obj: unknown, msg?: string): void;
8
- error(obj: unknown, msg?: string): void;
2
+ level: string
3
+ child(obj: Record<string, unknown>): ILogger
4
+ trace(obj: unknown, msg?: string): any
5
+ debug(obj: unknown, msg?: string): any
6
+ info(obj: unknown, msg?: string): any
7
+ warn(obj: unknown, msg?: string): any
8
+ error(obj: unknown, msg?: string): any
9
9
  }
10
- declare const _default: import("pino").Logger<never, boolean>;
11
- export default _default;
12
- //# sourceMappingURL=logger.d.ts.map
10
+
11
+ declare const _default: import("pino").Logger<never, boolean>
12
+
13
+ export default _default
@@ -1,3 +1,7 @@
1
- import P from 'pino';
2
- export default P({ timestamp: () => `,"time":"${new Date().toJSON()}"` });
3
- //# sourceMappingURL=logger.js.map
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
+ const pino_1 = __importDefault(require("pino"))
7
+ exports.default = pino_1.default({ timestamp: () => `,"time":"${new Date().toJSON()}"` })
@@ -1,8 +1,14 @@
1
- import { LTHashAntiTampering } from 'whatsapp-rust-bridge';
2
- /**
3
- * LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
4
- * over a series of mutations. You can add/remove mutations and it'll return a hash equal to
5
- * if the same series of mutations was made sequentially.
6
- */
7
- export declare const LT_HASH_ANTI_TAMPERING: LTHashAntiTampering;
8
- //# sourceMappingURL=lt-hash.d.ts.map
1
+ declare class d {
2
+ salt: string
3
+ constructor(e: string)
4
+ add(e: any, t: any): any
5
+ subtract(e: any, t: any): any
6
+ subtractThenAdd(e: any, t: any, r: any): any
7
+ _addSingle(e: any, t: any): Promise<ArrayBuffer>
8
+ _subtractSingle(e: any, t: any): Promise<ArrayBuffer>
9
+ performPointwiseWithOverflow(e: any, t: any, r: any): ArrayBuffer
10
+ }
11
+
12
+ export declare const LT_HASH_ANTI_TAMPERING: d
13
+
14
+ export {}