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.
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +5479 -0
- package/WAProto/fix-imports.js +73 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +89351 -0
- package/WAProto/p.html +1 -0
- package/engine-requirements.js +7 -0
- package/lib/Defaults/astrabail-version.json +8 -0
- package/lib/Defaults/index.d.ts +74 -0
- package/lib/Defaults/index.js +166 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/update-wa-version.js +75 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.js +66 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +85 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +29 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.js +44 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.js +87 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +29 -0
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.js +478 -0
- package/lib/Signal/lid-mapping.d.ts +19 -0
- package/lib/Signal/lid-mapping.js +274 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +18 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +14 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +60 -0
- package/lib/Socket/business.d.ts +202 -0
- package/lib/Socket/business.js +382 -0
- package/lib/Socket/chats.d.ts +111 -0
- package/lib/Socket/chats.js +1155 -0
- package/lib/Socket/communities.d.ts +258 -0
- package/lib/Socket/communities.js +438 -0
- package/lib/Socket/community.js +333 -0
- package/lib/Socket/groups.d.ts +150 -0
- package/lib/Socket/groups.js +470 -0
- package/lib/Socket/index.d.ts +245 -0
- package/lib/Socket/index.js +13 -0
- package/lib/Socket/messages-recv.d.ts +187 -0
- package/lib/Socket/messages-recv.js +1708 -0
- package/lib/Socket/messages-send.d.ts +183 -0
- package/lib/Socket/messages-send.js +1692 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.d.ts +160 -0
- package/lib/Socket/newsletter.js +293 -0
- package/lib/Socket/socket.d.ts +55 -0
- package/lib/Socket/socket.js +947 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.js +20 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.js +398 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +116 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +123 -0
- package/lib/Types/Chat.js +10 -0
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +237 -0
- package/lib/Types/Events.js +3 -0
- package/lib/Types/GroupMetadata.d.ts +67 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.d.ts +305 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/MexUpdates.js +11 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Newsletter.js +43 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.d.ts +76 -0
- package/lib/Types/Signal.js +3 -0
- package/lib/Types/Socket.d.ts +133 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/State.d.ts +39 -0
- package/lib/Types/State.js +14 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +3 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Types/index.js +42 -0
- package/lib/Utils/astrabail-event-stream.js +3 -0
- package/lib/Utils/audioToBuffer.js +31 -0
- package/lib/Utils/auth-utils.d.ts +19 -0
- package/lib/Utils/auth-utils.js +298 -0
- package/lib/Utils/baileys-event-stream.js +60 -0
- package/lib/Utils/bridge-runtime.d.ts +1 -0
- package/lib/Utils/bridge-runtime.js +14 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.js +44 -0
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.js +240 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +825 -0
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.js +168 -0
- package/lib/Utils/decode-wa-message.d.ts +48 -0
- package/lib/Utils/decode-wa-message.js +287 -0
- package/lib/Utils/event-buffer.d.ts +34 -0
- package/lib/Utils/event-buffer.js +580 -0
- package/lib/Utils/generics.d.ts +91 -0
- package/lib/Utils/generics.js +483 -0
- package/lib/Utils/history.d.ts +22 -0
- package/lib/Utils/history.js +137 -0
- package/lib/Utils/identity-change-handler.d.ts +37 -0
- package/lib/Utils/identity-change-handler.js +54 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.js +48 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +121 -0
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.js +10 -0
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.js +37 -0
- package/lib/Utils/message-retry-manager.d.ts +110 -0
- package/lib/Utils/message-retry-manager.js +226 -0
- package/lib/Utils/messages-media.d.ts +130 -0
- package/lib/Utils/messages-media.js +887 -0
- package/lib/Utils/messages-newsletter.d.ts +84 -0
- package/lib/Utils/messages-newsletter.js +295 -0
- package/lib/Utils/messages.d.ts +92 -0
- package/lib/Utils/messages.js +1752 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +204 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.js +112 -0
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.js +536 -0
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.js +262 -0
- package/lib/Utils/resolve-jid.d.ts +43 -0
- package/lib/Utils/resolve-jid.js +95 -0
- package/lib/Utils/rust-bridge-shim.d.ts +22 -0
- package/lib/Utils/rust-bridge-shim.js +70 -0
- package/lib/Utils/serial-task-queue.js +29 -0
- package/lib/Utils/signal.d.ts +34 -0
- package/lib/Utils/signal.js +170 -0
- package/lib/Utils/streamToBuffer.js +17 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.js +52 -0
- package/lib/Utils/tc-token-utils.d.ts +12 -0
- package/lib/Utils/tc-token-utils.js +20 -0
- package/lib/Utils/use-mongo-file-auth-state.js +71 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +124 -0
- package/lib/Utils/use-single-file-auth-state.js +73 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +206 -0
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +300 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +256 -0
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +138 -0
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +25 -0
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.js +115 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +36 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.js +22855 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +153 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +41 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +54 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +32 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.js +22 -0
- package/lib/WAUSync/USyncQuery.d.ts +29 -0
- package/lib/WAUSync/USyncQuery.js +97 -0
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +124 -0
- package/package.json +120 -0
- 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
|