nexus-fca 2.0.5 → 2.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.
package/index.js CHANGED
@@ -25,7 +25,7 @@ const { User } = require('./lib/message/User');
25
25
  // Advanced Safety Module - Minimizes ban/lock/checkpoint rates
26
26
  const FacebookSafety = require('./lib/safety/FacebookSafety');
27
27
 
28
- // Legacy imports for backward compatibility
28
+ // Core compatibility imports
29
29
  const MqttManager = require('./lib/mqtt/MqttManager');
30
30
  const { DatabaseManager, getInstance } = require('./lib/database/DatabaseManager');
31
31
  const { PerformanceOptimizer, getInstance: getPerformanceOptimizerInstance } = require('./lib/performance/PerformanceOptimizer');
@@ -256,7 +256,7 @@ function buildAPI(globalOptions, html, jar) {
256
256
  };
257
257
  }
258
258
 
259
- // Legacy login helper function for appstate-only login
259
+ // Appstate login helper function
260
260
  function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
261
261
  let mainPromise = null;
262
262
  const jar = utils.getJar();
@@ -295,7 +295,7 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
295
295
  return callback(new Error("Invalid appState format"));
296
296
  }
297
297
  } else {
298
- return callback(new Error("AppState is required for legacy login"));
298
+ return callback(new Error("AppState is required for session authentication"));
299
299
  }
300
300
 
301
301
  function handleRedirect(res) {
@@ -345,7 +345,7 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
345
345
  logger(`⚠️ Login safety warning: ${safetyStatus.reason}`, 'warn');
346
346
  }
347
347
 
348
- logger('Legacy login successful!', 'info');
348
+ logger(' Session authenticated successfully', 'info');
349
349
 
350
350
  // Initialize safety monitoring
351
351
  globalSafety.startMonitoring(ctx, api);
@@ -388,7 +388,7 @@ class IntegratedNexusLoginSystem {
388
388
  this.lastLoginTime = 0;
389
389
 
390
390
  this.ensureDirectories();
391
- this.logger('Nexus Login System initialized', '🚀');
391
+ this.logger('Login system ready', '🚀');
392
392
  }
393
393
 
