nexus-fca 2.0.2 → 2.0.3

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 (2) hide show
  1. package/index.js +44 -182
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -256,192 +256,54 @@ function buildAPI(globalOptions, html, jar) {
256
256
  };
257
257
  }
258
258
 
259
- function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
260
- let mainPromise = null;
261
- const jar = utils.getJar();
262
-
263
- // Apply maximum safety validation
264
- const safetyCheck = globalSafety.validateLogin(appState, email, password);
265
- if (!safetyCheck.safe) {
266
- return callback(new Error(`Login Safety Check Failed: ${safetyCheck.reason}`));
267
- }
268
-
269
- // Apply safe user agent from safety module
270
- globalOptions.userAgent = globalSafety.getSafeUserAgent();
271
-
272
- if (appState) {
273
- try {
274
- appState = JSON.parse(appState);
275
- } catch (e) {
276
- try {
277
- appState = appState;
278
- } catch (e) {
279
- return callback(new Error("Failed to parse appState"));
280
- }
281
- }
282
-
283
- try {
284
- appState.forEach(c => {
285
- const str = `${c.key}=${c.value}; expires=${c.expires}; domain=${c.domain}; path=${c.path};`;
286
- jar.setCookie(str, "http://" + c.domain);
287
- });
288
-
289
- // Apply safety headers and no delays for maximum safety
290
- mainPromise = utils.get('https://www.facebook.com/', jar, null,
291
- globalSafety.applySafeRequestOptions(globalOptions), { noRef: true })
292
- .then(utils.saveCookies(jar));
293
- } catch (e) {
294
- process.exit(0);
295
- }
296
- } 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)));
304
- }
305
-
306
- function handleRedirect(res) {
307
- const reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
308
- const redirect = reg.exec(res.body);
309
- if (redirect && redirect[1]) {
310
- return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
311
- }
312
- return res;
313
- }
314
-
315
- let ctx, api;
316
- mainPromise = mainPromise
317
- .then(handleRedirect)
318
- .then(res => {
319
- const mobileAgentRegex = /MPageLoadClientMetrics/gs;
320
- if (!mobileAgentRegex.test(res.body)) {
321
- globalOptions.userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36";
322
- return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
323
- }
324
- return res;
325
- })
326
- .then(handleRedirect)
327
- .then(res => {
328
- const html = res.body;
329
- const Obj = buildAPI(globalOptions, html, jar);
330
- ctx = Obj.ctx;
331
- api = Obj.api;
332
- return res;
333
- });
259
+ // --- REPLACE LEGACY LOGIN WITH NEXUS LOGIN SYSTEM ---
260
+ const { nexusLogin } = require('./nexloginsystem');
334
261
 
335
- if (globalOptions.pageID) {
336
- mainPromise = mainPromise
337
- .then(() => utils.get(`https://www.facebook.com/${globalOptions.pageID}/messages/?section=messages&subsection=inbox`, jar, null, globalOptions))
338
- .then(resData => {
339
- let url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
340
- url = url.substring(0, url.length - 1);
341
- return utils.get('https://www.facebook.com' + url, jar, null, globalOptions);
342
- });
343
- }
344
-
345
- mainPromise
346
- .then(async () => {
347
- // Enhanced safety check after login
348
- const safetyStatus = globalSafety.validateSession(ctx);
349
- if (!safetyStatus.safe) {
350
- logger(`⚠️ Login safety warning: ${safetyStatus.reason}`, 'warn');
351
- }
352
-
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
-
358
- // Initialize safety monitoring
359
- globalSafety.startMonitoring(ctx, api);
360
-
361
- callback(null, api);
362
- })
363
- .catch(e => {
364
- // Enhanced error handling with safety checks
365
- const safetyCheck = globalSafety.checkErrorSafety(e);
366
- if (!safetyCheck.safe) {
367
- logger(`🚨 SAFETY ALERT: ${safetyCheck.danger} - ${e.message}`, 'error');
368
- }
369
-
370
- callback(e);
371
- });
372
- }
373
-
374
- function login(loginData, options, callback) {
375
- if (
376
- utils.getType(options) === "Function" ||
377
- utils.getType(options) === "AsyncFunction"
378
- ) {
262
+ /**
263
+ * Modern login entry point using Nexus Login System
264
+ * Supports: username/password/2FA, auto appstate, ultra-safe mode
265
+ * Usage: login({ email, password, twofactor }, options, callback)
266
+ */
267
+ async function login(loginData, options = {}, callback) {
268
+ // Support legacy callback signature
269
+ if (typeof options === 'function') {
379
270
  callback = options;
380
271
  options = {};
381
272
  }
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);
413
- }
414
- return resolveFunc(api);
415
- };
416
- callback = prCallback;
273
+ // Use Nexus Login System for all logins
274
+ try {
275
+ const result = await nexusLogin({
276
+ username: loginData.email || loginData.username,
277
+ password: loginData.password,
278
+ twofactor: loginData.twofactor || loginData.otp || undefined,
279
+ appstate: loginData.appState || loginData.appstate || undefined
280
+ }, options);
281
+ if (result.success && result.api) {
282
+ if (callback) return callback(null, result.api);
283
+ return result.api;
284
+ } else {
285
+ if (callback) return callback(new Error(result.message || 'Login failed'));
286
+ throw new Error(result.message || 'Login failed');
287
+ }
288
+ } catch (error) {
289
+ log.error('login', "Lỗi không xác định, vui lòng thử lại sau: " + error.message);
290
+ if (callback) return callback(error);
417
291
  }
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
292
  }
434
293
 
435
- const enhancedDatabase = new EnhancedDatabase();
436
-
437
- // Enhanced exports
438
- module.exports = login;
439
- module.exports.NexusClient = NexusClient;
440
- module.exports.PerformanceManager = PerformanceManager;
441
- module.exports.ErrorHandler = ErrorHandler;
442
- module.exports.AdvancedMqttManager = AdvancedMqttManager;
443
- module.exports.EnhancedDatabase = EnhancedDatabase;
444
- module.exports.CompatibilityLayer = CompatibilityLayer;
445
- module.exports.Message = Message;
446
- module.exports.Thread = Thread;
447
- module.exports.User = User;
294
+ module.exports = {
295
+ buildAPI,
296
+ login,
297
+ setOptions,
298
+ utils,
299
+ logger,
300
+ FacebookSafety,
301
+ CompatibilityLayer,
302
+ PerformanceManager,
303
+ ErrorHandler,
304
+ AdvancedMqttManager,
305
+ EnhancedDatabase,
306
+ Message,
307
+ Thread,
308
+ User
309
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexus-fca",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "A modern, safe, and advanced Facebook Chat API for Node.js with enhanced performance, smart caching, and TypeScript support. Messenger automation, bots, and integrations made easy.",
5
5
  "main": "index.js",
6
6
  "repository": {