fca-nx 6.8.8 → 7.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.
Files changed (79) hide show
  1. package/README.md +24 -10
  2. package/func/checkUpdate.js +1 -1
  3. package/func/logAdapter.js +2 -0
  4. package/index.js +3 -0
  5. package/module/config.js +5 -3
  6. package/module/login.js +38 -13
  7. package/module/loginHelper.js +207 -148
  8. package/module/options.js +7 -1
  9. package/package.json +2 -2
  10. package/src/api/action/addfriend.js +9 -3
  11. package/src/api/action/changeAvatar.js +1 -0
  12. package/src/api/action/changeCover.js +3 -1
  13. package/src/api/action/enableAutoSaveAppState.js +18 -5
  14. package/src/api/action/refreshFb_dtsg.js +18 -76
  15. package/src/api/http/httpGet.js +6 -2
  16. package/src/api/http/httpPost.js +7 -2
  17. package/src/api/messaging/createNewGroup.js +1 -1
  18. package/src/api/messaging/deleteMessage.js +1 -1
  19. package/src/api/messaging/forwardMessage.js +9 -1
  20. package/src/api/messaging/getEmojiUrl.js +5 -1
  21. package/src/api/messaging/getMessage.js +4 -2
  22. package/src/api/messaging/getThemePictures.js +7 -0
  23. package/src/api/messaging/markAsRead.js +1 -0
  24. package/src/api/messaging/muteThread.js +1 -1
  25. package/src/api/messaging/pinMessage.js +10 -1
  26. package/src/api/messaging/scheduler.js +71 -4
  27. package/src/api/messaging/sendBroadcast.js +15 -0
  28. package/src/api/messaging/sendMessage.js +23 -1
  29. package/src/api/messaging/sendTypingIndicator.js +0 -15
  30. package/src/api/messaging/sessionGuard.js +45 -9
  31. package/src/api/messaging/setMessageReaction.js +2 -1
  32. package/src/api/messaging/threadColors.js +45 -12
  33. package/src/api/messaging/uploadAttachment.js +37 -3
  34. package/src/api/socket/OldMessage.js +7 -2
  35. package/src/api/socket/core/connectMqtt.js +68 -81
  36. package/src/api/socket/core/emitAuth.js +11 -2
  37. package/src/api/socket/core/getSeqID.js +52 -56
  38. package/src/api/socket/core/getTaskResponseData.js +3 -1
  39. package/src/api/socket/core/parseDelta.js +1 -1
  40. package/src/api/socket/detail/buildStream.js +4 -1
  41. package/src/api/socket/detail/constants.js +4 -1
  42. package/src/api/socket/e2ee/crypto.js +40 -2
  43. package/src/api/socket/e2ee/index.js +123 -10
  44. package/src/api/socket/e2ee/protocol.js +32 -1
  45. package/src/api/socket/e2ee/ratchet.js +44 -10
  46. package/src/api/socket/e2ee/store.js +13 -1
  47. package/src/api/socket/listenE2EE.js +25 -1
  48. package/src/api/socket/listenMqtt.js +94 -110
  49. package/src/api/socket/middleware/index.js +61 -7
  50. package/src/api/socket/sendMessage.js +19 -2
  51. package/src/api/socket/sendMessageMqtt.js +6 -0
  52. package/src/api/threads/getThreadHistory.js +68 -38
  53. package/src/api/threads/getThreadInfo.js +4 -3
  54. package/src/api/threads/getThreadList.js +34 -31
  55. package/src/api/threads/getThreadPictures.js +1 -1
  56. package/src/api/users/getUserInfo.js +5 -2
  57. package/src/api/users/getUserInfoV2.js +9 -3
  58. package/src/app/createFcaClient.js +2 -2
  59. package/src/core/sendReqMqtt.js +2 -1
  60. package/src/database/helpers.js +12 -0
  61. package/src/database/models/index.js +8 -9
  62. package/src/utils/broadcast.js +1 -1
  63. package/src/utils/clientIdentity.js +50 -3
  64. package/src/utils/cookies.js +4 -2
  65. package/src/utils/format/utils.js +10 -0
  66. package/src/utils/headers.js +26 -12
  67. package/src/utils/loginParser/autoLogin.js +12 -0
  68. package/src/utils/loginParser/parseAndCheckLogin.js +7 -0
  69. package/src/utils/loginParser/textUtils.js +6 -0
  70. package/src/utils/request/config.js +4 -1
  71. package/src/utils/request/methods.js +0 -13
  72. package/src/utils/request/proxy.js +13 -0
  73. package/src/utils/request/retry.js +0 -10
  74. package/src/utils/request/sanitize.js +1 -1
  75. package/src/utils/sendThrottle.js +14 -1
  76. package/src/utils/textEffects.js +92 -0
  77. package/src/utils/utils.js +17 -3
  78. package/src/utils/instanceLock.js +0 -35
  79. package/src/utils/ipGuard.js +0 -58
