@lazyneoaz/testfca 1.0.0

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 (120) hide show
  1. package/CHANGELOG.md +229 -0
  2. package/COOKIE_LOGIN.md +208 -0
  3. package/LICENSE +3 -0
  4. package/README.md +492 -0
  5. package/index.js +2 -0
  6. package/package.json +120 -0
  7. package/scripts/build-go.mjs +54 -0
  8. package/scripts/detect-platform.mjs +36 -0
  9. package/scripts/download-prebuilt.mjs +119 -0
  10. package/scripts/package.mjs +6 -0
  11. package/scripts/postinstall.mjs +113 -0
  12. package/src/apis/addExternalModule.js +24 -0
  13. package/src/apis/addUserToGroup.js +108 -0
  14. package/src/apis/changeAdminStatus.js +148 -0
  15. package/src/apis/changeArchivedStatus.js +61 -0
  16. package/src/apis/changeAvatar.js +103 -0
  17. package/src/apis/changeBio.js +69 -0
  18. package/src/apis/changeBlockedStatus.js +54 -0
  19. package/src/apis/changeGroupImage.js +136 -0
  20. package/src/apis/changeThreadColor.js +116 -0
  21. package/src/apis/changeThreadEmoji.js +53 -0
  22. package/src/apis/comment.js +207 -0
  23. package/src/apis/createAITheme.js +129 -0
  24. package/src/apis/createNewGroup.js +79 -0
  25. package/src/apis/createPoll.js +73 -0
  26. package/src/apis/deleteMessage.js +52 -0
  27. package/src/apis/deleteThread.js +52 -0
  28. package/src/apis/e2ee.js +170 -0
  29. package/src/apis/editMessage.js +78 -0
  30. package/src/apis/emoji.js +124 -0
  31. package/src/apis/fetchThemeData.js +82 -0
  32. package/src/apis/follow.js +81 -0
  33. package/src/apis/forwardMessage.js +52 -0
  34. package/src/apis/friend.js +243 -0
  35. package/src/apis/gcmember.js +122 -0
  36. package/src/apis/gcname.js +123 -0
  37. package/src/apis/gcrule.js +119 -0
  38. package/src/apis/getAccess.js +111 -0
  39. package/src/apis/getBotInfo.js +88 -0
  40. package/src/apis/getBotInitialData.js +43 -0
  41. package/src/apis/getFriendsList.js +79 -0
  42. package/src/apis/getMessage.js +423 -0
  43. package/src/apis/getTheme.js +95 -0
  44. package/src/apis/getThemeInfo.js +116 -0
  45. package/src/apis/getThreadHistory.js +239 -0
  46. package/src/apis/getThreadInfo.js +267 -0
  47. package/src/apis/getThreadList.js +232 -0
  48. package/src/apis/getThreadPictures.js +58 -0
  49. package/src/apis/getUserID.js +117 -0
  50. package/src/apis/getUserInfo.js +513 -0
  51. package/src/apis/getUserInfoV2.js +146 -0
  52. package/src/apis/handleMessageRequest.js +50 -0
  53. package/src/apis/httpGet.js +63 -0
  54. package/src/apis/httpPost.js +89 -0
  55. package/src/apis/httpPostFormData.js +69 -0
  56. package/src/apis/listenMqtt.js +1236 -0
  57. package/src/apis/listenSpeed.js +179 -0
  58. package/src/apis/logout.js +93 -0
  59. package/src/apis/markAsDelivered.js +47 -0
  60. package/src/apis/markAsRead.js +115 -0
  61. package/src/apis/markAsReadAll.js +40 -0
  62. package/src/apis/markAsSeen.js +70 -0
  63. package/src/apis/mqttDeltaValue.js +250 -0
  64. package/src/apis/muteThread.js +45 -0
  65. package/src/apis/nickname.js +132 -0
  66. package/src/apis/notes.js +163 -0
  67. package/src/apis/pinMessage.js +150 -0
  68. package/src/apis/produceMetaTheme.js +180 -0
  69. package/src/apis/realtime.js +182 -0
  70. package/src/apis/removeUserFromGroup.js +117 -0
  71. package/src/apis/resolvePhotoUrl.js +58 -0
  72. package/src/apis/searchForThread.js +154 -0
  73. package/src/apis/sendMessage.js +346 -0
  74. package/src/apis/sendMessageMqtt.js +248 -0
  75. package/src/apis/sendTypingIndicator.js +105 -0
  76. package/src/apis/setMessageReaction.js +38 -0
  77. package/src/apis/setMessageReactionMqtt.js +61 -0
  78. package/src/apis/setThreadTheme.js +260 -0
  79. package/src/apis/setThreadThemeMqtt.js +94 -0
  80. package/src/apis/share.js +107 -0
  81. package/src/apis/shareContact.js +66 -0
  82. package/src/apis/stickers.js +257 -0
  83. package/src/apis/story.js +181 -0
  84. package/src/apis/theme.js +233 -0
  85. package/src/apis/unfriend.js +47 -0
  86. package/src/apis/unsendMessage.js +25 -0
  87. package/src/database/appStateBackup.js +298 -0
  88. package/src/database/models/index.js +56 -0
  89. package/src/database/models/thread.js +31 -0
  90. package/src/database/models/user.js +32 -0
  91. package/src/database/threadData.js +101 -0
  92. package/src/database/userData.js +90 -0
  93. package/src/e2ee/bridge.js +275 -0
  94. package/src/e2ee/index.js +60 -0
  95. package/src/engine/client.js +95 -0
  96. package/src/engine/models/buildAPI.js +152 -0
  97. package/src/engine/models/loginHelper.js +574 -0
  98. package/src/engine/models/setOptions.js +88 -0
  99. package/src/types/index.d.ts +574 -0
  100. package/src/utils/antiSuspension.js +529 -0
  101. package/src/utils/auth-helpers.js +149 -0
  102. package/src/utils/autoReLogin.js +336 -0
  103. package/src/utils/axios.js +436 -0
  104. package/src/utils/cache.js +54 -0
  105. package/src/utils/clients.js +282 -0
  106. package/src/utils/constants.js +410 -0
  107. package/src/utils/formatters/data/formatAttachment.js +370 -0
  108. package/src/utils/formatters/data/formatDelta.js +109 -0
  109. package/src/utils/formatters/index.js +159 -0
  110. package/src/utils/formatters/value/formatCookie.js +91 -0
  111. package/src/utils/formatters/value/formatDate.js +36 -0
  112. package/src/utils/formatters/value/formatID.js +16 -0
  113. package/src/utils/formatters.js +1373 -0
  114. package/src/utils/headers.js +235 -0
  115. package/src/utils/index.js +153 -0
  116. package/src/utils/monitoring.js +333 -0
  117. package/src/utils/rateLimiter.js +319 -0
  118. package/src/utils/tokenRefresh.js +680 -0
  119. package/src/utils/user-agents.js +238 -0
  120. package/src/utils/validation.js +157 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,229 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ---
