@realvare/based 2.5.6 → 2.5.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.
@@ -18,6 +18,10 @@ export interface PerformanceSettings {
18
18
  maxRetryDelay: number;
19
19
  maxMsgRetryCount: number;
20
20
  memoryThreshold: number;
21
+ // Anti-ban specific settings
22
+ markOnlineOnConnect?: boolean;
23
+ syncFullHistory?: boolean;
24
+ keepAliveIntervalMs?: number;
21
25
  }
22
26
 
23
27
  export interface DebugSettings {
@@ -26,18 +26,22 @@ class PerformanceConfig {
26
26
  }
27
27
  };
28
28
 
29
- // Performance settings
29
+ // Performance settings - Conservative defaults for anti-ban protection
30
30
  this.performance = {
31
31
  enableCache: true,
32
32
  enableLogging: false,
33
33
  enableMetrics: true,
34
- batchSize: 50,
35
- maxRetries: 5,
34
+ batchSize: 20, // Reduced from 50 for anti-ban
35
+ maxRetries: 3, // Reduced from 5 for anti-ban
36
36
  retryDelay: 5000,
37
37
  retryBackoffMultiplier: 1.5,
38
38
  maxRetryDelay: 60000,
39
39
  maxMsgRetryCount: 3,
40
- memoryThreshold: 0.85 // 85% memory usage threshold
40
+ memoryThreshold: 0.85, // 85% memory usage threshold
41
+ // Anti-ban specific settings
42
+ markOnlineOnConnect: false, // Don't appear always online
43
+ syncFullHistory: false, // Limit initial sync
44
+ keepAliveIntervalMs: 30000 // Maintain connection without excess
41
45
  };
42
46
 
43
47
  // Debug settings
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * RateLimiter class for controlling message sending frequency
5
+ * to prevent ban detection by simulating human-like behavior
6
+ */
7
+ class RateLimiter {
8
+ constructor(limitPerSecond = 1) {
9
+ this.limitPerSecond = limitPerSecond;
10
+ this.interval = 1000 / limitPerSecond; // milliseconds between messages
11
+ this.queue = [];
12
+ this.processing = false;
13
+ this.lastSendTime = 0;
14
+ }
15
+
16
+ /**
17
+ * Add a task to the rate limiting queue
18
+ * @param {Function} task - Async function to execute
19
+ * @returns {Promise} - Promise that resolves when task is complete
20
+ */
21
+ async add(task) {
22
+ return new Promise((resolve, reject) => {
23
+ this.queue.push({ task, resolve, reject });
24
+ if (!this.processing) {
25
+ this.process();
26
+ }
27
+ });
28
+ }
29
+
30
+ /**
31
+ * Process the queue with rate limiting
32
+ */
33
+ async process() {
34
+ if (this.processing || this.queue.length === 0) {
35
+ return;
36
+ }
37
+
38
+ this.processing = true;
39
+
40
+ while (this.queue.length > 0) {
41
+ const { task, resolve, reject } = this.queue.shift();
42
+ const now = Date.now();
43
+ const timeSinceLastSend = now - this.lastSendTime;
44
+
45
+ // Wait if we need to respect the rate limit
46
+ if (timeSinceLastSend < this.interval) {
47
+ const waitTime = this.interval - timeSinceLastSend;
48
+ await new Promise(r => setTimeout(r, waitTime));
49
+ }
50
+
51
+ try {
52
+ const result = await task();
53
+ this.lastSendTime = Date.now();
54
+ resolve(result);
55
+ } catch (error) {
56
+ reject(error);
57
+ }
58
+
59
+ // Add small random delay to simulate human behavior (0-500ms)
60
+ const randomDelay = Math.random() * 500;
61
+ await new Promise(r => setTimeout(r, randomDelay));
62
+ }
63
+
64
+ this.processing = false;
65
+ }
66
+
67
+ /**
68
+ * Update the rate limit
69
+ * @param {number} newLimit - New messages per second limit
70
+ */
71
+ setLimit(newLimit) {
72
+ this.limitPerSecond = newLimit;
73
+ this.interval = 1000 / newLimit;
74
+ }
75
+
76
+ /**
77
+ * Get current queue length
78
+ * @returns {number} - Number of pending tasks
79
+ */
80
+ getQueueLength() {
81
+ return this.queue.length;
82
+ }
83
+
84
+ /**
85
+ * Clear all pending tasks
86
+ */
87
+ clear() {
88
+ this.queue.forEach(({ reject }) => {
89
+ reject(new Error('Rate limiter cleared'));
90
+ });
91
+ this.queue = [];
92
+ }
93
+ }
94
+
95
+ module.exports = RateLimiter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realvare/based",
3
- "version": "2.5.6",
3
+ "version": "2.5.7",
4
4
  "description": "whatsapp api by sam",
5
5
  "keywords": [
6
6
  "baileys",
@@ -37,7 +37,7 @@
37
37
  "lint:fix": "eslint src --fix --ext .js,.ts,.jsx,.tsx",
38
38
  "preinstall": "node ./engine-requirements.js",
39
39
  "release": "release-it",
40
- "test": "jest"
40
+ "test": "test"
41
41
  },
42
42
  "dependencies": {
43
43
  "@adiwajshing/keyed-db": "^0.2.4",
@@ -97,9 +97,6 @@
97
97
  "link-preview-js": {
98
98
  "optional": true
99
99
  },
100
- "qrcode-terminal": {
101
- "optional": true
102
- },
103
100
  "sharp": {
104
101
  "optional": true
105
102
  }
@@ -108,4 +105,4 @@
108
105
  "engines": {
109
106
  "node": ">=20.0.0"
110
107
  }
111
- }
108
+ }