nexus-fca 1.0.1 → 2.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 (87) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/ENHANCED_DOCS.md +386 -0
  3. package/LICENSE-MIT +21 -21
  4. package/README.md +451 -240
  5. package/docs/Migration-fca-unofficial.md +523 -0
  6. package/docs/NexusClient.md +428 -0
  7. package/docs/README.md +84 -5
  8. package/index.d.ts +1018 -617
  9. package/index.js +399 -361
  10. package/lib/client/NexusClient.js +393 -0
  11. package/lib/command/CommandSystem.js +618 -0
  12. package/lib/compatibility/CompatibilityLayer.js +367 -0
  13. package/lib/compatibility/NexusClient.js +525 -0
  14. package/lib/database/DatabaseManager.js +466 -0
  15. package/lib/database/EnhancedDatabase.js +659 -0
  16. package/lib/database/models/index.js +46 -46
  17. package/lib/database/models/thread.js +30 -30
  18. package/lib/database/threadData.js +92 -92
  19. package/lib/error/ErrorHandler.js +682 -0
  20. package/lib/logger.js +23 -23
  21. package/lib/message/EnhancedMessageHandler.js +510 -0
  22. package/lib/message/Message.js +398 -0
  23. package/lib/message/Thread.js +490 -0
  24. package/lib/message/User.js +429 -0
  25. package/lib/mqtt/AdvancedMqttManager.js +553 -0
  26. package/lib/mqtt/MqttManager.js +456 -0
  27. package/lib/performance/PerformanceManager.js +218 -0
  28. package/lib/performance/PerformanceOptimizer.js +518 -0
  29. package/package.json +123 -90
  30. package/src/addExternalModule.js +19 -19
  31. package/src/addUserToGroup.js +113 -113
  32. package/src/changeAdminStatus.js +79 -79
  33. package/src/changeArchivedStatus.js +55 -55
  34. package/src/changeAvatar.js +126 -126
  35. package/src/changeBio.js +77 -77
  36. package/src/changeBlockedStatus.js +47 -47
  37. package/src/changeGroupImage.js +132 -132
  38. package/src/changeNickname.js +59 -59
  39. package/src/changeThreadColor.js +65 -65
  40. package/src/changeThreadEmoji.js +55 -55
  41. package/src/createNewGroup.js +86 -86
  42. package/src/createPoll.js +71 -71
  43. package/src/deleteMessage.js +56 -56
  44. package/src/deleteThread.js +56 -56
  45. package/src/forwardAttachment.js +60 -60
  46. package/src/getCurrentUserID.js +7 -7
  47. package/src/getEmojiUrl.js +29 -29
  48. package/src/getFriendsList.js +83 -83
  49. package/src/getMessage.js +795 -795
  50. package/src/getThreadHistory.js +666 -666
  51. package/src/getThreadInfo.js +534 -534
  52. package/src/getThreadList.js +191 -191
  53. package/src/getThreadPictures.js +79 -79
  54. package/src/getUserID.js +66 -66
  55. package/src/getUserInfo.js +79 -79
  56. package/src/handleFriendRequest.js +61 -61
  57. package/src/handleMessageRequest.js +65 -65
  58. package/src/httpGet.js +57 -57
  59. package/src/httpPost.js +57 -57
  60. package/src/httpPostFormData.js +63 -63
  61. package/src/listenMqtt.js +1043 -1038
  62. package/src/logout.js +75 -75
  63. package/src/markAsDelivered.js +58 -58
  64. package/src/markAsRead.js +80 -80
  65. package/src/markAsReadAll.js +49 -49
  66. package/src/markAsSeen.js +59 -59
  67. package/src/muteThread.js +52 -52
  68. package/src/postFormData.js +45 -45
  69. package/src/refreshFb_dtsg.js +65 -65
  70. package/src/removeUserFromGroup.js +79 -79
  71. package/src/resolvePhotoUrl.js +45 -45
  72. package/src/searchForThread.js +53 -53
  73. package/src/sendMessage.js +328 -328
  74. package/src/sendMessageMqtt.js +315 -315
  75. package/src/sendTypingIndicator.js +103 -103
  76. package/src/setMessageReaction.js +118 -118
  77. package/src/setPostReaction.js +108 -108
  78. package/src/setTitle.js +86 -86
  79. package/src/shareContact.js +48 -48
  80. package/src/threadColors.js +131 -131
  81. package/src/unfriend.js +52 -52
  82. package/src/unsendMessage.js +49 -49
  83. package/src/uploadAttachment.js +94 -94
  84. package/utils.js +1431 -1431
  85. package/DOCS.md +0 -2047
  86. package/Fca_Database/database.sqlite +0 -0
  87. package/fca-config.json +0 -7