9
+
10
+ ## [1.0.6] - 2026-03-31
11
+
12
+ ### Fixed
13
+
14
+ **Session & Long-Term Stability**
15
+ - `sendTypingIndicator`: Now verifies `ctx.mqttClient` exists before publishing. Removed unreliable string-length heuristic for group detection — uses API lookup with per-session cache, same as `sendMessage`. Added 8-second timeout so a disconnected MQTT client can no longer hang the call indefinitely.
16
+ - `markAsRead`: Replaced a bare Promise that could hang forever if the MQTT client was silently disconnected. Publish now times out after 8 seconds and rejects cleanly.
17
+ - `logout`: After successful logout, sensitive tokens (`fb_dtsg`, `fb_dtsg_ag`, `lsd`, `access_token`) are cleared from context so stale credentials cannot be reused. Background timers (token refresh, session monitor, cookie backup) are stopped. The response cache is cleared.
18
+ - `buildAPI`: Wrapped `new URL(mqttEndpoint)` in a try/catch — a malformed or missing MQTT endpoint in the page HTML no longer throws an unhandled exception during login.
19
+
20
+ **Headers**
21
+ - `headers.js`: Spin params (`X-Fb-Spin-R/B/T`) were reading from `ctx.master`, which is never set anywhere in the codebase. Fixed to read `ctx.__spin_r`, `ctx.__spin_b`, `ctx.__spin_t` directly, since `buildAPI` spreads them into ctx. Affects both desktop and Android header paths.
22
+
23
+ **Rate Limiter / Concurrency**
24
+ - `rateLimiter.js`: `checkRateLimit` now returns a `release()` function instead of using a hard-coded 1-second `setTimeout` to decrement `activeRequests`. The slot is now released exactly when the request finishes, not after an arbitrary delay — preventing both premature slot release (too fast requests) and slot starvation (slow requests).
25
+ - `axios.js`: `requestWithRetry` calls `checkRateLimit` with the endpoint hint and wraps the entire retry loop in `try/finally` to guarantee the concurrency slot is always released regardless of success or failure.
26
+
27
+ **API Correctness**
28
+ - `sendMessage.js`: Error message for invalid `replyToMessage` type was reporting `threadIDType` instead of `messageIDType`.
29
+
30
+ **Branding & Documentation**
31
+ - All `dhoner-fca` references in `README.md`, `COOKIE_LOGIN.md`, `examples/verify.js`, `src/utils/constants.js`, and `src/utils/antiSuspension.js` updated to `@neoaz07/nkxfca`.
32
+ - Removed empty `examples/ping.js`.
33
+ - `.gitignore` cleaned of unrelated entries; `.npmignore` added to explicitly exclude Replit-specific files from the published package.
34
+
35
+ ---
36
+
37
+ ## [1.0.5] - 2026-03-31
38
+
39
+ ### Fixed
40
+
41
+ **MQTT**
42
+ - `clientId` randomized per session — was hardcoded to `"mqttwsclient"`, causing the server to immediately kick existing connections on reconnect
43
+ - `unsubAll` now has a 3-second safety timeout so a stale network cannot permanently block the reconnect path
44
+
45
+ **HTTP / Axios**
46
+ - `postFormData` argument order corrected — `ctx` was not being passed, silently bypassing auth detection on file uploads
47
+ - `auto_login` flag resets after 2 minutes via safety timer — a crashed re-login attempt can no longer permanently suppress future session expiry detection
48
+
49
+ **Session Validation**
50
+ - `isSessionValid` no longer requires the user ID in the response body — removes false-negatives that triggered unnecessary re-logins
51
+
52
+ **Token & Cookie Persistence**
53
+ - AppState (cookies) now saved to the database after every token refresh, not only at initial login — prevents stale credentials after restart
54
+
55
+ **Re-Login**
56
+ - Re-login race condition fixed — multiple concurrent session-expiry detections no longer all attempt their own re-login simultaneously
57
+ - `SIGINT`/`SIGTERM` process handlers no longer accumulate across re-logins — registered once per process
58
+
59
+ **Cookie Backup**
60
+ - Cookies now saved to the database every 15 minutes (previously only at login)
61
+
62
+ ---
63
+
64
+ ## [1.0.0] - 2026-03-14
65
+
66
+ Initial public release of **nkxfca** — a full rewrite/rebranding of the FCA-KEX engine.
67
+ Developed and maintained by [NeoKEX](https://github.com/NeoKEX).
68
+
69
+ ### Added
70
+
71
+ **Core**
72
+ - Login via `appState` cookie arrays (supports `name/value`, `key/value`, and cookie strings)
73
+ - Multi-persona support: `desktop` (Chrome/Edge) and `android/mobile` personas
74
+ - Real-time MQTT messaging with `listenMqtt` and `sendMessageMqtt`
75
+ - HTTP send with automatic MQTT fallback (`sendMessage`)
76
+ - MQTT auto-reconnect with exponential backoff and jitter
77
+ - MQTT watchdog timer to detect and recover from idle/stale connections
78
+ - `TokenRefreshManager` with randomized refresh intervals to avoid detectable periodicity
79
+ - `AutoReLogin` using refreshed AppState on session expiry
80
+ - AppState backup/restore to disk to survive crashes
81
+ - SQLite-backed thread and user data caching via Sequelize
82
+
83
+ **Anti-Suspension System**
84
+ - `AntiSuspension` class with circuit breaker — trips after repeated suspension signals
85
+ - Expanded suspension signal detection: 60+ patterns covering checkpoints, spam flags, session expiry, rate limits, policy violations, identity verification, and more
86
+ - Adaptive per-thread message delay that scales with session volume
87
+ - Hourly and daily volume limits with automatic warning pauses
88
+ - `checkVolumeLimit()` called before every `sendMessage` and `sendMessageMqtt` send
89
+ - Warmup mode — reduced hourly limit for fresh sessions
90
+ - Session fingerprint locking: User-Agent, Sec-Ch-Ua, locale, timezone locked per session
91
+ - `safeRetry()` with suspension-aware exponential backoff
92
+ - `batchOperations()` for safe, sequential multi-send workflows
93
+
94
+ **API Methods**
95
+ - `api.sendMessage`, `api.sendMessageMqtt`, `api.listenMqtt`
96
+ - `api.editMessage`, `api.unsendMessage`, `api.forwardMessage`, `api.deleteMessage`
97
+ - `api.setMessageReaction`, `api.setMessageReactionMqtt`, `api.pinMessage`
98
+ - `api.sendTypingIndicator`, `api.markAsRead`, `api.markAsReadAll`, `api.markAsSeen`, `api.markAsDelivered`
99
+ - `api.getThreadInfo`, `api.getThreadList`, `api.getThreadHistory`, `api.getThreadPictures`
100
+ - `api.getMessage`, `api.getUserInfo`, `api.getUserInfoV2`, `api.getUserID`
101
+ - `api.getFriendsList`, `api.friend`, `api.unfriend`, `api.searchForThread`
102
+ - `api.createNewGroup`, `api.addUserToGroup`, `api.removeUserFromGroup`, `api.changeAdminStatus`
103
+ - `api.changeGroupImage`, `api.changeThreadColor`, `api.changeThreadEmoji`
104
+ - `api.gcname`, `api.emoji`, `api.nickname`, `api.theme`, `api.muteThread`
105
+ - `api.createPoll`, `api.handleMessageRequest`, `api.changeBlockedStatus`
106
+ - `api.changeAvatar`, `api.changeBio`, `api.comment`, `api.share`, `api.follow`
107
+ - `api.getTheme`, `api.getThemeInfo`, `api.setThreadTheme`, `api.setThreadThemeMqtt`
108
+ - `api.createAITheme`, `api.stickers.*`, `api.e2ee.*`
109
+ - `api.getHealthStatus`, `api.httpGet`, `api.httpPost`, `api.httpPostFormData`
110
+ - `api.addExternalModule`, `api.shareContact`, `api.resolvePhotoUrl`, `api.logout`
111
+
112
+ **TypeScript Support**
113
+ - Full `index.d.ts` with all methods, events, options, and types
114
+
115
+ **Production Monitoring**
116
+ - `ProductionMonitor` — request counts, error rates, response times, rate limit telemetry
117
+
118
+ ---
119
+
120
+ > **Developed and maintained by [NeoKEX](https://github.com/NeoKEX)**
121
+ > Inspired by **ws3-fca** and **@dongdev/fca-unofficial**
122
+
123
+ ### Fixed
124
+
125
+ **MQTT Reliability**
126
+ - `close` handler now captures `wasConnected` before clearing `ctx._mqttConnected`, so the quick-close detection window is evaluated correctly instead of always being skipped
127
+ - Re-auth triggered by the quick-close threshold now `return`s immediately, preventing a duplicate reconnect from the normal backoff path racing against it
128
+ - `offline` event now schedules a backoff reconnect after ending the client — previously the bot would silently stay offline with no recovery
129
+ - Added `maxReconnectAttempts` cap (default 100): after hitting the cap the library pauses 10 minutes before resetting, preventing an indefinite 30 s retry loop that is a detectable bot pattern
130
+
131
+ **Session & Auth**
132
+ - `stopListening` now stops the token-refresh manager and session monitor — they were continuing to hit Facebook endpoints after the bot was asked to stop
133
+ - `api.isSessionValid` replaced the full homepage fetch (~400 kB) with a lightweight presence-ping endpoint, reducing bandwidth and detection surface
134
+ - `startSessionMonitoring(api)` moved to after `api.isSessionValid` is registered in `loginHelper`, so the health-check interval can actually invoke it (previously it was called 70 lines before `api.isSessionValid` existed)
135
+ - `setCredentials` now resets `retryCount = 0` on every fresh login, preventing 3 prior re-login failures from permanently locking out future re-logins for the process lifetime
136
+
137
+ **Core**
138
+ - Internal `listenMqtt` function now receives `emitAuthError` as a parameter at both call sites; previously both callers omitted it, causing a `ReferenceError` whenever an auth error arrived on the MQTT connection
139
+
140
+ ---
141
+
142
+ ## [1.0.0] - 2026-03-14
143
+
144
+ Initial public release of **dhoner-fca** — a full rewrite/rebranding of the FCA-KEX engine.
145
+ Developed and maintained by [NeoKEX](https://github.com/NeoKEX).
146
+
147
+ ### Added
148
+
149
+ **Core**
150
+ - Login via `appState` cookie arrays (supports `name/value`, `key/value`, and cookie strings)
151
+ - Multi-persona support: `desktop` (Chrome/Edge) and `android/mobile` personas
152
+ - Real-time MQTT messaging with `listenMqtt` and `sendMessageMqtt`
153
+ - HTTP send with automatic MQTT fallback (`sendMessage`)
154
+ - MQTT auto-reconnect with exponential backoff and jitter
155
+ - MQTT watchdog timer to detect and recover from idle/stale connections
156
+ - `TokenRefreshManager` with randomized refresh intervals to avoid detectable periodicity
157
+ - `AutoReLogin` using refreshed AppState on session expiry
158
+ - AppState backup/restore to disk to survive crashes
159
+ - SQLite-backed thread and user data caching via Sequelize
160
+
161
+ **Anti-Suspension System**
162
+ - `AntiSuspension` class with circuit breaker — trips after repeated suspension signals
163
+ - Expanded suspension signal detection: 60+ patterns covering checkpoints, spam flags, session expiry, rate limits, policy violations, identity verification, and more
164
+ - Adaptive per-thread message delay that scales with session volume
165
+ - Hourly and daily volume limits with automatic warning pauses
166
+ - `checkVolumeLimit()` called before every `sendMessage` and `sendMessageMqtt` send
167
+ - Warmup mode — reduced hourly limit for fresh sessions
168
+ - Session fingerprint locking: User-Agent, Sec-Ch-Ua, locale, timezone locked per session
169
+ - `safeRetry()` with suspension-aware exponential backoff
170
+ - `batchOperations()` for safe, sequential multi-send workflows
171
+ - MQTT Sec-Ch-Ua header updated to Chrome 136 (matching default User-Agent)
172
+ - PostSafe guard on HTTP post to detect auth failures in real-time
173
+
174
+ **API Methods**
175
+ - `api.sendMessage(msg, threadID)` — HTTP send with MQTT fallback
176
+ - `api.sendMessageMqtt(msg, threadID)` — MQTT send
177
+ - `api.listenMqtt(callback)` — real-time event listener
178
+ - `api.editMessage(text, messageID)` — in-place message edit
179
+ - `api.unsendMessage(messageID, threadID)` — retract a message
180
+ - `api.forwardMessage(messageID, threadID)` — forward a message
181
+ - `api.deleteMessage(messageIDs)` — delete locally
182
+ - `api.setMessageReaction(reaction, messageID)` — react via HTTP
183
+ - `api.setMessageReactionMqtt(reaction, messageID, threadID)` — react via MQTT
184
+ - `api.pinMessage(action, threadID, messageID?)` — pin/unpin/list pins
185
+ - `api.sendTypingIndicator(isTyping, threadID)` — typing status
186
+ - `api.markAsRead/markAsReadAll/markAsSeen/markAsDelivered` — message status
187
+ - `api.getThreadInfo/getThreadList/getThreadHistory/getThreadPictures` — thread data
188
+ - `api.getMessage(messageID)` — fetch a specific message
189
+ - `api.getUserInfo/getUserInfoV2/getUserID` — user data
190
+ - `api.getFriendsList/friend/unfriend` — friends management
191
+ - `api.searchForThread(name)` — search threads by name
192
+ - `api.createNewGroup/addUserToGroup/removeUserFromGroup/changeAdminStatus` — group admin
193
+ - `api.changeGroupImage/changeThreadColor/changeThreadEmoji` — group customization
194
+ - `api.gcname/emoji/nickname/theme` — per-thread personalization
195
+ - `api.muteThread/changeArchivedStatus/deleteThread` — thread management
196
+ - `api.createPoll` — create a poll in a thread
197
+ - `api.handleMessageRequest` — accept/decline message requests
198
+ - `api.changeBlockedStatus/changeAvatar/changeBio` — account actions
199
+ - `api.comment/share/follow` — social interactions
200
+ - `api.getTheme/getThemeInfo/setThreadTheme/setThreadThemeMqtt` — Messenger themes
201
+ - `api.createAITheme(prompt)` — generate AI-powered chat themes
202
+ - `api.stickers.search/listPacks/getStorePacks/addPack/getStickersInPack/getAiStickers` — sticker API
203
+ - `api.e2ee.enable/disable/getPublicKey/setPeerKey/encrypt/decrypt` — application-layer E2EE (X25519 + HKDF + AES-256-GCM)
204
+ - `api.getHealthStatus()` — MQTT, token refresh, and rate limiter telemetry
205
+ - `api.httpGet/httpPost/httpPostFormData` — raw HTTP helpers
206
+ - `api.addExternalModule(moduleObj)` — extend the API at runtime
207
+ - `api.shareContact/resolvePhotoUrl/getAccess/logout/getAppState/getCurrentUserID`
208
+ - `api.notes/gcrule/gcmember/story/realtime/getBotInfo/getBotInitialData/getUserInfoV2` — extended APIs
209
+
210
+ **TypeScript Support**
211
+ - Full `index.d.ts` with all methods, events, options, and types exported under `declare module "dhoner-fca"`
212
+
213
+ **Production Monitoring**
214
+ - `ProductionMonitor` — request counts, error rates, response times, rate limit telemetry
215
+ - `api.getHealthStatus()` providing MQTT, token refresh, and rate limiter stats
216
+
217
+ ### Fixed
218
+ - Sec-Ch-Ua MQTT header aligned with Chrome 136 User-Agent (was Chrome 131)
219
+ - `sendMessageMqtt` now calls `prepareBeforeMessage` before every send
220
+ - `sendMessage` now calls `prepareBeforeMessage` before every send
221
+ - Volume limit checks (`isDailyLimitReached`, `isHourlyLimitReached`) now apply to both send paths
222
+ - TypeScript: removed duplicate `API` interface declaration and stray closing brace
223
+ - Database path renamed from `fca_kex_database` to `dhoner_fca_database`
224
+ - Credits function updated to reference `dhoner-fca` and `github.com/NeoKEX`
225
+
226
+ ---
227
+
228
+ > **Developed and maintained by [NeoKEX](https://github.com/NeoKEX)**
229
+ > Inspired by **ws3-fca** and **@dongdev/fca-unofficial**
@@ -0,0 +1,208 @@
1
+ # Login with Cookie Array
2
+
3
+ **nkxfca** supports multiple authentication methods. This guide explains how to login using a cookie array instead of email/password credentials.
4
+
5
+ > **Credits:** Developed and maintained by [NeoKEX](https://github.com/NeoKEX)
6
+
7
+ ---
8
+
9
+ ## Quick Start
10
+
11
+ ```javascript
12
+ const { login } = require('@neoaz07/nkxfca');
13
+
14
+ const cookieArray = [
15
+ { name: 'c_user', value: 'YOUR_USER_ID' },
16
+ { name: 'xs', value: 'YOUR_SESSION_TOKEN' },
17
+ { name: 'fr', value: 'YOUR_FR_TOKEN' },
18
+ { name: 'datr', value: 'YOUR_DEVICE_TOKEN' }
19
+ ];
20
+
21
+ login({ appState: cookieArray }, {}, (err, api) => {
22
+ if (err) return console.error('Login failed:', err);
23
+ console.log('Logged in as:', api.getCurrentUserID());
24
+ });
25
+ ```
26
+
27
+ ---
28
+
29
+ ## Supported Cookie Formats
30
+
31
+ ### 1. Cookie Array with `name` property (Recommended)
32
+ ```javascript
33
+ const appState = [
34
+ { name: 'c_user', value: '123456789' },
35
+ { name: 'xs', value: 'abc123...' },
36
+ // ... more cookies
37
+ ];
38
+
39
+ login({ appState });
40
+ ```
41
+
42
+ ### 2. Cookie Array with `key` property
43
+ ```javascript
44
+ const appState = [
45
+ { key: 'c_user', value: '123456789' },
46
+ { key: 'xs', value: 'abc123...' },
47
+ ];
48
+
49
+ login({ appState });
50
+ ```
51
+
52
+ ### 3. Cookie String
53
+ ```javascript
54
+ const cookieString = 'c_user=123456789; xs=abc123...; fr=xyz...; datr=...';
55
+
56
+ login({ appState: cookieString });
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Essential Cookies
62
+
63
+ | Cookie | Purpose | Notes |
64
+ |--------|---------|-------|
65
+ | `c_user` | User ID | Your Facebook user ID |
66
+ | `xs` | Session Token | Authentication token, required |
67
+ | `fr` | Fraud Detection | Device/browser fingerprint |
68
+ | `datr` | Device Token | Device identifier |
69
+
70
+ ---
71
+
72
+ ## How to Extract Cookies from Browser
73
+
74
+ ### Chrome / Firefox / Edge
75
+ 1. Navigate to `facebook.com` and log in normally
76
+ 2. Open Developer Tools — press **F12**
77
+ 3. Go to **Application** → **Cookies** → **facebook.com**
78
+ 4. Find and copy these cookies: `c_user`, `xs`, `fr`, `datr`
79
+
80
+ ### Export as Array (from browser console)
81
+ ```javascript
82
+ copy(JSON.stringify(
83
+ document.cookie.split('; ').map(c => {
84
+ const [name, ...rest] = c.split('=');
85
+ return { name, value: rest.join('=') };
86
+ })
87
+ ))
88
+ ```
89
+
90
+ ### Using a Browser Extension
91
+ - **Chrome/Edge:** "C3C FbState" or "CookieEditor"
92
+ - **Firefox:** "Cookie-Editor"
93
+
94
+ Export the cookies as JSON and save as `appstate.json`.
95
+
96
+ ---
97
+
98
+ ## Complete Example
99
+
100
+ ```javascript
101
+ const fs = require('fs');
102
+ const { login } = require('@neoaz07/nkxfca');
103
+
104
+ const appState = JSON.parse(fs.readFileSync('appstate.json', 'utf8'));
105
+
106
+ login({ appState }, {
107
+ online: true,
108
+ listenEvents: true,
109
+ autoMarkRead: true,
110
+ autoReconnect: true,
111
+ simulateTyping: true
112
+ }, (err, api) => {
113
+ if (err) return console.error('Login failed:', err);
114
+
115
+ console.log('Logged in as:', api.getCurrentUserID());
116
+
117
+ api.listenMqtt((err, event) => {
118
+ if (err || event.type !== 'message') return;
119
+ console.log(`[${event.threadID}] ${event.senderID}: ${event.body}`);
120
+ });
121
+ });
122
+ ```
123
+
124
+ ---
125
+
126
+ ## Cookie Refresh
127
+
128
+ Facebook cookies may expire after hours or days. If login fails:
129
+ 1. Log in to Facebook in your browser
130
+ 2. Export fresh cookies using a browser extension
131
+ 3. Replace your `appstate.json` with the new cookies
132
+ 4. Restart your bot
133
+
134
+ ---
135
+
136
+ ## Security Notes
137
+
138
+ - **Never commit `appstate.json` to version control**
139
+ - **Never share your cookies publicly**
140
+ - Store cookies in environment variables or secure files (`.env`, secrets manager)
141
+ - Rotate cookies periodically for long-running bots
142
+ - Each cookie set is tied to a specific browser/device session — do not reuse across machines
143
+
144
+ ---
145
+
146
+ ## Troubleshooting
147
+
148
+ ### Login Fails with Cookie Array
149
+ - Ensure `c_user` and `xs` cookies are present
150
+ - Check if the cookies are expired — extract fresh ones from your browser
151
+ - Verify cookie format: array of objects with `name` and `value` (or `key` and `value`)
152
+ - Make sure you are using cookies from a logged-in Facebook session
153
+
154
+ ### Cookies Expire Quickly
155
+ - Facebook cookies expire faster when used from a new IP or User-Agent
156
+ - Use a consistent residential proxy to extend cookie life
157
+ - Avoid switching network locations frequently
158
+
159
+ ### Account Suspended / Checkpoint
160
+ - Stop all bot activity immediately
161
+ - Complete any Facebook security check in your browser
162
+ - Wait at least 24–48 hours before resuming
163
+ - Reduce message frequency and enable warmup mode on restart
164
+
165
+ ---
166
+
167
+ ## Alternative: Email/Password Login
168
+
169
+ > Email/password login is not recommended for bots — it triggers stricter security checks.
170
+
171
+ ```javascript
172
+ login({
173
+ email: 'your-email@example.com',
174
+ password: 'your-password'
175
+ }, {}, (err, api) => {
176
+ if (err) return console.error(err);
177
+ console.log('Logged in:', api.getCurrentUserID());
178
+ });
179
+ ```
180
+
181
+ ---
182
+
183
+ ## AppState Backup
184
+
185
+ **nkxfca** automatically saves and restores your session state internally.
186
+ To manually save the current session after login:
187
+
188
+ ```javascript
189
+ const fs = require('fs');
190
+
191
+ login({ appState }, {}, (err, api) => {
192
+ if (err) return;
193
+ // Save refreshed appState
194
+ fs.writeFileSync('appstate.json', JSON.stringify(api.getAppState(), null, 2));
195
+ });
196
+ ```
197
+
198
+ ---
199
+
200
+ ## See Also
201
+ - [README.md](./README.md) — Full feature overview
202
+ - [examples/](./examples/) — Working code examples
203
+ - [CHANGELOG.md](./CHANGELOG.md) — Version history
204
+
205
+ ---
206
+
207
+ > **Credits:** nkxfca is developed and maintained by [NeoKEX](https://github.com/NeoKEX).
208
+ > Inspired by **ws3-fca** and **@dongdev/fca-unofficial**
package/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ All rights reserved to NeoKEX(github.com/NeoKEX)
2
+ ❌ PLEASE DO NOT STOLE MY SOURCE CODES AND CLAIM AS YOURS
3
+ Thanks for supporting ^_^