@cexy/hoonfca 1.0.5 → 1.0.7

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.
@@ -3,7 +3,7 @@ const fs = require("fs");
3
3
  const path = require("path");
4
4
  const { exec } = require("child_process");
5
5
  const https = require("https");
6
- const pkgName = "@dongdev/fca-unofficial";
6
+ const pkgName = "@cexy/hoonfca";
7
7
 
8
8
  let axios = null;
9
9
  try {
@@ -201,14 +201,25 @@ async function _checkAndUpdateVersionImpl() {
201
201
  let after = getInstalledVersion();
202
202
  if (!after) after = await getInstalledVersionByNpm();
203
203
 
204
- if (after && after === latest) {
205
- writeLock({ ts: Date.now(), latest, status: "updated" });
206
- logger(`Updated fca to the latest version: ${latest}, Restart to apply`, "info");
204
+ if (after && after === latest) {
205
+ writeLock({ ts: Date.now(), latest, status: "updated" });
206
+
207
+ logger(
208
+ `Updated fca to the latest version: ${latest}. Restart manually to apply.`,
209
+ "info"
210
+ );
211
+
212
+ if (process.env.FCA_AUTO_RESTART === "true") {
207
213
  process.exit(1);
208
- } else {
209
- writeLock({ ts: Date.now(), latest, status: "mismatch" });
210
- logger(`Installed but version mismatch (have: ${after || "unknown"}, want: ${latest}). Skip restart to avoid loop`, "error");
211
214
  }
215
+ } else {
216
+ writeLock({ ts: Date.now(), latest, status: "mismatch" });
217
+ logger(
218
+ `Installed but version mismatch (have: ${after || "unknown"}, want: ${latest}). Skip restart to avoid loop`,
219
+ "error"
220
+ );
221
+ }
222
+
212
223
  }
213
224
 
214
225
  function checkAndUpdateVersion(callback) {
package/module/config.js CHANGED
@@ -1,34 +1,67 @@
1
1
  const fs = require("fs");
2
2
  const path = require("path");
3
3
  const logger = require("../func/logger");
4
+
4
5
  const defaultConfig = {
5
- autoUpdate: true,
6
- mqtt: { enabled: true, reconnectInterval: 3600 },
6
+ autoUpdate: false,
7
+ mqtt: {
8
+ enabled: true,
9
+ reconnectInterval: 3600
10
+ },
7
11
  autoLogin: true,
8
- credentials: { email: "", password: "", twofactor: "" }
12
+ credentials: {
13
+ email: "",
14
+ password: "",
15
+ twofactor: ""
16
+ }
9
17
  };
10
18
 
11
19
  function loadConfig() {
12
20
  const configPath = path.join(process.cwd(), "fca-config.json");
13
- let config;
14
- if (!fs.existsSync(configPath)) {
15
- try {
16
- fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
17
- config = defaultConfig;
18
- } catch (err) {
19
- logger(`Error writing config file: ${err.message}`, "error");
20
- config = defaultConfig;
21
- }
22
- } else {
23
- try {
21
+ let config = {};
22
+
23
+ try {
24
+ if (!fs.existsSync(configPath)) {
25
+ config = { ...defaultConfig };
26
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
27
+ } else {
24
28
  const fileContent = fs.readFileSync(configPath, "utf8");
25
- config = Object.assign({}, defaultConfig, JSON.parse(fileContent));
26
- } catch (err) {
27
- logger(`Error reading config file: ${err.message}`, "error");
28
- config = defaultConfig;
29
+ config = JSON.parse(fileContent);
30
+
31
+ // Merge with defaults
32
+ config = {
33
+ ...defaultConfig,
34
+ ...config,
35
+ mqtt: {
36
+ ...defaultConfig.mqtt,
37
+ ...(config.mqtt || {})
38
+ },
39
+ credentials: {
40
+ ...defaultConfig.credentials,
41
+ ...(config.credentials || {})
42
+ }
43
+ };
44
+
45
+ // Save updated config if new keys were added
46
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
29
47
  }
48
+ } catch (err) {
49
+ logger(`Config error: ${err.message}`, "error");
50
+
51
+ config = { ...defaultConfig };
52
+
53
+ try {
54
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
55
+ } catch (_) {}
30
56
  }
31
- return { config, configPath };
57
+
58
+ return {
59
+ config,
60
+ configPath
61
+ };
32
62
  }
33
63
 
34
- module.exports = { loadConfig, defaultConfig };
64
+ module.exports = {
65
+ loadConfig,
66
+ defaultConfig
67
+ };
package/module/login.js CHANGED
@@ -119,18 +119,36 @@ function login(loginData, options, callback) {
119
119
  };
120
120
  callback = prCallback;
121
121
  }
122
- const proceed = () => loginHelper(loginData.appState, loginData.Cookie, loginData.email, loginData.password, globalOptions, callback, prCallback);
123
- if (config && config.autoUpdate) {
124
- const p = checkAndUpdateVersion();
125
- if (p && typeof p.then === "function") {
126
- p.then(proceed).catch(err => callback(err));
127
- } else {
128
- proceed();
122
+
123
+
124
+ const proceed = () =>
125
+ loginHelper(
126
+ loginData.appState,
127
+ loginData.Cookie,
128
+ loginData.email,
129
+ loginData.password,
130
+ globalOptions,
131
+ callback,
132
+ prCallback
133
+ );
134
+
135
+ // Login immediately
136
+ proceed();
137
+
138
+ // Run update check in background (never block login)
139
+ if (config && config.autoUpdate) {
140
+ setImmediate(async () => {
141
+ try {
142
+ await checkAndUpdateVersion();
143
+ } catch (err) {
144
+ logger(
145
+ `Background update check failed: ${err.message || err}`,
146
+ "warn"
147
+ );
129
148
  }
130
- } else {
131
- proceed();
132
- }
133
- return returnPromise;
149
+ });
150
+ }
151
+ return returnPromise;
134
152
  }
135
153
 
136
154
  module.exports = login;
package/module/options.js CHANGED
@@ -1,6 +1,5 @@
1
- const { getType } = require("../src/utils/format");
2
1
  const { setProxy } = require("../src/utils/request");
3
- const logger = require("../func/logger");
2
+
4
3
  const Boolean_Option = [
5
4
  "online",
6
5
  "selfListen",
@@ -14,32 +13,42 @@ const Boolean_Option = [
14
13
  "emitReady",
15
14
  "selfListenEvent"
16
15
  ];
17
- function setOptions(globalOptions, options) {
18
- for (const key of Object.keys(options || {})) {
16
+
17
+ function setOptions(globalOptions, options = {}) {
18
+ for (const key of Object.keys(options)) {
19
19
  if (Boolean_Option.includes(key)) {
20
20
  globalOptions[key] = Boolean(options[key]);
21
21
  continue;
22
22
  }
23
+
23
24
  switch (key) {
24
- case "userAgent": {
25
- globalOptions.userAgent = options.userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36";
25
+ case "userAgent":
26
+ globalOptions.userAgent =
27
+ options.userAgent ||
28
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36";
26
29
  break;
27
- }
28
- case "proxy": {
30
+
31
+ case "proxy":
29
32
  if (typeof options.proxy !== "string") {
30
33
  delete globalOptions.proxy;
31
34
  setProxy();
32
35
  } else {
33
36
  globalOptions.proxy = options.proxy;
34
- setProxy(globalOptions.proxy);
37
+ setProxy(options.proxy);
35
38
  }
36
39
  break;
37
- }
38
- default: {
39
- logger("setOptions Unrecognized option given to setOptions: " + key, "warn");
40
+
41
+ default:
42
+ // Accept any future/custom option silently
43
+ globalOptions[key] = options[key];
40
44
  break;
41
- }
42
45
  }
43
46
  }
47
+
48
+ return globalOptions;
44
49
  }
45
- module.exports = { setOptions, Boolean_Option };
50
+
51
+ module.exports = {
52
+ setOptions,
53
+ Boolean_Option
54
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cexy/hoonfca",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Unofficial Facebook Chat API for Node.js - Interact with Facebook Messenger programmatically",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",