baileys-antiban 3.8.5 → 3.8.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.
- package/CHANGELOG.md +25 -0
- package/README.md +78 -0
- package/dist/cjs/antiban.js +578 -0
- package/dist/cjs/cli.js +212 -0
- package/dist/cjs/contactGraph.js +240 -0
- package/dist/cjs/contentVariator.js +154 -0
- package/dist/cjs/credsSnapshot.js +157 -0
- package/dist/cjs/deviceFingerprint.js +110 -0
- package/dist/cjs/health.js +211 -0
- package/dist/cjs/index.js +121 -0
- package/dist/cjs/jidCanonicalizer.js +260 -0
- package/dist/cjs/lidFirstResolver.js +212 -0
- package/dist/cjs/lidResolver.js +328 -0
- package/dist/cjs/messageQueue.js +191 -0
- package/dist/cjs/messageRecovery.js +319 -0
- package/dist/cjs/observability.js +151 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/patch.js +339 -0
- package/dist/cjs/persist.js +116 -0
- package/dist/cjs/presenceChoreographer.js +435 -0
- package/dist/cjs/presets.js +71 -0
- package/dist/cjs/profiles.js +38 -0
- package/dist/cjs/proxyRotator.js +310 -0
- package/dist/cjs/rateLimiter.js +202 -0
- package/dist/cjs/readReceiptVariance.js +91 -0
- package/dist/cjs/reconnectThrottle.js +184 -0
- package/dist/cjs/replyRatio.js +165 -0
- package/dist/cjs/retryReason.js +97 -0
- package/dist/cjs/retryTracker.js +176 -0
- package/dist/cjs/scheduler.js +115 -0
- package/dist/cjs/sessionFingerprint.js +258 -0
- package/dist/cjs/sessionStability.js +337 -0
- package/dist/cjs/stateAdapter.js +110 -0
- package/dist/cjs/stealthConnect.js +136 -0
- package/dist/cjs/timelockGuard.js +185 -0
- package/dist/cjs/warmup.js +113 -0
- package/dist/cjs/webhooks.js +84 -0
- package/dist/cjs/wrapper.js +278 -0
- package/dist/cli.js +52 -0
- package/dist/messageRecovery.d.ts +1 -1
- package/dist/messageRecovery.js +4 -20
- package/dist/patch.d.ts +34 -0
- package/dist/patch.js +302 -0
- package/dist/proxyRotator.js +18 -6
- package/package.json +5 -7
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,31 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.8.7] - 2026-05-14
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **`baileys-antiban patch` CLI command** — for frameworks that create the Baileys socket internally (OpenClaw `@openclaw/whatsapp`, custom ESM loaders) and don't expose a `socket:ready` hook. Automatically locates the Baileys install, detects CJS vs ESM output format, backs up the original file, and injects a `wrapSocket()` call around `makeWASocket`. Idempotent — safe to re-run after plugin updates. Pairs with a `postinstall` npm script for zero-maintenance re-patching.
|
|
12
|
+
- Auto-discovers Baileys in `node_modules/@openclaw/whatsapp/node_modules/baileys`, `node_modules/baileys`, `node_modules/@whiskeysockets/baileys`, and parent directories.
|
|
13
|
+
- `--path <dir>` — explicit Baileys directory override.
|
|
14
|
+
- `--preset conservative|moderate|aggressive` — antiban profile (default: `conservative`).
|
|
15
|
+
- `--min-delay` / `--max-delay` — override delay range in ms (default 1500–4000).
|
|
16
|
+
- `--no-typing` — disable typing indicators.
|
|
17
|
+
- `--dry-run` — preview without writing files.
|
|
18
|
+
- `--force` — re-patch even if already patched.
|
|
19
|
+
- Runtime config via env: `ANTIBAN_PRESET`, `ANTIBAN_MIN_DELAY`, `ANTIBAN_MAX_DELAY`, `ANTIBAN_TYPING`.
|
|
20
|
+
- **`baileys-antiban unpatch` CLI command** — restores a patched file from its `.antiban-backup` or strips the patch block in-place if backup is missing.
|
|
21
|
+
|
|
22
|
+
## [3.8.6] - 2026-05-14
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
- **CJS build for NestJS / CommonJS consumers.** Adds `dist/cjs/` output compiled with `module: CommonJS`, a `{"type":"commonjs"}` package marker injected at build time, and an `exports["require"]` condition so `require('baileys-antiban')` now resolves cleanly. Previously CommonJS callers hit `ERR_PACKAGE_PATH_NOT_EXPORTED` or `ERR_REQUIRE_ESM`.
|
|
26
|
+
- **`messageRecovery` persistence load in ESM context.** `loadPersistence()` previously called `require('fs')` which is not defined in native ESM scope, throwing `ReferenceError` at runtime whenever `persistPath` was configured. Fixed by using static `import { existsSync, readFileSync } from 'node:fs'` at module top level.
|
|
27
|
+
- **`messageRecovery` doc comment.** Placeholder `issues/XXX` issue reference updated to `issues/2491` (deaf-session / silent message loss tracker).
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
- Removed unused `jest`, `@types/jest`, and `ts-jest` devDependencies (test runner uses `tsx` directly; `vitest` retained as future framework).
|
|
31
|
+
- **Docs: ESM plugin-framework integration.** Added troubleshooting section to README covering `wrapSocket()` as the correct integration point for OpenClaw, custom ESM loaders, and other plugin frameworks that use native ESM. Documents why `Module._load` interception does not work with ESM and how to set up `ev.process` + `ev.on` fallback correctly.
|
|
32
|
+
|
|
8
33
|
## [3.8.5] - 2026-05-09
|
|
9
34
|
|
|
10
35
|
### Added
|
package/README.md
CHANGED
|
@@ -1045,6 +1045,84 @@ const antiban = new AntiBan({
|
|
|
1045
1045
|
});
|
|
1046
1046
|
```
|
|
1047
1047
|
|
|
1048
|
+
### Using inside a plugin framework (OpenClaw, custom ESM loaders, etc.)
|
|
1049
|
+
|
|
1050
|
+
`baileys-antiban` is a **pure ESM package**. `wrapSocket()` is the correct integration point — it works in any ESM or CJS context without patching Baileys directly.
|
|
1051
|
+
|
|
1052
|
+
If your framework (e.g. OpenClaw's WhatsApp plugin) uses native ESM, **do not attempt `Module._load` interception** — it only intercepts CJS modules and silently does nothing for ESM imports.
|
|
1053
|
+
|
|
1054
|
+
Correct approach — wrap the socket after it's created, regardless of how it was imported:
|
|
1055
|
+
|
|
1056
|
+
```typescript
|
|
1057
|
+
import { makeWASocket } from 'baileys'; // or however your framework exposes it
|
|
1058
|
+
import { wrapSocket } from 'baileys-antiban';
|
|
1059
|
+
|
|
1060
|
+
const rawSock = makeWASocket({ ... });
|
|
1061
|
+
const sock = wrapSocket(rawSock); // drop-in — use sock everywhere
|
|
1062
|
+
```
|
|
1063
|
+
|
|
1064
|
+
If your framework creates the socket internally and only exposes it via a callback or event, wrap it at that point:
|
|
1065
|
+
|
|
1066
|
+
```typescript
|
|
1067
|
+
// OpenClaw / plugin pattern
|
|
1068
|
+
framework.on('socket', (rawSock) => {
|
|
1069
|
+
const sock = wrapSocket(rawSock);
|
|
1070
|
+
// use sock from here on
|
|
1071
|
+
});
|
|
1072
|
+
```
|
|
1073
|
+
|
|
1074
|
+
**If your framework creates the socket with no event or callback exposed** (common in tightly-integrated plugins), use the `patch` CLI command — see [CLI: patch command](#cli-patch-command) below.
|
|
1075
|
+
|
|
1076
|
+
> **Note:** If you install/update the Baileys package or plugin via a package manager, `wrapSocket()` survives the update untouched. Patching Baileys source directly (as a workaround) will be reset by any reinstall — use the `patch` command to automate re-patching.
|
|
1077
|
+
|
|
1078
|
+
---
|
|
1079
|
+
|
|
1080
|
+
### CLI: patch command
|
|
1081
|
+
|
|
1082
|
+
For plugin frameworks where `makeWASocket` is called internally and no socket hook is exposed (e.g. OpenClaw `@openclaw/whatsapp`), the `patch` command modifies the installed Baileys package to inject `wrapSocket()` automatically.
|
|
1083
|
+
|
|
1084
|
+
```bash
|
|
1085
|
+
# Auto-detect Baileys location + apply patch
|
|
1086
|
+
npx baileys-antiban patch
|
|
1087
|
+
|
|
1088
|
+
# OpenClaw: Baileys is nested inside the plugin
|
|
1089
|
+
npx baileys-antiban patch --path ./node_modules/@openclaw/whatsapp/node_modules/baileys
|
|
1090
|
+
|
|
1091
|
+
# Custom profile
|
|
1092
|
+
npx baileys-antiban patch --preset moderate --min-delay 1000 --max-delay 3000
|
|
1093
|
+
|
|
1094
|
+
# Preview without writing (dry run)
|
|
1095
|
+
npx baileys-antiban patch --dry-run
|
|
1096
|
+
|
|
1097
|
+
# Restore original
|
|
1098
|
+
npx baileys-antiban unpatch --file ./node_modules/baileys/lib/socket/index.js
|
|
1099
|
+
```
|
|
1100
|
+
|
|
1101
|
+
The patch is **idempotent** — re-running it on an already-patched file is a no-op. A `.antiban-backup` file is kept alongside the patched file for safe restoration.
|
|
1102
|
+
|
|
1103
|
+
**Auto re-patch after plugin updates** — add a `postinstall` script to your project's `package.json`:
|
|
1104
|
+
|
|
1105
|
+
```json
|
|
1106
|
+
{
|
|
1107
|
+
"scripts": {
|
|
1108
|
+
"postinstall": "npx baileys-antiban patch --path ./node_modules/@openclaw/whatsapp/node_modules/baileys"
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
```
|
|
1112
|
+
|
|
1113
|
+
Now every `npm install` / `openclaw plugins install @openclaw/whatsapp` automatically re-applies the patch.
|
|
1114
|
+
|
|
1115
|
+
**Runtime config via environment variables** (no re-patch needed to change settings):
|
|
1116
|
+
|
|
1117
|
+
| Variable | Default | Description |
|
|
1118
|
+
|---|---|---|
|
|
1119
|
+
| `ANTIBAN_PRESET` | `conservative` | `conservative`, `moderate`, or `aggressive` |
|
|
1120
|
+
| `ANTIBAN_MIN_DELAY` | `1500` | Minimum delay between messages (ms) |
|
|
1121
|
+
| `ANTIBAN_MAX_DELAY` | `4000` | Maximum delay between messages (ms) |
|
|
1122
|
+
| `ANTIBAN_TYPING` | `true` | Enable typing indicators (`false` to disable) |
|
|
1123
|
+
|
|
1124
|
+
---
|
|
1125
|
+
|
|
1048
1126
|
### State not persisting across restarts
|
|
1049
1127
|
|
|
1050
1128
|
Use the FileStateAdapter:
|