aunubaileys 1.0.25 → 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 +8 -0
- package/lib/Utils/antiban.d.ts +3 -0
- package/lib/Utils/antiban.js +35 -0
- package/lib/Utils/generics.js +20 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,6 +64,14 @@ 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
|
+
|
|
71
|
+
### 🆕 What's new in 1.0.26 / Baru di 1.0.26
|
|
72
|
+
|
|
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.
|
|
74
|
+
|
|
67
75
|
### 🆕 What's new in 1.0.25 / Baru di 1.0.25
|
|
68
76
|
|
|
69
77
|
- 🪪 **DM receipt status no longer gets stuck on LID addressing** — receipts increasingly arrive addressed to the peer's LID while consumers keyed the sent message by its phone-number JID (or the reverse), so the status update never matched and the message looked forever "sent". When the LID store knows the pair, DM `messages.update` events now carry the alternate form as `key.remoteJidAlt` (purely additive; `remoteJid` unchanged). Under the hood the LID store is now created once in the base socket layer, so the single instance the public `sock.aunuLid` learns into is the same one inner layers read — and the store gains a `getAltJid(jid)` helper.
|
package/lib/Utils/antiban.d.ts
CHANGED
|
@@ -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;
|
package/lib/Utils/antiban.js
CHANGED
|
@@ -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/lib/Utils/generics.js
CHANGED
|
@@ -188,13 +188,31 @@ export const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connect
|
|
|
188
188
|
* utility that fetches latest baileys version from the master branch.
|
|
189
189
|
* Use to ensure your WA connection is always on the latest version
|
|
190
190
|
*/
|
|
191
|
+
// AunuBaileys: last-good cache for the fetched WA version. The endpoint's
|
|
192
|
+
// value is the server-accepted truth (a bundled version can be a rejected
|
|
193
|
+
// beta build — see 1.0.13), so once a fetch succeeds in this process, a
|
|
194
|
+
// later network failure must fall back to that fetched value, not silently
|
|
195
|
+
// downgrade to the bundled one. Repeated calls within the TTL also skip
|
|
196
|
+
// the network entirely; consumers typically call this on every reconnect.
|
|
197
|
+
const BAILEYS_VERSION_CACHE_TTL_MS = 10 * 60 * 1000;
|
|
198
|
+
let lastGoodBaileysVersion = null;
|
|
199
|
+
let lastGoodBaileysVersionAt = 0;
|
|
191
200
|
export const fetchLatestBaileysVersion = async (options = {}) => {
|
|
192
201
|
const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/baileys-version.json';
|
|
202
|
+
const { cacheTtlMs = BAILEYS_VERSION_CACHE_TTL_MS, forceRefresh = false, ...axiosOptions } = options;
|
|
203
|
+
if (!forceRefresh && lastGoodBaileysVersion && (Date.now() - lastGoodBaileysVersionAt) < cacheTtlMs) {
|
|
204
|
+
return {
|
|
205
|
+
version: lastGoodBaileysVersion,
|
|
206
|
+
isLatest: true
|
|
207
|
+
};
|
|
208
|
+
}
|
|
193
209
|
try {
|
|
194
210
|
const result = await axios.get(URL, {
|
|
195
|
-
...
|
|
211
|
+
...axiosOptions,
|
|
196
212
|
responseType: 'json'
|
|
197
213
|
});
|
|
214
|
+
lastGoodBaileysVersion = result.data.version;
|
|
215
|
+
lastGoodBaileysVersionAt = Date.now();
|
|
198
216
|
return {
|
|
199
217
|
version: result.data.version,
|
|
200
218
|
isLatest: true
|
|
@@ -202,7 +220,7 @@ export const fetchLatestBaileysVersion = async (options = {}) => {
|
|
|
202
220
|
}
|
|
203
221
|
catch (error) {
|
|
204
222
|
return {
|
|
205
|
-
version: baileysVersion,
|
|
223
|
+
version: lastGoodBaileysVersion ?? baileysVersion,
|
|
206
224
|
isLatest: false,
|
|
207
225
|
error
|
|
208
226
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aunubaileys",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
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",
|