nexus-fca 2.0.2 → 2.0.4

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 CHANGED
@@ -1,6 +1,16 @@
1
1
  #
2
2
  # Changelog
3
3
  #
4
+ ## [2.0.4] - 2025-07-29
5
+ ### Fixed
6
+ - 🐛 **Missing nexloginsystem folder**: Added `nexloginsystem/` to npm package files array to fix "Cannot find module './nexloginsystem'" error
7
+ - 🔄 **Legacy login fallback**: Added automatic fallback to appstate-only login when Nexus Login System is not available
8
+ - 🛡️ **Backward compatibility**: Enhanced compatibility for users using nexus-fca as npm dependency without full login system
9
+
10
+ ### Changed
11
+ - Updated package.json to include nexloginsystem folder in published package
12
+ - Enhanced error handling with graceful fallback mechanisms
13
+
4
14
  ## [2.0.1] - 2025-07-28
5
15
  ### Added
6
16
  - 🚀 **Nexus Login System**: Advanced, safe, and automatic Facebook login system added under `/nexloginsystem`.
package/index.js CHANGED
@@ -256,6 +256,7 @@ function buildAPI(globalOptions, html, jar) {
256
256
  };
257
257
  }
258
258
 
259
+ // Legacy login helper function for appstate-only login
259
260
  function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
260
261
  let mainPromise = null;
261
262
  const jar = utils.getJar();
@@ -291,16 +292,10 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
291
292
  globalSafety.applySafeRequestOptions(globalOptions), { noRef: true })
292
293
  .then(utils.saveCookies(jar));
293
294
  } catch (e) {
294
- process.exit(0);
295
+ return callback(new Error("Invalid appState format"));
295
296
  }
296
297
  } else {
297
- mainPromise = utils
298
- .get("https://www.facebook.com/", null, null,
299
- globalSafety.applySafeRequestOptions(globalOptions), { noRef: true })
300
- .then(utils.saveCookies(jar))
301
- .then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
302
- .then(() => utils.get('https://www.facebook.com/', jar, null,
303
- globalSafety.applySafeRequestOptions(globalOptions)).then(utils.saveCookies(jar)));
298
+ return callback(new Error("AppState is required for legacy login"));
304
299
  }
305
300
 
306
301
  function handleRedirect(res) {
@@ -350,11 +345,8 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
350
345
  logger(`⚠️ Login safety warning: ${safetyStatus.reason}`, 'warn');
351
346
  }
352
347
 
353
- // No version checking or auto-update for maximum safety and performance
354
- logger('Login successful!', 'info');
355
- logger('Nexus 2.0 (Enhanced)', 'info');
356
- logger('Operating Normally', 'info');
357
-
348
+ logger('Legacy login successful!', 'info');
349
+
358
350
  // Initialize safety monitoring
359
351
  globalSafety.startMonitoring(ctx, api);
360
352
 
@@ -371,71 +363,93 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
371
363
  });
372
364
  }
373
365
 
