aunubaileys 1.0.26 → 1.0.27

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/README.md CHANGED
@@ -64,6 +64,10 @@ Everything else is pure upstream. When upstream moves, we rebase the patch layer
64
64
 
65
65
 
66
66
 
67
+ ### 🆕 What's new in 1.0.27 / Baru di 1.0.27
68
+
69
+ - ⏱️ **New `getReconnectDelay(attempt, reason)` helper** — the companion to AunuAntiBan's `classifyDisconnect`: it turns a disconnect reason (Boom error, status code, or a classification result) into a suggested wait in milliseconds, or `null` when the connection must NOT be re-established automatically (logged out, replaced, bad session, 403). Server-requested restarts return 0; transient failures back off exponentially with Gaussian jitter (1s base, 60s cap); rate limits back off much longer (30s base, 15 min cap). `baseDelayMs` / `maxDelayMs` overrides available.
70
+
67
71
  ### 🆕 What's new in 1.0.26 / Baru di 1.0.26
68
72
 
69
73
  - 📡 **`fetchLatestBaileysVersion` now remembers the last-good fetched version** — it is called on every reconnect and used to hit the network every time; a mid-session fetch failure silently downgraded to the bundled version, even though the endpoint value is the only server-accepted truth (see 1.0.13). Successful fetches are now cached for 10 minutes, and a later failure returns the last fetched version instead of the bundled one. New `forceRefresh` / `cacheTtlMs` options.
@@ -7,6 +7,9 @@ export declare class RateLimiter {
7
7
  }
8
8
  export interface DisconnectClassification { category: string; action: 'stop' | 'restart' | 'reconnect' | 'backoff'; detail: string; }
9
9
  export declare const classifyDisconnect: (error: unknown) => DisconnectClassification;
10
+ export interface ReconnectDelayOptions { baseDelayMs?: number; maxDelayMs?: number; }
11
+ /** Suggested reconnect delay in ms for a disconnect reason (error, status code, or a classifyDisconnect result); null when the connection must NOT be re-established automatically. */
12
+ export declare const getReconnectDelay: (attempt: number, reason: unknown, options?: ReconnectDelayOptions) => number | null;
10
13
  export interface AunuAntiBanOptions {
11
14
  perChatPerMinute?: number; globalPerMinute?: number; minDelayMs?: number; jitterMs?: number;
12
15
  warmupDays?: number; warmupStart?: number; typingSimulation?: boolean;
@@ -166,5 +166,40 @@ export class AunuAntiBan {
166
166
  }
167
167
  }
168
168
 
169
+ /**
170
+ * Jeda reconnect yang disarankan, pendamping classifyDisconnect.
171
+ * Mengembalikan milidetik untuk menunggu sebelum reconnect, atau null
172
+ * bila koneksi TIDAK boleh disambung ulang otomatis (sesi logout,
173
+ * digantikan, rusak, atau 403). `reason` boleh berupa error Boom,
174
+ * kode status numerik, atau hasil classifyDisconnect ({ action } /
175
+ * { category }). Backoff eksponensial + jitter Gaussian; kategori
176
+ * rate_limited memakai basis dan plafon jauh lebih besar karena
177
+ * reconnect terlalu cepat pada 429 memperburuk pembatasan.
178
+ */
179
+ export const getReconnectDelay = (attempt, reason, options = {}) => {
180
+ const a = Math.max(0, Math.floor(+attempt) || 0);
181
+ let action;
182
+ if (reason && typeof reason === 'object' && typeof reason.action === 'string') {
183
+ action = reason.action;
184
+ }
185
+ else if (reason && typeof reason === 'object' && typeof reason.category === 'string') {
186
+ action = { logged_out: 'stop', replaced: 'stop', bad_session: 'stop', mismatch: 'stop', forbidden: 'stop', restart_required: 'restart', rate_limited: 'backoff', transient: 'reconnect' }[reason.category] ?? 'reconnect';
187
+ }
188
+ else {
189
+ action = classifyDisconnect(reason).action;
190
+ }
191
+ if (action === 'stop') {
192
+ return null;
193
+ }
194
+ if (action === 'restart') {
195
+ return 0;
196
+ }
197
+ const isRateLimited = action === 'backoff';
198
+ const base = options.baseDelayMs ?? (isRateLimited ? 30000 : 1000);
199
+ const cap = options.maxDelayMs ?? (isRateLimited ? 900000 : 60000);
200
+ const grown = Math.min(cap, base * 2 ** a);
201
+ return Math.round(grown + gaussianJitter(0, grown * 0.1));
202
+ };
203
+
169
204
  /** Bungkus socket dengan AunuAntiBan (jalan pintas). */
170
205
  export const wrapAntiBan = (sock, options) => new AunuAntiBan(options).wrap(sock);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "aunubaileys",
3
3
  "type": "module",
4
- "version": "1.0.26",
4
+ "version": "1.0.27",
5
5
  "description": "AunuBaileys \u2014 a WhatsApp Web API for bots that never sleep. Full upstream power with the beloved in-memory store restored and pairing that just works. Forged by AunuCore.",
6
6
  "keywords": [
7
7
  "whatsapp",