@nexustechpro/baileys 2.0.2 → 2.0.6

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 (108) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +924 -1299
  3. package/WAProto/index.js +22 -18
  4. package/lib/Defaults/baileys-version.json +6 -2
  5. package/lib/Defaults/index.js +173 -172
  6. package/lib/Signal/libsignal.js +395 -292
  7. package/lib/Signal/lid-mapping.js +264 -171
  8. package/lib/Socket/Client/index.js +2 -2
  9. package/lib/Socket/Client/types.js +10 -10
  10. package/lib/Socket/Client/websocket.js +45 -310
  11. package/lib/Socket/business.js +375 -375
  12. package/lib/Socket/chats.js +916 -963
  13. package/lib/Socket/communities.js +430 -430
  14. package/lib/Socket/groups.js +342 -342
  15. package/lib/Socket/index.js +21 -22
  16. package/lib/Socket/messages-recv.js +963 -743
  17. package/lib/Socket/messages-send.js +273 -321
  18. package/lib/Socket/mex.js +50 -50
  19. package/lib/Socket/newsletter.js +148 -148
  20. package/lib/Socket/nexus-handler.js +296 -247
  21. package/lib/Socket/registration.js +50 -33
  22. package/lib/Socket/socket.js +872 -1201
  23. package/lib/Store/index.js +5 -5
  24. package/lib/Store/make-cache-manager-store.js +81 -81
  25. package/lib/Store/make-in-memory-store.js +416 -416
  26. package/lib/Store/make-ordered-dictionary.js +81 -81
  27. package/lib/Store/object-repository.js +30 -30
  28. package/lib/Types/Auth.js +1 -1
  29. package/lib/Types/Bussines.js +1 -1
  30. package/lib/Types/Call.js +1 -1
  31. package/lib/Types/Chat.js +7 -7
  32. package/lib/Types/Contact.js +1 -1
  33. package/lib/Types/Events.js +1 -1
  34. package/lib/Types/GroupMetadata.js +1 -1
  35. package/lib/Types/Label.js +24 -24
  36. package/lib/Types/LabelAssociation.js +6 -6
  37. package/lib/Types/Message.js +10 -10
  38. package/lib/Types/Newsletter.js +37 -29
  39. package/lib/Types/Product.js +1 -1
  40. package/lib/Types/Signal.js +1 -1
  41. package/lib/Types/Socket.js +2 -2
  42. package/lib/Types/State.js +55 -12
  43. package/lib/Types/USync.js +1 -1
  44. package/lib/Types/index.js +25 -25
  45. package/lib/Utils/auth-utils.js +264 -256
  46. package/lib/Utils/baileys-event-stream.js +55 -55
  47. package/lib/Utils/browser-utils.js +27 -27
  48. package/lib/Utils/business.js +228 -230
  49. package/lib/Utils/chat-utils.js +726 -764
  50. package/lib/Utils/companion-reg-client-utils.js +34 -0
  51. package/lib/Utils/crypto.js +109 -135
  52. package/lib/Utils/decode-wa-message.js +342 -314
  53. package/lib/Utils/event-buffer.js +547 -547
  54. package/lib/Utils/generics.js +295 -297
  55. package/lib/Utils/history.js +91 -83
  56. package/lib/Utils/index.js +25 -20
  57. package/lib/Utils/key-store.js +17 -0
  58. package/lib/Utils/link-preview.js +107 -98
  59. package/lib/Utils/logger.js +2 -2
  60. package/lib/Utils/lt-hash.js +47 -47
  61. package/lib/Utils/make-mutex.js +39 -39
  62. package/lib/Utils/message-retry-manager.js +148 -148
  63. package/lib/Utils/messages-media.js +579 -535
  64. package/lib/Utils/messages.js +821 -706
  65. package/lib/Utils/noise-handler.js +255 -255
  66. package/lib/Utils/pre-key-manager.js +105 -105
  67. package/lib/Utils/process-message.js +430 -412
  68. package/lib/Utils/reporting-utils.js +155 -0
  69. package/lib/Utils/signal.js +191 -159
  70. package/lib/Utils/sync-action-utils.js +33 -0
  71. package/lib/Utils/tc-token-utils.js +162 -0
  72. package/lib/Utils/use-multi-file-auth-state.js +120 -120
  73. package/lib/Utils/validate-connection.js +194 -194
  74. package/lib/WABinary/constants.js +1306 -1300
  75. package/lib/WABinary/decode.js +237 -237
  76. package/lib/WABinary/encode.js +232 -232
  77. package/lib/WABinary/generic-utils.js +252 -211
  78. package/lib/WABinary/index.js +6 -5
  79. package/lib/WABinary/jid-utils.js +279 -95
  80. package/lib/WABinary/types.js +1 -1
  81. package/lib/WAM/BinaryInfo.js +9 -9
  82. package/lib/WAM/constants.js +22852 -22852
  83. package/lib/WAM/encode.js +149 -149
  84. package/lib/WAM/index.js +3 -3
  85. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -28
  86. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -53
  87. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -26
  88. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -37
  89. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
  90. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -28
  91. package/lib/WAUSync/Protocols/index.js +4 -4
  92. package/lib/WAUSync/USyncQuery.js +93 -93
  93. package/lib/WAUSync/USyncUser.js +22 -22
  94. package/lib/WAUSync/index.js +3 -3
  95. package/lib/index.js +65 -66
  96. package/package.json +172 -143
  97. package/lib/Signal/Group/ciphertext-message.js +0 -12
  98. package/lib/Signal/Group/group-session-builder.js +0 -30
  99. package/lib/Signal/Group/group_cipher.js +0 -100
  100. package/lib/Signal/Group/index.js +0 -12
  101. package/lib/Signal/Group/keyhelper.js +0 -18
  102. package/lib/Signal/Group/sender-chain-key.js +0 -26
  103. package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
  104. package/lib/Signal/Group/sender-key-message.js +0 -66
  105. package/lib/Signal/Group/sender-key-name.js +0 -48
  106. package/lib/Signal/Group/sender-key-record.js +0 -41
  107. package/lib/Signal/Group/sender-key-state.js +0 -84
  108. package/lib/Signal/Group/sender-message-key.js +0 -26
