dibosockets 1.0.2 → 1.0.3

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.
Files changed (40) hide show
  1. package/WAProto/WAProto.proto +4775 -5619
  2. package/lib/Defaults/baileys-version.json +3 -3
  3. package/lib/Defaults/index.js +106 -122
  4. package/lib/Socket/RHandler.js +530 -448
  5. package/lib/Socket/business.js +260 -266
  6. package/lib/Socket/chats.js +908 -1137
  7. package/lib/Socket/index.js +10 -43
  8. package/lib/Socket/messages-recv.js +1054 -1065
  9. package/lib/Socket/messages-send.js +903 -881
  10. package/lib/Socket/newsletter.js +303 -286
  11. package/lib/Socket/socket.js +654 -666
  12. package/lib/Store/make-in-memory-store.js +439 -439
  13. package/lib/Types/Newsletter.js +38 -18
  14. package/lib/Utils/baileys-event-stream.js +63 -63
  15. package/lib/Utils/event-buffer.js +518 -518
  16. package/lib/Utils/generics.js +428 -432
  17. package/lib/Utils/index.js +36 -36
  18. package/lib/Utils/messages-media.js +887 -926
  19. package/lib/Utils/messages.js +1030 -1105
  20. package/lib/Utils/process-message.js +385 -404
  21. package/lib/Utils/use-multi-file-auth-state.js +125 -122
  22. package/lib/Utils/validate-connection.js +173 -229
  23. package/lib/WABinary/jid-utils.js +83 -85
  24. package/lib/index.js +86 -74
  25. package/package.json +2 -2
  26. package/lib/Api/Internet/growagarden.js +0 -28
  27. package/lib/Api/creator.json +0 -13
  28. package/lib/Api/downloader/tiktokdownload.js +0 -132
  29. package/lib/Api/index.js +0 -38
  30. package/lib/Api/nsfw/loli.js +0 -79
  31. package/lib/Api/stalker/githubstalk.js +0 -46
  32. package/lib/Api/stalker/stalkroblox.js +0 -94
  33. package/lib/Api/stalker/tiktokstalk.js +0 -68
  34. package/lib/Api/tools/ssweb.js +0 -38
  35. package/lib/Defaults/phonenumber_mcc.json +0 -223
  36. package/lib/Socket/communities.js +0 -441
  37. package/lib/Utils/async-iterable.js +0 -41
  38. package/lib/Utils/browser-utils.js +0 -35
  39. package/lib/Utils/message-retry-manager.js +0 -128
  40. package/lib/Utils/resolveJid.js +0 -52