374
- function login(loginData, options, callback) {
375
- if (
376
- utils.getType(options) === "Function" ||
377
- utils.getType(options) === "AsyncFunction"
378
- ) {
366
+ // --- REPLACE LEGACY LOGIN WITH NEXUS LOGIN SYSTEM ---
367
+ let nexusLogin;
368
+ try {
369
+ ({ nexusLogin } = require('./nexloginsystem'));
370
+ } catch (err) {
371
+ console.warn('Warning: Nexus Login System not found. Using legacy login fallback.');
372
+ // Legacy login fallback will be implemented below
373
+ }
374
+
375
+ /**
376
+ * Modern login entry point using Nexus Login System
377
+ * Supports: username/password/2FA, auto appstate, ultra-safe mode
378
+ * Usage: login({ email, password, twofactor }, options, callback)
379
+ */
380
+ async function login(loginData, options = {}, callback) {
381
+ // Support legacy callback signature
382
+ if (typeof options === 'function') {
379
383
  callback = options;
380
384
  options = {};
381
385
  }
382
- const globalOptions = {
383
- selfListen: false,
384
- selfListenEvent: false,
385
- listenEvents: false,
386
- listenTyping: false,
387
- updatePresence: false,
388
- forceLogin: false,
389
- autoMarkDelivery: true,
390
- autoMarkRead: false,
391
- autoReconnect: true,
392
- logRecordSize: defaultLogRecordSize,
393
- online: true,
394
- emitReady: false,
395
- userAgent:
396
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36",
397
- };
398
- setOptions(globalOptions, options);
399
- let prCallback = null;
400
- if (
401
- utils.getType(callback) !== "Function" &&
402
- utils.getType(callback) !== "AsyncFunction"
403
- ) {
404
- let rejectFunc = null;
405
- let resolveFunc = null;
406
- var returnPromise = new Promise(function (resolve, reject) {
407
- resolveFunc = resolve;
408
- rejectFunc = reject;
409
- });
410
- prCallback = function (error, api) {
411
- if (error) {
412
- return rejectFunc(error);
386
+
387
+ // Use Nexus Login System if available, otherwise fallback to legacy
388
+ if (nexusLogin) {
389
+ try {
390
+ const result = await nexusLogin({
391
+ username: loginData.email || loginData.username,
392
+ password: loginData.password,
393
+ twofactor: loginData.twofactor || loginData.otp || undefined,
394
+ appstate: loginData.appState || loginData.appstate || undefined
395
+ }, options);
396
+ if (result.success && result.api) {
397
+ if (callback) return callback(null, result.api);
398
+ return result.api;
399
+ } else {
400
+ if (callback) return callback(new Error(result.message || 'Login failed'));
401
+ throw new Error(result.message || 'Login failed');
413
402
  }
414
- return resolveFunc(api);
403
+ } catch (error) {
404
+ log.error('login', "Nexus Login System error: " + error.message);
405
+ if (callback) return callback(error);
406
+ throw error;
407
+ }
408
+ } else {
409
+ // Legacy login fallback (direct appstate login only)
410
+ if (!loginData.appState && !loginData.appstate) {
411
+ const error = new Error('Nexus Login System not available. Please provide appState for legacy login or install the complete package.');
412
+ if (callback) return callback(error);
413
+ throw error;
414
+ }
415
+
416
+ // Legacy appstate login
417
+ const globalOptions = {
418
+ selfListen: false,
419
+ selfListenEvent: false,
420
+ listenEvents: false,
421
+ listenTyping: false,
422
+ updatePresence: false,
423
+ forceLogin: false,
424
+ autoMarkDelivery: true,
425
+ autoMarkRead: false,
426
+ autoReconnect: true,
427
+ logRecordSize: defaultLogRecordSize,
428
+ online: true,
429
+ emitReady: false,
430
+ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36",
431
+ ...options
415
432
  };
416
- callback = prCallback;
433
+
434
+ return loginHelper(
435
+ loginData.appState || loginData.appstate,
436
+ null, // No email for appstate login
437
+ null, // No password for appstate login
438
+ globalOptions,
439
+ callback,
440
+ null
441
+ );
417
442
  }
418
-
419
- // Initialize enhanced systems before login
420
- enhancedDatabase.initialize().catch(err => {
421
- logger('Failed to initialize enhanced database:', err);
422
- });
423
-
424
- loginHelper(
425
- loginData.appState,
426
- loginData.email,
427
- loginData.password,
428
- globalOptions,
429
- callback,
430
- prCallback
431
- );
432
- return returnPromise;
433
443
  }
434
444
 
435
- const enhancedDatabase = new EnhancedDatabase();
436
-
437
445
  // Enhanced exports
438
446
  module.exports = login;
447
+ module.exports.buildAPI = buildAPI;
448
+ module.exports.login = login;
449
+ module.exports.setOptions = setOptions;
450
+ module.exports.utils = utils;
451
+ module.exports.logger = logger;
452
+ module.exports.FacebookSafety = FacebookSafety;
439
453
  module.exports.NexusClient = NexusClient;
440
454
  module.exports.PerformanceManager = PerformanceManager;
441
455
  module.exports.ErrorHandler = ErrorHandler;