astrabail 1.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 (224) hide show
  1. package/WAProto/GenerateStatics.sh +3 -0
  2. package/WAProto/WAProto.proto +5479 -0
  3. package/WAProto/fix-imports.js +73 -0
  4. package/WAProto/index.d.ts +14017 -0
  5. package/WAProto/index.js +89351 -0
  6. package/WAProto/p.html +1 -0
  7. package/engine-requirements.js +7 -0
  8. package/lib/Defaults/astrabail-version.json +8 -0
  9. package/lib/Defaults/index.d.ts +74 -0
  10. package/lib/Defaults/index.js +166 -0
  11. package/lib/Defaults/phonenumber-mcc.json +223 -0
  12. package/lib/Defaults/update-wa-version.js +75 -0
  13. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  14. package/lib/Signal/Group/ciphertext-message.js +15 -0
  15. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  16. package/lib/Signal/Group/group-session-builder.js +66 -0
  17. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  18. package/lib/Signal/Group/group_cipher.js +85 -0
  19. package/lib/Signal/Group/index.d.ts +12 -0
  20. package/lib/Signal/Group/index.js +57 -0
  21. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  22. package/lib/Signal/Group/keyhelper.js +55 -0
  23. package/lib/Signal/Group/queue-job.js +57 -0
  24. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  25. package/lib/Signal/Group/sender-chain-key.js +29 -0
  26. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  27. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  28. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  29. package/lib/Signal/Group/sender-key-message.js +69 -0
  30. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  31. package/lib/Signal/Group/sender-key-name.js +51 -0
  32. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  33. package/lib/Signal/Group/sender-key-record.js +44 -0
  34. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  35. package/lib/Signal/Group/sender-key-state.js +87 -0
  36. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  37. package/lib/Signal/Group/sender-message-key.js +29 -0
  38. package/lib/Signal/libsignal.d.ts +5 -0
  39. package/lib/Signal/libsignal.js +478 -0
  40. package/lib/Signal/lid-mapping.d.ts +19 -0
  41. package/lib/Signal/lid-mapping.js +274 -0
  42. package/lib/Socket/Client/index.d.ts +3 -0
  43. package/lib/Socket/Client/index.js +18 -0
  44. package/lib/Socket/Client/types.d.ts +16 -0
  45. package/lib/Socket/Client/types.js +14 -0
  46. package/lib/Socket/Client/websocket.d.ts +13 -0
  47. package/lib/Socket/Client/websocket.js +60 -0
  48. package/lib/Socket/business.d.ts +202 -0
  49. package/lib/Socket/business.js +382 -0
  50. package/lib/Socket/chats.d.ts +111 -0
  51. package/lib/Socket/chats.js +1155 -0
  52. package/lib/Socket/communities.d.ts +258 -0
  53. package/lib/Socket/communities.js +438 -0
  54. package/lib/Socket/community.js +333 -0
  55. package/lib/Socket/groups.d.ts +150 -0
  56. package/lib/Socket/groups.js +470 -0
  57. package/lib/Socket/index.d.ts +245 -0
  58. package/lib/Socket/index.js +13 -0
  59. package/lib/Socket/messages-recv.d.ts +187 -0
  60. package/lib/Socket/messages-recv.js +1708 -0
  61. package/lib/Socket/messages-send.d.ts +183 -0
  62. package/lib/Socket/messages-send.js +1692 -0
  63. package/lib/Socket/mex.d.ts +3 -0
  64. package/lib/Socket/mex.js +45 -0
  65. package/lib/Socket/newsletter.d.ts +160 -0
  66. package/lib/Socket/newsletter.js +293 -0
  67. package/lib/Socket/socket.d.ts +55 -0
  68. package/lib/Socket/socket.js +947 -0
  69. package/lib/Socket/usync.js +70 -0
  70. package/lib/Store/index.js +20 -0
  71. package/lib/Store/make-cache-manager-store.js +83 -0
  72. package/lib/Store/make-in-memory-store.js +398 -0
  73. package/lib/Store/make-ordered-dictionary.js +81 -0
  74. package/lib/Store/object-repository.js +27 -0
  75. package/lib/Types/Auth.d.ts +116 -0
  76. package/lib/Types/Auth.js +2 -0
  77. package/lib/Types/Bussines.d.ts +25 -0
  78. package/lib/Types/Bussines.js +2 -0
  79. package/lib/Types/Call.d.ts +15 -0
  80. package/lib/Types/Call.js +2 -0
  81. package/lib/Types/Chat.d.ts +123 -0
  82. package/lib/Types/Chat.js +10 -0
  83. package/lib/Types/Contact.d.ts +24 -0
  84. package/lib/Types/Contact.js +2 -0
  85. package/lib/Types/Events.d.ts +237 -0
  86. package/lib/Types/Events.js +3 -0
  87. package/lib/Types/GroupMetadata.d.ts +67 -0
  88. package/lib/Types/GroupMetadata.js +2 -0
  89. package/lib/Types/Label.d.ts +47 -0
  90. package/lib/Types/Label.js +25 -0
  91. package/lib/Types/LabelAssociation.d.ts +30 -0
  92. package/lib/Types/LabelAssociation.js +7 -0
  93. package/lib/Types/Message.d.ts +305 -0
  94. package/lib/Types/Message.js +11 -0
  95. package/lib/Types/MexUpdates.js +11 -0
  96. package/lib/Types/Newsletter.d.ts +135 -0
  97. package/lib/Types/Newsletter.js +43 -0
  98. package/lib/Types/Product.d.ts +79 -0
  99. package/lib/Types/Product.js +2 -0
  100. package/lib/Types/Signal.d.ts +76 -0
  101. package/lib/Types/Signal.js +3 -0
  102. package/lib/Types/Socket.d.ts +133 -0
  103. package/lib/Types/Socket.js +3 -0
  104. package/lib/Types/State.d.ts +39 -0
  105. package/lib/Types/State.js +14 -0
  106. package/lib/Types/USync.d.ts +26 -0
  107. package/lib/Types/USync.js +3 -0
  108. package/lib/Types/index.d.ts +65 -0
  109. package/lib/Types/index.js +42 -0
  110. package/lib/Utils/astrabail-event-stream.js +3 -0
  111. package/lib/Utils/audioToBuffer.js +31 -0
  112. package/lib/Utils/auth-utils.d.ts +19 -0
  113. package/lib/Utils/auth-utils.js +298 -0
  114. package/lib/Utils/baileys-event-stream.js +60 -0
  115. package/lib/Utils/bridge-runtime.d.ts +1 -0
  116. package/lib/Utils/bridge-runtime.js +14 -0
  117. package/lib/Utils/browser-utils.d.ts +4 -0
  118. package/lib/Utils/browser-utils.js +44 -0
  119. package/lib/Utils/business.d.ts +23 -0
  120. package/lib/Utils/business.js +240 -0
  121. package/lib/Utils/chat-utils.d.ts +70 -0
  122. package/lib/Utils/chat-utils.js +825 -0
  123. package/lib/Utils/crypto.d.ts +37 -0
  124. package/lib/Utils/crypto.js +168 -0
  125. package/lib/Utils/decode-wa-message.d.ts +48 -0
  126. package/lib/Utils/decode-wa-message.js +287 -0
  127. package/lib/Utils/event-buffer.d.ts +34 -0
  128. package/lib/Utils/event-buffer.js +580 -0
  129. package/lib/Utils/generics.d.ts +91 -0
  130. package/lib/Utils/generics.js +483 -0
  131. package/lib/Utils/history.d.ts +22 -0
  132. package/lib/Utils/history.js +137 -0
  133. package/lib/Utils/identity-change-handler.d.ts +37 -0
  134. package/lib/Utils/identity-change-handler.js +54 -0
  135. package/lib/Utils/index.d.ts +22 -0
  136. package/lib/Utils/index.js +48 -0
  137. package/lib/Utils/link-preview.d.ts +21 -0
  138. package/lib/Utils/link-preview.js +121 -0
  139. package/lib/Utils/logger.d.ts +13 -0
  140. package/lib/Utils/logger.js +7 -0
  141. package/lib/Utils/lt-hash.d.ts +8 -0
  142. package/lib/Utils/lt-hash.js +10 -0
  143. package/lib/Utils/make-mutex.d.ts +9 -0
  144. package/lib/Utils/make-mutex.js +37 -0
  145. package/lib/Utils/message-retry-manager.d.ts +110 -0
  146. package/lib/Utils/message-retry-manager.js +226 -0
  147. package/lib/Utils/messages-media.d.ts +130 -0
  148. package/lib/Utils/messages-media.js +887 -0
  149. package/lib/Utils/messages-newsletter.d.ts +84 -0
  150. package/lib/Utils/messages-newsletter.js +295 -0
  151. package/lib/Utils/messages.d.ts +92 -0
  152. package/lib/Utils/messages.js +1752 -0
  153. package/lib/Utils/noise-handler.d.ts +20 -0
  154. package/lib/Utils/noise-handler.js +204 -0
  155. package/lib/Utils/pre-key-manager.d.ts +28 -0
  156. package/lib/Utils/pre-key-manager.js +112 -0
  157. package/lib/Utils/process-message.d.ts +60 -0
  158. package/lib/Utils/process-message.js +536 -0
  159. package/lib/Utils/reporting-utils.d.ts +11 -0
  160. package/lib/Utils/reporting-utils.js +262 -0
  161. package/lib/Utils/resolve-jid.d.ts +43 -0
  162. package/lib/Utils/resolve-jid.js +95 -0
  163. package/lib/Utils/rust-bridge-shim.d.ts +22 -0
  164. package/lib/Utils/rust-bridge-shim.js +70 -0
  165. package/lib/Utils/serial-task-queue.js +29 -0
  166. package/lib/Utils/signal.d.ts +34 -0
  167. package/lib/Utils/signal.js +170 -0
  168. package/lib/Utils/streamToBuffer.js +17 -0
  169. package/lib/Utils/sync-action-utils.d.ts +19 -0
  170. package/lib/Utils/sync-action-utils.js +52 -0
  171. package/lib/Utils/tc-token-utils.d.ts +12 -0
  172. package/lib/Utils/tc-token-utils.js +20 -0
  173. package/lib/Utils/use-mongo-file-auth-state.js +71 -0
  174. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  175. package/lib/Utils/use-multi-file-auth-state.js +124 -0
  176. package/lib/Utils/use-single-file-auth-state.js +73 -0
  177. package/lib/Utils/validate-connection.d.ts +11 -0
  178. package/lib/Utils/validate-connection.js +206 -0
  179. package/lib/WABinary/constants.d.ts +28 -0
  180. package/lib/WABinary/constants.js +1303 -0
  181. package/lib/WABinary/decode.d.ts +7 -0
  182. package/lib/WABinary/decode.js +300 -0
  183. package/lib/WABinary/encode.d.ts +3 -0
  184. package/lib/WABinary/encode.js +256 -0
  185. package/lib/WABinary/generic-utils.d.ts +15 -0
  186. package/lib/WABinary/generic-utils.js +138 -0
  187. package/lib/WABinary/index.d.ts +6 -0
  188. package/lib/WABinary/index.js +25 -0
  189. package/lib/WABinary/jid-utils.d.ts +48 -0
  190. package/lib/WABinary/jid-utils.js +115 -0
  191. package/lib/WABinary/types.d.ts +19 -0
  192. package/lib/WABinary/types.js +36 -0
  193. package/lib/WAM/BinaryInfo.d.ts +9 -0
  194. package/lib/WAM/BinaryInfo.js +13 -0
  195. package/lib/WAM/constants.d.ts +40 -0
  196. package/lib/WAM/constants.js +22855 -0
  197. package/lib/WAM/encode.d.ts +3 -0
  198. package/lib/WAM/encode.js +153 -0
  199. package/lib/WAM/index.d.ts +4 -0
  200. package/lib/WAM/index.js +19 -0
  201. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  202. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  203. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  204. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  205. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  206. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  207. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  208. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +41 -0
  209. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  210. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +54 -0
  211. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  212. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +32 -0
  213. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  214. package/lib/WAUSync/Protocols/index.js +22 -0
  215. package/lib/WAUSync/USyncQuery.d.ts +29 -0
  216. package/lib/WAUSync/USyncQuery.js +97 -0
  217. package/lib/WAUSync/USyncUser.d.ts +13 -0
  218. package/lib/WAUSync/USyncUser.js +26 -0
  219. package/lib/WAUSync/index.d.ts +4 -0
  220. package/lib/WAUSync/index.js +19 -0
  221. package/lib/index.d.ts +12 -0
  222. package/lib/index.js +124 -0
  223. package/package.json +120 -0
  224. package/readme.md +1956 -0
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.handleIdentityChange = handleIdentityChange;
7
+ const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
8
+ const index_js_1 = require("../WABinary/index.js");
9
+ const generics_js_1 = require("./generics.js");
10
+ async function handleIdentityChange(node, ctx) {
11
+ const from = node.attrs.from;
12
+ if (!from) {
13
+ return { action: 'invalid_notification' };
14
+ }
15
+ const identityNode = (0, index_js_1.getBinaryNodeChild)(node, 'identity');
16
+ if (!identityNode) {
17
+ return { action: 'no_identity_node' };
18
+ }
19
+ ctx.logger.info({ jid: from }, 'identity changed');
20
+ const decoded = (0, index_js_1.jidDecode)(from);
21
+ if (decoded?.device && decoded.device !== 0) {
22
+ ctx.logger.debug({ jid: from, device: decoded.device }, 'ignoring identity change from companion device');
23
+ return { action: 'skipped_companion_device', device: decoded.device };
24
+ }
25
+ const isSelfPrimary = ctx.meId && ((0, index_js_1.areJidsSameUser)(from, ctx.meId) || (ctx.meLid && (0, index_js_1.areJidsSameUser)(from, ctx.meLid)));
26
+ if (isSelfPrimary) {
27
+ ctx.logger.info({ jid: from }, 'self primary identity changed');
28
+ return { action: 'skipped_self_primary' };
29
+ }
30
+ if (ctx.debounceCache.get(from)) {
31
+ ctx.logger.debug({ jid: from }, 'skipping identity assert (debounced)');
32
+ return { action: 'debounced' };
33
+ }
34
+ ctx.debounceCache.set(from, true);
35
+ const isOfflineNotification = !(0, generics_js_1.isStringNullOrEmpty)(node.attrs.offline);
36
+ const hasExistingSession = await ctx.validateSession(from);
37
+ if (!hasExistingSession.exists) {
38
+ ctx.logger.debug({ jid: from }, 'no old session, skipping session refresh');
39
+ return { action: 'skipped_no_session' };
40
+ }
41
+ ctx.logger.debug({ jid: from }, 'old session exists, will refresh session');
42
+ if (isOfflineNotification) {
43
+ ctx.logger.debug({ jid: from }, 'skipping session refresh during offline processing');
44
+ return { action: 'skipped_offline' };
45
+ }
46
+ try {
47
+ await ctx.assertSessions([from], true);
48
+ return { action: 'session_refreshed' };
49
+ }
50
+ catch (error) {
51
+ ctx.logger.warn({ error, jid: from }, 'failed to assert sessions after identity change');
52
+ return { action: 'session_refresh_failed', error };
53
+ }
54
+ }
@@ -0,0 +1,22 @@
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 './link-preview.js';
15
+ export * from './event-buffer.js';
16
+ export * from './process-message.js';
17
+ export * from './message-retry-manager.js';
18
+ export * from './browser-utils.js';
19
+ export * from './identity-change-handler.js';
20
+ export * from './messages-newsletter.js';
21
+ export * from './resolve-jid.js';
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./generics.js"), exports);
18
+ __exportStar(require("./audioToBuffer.js"), exports);
19
+ __exportStar(require("./streamToBuffer.js"), exports);
20
+ __exportStar(require("./decode-wa-message.js"), exports);
21
+ __exportStar(require("./messages.js"), exports);
22
+ __exportStar(require("./messages-media.js"), exports);
23
+ __exportStar(require("./messages-newsletter.js"), exports);
24
+ __exportStar(require("./validate-connection.js"), exports);
25
+ __exportStar(require("./crypto.js"), exports);
26
+ __exportStar(require("./signal.js"), exports);
27
+ __exportStar(require("./noise-handler.js"), exports);
28
+ __exportStar(require("./history.js"), exports);
29
+ __exportStar(require("./chat-utils.js"), exports);
30
+ __exportStar(require("./business.js"), exports);
31
+ __exportStar(require("./lt-hash.js"), exports);
32
+ __exportStar(require("./auth-utils.js"), exports);
33
+ __exportStar(require("./pre-key-manager.js"), exports);
34
+ __exportStar(require("./use-multi-file-auth-state.js"), exports);
35
+ __exportStar(require("./use-single-file-auth-state.js"), exports);
36
+ __exportStar(require("./use-mongo-file-auth-state.js"), exports);
37
+ __exportStar(require("./astrabail-event-stream.js"), exports);
38
+ __exportStar(require("./baileys-event-stream.js"), exports);
39
+ __exportStar(require("./link-preview.js"), exports);
40
+ __exportStar(require("./event-buffer.js"), exports);
41
+ __exportStar(require("./process-message.js"), exports);
42
+ __exportStar(require("./message-retry-manager.js"), exports);
43
+ __exportStar(require("./browser-utils.js"), exports);
44
+ __exportStar(require("./identity-change-handler.js"), exports);
45
+ __exportStar(require("./resolve-jid.js"), exports);
46
+ __exportStar(require("./reporting-utils.js"), exports);
47
+ __exportStar(require("./sync-action-utils.js"), exports);
48
+ __exportStar(require("./tc-token-utils.js"), exports);
@@ -0,0 +1,21 @@
1
+ import type { WAMediaUploadFunction, WAUrlInfo } from '../Types/index.js';
2
+ import type { ILogger } from './logger.js';
3
+ export type URLGenerationOptions = {
4
+ thumbnailWidth: number;
5
+ fetchOpts: {
6
+ /** Timeout in ms */
7
+ timeout: number;
8
+ proxyUrl?: string;
9
+ headers?: HeadersInit;
10
+ };
11
+ uploadImage?: WAMediaUploadFunction;
12
+ logger?: ILogger;
13
+ };
14
+ /**
15
+ * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
16
+ * Return undefined if the fetch failed or no URL was found
17
+ * @param text first matched URL in text
18
+ * @returns the URL info required to generate link preview
19
+ */
20
+ export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined>;
21
+ //# sourceMappingURL=link-preview.d.ts.map
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.getUrlInfo = void 0;
37
+ const messages_js_1 = require("./messages.js");
38
+ const messages_media_js_1 = require("./messages-media.js");
39
+ const THUMBNAIL_WIDTH_PX = 192;
40
+ /** Fetches an image and generates a thumbnail for it */
41
+ const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
42
+ const stream = await (0, messages_media_js_1.getHttpStream)(url, fetchOpts);
43
+ const result = await (0, messages_media_js_1.extractImageThumb)(stream, thumbnailWidth);
44
+ return result;
45
+ };
46
+ /**
47
+ * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
48
+ * Return undefined if the fetch failed or no URL was found
49
+ * @param text first matched URL in text
50
+ * @returns the URL info required to generate link preview
51
+ */
52
+ const getUrlInfo = async (text, opts = {
53
+ thumbnailWidth: THUMBNAIL_WIDTH_PX,
54
+ fetchOpts: { timeout: 3000 }
55
+ }) => {
56
+ try {
57
+ // retries
58
+ const retries = 0;
59
+ const maxRetry = 5;
60
+ const { getLinkPreview } = await Promise.resolve().then(() => __importStar(require('link-preview-js')));
61
+ let previewLink = text;
62
+ if (!text.startsWith('https://') && !text.startsWith('http://')) {
63
+ previewLink = 'https://' + previewLink;
64
+ }
65
+ const info = await getLinkPreview(previewLink, {
66
+ ...opts.fetchOpts,
67
+ followRedirects: 'follow',
68
+ handleRedirects: (baseURL, forwardedURL) => {
69
+ const urlObj = new URL(baseURL);
70
+ const forwardedURLObj = new URL(forwardedURL);
71
+ if (retries >= maxRetry) {
72
+ return false;
73
+ }
74
+ if (forwardedURLObj.hostname === urlObj.hostname ||
75
+ forwardedURLObj.hostname === 'www.' + urlObj.hostname ||
76
+ 'www.' + forwardedURLObj.hostname === urlObj.hostname) {
77
+ retries + 1;
78
+ return true;
79
+ }
80
+ else {
81
+ return false;
82
+ }
83
+ },
84
+ headers: opts.fetchOpts?.headers
85
+ });
86
+ if (info && 'title' in info && info.title) {
87
+ const [image] = info.images;
88
+ const urlInfo = {
89
+ 'canonical-url': info.url,
90
+ 'matched-text': text,
91
+ title: info.title,
92
+ description: info.description,
93
+ originalThumbnailUrl: image
94
+ };
95
+ if (opts.uploadImage) {
96
+ const { imageMessage } = await (0, messages_js_1.prepareWAMessageMedia)({ image: { url: image } }, {
97
+ upload: opts.uploadImage,
98
+ mediaTypeOverride: 'thumbnail-link',
99
+ options: opts.fetchOpts
100
+ });
101
+ urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined;
102
+ urlInfo.highQualityThumbnail = imageMessage || undefined;
103
+ }
104
+ else {
105
+ try {
106
+ urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined;
107
+ }
108
+ catch (error) {
109
+ opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail');
110
+ }
111
+ }
112
+ return urlInfo;
113
+ }
114
+ }
115
+ catch (error) {
116
+ if (!error.message.includes('receive a valid')) {
117
+ throw error;
118
+ }
119
+ }
120
+ };
121
+ exports.getUrlInfo = getUrlInfo;
@@ -0,0 +1,13 @@
1
+ import P from 'pino';
2
+ export interface ILogger {
3
+ level: string;
4
+ child(obj: Record<string, unknown>): ILogger;
5
+ trace(obj: unknown, msg?: string): void;
6
+ debug(obj: unknown, msg?: string): void;
7
+ info(obj: unknown, msg?: string): void;
8
+ warn(obj: unknown, msg?: string): void;
9
+ error(obj: unknown, msg?: string): void;
10
+ }
11
+ declare const _default: P.Logger<never, boolean>;
12
+ export default _default;
13
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1,7 @@
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 = (0, pino_1.default)({ timestamp: () => `,"time":"${new Date().toJSON()}"` });
@@ -0,0 +1,8 @@
1
+ import { LTHashAntiTampering } from './bridge-runtime.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
+ export declare const LT_HASH_ANTI_TAMPERING: LTHashAntiTampering;
8
+ //# sourceMappingURL=lt-hash.d.ts.map
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LT_HASH_ANTI_TAMPERING = void 0;
4
+ const bridge_runtime_js_1 = require("./bridge-runtime.js");
5
+ /**
6
+ * LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
7
+ * over a series of mutations. You can add/remove mutations and it'll return a hash equal to
8
+ * if the same series of mutations was made sequentially.
9
+ */
10
+ exports.LT_HASH_ANTI_TAMPERING = new bridge_runtime_js_1.LTHashAntiTampering();
@@ -0,0 +1,9 @@
1
+ export declare const makeMutex: () => {
2
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
3
+ };
4
+ export type Mutex = ReturnType<typeof makeMutex>;
5
+ export declare const makeKeyedMutex: () => {
6
+ mutex<T>(key: string, task: () => Promise<T> | T): Promise<T>;
7
+ };
8
+ export type KeyedMutex = ReturnType<typeof makeKeyedMutex>;
9
+ //# sourceMappingURL=make-mutex.d.ts.map
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeKeyedMutex = exports.makeMutex = void 0;
4
+ const async_mutex_1 = require("async-mutex");
5
+ const makeMutex = () => {
6
+ const mutex = new async_mutex_1.Mutex();
7
+ return {
8
+ mutex(code) {
9
+ return mutex.runExclusive(code);
10
+ }
11
+ };
12
+ };
13
+ exports.makeMutex = makeMutex;
14
+ const makeKeyedMutex = () => {
15
+ const map = new Map();
16
+ return {
17
+ async mutex(key, task) {
18
+ let entry = map.get(key);
19
+ if (!entry) {
20
+ entry = { mutex: new async_mutex_1.Mutex(), refCount: 0 };
21
+ map.set(key, entry);
22
+ }
23
+ entry.refCount++;
24
+ try {
25
+ return await entry.mutex.runExclusive(task);
26
+ }
27
+ finally {
28
+ entry.refCount--;
29
+ // only delete it if this is still the current entry
30
+ if (entry.refCount === 0 && map.get(key) === entry) {
31
+ map.delete(key);
32
+ }
33
+ }
34
+ }
35
+ };
36
+ };
37
+ exports.makeKeyedMutex = makeKeyedMutex;
@@ -0,0 +1,110 @@
1
+ import type { proto } from '../../WAProto/index.js';
2
+ import type { ILogger } from './logger.js';
3
+ export interface RecentMessageKey {
4
+ to: string;
5
+ id: string;
6
+ }
7
+ export interface RecentMessage {
8
+ message: proto.IMessage;
9
+ timestamp: number;
10
+ }
11
+ export interface SessionRecreateHistory {
12
+ [jid: string]: number;
13
+ }
14
+ export interface RetryCounter {
15
+ [messageId: string]: number;
16
+ }
17
+ export type PendingPhoneRequest = Record<string, ReturnType<typeof setTimeout>>;
18
+ export interface RetryStatistics {
19
+ totalRetries: number;
20
+ successfulRetries: number;
21
+ failedRetries: number;
22
+ mediaRetries: number;
23
+ sessionRecreations: number;
24
+ phoneRequests: number;
25
+ }
26
+ export declare enum RetryReason {
27
+ UnknownError = 0,
28
+ SignalErrorNoSession = 1,
29
+ SignalErrorInvalidKey = 2,
30
+ SignalErrorInvalidKeyId = 3,
31
+ /** MAC verification failed - most common cause of decryption failures */
32
+ SignalErrorInvalidMessage = 4,
33
+ SignalErrorInvalidSignature = 5,
34
+ SignalErrorFutureMessage = 6,
35
+ /** Explicit MAC failure - session is definitely out of sync */
36
+ SignalErrorBadMac = 7,
37
+ SignalErrorInvalidSession = 8,
38
+ SignalErrorInvalidMsgKey = 9,
39
+ BadBroadcastEphemeralSetting = 10,
40
+ UnknownCompanionNoPrekey = 11,
41
+ AdvFailure = 12,
42
+ StatusRevokeDelay = 13
43
+ }
44
+ export declare class MessageRetryManager {
45
+ private logger;
46
+ private recentMessagesMap;
47
+ private messageKeyIndex;
48
+ private sessionRecreateHistory;
49
+ private retryCounters;
50
+ private pendingPhoneRequests;
51
+ private readonly maxMsgRetryCount;
52
+ private statistics;
53
+ constructor(logger: ILogger, maxMsgRetryCount: number);
54
+ /**
55
+ * Add a recent message to the cache for retry handling
56
+ */
57
+ addRecentMessage(to: string, id: string, message: proto.IMessage): void;
58
+ /**
59
+ * Get a recent message from the cache
60
+ */
61
+ getRecentMessage(to: string, id: string): RecentMessage | undefined;
62
+ /**
63
+ * Check if a session should be recreated based on retry count, history, and error code.
64
+ * MAC errors (codes 4 and 7) trigger immediate session recreation regardless of timeout.
65
+ */
66
+ shouldRecreateSession(jid: string, hasSession: boolean, errorCode?: RetryReason): {
67
+ reason: string;
68
+ recreate: boolean;
69
+ };
70
+ /**
71
+ * Parse error code from retry receipt's retry node.
72
+ * Returns undefined if no error code is present.
73
+ */
74
+ parseRetryErrorCode(errorAttr: string | undefined): RetryReason | undefined;
75
+ /**
76
+ * Check if an error code indicates a MAC failure
77
+ */
78
+ isMacError(errorCode: RetryReason | undefined): boolean;
79
+ /**
80
+ * Increment retry counter for a message
81
+ */
82
+ incrementRetryCount(messageId: string): number;
83
+ /**
84
+ * Get retry count for a message
85
+ */
86
+ getRetryCount(messageId: string): number;
87
+ /**
88
+ * Check if message has exceeded maximum retry attempts
89
+ */
90
+ hasExceededMaxRetries(messageId: string): boolean;
91
+ /**
92
+ * Mark retry as successful
93
+ */
94
+ markRetrySuccess(messageId: string): void;
95
+ /**
96
+ * Mark retry as failed
97
+ */
98
+ markRetryFailed(messageId: string): void;
99
+ /**
100
+ * Schedule a phone request with delay
101
+ */
102
+ schedulePhoneRequest(messageId: string, callback: () => void, delay?: number): void;
103
+ /**
104
+ * Cancel pending phone request
105
+ */
106
+ cancelPendingPhoneRequest(messageId: string): void;
107
+ private keyToString;
108
+ private removeRecentMessage;
109
+ }
110
+ //# sourceMappingURL=message-retry-manager.d.ts.map