@itsliaaa/baileys 0.3.11 → 0.3.12

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
@@ -41,21 +41,26 @@ This fork designed for production use with a focus on clarity and safety:
41
41
  >
42
42
  > Some npm packages are reuploading my fork under different names, with almost no meaningful changes:
43
43
  >
44
- > - [@itsmelody](https://www.npmjs.com/package/@itsmelody/baileys)
44
+ > - [@nuisockets](https://www.npmjs.com/package/@nuisockets/baileys)
45
45
  > - [@kaels](https://www.npmjs.com/package/@kaels/casileys)
46
46
  > - [@lumina-md](https://www.npmjs.com/package/@lumina-md/baileys)
47
47
  >
48
48
  > They:
49
49
  >
50
- > - Renamed my fork
50
+ > - Renamed my fork under different package names
51
+ > - Removed or ignored proper maintainer credit
51
52
  > - Added unnecessary overhead
52
- > - Rewrote all changelogs and note changes with their own names
53
- > - Claimed the modifications as their own work
53
+ > - Rewrote changelogs and modification notes under their own names
54
+ > - Claimed existing work and changes as if they made them
55
+ > - Copied code directly from my fork with little to no meaningful modification
54
56
  >
55
57
  > This is not acceptable.
56
58
  >
57
- > To be clear, I am not the original maintainer of Baileys (full respect to https://github.com/WhiskeySockets/Baileys).
58
- > **This is about proper attribution and honesty in contributions.**
59
+ > To be clear, I am **NOT** the original maintainer of Baileys. full respect goes to https://github.com/WhiskeySockets/Baileys.
60
+ >
61
+ > **This issue is about attribution, honesty, and respecting open-source contributions.**
62
+ >
63
+ > Forking is completely fine. Removing credits and presenting someone else's work as your own is not.
59
64
  >
60
65
  > Please report if necessary.
61
66
  >
@@ -269,7 +274,7 @@ connectToWhatsApp()
269
274
  #### 🔐 Auth State
270
275
 
271
276
  > [!NOTE]
272
- > You can use the experimental `useSingleFileAuthState` as an alternative to `useMultiFileAuthState`. However, `useSingleFileAuthState` already includes an internal caching mechanism, so there is no need to wrap `state.keys` with `makeCacheableSignalKeyStore`.
277
+ > You can use the experimental `useSingleFileAuthState` and `useSqliteAuthState` as an alternative to `useMultiFileAuthState`. However, `useSingleFileAuthState` already includes an internal caching mechanism, so there is no need to wrap `state.keys` with `makeCacheableSignalKeyStore`.
273
278
 
274
279
  ### 🗄️ Implementing Data Store
275
280
 
@@ -0,0 +1,11 @@
1
+ export function useSqliteAuthState(opts: any): Promise<{
2
+ state: {
3
+ creds: any;
4
+ keys: {
5
+ get: (type: any, ids: any) => Promise<{}>;
6
+ set: (data: any) => Promise<void>;
7
+ };
8
+ };
9
+ saveCreds: () => Promise<void>;
10
+ }>;
11
+ //# sourceMappingURL=use-sqlite-auth-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-sqlite-auth-state.d.ts","sourceRoot":"","sources":["../../src/Utils/use-sqlite-auth-state.js"],"names":[],"mappings":"AAoCA;;;;;;;;;GAkFC"}
@@ -0,0 +1,109 @@
1
+ import { mkdir, readFile, stat, unlink, writeFile } from 'fs/promises';
2
+ import { join } from 'path';
3
+ import { proto } from '../../WAProto/index.js';
4
+ import { initAuthCreds } from './auth-utils.js';
5
+ import { BufferJSON } from './generics.js';
6
+ async function loadBetterSqlite3() {
7
+ try {
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ const mod = (await import('better-sqlite3'));
10
+ return mod.default ?? mod;
11
+ }
12
+ catch (err) {
13
+ const helpful = new Error('`better-sqlite3` is required for `useSqliteAuthState`. Install it as a peer dependency: `npm install better-sqlite3` (or `yarn add better-sqlite3`).');
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ helpful.cause = err;
16
+ throw helpful;
17
+ }
18
+ }
19
+ const CREDS_ROW_KEY = '__creds__';
20
+ const CREATE_SCHEMA_SQL = `
21
+ CREATE TABLE IF NOT EXISTS creds (
22
+ key TEXT PRIMARY KEY,
23
+ value TEXT NOT NULL
24
+ );
25
+ CREATE TABLE IF NOT EXISTS signal_keys (
26
+ type TEXT NOT NULL,
27
+ id TEXT NOT NULL,
28
+ value TEXT NOT NULL,
29
+ PRIMARY KEY (type, id)
30
+ );
31
+ CREATE INDEX IF NOT EXISTS signal_keys_type_idx ON signal_keys(type);
32
+ `;
33
+ export async function useSqliteAuthState(opts) {
34
+ let db;
35
+ if (opts.database) {
36
+ db = opts.database;
37
+ }
38
+ else {
39
+ const Database = await loadBetterSqlite3();
40
+ db = new Database(opts.dbPath);
41
+ }
42
+ // WAL mode allows concurrent reads alongside a single writer; matches
43
+ // what SQLite recommends for read-heavy workloads with sporadic writes.
44
+ db.pragma('journal_mode = WAL');
45
+ db.pragma('synchronous = NORMAL');
46
+ db.exec(CREATE_SCHEMA_SQL);
47
+ const stmts = {
48
+ credsSelect: db.prepare('SELECT value FROM creds WHERE key = ?'),
49
+ credsUpsert: db.prepare('INSERT INTO creds (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value'),
50
+ keySelect: db.prepare('SELECT value FROM signal_keys WHERE type = ? AND id = ?'),
51
+ keyUpsert: db.prepare('INSERT INTO signal_keys (type, id, value) VALUES (?, ?, ?) ON CONFLICT(type, id) DO UPDATE SET value = excluded.value'),
52
+ keyDelete: db.prepare('DELETE FROM signal_keys WHERE type = ? AND id = ?'),
53
+ keyListIds: db.prepare('SELECT id FROM signal_keys WHERE type = ?'),
54
+ keyList: db.prepare('SELECT id, value FROM signal_keys WHERE type = ?'),
55
+ clearKeys: db.prepare('DELETE FROM signal_keys')
56
+ };
57
+ const loadCreds = () => {
58
+ const row = stmts.credsSelect.get(CREDS_ROW_KEY);
59
+ if (!row)
60
+ return initAuthCreds();
61
+ return JSON.parse(row.value, BufferJSON.reviver);
62
+ };
63
+ const persistCreds = (creds) => {
64
+ stmts.credsUpsert.run(CREDS_ROW_KEY, JSON.stringify(creds, BufferJSON.replacer));
65
+ };
66
+ const creds = loadCreds();
67
+ return {
68
+ state: {
69
+ creds,
70
+ keys: {
71
+ get: async (type, ids) => {
72
+ const data = {};
73
+ for (const id of ids) {
74
+ const row = stmts.keySelect.get(type, id);
75
+ if (row) {
76
+ let value = JSON.parse(row.value, BufferJSON.reviver);
77
+ if (type === 'app-state-sync-key' && value) {
78
+ value = proto.Message.AppStateSyncKeyData.fromObject(value);
79
+ }
80
+ data[id] = value;
81
+ }
82
+ }
83
+ return data;
84
+ },
85
+ set: async (data) => {
86
+ const writeTx = db.transaction(() => {
87
+ for (const category in data) {
88
+ for (const id in data[category]) {
89
+ const value = data[category][id];
90
+ if (value) {
91
+ const stringified = JSON.stringify(value, BufferJSON.replacer);
92
+ stmts.keyUpsert.run(category, id, stringified);
93
+ }
94
+ else {
95
+ stmts.keyDelete.run(category, id);
96
+ }
97
+ }
98
+ }
99
+ });
100
+ writeTx();
101
+ }
102
+ }
103
+ },
104
+ saveCreds: async () => {
105
+ persistCreds(creds);
106
+ }
107
+ };
108
+ }
109
+ //# sourceMappingURL=use-sqlite-auth-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-sqlite-auth-state.js","sourceRoot":"","sources":["../../src/Utils/use-sqlite-auth-state.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,KAAK,UAAU,iBAAiB;IAC/B,IAAI,CAAC;QACJ,8DAA8D;QAC9D,MAAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAA;QAC5C,OAAO,GAAG,CAAC,OAAO,IAAI,GAAG,CAAA;IAC1B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,MAAM,OAAO,GAAG,IAAI,KAAK,CACxB,sJAAsJ,CACtJ,CAAA;QACD,8DAA8D;QAC9D,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G,EAAE;wBAChC,KAAK,MAAM,QAAQ,IAAI,IAAI,EAAE,CAAC;4BAC1B,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;gCAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;gCACjC,IAAI,KAAK,EAAE,CAAC;oCACR,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;oCAC/D,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;gCACnD,CAAC;qCACI,CAAC;oCACF,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;gCACtC,CAAC;4BACL,CAAC;wBACL,CAAC;oBACL,CAAC,CAAC,CAAC;oBAEH,OAAO,EAAE,CAAC;gBACd,CAAC;aACJ;SACJ;QACD,SAAS,EAAE,KAAK,IAAI,EAAE;YAClB,YAAY,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC;KACJ,CAAC;AACN,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itsliaaa/baileys",
3
- "version": "0.3.11",
3
+ "version": "0.3.12",
4
4
  "description": "Enhanced Baileys v7 with fixes for newsletter media uploads, plus support for interactive messages, albums, and additional message types.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -56,6 +56,7 @@
56
56
  "peerDependencies": {
57
57
  "@napi-rs/image": "~1.12.0",
58
58
  "audio-decode": "^2.2.3",
59
+ "better-sqlite3": "^11.0.0",
59
60
  "jimp": "^1.6.1",
60
61
  "link-preview-js": "^3.0.0",
61
62
  "sharp": "*"
@@ -67,6 +68,9 @@
67
68
  "audio-decode": {
68
69
  "optional": true
69
70
  },
71
+ "better-sqlite3": {
72
+ "optional": true
73
+ },
70
74
  "jimp": {
71
75
  "optional": true
72
76
  },