@baileys-md/baileys 12.0.0 → 12.2.0

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 (109) hide show
  1. package/LICENSE +21 -13
  2. package/WAProto/WAProto.proto +769 -233
  3. package/WAProto/index.js +65813 -141372
  4. package/lib/Defaults/index.js +128 -113
  5. package/lib/KeyDB/BinarySearch.js +30 -0
  6. package/lib/KeyDB/KeyedDB.js +178 -0
  7. package/lib/KeyDB/index.js +14 -0
  8. package/lib/Signal/Group/ciphertext-message.js +22 -14
  9. package/lib/Signal/Group/group-session-builder.js +21 -42
  10. package/lib/Signal/Group/group_cipher.js +85 -87
  11. package/lib/Signal/Group/index.js +23 -57
  12. package/lib/Signal/Group/keyhelper.js +28 -52
  13. package/lib/Signal/Group/sender-chain-key.js +37 -33
  14. package/lib/Signal/Group/sender-key-distribution-message.js +73 -63
  15. package/lib/Signal/Group/sender-key-message.js +75 -66
  16. package/lib/Signal/Group/sender-key-name.js +55 -44
  17. package/lib/Signal/Group/sender-key-record.js +49 -49
  18. package/lib/Signal/Group/sender-key-state.js +90 -93
  19. package/lib/Signal/Group/sender-message-key.js +37 -28
  20. package/lib/Signal/libsignal.js +324 -163
  21. package/lib/Signal/lid-mapping.js +166 -0
  22. package/lib/Socket/Client/index.js +14 -18
  23. package/lib/Socket/Client/types.js +12 -12
  24. package/lib/Socket/Client/websocket.js +60 -109
  25. package/lib/Socket/business.js +359 -242
  26. package/lib/Socket/chats.js +857 -898
  27. package/lib/Socket/communities.js +413 -0
  28. package/lib/Socket/groups.js +304 -324
  29. package/lib/Socket/index.js +25 -9
  30. package/lib/Socket/messages-recv.js +1109 -1000
  31. package/lib/Socket/messages-send.js +615 -387
  32. package/lib/Socket/mex.js +45 -0
  33. package/lib/Socket/newsletter.js +231 -227
  34. package/lib/Socket/socket.js +803 -628
  35. package/lib/Store/index.js +18 -8
  36. package/lib/Store/make-cache-manager-store.js +75 -0
  37. package/lib/Store/make-in-memory-store.js +286 -435
  38. package/lib/Store/make-ordered-dictionary.js +77 -79
  39. package/lib/Store/object-repository.js +24 -26
  40. package/lib/Types/Auth.js +13 -2
  41. package/lib/Types/Bussines.js +13 -0
  42. package/lib/Types/Call.js +13 -2
  43. package/lib/Types/Chat.js +19 -4
  44. package/lib/Types/Contact.js +13 -2
  45. package/lib/Types/Events.js +13 -2
  46. package/lib/Types/GroupMetadata.js +13 -2
  47. package/lib/Types/Label.js +43 -26
  48. package/lib/Types/LabelAssociation.js +16 -8
  49. package/lib/Types/Message.js +22 -7
  50. package/lib/Types/Newsletter.js +42 -17
  51. package/lib/Types/Product.js +13 -2
  52. package/lib/Types/Signal.js +13 -2
  53. package/lib/Types/Socket.js +14 -2
  54. package/lib/Types/State.js +21 -2
  55. package/lib/Types/USync.js +13 -2
  56. package/lib/Types/index.js +37 -41
  57. package/lib/Utils/auth-utils.js +219 -189
  58. package/lib/Utils/baileys-event-stream.js +54 -0
  59. package/lib/Utils/browser-utils.js +21 -31
  60. package/lib/Utils/business.js +213 -214
  61. package/lib/Utils/chat-utils.js +711 -689
  62. package/lib/Utils/crypto.js +112 -175
  63. package/lib/Utils/decode-wa-message.js +254 -194
  64. package/lib/Utils/event-buffer.js +510 -500
  65. package/lib/Utils/generics.js +318 -430
  66. package/lib/Utils/history.js +83 -90
  67. package/lib/Utils/index.js +31 -35
  68. package/lib/Utils/link-preview.js +71 -116
  69. package/lib/Utils/logger.js +5 -7
  70. package/lib/Utils/lt-hash.js +40 -46
  71. package/lib/Utils/make-mutex.js +34 -41
  72. package/lib/Utils/message-retry-manager.js +33 -48
  73. package/lib/Utils/messages-media.js +516 -784
  74. package/lib/Utils/messages.js +347 -489
  75. package/lib/Utils/noise-handler.js +138 -144
  76. package/lib/Utils/pre-key-manager.js +95 -0
  77. package/lib/Utils/process-message.js +331 -384
  78. package/lib/Utils/signal.js +157 -139
  79. package/lib/Utils/use-multi-file-auth-state.js +119 -91
  80. package/lib/Utils/validate-connection.js +184 -203
  81. package/lib/WABinary/constants.js +1308 -1298
  82. package/lib/WABinary/decode.js +241 -256
  83. package/lib/WABinary/encode.js +217 -239
  84. package/lib/WABinary/generic-utils.js +131 -40
  85. package/lib/WABinary/index.js +17 -21
  86. package/lib/WABinary/jid-utils.js +97 -79
  87. package/lib/WABinary/types.js +13 -2
  88. package/lib/WAM/BinaryInfo.js +20 -12
  89. package/lib/WAM/constants.js +22863 -15348
  90. package/lib/WAM/encode.js +145 -136
  91. package/lib/WAM/index.js +15 -19
  92. package/lib/WAUSync/Protocols/USyncContactProtocol.js +39 -31
  93. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +61 -54
  94. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +39 -29
  95. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +48 -40
  96. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +62 -51
  97. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +38 -21
  98. package/lib/WAUSync/Protocols/index.js +17 -20
  99. package/lib/WAUSync/USyncQuery.js +98 -86
  100. package/lib/WAUSync/USyncUser.js +35 -26
  101. package/lib/WAUSync/index.js +16 -19
  102. package/lib/index.js +23 -41
  103. package/package.json +46 -56
  104. package/README.md +0 -113
  105. package/WAProto/GenerateStatics.sh +0 -4
  106. package/lib/Defaults/wileys-version.json +0 -3
  107. package/lib/Signal/Group/queue-job.js +0 -57
  108. package/lib/Socket/usync.js +0 -70
  109. package/lib/Utils/wileys-event-stream.js +0 -63
