@queenanya/baileys 7.4.5 → 7.4.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.
@@ -362,6 +362,7 @@ const makeSocket = (config) => {
362
362
  end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
363
363
  };
364
364
  const requestPairingCode = async (phoneNumber) => {
365
+ await waitForSocketOpen();
365
366
  authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
366
367
  authState.creds.me = {
367
368
  id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
@@ -11,6 +11,7 @@ export * from './chat-utils';
11
11
  export * from './lt-hash';
12
12
  export * from './auth-utils';
13
13
  export * from './baileys-event-stream';
14
+ export * from './use-single-file-auth-state';
14
15
  export * from './use-multi-file-auth-state';
15
16
  export * from './link-preview';
16
17
  export * from './event-buffer';
@@ -27,6 +27,7 @@ __exportStar(require("./chat-utils"), exports);
27
27
  __exportStar(require("./lt-hash"), exports);
28
28
  __exportStar(require("./auth-utils"), exports);
29
29
  __exportStar(require("./baileys-event-stream"), exports);
30
+ __exportStar(require("./use-single-file-auth-state"), exports);
30
31
  __exportStar(require("./use-multi-file-auth-state"), exports);
31
32
  __exportStar(require("./link-preview"), exports);
32
33
  __exportStar(require("./event-buffer"), exports);
@@ -0,0 +1,5 @@
1
+ import { AuthenticationState } from '../Types/index';
2
+ export declare const useSingleFileAuthState: (filepath: string) => Promise<{
3
+ state: AuthenticationState;
4
+ saveCreds: () => Promise<void>;
5
+ }>;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useSingleFileAuthState = void 0;
7
+ const async_lock_1 = __importDefault(require("async-lock"));
8
+ const promises_1 = require("fs/promises");
9
+ const index_1 = require("../../WAProto/index");
10
+ const auth_utils_1 = require("./auth-utils");
11
+ const generics_1 = require("./generics");
12
+ const fileLock = new async_lock_1.default({ maxPending: Infinity });
13
+ const useSingleFileAuthState = async (filepath) => {
14
+ const filePath = filepath + '.json';
15
+ const writeData = (data) => {
16
+ return fileLock.acquire(filePath, () => (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer)));
17
+ };
18
+ const readData = async () => {
19
+ try {
20
+ const data = await fileLock.acquire(filePath, () => (0, promises_1.readFile)(filePath, { encoding: 'utf-8' }));
21
+ return JSON.parse(data, generics_1.BufferJSON.reviver);
22
+ }
23
+ catch (error) {
24
+ return null;
25
+ }
26
+ };
27
+ const fileInfo = await (0, promises_1.stat)(filePath).catch(() => null);
28
+ if (fileInfo && !fileInfo.isFile()) {
29
+ throw new Error(`A non-file exists at ${filePath}, please delete it or specify a different path.`);
30
+ }
31
+ // Initialize with default credentials if the file is empty or doesn't exist
32
+ const { creds = (0, auth_utils_1.initAuthCreds)(), keys = {} } = await readData() || {};
33
+ return {
34
+ state: {
35
+ creds,
36
+ keys: {
37
+ get: async (type, ids) => {
38
+ const data = {};
39
+ for (const id of ids) {
40
+ const value = keys[`${type}-${id}`];
41
+ data[id] = type === 'app-state-sync-key' && value
42
+ ? index_1.proto.Message.AppStateSyncKeyData.fromObject(value)
43
+ : value;
44
+ }
45
+ return data;
46
+ },
47
+ set: async (data) => {
48
+ for (const category in data) {
49
+ for (const id in data[category]) {
50
+ const value = data[category][id];
51
+ if (value) {
52
+ keys[`${category}-${id}`] = value;
53
+ }
54
+ else {
55
+ delete keys[`${category}-${id}`];
56
+ }
57
+ }
58
+ }
59
+ await writeData({ creds, keys });
60
+ }
61
+ }
62
+ },
63
+ saveCreds: () => writeData({ creds, keys })
64
+ };
65
+ };
66
+ exports.useSingleFileAuthState = useSingleFileAuthState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@queenanya/baileys",
3
- "version": "7.4.5",
3
+ "version": "7.4.7",
4
4
  "description": "WhatsApp API",
5
5
  "keywords": [
6
6
  "whatsapp",
@@ -14,7 +14,7 @@
14
14
  ],
15
15
  "homepage": "https://github.com/QueenAnya/bail",
16
16
  "repository": {
17
- "url": "git@github.com:QueenAnya/bail"
17
+ "url": "git@github.com:QueenAnya/bail.git"
18
18
  },
19
19
  "license": "MIT",
20
20
  "author": "Adhiraj Singh",
@@ -28,12 +28,13 @@
28
28
  "dependencies": {
29
29
  "@adiwajshing/keyed-db": "^0.2.4",
30
30
  "@queenanya/eslint-config": "github:whiskeysockets/eslint-config",
31
- "@hapi/boom": "* || latest",
31
+ "@hapi/boom": "^10.0.1",
32
32
  "async-lock": "^1.4.1",
33
33
  "audio-decode": "^2.2.0",
34
- "axios": "* || latest || next",
34
+ "axios": "^1.7.3",
35
35
  "cache-manager": "^5.7.6",
36
36
  "futoin-hkdf": "^1.5.3",
37
+ "jimp": "^0.22.12",
37
38
  "json": "^11.0.0",
38
39
  "libphonenumber-js": "^1.11.4",
39
40
  "libsignal": "npm:@queenanya/libsignal@latest",
@@ -55,7 +56,6 @@
55
56
  "conventional-changelog-cli": "^5.0.0",
56
57
  "eslint": "^9.7.0",
57
58
  "jest": "^29.7.0",
58
- "jimp": "^0.22.12",
59
59
  "json": "^11.0.0",
60
60
  "link-preview-js": "^3.0.5",
61
61
  "open": "^10.1.0",