package/CHANGELOG.md CHANGED
@@ -1 +1 @@
1
- #
1
+ #
@@ -0,0 +1,386 @@
1
+ # Nexus-FCA: Enhanced Documentation
2
+
3
+ ## 🚀 What's New in Enhanced Version
4
+
5
+ ### Performance Optimizations
6
+ - **Smart Caching System**: Automatic caching of user info, thread info, and API responses
7
+ - **Request Optimization**: Intelligent batching and rate limiting
8
+ - **Memory Management**: Automatic garbage collection and memory monitoring
9
+ - **Response Time Tracking**: Real-time performance metrics
10
+
11
+ ### Enhanced TypeScript Support
12
+ ```typescript
13
+ import { NexusClient, NexusMessage } from 'nexus-fca';
14
+
15
+ const client = new NexusClient({
16
+ prefix: '!',
17
+ selfListen: false,
18
+ rateLimitEnabled: true
19
+ });
20
+
21
+ client.on('message', (message: NexusMessage) => {
22
+ message.reply('Hello!');
23
+ });
24
+ ```
25
+
26
+ ### Advanced MQTT Connection
27
+ - **Auto-Reconnection**: Exponential backoff with smart retry logic
28
+ - **Connection Stability**: Enhanced error handling and recovery
29
+ - **Real-time Metrics**: Connection quality monitoring
30
+ - **Graceful Disconnection**: Proper cleanup on shutdown
31
+
32
+ ### Database & Caching System
33
+ ```javascript
34
+ // Auto-cached user info
35
+ const userInfo = await api.getUserInfo(userID); // Cached for 1 hour
36
+
37
+ // Auto-cached thread info
38
+ const threadInfo = await api.getThreadInfo(threadID); // Cached for 30 minutes
39
+
40
+ // Custom caching
41
+ await dbManager.setCache('my_key', data, 3600); // 1 hour TTL
42
+ const cachedData = await dbManager.getCache('my_key');
43
+ ```
44
+
45
+ ### Enhanced Error Handling
46
+ ```javascript
47
+ const { NexusError, ValidationError } = require('nexus-fca');
48
+
49
+ try {
50
+ await api.sendMessage('Hello', threadID);
51
+ } catch (error) {
52
+ if (error instanceof ValidationError) {
53
+ console.log('Invalid input:', error.message);
54
+ } else if (error.code === 'RATE_LIMITED') {
55
+ console.log('Rate limited, retrying after:', error.retryAfter);
56
+ }
57
+ }
58
+ ```
59
+
60
+ ### API Compatibility Layer
61
+ ```javascript
62
+ // Discord.js style client
63
+ const { NexusClient } = require('nexus-fca');
64
+
65
+ const client = new NexusClient({
66
+ prefix: '!',
67
+ selfListen: false
68
+ });
69
+
70
+ client.on('ready', (api, userID) => {
71
+ console.log(`Logged in as ${userID}`);
72
+ });
73
+
74
+ client.on('message', (message) => {
75
+ if (message.content === 'ping') {
76
+ message.reply('pong!');
77
+ }
78
+ });
79
+
80
+ client.on('command', ({ name, args, message }) => {
81
+ if (name === 'info') {
82
+ message.reply(`Args: ${args.join(', ')}`);
83
+ }
84
+ });
85
+
86
+ // Login
87
+ await client.loginWithAppState(appState);
88
+ ```
89
+
90
+ ## 🔧 New Features
91
+
92
+ ### 1. Performance Optimizer
93
+ ```javascript
94
+ const { PerformanceOptimizer } = require('nexus-fca');
95
+ const optimizer = PerformanceOptimizer.getInstance();
96
+
97
+ // Get performance report
98
+ const report = optimizer.getPerformanceReport();
99
+ console.log('Memory usage:', report.memory.usage);
100
+ console.log('Cache hit rate:', report.cache.hitRate);
101
+ console.log('Average response time:', report.requests.averageResponseTime);
102
+ ```
103
+
104
+ ### 2. Enhanced Message Objects
105
+ ```javascript
106
+ client.on('message', async (message) => {
107
+ // Rich message object with methods
108
+ await message.reply('Reply to this message');
109
+ await message.react('👍');
110
+ await message.edit('Edited content'); // If message is from bot
111
+ await message.unsend(); // Unsend message
112
+
113
+ // Get additional info
114
+ const thread = await message.getThread();
115
+ const author = await message.getAuthor();
116
+
117
+ console.log('Message ID:', message.id);
118
+ console.log('Content:', message.content);
119
+ console.log('Attachments:', message.attachments);
120
+ console.log('Is from group:', message.isGroup);
121
+ });
122
+ ```
123
+
124
+ ### 3. Smart Command Loading
125
+ ```javascript
126
+ // Create commands directory structure
127
+ mkdir commands/
128
+ echo 'module.exports = {
129
+ name: "ping",
130
+ description: "Responds with pong",
131
+ aliases: ["p"],
132
+ async execute({ message, args }) {
133
+ await message.reply("Pong!");
134
+ }
135
+ };' > commands/ping.js
136
+
137
+ // Load commands
138
+ client.loadCommands('./commands');
139
+ ```
140
+
141
+ ### 4. Database Management
142
+ ```javascript
143
+ const { DatabaseManager } = require('nexus-fca');
144
+ const db = DatabaseManager.getInstance();
145
+
146
+ // Cache user data
147
+ await db.cacheUserInfo(userID, userInfo);
148
+ const cached = await db.getUserInfo(userID);
149
+
150
+ // Cache thread data
151
+ await db.cacheThreadInfo(threadID, threadInfo);
152
+ const threadData = await db.getThreadInfo(threadID);
153
+
154
+ // Save metrics
155
+ await db.saveMetric('messages_sent', messageCount);
156
+ const metrics = await db.getMetrics('messages_sent', 24); // Last 24 hours
157
+
158
+ // Get database stats
159
+ const stats = await db.getStats();
160
+ console.log('Cache hit rate:', stats.cache.hitRate);
161
+ ```
162
+
163
+ ### 5. Enhanced MQTT Manager
164
+ ```javascript
165
+ const MqttManager = require('nexus-fca/lib/mqtt/MqttManager');
166
+
167
+ const mqttManager = new MqttManager(ctx, defaultFuncs);
168
+
169
+ mqttManager.on('connected', () => {
170
+ console.log('MQTT connected with enhanced stability');
171
+ });
172
+
173
+ mqttManager.on('message', ({ topic, message }) => {
174
+ console.log('Received message from:', topic);
175
+ });
176
+
177
+ // Get connection metrics
178
+ const metrics = mqttManager.getMetrics();
179
+ console.log('Messages received:', metrics.messagesReceived);
180
+ console.log('Connection uptime:', metrics.uptime);
181
+ console.log('Queue size:', metrics.queueSize);
182
+ ```
183
+
184
+ ## 📊 Performance Monitoring
185
+
186
+ ### Built-in Metrics
187
+ ```javascript
188
+ // Get comprehensive performance report
189
+ const optimizer = PerformanceOptimizer.getInstance();
190
+ const report = optimizer.getPerformanceReport();
191
+
192
+ console.log('=== Performance Report ===');
193
+ console.log('Memory:', report.memory);
194
+ console.log('Requests:', report.requests);
195
+ console.log('Cache:', report.cache);
196
+ console.log('MQTT:', report.mqtt);
197
+ ```
198
+
199
+ ### Memory Management
200
+ ```javascript
201
+ // Monitor memory usage
202
+ setInterval(() => {
203
+ const report = optimizer.getPerformanceReport();
204
+ if (parseFloat(report.memory.usage) > 80) {
205
+ console.warn('High memory usage detected:', report.memory.usage);
206
+ }
207
+ }, 60000); // Check every minute
208
+ ```
209
+
210
+ ## 🛡️ Enhanced Error Handling
211
+
212
+ ### Error Types
213
+ ```javascript
214
+ const {
215
+ NexusError,
216
+ LoginError,
217
+ NetworkError,
218
+ ValidationError,
219
+ RateLimitError
220
+ } = require('nexus-fca');
221
+
222
+ // Custom error handling
223
+ client.on('error', async (error) => {
224
+ if (error instanceof LoginError) {
225
+ console.log('Login failed:', error.message);
226
+ // Handle re-login
227
+ } else if (error instanceof RateLimitError) {
228
+ console.log('Rate limited, waiting:', error.retryAfter);
229
+ await new Promise(resolve => setTimeout(resolve, error.retryAfter * 1000));
230
+ }
231
+ });
232
+ ```
233
+
234
+ ### Recovery Strategies
235
+ ```javascript
236
+ const { errorHandler } = require('nexus-fca');
237
+
238
+ // Add custom recovery strategy
239
+ errorHandler.addRecoveryStrategy('CUSTOM_ERROR', async (error, context) => {
240
+ // Custom recovery logic
241
+ console.log('Attempting custom recovery...');
242
+ return { success: true, message: 'Recovery successful' };
243
+ });
244
+
245
+ // Add user-friendly message
246
+ errorHandler.addUserFriendlyMessage('CUSTOM_ERROR', 'Something went wrong, but we fixed it!');
247
+ ```
248
+
249
+ ## 🔄 Migration Guide
250
+
251
+ ### From Old FCA
252
+ ```javascript
253
+ // Old way
254
+ const login = require('nexus-fca');
255
+ login(credentials, (err, api) => {
256
+ api.listen((err, message) => {
257
+ api.sendMessage(message.body, message.threadID);
258
+ });
259
+ });
260
+
261
+ // Enhanced way
262
+ const { NexusClient } = require('nexus-fca');
263
+ const client = new NexusClient();
264
+
265
+ client.on('message', (message) => {
266
+ message.reply(message.content);
267
+ });
268
+
269
+ await client.loginWithAppState(appState);
270
+ ```
271
+
272
+ ### Backward Compatibility
273
+ ```javascript
274
+ // Still works - traditional login
275
+ const login = require('nexus-fca');
276
+ login(credentials, (err, api) => {
277
+ // All existing API methods work
278
+ api.sendMessage('Hello', threadID);
279
+ api.listen((err, message) => {
280
+ // Traditional message handling
281
+ });
282
+ });
283
+ ```
284
+
285
+ ## 📈 Best Practices
286
+
287
+ ### 1. Use Enhanced Client for New Projects
288
+ ```javascript
289
+ const { NexusClient } = require('nexus-fca');
290
+ const client = new NexusClient({
291
+ prefix: '!',
292
+ rateLimitEnabled: true,
293
+ safeMode: true
294
+ });
295
+ ```
296
+
297
+ ### 2. Implement Error Handling
298
+ ```javascript
299
+ client.on('error', (error) => {
300
+ console.error('Client error:', error.message);
301
+ });
302
+
303
+ client.on('maxReconnectAttemptsReached', () => {
304
+ console.error('Connection permanently failed');
305
+ process.exit(1);
306
+ });
307
+ ```
308
+
309
+ ### 3. Monitor Performance
310
+ ```javascript
311
+ setInterval(() => {
312
+ const report = optimizer.getPerformanceReport();
313
+ console.log(`Performance: ${report.memory.usage} memory, ${report.cache.hitRate} cache hit rate`);
314
+ }, 300000); // Every 5 minutes
315
+ ```
316
+
317
+ ### 4. Use Caching Effectively
318
+ ```javascript
319
+ // Cache expensive operations
320
+ const getUserInfoCached = async (userID) => {
321
+ const cached = await db.getUserInfo(userID);
322
+ if (cached) return cached;
323
+
324
+ const userInfo = await api.getUserInfo(userID);
325
+ await db.cacheUserInfo(userID, userInfo);
326
+ return userInfo;
327
+ };
328
+ ```
329
+
330
+ ## 🔧 Configuration
331
+
332
+ ### Enhanced Config File
333
+ ```json
334
+ {
335
+ "autoUpdate": true,
336
+ "mqtt": {
337
+ "enabled": true,
338
+ "reconnectInterval": 3600,
339
+ "maxReconnectAttempts": 10
340
+ },
341
+ "performance": {
342
+ "cacheEnabled": true,
343
+ "maxCacheSize": 10000,
344
+ "rateLimitEnabled": true,
345
+ "maxConcurrentRequests": 5
346
+ },
347
+ "database": {
348
+ "path": "./Fca_Database/nexus_cache.sqlite",
349
+ "vacuumInterval": 86400
350
+ },
351
+ "logging": {
352
+ "level": "info",
353
+ "saveErrors": true
354
+ }
355
+ }
356
+ ```
357
+
358
+ ## 📝 API Reference
359
+
360
+ ### Enhanced Methods
361
+ - `client.loadCommands(directory)` - Load commands from directory
362
+ - `client.getUser()` - Get current user info
363
+ - `client.isReady()` - Check if client is ready
364
+ - `message.reply(content)` - Reply to message
365
+ - `message.react(emoji)` - React to message
366
+ - `message.edit(content)` - Edit message
367
+ - `message.unsend()` - Unsend message
368
+
369
+ ### Performance Methods
370
+ - `optimizer.getPerformanceReport()` - Get comprehensive performance data
371
+ - `optimizer.optimizeRequest(fn, cacheKey, ttl)` - Optimize API request
372
+ - `db.getStats()` - Get database statistics
373
+ - `mqttManager.getMetrics()` - Get MQTT connection metrics
374
+
375
+ ## 🚀 Examples
376
+
377
+ Check the `examples/` directory for:
378
+ - Enhanced client setup
379
+ - Command system implementation
380
+ - Performance monitoring
381
+ - Error handling patterns
382
+ - Database usage examples
383
+
384
+ ---
385
+
386
+ **Nexus-FCA Enhanced** - The most advanced Facebook Chat API for Node.js with built-in performance optimization, smart caching, and enhanced error handling.
package/LICENSE-MIT CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2025 Nexus-016
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Nexus-016
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.