nexus-fca 2.1.6 → 2.1.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/CHANGELOG.md +16 -0
- package/README.md +81 -34
- package/index.js +21 -8
- package/lib/safety/FacebookSafety.js +20 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.1.7] - 2025-09-01 - Session Stability Patch
|
|
4
|
+
### Added
|
|
5
|
+
- User-Agent continuity (anchored single UA for entire session via safety module; eliminates mid-session UA drift increasing 20–22h expiry risk).
|
|
6
|
+
- Exposed `setFixedUserAgent()` in `FacebookSafety` to allow explicit anchoring from credential phase.
|
|
7
|
+
- Mid-session lightweight token poke (6h ±40m) to keep session warm without full heavy refresh cycle.
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
- Removed legacy mobile agent override fallback in `loginHelper` that caused mixed UA fingerprints.
|
|
11
|
+
- All safe requests now inherit continuity-aware UA through `applySafeRequestOptions`.
|
|
12
|
+
|
|
13
|
+
### Improved
|
|
14
|
+
- Extended resilience against 20–22h cookie invalidation observed with prior dual-phase UA pattern.
|
|
15
|
+
- Reduced unnecessary full refresh churn while preserving stealth (`safeRefresh` + light poke coexist).
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
3
19
|
## [2.1.6] - 2025-08-31 - Memory Guard & Queue Sweeping
|
|
4
20
|
### Added
|
|
5
21
|
- Central lightweight memory guard sweeps: group queue pruning (idle >30m, overflow trim) and pendingEdits TTL sweeper (every 4m).
|
package/README.md
CHANGED
|
@@ -1,33 +1,75 @@
|
|
|
1
|
-
# Nexus-FCA v2.1.
|
|
1
|
+
# Nexus-FCA v2.1.7
|
|
2
2
|
|
|
3
|
-
<!-- 2.1.
|
|
4
|
-
> New in 2.1.
|
|
3
|
+
<!-- 2.1.7 Session Stability Patch -->
|
|
4
|
+
> New in 2.1.7: Session Stability Patch – anchored User-Agent continuity (eliminates 20–22h silent expiry pattern), lightweight mid‑session token poke (6h ±40m) + existing adaptive safeRefresh, retains ultra‑low ban profile.
|
|
5
|
+
|
|
6
|
+
<!-- 2.1.6 Memory Guard -->
|
|
7
|
+
> 2.1.6: Memory Guard & Queue Sweeping – bounded group queues, pending edit TTL sweeper, memory metrics exporter.
|
|
8
|
+
|
|
9
|
+
<!-- 2.1.5 PendingEdits -->
|
|
10
|
+
> 2.1.5: PendingEdits buffer (cap + TTL + safe resend), edit ACK watchdog, p95 ACK latency & edit resend/failure metrics, configurable via `api.setEditOptions()`.
|
|
5
11
|
|
|
6
12
|
<p align="center">
|
|
7
13
|
<!-- Preview image wrapped in link (corrected ibb.co domain) -->
|
|
8
14
|
<a href="https://ibb.co/8ymR1tw"><img src="https://i.ibb.co/Sk61FGg/Dragon-Fruit-1.jpg" alt="Nexus-FCA Dragon Fruit" width="520" border="0" /></a>
|
|
9
15
|
</p>
|
|
10
16
|
|
|
11
|
-
> Advanced, safe, modern Facebook Chat (Messenger) API with integrated secure login (ID / Password / 2FA), ultra‑low ban rate session management, MQTT
|
|
17
|
+
> Advanced, safe, modern Facebook Chat (Messenger) API with integrated secure login (ID / Password / 2FA), ultra‑low ban rate session management, adaptive MQTT resilience, memory guard, and TypeScript-ready developer experience.
|
|
12
18
|
|
|
13
19
|
---
|
|
14
|
-
## ✨ Highlights
|
|
20
|
+
## ✨ Highlights (Core Pillars)
|
|
15
21
|
- 🔐 Integrated secure login system (username/password + TOTP 2FA) → auto appstate
|
|
16
|
-
- 🛡️ Ultra-low ban rate design (human timing, safety limiter, risk heuristics)
|
|
17
|
-
- 🔄 Resilient MQTT listener (
|
|
18
|
-
-
|
|
19
|
-
- 🧠 Smart session validation (multi-endpoint retry, reduced false logouts)
|
|
20
|
-
-
|
|
21
|
-
- 🧩 Modular architecture (safety, performance, error, mqtt managers)
|
|
22
|
-
- 🗂️ Rich feature docs in `/docs` (thread, message, reactions, attachments)
|
|
22
|
+
- 🛡️ Ultra-low ban rate design (human timing, safety limiter, anchored UA, risk heuristics)
|
|
23
|
+
- 🔄 Resilient MQTT listener (adaptive backoff + idle / ghost detection + periodic recycle)
|
|
24
|
+
- ♻️ Session continuity: anchored UA + adaptive safe refresh + lightweight mid-session poke
|
|
25
|
+
- 🧠 Smart session validation (lazy preflight, multi-endpoint retry, reduced false logouts)
|
|
26
|
+
- 📊 Live health & memory metrics (`api.getHealthMetrics()`, `api.getMemoryMetrics()`)
|
|
23
27
|
- 🧾 Type definitions (`index.d.ts`) & modern Promise / callback API
|
|
28
|
+
- 🧩 Modular architecture (safety, performance, error, mqtt managers)
|
|
24
29
|
|
|
25
30
|
---
|
|
26
|
-
## 🚀
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
## 🚀 Recent Stability Enhancements (2.1.7 / 2.1.6 / 2.1.5)
|
|
32
|
+
| Version | Focus | Key Additions |
|
|
33
|
+
|---------|-------|---------------|
|
|
34
|
+
| 2.1.7 | Session Longevity | UA continuity anchor, lightweight token poke, removal of mid-login UA drift |
|
|
35
|
+
| 2.1.6 | Memory Safety | Group queue idle purge + overflow trim, pendingEdits TTL sweeper, memory guard metrics |
|
|
36
|
+
| 2.1.5 | Edit Reliability | PendingEdits buffer (cap+TTL), ACK watchdog, resend limits, p95 ACK latency |
|
|
37
|
+
|
|
38
|
+
### Why UA Continuity Matters
|
|
39
|
+
Previously, dual-phase login could swap user agents (mobile → desktop) causing server-side heuristic expiry near 20–22h. Anchoring a single UA eliminates the inconsistent device fingerprint pattern and extends stable runtime under identical safety posture.
|
|
40
|
+
|
|
41
|
+
### Lightweight Mid-Session Poke
|
|
42
|
+
A subtle `fb_dtsg` refresh every ~6h ±40m (in addition to adaptive risk-based safeRefresh) keeps tokens warm without aggressive churn, lowering validation friction while avoiding noisy traffic patterns.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
## 🧪 Key API Additions
|
|
46
|
+
```js
|
|
47
|
+
api.setEditOptions({ maxPendingEdits, editTTLms, ackTimeoutMs, maxResendAttempts });
|
|
48
|
+
api.setBackoffOptions({ base, factor, max, jitter });
|
|
49
|
+
api.enableLazyPreflight(true); // Skip heavy validation if a recent good connect exists
|
|
50
|
+
api.getHealthMetrics(); // uptime, reconnect stats, ack latency, synthetic keepalives
|
|
51
|
+
api.getMemoryMetrics(); // queue depths, drops, guard run counters
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
## 🔍 Monitoring Example
|
|
56
|
+
```js
|
|
57
|
+
setInterval(() => {
|
|
58
|
+
const h = api.getHealthMetrics();
|
|
59
|
+
const m = api.getMemoryMetrics();
|
|
60
|
+
console.log('[HEALTH]', h?.status, 'acks', h?.ackCount, 'p95Ack', h?.p95AckLatencyMs);
|
|
61
|
+
console.log('[MEM]', m);
|
|
62
|
+
}, 60000);
|
|
29
63
|
```
|
|
30
64
|
|
|
65
|
+
---
|
|
66
|
+
## 🧷 Long Session Best Practices
|
|
67
|
+
1. Use appstate login when possible (avoid frequent credential logins).
|
|
68
|
+
2. Keep `persistent-device.json` – do not rotate unless forced.
|
|
69
|
+
3. Avoid changing UA manually; continuity is automatic post‑2.1.7.
|
|
70
|
+
4. Inspect health metrics before manually forcing reconnects.
|
|
71
|
+
5. Let adaptive backoff handle transient network instability.
|
|
72
|
+
|
|
31
73
|
---
|
|
32
74
|
## ⚡ Quick Start (Appstate)
|
|
33
75
|
```js
|
|
@@ -61,14 +103,17 @@ const login = require('nexus-fca');
|
|
|
61
103
|
```
|
|
62
104
|
|
|
63
105
|
---
|
|
64
|
-
## 🛡️ Safety Layer (
|
|
106
|
+
## 🛡️ Safety Layer (Updated)
|
|
65
107
|
| Feature | Benefit |
|
|
66
108
|
|---------|---------|
|
|
67
|
-
|
|
|
68
|
-
|
|
|
69
|
-
|
|
|
70
|
-
|
|
|
71
|
-
|
|
|
109
|
+
| Anchored User-Agent | Eliminates fingerprint drift (prevents 20–22h expiry) |
|
|
110
|
+
| Adaptive Safe Refresh | Risk‑sensitive token renewal bands |
|
|
111
|
+
| Lightweight Token Poke | Quiet longevity without churn |
|
|
112
|
+
| Idle / Ghost Detection | Auto probe + reconnect on silent stalls |
|
|
113
|
+
| Periodic Recycle | 6h ± jitter connection rejuvenation |
|
|
114
|
+
| Persistent Device Profile | Fewer checkpoints / trust continuity |
|
|
115
|
+
| Lazy Preflight | Skips heavy validation when recently healthy |
|
|
116
|
+
| Human-like Timing | Reduces automation signal surface |
|
|
72
117
|
|
|
73
118
|
Disable preflight if needed:
|
|
74
119
|
```js
|
|
@@ -77,13 +122,14 @@ await login({ appState }, { disablePreflight: true });
|
|
|
77
122
|
|
|
78
123
|
---
|
|
79
124
|
## 🛰️ MQTT Listener Enhancements
|
|
80
|
-
-
|
|
81
|
-
-
|
|
82
|
-
-
|
|
125
|
+
- Adaptive exponential backoff with jitter (caps 5m)
|
|
126
|
+
- Soft-stale probing (2m30s) + hard watchdog tiers
|
|
127
|
+
- Layered post-refresh health checks (1s / 10s / 30s) after token renewal
|
|
128
|
+
- Synthetic keepalives (randomized 55–75s) feeding metrics
|
|
83
129
|
|
|
84
130
|
---
|
|
85
131
|
## 📦 Example Echo Test
|
|
86
|
-
`examples/echo-test.js
|
|
132
|
+
`examples/echo-test.js`:
|
|
87
133
|
```bash
|
|
88
134
|
node examples/echo-test.js
|
|
89
135
|
```
|
|
@@ -91,9 +137,9 @@ Provide `appstate.json` or set `EMAIL` / `PASSWORD` env variables.
|
|
|
91
137
|
|
|
92
138
|
---
|
|
93
139
|
## 🧠 Advanced Login Flow
|
|
94
|
-
1.
|
|
95
|
-
2.
|
|
96
|
-
3.
|
|
140
|
+
1. Integrated system safely generates / refreshes cookies (if credentials supplied)
|
|
141
|
+
2. Core consumes resulting appstate for stable API behavior
|
|
142
|
+
3. Persistent device JSON: `persistent-device.json`
|
|
97
143
|
|
|
98
144
|
Persistent device toggle:
|
|
99
145
|
```js
|
|
@@ -174,15 +220,16 @@ const login = require('nexus-fca');
|
|
|
174
220
|
- Examples: `/examples`
|
|
175
221
|
|
|
176
222
|
---
|
|
177
|
-
## 🔁 Updating from 2.0.x → 2.1.
|
|
223
|
+
## 🔁 Updating from 2.0.x → 2.1.x
|
|
178
224
|
| Change | Action |
|
|
179
225
|
|--------|--------|
|
|
180
|
-
|
|
|
181
|
-
|
|
|
182
|
-
|
|
|
183
|
-
|
|
|
226
|
+
| UA Continuity (2.1.7) | No action; auto applied |
|
|
227
|
+
| Memory Guard (2.1.6) | Inspect `api.getMemoryMetrics()` periodically |
|
|
228
|
+
| PendingEdits (2.1.5) | Tune via `api.setEditOptions()` if needed |
|
|
229
|
+
| Lazy Preflight | Optionally disable when embedding in other frameworks |
|
|
230
|
+
| Persistent Device | Keep file unless forced reset required |
|
|
184
231
|
|
|
185
|
-
No breaking API changes.
|
|
232
|
+
No breaking API changes across 2.1.x line.
|
|
186
233
|
|
|
187
234
|
---
|
|
188
235
|
## ⚠️ Disclaimer
|
package/index.js
CHANGED
|
@@ -428,7 +428,8 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
|
|
|
428
428
|
return callback(new Error(`Login Safety Check Failed: ${safetyCheck.reason}`));
|
|
429
429
|
}
|
|
430
430
|
|
|
431
|
-
//
|
|
431
|
+
// Establish continuity user agent ONCE (credential/appstate phase)
|
|
432
|
+
if(!globalSafety._fixedUA){ globalSafety.setFixedUserAgent(globalSafety.getSafeUserAgent()); }
|
|
432
433
|
globalOptions.userAgent = globalSafety.getSafeUserAgent();
|
|
433
434
|
|
|
434
435
|
if (appState) {
|
|
@@ -448,7 +449,7 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
|
|
|
448
449
|
jar.setCookie(str, "http://" + c.domain);
|
|
449
450
|
});
|
|
450
451
|
|
|
451
|
-
// Apply safety headers
|
|
452
|
+
// Apply safety headers with continuity UA
|
|
452
453
|
mainPromise = utils.get('https://www.facebook.com/', jar, null,
|
|
453
454
|
globalSafety.applySafeRequestOptions(globalOptions), { noRef: true })
|
|
454
455
|
.then(utils.saveCookies(jar));
|
|
@@ -463,7 +464,7 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
|
|
|
463
464
|
const reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
|
|
464
465
|
const redirect = reg.exec(res.body);
|
|
465
466
|
if (redirect && redirect[1]) {
|
|
466
|
-
return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
|
|
467
|
+
return utils.get(redirect[1], jar, null, globalSafety.applySafeRequestOptions(globalOptions)).then(utils.saveCookies(jar));
|
|
467
468
|
}
|
|
468
469
|
return res;
|
|
469
470
|
}
|
|
@@ -472,11 +473,7 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
|
|
|
472
473
|
mainPromise = mainPromise
|
|
473
474
|
.then(handleRedirect)
|
|
474
475
|
.then(res => {
|
|
475
|
-
|
|
476
|
-
if (!mobileAgentRegex.test(res.body)) {
|
|
477
|
-
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";
|
|
478
|
-
return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
|
|
479
|
-
}
|
|
476
|
+
// Remove UA override logic to maintain continuity (previous mobileAgentRegex swap)
|
|
480
477
|
return res;
|
|
481
478
|
})
|
|
482
479
|
.then(handleRedirect)
|
|
@@ -508,6 +505,22 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
|
|
|
508
505
|
logger('✅ Session authenticated successfully', 'info');
|
|
509
506
|
// Initialize safety monitoring
|
|
510
507
|
globalSafety.startMonitoring(ctx, api);
|
|
508
|
+
// Schedule mid-session lightweight token poke (~ every 6h ±40m) to keep cookies warm
|
|
509
|
+
if(!globalOptions._lightRefreshTimer){
|
|
510
|
+
const scheduleLight = () => {
|
|
511
|
+
const base = 6 * 60 * 60 * 1000; // 6h
|
|
512
|
+
const jitter = (Math.random()*80 - 40) * 60 * 1000; // ±40m
|
|
513
|
+
globalOptions._lightRefreshTimer = setTimeout(async () => {
|
|
514
|
+
try {
|
|
515
|
+
if(api && typeof api.refreshFb_dtsg === 'function'){
|
|
516
|
+
await api.refreshFb_dtsg().catch(()=>{});
|
|
517
|
+
}
|
|
518
|
+
} catch(_) {}
|
|
519
|
+
scheduleLight();
|
|
520
|
+
}, base + jitter);
|
|
521
|
+
};
|
|
522
|
+
scheduleLight();
|
|
523
|
+
}
|
|
511
524
|
// Post-login identity banner
|
|
512
525
|
try {
|
|
513
526
|
const uid = api.getCurrentUserID && api.getCurrentUserID();
|
|
@@ -18,6 +18,8 @@ class FacebookSafety {
|
|
|
18
18
|
enableSafeDelays: true,
|
|
19
19
|
bypassRegionLock: true,
|
|
20
20
|
ultraLowBanMode: true,
|
|
21
|
+
// NEW: ensure a single stable UA across entire session lifecycle
|
|
22
|
+
enableUAContinuity: true,
|
|
21
23
|
...options
|
|
22
24
|
};
|
|
23
25
|
|
|
@@ -29,6 +31,8 @@ class FacebookSafety {
|
|
|
29
31
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
|
30
32
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36'
|
|
31
33
|
];
|
|
34
|
+
// NEW: fixed user agent anchor (set once per session)
|
|
35
|
+
this._fixedUA = null;
|
|
32
36
|
|
|
33
37
|
this.safeDomains = [
|
|
34
38
|
'https://www.facebook.com',
|
|
@@ -88,9 +92,23 @@ class FacebookSafety {
|
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
/**
|
|
91
|
-
*
|
|
95
|
+
* Allow external code to explicitly anchor the session UA (e.g. carry over from credential phase)
|
|
96
|
+
*/
|
|
97
|
+
setFixedUserAgent(ua){
|
|
98
|
+
if(!ua || typeof ua !== 'string') return;
|
|
99
|
+
this._fixedUA = ua;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Get safe user agent that reduces detection risk (now continuity‑aware)
|
|
92
104
|
*/
|
|
93
105
|
getSafeUserAgent() {
|
|
106
|
+
if (this.options.enableUAContinuity) {
|
|
107
|
+
if (this._fixedUA) return this._fixedUA;
|
|
108
|
+
// choose once then cache
|
|
109
|
+
this._fixedUA = this.safeUserAgents[Math.floor(Math.random() * this.safeUserAgents.length)];
|
|
110
|
+
return this._fixedUA;
|
|
111
|
+
}
|
|
94
112
|
return this.safeUserAgents[Math.floor(Math.random() * this.safeUserAgents.length)];
|
|
95
113
|
}
|
|
96
114
|
|
|
@@ -146,7 +164,7 @@ class FacebookSafety {
|
|
|
146
164
|
maxRedirects: 5
|
|
147
165
|
};
|
|
148
166
|
|
|
149
|
-
// Apply
|
|
167
|
+
// Apply stable user agent (continuity aware)
|
|
150
168
|
safeOptions.userAgent = this.getSafeUserAgent();
|
|
151
169
|
|
|
152
170
|
return safeOptions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nexus-fca",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.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": {
|