@@ -1,42 +1,38 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.DisconnectReason = void 0;
18
- __exportStar(require("./Auth"), exports);
19
- __exportStar(require("./GroupMetadata"), exports);
20
- __exportStar(require("./Newsletter"), exports);
21
- __exportStar(require("./Chat"), exports);
22
- __exportStar(require("./Contact"), exports);
23
- __exportStar(require("./State"), exports);
24
- __exportStar(require("./Message"), exports);
25
- __exportStar(require("./Socket"), exports);
26
- __exportStar(require("./Events"), exports);
27
- __exportStar(require("./Product"), exports);
28
- __exportStar(require("./Call"), exports);
29
- __exportStar(require("./Signal"), exports);
30
- var DisconnectReason;
1
+ //========================================//
2
+ /**
3
+ * @project @sixcore/baileys
4
+ * @author Sixx.js </>🌿
5
+ * @version 1.0.3
6
+ * @license MIT
7
+ * @country Mozambique 🇲🇿♥️
8
+ * @chamadas || sms +258860817689
9
+ * @whatsApp +55889616-2417 || +258851907875
10
+ * @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
11
+ */
12
+
13
+ export * from "./GroupMetadata.js";
14
+ export * from "./Newsletter.js";
15
+ export * from "./Contact.js";
16
+ export * from "./Message.js";
17
+ export * from "./Product.js";
18
+ export * from "./Socket.js";
19
+ export * from "./Events.js";
20
+ export * from "./Signal.js";
21
+ export * from "./State.js";
22
+ export * from "./Chat.js";
23
+ export * from "./Call.js";
24
+ export * from "./Auth.js";
25
+
26
+ export var DisconnectReason;
31
27
  (function (DisconnectReason) {
32
- DisconnectReason[DisconnectReason["connectionClosed"] = 428] = "connectionClosed";
33
- DisconnectReason[DisconnectReason["connectionLost"] = 408] = "connectionLost";
34
- DisconnectReason[DisconnectReason["connectionReplaced"] = 440] = "connectionReplaced";
35
- DisconnectReason[DisconnectReason["timedOut"] = 408] = "timedOut";
36
- DisconnectReason[DisconnectReason["loggedOut"] = 401] = "loggedOut";
37
- DisconnectReason[DisconnectReason["badSession"] = 500] = "badSession";
38
- DisconnectReason[DisconnectReason["restartRequired"] = 515] = "restartRequired";
39
- DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
40
- DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
41
- DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
42
- })(DisconnectReason || (exports.DisconnectReason = DisconnectReason = {}));
28
+ DisconnectReason[DisconnectReason["connectionClosed"] = 428] = "connectionClosed";
29
+ DisconnectReason[DisconnectReason["connectionLost"] = 408] = "connectionLost";
30
+ DisconnectReason[DisconnectReason["connectionReplaced"] = 440] = "connectionReplaced";
31
+ DisconnectReason[DisconnectReason["timedOut"] = 408] = "timedOut";
32
+ DisconnectReason[DisconnectReason["loggedOut"] = 401] = "loggedOut";
33
+ DisconnectReason[DisconnectReason["badSession"] = 500] = "badSession";
34
+ DisconnectReason[DisconnectReason["restartRequired"] = 515] = "restartRequired";
35
+ DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
36
+ DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
37
+ DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
38
+ })(DisconnectReason || (DisconnectReason = {}));
@@ -1,199 +1,229 @@
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.initAuthCreds = exports.addTransactionCapability = void 0;
7
- exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
8
- const crypto_1 = require("crypto");
9
- const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
10
- const Defaults_1 = require("../Defaults");
11
- const crypto_2 = require("./crypto");
12
- const generics_1 = require("./generics");
1
+ //========================================//
13
2
  /**
14
- * Adds caching capability to a SignalKeyStore
15
- * @param store the store to add caching to
16
- * @param logger to log trace events
17
- * @param _cache cache store to use
3
+ * @project @sixcore/baileys
4
+ * @author Sixx.js </>🌿
5
+ * @version 1.0.3
6
+ * @license MIT
7
+ * @country Mozambique 🇲🇿♥️
8
+ * @chamadas || sms +258860817689
9
+ * @whatsApp +55889616-2417 || +258851907875
10
+ * @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
18
11
  */
