@ubedsockets/baileys 1.6.4 → 1.6.5
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/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -18
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +4 -6
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +21 -78
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +217 -0
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +162 -43
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +124 -0
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +571 -249
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +273 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +161 -0
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +114 -99
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +260 -0
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +11 -9
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +203 -0
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +1277 -559
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +199 -0
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +674 -669
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +170 -0
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +149 -286
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +59 -0
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +24 -0
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +239 -136
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +66 -69
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +100 -0
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +380 -238
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/companion-reg-client-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +56 -127
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +66 -0
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +173 -63
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +36 -0
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +174 -70
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +91 -0
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +159 -207
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +24 -0
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +93 -53
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/identity-change-handler.d.ts +44 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/identity-change-handler.js.map +1 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +22 -33
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +17 -58
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +3 -46
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +24 -34
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +115 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +133 -0
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +483 -744
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +91 -0
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +411 -621
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +149 -99
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.d.ts.map +1 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/offline-node-processor.js.map +1 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.d.ts.map +1 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/pre-key-manager.js.map +1 -0
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +459 -150
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.d.ts.map +1 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/reporting-utils.js.map +1 -0
- package/lib/Utils/signal.d.ts +47 -0
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +112 -73
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.d.ts.map +1 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/stanza-ack.js.map +1 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.d.ts.map +1 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/sync-action-utils.js.map +1 -0
- package/lib/Utils/tc-token-utils.d.ts +37 -0
- package/lib/Utils/tc-token-utils.d.ts.map +1 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/tc-token-utils.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +23 -27
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +74 -104
- package/lib/Utils/validate-connection.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AuthenticationCreds, CacheStore, SignalKeyStore, SignalKeyStoreWithTransaction, TransactionCapabilityOptions } from '../Types/index.js';
|
|
2
|
+
import type { ILogger } from './logger.js';
|
|
3
|
+
/**
|
|
4
|
+
* Adds caching capability to a SignalKeyStore
|
|
5
|
+
* @param store the store to add caching to
|
|
6
|
+
* @param logger to log trace events
|
|
7
|
+
* @param _cache cache store to use
|
|
8
|
+
*/
|
|
9
|
+
export declare function makeCacheableSignalKeyStore(store: SignalKeyStore, logger?: ILogger, _cache?: CacheStore): SignalKeyStore;
|
|
10
|
+
/**
|
|
11
|
+
* Adds DB-like transaction capability to the SignalKeyStore
|
|
12
|
+
* Uses AsyncLocalStorage for automatic context management
|
|
13
|
+
* @param state the key store to apply this capability to
|
|
14
|
+
* @param logger logger to log events
|
|
15
|
+
* @returns SignalKeyStore with transaction capability
|
|
16
|
+
*/
|
|
17
|
+
export declare const addTransactionCapability: (state: SignalKeyStore, logger: ILogger, { maxCommitRetries, delayBetweenTriesMs }: TransactionCapabilityOptions) => SignalKeyStoreWithTransaction;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the authenticated user's JID, or throws a Boom-401 if creds are not yet authenticated.
|
|
20
|
+
* Use this anywhere we'd otherwise reach for `creds.me!.id` to fail fast with a descriptive error.
|
|
21
|
+
*/
|
|
22
|
+
export declare const assertMeId: (creds: AuthenticationCreds) => string;
|
|
23
|
+
export declare const initAuthCreds: () => AuthenticationCreds;
|
|
24
|
+
//# sourceMappingURL=auth-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-utils.d.ts","sourceRoot":"","sources":["../../src/Utils/auth-utils.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACX,mBAAmB,EACnB,UAAU,EAGV,cAAc,EACd,6BAA6B,EAC7B,4BAA4B,EAC5B,MAAM,UAAU,CAAA;AAGjB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAYvC;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAC1C,KAAK,EAAE,cAAc,EACrB,MAAM,CAAC,EAAE,OAAO,EAChB,MAAM,CAAC,EAAE,UAAU,GACjB,cAAc,CAkEhB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,GACpC,OAAO,cAAc,EACrB,QAAQ,OAAO,EACf,2CAA2C,4BAA4B,KACrE,6BAiOF,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,mBAAmB,KAAG,MAOvD,CAAA;AAED,eAAO,MAAM,aAAa,QAAO,mBAsBhC,CAAA"}
|
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -1,188 +1,290 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const crypto_2 = require("./crypto");
|
|
12
|
-
const generics_1 = require("./generics");
|
|
1
|
+
import NodeCache from '@cacheable/node-cache';
|
|
2
|
+
import { Boom } from '@hapi/boom';
|
|
3
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
4
|
+
import { Mutex } from 'async-mutex';
|
|
5
|
+
import { randomBytes } from 'crypto';
|
|
6
|
+
import PQueue from 'p-queue';
|
|
7
|
+
import { DEFAULT_CACHE_TTLS } from '../Defaults/index.js';
|
|
8
|
+
import { Curve, signedKeyPair } from './crypto.js';
|
|
9
|
+
import { delay, generateRegistrationId } from './generics.js';
|
|
10
|
+
import { PreKeyManager } from './pre-key-manager.js';
|
|
13
11
|
/**
|
|
14
12
|
* Adds caching capability to a SignalKeyStore
|
|
15
13
|
* @param store the store to add caching to
|
|
16
14
|
* @param logger to log trace events
|
|
17
15
|
* @param _cache cache store to use
|
|
18
16
|
*/
|
|
19
|
-
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
20
|
-
const cache = _cache ||
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
export function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
18
|
+
const cache = _cache ||
|
|
19
|
+
new NodeCache({
|
|
20
|
+
stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
|
|
21
|
+
useClones: false,
|
|
22
|
+
deleteOnExpire: true
|
|
23
|
+
});
|
|
24
|
+
// Mutex for protecting cache operations
|
|
25
|
+
const cacheMutex = new Mutex();
|
|
25
26
|
function getUniqueId(type, id) {
|
|
26
27
|
return `${type}.${id}`;
|
|
27
28
|
}
|
|
28
29
|
return {
|
|
29
30
|
async get(type, ids) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
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) {
|
|
31
|
+
return cacheMutex.runExclusive(async () => {
|
|
32
|
+
const data = {};
|
|
33
|
+
const idsToFetch = [];
|
|
34
|
+
for (const id of ids) {
|
|
35
|
+
const item = (await cache.get(getUniqueId(type, id)));
|
|
36
|
+
if (typeof item !== 'undefined') {
|
|
47
37
|
data[id] = item;
|
|
48
|
-
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
idsToFetch.push(id);
|
|
49
41
|
}
|
|
50
42
|
}
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
if (idsToFetch.length) {
|
|
44
|
+
logger?.trace({ items: idsToFetch.length }, 'loading from store');
|
|
45
|
+
const fetched = await store.get(type, idsToFetch);
|
|
46
|
+
for (const id of idsToFetch) {
|
|
47
|
+
const item = fetched[id];
|
|
48
|
+
if (item) {
|
|
49
|
+
data[id] = item;
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
51
|
+
await cache.set(getUniqueId(type, id), item);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return data;
|
|
56
|
+
});
|
|
53
57
|
},
|
|
54
58
|
async set(data) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
for (const
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
return cacheMutex.runExclusive(async () => {
|
|
60
|
+
let keys = 0;
|
|
61
|
+
for (const type in data) {
|
|
62
|
+
for (const id in data[type]) {
|
|
63
|
+
await cache.set(getUniqueId(type, id), data[type][id]);
|
|
64
|
+
keys += 1;
|
|
65
|
+
}
|
|
60
66
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
logger?.trace({ keys }, 'updated cache');
|
|
68
|
+
await store.set(data);
|
|
69
|
+
});
|
|
64
70
|
},
|
|
65
71
|
async clear() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
await ((_a = store.clear) === null || _a === void 0 ? void 0 : _a.call(store));
|
|
72
|
+
await cache.flushAll();
|
|
73
|
+
await store.clear?.();
|
|
69
74
|
}
|
|
70
75
|
};
|
|
71
76
|
}
|
|
72
77
|
/**
|
|
73
|
-
* Adds DB
|
|
74
|
-
*
|
|
78
|
+
* Adds DB-like transaction capability to the SignalKeyStore
|
|
79
|
+
* Uses AsyncLocalStorage for automatic context management
|
|
75
80
|
* @param state the key store to apply this capability to
|
|
76
81
|
* @param logger logger to log events
|
|
77
82
|
* @returns SignalKeyStore with transaction capability
|
|
78
83
|
*/
|
|
79
|
-
const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
|
|
80
|
-
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
84
|
+
export const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
|
|
85
|
+
const txStorage = new AsyncLocalStorage();
|
|
86
|
+
// Queues for concurrency control (keyed by signal data type - bounded set)
|
|
87
|
+
const keyQueues = new Map();
|
|
88
|
+
// Transaction mutexes with reference counting for cleanup
|
|
89
|
+
const txMutexes = new Map();
|
|
90
|
+
const txMutexRefCounts = new Map();
|
|
91
|
+
// Pre-key manager for specialized operations
|
|
92
|
+
const preKeyManager = new PreKeyManager(state, logger);
|
|
93
|
+
/**
|
|
94
|
+
* Get or create a queue for a specific key type
|
|
95
|
+
*/
|
|
96
|
+
function getQueue(key) {
|
|
97
|
+
if (!keyQueues.has(key)) {
|
|
98
|
+
keyQueues.set(key, new PQueue({ concurrency: 1 }));
|
|
99
|
+
}
|
|
100
|
+
return keyQueues.get(key);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get or create a transaction mutex
|
|
104
|
+
*/
|
|
105
|
+
function getTxMutex(key) {
|
|
106
|
+
if (!txMutexes.has(key)) {
|
|
107
|
+
txMutexes.set(key, new Mutex());
|
|
108
|
+
txMutexRefCounts.set(key, 0);
|
|
109
|
+
}
|
|
110
|
+
return txMutexes.get(key);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Acquire a reference to a transaction mutex
|
|
114
|
+
*/
|
|
115
|
+
function acquireTxMutexRef(key) {
|
|
116
|
+
const count = txMutexRefCounts.get(key) ?? 0;
|
|
117
|
+
txMutexRefCounts.set(key, count + 1);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Release a reference to a transaction mutex and cleanup if no longer needed
|
|
121
|
+
*/
|
|
122
|
+
function releaseTxMutexRef(key) {
|
|
123
|
+
const count = (txMutexRefCounts.get(key) ?? 1) - 1;
|
|
124
|
+
txMutexRefCounts.set(key, count);
|
|
125
|
+
// Cleanup if no more references and mutex is not locked
|
|
126
|
+
if (count <= 0) {
|
|
127
|
+
const mutex = txMutexes.get(key);
|
|
128
|
+
if (mutex && !mutex.isLocked()) {
|
|
129
|
+
txMutexes.delete(key);
|
|
130
|
+
txMutexRefCounts.delete(key);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Check if currently in a transaction
|
|
136
|
+
*/
|
|
137
|
+
function isInTransaction() {
|
|
138
|
+
return !!txStorage.getStore();
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Commit transaction with retries
|
|
142
|
+
*/
|
|
143
|
+
async function commitWithRetry(mutations) {
|
|
144
|
+
if (Object.keys(mutations).length === 0) {
|
|
145
|
+
logger.trace('no mutations in transaction');
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
logger.trace('committing transaction');
|
|
149
|
+
for (let attempt = 0; attempt < maxCommitRetries; attempt++) {
|
|
150
|
+
try {
|
|
151
|
+
await state.set(mutations);
|
|
152
|
+
logger.trace({ mutationCount: Object.keys(mutations).length }, 'committed transaction');
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
const retriesLeft = maxCommitRetries - attempt - 1;
|
|
157
|
+
logger.warn(`failed to commit mutations, retries left=${retriesLeft}`);
|
|
158
|
+
if (retriesLeft === 0) {
|
|
159
|
+
throw error;
|
|
99
160
|
}
|
|
100
|
-
|
|
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
|
-
}, {});
|
|
161
|
+
await delay(delayBetweenTriesMs);
|
|
108
162
|
}
|
|
109
|
-
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
get: async (type, ids) => {
|
|
167
|
+
const ctx = txStorage.getStore();
|
|
168
|
+
if (!ctx) {
|
|
169
|
+
// No transaction - direct read without exclusive lock for concurrency
|
|
110
170
|
return state.get(type, ids);
|
|
111
171
|
}
|
|
172
|
+
// In transaction - check cache first
|
|
173
|
+
const cached = ctx.cache[type] || {};
|
|
174
|
+
const missing = ids.filter(id => !(id in cached));
|
|
175
|
+
if (missing.length > 0) {
|
|
176
|
+
ctx.dbQueries++;
|
|
177
|
+
logger.trace({ type, count: missing.length }, 'fetching missing keys in transaction');
|
|
178
|
+
const fetched = await getTxMutex(type).runExclusive(() => state.get(type, missing));
|
|
179
|
+
// Update cache
|
|
180
|
+
ctx.cache[type] = ctx.cache[type] || {};
|
|
181
|
+
Object.assign(ctx.cache[type], fetched);
|
|
182
|
+
}
|
|
183
|
+
// Return requested ids from cache
|
|
184
|
+
const result = {};
|
|
185
|
+
for (const id of ids) {
|
|
186
|
+
const value = ctx.cache[type]?.[id];
|
|
187
|
+
if (value !== undefined && value !== null) {
|
|
188
|
+
result[id] = value;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return result;
|
|
112
192
|
},
|
|
113
|
-
set: data => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
193
|
+
set: async (data) => {
|
|
194
|
+
const ctx = txStorage.getStore();
|
|
195
|
+
if (!ctx) {
|
|
196
|
+
// No transaction - direct write with queue protection
|
|
197
|
+
const types = Object.keys(data);
|
|
198
|
+
// Process pre-keys with validation
|
|
199
|
+
for (const type_ of types) {
|
|
200
|
+
const type = type_;
|
|
201
|
+
if (type === 'pre-key') {
|
|
202
|
+
await preKeyManager.validateDeletions(data, type);
|
|
203
|
+
}
|
|
121
204
|
}
|
|
205
|
+
// Write all data in parallel
|
|
206
|
+
await Promise.all(types.map(type => getQueue(type).add(async () => {
|
|
207
|
+
const typeData = { [type]: data[type] };
|
|
208
|
+
await state.set(typeData);
|
|
209
|
+
})));
|
|
210
|
+
return;
|
|
122
211
|
}
|
|
123
|
-
|
|
124
|
-
|
|
212
|
+
// In transaction - update cache and mutations
|
|
213
|
+
logger.trace({ types: Object.keys(data) }, 'caching in transaction');
|
|
214
|
+
for (const key_ in data) {
|
|
215
|
+
const key = key_;
|
|
216
|
+
// Ensure structures exist
|
|
217
|
+
ctx.cache[key] = ctx.cache[key] || {};
|
|
218
|
+
ctx.mutations[key] = ctx.mutations[key] || {};
|
|
219
|
+
// Special handling for pre-keys
|
|
220
|
+
if (key === 'pre-key') {
|
|
221
|
+
await preKeyManager.processOperations(data, key, ctx.cache, ctx.mutations, true);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
// Normal key types
|
|
225
|
+
Object.assign(ctx.cache[key], data[key]);
|
|
226
|
+
Object.assign(ctx.mutations[key], data[key]);
|
|
227
|
+
}
|
|
125
228
|
}
|
|
126
229
|
},
|
|
127
230
|
isInTransaction,
|
|
128
|
-
async
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (
|
|
132
|
-
logger.trace('
|
|
231
|
+
transaction: async (work, key) => {
|
|
232
|
+
const existing = txStorage.getStore();
|
|
233
|
+
// Nested transaction - reuse existing context
|
|
234
|
+
if (existing) {
|
|
235
|
+
logger.trace('reusing existing transaction context');
|
|
236
|
+
return work();
|
|
133
237
|
}
|
|
238
|
+
// New transaction - acquire mutex and create context
|
|
239
|
+
const mutex = getTxMutex(key);
|
|
240
|
+
acquireTxMutexRef(key);
|
|
134
241
|
try {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
}
|
|
242
|
+
return await mutex.runExclusive(async () => {
|
|
243
|
+
const ctx = {
|
|
244
|
+
cache: {},
|
|
245
|
+
mutations: {},
|
|
246
|
+
dbQueries: 0
|
|
247
|
+
};
|
|
248
|
+
logger.trace('entering transaction');
|
|
249
|
+
try {
|
|
250
|
+
const result = await txStorage.run(ctx, work);
|
|
251
|
+
// Commit mutations
|
|
252
|
+
await commitWithRetry(ctx.mutations);
|
|
253
|
+
logger.trace({ dbQueries: ctx.dbQueries }, 'transaction completed');
|
|
254
|
+
return result;
|
|
155
255
|
}
|
|
156
|
-
|
|
157
|
-
logger.
|
|
256
|
+
catch (error) {
|
|
257
|
+
logger.error({ error }, 'transaction failed, rolling back');
|
|
258
|
+
throw error;
|
|
158
259
|
}
|
|
159
|
-
}
|
|
260
|
+
});
|
|
160
261
|
}
|
|
161
262
|
finally {
|
|
162
|
-
|
|
163
|
-
if (transactionsInProgress === 0) {
|
|
164
|
-
transactionCache = {};
|
|
165
|
-
mutations = {};
|
|
166
|
-
dbQueriesInTransaction = 0;
|
|
167
|
-
}
|
|
263
|
+
releaseTxMutexRef(key);
|
|
168
264
|
}
|
|
169
|
-
return result;
|
|
170
265
|
}
|
|
171
266
|
};
|
|
172
|
-
|
|
173
|
-
|
|
267
|
+
};
|
|
268
|
+
/**
|
|
269
|
+
* Returns the authenticated user's JID, or throws a Boom-401 if creds are not yet authenticated.
|
|
270
|
+
* Use this anywhere we'd otherwise reach for `creds.me!.id` to fail fast with a descriptive error.
|
|
271
|
+
*/
|
|
272
|
+
export const assertMeId = (creds) => {
|
|
273
|
+
const id = creds.me?.id;
|
|
274
|
+
if (!id) {
|
|
275
|
+
throw new Boom('Cannot proceed: socket is not authenticated yet (creds.me.id is missing)', { statusCode: 401 });
|
|
174
276
|
}
|
|
277
|
+
return id;
|
|
175
278
|
};
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
const identityKey = crypto_2.Curve.generateKeyPair();
|
|
279
|
+
export const initAuthCreds = () => {
|
|
280
|
+
const identityKey = Curve.generateKeyPair();
|
|
179
281
|
return {
|
|
180
|
-
noiseKey:
|
|
181
|
-
pairingEphemeralKeyPair:
|
|
282
|
+
noiseKey: Curve.generateKeyPair(),
|
|
283
|
+
pairingEphemeralKeyPair: Curve.generateKeyPair(),
|
|
182
284
|
signedIdentityKey: identityKey,
|
|
183
|
-
signedPreKey:
|
|
184
|
-
registrationId:
|
|
185
|
-
advSecretKey:
|
|
285
|
+
signedPreKey: signedKeyPair(identityKey, 1),
|
|
286
|
+
registrationId: generateRegistrationId(),
|
|
287
|
+
advSecretKey: randomBytes(32).toString('base64'),
|
|
186
288
|
processedHistoryMessages: [],
|
|
187
289
|
nextPreKeyId: 1,
|
|
188
290
|
firstUnuploadedPreKeyId: 1,
|
|
@@ -194,6 +296,7 @@ const initAuthCreds = () => {
|
|
|
194
296
|
pairingCode: undefined,
|
|
195
297
|
lastPropHash: undefined,
|
|
196
298
|
routingInfo: undefined,
|
|
299
|
+
additionalData: undefined
|
|
197
300
|
};
|
|
198
301
|
};
|
|
199
|
-
|
|
302
|
+
//# sourceMappingURL=auth-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-utils.js","sourceRoot":"","sources":["../../src/Utils/auth-utils.ts"],"names":[],"mappings":"AA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0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-utils.d.ts","sourceRoot":"","sources":["../../src/Utils/browser-utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAgB3C,eAAO,MAAM,QAAQ,EAAE,WAOtB,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,WAG5C,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { platform, release } from 'os';
|
|
2
|
+
import { proto } from '../../WAProto/index.js';
|
|
3
|
+
const PLATFORM_MAP = {
|
|
4
|
+
aix: 'AIX',
|
|
5
|
+
darwin: 'Mac OS',
|
|
6
|
+
win32: 'Windows',
|
|
7
|
+
android: 'Android',
|
|
8
|
+
freebsd: 'FreeBSD',
|
|
9
|
+
openbsd: 'OpenBSD',
|
|
10
|
+
sunos: 'Solaris',
|
|
11
|
+
linux: undefined,
|
|
12
|
+
haiku: undefined,
|
|
13
|
+
cygwin: undefined,
|
|
14
|
+
netbsd: undefined
|
|
15
|
+
};
|
|
16
|
+
export const Browsers = {
|
|
17
|
+
ubuntu: browser => ['Ubuntu', browser, '22.04.4'],
|
|
18
|
+
macOS: browser => ['Mac OS', browser, '14.4.1'],
|
|
19
|
+
baileys: browser => ['Baileys', browser, '6.5.0'],
|
|
20
|
+
windows: browser => ['Windows', browser, '10.0.22631'],
|
|
21
|
+
/** The appropriate browser based on your OS & release */
|
|
22
|
+
appropriate: browser => [PLATFORM_MAP[platform()] || 'Ubuntu', browser, release()]
|
|
23
|
+
};
|
|
24
|
+
export const getPlatformId = (browser) => {
|
|
25
|
+
const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
26
|
+
return platformType ? platformType.toString() : '1'; //chrome
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=browser-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-utils.js","sourceRoot":"","sources":["../../src/Utils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;AAC7D,CAAC,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CatalogCollection, OrderDetails, Product, ProductCreate, ProductUpdate, WAMediaUpload, WAMediaUploadFunction } from '../Types/index.js';
|
|
2
|
+
import { type BinaryNode } from '../WABinary/index.js';
|
|
3
|
+
export declare const parseCatalogNode: (node: BinaryNode) => {
|
|
4
|
+
products: Product[];
|
|
5
|
+
nextPageCursor: string | undefined;
|
|
6
|
+
};
|
|
7
|
+
export declare const parseCollectionsNode: (node: BinaryNode) => {
|
|
8
|
+
collections: CatalogCollection[];
|
|
9
|
+
};
|
|
10
|
+
export declare const parseOrderDetailsNode: (node: BinaryNode) => OrderDetails;
|
|
11
|
+
export declare const toProductNode: (productId: string | undefined, product: ProductCreate | ProductUpdate) => BinaryNode;
|
|
12
|
+
export declare const parseProductNode: (productNode: BinaryNode) => Product;
|
|
13
|
+
/**
|
|
14
|
+
* Uploads images not already uploaded to WA's servers
|
|
15
|
+
*/
|
|
16
|
+
export declare function uploadingNecessaryImagesOfProduct<T extends ProductUpdate | ProductCreate>(product: T, waUploadToServer: WAMediaUploadFunction, timeoutMs?: number): Promise<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Uploads images not already uploaded to WA's servers
|
|
19
|
+
*/
|
|
20
|
+
export declare const uploadingNecessaryImages: (images: WAMediaUpload[], waUploadToServer: WAMediaUploadFunction, timeoutMs?: number) => Promise<{
|
|
21
|
+
url: string;
|
|
22
|
+
}[]>;
|
|
23
|
+
//# sourceMappingURL=business.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"business.d.ts","sourceRoot":"","sources":["../../src/Utils/business.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACX,iBAAiB,EAEjB,YAAY,EAEZ,OAAO,EACP,aAAa,EACb,aAAa,EACb,aAAa,EACb,qBAAqB,EACrB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,KAAK,UAAU,EAAuE,MAAM,aAAa,CAAA;AAIlH,eAAO,MAAM,gBAAgB,GAAI,MAAM,UAAU;;;CAShD,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,MAAM,UAAU;;CAkBpD,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAI,MAAM,UAAU,iBAyBrD,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,WAAW,MAAM,GAAG,SAAS,EAAE,SAAS,aAAa,GAAG,aAAa,eAwGlG,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,aAAa,UAAU,YAwBvD,CAAA;AAED;;GAEG;AACH,wBAAsB,iCAAiC,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,EAC9F,OAAO,EAAE,CAAC,EACV,gBAAgB,EAAE,qBAAqB,EACvC,SAAS,SAAS,cASlB;AAED;;GAEG;AACH,eAAO,MAAM,wBAAwB,GACpC,QAAQ,aAAa,EAAE,EACvB,kBAAkB,qBAAqB,EACvC,kBAAkB;SAGS,MAAM;IAiCjC,CAAA"}
|