hridoy-ultimate 9.0.0 → 9.0.2

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 (46) hide show
  1. package/CHANGELOG.md +346 -69
  2. package/{docs/UPSTREAM_API_DOCS.md → DOCS.md} +3 -3
  3. package/README.md +536 -161
  4. package/func/checkUpdate.js +1 -0
  5. package/index.d.ts +13 -74
  6. package/index.js +0 -6
  7. package/module/config.js +2 -5
  8. package/module/login.js +1 -2
  9. package/module/loginHelper.js +9 -41
  10. package/module/options.js +6 -6
  11. package/package.json +44 -39
  12. package/src/api/action/logout.js +0 -19
  13. package/src/api/messaging/sendMessage.js +1 -1
  14. package/src/api/messaging/sessionGuard.js +8 -0
  15. package/src/api/messaging/setMessageReaction.js +2 -7
  16. package/src/api/socket/core/connectMqtt.js +72 -99
  17. package/src/api/socket/core/emitAuth.js +17 -9
  18. package/src/api/socket/e2ee/index.js +15 -33
  19. package/src/api/socket/e2ee/native/NOTICE.md +2 -2
  20. package/src/api/socket/e2ee/native/lib/index.mjs +1 -2
  21. package/src/api/socket/e2ee/native/nativeMediaBridge.js +4 -4
  22. package/src/api/socket/listenE2EE.js +1 -3
  23. package/src/api/socket/listenMqtt.js +60 -67
  24. package/src/utils/antiSuspension.js +3 -3
  25. package/src/utils/fingerprint.js +35 -16
  26. package/src/utils/headers.js +1 -1
  27. package/src/utils/versionCheck.js +47 -0
  28. package/LICENSE +0 -23
  29. package/MERGE_REPORT.md +0 -54
  30. package/THIRD_PARTY_NOTICES.md +0 -36
  31. package/docs/TEST_RESULTS.md +0 -68
  32. package/scripts/run-tests.js +0 -19
  33. package/scripts/syntax-check.js +0 -22
  34. package/src/api/socket/core/lifecycle.js +0 -117
  35. package/src/api/socket/e2ee/proto/proto-writer.ts +0 -76
  36. package/src/utils/typingIndicator.js +0 -202
  37. package/test/helpers/stub-modules.js +0 -122
  38. package/test/integration/logout.test.js +0 -69
  39. package/test/integration/mqtt-lifecycle.test.js +0 -195
  40. package/test/integration/package.test.js +0 -116
  41. package/test/integration/typing-wiring.test.js +0 -71
  42. package/test/unit/fingerprint.test.js +0 -19
  43. package/test/unit/humanizer.test.js +0 -32
  44. package/test/unit/lifecycle.test.js +0 -92
  45. package/test/unit/parsers.test.js +0 -43
  46. package/test/unit/typing.test.js +0 -136
@@ -1,136 +0,0 @@
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
- });