@@ -1,122 +1,125 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useMultiFileAuthState = void 0;
4
- const async_mutex_1 = require("async-mutex");
5
- const promises_1 = require("fs/promises");
6
- const path_1 = require("path");
7
- const WAProto_1 = require("../../WAProto");
8
- const auth_utils_1 = require("./auth-utils");
9
- const generics_1 = require("./generics");
10
- // We need to lock files due to the fact that we are using async functions to read and write files
11
- const fileLocks = new Map();
12
- // Get or create a mutex for a specific file path
13
- const getFileLock = (path) => {
14
- let mutex = fileLocks.get(path);
15
- if (!mutex) {
16
- mutex = new async_mutex_1.Mutex();
17
- fileLocks.set(path, mutex);
18
- }
19
- return mutex;
20
- };
21
- /**
22
- * stores the full authentication state in a single folder.
23
- * Far more efficient than singlefileauthstate
24
- *
25
- * Again, I wouldn't endorse this for any production level use other than perhaps a bot.
26
- * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
27
- * */
28
- const useMultiFileAuthState = async (folder) => {
29
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
- const writeData = async (data, file) => {
31
- const filePath = (0, path_1.join)(folder, fixFileName(file));
32
- const mutex = getFileLock(filePath);
33
- return mutex.acquire().then(async (release) => {
34
- try {
35
- await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
36
- }
37
- finally {
38
- release();
39
- }
40
- });
41
- };
42
- const readData = async (file) => {
43
- try {
44
- const filePath = (0, path_1.join)(folder, fixFileName(file));
45
- const mutex = getFileLock(filePath);
46
- return await mutex.acquire().then(async (release) => {
47
- try {
48
- const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
49
- return JSON.parse(data, generics_1.BufferJSON.reviver);
50
- }
51
- finally {
52
- release();
53
- }
54
- });
55
- }
56
- catch (error) {
57
- return null;
58
- }
59
- };
60
- const removeData = async (file) => {
61
- try {
62
- const filePath = (0, path_1.join)(folder, fixFileName(file));
63
- const mutex = getFileLock(filePath);
64
- return mutex.acquire().then(async (release) => {
65
- try {
66
- await (0, promises_1.unlink)(filePath);
67
- }
68
- catch (_a) {
69
- }
70
- finally {
71
- release();
72
- }
73
- });
74
- }
75
- catch (_a) {
76
- }
77
- };
78
- const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
79
- if (folderInfo) {
80
- if (!folderInfo.isDirectory()) {
81
- throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
82
- }
83
- }
84
- else {
85
- await (0, promises_1.mkdir)(folder, { recursive: true });
86
- }
87
- const fixFileName = (file) => { var _a; return (_a = file === null || file === void 0 ? void 0 : file.replace(/\//g, '__')) === null || _a === void 0 ? void 0 : _a.replace(/:/g, '-'); };
88
- const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
89
- return {
90
- state: {
91
- creds,
92
- keys: {
93
- get: async (type, ids) => {
94
- const data = {};
95
- await Promise.all(ids.map(async (id) => {
96
- let value = await readData(`${type}-${id}.json`);
97
- if (type === 'app-state-sync-key' && value) {
98
- value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
99
- }
100
- data[id] = value;
101
- }));
102
- return data;
103
- },
104
- set: async (data) => {
105
- const tasks = [];
106
- for (const category in data) {
107
- for (const id in data[category]) {
108
- const value = data[category][id];
109
- const file = `${category}-${id}.json`;
110
- tasks.push(value ? writeData(value, file) : removeData(file));
111
- }
112
- }
113
- await Promise.all(tasks);
114
- }
115
- }
116
- },
117
- saveCreds: async () => {
118
- return writeData(creds, 'creds.json');
119
- }
120
- };
121
- };
122
- exports.useMultiFileAuthState = useMultiFileAuthState;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useMultiFileAuthState = void 0;
4
+ const async_mutex_1 = require("async-mutex");
5
+ const promises_1 = require("fs/promises");
6
+ const path_1 = require("path");
7
+ const WAProto_1 = require("../../WAProto");
8
+ const auth_utils_1 = require("./auth-utils");
9
+ const generics_1 = require("./generics");
10
+ // We need to lock files due to the fact that we are using async functions to read and write files
11
+ // https://github.com/WhiskeySockets/Baileys/issues/794
12
+ // https://github.com/nodejs/node/issues/26338
13
+ // Use a Map to store mutexes for each file path
14
+ const fileLocks = new Map();
15
+ // Get or create a mutex for a specific file path
16
+ const getFileLock = (path) => {
17
+ let mutex = fileLocks.get(path);
18
+ if (!mutex) {
19
+ mutex = new async_mutex_1.Mutex();
20
+ fileLocks.set(path, mutex);
21
+ }
22
+ return mutex;
23
+ };
24
+ /**
25
+ * stores the full authentication state in a single folder.
26
+ * Far more efficient than singlefileauthstate
27
+ *
28
+ * Again, I wouldn't endorse this for any production level use other than perhaps a bot.
29
+ * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
30
+ * */
31
+ const useMultiFileAuthState = async (folder) => {
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
+ const writeData = async (data, file) => {
34
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
35
+ const mutex = getFileLock(filePath);
36
+ return mutex.acquire().then(async (release) => {
37
+ try {
38
+ await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
39
+ }
40
+ finally {
41
+ release();
42
+ }
43
+ });
44
+ };
45
+ const readData = async (file) => {
46
+ try {
47
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
48
+ const mutex = getFileLock(filePath);
49
+ return await mutex.acquire().then(async (release) => {
50
+ try {
51
+ const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
52
+ return JSON.parse(data, generics_1.BufferJSON.reviver);
53
+ }
54
+ finally {
55
+ release();
56
+ }
57
+ });
58
+ }
59
+ catch (error) {
60
+ return null;
61
+ }
62
+ };
63
+ const removeData = async (file) => {
64
+ try {
65
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
66
+ const mutex = getFileLock(filePath);
67
+ return mutex.acquire().then(async (release) => {
68
+ try {
69
+ await (0, promises_1.unlink)(filePath);
70
+ }
71
+ catch (_a) {
72
+ }
73
+ finally {
74
+ release();
75
+ }
76
+ });
77
+ }
78
+ catch (_a) {
79
+ }
80
+ };
81
+ const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
82
+ if (folderInfo) {
83
+ if (!folderInfo.isDirectory()) {
84
+ throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
85
+ }
86
+ }
87
+ else {
88
+ await (0, promises_1.mkdir)(folder, { recursive: true });
89
+ }
90
+ const fixFileName = (file) => { var _a; return (_a = file === null || file === void 0 ? void 0 : file.replace(/\//g, '__')) === null || _a === void 0 ? void 0 : _a.replace(/:/g, '-'); };
91
+ const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
92
+ return {
93
+ state: {
94
+ creds,
95
+ keys: {
96
+ get: async (type, ids) => {
97
+ const data = {};
98
+ await Promise.all(ids.map(async (id) => {
99
+ let value = await readData(`${type}-${id}.json`);
100
+ if (type === 'app-state-sync-key' && value) {
101
+ value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
102
+ }
103
+ data[id] = value;
104
+ }));
105
+ return data;
106
+ },
107
+ set: async (data) => {
108
+ const tasks = [];
109
+ for (const category in data) {
110
+ for (const id in data[category]) {
111
+ const value = data[category][id];
112
+ const file = `${category}-${id}.json`;
113
+ tasks.push(value ? writeData(value, file) : removeData(file));
114
+ }
115
+ }
116
+ await Promise.all(tasks);
117
+ }
118
+ }
119
+ },
120
+ saveCreds: async () => {
121
+ return writeData(creds, 'creds.json');
122
+ }
123
+ };
124
+ };
125
+ exports.useMultiFileAuthState = useMultiFileAuthState;