nexus-fca 2.0.3 → 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 +10 -0
- package/index.js +186 -34
- package/nexloginsystem/NexusLoginSystem.js +611 -0
- package/nexloginsystem/README.md +510 -0
- package/nexloginsystem/examples.js +150 -0
- package/nexloginsystem/index.js +247 -0
- package/package.json +2 -1
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,8 +256,121 @@ function buildAPI(globalOptions, html, jar) {
|
|
|
256
256
|
};
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
+
// Legacy login helper function for appstate-only login
|
|
260
|
+
function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
|
|
261
|
+
let mainPromise = null;
|
|
262
|
+
const jar = utils.getJar();
|
|
263
|
+
|
|
264
|
+
// Apply maximum safety validation
|
|
265
|
+
const safetyCheck = globalSafety.validateLogin(appState, email, password);
|
|
266
|
+
if (!safetyCheck.safe) {
|
|
267
|
+
return callback(new Error(`Login Safety Check Failed: ${safetyCheck.reason}`));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Apply safe user agent from safety module
|
|
271
|
+
globalOptions.userAgent = globalSafety.getSafeUserAgent();
|
|
272
|
+
|
|
273
|
+
if (appState) {
|
|
274
|
+
try {
|
|
275
|
+
appState = JSON.parse(appState);
|
|
276
|
+
} catch (e) {
|
|
277
|
+
try {
|
|
278
|
+
appState = appState;
|
|
279
|
+
} catch (e) {
|
|
280
|
+
return callback(new Error("Failed to parse appState"));
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
try {
|
|
285
|
+
appState.forEach(c => {
|
|
286
|
+
const str = `${c.key}=${c.value}; expires=${c.expires}; domain=${c.domain}; path=${c.path};`;
|
|
287
|
+
jar.setCookie(str, "http://" + c.domain);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// Apply safety headers and no delays for maximum safety
|
|
291
|
+
mainPromise = utils.get('https://www.facebook.com/', jar, null,
|
|
292
|
+
globalSafety.applySafeRequestOptions(globalOptions), { noRef: true })
|
|
293
|
+
.then(utils.saveCookies(jar));
|
|
294
|
+
} catch (e) {
|
|
295
|
+
return callback(new Error("Invalid appState format"));
|
|
296
|
+
}
|
|
297
|
+
} else {
|
|
298
|
+
return callback(new Error("AppState is required for legacy login"));
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function handleRedirect(res) {
|
|
302
|
+
const reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
|
|
303
|
+
const redirect = reg.exec(res.body);
|
|
304
|
+
if (redirect && redirect[1]) {
|
|
305
|
+
return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
|
|
306
|
+
}
|
|
307
|
+
return res;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
let ctx, api;
|
|
311
|
+
mainPromise = mainPromise
|
|
312
|
+
.then(handleRedirect)
|
|
313
|
+
.then(res => {
|
|
314
|
+
const mobileAgentRegex = /MPageLoadClientMetrics/gs;
|
|
315
|
+
if (!mobileAgentRegex.test(res.body)) {
|
|
316
|
+
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";
|
|
317
|
+
return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
|
|
318
|
+
}
|
|
319
|
+
return res;
|
|
320
|
+
})
|
|
321
|
+
.then(handleRedirect)
|
|
322
|
+
.then(res => {
|
|
323
|
+
const html = res.body;
|
|
324
|
+
const Obj = buildAPI(globalOptions, html, jar);
|
|
325
|
+
ctx = Obj.ctx;
|
|
326
|
+
api = Obj.api;
|
|
327
|
+
return res;
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
if (globalOptions.pageID) {
|
|
331
|
+
mainPromise = mainPromise
|
|
332
|
+
.then(() => utils.get(`https://www.facebook.com/${globalOptions.pageID}/messages/?section=messages&subsection=inbox`, jar, null, globalOptions))
|
|
333
|
+
.then(resData => {
|
|
334
|
+
let url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
|
|
335
|
+
url = url.substring(0, url.length - 1);
|
|
336
|
+
return utils.get('https://www.facebook.com' + url, jar, null, globalOptions);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
mainPromise
|
|
341
|
+
.then(async () => {
|
|
342
|
+
// Enhanced safety check after login
|
|
343
|
+
const safetyStatus = globalSafety.validateSession(ctx);
|
|
344
|
+
if (!safetyStatus.safe) {
|
|
345
|
+
logger(`⚠️ Login safety warning: ${safetyStatus.reason}`, 'warn');
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
logger('Legacy login successful!', 'info');
|
|
349
|
+
|
|
350
|
+
// Initialize safety monitoring
|
|
351
|
+
globalSafety.startMonitoring(ctx, api);
|
|
352
|
+
|
|
353
|
+
callback(null, api);
|
|
354
|
+
})
|
|
355
|
+
.catch(e => {
|
|
356
|
+
// Enhanced error handling with safety checks
|
|
357
|
+
const safetyCheck = globalSafety.checkErrorSafety(e);
|
|
358
|
+
if (!safetyCheck.safe) {
|
|
359
|
+
logger(`🚨 SAFETY ALERT: ${safetyCheck.danger} - ${e.message}`, 'error');
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
callback(e);
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
259
366
|
// --- REPLACE LEGACY LOGIN WITH NEXUS LOGIN SYSTEM ---
|
|
260
|
-
|
|
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
|
+
}
|
|
261
374
|
|
|
262
375
|
/**
|
|
263
376
|
* Modern login entry point using Nexus Login System
|
|
@@ -270,40 +383,79 @@ async function login(loginData, options = {}, callback) {
|
|
|
270
383
|
callback = options;
|
|
271
384
|
options = {};
|
|
272
385
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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');
|
|
402
|
+
}
|
|
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;
|
|
287
414
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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
|
|
432
|
+
};
|
|
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
|
+
);
|
|
291
442
|
}
|
|
292
443
|
}
|
|
293
444
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
445
|
+
// Enhanced exports
|
|
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;
|
|
453
|
+
module.exports.NexusClient = NexusClient;
|
|
454
|
+
module.exports.PerformanceManager = PerformanceManager;
|
|
455
|
+
module.exports.ErrorHandler = ErrorHandler;
|
|
456
|
+
module.exports.AdvancedMqttManager = AdvancedMqttManager;
|
|
457
|
+
module.exports.EnhancedDatabase = EnhancedDatabase;
|
|
458
|
+
module.exports.CompatibilityLayer = CompatibilityLayer;
|
|
459
|
+
module.exports.Message = Message;
|
|
460
|
+
module.exports.Thread = Thread;
|
|
461
|
+
module.exports.User = User;
|