hridoy-ultimate 8.0.2 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +68 -40
- package/LICENSE +23 -0
- package/MERGE_REPORT.md +54 -0
- package/README.md +158 -113
- package/THIRD_PARTY_NOTICES.md +36 -0
- package/docs/TEST_RESULTS.md +68 -0
- package/docs/UPSTREAM_API_DOCS.md +2712 -0
- package/func/checkUpdate.js +6 -0
- package/func/logAdapter.js +33 -0
- package/func/logger.js +48 -0
- package/index.d.ts +812 -0
- package/index.js +30 -824
- package/module/config.js +46 -0
- package/module/login.js +136 -0
- package/module/loginHelper.js +1413 -0
- package/module/options.js +55 -0
- package/package.json +75 -22
- package/scripts/run-tests.js +19 -0
- package/scripts/syntax-check.js +22 -0
- package/src/{addExternalModule.js → api/action/addExternalModule.js} +8 -8
- package/src/{changeAvatar.js → api/action/changeAvatar.js} +32 -33
- package/src/{changeBio.js → api/action/changeBio.js} +19 -22
- package/src/api/action/dismissScrapingWarning.js +50 -0
- package/src/api/action/enableAutoSaveAppState.js +73 -0
- package/src/{getCurrentUserID.js → api/action/getCurrentUserID.js} +1 -1
- package/src/api/action/handleFriendRequest.js +57 -0
- package/src/api/action/logout.js +95 -0
- package/src/api/action/refreshFb_dtsg.js +47 -0
- package/src/{setPostReaction.js → api/action/setPostReaction.js} +23 -31
- package/src/{unfriend.js → api/action/unfriend.js} +14 -14
- package/src/api/http/httpGet.js +46 -0
- package/src/api/http/httpPost.js +52 -0
- package/src/api/http/postFormData.js +47 -0
- package/src/api/messaging/addUserToGroup.js +68 -0
- package/src/api/messaging/changeAdminStatus.js +126 -0
- package/src/{changeArchivedStatus.js → api/messaging/changeArchivedStatus.js} +15 -17
- package/src/{changeBlockedStatus.js → api/messaging/changeBlockedStatus.js} +13 -16
- package/src/api/messaging/changeGroupImage.js +91 -0
- package/src/api/messaging/changeNickname.js +70 -0
- package/src/api/messaging/changeThreadColor.js +79 -0
- package/src/api/messaging/changeThreadEmoji.js +111 -0
- package/src/{createNewGroup.js → api/messaging/createNewGroup.js} +24 -26
- package/src/api/messaging/createPoll.js +46 -0
- package/src/api/messaging/createThemeAI.js +98 -0
- package/src/api/messaging/deleteMessage.js +136 -0
- package/src/{deleteThread.js → api/messaging/deleteThread.js} +14 -16
- package/src/api/messaging/editMessage.js +105 -0
- package/src/api/messaging/forwardAttachment.js +57 -0
- package/src/api/messaging/forwardMessage.js +134 -0
- package/src/{getEmojiUrl.js → api/messaging/getEmojiUrl.js} +2 -2
- package/src/{getFriendsList.js → api/messaging/getFriendsList.js} +16 -19
- package/src/{getMessage.js → api/messaging/getMessage.js} +160 -180
- package/src/api/messaging/getThemePictures.js +62 -0
- package/src/api/messaging/handleMessageRequest.js +65 -0
- package/src/api/messaging/markAsDelivered.js +69 -0
- package/src/api/messaging/markAsRead.js +110 -0
- package/src/api/messaging/markAsReadAll.js +56 -0
- package/src/api/messaging/markAsSeen.js +68 -0
- package/src/api/messaging/muteThread.js +50 -0
- package/src/api/messaging/pinMessage.js +115 -0
- package/src/api/messaging/removeUserFromGroup.js +62 -0
- package/src/{resolvePhotoUrl.js → api/messaging/resolvePhotoUrl.js} +11 -15
- package/src/api/messaging/scheduler.js +264 -0
- package/src/{searchForThread.js → api/messaging/searchForThread.js} +12 -12
- package/src/api/messaging/sendBroadcast.js +93 -0
- package/src/api/messaging/sendMessage.js +269 -0
- package/src/api/messaging/sendTypingIndicator.js +90 -0
- package/src/api/messaging/sessionGuard.js +130 -0
- package/src/api/messaging/setMessageReaction.js +114 -0
- package/src/api/messaging/setTitle.js +124 -0
- package/src/api/messaging/shareContact.js +98 -0
- package/src/{threadColors.js → api/messaging/threadColors.js} +2 -5
- package/src/api/messaging/unsendMessage.js +105 -0
- package/src/api/messaging/uploadAttachment.js +493 -0
- package/src/api/socket/OldMessage.js +199 -0
- package/src/api/socket/core/connectMqtt.js +304 -0
- package/src/api/socket/core/emitAuth.js +95 -0
- package/src/api/socket/core/getSeqID.js +331 -0
- package/src/api/socket/core/getTaskResponseData.js +25 -0
- package/src/api/socket/core/lifecycle.js +117 -0
- package/src/api/socket/core/parseDelta.js +387 -0
- package/src/api/socket/detail/buildStream.js +215 -0
- package/src/api/socket/detail/constants.js +28 -0
- package/src/api/socket/e2ee/crypto.js +173 -0
- package/src/api/socket/e2ee/index.js +977 -0
- package/src/api/socket/e2ee/localMediaServer.js +59 -0
- package/src/api/socket/e2ee/mediaDecode.js +155 -0
- package/src/api/socket/e2ee/native/NOTICE.md +29 -0
- package/{lib → src/api/socket/e2ee/native/lib}/index.mjs +109 -66
- package/src/api/socket/e2ee/native/nativeMediaBridge.js +273 -0
- package/src/api/socket/e2ee/proto/ArmadilloApplication.proto +281 -0
- package/src/api/socket/e2ee/proto/ArmadilloICDC.proto +14 -0
- package/src/api/socket/e2ee/proto/ConsumerApplication.proto +232 -0
- package/src/api/socket/e2ee/proto/MessageApplication.proto +82 -0
- package/src/api/socket/e2ee/proto/MessageTransport.proto +77 -0
- package/src/api/socket/e2ee/proto/WACommon.proto +66 -0
- package/src/api/socket/e2ee/proto/WAMediaTransport.proto +176 -0
- package/src/api/socket/e2ee/proto/proto-writer.ts +76 -0
- package/src/api/socket/e2ee/protocol.js +196 -0
- package/src/api/socket/e2ee/ratchet.js +219 -0
- package/src/api/socket/e2ee/store.js +182 -0
- package/src/api/socket/e2ee/vendor/fme/dist/index.cjs +6477 -0
- package/src/api/socket/e2ee/vendor/fme/proto/ArmadilloApplication.proto +281 -0
- package/src/api/socket/e2ee/vendor/fme/proto/ArmadilloICDC.proto +14 -0
- package/src/api/socket/e2ee/vendor/fme/proto/ConsumerApplication.proto +232 -0
- package/src/api/socket/e2ee/vendor/fme/proto/MessageApplication.proto +82 -0
- package/src/api/socket/e2ee/vendor/fme/proto/MessageTransport.proto +77 -0
- package/src/api/socket/e2ee/vendor/fme/proto/WACommon.proto +66 -0
- package/src/api/socket/e2ee/vendor/fme/proto/WAMediaTransport.proto +176 -0
- package/src/api/socket/listenE2EE.js +87 -0
- package/src/api/socket/listenMqtt.js +499 -0
- package/src/api/socket/middleware/index.js +216 -0
- package/src/api/socket/sendMessage.js +331 -0
- package/src/api/socket/sendMessageMqtt.js +69 -0
- package/src/{getThreadHistory.js → api/threads/getThreadHistory.js} +114 -132
- package/src/api/threads/getThreadInfo.js +329 -0
- package/src/api/threads/getThreadList.js +293 -0
- package/src/api/threads/getThreadPictures.js +78 -0
- package/src/{getUserID.js → api/users/getUserID.js} +22 -18
- package/src/api/users/getUserInfo.js +402 -0
- package/src/api/users/getUserInfoV2.js +134 -0
- package/src/app/MessengerBot.js +209 -0
- package/src/app/MessengerContext.js +32 -0
- package/src/app/createFcaClient.js +136 -0
- package/src/app/threadInfoRealtimeSync.js +284 -0
- package/src/core/sendReqMqtt.js +96 -0
- package/src/database/helpers.js +53 -0
- package/src/database/models/index.js +88 -0
- package/src/database/models/thread.js +50 -0
- package/src/database/models/user.js +46 -0
- package/src/database/threadData.js +94 -0
- package/src/database/userData.js +98 -0
- package/src/remote/remoteClient.js +123 -0
- package/src/utils/antiSuspension.js +219 -0
- package/src/utils/broadcast.js +51 -0
- package/src/utils/client.js +10 -0
- package/src/utils/constants.js +23 -0
- package/src/utils/cookies.js +85 -0
- package/src/utils/fingerprint.js +110 -0
- package/src/utils/format/attachment.js +357 -0
- package/src/utils/format/cookie.js +9 -0
- package/src/utils/format/date.js +50 -0
- package/src/utils/format/decode.js +44 -0
- package/src/utils/format/delta.js +195 -0
- package/src/utils/format/ids.js +64 -0
- package/src/utils/format/index.js +64 -0
- package/src/utils/format/message.js +88 -0
- package/src/utils/format/presence.js +132 -0
- package/src/utils/format/readTyp.js +44 -0
- package/src/utils/format/thread.js +42 -0
- package/src/utils/format/utils.js +141 -0
- package/src/utils/headers.js +125 -0
- package/src/utils/humanizer.js +256 -0
- package/src/utils/loginParser/autoLogin.js +125 -0
- package/src/utils/loginParser/extractDtsg.js +44 -0
- package/src/utils/loginParser/helpers.js +43 -0
- package/src/utils/loginParser/index.js +10 -0
- package/src/utils/loginParser/parseAndCheckLogin.js +241 -0
- package/src/utils/loginParser/textUtils.js +28 -0
- package/src/utils/nexca-logger.js +144 -0
- package/src/utils/nexca-utils.js +687 -0
- package/src/utils/request/client.js +26 -0
- package/src/utils/request/config.js +23 -0
- package/src/utils/request/defaults.js +46 -0
- package/src/utils/request/helpers.js +46 -0
- package/src/utils/request/index.js +17 -0
- package/src/utils/request/methods.js +163 -0
- package/src/utils/request/proxy.js +21 -0
- package/src/utils/request/retry.js +77 -0
- package/src/utils/request/sanitize.js +49 -0
- package/src/utils/typingIndicator.js +202 -0
- package/test/helpers/stub-modules.js +122 -0
- package/test/integration/logout.test.js +69 -0
- package/test/integration/mqtt-lifecycle.test.js +195 -0
- package/test/integration/package.test.js +116 -0
- package/test/integration/typing-wiring.test.js +71 -0
- package/test/unit/fingerprint.test.js +19 -0
- package/test/unit/humanizer.test.js +32 -0
- package/test/unit/lifecycle.test.js +92 -0
- package/test/unit/parsers.test.js +43 -0
- package/test/unit/typing.test.js +136 -0
- package/ANALYSIS.md +0 -31
- package/AUDIT_REPORT.md +0 -57
- package/advancedSystem.js +0 -95
- package/checkUpdate.js +0 -47
- package/config.json +0 -51
- package/e2ee.js +0 -738
- package/examples/basic-bot.js +0 -122
- package/examples/e2ee-bot.js +0 -141
- package/fca-config.example.json +0 -73
- package/scripts/check.js +0 -38
- package/src/OldMessage.js +0 -357
- package/src/addUserToGroup.js +0 -117
- package/src/changeAdminStatus.js +0 -105
- package/src/changeAvatarV2.js +0 -86
- package/src/changeAvt.js +0 -85
- package/src/changeBlockedStatusMqtt.js +0 -75
- package/src/changeCover.js +0 -73
- package/src/changeGroupImage.js +0 -137
- package/src/changeName.js +0 -79
- package/src/changeNickname.js +0 -61
- package/src/changeThreadColor.js +0 -67
- package/src/changeThreadEmoji.js +0 -57
- package/src/changeUsername.js +0 -59
- package/src/createCommentPost.js +0 -232
- package/src/createPoll.js +0 -73
- package/src/createPost.js +0 -276
- package/src/deleteMessage.js +0 -58
- package/src/editMessage.js +0 -76
- package/src/editMessageOld.js +0 -62
- package/src/follow.js +0 -74
- package/src/forwardAttachment.js +0 -62
- package/src/friendList.js +0 -104
- package/src/getAccess.js +0 -112
- package/src/getAvatarUser.js +0 -78
- package/src/getBotInitialData.js +0 -42
- package/src/getCtx.js +0 -5
- package/src/getOptions.js +0 -5
- package/src/getRegion.js +0 -7
- package/src/getThreadHistoryDeprecated.js +0 -71
- package/src/getThreadInfo.js +0 -232
- package/src/getThreadInfoDeprecated.js +0 -56
- package/src/getThreadList.js +0 -213
- package/src/getThreadListDeprecated.js +0 -46
- package/src/getThreadPictures.js +0 -59
- package/src/getThreadTheme.js +0 -81
- package/src/getUID.js +0 -119
- package/src/getUserInfo.js +0 -66
- package/src/handleFriendRequest.js +0 -46
- package/src/handleMessageRequest.js +0 -47
- package/src/httpGet.js +0 -49
- package/src/httpPost.js +0 -48
- package/src/httpPostFormData.js +0 -70
- package/src/listenMqtt.js +0 -1081
- package/src/listenNotification.js +0 -85
- package/src/logout.js +0 -18
- package/src/markAsDelivered.js +0 -47
- package/src/markAsRead.js +0 -72
- package/src/markAsReadAll.js +0 -40
- package/src/markAsSeen.js +0 -48
- package/src/metaTheme.js +0 -189
- package/src/muteThread.js +0 -45
- package/src/note.js +0 -228
- package/src/pinMessage.js +0 -54
- package/src/refreshFb_dtsg.js +0 -49
- package/src/removeSuspiciousAccount.js +0 -78
- package/src/removeUserFromGroup.js +0 -81
- package/src/reply.js +0 -442
- package/src/searchFriends.js +0 -140
- package/src/searchStickers.js +0 -53
- package/src/send.js +0 -46
- package/src/sendButtons.js +0 -163
- package/src/sendComment.js +0 -159
- package/src/sendFriendRequest.js +0 -112
- package/src/sendMessage.js +0 -441
- package/src/sendMessageMqtt.js +0 -323
- package/src/sendTypingIndicator.js +0 -68
- package/src/sendTypingIndicatorV2.js +0 -22
- package/src/setActiveStatus.js +0 -92
- package/src/setMessageReaction.js +0 -150
- package/src/setMessageReactionMqtt.js +0 -104
- package/src/setMessageReactionSafe.js +0 -44
- package/src/setProfileGuard.js +0 -44
- package/src/setProfileLock.js +0 -97
- package/src/setStoryReaction.js +0 -133
- package/src/setStorySeen.js +0 -108
- package/src/setThreadTheme.js +0 -102
- package/src/setTitle.js +0 -92
- package/src/shareContact.js +0 -110
- package/src/shareLink.js +0 -59
- package/src/stopListenMqtt.js +0 -60
- package/src/storyManager.js +0 -357
- package/src/suggestFriend.js +0 -132
- package/src/unsendMessage.js +0 -68
- package/src/uploadAttachment.js +0 -115
- package/test/fixes-1_2_4.test.js +0 -118
- package/test/mqtt-stop.test.js +0 -32
- package/test/reaction-mqtt.test.js +0 -57
- package/utils.js +0 -3056
- /package/{build → src/api/socket/e2ee/native/build}/messagix.dll +0 -0
- /package/{build → src/api/socket/e2ee/native/build}/messagix.so +0 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const test = require("node:test");
|
|
3
|
+
const assert = require("node:assert/strict");
|
|
4
|
+
const EventEmitter = require("events");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const root = process.env.HRIDOY_TEST_ROOT || path.join(__dirname, "..", "..");
|
|
7
|
+
const L = require(path.join(root, "src/api/socket/core/lifecycle"));
|
|
8
|
+
|
|
9
|
+
test("computeBackoff grows exponentially, is bounded and never negative", () => {
|
|
10
|
+
const rand = () => 0.5; // zero jitter offset
|
|
11
|
+
const seq = [0, 1, 2, 3, 4, 5, 6, 7, 8, 20, 1000].map(a => L.computeBackoff(a, { baseMs: 1000, maxMs: 60000, jitter: 0.3, random: rand }));
|
|
12
|
+
assert.deepEqual(seq.slice(0, 7), [1000, 2000, 4000, 8000, 16000, 32000, 60000]);
|
|
13
|
+
for (const v of seq) { assert.ok(v >= 0 && v <= 60000, `out of bounds: ${v}`); }
|
|
14
|
+
assert.equal(seq[seq.length - 1], 60000);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("computeBackoff jitter stays within +/- jitter and clamps to max", () => {
|
|
18
|
+
const lo = L.computeBackoff(2, { baseMs: 1000, maxMs: 1e9, jitter: 0.3, random: () => 0 });
|
|
19
|
+
const hi = L.computeBackoff(2, { baseMs: 1000, maxMs: 1e9, jitter: 0.3, random: () => 1 });
|
|
20
|
+
assert.equal(lo, 2800); assert.equal(hi, 5200);
|
|
21
|
+
assert.equal(L.computeBackoff(10, { baseMs: 1000, maxMs: 5000, jitter: 1, random: () => 1 }), 5000);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("computeBackoff tolerates garbage input", () => {
|
|
25
|
+
for (const bad of [undefined, null, NaN, -5, "x"]) {
|
|
26
|
+
const v = L.computeBackoff(bad, { baseMs: bad, maxMs: bad, jitter: bad });
|
|
27
|
+
assert.ok(Number.isFinite(v) && v >= 0);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("scheduleReconnect: single timer, debounce, stop, exhaustion", async (t) => {
|
|
32
|
+
t.mock.timers.enable({ apis: ["setTimeout"] });
|
|
33
|
+
const ctx = { _mqttOpt: { reconnectDelayMs: 100, maxReconnectAttempts: 2, reconnectJitter: 0 } };
|
|
34
|
+
let fired = 0;
|
|
35
|
+
const fn = () => { fired++; };
|
|
36
|
+
assert.equal(L.scheduleReconnect(ctx, null, fn, "a"), "scheduled");
|
|
37
|
+
assert.equal(L.scheduleReconnect(ctx, null, fn, "b"), "debounced");
|
|
38
|
+
t.mock.timers.tick(100);
|
|
39
|
+
assert.equal(fired, 1);
|
|
40
|
+
assert.equal(ctx._reconnectTimer, null);
|
|
41
|
+
assert.equal(L.scheduleReconnect(ctx, null, fn, "c"), "scheduled"); // attempt 2 -> delay 200
|
|
42
|
+
t.mock.timers.tick(200);
|
|
43
|
+
assert.equal(fired, 2);
|
|
44
|
+
assert.equal(L.scheduleReconnect(ctx, null, fn, "d"), "exhausted");
|
|
45
|
+
ctx._stopped = true;
|
|
46
|
+
assert.equal(L.scheduleReconnect(ctx, null, fn, "e"), "stopped");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("scheduleReconnect: a timer that fires after stop does nothing (race regression)", (t) => {
|
|
50
|
+
t.mock.timers.enable({ apis: ["setTimeout"] });
|
|
51
|
+
const ctx = { _mqttOpt: { reconnectDelayMs: 100, reconnectJitter: 0 } };
|
|
52
|
+
let fired = 0;
|
|
53
|
+
L.scheduleReconnect(ctx, null, () => fired++, "x");
|
|
54
|
+
ctx._stopped = true; // stop WITHOUT clearing the timer, e.g. a path that forgot to
|
|
55
|
+
t.mock.timers.tick(10000);
|
|
56
|
+
assert.equal(fired, 0);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("maxReconnectAttempts: 0 means unlimited only when explicitly set", () => {
|
|
60
|
+
const ctx = { _reconnectAttempt: 9999, _mqttOpt: { maxReconnectAttempts: 0 } };
|
|
61
|
+
assert.equal(L.scheduleReconnect(ctx, null, () => {}, "u"), "scheduled");
|
|
62
|
+
clearTimeout(ctx._reconnectTimer);
|
|
63
|
+
const ctx2 = { _reconnectAttempt: 10, _mqttOpt: {} };
|
|
64
|
+
assert.equal(L.scheduleReconnect(ctx2, null, () => {}, "default"), "exhausted"); // default cap = 10
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("clearListenerTimers is idempotent and clears every owned timer", () => {
|
|
68
|
+
const ctx = {
|
|
69
|
+
_autoCycleTimer: setInterval(() => {}, 1e6), _heartbeatInterval: setInterval(() => {}, 1e6),
|
|
70
|
+
_sessionKeeperInterval: setTimeout(() => {}, 1e6), _rTimeout: setTimeout(() => {}, 1e6),
|
|
71
|
+
_reconnectTimer: setTimeout(() => {}, 1e6), _dtsgRefreshInterval: setInterval(() => {}, 1e6)
|
|
72
|
+
};
|
|
73
|
+
L.clearListenerTimers(ctx, false);
|
|
74
|
+
assert.equal(ctx._autoCycleTimer, null); assert.equal(ctx._heartbeatInterval, null);
|
|
75
|
+
assert.equal(ctx._sessionKeeperInterval, null); assert.equal(ctx._rTimeout, null); assert.equal(ctx._reconnectTimer, null);
|
|
76
|
+
assert.notEqual(ctx._dtsgRefreshInterval, null, "session timer kept unless includeSession");
|
|
77
|
+
L.clearListenerTimers(ctx, true);
|
|
78
|
+
assert.equal(ctx._dtsgRefreshInterval, null);
|
|
79
|
+
assert.doesNotThrow(() => L.clearListenerTimers(ctx, true));
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("detachClient: a late 'error' after detach must not throw", () => {
|
|
83
|
+
const c = new EventEmitter();
|
|
84
|
+
c.on("error", () => {});
|
|
85
|
+
L.detachClient(c);
|
|
86
|
+
assert.equal(c.listenerCount("message"), 0);
|
|
87
|
+
assert.doesNotThrow(() => c.emit("error", new Error("late socket error")));
|
|
88
|
+
assert.doesNotThrow(() => L.detachClient(null));
|
|
89
|
+
// contrast: plain removeAllListeners (the old behaviour) DOES throw
|
|
90
|
+
const d = new EventEmitter(); d.removeAllListeners();
|
|
91
|
+
assert.throws(() => d.emit("error", new Error("boom")));
|
|
92
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const test = require("node:test");
|
|
3
|
+
const assert = require("node:assert/strict");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const root = process.env.HRIDOY_TEST_ROOT || path.join(__dirname, "..", "..");
|
|
6
|
+
const { extractDtsg } = require(path.join(root, "src/utils/loginParser/extractDtsg"));
|
|
7
|
+
const fp = require(path.join(root, "src/utils/fingerprint"));
|
|
8
|
+
|
|
9
|
+
test("extractDtsg handles each supported markup shape", () => {
|
|
10
|
+
const cases = [
|
|
11
|
+
['<script>["DTSGInitialData",[],{"token":"TOK_A"}]</script>', "TOK_A"],
|
|
12
|
+
['x["DTSGInitData",[],{"token":"TOK_B","async_get_token":"zz"}]', "TOK_B"],
|
|
13
|
+
['{"dtsg":{"token":"TOK_C"}}', "TOK_C"],
|
|
14
|
+
['{"async_get_token":"TOK_D"}', "TOK_D"],
|
|
15
|
+
['<input name="fb_dtsg" value="TOK_E">', "TOK_E"]
|
|
16
|
+
];
|
|
17
|
+
for (const [html, want] of cases) assert.equal(extractDtsg(html).fb_dtsg, want, html);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("extractDtsg: jazoest forms, empty and non-string input", () => {
|
|
21
|
+
assert.equal(extractDtsg('<input name="jazoest" value="2987">').jazoest, "2987");
|
|
22
|
+
assert.equal(extractDtsg("a?jazoest=2123&b").jazoest, "2123");
|
|
23
|
+
assert.deepEqual(extractDtsg(""), { fb_dtsg: null, jazoest: null });
|
|
24
|
+
assert.deepEqual(extractDtsg(null), { fb_dtsg: null, jazoest: null });
|
|
25
|
+
assert.deepEqual(extractDtsg("<html>nothing here</html>"), { fb_dtsg: null, jazoest: null });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("fingerprint: default UA and client hints are mutually consistent", () => {
|
|
29
|
+
const ua = fp.getDefaultUserAgent();
|
|
30
|
+
assert.match(ua, /^Mozilla\/5\.0 /);
|
|
31
|
+
const h = fp.clientHintsFromUA(ua);
|
|
32
|
+
assert.equal(h["sec-ch-ua-mobile"], /Mobile|Android|iPhone/.test(ua) ? "?1" : "?0");
|
|
33
|
+
const m = ua.match(/Chrome\/(\d+)/);
|
|
34
|
+
if (m) assert.ok(h["sec-ch-ua"].includes(`v="${m[1]}"`), "hint major must match UA major");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("fingerprint: Android UA yields mobile Android hints (no desktop contradiction)", () => {
|
|
38
|
+
const ua = "Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.0.0 Mobile Safari/537.36";
|
|
39
|
+
const h = fp.clientHintsFromUA(ua);
|
|
40
|
+
assert.equal(h["sec-ch-ua-mobile"], "?1");
|
|
41
|
+
assert.equal(h["sec-ch-ua-platform"], '"Android"');
|
|
42
|
+
assert.equal(h["sec-ch-ua-arch"], undefined);
|
|
43
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const test = require("node:test");
|
|
3
|
+
const assert = require("node:assert/strict");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const root = process.env.HRIDOY_TEST_ROOT || path.join(__dirname, "..", "..");
|
|
6
|
+
const { TypingIndicator, wrapSendMessage, normalizeOptions } = require(path.join(root, "src/utils/typingIndicator"));
|
|
7
|
+
|
|
8
|
+
function fakeApi() {
|
|
9
|
+
const calls = [];
|
|
10
|
+
return {
|
|
11
|
+
calls,
|
|
12
|
+
sendTypingIndicator(threadID, state, opts) { calls.push([threadID, state, opts]); return Promise.resolve(); },
|
|
13
|
+
sendMessage(msg, threadID) { return Promise.resolve({ messageID: "m1", threadID }); }
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const cmd = (over) => Object.assign({ type: "message", threadID: "t1", senderID: "u1", body: "/help", isGroup: true }, over);
|
|
17
|
+
|
|
18
|
+
test("typing: command-like message starts typing; plain chat / own messages / non-message events do not", () => {
|
|
19
|
+
const api = fakeApi();
|
|
20
|
+
const t = new TypingIndicator(api, { userID: "bot" }, undefined);
|
|
21
|
+
assert.equal(t.wants(cmd()), true);
|
|
22
|
+
assert.equal(t.wants(cmd({ body: "hello there" })), false);
|
|
23
|
+
assert.equal(t.wants(cmd({ senderID: "bot" })), false);
|
|
24
|
+
assert.equal(t.wants(cmd({ type: "typ" })), false);
|
|
25
|
+
assert.equal(t.wants(cmd({ body: " " })), false);
|
|
26
|
+
t.stopAll();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("typing: GoatBot prefix and extra prefixes count as commands; onlyCommands:false types for any text", () => {
|
|
30
|
+
global.GoatBot = { config: { prefix: "+" } };
|
|
31
|
+
try {
|
|
32
|
+
const t = new TypingIndicator(fakeApi(), {}, { commands: ["#"] });
|
|
33
|
+
assert.equal(t.wants(cmd({ body: "+ping" })), true);
|
|
34
|
+
assert.equal(t.wants(cmd({ body: "#x" })), true);
|
|
35
|
+
const all = new TypingIndicator(fakeApi(), {}, { onlyCommands: false });
|
|
36
|
+
assert.equal(all.wants(cmd({ body: "just chatting" })), true);
|
|
37
|
+
} finally { delete global.GoatBot; }
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("typing: middleware calls next() synchronously (zero added latency) and then starts typing", () => {
|
|
41
|
+
const api = fakeApi();
|
|
42
|
+
const t = new TypingIndicator(api, {}, undefined);
|
|
43
|
+
const order = [];
|
|
44
|
+
const origStart = t.start.bind(t);
|
|
45
|
+
t.start = (tid) => { order.push("start"); return origStart(tid); };
|
|
46
|
+
t.middleware()(cmd(), () => order.push("next"));
|
|
47
|
+
assert.deepEqual(order, ["next", "start"]);
|
|
48
|
+
assert.equal(api.calls.length, 1);
|
|
49
|
+
assert.deepEqual(api.calls[0].slice(0, 2), ["t1", true]);
|
|
50
|
+
assert.equal(api.calls[0][2].autoStop, false);
|
|
51
|
+
t.stopAll();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("typing: sending a reply clears typing after the send resolves", async () => {
|
|
55
|
+
const api = fakeApi();
|
|
56
|
+
const t = new TypingIndicator(api, {}, undefined);
|
|
57
|
+
assert.equal(wrapSendMessage(api, t), true);
|
|
58
|
+
assert.equal(wrapSendMessage(api, t), false, "wrapping is idempotent");
|
|
59
|
+
t.start("t1");
|
|
60
|
+
const res = await api.sendMessage("hi", "t1");
|
|
61
|
+
assert.equal(res.messageID, "m1", "result passes through unchanged");
|
|
62
|
+
await new Promise((r) => setImmediate(r));
|
|
63
|
+
assert.equal(t.isTyping("t1"), false);
|
|
64
|
+
assert.deepEqual(api.calls.map((c) => c[1]), [true, false]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("typing: safety timeout stops a typing indicator that never got a reply", (ctx) => {
|
|
68
|
+
ctx.mock.timers.enable({ apis: ["setTimeout", "Date"], now: 10_000 });
|
|
69
|
+
const api = fakeApi();
|
|
70
|
+
const t = new TypingIndicator(api, {}, { maxMs: 3000 });
|
|
71
|
+
t.start("t1");
|
|
72
|
+
assert.equal(t.isTyping("t1"), true);
|
|
73
|
+
ctx.mock.timers.tick(2999);
|
|
74
|
+
assert.equal(t.isTyping("t1"), true);
|
|
75
|
+
ctx.mock.timers.tick(2);
|
|
76
|
+
assert.equal(t.isTyping("t1"), false);
|
|
77
|
+
assert.deepEqual(api.calls.map((c) => c[1]), [true, false]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("typing: repeated starts inside minGapMs do not re-publish; after the gap they do", (ctx) => {
|
|
81
|
+
ctx.mock.timers.enable({ apis: ["setTimeout", "Date"], now: 50_000 });
|
|
82
|
+
const api = fakeApi();
|
|
83
|
+
const t = new TypingIndicator(api, {}, { minGapMs: 1500, maxMs: 8000 });
|
|
84
|
+
assert.equal(t.start("t1"), true);
|
|
85
|
+
ctx.mock.timers.tick(500);
|
|
86
|
+
assert.equal(t.start("t1"), false);
|
|
87
|
+
ctx.mock.timers.tick(1500);
|
|
88
|
+
assert.equal(t.start("t1"), true);
|
|
89
|
+
assert.equal(api.calls.filter((c) => c[1] === true).length, 2);
|
|
90
|
+
t.stopAll();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("typing: disabled by option false, and by GoatBot enableTypingIndicator:false unless explicitly overridden", () => {
|
|
94
|
+
assert.equal(normalizeOptions(false).enabled, false);
|
|
95
|
+
assert.equal(normalizeOptions(undefined).enabled, true, "default is ON");
|
|
96
|
+
global.GoatBot = { config: { enableTypingIndicator: false } };
|
|
97
|
+
try {
|
|
98
|
+
assert.equal(normalizeOptions(undefined).enabled, false);
|
|
99
|
+
assert.equal(normalizeOptions(true).enabled, true, "explicit option wins");
|
|
100
|
+
} finally { delete global.GoatBot; }
|
|
101
|
+
const api = fakeApi();
|
|
102
|
+
const t = new TypingIndicator(api, {}, false);
|
|
103
|
+
assert.equal(t.start("t1"), false);
|
|
104
|
+
assert.equal(api.calls.length, 0);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("typing: configure(false) clears active timers; stopAll is idempotent and publishes nothing", () => {
|
|
108
|
+
const api = fakeApi();
|
|
109
|
+
const t = new TypingIndicator(api, {}, undefined);
|
|
110
|
+
t.start("a"); t.start("b");
|
|
111
|
+
assert.equal(api.calls.length, 2);
|
|
112
|
+
t.configure(false);
|
|
113
|
+
t.stopAll();
|
|
114
|
+
assert.equal(t.isTyping("a") || t.isTyping("b"), false);
|
|
115
|
+
assert.equal(api.calls.length, 2, "no 'typing off' sent when tearing down");
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("typing: a throwing / rejecting sendTypingIndicator never breaks the bot", async () => {
|
|
119
|
+
const bad = { sendTypingIndicator() { throw new Error("boom"); } };
|
|
120
|
+
const rej = { sendTypingIndicator() { return Promise.reject(new Error("nope")); } };
|
|
121
|
+
const t1 = new TypingIndicator(bad, {}, undefined);
|
|
122
|
+
const t2 = new TypingIndicator(rej, {}, undefined);
|
|
123
|
+
assert.doesNotThrow(() => t1.middleware()(cmd(), () => {}));
|
|
124
|
+
assert.doesNotThrow(() => t2.middleware()(cmd(), () => {}));
|
|
125
|
+
await new Promise((r) => setImmediate(r));
|
|
126
|
+
t1.stopAll(); t2.stopAll();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("typing: withTyping shows typing around fn and clears it even when fn throws", async () => {
|
|
130
|
+
const api = fakeApi();
|
|
131
|
+
const t = new TypingIndicator(api, {}, undefined);
|
|
132
|
+
assert.equal(await t.withTyping("t1", async () => 42), 42);
|
|
133
|
+
await assert.rejects(() => t.withTyping("t2", async () => { throw new Error("x"); }), /x/);
|
|
134
|
+
assert.equal(t.isTyping("t1") || t.isTyping("t2"), false);
|
|
135
|
+
assert.deepEqual(api.calls.map((c) => c[1]), [true, false, true, false]);
|
|
136
|
+
});
|
package/ANALYSIS.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# Analysis of the packages reviewed for toru-fca v1.2.1
|
|
2
|
-
|
|
3
|
-
## Lineages
|
|
4
|
-
| Group | Packages | Notes |
|
|
5
|
-
|---|---|---|
|
|
6
|
-
| A (toru line) | HRIDOY-FCA 2.0.0, ST-FCA 1.2.29, toru-fca 1.1.0 / 1.2.0 | ST ≈ HRIDOY (only index/config/checkUpdate differ). toru 1.2.0 rewrote listenMqtt, refreshFb_dtsg, logout, sendMessage, stopListenMqtt, sendTypingIndicator, index. **Used as base.** |
|
|
7
|
-
| B (eryxenx line) | @eryxenx/fca 1.0.0 / 1.0.4 / 1.1.9, fca-eryxenx-merged, fca-abalcdiokay | ~75% identical files. TypeScript-free but different architecture (src/api/*, E2EE via Signal/koffi). |
|
|
8
|
-
| C (native line) | fca-native 5.0.0, Metachat 1.2.2 | Nearly the same code; adds ErrorHandler, SessionRecovery, rate limiter, etc. |
|
|
9
|
-
| D | shadowx-fca 10.8.0 | B-like plus extra helpers (unsendOnReaction, listenSpeed, reaction v2...). |
|
|
10
|
-
| E | xtreme-fca 1.0.2 | Single bundled dist (TS source not included). No anti-logout, no E2EE. |
|
|
11
|
-
|
|
12
|
-
## Security findings (NOT merged)
|
|
13
|
-
- **Third-party login API:** group B (`module/loginHelper.js`, default `apiServer: https://minhdong.site`) and the fca-native example config (`https://donixdev.com`) can POST **email, password and the 2FA secret** to that server (`loginViaAPI` / `tokensViaAPI`). It only runs when `autoLogin:true`, but it is a credential-leak risk. Not included. toru-fca logs in only directly to facebook.com.
|
|
14
|
-
- **ST-FCA / HRIDOY `checkUpdate.js`** runs `npm install` automatically. Not included (toru's version only prints a notice).
|
|
15
|
-
- **remoteClient.js** (group B) opens a WebSocket to an arbitrary configured URL and accepts remote commands. Opt-in, but not included.
|
|
16
|
-
- **fca-abalcdiokay and fca-eryxenx-merged ship `Fca_Database/database.sqlite` containing `app_state_backups` rows** — most likely a saved Facebook session (cookies). I did not read it. If it is your account, treat it as exposed and log that session out / change the password. It is NOT in toru-fca.
|
|
17
|
-
- ST/HRIDOY `getUID` uses id.traodoisub.com / api.findids.net (username → uid). Present in toru base already; sends only a public username/URL.
|
|
18
|
-
|
|
19
|
-
## Ideas ported into 1.2.1
|
|
20
|
-
- shadowx `setMessageReactionv2` → `setMessageReactionSafe` (MQTT first, HTTP retry fallback).
|
|
21
|
-
- Stale-MQTT-client guard (eryxenx `isActiveClient` idea) → `ctx.mqttClient !== mqttClient` guards.
|
|
22
|
-
- Reconnect backoff + old-client teardown (eryxenx/native CriticalBugFixes idea).
|
|
23
|
-
|
|
24
|
-
## Not ported (and why)
|
|
25
|
-
- E2EE native binaries (messagix .so/.dll, ~17 MB each) — platform-specific, unverified; toru keeps its optional bridge, off by default.
|
|
26
|
-
- fca-native resilience classes (ConnectionPool, RateLimit, Monitoring...) — large, overlapping with what toru already has; would add risk.
|
|
27
|
-
- Theme/AI-theme, broadcast, scheduler, spy, bypassScrap modules — not needed for your goals; "spy/bypassScrap" are scraping-oriented.
|
|
28
|
-
- xtreme — compiled bundle only, cannot be reviewed line by line.
|
|
29
|
-
|
|
30
|
-
## Limits of this review
|
|
31
|
-
No network, no real Facebook cookie: nothing was run against Facebook. Code was syntax-checked and key functions stub-tested.
|
package/AUDIT_REPORT.md
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
# TORU-FCA 1.2.4 — Defect Fix Addendum
|
|
2
|
-
|
|
3
|
-
Found by a static review of the 1.2.3 archive (syntax check, require-resolution, TypeScript `checkJs` undefined-name scan, manual reading) and fixed in 1.2.4:
|
|
4
|
-
|
|
5
|
-
| # | File | Defect | Status |
|
|
6
|
-
|---|---|---|---|
|
|
7
|
-
| 1 | src/listenMqtt.js | `getSeqID` not in scope inside `scheduleReconnect` -> ReferenceError, auto-reconnect dead | Fixed + regression test |
|
|
8
|
-
| 2 | src/changeCover.js | `log` never required | Fixed + test |
|
|
9
|
-
| 3 | src/createCommentPost.js | `calback` typo; `image` undefined; errors resolved as success | Fixed + tests |
|
|
10
|
-
| 4 | package.json | `form-data`, `https-proxy-agent` undeclared; 3 unused deps | Fixed |
|
|
11
|
-
| 5 | checkUpdate.js | version hard-coded 1.2.1 | Fixed + test |
|
|
12
|
-
| 6 | fca-config.example.json | stale version 1.1.0 | Fixed |
|
|
13
|
-
| 7 | 5 src files | CRLF line endings | Normalised |
|
|
14
|
-
|
|
15
|
-
Not changed / still open: `yumi-json-bigint` is pinned to `*` (could not look up a safe version offline); no live Facebook/MQTT test was possible; the 1.2.3 limitations below still apply.
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
# (previous) TORU-FCA 1.2.3 — Comparative Audit and Second-Stage Patch Report
|
|
20
|
-
|
|
21
|
-
## Scope
|
|
22
|
-
This is a static source review and local unit-test run using the supplied TORU-FCA and HRIDOY-FCA archives. No Facebook account, live session, or production Messenger traffic was used. Other FCA archives were used as comparison references, not as proof of runtime correctness.
|
|
23
|
-
|
|
24
|
-
## Changes carried into 1.2.3
|
|
25
|
-
|
|
26
|
-
### MQTT lifecycle
|
|
27
|
-
- Clear an existing reconnect timer and dead-connection watchdog when `listenMqtt()` replaces/restarts the listener.
|
|
28
|
-
- Reject and remove pending `ctx.reqCallbacks` on current MQTT transport errors and close events, instead of leaving callbacks waiting until their individual timeout.
|
|
29
|
-
- On explicit `stopListenMqtt()`, clear pending request callbacks with an error and empty the callback map, including when no client is currently present.
|
|
30
|
-
- Added a unit test for pending callback cleanup on explicit stop.
|
|
31
|
-
|
|
32
|
-
### E2EE bridge lifecycle
|
|
33
|
-
- Track the E2EE reconnect timer in bridge state and ensure repeated `disconnected` events do not create multiple reconnect timers.
|
|
34
|
-
- Use bounded exponential backoff with jitter and `unref()` the timer so it does not keep the Node process alive by itself.
|
|
35
|
-
- Clear reconnect timers on successful connect and explicit disconnect.
|
|
36
|
-
- Disable the native client's own auto-reconnect option and let TORU's wrapper manage retries, avoiding two competing retry managers.
|
|
37
|
-
|
|
38
|
-
## Local verification
|
|
39
|
-
- `node --check` passed for `index.js`, `e2ee.js`, all `src/*.js` and all `test/*.js` files.
|
|
40
|
-
- `npm test`: 3 tests passed, 0 failed.
|
|
41
|
-
- `npm run check`: passed.
|
|
42
|
-
- `npm pack --dry-run`: package contents validated for `toru-fca@1.2.3`.
|
|
43
|
-
- The publishable source archive excludes obvious session filenames (`cookie.txt`, `appstate.json`, `*.session`). This does not prove every file is free of secrets; review before publishing.
|
|
44
|
-
|
|
45
|
-
## Important limitations / not verified
|
|
46
|
-
1. No live MQTT integration test was run. Reconnect timing, subscription restoration, sequence ID refresh, and callback cleanup still need a controlled integration test.
|
|
47
|
-
2. No E2EE native bridge was loaded. The package archive does not bundle the required native `build/messagix` runtime binary, so E2EE connection, key persistence, and message delivery remain unverified.
|
|
48
|
-
3. No multi-hour memory/listener soak test was run.
|
|
49
|
-
4. `api.logout()` intentionally blocks logout and invokes its callback as success in the existing design. This remains misleading API behavior and should be redesigned in a separately documented breaking-change-safe patch.
|
|
50
|
-
5. Reaction MQTT acknowledgment may confirm a transport/task response rather than proving the final reaction is visible to recipients. Timeout delivery remains unknown.
|
|
51
|
-
6. No patch can guarantee Facebook session persistence or prevent server-side account restrictions.
|
|
52
|
-
|
|
53
|
-
## Recommended next steps
|
|
54
|
-
- Test MQTT disconnect/reconnect and manual stop in a sandbox using mocked sockets before using a live account.
|
|
55
|
-
- Confirm that the native E2EE client supports repeated `connect()` calls on the same instance after a disconnect; if not, recreate the client safely during retries and detach old listeners.
|
|
56
|
-
- Add GoatBot API compatibility tests and run a controlled 2–6 hour heap/RSS/listener soak test.
|
|
57
|
-
- Inspect all archive contents for credentials/session data before publishing.
|
package/advancedSystem.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* AdvancedSystem — minimal queue + health monitor for alpha-fca.
|
|
5
|
-
* Automation is OFF by default. No background polling, no aggressive requests.
|
|
6
|
-
* Only runs tasks you explicitly enqueue.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const EventEmitter = require("events");
|
|
10
|
-
|
|
11
|
-
class AdvancedSystem extends EventEmitter {
|
|
12
|
-
constructor(options) {
|
|
13
|
-
super();
|
|
14
|
-
options = options || {};
|
|
15
|
-
this.options = Object.assign({
|
|
16
|
-
automationEnabled: false,
|
|
17
|
-
minDelayMs: 1000,
|
|
18
|
-
maxDelayMs: 30000,
|
|
19
|
-
maxQueue: 50
|
|
20
|
-
}, options);
|
|
21
|
-
this.startedAt = Date.now();
|
|
22
|
-
this._queue = [];
|
|
23
|
-
this._running = false;
|
|
24
|
-
this._stats = { enqueued: 0, completed: 0, failed: 0 };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** @returns {boolean} */
|
|
28
|
-
isAutomationEnabled() {
|
|
29
|
-
return this.options.automationEnabled === true;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** Explicit opt-in only — no background automation started automatically. */
|
|
33
|
-
setAutomationEnabled(enabled) {
|
|
34
|
-
this.options.automationEnabled = Boolean(enabled);
|
|
35
|
-
this.emit("automation", this.options.automationEnabled);
|
|
36
|
-
return this.options.automationEnabled;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Health snapshot — safe to call anytime. */
|
|
40
|
-
health(api) {
|
|
41
|
-
const mqttClient = api && (api.mqttClient || (api.ctx && api.ctx.mqttClient));
|
|
42
|
-
return {
|
|
43
|
-
version: "1.0.0",
|
|
44
|
-
uptimeMs: Date.now() - this.startedAt,
|
|
45
|
-
automationEnabled: this.isAutomationEnabled(),
|
|
46
|
-
inboxEnabled: true,
|
|
47
|
-
mqtt: mqttClient ? {
|
|
48
|
-
connected: Boolean(mqttClient.connected),
|
|
49
|
-
reconnecting: Boolean(mqttClient.reconnecting)
|
|
50
|
-
} : null,
|
|
51
|
-
queue: { size: this._queue.length, running: this._running },
|
|
52
|
-
stats: Object.assign({}, this._stats)
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Enqueue a task function. Runs sequentially.
|
|
58
|
-
* @param {Function} task async () => result
|
|
59
|
-
* @returns {Promise<any>}
|
|
60
|
-
*/
|
|
61
|
-
enqueue(task) {
|
|
62
|
-
if (typeof task !== "function") return Promise.reject(new TypeError("task must be a function"));
|
|
63
|
-
if (this._queue.length >= this.options.maxQueue) {
|
|
64
|
-
return Promise.reject(new Error("AdvancedSystem queue is full (" + this.options.maxQueue + ")"));
|
|
65
|
-
}
|
|
66
|
-
this._stats.enqueued++;
|
|
67
|
-
return new Promise((resolve, reject) => {
|
|
68
|
-
this._queue.push({ task, resolve, reject });
|
|
69
|
-
this._drain();
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async _drain() {
|
|
74
|
-
if (this._running || this._queue.length === 0) return;
|
|
75
|
-
this._running = true;
|
|
76
|
-
while (this._queue.length > 0) {
|
|
77
|
-
const { task, resolve, reject } = this._queue.shift();
|
|
78
|
-
try {
|
|
79
|
-
const result = await task();
|
|
80
|
-
this._stats.completed++;
|
|
81
|
-
resolve(result);
|
|
82
|
-
} catch (err) {
|
|
83
|
-
this._stats.failed++;
|
|
84
|
-
reject(err);
|
|
85
|
-
}
|
|
86
|
-
// Small throttle between tasks to avoid burst requests
|
|
87
|
-
if (this._queue.length > 0) {
|
|
88
|
-
await new Promise(r => setTimeout(r, this.options.minDelayMs));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
this._running = false;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
module.exports = AdvancedSystem;
|
package/checkUpdate.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// v1.2.4: read from package.json so the notice can never drift from the real version.
|
|
4
|
-
const CURRENT_VERSION = (function () {
|
|
5
|
-
try { return require("./package.json").version; } catch (_) { return "0.0.0"; }
|
|
6
|
-
})();
|
|
7
|
-
|
|
8
|
-
async function checkForFCAUpdate() {
|
|
9
|
-
try {
|
|
10
|
-
if (process.env.HRIDOY_ULTIMATE_NO_UPDATE_CHECK || process.env.TORU_FCA_NO_UPDATE_CHECK) return; // v1.2.1: opt-out, never auto-installs anything
|
|
11
|
-
const https = require("https");
|
|
12
|
-
|
|
13
|
-
const data = await new Promise(function(resolve) {
|
|
14
|
-
var req = https.get(
|
|
15
|
-
"https://registry.npmjs.org/hridoy-ultimate/latest",
|
|
16
|
-
{ timeout: 5000 },
|
|
17
|
-
function(res) {
|
|
18
|
-
var body = "";
|
|
19
|
-
res.on("data", function(c) { body += c; });
|
|
20
|
-
res.on("end", function() {
|
|
21
|
-
try { resolve(JSON.parse(body)); } catch (_) { resolve(null); }
|
|
22
|
-
});
|
|
23
|
-
res.on("error", function() { resolve(null); });
|
|
24
|
-
}
|
|
25
|
-
);
|
|
26
|
-
req.on("error", function() { resolve(null); });
|
|
27
|
-
// Destroy on timeout to avoid hanging socket
|
|
28
|
-
req.on("timeout", function() { req.destroy(); resolve(null); });
|
|
29
|
-
// Hard abort after 8s as a belt-and-suspenders guard
|
|
30
|
-
var hard = setTimeout(function() { try { req.destroy(); } catch (_) {} resolve(null); }, 8000);
|
|
31
|
-
if (hard.unref) hard.unref();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
if (data && data.version && data.version !== CURRENT_VERSION) {
|
|
35
|
-
var log = require("npmlog");
|
|
36
|
-
log.warn(
|
|
37
|
-
"hridoy-ultimate",
|
|
38
|
-
"Update available: v" + CURRENT_VERSION + " \u2192 v" + data.version +
|
|
39
|
-
" \u2014 npm update hridoy-ultimate"
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
} catch (_) {
|
|
43
|
-
// Non-fatal; version check is best-effort only
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
module.exports = { checkForFCAUpdate, CURRENT_VERSION };
|
package/config.json
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"_info": "hridoy-ultimate v8.0.1 \u2014 Main Config",
|
|
3
|
-
"version": "1.2.4",
|
|
4
|
-
"antiLogout": {
|
|
5
|
-
"enabled": true,
|
|
6
|
-
"refreshIntervalMs": 1200000,
|
|
7
|
-
"_note": "Periodically refreshes fb_dtsg when supported; this cannot guarantee session persistence or prevent server-side logout."
|
|
8
|
-
},
|
|
9
|
-
"sessionGuard": {
|
|
10
|
-
"enabled": true,
|
|
11
|
-
"intervalMs": 180000,
|
|
12
|
-
"debounceMs": 20000,
|
|
13
|
-
"backupEnabled": true,
|
|
14
|
-
"_note": "Periodically saves valid appstate and a backup. Cookie expiry changes cannot override server-side session expiry."
|
|
15
|
-
},
|
|
16
|
-
"automation": {
|
|
17
|
-
"enabled": false,
|
|
18
|
-
"_note": "KEEP FALSE. Disables background automation. Protects against Facebook restrictions."
|
|
19
|
-
},
|
|
20
|
-
"smooth": {
|
|
21
|
-
"enabled": true,
|
|
22
|
-
"messageDelay": 300,
|
|
23
|
-
"_note": "Shows typing indicator before sending. 300ms delay for human-like behavior."
|
|
24
|
-
},
|
|
25
|
-
"connection": {
|
|
26
|
-
"minDelayMs": 3000,
|
|
27
|
-
"maxDelayMs": 60000,
|
|
28
|
-
"_note": "MQTT reconnect exponential backoff range."
|
|
29
|
-
},
|
|
30
|
-
"e2ee": {
|
|
31
|
-
"enable": true,
|
|
32
|
-
"saveType": "memory",
|
|
33
|
-
"devicePath": "./data/e2ee-device.json",
|
|
34
|
-
"autoReconnect": true,
|
|
35
|
-
"logLevel": "none",
|
|
36
|
-
"_note": "E2EE Labyrinth bridge. Needs the native build/messagix binary (not bundled). Keep false unless you add it."
|
|
37
|
-
},
|
|
38
|
-
"facebookProtection": {
|
|
39
|
-
"enabled": true,
|
|
40
|
-
"blockAutomationDetection": true,
|
|
41
|
-
"humanLikeDelay": true,
|
|
42
|
-
"_note": "Optional request delays and conservative presence settings; no method can guarantee avoidance of platform restrictions."
|
|
43
|
-
},
|
|
44
|
-
"inbox": {
|
|
45
|
-
"enabled": true,
|
|
46
|
-
"replyToInbox": true,
|
|
47
|
-
"_note": "Bot replies in both inbox/DM and group threads."
|
|
48
|
-
},
|
|
49
|
-
"enableTypingIndicator": false,
|
|
50
|
-
"typingDuration": 4000
|
|
51
|
-
}
|