package/README.md CHANGED
@@ -132,22 +132,36 @@ api.restoreFromBackup();
132
132
  api.stopAutoSave();
133
133
 
134
134
  ```
135
-
136
- ### Local E2EE helper-store encryption
137
-
138
- The optional local E2EE helper store requires an external secret. Set
139
- `FCA_NX_E2EE_STORE_KEY` to a high-entropy value of at least 32 characters, or
140
- pass `{ encryptionKey }` to `E2EEStore`. The secret is not written to the store
141
- file. Keep it in your deployment's secret manager; without it, loading or
142
- saving the helper store fails closed. Legacy helper-store files are re-encrypted
143
- on load when this key is configured.
144
-
145
135
  # 💬 Messaging
146
136
  ### Send Message
147
137
  ```javascript
148
138
  api.sendMessage("Hello world!", threadID);
149
139
 
150
140
  ```
141
+ ### Message Effects
142
+ ```javascript
143
+ api.sendMessage(
144
+ {
145
+ body: "I love you! ❤️",
146
+ textEffect: "love"
147
+ },
148
+ threadID
149
+ );
150
+ ```
151
+
152
+ Built-in effect names are `heart`, `hearts`, `love`, `gift`, `present`, `fire`,
153
+ `flame`, `confetti`, `confecti`, `party`, `sparkles`, `sparkle`, `star`, and
154
+ `magic`. You can also pass a custom numeric effect ID:
155
+
156
+ ```javascript
157
+ api.sendMessage({ body: "Party time!", effect: "confetti" }, threadID);
158
+ api.sendMessage({ body: "Custom effect", textEffect: 27 }, threadID);
159
+ ```
160
+
161
+ The aliases `textEffect`, `text_effect`, `effect`, `effectName`, and their
162
+ snake/camel-case ID variants are accepted. Effects are applied through both
163
+ the MQTT sender and the legacy fallback sender.
164
+
151
165
  ### Send Attachment
152
166
  ```javascript