@@ -1,84 +1,92 @@
1
- import { promisify } from 'util';
2
- import { inflate } from 'zlib';
3
- import { proto } from '../../WAProto/index.js';
4
- import { WAMessageStubType } from '../Types/index.js';
5
- import { toNumber } from './generics.js';
6
- import { normalizeMessageContent } from './messages.js';
7
- import { downloadContentFromMessage } from './messages-media.js';
8
- const inflatePromise = promisify(inflate);
9
- export const downloadHistory = async (msg, options) => {
10
- const stream = await downloadContentFromMessage(msg, 'md-msg-hist', { options });
11
- const bufferArray = [];
12
- for await (const chunk of stream) {
13
- bufferArray.push(chunk);
14
- }
15
- let buffer = Buffer.concat(bufferArray);
16
- // decompress buffer
17
- buffer = await inflatePromise(buffer);
18
- const syncData = proto.HistorySync.decode(buffer);
19
- return syncData;
20
- };
21
- export const processHistoryMessage = (item) => {
22
- const messages = [];
23
- const contacts = [];
24
- const chats = [];
25
- switch (item.syncType) {
26
- case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
27
- case proto.HistorySync.HistorySyncType.RECENT:
28
- case proto.HistorySync.HistorySyncType.FULL:
29
- case proto.HistorySync.HistorySyncType.ON_DEMAND:
30
- for (const chat of item.conversations) {
31
- contacts.push({
32
- id: chat.id,
33
- name: chat.name || undefined,
34
- lid: chat.lidJid || undefined,
35
- phoneNumber: chat.pnJid || undefined
36
- });
37
- const msgs = chat.messages || [];
38
- delete chat.messages;
39
- for (const item of msgs) {
40
- const message = item.message;
41
- messages.push(message);
42
- if (!chat.messages?.length) {
43
- // keep only the most recent message in the chat array
44
- chat.messages = [{ message }];
45
- }
46
- if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
47
- chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp);
48
- }
49
- if ((message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
50
- message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) &&
51
- message.messageStubParameters?.[0]) {
52
- contacts.push({
53
- id: message.key.participant || message.key.remoteJid,
54
- verifiedName: message.messageStubParameters?.[0]
55
- });
56
- }
57
- }
58
- chats.push({ ...chat });
59
- }
60
- break;
61
- case proto.HistorySync.HistorySyncType.PUSH_NAME:
62
- for (const c of item.pushnames) {
63
- contacts.push({ id: c.id, notify: c.pushname });
64
- }
65
- break;
66
- }
67
- return {
68
- chats,
69
- contacts,
70
- messages,
71
- syncType: item.syncType,
72
- progress: item.progress
73
- };
74
- };
75
- export const downloadAndProcessHistorySyncNotification = async (msg, options) => {
76
- const historyMsg = await downloadHistory(msg, options);
77
- return processHistoryMessage(historyMsg);
78
- };
79
- export const getHistoryMsg = (message) => {
80
- const normalizedContent = !!message ? normalizeMessageContent(message) : undefined;
81
- const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification;
82
- return anyHistoryMsg;
83
- };
1
+ import { promisify } from 'util';
2
+ import { inflate } from 'zlib';
3
+ import { proto } from '../../WAProto/index.js';
4
+ import { WAMessageStubType } from '../Types/index.js';
5
+ import { isJidUser } from '../WABinary/index.js';
6
+ import { toNumber } from './generics.js';
7
+ import { normalizeMessageContent } from './messages.js';
8
+ import { downloadContentFromMessage } from './messages-media.js';
9
+ const inflatePromise = promisify(inflate);
10
+ export const downloadHistory = async (msg, options) => {
11
+ const stream = await downloadContentFromMessage(msg, 'md-msg-hist', { options });
12
+ const bufferArray = [];
13
+ for await (const chunk of stream) {
14
+ bufferArray.push(chunk);
15
+ }
16
+ let buffer = Buffer.concat(bufferArray);
17
+ // decompress buffer
18
+ buffer = await inflatePromise(buffer);
19
+ const syncData = proto.HistorySync.decode(buffer);
20
+ return syncData;
21
+ };
22
+ export const processHistoryMessage = (item) => {
23
+ const messages = [];
24
+ const contacts = [];
25
+ const chats = [];
26
+ switch (item.syncType) {
27
+ case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
28
+ case proto.HistorySync.HistorySyncType.RECENT:
29
+ case proto.HistorySync.HistorySyncType.FULL:
30
+ case proto.HistorySync.HistorySyncType.ON_DEMAND:
31
+ for (const chat of item.conversations) {
32
+ contacts.push({
33
+ id: chat.id,
34
+ name: chat.name || undefined,
35
+ lid: chat.lidJid || undefined,
36
+ phoneNumber: chat.pnJid || undefined,
37
+ jid: isJidUser(chat.id) ? chat.id : undefined
38
+ });
39
+ const msgs = chat.messages || [];
40
+ delete chat.messages;
41
+ delete chat.archived;
42
+ delete chat.muteEndTime;
43
+ delete chat.pinned;
44
+ for (const item of msgs) {
45
+ const message = item.message;
46
+ messages.push(message);
47
+ if (!chat.messages?.length) {
48
+ // keep only the most recent message in the chat array
49
+ chat.messages = [{ message }];
50
+ }
51
+ if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
52
+ chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp);
53
+ }
54
+ if ((message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
55
+ message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) &&
56
+ message.messageStubParameters?.[0]) {
57
+ contacts.push({
58
+ id: message.key.participant || message.key.remoteJid,
59
+ verifiedName: message.messageStubParameters?.[0]
60
+ });
61
+ }
62
+ }
63
+ if (isJidUser(chat.id) && chat.readOnly && chat.archived) {
64
+ delete chat.readOnly;
65
+ }
66
+ chats.push({ ...chat });
67
+ }
68
+ break;
69
+ case proto.HistorySync.HistorySyncType.PUSH_NAME:
70
+ for (const c of item.pushnames) {
71
+ contacts.push({ id: c.id, notify: c.pushname });
72
+ }
73
+ break;
74
+ }
75
+ return {
76
+ chats,
77
+ contacts,
78
+ messages,
79
+ syncType: item.syncType,
80
+ progress: item.progress
81
+ };
82
+ };
83
+ export const downloadAndProcessHistorySyncNotification = async (msg, options) => {
84
+ const historyMsg = await downloadHistory(msg, options);
85
+ return processHistoryMessage(historyMsg);
86
+ };
87
+ export const getHistoryMsg = (message) => {
88
+ const normalizedContent = !!message ? normalizeMessageContent(message) : undefined;
89
+ const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification;
90
+ return anyHistoryMsg;
91
+ };
84
92
  //# sourceMappingURL=history.js.map
