@itsliaaa/baileys 0.1.13 → 0.1.15

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
@@ -272,7 +272,7 @@ sock.sendMessage(jid, {
272
272
  const vcard = 'BEGIN:VCARD\n'
273
273
  + 'VERSION:3.0\n'
274
274
  + 'FN:Lia Wynn\n'
275
- + 'ORG:Waiters;\n'
275
+ + 'ORG:Waitress;\n'
276
276
  + 'TEL;type=CELL;type=VOICE;waid=628123456789:+62 8123 4567 89\n'
277
277
  + 'END:VCARD'
278
278
 
package/WAProto/index.js CHANGED
@@ -92815,7 +92815,7 @@ export const proto = $root.proto = (() => {
92815
92815
  this[ks[i]] = p[ks[i]];
92816
92816
  }
92817
92817
 
92818
- CustomList.prototype.id = null;
92818
+ CustomList.prototype.listId = null;
92819
92819
  CustomList.prototype.name = null;
92820
92820
  CustomList.prototype.emoji = null;
92821
92821
  CustomList.prototype.isSelected = null;
@@ -92823,8 +92823,8 @@ export const proto = $root.proto = (() => {
92823
92823
 
92824
92824
  let $oneOfFields;
92825
92825
 
92826
- Object.defineProperty(CustomList.prototype, "_id", {
92827
- get: $util.oneOfGetter($oneOfFields = ["id"]),
92826
+ Object.defineProperty(CustomList.prototype, "_listId", {
92827
+ get: $util.oneOfGetter($oneOfFields = ["listId"]),
92828
92828
  set: $util.oneOfSetter($oneOfFields)
92829
92829
  });
92830
92830
 
@@ -92850,8 +92850,8 @@ export const proto = $root.proto = (() => {
92850
92850
  CustomList.encode = function encode(m, w) {
92851
92851
  if (!w)
92852
92852
  w = $Writer.create();
92853
- if (m.id != null && Object.hasOwnProperty.call(m, "id"))
92854
- w.uint32(8).int64(m.id);
92853
+ if (m.listId != null && Object.hasOwnProperty.call(m, "listId"))
92854
+ w.uint32(10).string(m.listId);
92855
92855
  if (m.name != null && Object.hasOwnProperty.call(m, "name"))
92856
92856
  w.uint32(18).string(m.name);
92857
92857
  if (m.emoji != null && Object.hasOwnProperty.call(m, "emoji"))
@@ -92875,7 +92875,7 @@ export const proto = $root.proto = (() => {
92875
92875
  break;
92876
92876
  switch (t >>> 3) {
92877
92877
  case 1: {
92878
- m.id = r.int64();
92878
+ m.listId = r.string();
92879
92879
  break;
92880
92880
  }
92881
92881
  case 2: {
@@ -92908,15 +92908,8 @@ export const proto = $root.proto = (() => {
92908
92908
  if (d instanceof $root.proto.SyncActionValue.StatusPrivacyAction.CustomList)
92909
92909
  return d;
92910
92910
  var m = new $root.proto.SyncActionValue.StatusPrivacyAction.CustomList();
92911
- if (d.id != null) {
92912
- if ($util.Long)
92913
- (m.id = $util.Long.fromValue(d.id)).unsigned = false;
92914
- else if (typeof d.id === "string")
92915
- m.id = parseInt(d.id, 10);
92916
- else if (typeof d.id === "number")
92917
- m.id = d.id;
92918
- else if (typeof d.id === "object")
92919
- m.id = new $util.LongBits(d.id.low >>> 0, d.id.high >>> 0).toNumber();
92911
+ if (d.listId != null) {
92912
+ m.listId = String(d.listId);
92920
92913
  }
92921
92914
  if (d.name != null) {
92922
92915
  m.name = String(d.name);
@@ -92945,13 +92938,10 @@ export const proto = $root.proto = (() => {
92945
92938
  if (o.arrays || o.defaults) {
92946
92939
  d.userJid = [];
92947
92940
  }
92948
- if (m.id != null && m.hasOwnProperty("id")) {
92949
- if (typeof m.id === "number")
92950
- d.id = o.longs === String ? String(m.id) : m.id;
92951
- else
92952
- d.id = o.longs === String ? longToString(m.id) : o.longs === Number ? longToNumber(m.id) : m.id;
92941
+ if (m.listId != null && m.hasOwnProperty("listId")) {
92942
+ d.listId = m.listId;
92953
92943
  if (o.oneofs)
92954
- d._id = "id";
92944
+ d._listId = "listId";
92955
92945
  }
92956
92946
  if (m.name != null && m.hasOwnProperty("name")) {
92957
92947
  d.name = m.name;
@@ -11,6 +11,7 @@ export * from './chat-utils.js';
11
11
  export * from './lt-hash.js';
12
12
  export * from './auth-utils.js';
13
13
  export * from './use-multi-file-auth-state.js';
14
+ export * from './use-single-file-auth-state.js';
14
15
  export * from './link-preview.js';
15
16
  export * from './event-buffer.js';
16
17
  export * from './process-message.js';
@@ -0,0 +1,97 @@
1
+ import { readFile, rename, stat, writeFile } from 'fs/promises';
2
+ import { DEFAULT_CACHE_TTLS } from '../Defaults/index.js';
3
+ import { proto } from '../../WAProto/index.js';
4
+ import { initAuthCreds } from './auth-utils.js';
5
+ import { BufferJSON } from './generics.js';
6
+ // Lia@Changes 25-03-26 --- Add useSingleFileAuthState with integrated cache
7
+ const FLUSH_TIMEOUT_MS = 3000
8
+ export const useSingleFileAuthState = async (fileName) => {
9
+ const cache = new Map();
10
+ let isLoaded,
11
+ isWriting,
12
+ isNeedWrite,
13
+ flushTimeout,
14
+ loadPromise;
15
+ const loadKey = () => {
16
+ if (isLoaded) return;
17
+ if (loadPromise) return loadPromise;
18
+ loadPromise = (async () => {
19
+ try {
20
+ const data = JSON.parse(await readFile(fileName, 'utf-8'), BufferJSON.reviver);
21
+ for (const [keyName, value] of Object.entries(data)) {
22
+ cache.set(keyName, value);
23
+ }
24
+ }
25
+ catch { }
26
+ isLoaded = true;
27
+ loadPromise = null;
28
+ })();
29
+ return loadPromise;
30
+ };
31
+ const flushKey = () => {
32
+ if (flushTimeout) return;
33
+ flushTimeout = setTimeout(async () => {
34
+ flushTimeout = null;
35
+ if (isWriting) {
36
+ isNeedWrite = true;
37
+ return;
38
+ }
39
+ isWriting = true;
40
+ do {
41
+ isNeedWrite = false;
42
+ const tempFile = fileName + '.temp';
43
+ const value = Object.fromEntries(cache);
44
+ await writeFile(tempFile, JSON.stringify(value, BufferJSON.replacer));
45
+ await rename(tempFile, fileName);
46
+ }
47
+ while (isNeedWrite);
48
+ isWriting = false;
49
+ }, FLUSH_TIMEOUT_MS);
50
+ };
51
+ const writeKey = (keyName, value) => {
52
+ cache.set(keyName, value);
53
+ flushKey();
54
+ };
55
+ const removeKey = (keyName) => {
56
+ cache.delete(keyName);
57
+ flushKey();
58
+ };
59
+ const fileInfo = await stat(fileName).catch(() => null);
60
+ if (!fileInfo) {
61
+ await writeFile(fileName, '{}');
62
+ }
63
+ else if (!fileInfo.isFile()) {
64
+ throw new Error(`found something that is not a file at ${fileName}, either delete it or specify a different location`);
65
+ }
66
+ await loadKey();
67
+ const creds = cache.get('creds') || initAuthCreds();
68
+ return {
69
+ state: {
70
+ creds,
71
+ keys: {
72
+ get: (type, ids) => {
73
+ const data = {};
74
+ for (const id of ids) {
75
+ let value = cache.get(type + '-' + id);
76
+ if (type === 'app-state-sync-key' && value) {
77
+ value = proto.Message.AppStateSyncKeyData.fromObject(value);
78
+ }
79
+ data[id] = value;
80
+ }
81
+ return data;
82
+ },
83
+ set: (data) => {
84
+ for (const category in data) {
85
+ for (const id in data[category]) {
86
+ const keyName = category + '-' + id;
87
+ const value = data[category][id];
88
+ value ? writeKey(keyName, value) : removeKey(keyName)
89
+ }
90
+ }
91
+ },
92
+ clear: () => cache.clear()
93
+ }
94
+ },
95
+ saveCreds: () => writeKey('creds', creds)
96
+ };
97
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itsliaaa/baileys",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "A simple fork of Baileys for WhatsApp automation",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",