npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

baileys-diag

v0.1.1

Published

Protocol-level diagnostic capture for Baileys — flight recorder for debugging sync issues

Readme

baileys-diag

npm version npm downloads license

Protocol-level diagnostic capture for Baileys. Records a timeline of app state sync, history sync, key operations, and connection events into a single compressed file for offline debugging.

Install

npm install baileys-diag
# or
bun add baileys-diag

Requires @whiskeysockets/baileys >= 7.0.0 as a peer dependency.

Usage

import makeWASocket, { useMultiFileAuthState } from '@whiskeysockets/baileys'
import { makeDiagnosticCapture } from 'baileys-diag'

// create capture once — survives reconnects
const diag = makeDiagnosticCapture('./capture.diag.gz')

async function startSock() {
  const { state, saveCreds } = await useMultiFileAuthState('./auth')
  const sock = makeWASocket({ auth: state })

  // attach to each new socket
  diag.attachSocket(sock)

  sock.ev.on('creds.update', saveCreds)
  sock.ev.on('connection.update', ({ connection, lastDisconnect }) => {
    if (connection === 'close') {
      // reconnect logic...
      startSock()
    }
  })
}

startSock()
// Ctrl+C flushes the capture automatically

Reading captures

The output is gzipped NDJSON — one JSON object per line.

# quick check: did nctSalt arrive?
zcat capture.diag.gz | grep nctSalt

# list all event types
zcat capture.diag.gz | jq -r .type | sort | uniq -c | sort -rn

# see history sync details
zcat capture.diag.gz | jq 'select(.type == "history-sync")'

# see app state version changes
zcat capture.diag.gz | jq 'select(.type == "key-set" and .keyType == "app-state-sync-version")'

# see all syncd mutation effects
zcat capture.diag.gz | jq -r 'select(.type == "syncd-effect") | .event' | sort | uniq -c

# full timeline
zcat capture.diag.gz | jq -c '[.ts, .type, .generation] | @tsv'

What it captures

| Record type | Source | Content | |---|---|---| | init | On create | Format version | | socket-attach | attachSocket() | Session metadata, nctSalt status | | creds-snapshot | attachSocket() | Full credentials (private keys redacted) | | connection | connection.update | Connection state changes | | creds-update | creds.update | Credential changes with nctSalt tracking | | history-sync | messaging-history.set | Sync type, progress, chat/contact/message counts | | syncd-effect | chats.update, settings.update, etc. | All effects of app state sync mutations | | key-get | keys.get() | App state sync key and version reads | | key-set | keys.set() | App state sync key and version writes | | close | On shutdown | Signal that triggered close |

Options

makeDiagnosticCapture('./capture.diag.gz', {
  captureCredsUpdates: true,   // creds.update events (default: true)
  captureKeyOps: true,         // app-state-sync-key/version operations (default: true)
  captureHistorySync: true,    // messaging-history.set events (default: true)
  captureAllKeyOps: false,     // ALL key store operations, very verbose (default: false)
})

Security

Private keys are automatically redacted in credential snapshots:

  • noiseKey.private
  • signedIdentityKey.private
  • pairingEphemeralKeyPair.private
  • signedPreKey.keyPair.private
  • advSecretKey

Public keys, account identifiers, and app state sync keys are preserved since they're needed for offline replay.

How it works

The capture hooks into the Baileys socket non-invasively:

  • Event listeners on ev.on() for connection, creds, history sync, and syncd effect events
  • Key store interception by wrapping keys.get() and keys.set() to capture app state sync operations
  • Periodic gzip flush (every 5s) so the file is readable while the session is still running
  • SIGINT/SIGTERM handler flushes the capture before process exit

No Baileys internals are modified. The capture attaches and detaches cleanly via attachSocket() and close().

License

MIT