19
- function makeCacheableSignalKeyStore(store, logger, _cache) {
20
- const cache = _cache || new node_cache_1.default({
21
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
22
- useClones: false,
23
- deleteOnExpire: true,
12
+
13
+ import { delay, generateRegistrationId } from "./generics.js";
14
+ import { DEFAULT_CACHE_TTLS } from "../Defaults/index.js";
15
+ import { PreKeyManager } from "./pre-key-manager.js";
16
+ import { Curve, signedKeyPair } from "./crypto.js";
17
+ import { AsyncLocalStorage } from "async_hooks";
18
+ import NodeCache from "@cacheable/node-cache";
19
+ import { randomBytes } from "crypto";
20
+ import { Mutex } from "async-mutex";
21
+ import PQueue from "p-queue";
22
+
23
+ export function makeCacheableSignalKeyStore(store, logger, _cache) {
24
+ const cache = _cache ||
25
+ new NodeCache({
26
+ stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE,
27
+ useClones: false,
28
+ deleteOnExpire: true
24
29
  });
25
- function getUniqueId(type, id) {
26
- return `${type}.${id}`;
27
- }
28
- return {
29
- async get(type, ids) {
30
- const data = {};
31
- const idsToFetch = [];
32
- for (const id of ids) {
33
- const item = cache.get(getUniqueId(type, id));
34
- if (typeof item !== 'undefined') {
35
- data[id] = item;
36
- }
37
- else {
38
- idsToFetch.push(id);
39
- }
40
- }
41
- if (idsToFetch.length) {
42
- logger === null || logger === void 0 ? void 0 : logger.trace({ items: idsToFetch.length }, 'loading from store');
43
- const fetched = await store.get(type, idsToFetch);
44
- for (const id of idsToFetch) {
45
- const item = fetched[id];
46
- if (item) {
47
- data[id] = item;
48
- cache.set(getUniqueId(type, id), item);
49
- }
50
- }
51
- }
52
- return data;
53
- },
54
- async set(data) {
55
- let keys = 0;
56
- for (const type in data) {
57
- for (const id in data[type]) {
58
- cache.set(getUniqueId(type, id), data[type][id]);
59
- keys += 1;
60
- }
30
+ const cacheMutex = new Mutex();
31
+ function getUniqueId(type, id) {
32
+ return `${type}.${id}`;
33
+ }
34
+ return {
35
+ async get(type, ids) {
36
+ return cacheMutex.runExclusive(async () => {
37
+ const data = {};
38
+ const idsToFetch = [];
39
+ for (const id of ids) {
40
+ const item = (await cache.get(getUniqueId(type, id)));
41
+ if (typeof item !== "undefined") {
42
+ data[id] = item;
43
+ }
44
+ else {
45
+ idsToFetch.push(id);
46
+ }
47
+ }
48
+ if (idsToFetch.length) {
49
+ logger?.trace({ items: idsToFetch.length }, "loading from store");
50
+ const fetched = await store.get(type, idsToFetch);
51
+ for (const id of idsToFetch) {
52
+ const item = fetched[id];
53
+ if (item) {
54
+ data[id] = item;
55
+ cache.set(getUniqueId(type, id), item);
61
56
  }
62
- logger === null || logger === void 0 ? void 0 : logger.trace({ keys }, 'updated cache');
63
- await store.set(data);
64
- },
65
- async clear() {
66
- var _a;
67
- cache.flushAll();
68
- await ((_a = store.clear) === null || _a === void 0 ? void 0 : _a.call(store));
57
+ }
58
+ }
59
+ return data;
60
+ });
61
+ },
62
+ async set(data) {
63
+ return cacheMutex.runExclusive(async () => {
64
+ let keys = 0;
65
+ for (const type in data) {
66
+ for (const id in data[type]) {
67
+ await cache.set(getUniqueId(type, id), data[type][id]);
68
+ keys += 1;
69
+ }
69
70
  }
70
- };
71
+ logger?.trace({ keys }, "updated cache");
72
+ await store.set(data);
73
+ });
74
+ },
75
+ async clear() {
76
+ await cache.flushAll();
77
+ await store.clear?.();
78
+ }
79
+ };
71
80
  }
72
- /**
73
- * Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
74
- * this allows batch read & write operations & improves the performance of the lib
75
- * @param state the key store to apply this capability to
76
- * @param logger logger to log events
77
- * @returns SignalKeyStore with transaction capability
78
- */
79
- const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
80
- // number of queries made to the DB during the transaction
81
- // only there for logging purposes
82
- let dbQueriesInTransaction = 0;
83
- let transactionCache = {};
84
- let mutations = {};
85
- let transactionsInProgress = 0;
86
- return {
87
- get: async (type, ids) => {
88
- if (isInTransaction()) {
89
- const dict = transactionCache[type];
90
- const idsRequiringFetch = dict
91
- ? ids.filter(item => typeof dict[item] === 'undefined')
92
- : ids;
93
- // only fetch if there are any items to fetch
94
- if (idsRequiringFetch.length) {
95
- dbQueriesInTransaction += 1;
96
- const result = await state.get(type, idsRequiringFetch);
97
- transactionCache[type] || (transactionCache[type] = {});
98
- Object.assign(transactionCache[type], result);
99
- }
100
- return ids.reduce((dict, id) => {
101
- var _a;
102
- const value = (_a = transactionCache[type]) === null || _a === void 0 ? void 0 : _a[id];
103
- if (value) {
104
- dict[id] = value;
105
- }
106
- return dict;
107
- }, {});
108
- }
109
- else {
110
- return state.get(type, ids);
111
- }
112
- },
113
- set: data => {
114
- if (isInTransaction()) {
115
- logger.trace({ types: Object.keys(data) }, 'caching in transaction');
116
- for (const key in data) {
117
- transactionCache[key] = transactionCache[key] || {};
118
- Object.assign(transactionCache[key], data[key]);
119
- mutations[key] = mutations[key] || {};
120
- Object.assign(mutations[key], data[key]);
121
- }
122
- }
123
- else {
124
- return state.set(data);
125
- }
126
- },
127
- isInTransaction,
128
- async transaction(work) {
129
- let result;
130
- transactionsInProgress += 1;
131
- if (transactionsInProgress === 1) {
132
- logger.trace('entering transaction');
133
- }
134
- try {
135
- result = await work();
136
- // commit if this is the outermost transaction
137
- if (transactionsInProgress === 1) {
138
- if (Object.keys(mutations).length) {
139
- logger.trace('committing transaction');
140
- // retry mechanism to ensure we've some recovery
141
- // in case a transaction fails in the first attempt
142
- let tries = maxCommitRetries;
143
- while (tries) {
144
- tries -= 1;
145
- try {
146
- await state.set(mutations);
147
- logger.trace({ dbQueriesInTransaction }, 'committed transaction');
148
- break;
149
- }
150
- catch (error) {
151
- logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`);
152
- await (0, generics_1.delay)(delayBetweenTriesMs);
153
- }
154
- }
155
- }
156
- else {
157
- logger.trace('no mutations in transaction');
158
- }
159
- }
160
- }
161
- finally {
162
- transactionsInProgress -= 1;
163
- if (transactionsInProgress === 0) {
164
- transactionCache = {};
165
- mutations = {};
166
- dbQueriesInTransaction = 0;
167
- }
168
- }
169
- return result;
81
+
82
+ export const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
83
+ const txStorage = new AsyncLocalStorage();
84
+ const keyQueues = new Map();
85
+ const txMutexes = new Map();
86
+ const preKeyManager = new PreKeyManager(state, logger);
87
+ function getQueue(key) {
88
+ if (!keyQueues.has(key)) {
89
+ keyQueues.set(key, new PQueue({ concurrency: 1 }));
90
+ }
91
+ return keyQueues.get(key);
92
+ }
93
+ function getTxMutex(key) {
94
+ if (!txMutexes.has(key)) {
95
+ txMutexes.set(key, new Mutex());
96
+ }
97
+ return txMutexes.get(key);
98
+ }
99
+ function isInTransaction() {
100
+ return !!txStorage.getStore();
101
+ }
102
+ async function commitWithRetry(mutations) {
103
+ if (Object.keys(mutations).length === 0) {
104
+ logger.trace("no mutations in transaction");
105
+ return;
106
+ }
107
+ logger.trace("committing transaction");
108
+ for (let attempt = 0; attempt < maxCommitRetries; attempt++) {
109
+ try {
110
+ await state.set(mutations);
111
+ logger.trace({ mutationCount: Object.keys(mutations).length }, "committed transaction");
112
+ return;
113
+ }
114
+ catch (error) {
115
+ const retriesLeft = maxCommitRetries - attempt - 1;
116
+ logger.warn(`failed to commit mutations, retries left=${retriesLeft}`);
117
+ if (retriesLeft === 0) {
118
+ throw error;
119
+ }
120
+ await delay(delayBetweenTriesMs);
121
+ }
122
+ }
123
+ }
124
+ return {
125
+ get: async (type, ids) => {
126
+ const ctx = txStorage.getStore();
127
+ if (!ctx) {
128
+ return state.get(type, ids);
129
+ }
130
+ const cached = ctx.cache[type] || {};
131
+ const missing = ids.filter(id => !(id in cached));
132
+ if (missing.length > 0) {
133
+ ctx.dbQueries++;
134
+ logger.trace({ type, count: missing.length }, "fetching missing keys in transaction");
135
+ const fetched = await getTxMutex(type).runExclusive(() => state.get(type, missing));
136
+ ctx.cache[type] = ctx.cache[type] || {};
137
+ Object.assign(ctx.cache[type], fetched);
138
+ }
139
+ const result = {};
140
+ for (const id of ids) {
141
+ const value = ctx.cache[type]?.[id];
142
+ if (value !== undefined && value !== null) {
143
+ result[id] = value;
144
+ }
145
+ }
146
+ return result;
147
+ },
148
+ set: async (data) => {
149
+ const ctx = txStorage.getStore();
150
+ if (!ctx) {
151
+ const types = Object.keys(data);
152
+ for (const type_ of types) {
153
+ const type = type_;
154
+ if (type === "pre-key") {
155
+ await preKeyManager.validateDeletions(data, type);
156
+ }
157
+ }
158
+ await Promise.all(types.map(type => getQueue(type).add(async () => {
159
+ const typeData = { [type]: data[type] };
160
+ await state.set(typeData);
161
+ })));
162
+ return;
163
+ }
164
+ logger.trace({ types: Object.keys(data) }, "caching in transaction");
165
+ for (const key_ in data) {
166
+ const key = key_;
167
+ ctx.cache[key] = ctx.cache[key] || {};
168
+ ctx.mutations[key] = ctx.mutations[key] || {};
169
+ if (key === "pre-key") {
170
+ await preKeyManager.processOperations(data, key, ctx.cache, ctx.mutations, true);
171
+ }
172
+ else {
173
+ Object.assign(ctx.cache[key], data[key]);
174
+ Object.assign(ctx.mutations[key], data[key]);
175
+ }
176
+ }
177
+ },
178
+ isInTransaction,
179
+ transaction: async (work, key) => {
180
+ const existing = txStorage.getStore();
181
+ if (existing) {
182
+ logger.trace("reusing existing transaction context");
183
+ return work();
184
+ }
185
+ return getTxMutex(key).runExclusive(async () => {
186
+ const ctx = {
187
+ cache: {},
188
+ mutations: {},
189
+ dbQueries: 0
190
+ };
191
+ logger.trace("entering transaction");
192
+ try {
193
+ const result = await txStorage.run(ctx, work);
194
+ await commitWithRetry(ctx.mutations);
195
+ logger.trace({ dbQueries: ctx.dbQueries }, "transaction completed");
196
+ return result;
197
+ }
198
+ catch (error) {
199
+ logger.error({ error }, "transaction failed, rolling back");
200
+ throw error;
170
201
  }
171
- };
172
- function isInTransaction() {
173
- return transactionsInProgress > 0;
202
+ });
174
203
  }
204
+ };
175
205
  };
176
- exports.addTransactionCapability = addTransactionCapability;
177
- const initAuthCreds = () => {
178
- const identityKey = crypto_2.Curve.generateKeyPair();
179
- return {
180
- noiseKey: crypto_2.Curve.generateKeyPair(),
181
- pairingEphemeralKeyPair: crypto_2.Curve.generateKeyPair(),
182
- signedIdentityKey: identityKey,
183
- signedPreKey: (0, crypto_2.signedKeyPair)(identityKey, 1),
184
- registrationId: (0, generics_1.generateRegistrationId)(),
185
- advSecretKey: (0, crypto_1.randomBytes)(32).toString('base64'),
186
- processedHistoryMessages: [],
187
- nextPreKeyId: 1,
188
- firstUnuploadedPreKeyId: 1,
189
- accountSyncCounter: 0,
190
- accountSettings: {
191
- unarchiveChats: false
192
- },
193
- registered: false,
194
- pairingCode: undefined,
195
- lastPropHash: undefined,
196
- routingInfo: undefined,
197
- };
206
+
207
+ export const initAuthCreds = () => {
208
+ const identityKey = Curve.generateKeyPair();
209
+ return {
210
+ "noiseKey": Curve.generateKeyPair(),
211
+ "pairingEphemeralKeyPair": Curve.generateKeyPair(),
212
+ "signedIdentityKey": identityKey,
213
+ "signedPreKey": signedKeyPair(identityKey, 1),
214
+ "registrationId": generateRegistrationId(),
215
+ "advSecretKey": randomBytes(32).toString("base64"),
216
+ "processedHistoryMessages": [],
217
+ "nextPreKeyId": 1,
218
+ "firstUnuploadedPreKeyId": 1,
219
+ "accountSyncCounter": 0,
220
+ "accountSettings": {
221
+ "unarchiveChats": false
222
+ },
223
+ "registered": false,
224
+ "pairingCode": undefined,
225
+ "lastPropHash": undefined,
226
+ "routingInfo": undefined,
227
+ "additionalData": undefined
228
+ };
198
229
  };
199
- exports.initAuthCreds = initAuthCreds;
@@ -0,0 +1,54 @@
1
+ //========================================//
2
+ /**
3
+ * @project @sixcore/baileys
4
+ * @author Sixx.js </>🌿
5
+ * @version 1.0.3
6
+ * @license MIT
7
+ * @country Mozambique 🇲🇿♥️
8
+ * @chamadas || sms +258860817689
9
+ * @whatsApp +55889616-2417 || +258851907875
10
+ * @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
11
+ */
12
+
13
+ import { makeMutex } from "./make-mutex.js";
14
+ import { createInterface } from "readline";
15
+ import { writeFile } from "fs/promises";
16
+ import { delay } from "./generics.js";
17
+ import { createReadStream } from "fs";
18
+ import EventEmitter from "events";
19
+
20
+ export const captureEventStream = (ev, filename) => {
21
+ const oldEmit = ev.emit;
22
+ const writeMutex = makeMutex();
23
+ ev.emit = function (...args) {
24
+ const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + "\n";
25
+ const result = oldEmit.apply(ev, args);
26
+ writeMutex.mutex(async () => {
27
+ await writeFile(filename, content, { flag: "a" });
28
+ });
29
+ return result;
30
+ };
31
+ };
32
+
33
+ export const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
34
+ const ev = new EventEmitter();
35
+ const fireEvents = async () => {
36
+ const fileStream = createReadStream(filename);
37
+ const rl = createInterface({
38
+ input: fileStream,
39
+ crlfDelay: Infinity
40
+ });
41
+ for await (const line of rl) {
42
+ if (line) {
43
+ const { event, data } = JSON.parse(line);
44
+ ev.emit(event, data);
45
+ delayIntervalMs && (await delay(delayIntervalMs));
46
+ }
47
+ }
48
+ fileStream.close();
49
+ };
50
+ return {
51
+ ev,
52
+ task: fireEvents()
53
+ };
54
+ };
@@ -1,35 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPlatformId = exports.Browsers = void 0;
4
-
5
- const os = require("os");
6
- const { proto } = require("../../WAProto/index.js");
7
-
1
+ //=======================================================//
2
+ import { proto } from "../../WAProto/index.js";
3
+ import { platform, release } from "os";
4
+ //=======================================================//
8
5
  const PLATFORM_MAP = {
9
- 'aix': 'AIX',
10
- 'darwin': 'Mac OS',
11
- 'win32': 'Windows',
12
- 'android': 'Android',
13
- 'freebsd': 'FreeBSD',
14
- 'openbsd': 'OpenBSD',
15
- 'sunos': 'Solaris',
16
- 'linux': undefined, // Default ke Ubuntu untuk Linux
17
- 'haiku': undefined,
18
- 'cygwin': undefined,
19
- 'netbsd': undefined
6
+ 'Chrome': '49',
7
+ 'Edge': '50',
8
+ 'Firefox': '51',
9
+ 'Opera': '53',
10
+ 'Safari': '54'
20
11
  };
21
-
22
- // Fixed: Browsers sekarang fungsi yang return array [platform, browser, version]
23
- // Ini kompatibel dengan pemanggilan Browsers('Chrome') di Defaults/index.js
24
- exports.Browsers = (browser) => {
25
- const osName = PLATFORM_MAP[os.platform()] || 'Ubuntu'; // Default Ubuntu kalau undefined
26
- const osRelease = os.release(); // Ambil versi OS real-time
27
- return [osName, browser, osRelease];
12
+ //=======================================================//
13
+ export const Browsers = {
14
+ iOS: (browser) => ["ios", browser, "18.2"],
15
+ ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
16
+ macOS: (browser) => ['Mac OS', browser, '14.4.1'],
17
+ baileys: (browser) => ['Baileys', browser, '6.5.0'],
18
+ windows: (browser) => ['Windows', browser, '10.0.22631']
28
19
  };
29
-
30
- const getPlatformId = (browser) => {
31
- const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
32
- return platformType ? platformType.toString() : '1'; // Default Chrome
20
+ //=======================================================//
21
+ export const getPlatformId = (browser) => {
22
+ const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
23
+ return platformType ? platformType.toString() : "1";
33
24
  };
34
-
35
- exports.getPlatformId = getPlatformId;
25
+ //=======================================================//