@@ -1,21 +1,26 @@
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 './baileys-event-stream.js';
14
- export * from './use-multi-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 './message-retry-manager.js';
19
- export * from './browser-utils.js';
20
- export * from './identity-chnage-handler.js';
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 './make-mutex.js';
9
+ export * from './noise-handler.js';
10
+ export * from './history.js';
11
+ export * from './chat-utils.js';
12
+ export * from './lt-hash.js';
13
+ export * from './auth-utils.js';
14
+ export * from './baileys-event-stream.js';
15
+ export * from './use-multi-file-auth-state.js';
16
+ export * from './link-preview.js';
17
+ export * from './event-buffer.js';
18
+ export * from './process-message.js';
19
+ export * from './message-retry-manager.js';
20
+ export * from './browser-utils.js';
21
+ export * from './identity-chnage-handler.js';
22
+ export * from './key-store.js';
23
+ export * from './reporting-utils.js';
24
+ export * from './companion-reg-client-utils.js';
25
+ export * from './tc-token-utils.js';
21
26
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,17 @@
1
+ // ─── Key Store Helpers ─────────────────────────────────────────────────────────
2
+ // Single source of truth for blob key names — change here, changes everywhere
3
+ export const SESSION_INDEX_KEY = 'index'
4
+ export const DEVICE_LIST_INDEX_KEY = 'index'
5
+
6
+ // Migrates old _index blob to new index key in-place, returns the batch data
7
+ export const migrateIndexKey = async (keys, type) => {
8
+ const oldKey = '_index'
9
+ const newKey = 'index'
10
+ const oldData = await keys.get(type, [oldKey])
11
+ if (oldData?.[oldKey] && typeof oldData[oldKey] === 'object') { // only migrate if old blob actually exists and has data
12
+ await keys.set({ [type]: { [newKey]: oldData[oldKey], [oldKey]: null } })
13
+ return oldData[oldKey]
14
+ }
15
+ const newData = await keys.get(type, [newKey])
16
+ return newData?.[newKey] || {}
17
+ }
@@ -1,99 +1,108 @@
1
- import { prepareWAMessageMedia } from './messages.js';
2
- import { extractImageThumb, getHttpStream } from './messages-media.js';
3
- const THUMBNAIL_WIDTH_PX = 192;
4
- /** Fetches an image and generates a thumbnail for it */
5
- const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
6
- const stream = await getHttpStream(url, fetchOpts);
7
- const result = await extractImageThumb(stream, thumbnailWidth);
8
- return result;
9
- };
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
- */
16
- export const getUrlInfo = async (text, opts = {
17
- thumbnailWidth: THUMBNAIL_WIDTH_PX,
18
- fetchOpts: { timeout: 3000 }
19
- }) => {
20
- try {
21
- // Fix 1: use let so retries can actually increment
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
28
- }
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) return false
36
- if (
37
- forwardedURLObj.hostname === urlObj.hostname ||
38
- forwardedURLObj.hostname === 'www.' + urlObj.hostname ||
39
- 'www.' + forwardedURLObj.hostname === urlObj.hostname
40
- ) {
41
- retries += 1 // Fix 1: actually increment
42
- return true
43
- }
44
- return false
45
- },
46
- headers: opts.fetchOpts?.headers
47
- })
48
-
49
- if (info && 'title' in info && info.title) {
50
- const [image] = info.images
51
- const urlInfo = {
52
- 'canonical-url': info.url,
53
- 'matched-text': text,
54
- title: info.title,
55
- description: info.description,
56
- originalThumbnailUrl: image
57
- }
58
-
59
- if (opts.uploadImage) {
60
- try {
61
- const { imageMessage } = await prepareWAMessageMedia({ image: { url: image } }, {
62
- upload: opts.uploadImage,
63
- mediaTypeOverride: 'thumbnail-link',
64
- options: opts.fetchOpts
65
- })
66
- urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail
67
- ? Buffer.from(imageMessage.jpegThumbnail)
68
- : undefined
69
- urlInfo.highQualityThumbnail = imageMessage || undefined
70
- } catch (error) {
71
- opts.logger?.warn({ err: error.message, url: image }, 'failed to upload link preview thumbnail, falling back to compressed')
72
- // Fix 2: fallback to compressed thumbnail instead of giving up entirely
73
- try {
74
- urlInfo.jpegThumbnail = image
75
- ? (await getCompressedJpegThumbnail(image, opts)).buffer
76
- : undefined
77
- } catch (fallbackErr) {
78
- opts.logger?.debug({ err: fallbackErr.stack }, 'fallback thumbnail also failed')
79
- }
80
- }
81
- } else {
82
- try {
83
- urlInfo.jpegThumbnail = image
84
- ? (await getCompressedJpegThumbnail(image, opts)).buffer
85
- : undefined
86
- } catch (error) {
87
- opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail')
88
- }
89
- }
90
-
91
- return urlInfo
92
- }
93
- } catch (error) {
94
- if (!error.message.includes('receive a valid')) {
95
- throw error
96
- }
97
- }
98
- }
1
+ import { promises as dnsPromises } from 'dns'
2
+ import { getLinkPreview } from 'link-preview-js'
3
+ import { prepareWAMessageMedia } from './messages.js'
4
+ import { extractImageThumb, getHttpStream } from './messages-media.js'
5
+
6
+ const THUMBNAIL_WIDTH_PX = 192
7
+ const MAX_REDIRECTS = 5
8
+ const PREVIEW_TIMEOUT = 5000
9
+ // Concurrency pool — max simultaneous link preview fetches
10
+ const MAX_CONCURRENT = 20
11
+ let _active = 0
12
+ const _queue = []
13
+ const _drain = () => {
14
+ if (_queue.length === 0 || _active >= MAX_CONCURRENT) return
15
+ _active++
16
+ const { fn, resolve, reject } = _queue.shift()
17
+ fn().then(resolve).catch(reject).finally(() => { _active--; _drain() })
18
+ }
19
+ const _enqueue = fn => new Promise((resolve, reject) => { _queue.push({ fn, resolve, reject }); _drain() })
20
+
21
+ /** Fetches a remote image and compresses it to a JPEG thumbnail buffer */
22
+ const _compressedThumb = async (url, opts) => {
23
+ const stream = await getHttpStream(url, opts.fetchOpts)
24
+ const result = await extractImageThumb(stream, opts.thumbnailWidth ?? THUMBNAIL_WIDTH_PX)
25
+ return result.buffer
26
+ }
27
+
28
+ /** Resolves jpegThumbnail + highQualityThumbnail from an image URL, never throws */
29
+ const _resolveThumbnail = async (image, opts) => {
30
+ if (!image) return {}
31
+ if (opts.uploadImage) {
32
+ try {
33
+ const { imageMessage } = await prepareWAMessageMedia(
34
+ { image: { url: image } },
35
+ { upload: opts.uploadImage, mediaTypeOverride: 'thumbnail-link', options: opts.fetchOpts }
36
+ )
37
+ return {
38
+ jpegThumbnail: imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined,
39
+ highQualityThumbnail: imageMessage ?? undefined
40
+ }
41
+ } catch (err) {
42
+ opts.logger?.warn({ err: err.message, url: image }, 'upload failed, falling back to compressed thumb')
43
+ }
44
+ }
45
+ // Fallback: local compression (also used when no uploadImage provided)
46
+ try {
47
+ return { jpegThumbnail: await _compressedThumb(image, opts) }
48
+ } catch (err) {
49
+ opts.logger?.debug({ err: err.stack }, 'compressed thumb failed')
50
+ return {}
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Extracts link preview info from a text string or URL.
56
+ * Queued for concurrency control — never throws on preview failure.
57
+ * @param {string} text - Raw text or URL to preview
58
+ * @param {object} opts - Options: thumbnailWidth, fetchOpts, uploadImage, logger
59
+ * @returns {Promise<object|undefined>} urlInfo or undefined if no valid URL/title found
60
+ */
61
+ export const getUrlInfo = (text, opts = {}) => _enqueue(async () => {
62
+ const fetchOpts = opts.fetchOpts ?? { timeout: PREVIEW_TIMEOUT }
63
+ const thumbnailWidth = opts.thumbnailWidth ?? THUMBNAIL_WIDTH_PX
64
+ const resolvedOpts = { ...opts, fetchOpts, thumbnailWidth }
65
+ try {
66
+ let retries = 0
67
+ const previewLink = (text.startsWith('https://') || text.startsWith('http://')) ? text : 'https://' + text
68
+ const info = await getLinkPreview(previewLink, {
69
+ ...fetchOpts,
70
+ followRedirects: 'manual',
71
+ handleRedirects: (baseURL, forwardedURL) => {
72
+ if (retries >= MAX_REDIRECTS) return false
73
+ const base = new URL(baseURL)
74
+ const fwd = new URL(forwardedURL)
75
+ const sameHost = fwd.hostname === base.hostname || fwd.hostname === 'www.' + base.hostname || 'www.' + fwd.hostname === base.hostname
76
+ if (sameHost) { retries++; return true }
77
+ return false
78
+ },
79
+ resolveDNSHost: async (url) => {
80
+ const hostname = new URL(url).hostname
81
+ try {
82
+ const { address } = await dnsPromises.lookup(hostname)
83
+ return address
84
+ } catch {
85
+ return hostname
86
+ }
87
+ },
88
+ headers: fetchOpts.headers
89
+ })
90
+ if (!info || !('title' in info) || !info.title) return undefined
91
+ const [image] = info.images ?? []
92
+ const thumbs = await _resolveThumbnail(image, resolvedOpts)
93
+ return {
94
+ 'canonical-url': info.url,
95
+ 'matched-text': text,
96
+ title: info.title,
97
+ description: info.description,
98
+ originalThumbnailUrl: image,
99
+ ...thumbs
100
+ }
101
+ } catch (err) {
102
+ // Suppress "no valid URL" and missing module errors; re-throw everything else
103
+ if (!err.message?.includes('receive a valid') && err.code !== 'ERR_MODULE_NOT_FOUND' && err.code !== 'MODULE_NOT_FOUND') {
104
+ throw err
105
+ }
106
+ }
107
+ })
99
108
  //# sourceMappingURL=link-preview.js.map
@@ -1,3 +1,3 @@
1
- import P from 'pino';
2
- export default P({ timestamp: () => `,"time":"${new Date().toJSON()}"` });
1
+ import P from 'pino';
2
+ export default P({ timestamp: () => `,"time":"${new Date().toJSON()}"` });
3
3
  //# sourceMappingURL=logger.js.map
@@ -1,48 +1,48 @@
1
- import { hkdf } from './crypto.js';
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
- const o = 128;
8
- class LTHash {
9
- constructor(e) {
10
- this.salt = e;
11
- }
12
- async add(e, t) {
13
- for (const item of t) {
14
- e = await this._addSingle(e, item);
15
- }
16
- return e;
17
- }
18
- async subtract(e, t) {
19
- for (const item of t) {
20
- e = await this._subtractSingle(e, item);
21
- }
22
- return e;
23
- }
24
- async subtractThenAdd(e, addList, subtractList) {
25
- const subtracted = await this.subtract(e, subtractList);
26
- return this.add(subtracted, addList);
27
- }
28
- async _addSingle(e, t) {
29
- const derived = new Uint8Array(hkdf(Buffer.from(t), o, { info: this.salt })).buffer;
30
- return this.performPointwiseWithOverflow(e, derived, (a, b) => a + b);
31
- }
32
- async _subtractSingle(e, t) {
33
- const derived = new Uint8Array(hkdf(Buffer.from(t), o, { info: this.salt })).buffer;
34
- return this.performPointwiseWithOverflow(e, derived, (a, b) => a - b);
35
- }
36
- performPointwiseWithOverflow(e, t, op) {
37
- const n = new DataView(e);
38
- const i = new DataView(t);
39
- const out = new ArrayBuffer(n.byteLength);
40
- const s = new DataView(out);
41
- for (let offset = 0; offset < n.byteLength; offset += 2) {
42
- s.setUint16(offset, op(n.getUint16(offset, true), i.getUint16(offset, true)), true);
43
- }
44
- return out;
45
- }
46
- }
47
- export const LT_HASH_ANTI_TAMPERING = new LTHash('WhatsApp Patch Integrity');
1
+ import { hkdf } from './crypto.js';
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
+ const o = 128;
8
+ class LTHash {
9
+ constructor(e) {
10
+ this.salt = e;
11
+ }
12
+ async add(e, t) {
13
+ for (const item of t) {
14
+ e = await this._addSingle(e, item);
15
+ }
16
+ return e;
17
+ }
18
+ async subtract(e, t) {
19
+ for (const item of t) {
20
+ e = await this._subtractSingle(e, item);
21
+ }
22
+ return e;
23
+ }
24
+ async subtractThenAdd(e, addList, subtractList) {
25
+ const subtracted = await this.subtract(e, subtractList);
26
+ return this.add(subtracted, addList);
27
+ }
28
+ async _addSingle(e, t) {
29
+ const derived = new Uint8Array(hkdf(Buffer.from(t), o, { info: this.salt })).buffer;
30
+ return this.performPointwiseWithOverflow(e, derived, (a, b) => a + b);
31
+ }
32
+ async _subtractSingle(e, t) {
33
+ const derived = new Uint8Array(hkdf(Buffer.from(t), o, { info: this.salt })).buffer;
34
+ return this.performPointwiseWithOverflow(e, derived, (a, b) => a - b);
35
+ }
36
+ performPointwiseWithOverflow(e, t, op) {
37
+ const n = new DataView(e);
38
+ const i = new DataView(t);
39
+ const out = new ArrayBuffer(n.byteLength);
40
+ const s = new DataView(out);
41
+ for (let offset = 0; offset < n.byteLength; offset += 2) {
42
+ s.setUint16(offset, op(n.getUint16(offset, true), i.getUint16(offset, true)), true);
43
+ }
44
+ return out;
45
+ }
46
+ }
47
+ export const LT_HASH_ANTI_TAMPERING = new LTHash('WhatsApp Patch Integrity');
48
48
  //# sourceMappingURL=lt-hash.js.map
@@ -1,40 +1,40 @@
1
- export const makeMutex = () => {
2
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
- let task = Promise.resolve();
4
- let taskTimeout;
5
- return {
6
- mutex(code) {
7
- task = (async () => {
8
- // wait for the previous task to complete
9
- // if there is an error, we swallow so as to not block the queue
10
- try {
11
- await task;
12
- }
13
- catch { }
14
- try {
15
- // execute the current task
16
- const result = await code();
17
- return result;
18
- }
19
- finally {
20
- clearTimeout(taskTimeout);
21
- }
22
- })();
23
- // we replace the existing task, appending the new piece of execution to it
24
- // so the next task will have to wait for this one to finish
25
- return task;
26
- }
27
- };
28
- };
29
- export const makeKeyedMutex = () => {
30
- const map = {};
31
- return {
32
- mutex(key, task) {
33
- if (!map[key]) {
34
- map[key] = makeMutex();
35
- }
36
- return map[key].mutex(task);
37
- }
38
- };
39
- };
1
+ export const makeMutex = () => {
2
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
+ let task = Promise.resolve();
4
+ let taskTimeout;
5
+ return {
6
+ mutex(code) {
7
+ task = (async () => {
8
+ // wait for the previous task to complete
9
+ // if there is an error, we swallow so as to not block the queue
10
+ try {
11
+ await task;
12
+ }
13
+ catch { }
14
+ try {
15
+ // execute the current task
16
+ const result = await code();
17
+ return result;
18
+ }
19
+ finally {
20
+ clearTimeout(taskTimeout);
21
+ }
22
+ })();
23
+ // we replace the existing task, appending the new piece of execution to it
24
+ // so the next task will have to wait for this one to finish
25
+ return task;
26
+ }
27
+ };
28
+ };
29
+ export const makeKeyedMutex = () => {
30
+ const map = {};
31
+ return {
32
+ mutex(key, task) {
33
+ if (!map[key]) {
34
+ map[key] = makeMutex();
35
+ }
36
+ return map[key].mutex(task);
37
+ }
38
+ };
39
+ };
40
40
  //# sourceMappingURL=make-mutex.js.map