@zervonex/baileys 3.0.5 → 3.0.6

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
@@ -377,7 +377,7 @@ Universal adapter for any database backend via [Keyv](https://github.com/jaredwr
377
377
 
378
378
  Storage format matches `useMultiFileAuthState` exactly: every value is wrapped as `{ data, __checksum }` with a sha256 integrity check, so corruption is detected and self-healed the same way on both adapters. Reads also auto-detect and repair values that were written by an older/buggy version of this adapter (including arbitrarily nested `{ value: { value: ... } }` wrapping) — no manual data-fixing needed if you're upgrading from an earlier release.
379
379
 
380
- The first argument is the **session ID** — equivalent to the folder name in `useMultiFileAuthState`. It's used as a key prefix (`sessionId::key`), so multiple bots can safely share one backend. The second argument is a connection string, a pre-built `Keyv` instance, or a raw `KeyvStoreAdapter`:
380
+ The first argument is the **session ID** — equivalent to the folder name in `useMultiFileAuthState`. It's used as a Keyv namespace, so multiple bots can safely share one backend. The second argument is a connection string, a pre-built `Keyv` instance, or a raw `KeyvStoreAdapter`:
381
381
 
382
382
  ```javascript
383
383
  import { useKeyvAuthState } from '@zervonex/baileys'
@@ -440,7 +440,7 @@ const { state, saveCreds, clearSession } = await useKeyvAuthState('bot1', 'redis
440
440
  await clearSession()
441
441
  ```
442
442
 
443
- `clearSession()` wipes every key belonging to that `sessionId` — creds, prekeys, sessions, sender keys, everything — by iterating the store filtering by the `sessionId::` prefix and calling `deleteMany`. Only this session's keys are removed; other sessions sharing the same backend are untouched. There is no equivalent method on `useMultiFileAuthState` — delete the session folder instead.
443
+ `clearSession()` wipes every key belonging to that `sessionId` — creds, prekeys, sessions, sender keys, everything — by calling `keyv.clear()` which removes all keys scoped to that session's namespace. Only this session's keys are removed; other sessions sharing the same backend are untouched. There is no equivalent method on `useMultiFileAuthState` — delete the session folder instead.
444
444
 
445
445
  #### Checking auth without loading full state
446
446
 
@@ -155,13 +155,12 @@ export const useKeyvAuthState = async (sessionId, backend, opts = {}) => {
155
155
  const { preKeyRetention = DEFAULT_PREKEY_RETENTION, cleanupThreshold = DEFAULT_CLEANUP_THRESHOLD, collectionName } = opts
156
156
 
157
157
  const store = await resolveStore(backend, collectionName)
158
- const keyv = store ? new Keyv({ store }) : new Keyv()
158
+ const keyv = store ? new Keyv({ store, namespace: sessionId }) : new Keyv({ namespace: sessionId })
159
159
  keyv.setMaxListeners?.(0)
160
160
  keyv.on('error', err => logger.warn({ err: err?.message, sessionId }, '[Auth] store error'))
161
161
 
162
- // all keys prefixed sessionId:: to isolate sessions on a shared store
163
- const kn = (type, id) => `${sessionId}::${type}-${id}`
164
- const credsKey = `${sessionId}::creds`
162
+ const kn = (type, id) => `${type}-${id}`
163
+ const credsKey = 'creds'
165
164
 
166
165
  let creds = bootstrapCreds(deser(await keyv.get(credsKey)))
167
166
  let cleanupRunning = false, lastCleanupAt = 0, lastCleanedId = creds.nextPreKeyId
@@ -213,29 +212,7 @@ export const useKeyvAuthState = async (sessionId, backend, opts = {}) => {
213
212
  }
214
213
 
215
214
  const clearSession = async () => {
216
- const prefix = `${sessionId}::`
217
- let done = false
218
- if (store) {
219
- // Redis: KEYS pattern scan
220
- const rc = store.client
221
- if (rc && typeof rc.keys === 'function') {
222
- try { await store.set('__probe__', 1); const m = await rc.keys(`${prefix}*`); if (m.length) await rc.del(m); done = true } catch { }
223
- }
224
- // Mongo/Postgres/SQLite: iterator scan
225
- if (!done && typeof store.iterator === 'function') {
226
- try {
227
- const targets = []
228
- for await (const [k] of store.iterator(prefix)) if (k.startsWith(prefix)) targets.push(k)
229
- if (targets.length) await store.deleteMany(targets)
230
- done = true
231
- } catch { }
232
- }
233
- }
234
- if (!done) {
235
- // fallback (in-memory): delete every key ever written — covers all types + JID-based IDs
236
- await Promise.all([..._writtenKeys].map(k => keyv.delete(k).catch(() => { })))
237
- _writtenKeys.clear()
238
- }
215
+ await keyv.clear()
239
216
  keyv.removeAllListeners?.()
240
217
  }
241
218
 
@@ -246,8 +223,8 @@ export const useKeyvAuthState = async (sessionId, backend, opts = {}) => {
246
223
  export const hasKeyvAuth = async (sessionId, backend, opts = {}) => {
247
224
  try {
248
225
  const store = await resolveStore(backend, opts.collectionName)
249
- const keyv = store ? new Keyv({ store }) : new Keyv()
250
- const parsed = deser(await keyv.get(`${sessionId}::creds`))
226
+ const keyv = store ? new Keyv({ store, namespace: sessionId }) : new Keyv({ namespace: sessionId })
227
+ const parsed = deser(await keyv.get('creds'))
251
228
  return !!(parsed?.noiseKey && parsed?.signedIdentityKey)
252
229
  } catch { return false }
253
230
  }
package/lib/index.js CHANGED
@@ -29,7 +29,7 @@ const info = [
29
29
  '╭──────────────────────────────────────────────────────────────╮',
30
30
  '│ │',
31
31
  '│ ◆ Package › @zervonex/baileys │',
32
- '│ ◆ Version › 3.0.5 │',
32
+ '│ ◆ Version › 3.0.6 │',
33
33
  '│ ◆ Status › Production Ready │',
34
34
  '│ │',
35
35
  '├──────────────────────────── ◇◆◇ ─────────────────────────────┤',
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@zervonex/baileys",
4
4
  "type": "module",
5
- "version": "3.0.5",
5
+ "version": "3.0.6",
6
6
  "description": "Advanced WhatsApp Web API built on Baileys — interactive messages, buttons, carousels, products, events, payments, polls, albums, sticker packs and more.",
7
7
  "keywords": [
8
8
  "baileys",