153
167
  const fs = require("fs");
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
-
2
+ // Auto-update disabled in fca-mueidmursalinrifat
3
3
  function checkAndUpdateVersion(callback) {
4
4
  if (typeof callback === "function") callback(null);
5
5
  return Promise.resolve();
@@ -3,6 +3,7 @@ const logger = require("./logger");
3
3
  function formatArgs(args) {
4
4
  const [prefix, msg] = args;
5
5
 
6
+ // Single argument: log as-is
6
7
  if (msg === undefined) {
7
8
  if (prefix instanceof Error) {
8
9
  return prefix.stack || prefix.message || String(prefix);
@@ -10,6 +11,7 @@ function formatArgs(args) {
10
11
  return String(prefix);
11
12
  }
12
13
 
14
+ // Two arguments: mimic npmlog("tag", message)
13
15
  const tag = prefix == null ? "" : String(prefix);
14
16
  if (msg instanceof Error) {
15
17
  const base = msg.message || String(msg);
package/index.js CHANGED
@@ -6,11 +6,14 @@ const { MessengerBot, createMessengerBot } = require("./src/app/MessengerBot");
6
6
  const { MessengerContext } = require("./src/app/MessengerContext");
7
7
  const { attachThreadInfoRealtimeSync, applyThreadInfoRealtimeEvent } = require("./src/app/threadInfoRealtimeSync");
8
8
 
9
+ // CommonJS default export — the login function (classic FCA / GoatBot compatible)
9
10
  module.exports = login;
10
11
 
12
+ // Named exports
11
13
  module.exports.login = login;
12
14
  module.exports.default = login;
13
15
 
16
+ // New features from dongdev
14
17
  module.exports.createFcaClient = createFcaClient;
15
18
  module.exports.MessengerBot = MessengerBot;
16
19
  module.exports.createMessengerBot = createMessengerBot;
package/module/config.js CHANGED
@@ -5,12 +5,14 @@ const defaultConfig = {
5
5
  autoUpdate: true,
6
6
  mqtt: { enabled: true, reconnectInterval: 3600 },
7
7
  autoLogin: true,
8
-
8
+ // SECURITY: intentionally no default value here. Sending Facebook
9
+ // credentials to a third-party server should be an explicit,
10
+ // operator-chosen opt-in (see module/loginHelper.js#loginViaAPI), never a
11
+ // silent default. Set this in fca-config.json only if you trust the
12
+ // server you're pointing it at.
9
13
  apiServer: "",
10
14
  apiKey: "",
11
15
  credentials: { email: "", password: "", twofactor: "" },
12
-
13
- e2ee: false,
14
16
  antiGetInfo: {
15
17
  AntiGetThreadInfo: false,
16
18
  AntiGetUserInfo: false
package/module/login.js CHANGED
@@ -9,72 +9,95 @@ const { DEFAULT_IDENTITY } = require("../src/utils/clientIdentity");
9
9
  const { config } = loadConfig();
10
10
  global.fca = { config };
11
11
 
12
+ // Global error handlers to prevent bot crashes
13
+ // Handle unhandled promise rejections (e.g., fetch timeouts, network errors)
12
14
  if (!global.fca._errorHandlersInstalled) {
13
15
  global.fca._errorHandlersInstalled = true;
14
16
 
15
17
  process.on("unhandledRejection", (reason, promise) => {
16
18
  try {
17
-
19
+ // Check if it's a fetch/network timeout error
18
20
  if (reason && typeof reason === "object") {
19
21
  const errorCode = reason.code || reason.cause?.code;
20
22
  const errorMessage = reason.message || String(reason);
21
23
 
24
+ // Suppress Sequelize instance errors (handled gracefully in getBackupModel)
22
25
  if (errorMessage.includes("No Sequelize instance passed")) {
23
- return;
26
+ return; // Silently ignore - already handled
24
27
  }
25
28
 
29
+ // Handle fetch timeout errors gracefully
26
30
  if (errorCode === "UND_ERR_CONNECT_TIMEOUT" ||
27
31
  errorCode === "ETIMEDOUT" ||
28
32
  errorMessage.includes("Connect Timeout") ||
29
33
  errorMessage.includes("fetch failed")) {
30
34
  logger(`Network timeout error caught (non-fatal): ${errorMessage}`, "warn");
31
- return;
35
+ return; // Don't crash, just log
32
36
  }
33
37
 
38
+ // Handle other network errors
34
39
  if (errorCode === "ECONNREFUSED" ||
35
40
  errorCode === "ENOTFOUND" ||
36
41
  errorCode === "ECONNRESET" ||
37
42
  errorMessage.includes("ECONNREFUSED") ||
38
43
  errorMessage.includes("ENOTFOUND")) {
39
44
  logger(`Network connection error caught (non-fatal): ${errorMessage}`, "warn");
40
- return;
45
+ return; // Don't crash, just log
41
46
  }
42
47
  }
43
48
 
49
+ // [Fixed by xalman] For other unhandled rejections, log but don't crash.
50
+ // Include the stack (when available) - logging only `.message` made
51
+ // real bugs impossible to trace back to where they were thrown.
44
52
  const errorDetail = reason && reason.stack ? reason.stack : (reason && reason.message ? reason.message : String(reason));
45
53
  logger(`Unhandled promise rejection (non-fatal): ${errorDetail}`, "error");
46
54
  } catch (e) {
47
-
55
+ // Logger itself failed - fall back to stderr so this isn't silently lost.
48
56
  try { console.error("[fca-nx] logger failed while handling unhandledRejection:", e, reason); } catch { }
49
57
  }
50
58
  });
51
59
 
60
+ // Handle uncaught exceptions (last resort)
52
61
  process.on("uncaughtException", (error) => {
53
62
  try {
54
63
  const errorMessage = error.message || String(error);
55
64
  const errorCode = error.code;
56
65
 
66
+ // Suppress Sequelize instance errors (handled gracefully in getBackupModel)
57
67
  if (errorMessage.includes("No Sequelize instance passed")) {
58
- return;
68
+ return; // Silently ignore - already handled
59
69
  }
60
70
 
71
+ // Handle fetch/network errors
61
72
  if (errorCode === "UND_ERR_CONNECT_TIMEOUT" ||
62
73
  errorCode === "ETIMEDOUT" ||
63
74
  errorMessage.includes("Connect Timeout") ||
64
75
  errorMessage.includes("fetch failed")) {
65
76
  logger(`Uncaught network timeout error (non-fatal): ${errorMessage}`, "warn");
66
- return;
77
+ return; // Don't crash
67
78
  }
68
79
 
80
+ // [Fixed by xalman] For other uncaught exceptions, log but try to continue.
81
+ // Include the stack trace - without it these were undebuggable in production.
69
82
  logger(`Uncaught exception (attempting to continue): ${error && error.stack ? error.stack : errorMessage}`, "error");
70
-
83
+ // Note: We don't exit here to allow bot to continue running.
84
+ // This trades crash-safety for the (small) risk of continuing in a
85
+ // partially-inconsistent process state. If you run this under a process
86
+ // manager (pm2/systemd) that auto-restarts on crash, consider calling
87
+ // process.exit(1) here instead for a clean restart on truly unknown errors.
71
88
  } catch (e) {
72
-
89
+ // Logger itself failed - fall back to stderr so this isn't silently lost.
73
90
  try { console.error("[fca-nx] logger failed while handling uncaughtException:", e, error); } catch { }
74
91
  }
75
92
  });
76
93
  }
77
94
 
95
+ // Prevent multiple simultaneous login attempts for the same account.
96
+ // Keyed by whatever identifies the account in loginData (email, or the
97
+ // c_user/i_user value pulled out of an appstate/cookie string) so that
98
+ // calling login() twice in a row for the same account before the first
99
+ // call resolves can't race and produce two half-initialized sessions
100
+ // fighting over the same cookies.
78
101
  if (!global.fca._activeLogins) global.fca._activeLogins = new Set();
79
102
 
80
103
  function extractLoginKey(loginData) {
@@ -114,7 +137,12 @@ function login(loginData, options, callback) {
114
137
  autoReconnect: true,
115
138
  online: true,
116
139
  emitReady: false,
117
-
140
+ // Single source of truth for the default identity - see src/utils/clientIdentity.js.
141
+ // This used to be hard-coded independently here (Chrome/121), in
142
+ // module/options.js (Chrome/125), src/utils/headers.js (Chrome/139) and
143
+ // src/api/messaging/uploadAttachment.js (Chrome/143), which meant a single
144
+ // session could send contradictory browser-version fingerprints between
145
+ // different requests. All four now derive from the same identity module.
118
146
  userAgent: DEFAULT_IDENTITY.userAgent
119
147
  };
120
148
  setOptions(globalOptions, options);
@@ -147,9 +175,6 @@ function login(loginData, options, callback) {
147
175
  callback(error, api);
148
176
  };
149
177
 
150
- if (loginData && (loginData.twofactor || loginData.twoFactor)) {
151
- globalOptions.twofactor = String(loginData.twofactor || loginData.twoFactor);
152
- }
153
178
  const proceed = () => loginHelper(loginData.appState, loginData.Cookie, loginData.email, loginData.password, globalOptions, wrappedCallback, prCallback);
154
179
  if (config && config.autoUpdate) {
155
180
  const p = checkAndUpdateVersion();