394
394
  logger(message, emoji = '📝') {
@@ -606,7 +606,7 @@ class IntegratedNexusLoginSystem {
606
606
  timeout: 30000
607
607
  };
608
608
 
609
- this.logger('Attempting login with enhanced security...', '🔐');
609
+ this.logger('Connecting to Facebook servers...', '🔐');
610
610
 
611
611
  return new Promise((resolve) => {
612
612
  axios.request(options).then(async (response) => {
@@ -646,7 +646,7 @@ class IntegratedNexusLoginSystem {
646
646
  };
647
647
 
648
648
  this.saveAppstate(appstate, result);
649
- this.logger('Login successful! Appstate generated and saved', '🎉');
649
+ this.logger('Login successful - Session established', '🎉');
650
650
 
651
651
  resolve(result);
652
652
  }
@@ -672,11 +672,11 @@ class IntegratedNexusLoginSystem {
672
672
  twoFactorCode = credentials._2fa;
673
673
  } else if (credentials.twofactor && credentials.twofactor !== "0") {
674
674
  try {
675
- this.logger('Processing 2FA with TOTP...', '🔐');
675
+ this.logger('Generating 2FA code...', '🔐');
676
676
  const cleanSecret = decodeURI(credentials.twofactor).replace(/\s+/g, '').toUpperCase();
677
677
  const { otp } = TOTP.generate(cleanSecret);
678
678
  twoFactorCode = otp;
679
- this.logger(`Generated 2FA code: ${otp}`, '🔑');
679
+ this.logger(`✅ 2FA code generated: ${otp}`, '🔑');
680
680
  } catch (e) {
681
681
  return resolve({
682
682
  success: false,
@@ -705,7 +705,7 @@ class IntegratedNexusLoginSystem {
705
705
  twoFactorForm.sig = this.encodesig(this.sort(twoFactorForm));
706
706
  options.data = twoFactorForm;
707
707
 
708
- this.logger('Attempting 2FA login...', '🔐');
708
+ this.logger('Verifying 2FA code...', '🔐');
709
709
 
710
710
  try {
711
711
  const twoFactorResponse = await axios.request(options);
@@ -742,7 +742,7 @@ class IntegratedNexusLoginSystem {
742
742
  };
743
743
 
744
744
  this.saveAppstate(appstate, result);
745
- this.logger('2FA login successful! Appstate saved', '🎉');
745
+ this.logger('2FA verification successful', '🎉');
746
746
 
747
747
  resolve(result);
748
748
 
@@ -775,19 +775,19 @@ class IntegratedNexusLoginSystem {
775
775
 
776
776
  async login(credentials = null) {
777
777
  try {
778
- this.logger('Starting Nexus Login System...', '🚀');
778
+ this.logger('Initializing authentication...', '🚀');
779
779
 
780
780
  // Check for existing valid appstate first
781
781
  if (this.options.autoLogin && this.hasValidAppstate()) {
782
- this.logger('Valid appstate found, loading...', '✅');
782
+ this.logger('Existing session found', '✅');
783
783
  const appstate = this.loadAppstate();
784
784
 
785
785
  if (appstate) {
786
786
  return {
787
787
  success: true,
788
788
  appstate: appstate,
789
- method: 'existing_appstate',
790
- message: 'Login successful using existing appstate'
789
+ method: 'existing_session',
790
+ message: 'Login successful using existing session'
791
791
  };
792
792
  }
793
793
  }
@@ -807,7 +807,7 @@ class IntegratedNexusLoginSystem {
807
807
  if (!credentials) {
808
808
  return {
809
809
  success: false,
810
- message: 'No valid appstate found and no credentials provided'
810
+ message: 'No valid session found and no credentials provided'
811
811
  };
812
812
  }
813
813
  }
@@ -820,7 +820,7 @@ class IntegratedNexusLoginSystem {
820
820
  };
821
821
  }
822
822
 
823
- this.logger('Generating new appstate...', '🔄');
823
+ this.logger('Creating new session...', '🔄');
824
824
 
825
825
  // Generate new appstate
826
826
  const result = await this.generateAppstate(credentials);
@@ -841,10 +841,10 @@ class IntegratedNexusLoginSystem {
841
841
  return result;
842
842
 
843
843
  } catch (error) {
844
- this.logger(`Login system error: ${error.message}`, '💥');
844
+ this.logger(`Authentication error: ${error.message}`, '💥');
845
845
  return {
846
846
  success: false,
847
- message: `System error: ${error.message}`
847
+ message: `Authentication error: ${error.message}`
848
848
  };
849
849
  }
850
850
  }
@@ -853,43 +853,107 @@ class IntegratedNexusLoginSystem {
853
853
  // Integrated Nexus Login wrapper for easy usage
854
854
  async function integratedNexusLogin(credentials = null, options = {}) {
855
855
  const loginSystem = new IntegratedNexusLoginSystem(options);
856
+
857
+ // Professional logging system
858
+ const Logger = {
859
+ info: (stage, message, details = null) => {
860
+ console.log(`\x1b[36m[INFO]\x1b[0m \x1b[32m[${stage}]\x1b[0m ${message}`);
861
+ if (details && options.verbose) console.log(`\x1b[90m → ${details}\x1b[0m`);
862
+ },
863
+ success: (stage, message, details = null) => {
864
+ console.log(`\x1b[32m[SUCCESS]\x1b[0m \x1b[32m[${stage}]\x1b[0m ${message}`);
865
+ if (details && options.verbose) console.log(`\x1b[90m → ${details}\x1b[0m`);
866
+ },
867
+ warn: (stage, message, details = null) => {
868
+ console.log(`\x1b[33m[WARN]\x1b[0m \x1b[33m[${stage}]\x1b[0m ${message}`);
869
+ if (details) console.log(`\x1b[90m → ${details}\x1b[0m`);
870
+ },
871
+ error: (stage, message, details = null) => {
872
+ console.log(`\x1b[31m[ERROR]\x1b[0m \x1b[31m[${stage}]\x1b[0m ${message}`);
873
+ if (details) console.log(`\x1b[90m → ${details}\x1b[0m`);
874
+ }
875
+ };
876
+
877
+ // Phase 1: Secure authentication and session generation
878
+ Logger.info('AUTH', 'Initializing secure authentication');
879
+ Logger.info('SECURE-LOGIN', 'Establishing secure connection to Facebook');
880
+
856
881
  const result = await loginSystem.login(credentials);
857
882
 
858
- if (result.success && options.autoStartBot !== false) {
859
- // Auto-start Nexus-FCA with the generated appstate
883
+ if (!result.success) {
884
+ Logger.error('AUTH', 'Authentication failed', result.message);
885
+ return result;
886
+ }
887
+
888
+ Logger.success('AUTH', 'Authentication completed successfully');
889
+ Logger.info('SESSION', `Login method: ${result.method} | Status: Active`);
890
+
891
+ if (options.autoStartBot !== false && result.appstate) {
892
+ // Phase 2: Start Nexus-FCA bot with authenticated session
893
+ Logger.info('BOT-INIT', 'Initializing bot with secure session');
894
+
860
895
  try {
896
+ // Prepare global options for bot system
897
+ const globalOptions = {
898
+ selfListen: false,
899
+ selfListenEvent: false,
900
+ listenEvents: false,
901
+ listenTyping: false,
902
+ updatePresence: false,
903
+ forceLogin: false,
904
+ autoMarkDelivery: true,
905
+ autoMarkRead: false,
906
+ autoReconnect: true,
907
+ logRecordSize: defaultLogRecordSize,
908
+ online: true,
909
+ emitReady: false,
910
+ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36",
911
+ ...options
912
+ };
913
+
861
914
  return new Promise((resolve) => {
862
- login({ appState: result.appstate }, options, (err, api) => {
915
+ // Initialize Nexus-FCA bot with authenticated session
916
+ Logger.info('BOT-INIT', 'Loading bot API systems');
917
+
918
+ loginHelper(result.appstate, null, null, globalOptions, (err, api) => {
863
919
  if (err) {
920
+ Logger.error('BOT-INIT', 'Failed to initialize bot API', err.message);
864
921
  resolve({
865
922
  success: true,
866
923
  appstate: result.appstate,
867
924
  method: result.method,
868
- warning: 'Appstate ready but bot startup failed',
925
+ warning: 'Session ready but bot initialization failed',
869
926
  botError: err.message
870
927
  });
871
928
  } else {
929
+ Logger.success('BOT-INIT', 'Bot initialized successfully');
930
+ Logger.success('READY', '🚀 Nexus-FCA is now ready for use');
931
+ Logger.info('STATUS', `Bot online | User ID: ${api.getCurrentUserID()}`);
932
+
872
933
  resolve({
873
934
  success: true,
874
935
  api: api,
875
936
  appstate: result.appstate,
876
937
  method: result.method,
877
- message: 'Nexus-FCA bot started successfully'
938
+ message: 'Nexus-FCA login successful'
878
939
  });
879
940
  }
880
- });
941
+ }, null);
881
942
  });
882
943
  } catch (error) {
944
+ Logger.error('BOT-INIT', 'Exception during bot initialization', error.message);
883
945
  return {
884
946
  success: true,
885
947
  appstate: result.appstate,
886
948
  method: result.method,
887
- warning: 'Appstate ready but bot startup failed',
949
+ warning: 'Session ready but bot initialization failed',
888
950
  botError: error.message
889
951
  };
890
952
  }
891
953
  }
892
954
 
955
+ // Return session-only result (no bot startup)
956
+ Logger.success('SESSION-ONLY', 'Authentication completed successfully');
893
957
  return result;
894
958
  }
895
959
 
@@ -897,46 +961,98 @@ async function integratedNexusLogin(credentials = null, options = {}) {
897
961
  * Modern login entry point using Integrated Nexus Login System
898
962
  * Supports: username/password/2FA, auto appstate, ultra-safe mode
899
963
  * Usage: login({ email, password, twofactor }, options, callback)
964
+ *
965
+ * FLOW:
966
+ * - ID/password: Generates secure session → Starts bot
967
+ * - Appstate only: Uses existing session directly
900
968
  */
901
969
  async function login(loginData, options = {}, callback) {
902
- // Support legacy callback signature
970
+ // Support multiple callback signatures
903
971
  if (typeof options === 'function') {
904
972
  callback = options;
905
973
  options = {};
906
974
  }
907
975
 
908
- // Use Integrated Nexus Login System for ID/pass login, or legacy for appstate-only
976
+ // Professional logging
977
+ const mainLogger = {
978
+ info: (message, details = null) => {
979
+ console.log(`\x1b[36m[NEXUS-FCA]\x1b[0m ${message}`);
980
+ if (details && options.verbose) console.log(`\x1b[90m → ${details}\x1b[0m`);
981
+ },
982
+ error: (message, details = null) => {
983
+ console.log(`\x1b[31m[NEXUS-FCA]\x1b[0m \x1b[31m${message}\x1b[0m`);
984
+ if (details) console.log(`\x1b[90m → ${details}\x1b[0m`);
985
+ }
986
+ };
987
+
988
+ // Enhanced login flow for ID/password authentication
909
989
  if (loginData.email || loginData.username || loginData.password) {
990
+ mainLogger.info('🔐 Starting secure authentication');
991
+ mainLogger.info('🛡️ Generating secure session with new system');
992
+
910
993
  try {
994
+ // STEP 1: Use NEW system ONLY to generate appstate/cookies
911
995
  const result = await integratedNexusLogin({
912
996
  username: loginData.email || loginData.username,
913
997
  password: loginData.password,
914
998
  twofactor: loginData.twofactor || loginData.otp || undefined,
915
999
  _2fa: loginData._2fa || undefined,
916
1000
  appstate: loginData.appState || loginData.appstate || undefined
917
- }, options);
1001
+ }, { autoStartBot: false }); // ONLY generate cookies, NO bot startup
918
1002
 
919
- if (result.success && result.api) {
920
- if (callback) return callback(null, result.api);
921
- return result.api;
922
- } else {
1003
+ if (!result.success || !result.appstate) {
1004
+ mainLogger.error('❌ Authentication failed', result.message);
923
1005
  if (callback) return callback(new Error(result.message || 'Login failed'));
924
1006
  throw new Error(result.message || 'Login failed');
925
1007
  }
1008
+
1009
+ mainLogger.info('✅ Session generated successfully');
1010
+ mainLogger.info('🔄 Starting bot with generated session (old system)');
1011
+
1012
+ // STEP 2: ALWAYS use OLD system for actual login/session/bot
1013
+ const globalOptions = {
1014
+ selfListen: false,
1015
+ selfListenEvent: false,
1016
+ listenEvents: false,
1017
+ listenTyping: false,
1018
+ updatePresence: false,
1019
+ forceLogin: false,
1020
+ autoMarkDelivery: true,
1021
+ autoMarkRead: false,
1022
+ autoReconnect: true,
1023
+ logRecordSize: defaultLogRecordSize,
1024
+ online: true,
1025
+ emitReady: false,
1026
+ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36",
1027
+ ...options
1028
+ };
1029
+
1030
+ return loginHelper(
1031
+ result.appstate, // Use generated appstate
1032
+ null, // No email for old system
1033
+ null, // No password for old system
1034
+ globalOptions,
1035
+ callback,
1036
+ null
1037
+ );
1038
+
926
1039
  } catch (error) {
927
- log.error('login', "Nexus Login System error: " + error.message);
1040
+ mainLogger.error('💥 Login error', error.message);
928
1041
  if (callback) return callback(error);
929
1042
  throw error;
930
1043
  }
931
1044
  } else {
932
- // Legacy appstate-only login
1045
+ // Appstate-only authentication (direct session authentication)
933
1046
  if (!loginData.appState && !loginData.appstate) {
934
- const error = new Error('Username and password are required for login, or provide appState for legacy login.');
1047
+ const error = new Error('Username and password are required for login, or provide appState for session authentication.');
1048
+ mainLogger.error('❌ No credentials provided', 'Either provide ID/password or appstate');
935
1049
  if (callback) return callback(error);
936
1050
  throw error;
937
1051
  }
938
1052
 
939
- // Legacy appstate login
1053
+ // Direct session authentication using appstate
1054
+ mainLogger.info('� Starting session authentication');
1055
+
940
1056
  const globalOptions = {
941
1057
  selfListen: false,
942
1058
  selfListenEvent: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexus-fca",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "description": "A modern, safe, and advanced Facebook Chat API for Node.js with fully integrated Nexus Login System. NPM-ready with ID/password/2FA support, ultra-low ban rate protection, and zero external dependencies.",
5
5
  "main": "index.js",
6
6
  "repository": {
package/src/listenMqtt.js CHANGED
@@ -197,8 +197,12 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
197
197
  connectTimeout: 5000,
198
198
  };
199
199
  if (ctx.globalOptions.proxy !== undefined) {
200
- const agent = new HttpsProxyAgent(ctx.globalOptions.proxy);
201
- options.wsOptions.agent = agent;
200
+ try {
201
+ const agent = new HttpsProxyAgent(ctx.globalOptions.proxy);
202
+ options.wsOptions.agent = agent;
203
+ } catch (error) {
204
+ log.error("listenMqtt", `Failed to create proxy agent: ${error.message}`);
205
+ }
202
206
  }
203
207
  ctx.mqttClient = new mqtt.Client(
204
208
  () =>