@vinzsocket/baileys 2.8.30 → 3.0.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.
- package/WAProto/fix-imports.js +7 -16
- package/WAProto/index.js +1 -37306
- package/lib/Defaults/index.js +37 -33
- package/lib/Signal/Group/ciphertext-message.js +6 -2
- package/lib/Signal/Group/group-session-builder.js +12 -7
- package/lib/Signal/Group/group_cipher.js +18 -13
- package/lib/Signal/Group/index.js +77 -12
- package/lib/Signal/Group/keyhelper.js +15 -8
- package/lib/Signal/Group/queue-job.js +7 -2
- package/lib/Signal/Group/sender-chain-key.js +11 -6
- package/lib/Signal/Group/sender-key-distribution-message.js +10 -6
- package/lib/Signal/Group/sender-key-message.js +14 -9
- package/lib/Signal/Group/sender-key-name.js +6 -2
- package/lib/Signal/Group/sender-key-record.js +13 -9
- package/lib/Signal/Group/sender-key-state.js +10 -6
- package/lib/Signal/Group/sender-message-key.js +9 -4
- package/lib/Signal/libsignal.js +34 -28
- package/lib/Signal/lid-mapping.js +24 -19
- package/lib/Socket/Client/index.js +25 -3
- package/lib/Socket/Client/types.js +8 -4
- package/lib/Socket/Client/websocket.js +16 -11
- package/lib/Socket/business.js +38 -34
- package/lib/Socket/chats.js +100 -95
- package/lib/Socket/communities.js +55 -49
- package/lib/Socket/groups.js +56 -51
- package/lib/Socket/index.js +9 -6
- package/lib/Socket/messages-recv.js +150 -145
- package/lib/Socket/messages-send.js +109 -104
- package/lib/Socket/mex.js +12 -8
- package/lib/Socket/newsletter.js +27 -23
- package/lib/Socket/socket.js +111 -107
- package/lib/Store/index.js +47 -4
- package/lib/Store/make-cache-manager-store.js +17 -11
- package/lib/Store/make-in-memory-store.js +31 -29
- package/lib/Store/make-ordered-dictionary.js +7 -2
- package/lib/Store/object-repository.js +7 -2
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -2
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.js +5 -2
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.js +1 -2
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.js +6 -3
- package/lib/Types/LabelAssociation.js +6 -3
- package/lib/Types/Message.js +16 -7
- package/lib/Types/Newsletter.js +8 -5
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.js +1 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +7 -4
- package/lib/Types/USync.js +1 -2
- package/lib/Types/index.js +153 -15
- package/lib/Utils/auth-utils.js +32 -25
- package/lib/Utils/baileys-event-stream.js +21 -15
- package/lib/Utils/business.js +71 -61
- package/lib/Utils/chat-utils.js +91 -77
- package/lib/Utils/crypto.js +54 -32
- package/lib/Utils/decode-wa-message.js +46 -39
- package/lib/Utils/event-buffer.js +24 -19
- package/lib/Utils/extended-messages.js +14 -9
- package/lib/Utils/generics.js +100 -64
- package/lib/Utils/history.js +30 -23
- package/lib/Utils/index.js +234 -22
- package/lib/Utils/lid-resolver.js +12 -5
- package/lib/Utils/link-preview.js +11 -7
- package/lib/Utils/logger.js +8 -4
- package/lib/Utils/lt-hash.js +8 -5
- package/lib/Utils/make-mutex.js +8 -3
- package/lib/Utils/mention.js +12 -4
- package/lib/Utils/message-retry-manager.js +10 -6
- package/lib/Utils/messages-media.js +127 -95
- package/lib/Utils/messages.js +122 -98
- package/lib/Utils/noise-handler.js +25 -21
- package/lib/Utils/process-message.js +72 -63
- package/lib/Utils/signal.js +45 -33
- package/lib/Utils/use-multi-file-auth-state.js +24 -20
- package/lib/Utils/validate-connection.js +54 -47
- package/lib/WABinary/constants.js +9 -6
- package/lib/WABinary/decode.js +17 -10
- package/lib/WABinary/encode.js +11 -6
- package/lib/WABinary/generic-utils.js +31 -17
- package/lib/WABinary/index.js +58 -6
- package/lib/WABinary/jid-utils.js +36 -20
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +6 -2
- package/lib/WAM/constants.js +1 -1
- package/lib/WAM/encode.js +16 -12
- package/lib/WAM/index.js +36 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +9 -5
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -6
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +8 -4
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +8 -4
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +9 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +23 -19
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -2
- package/lib/WAUSync/Protocols/index.js +58 -6
- package/lib/WAUSync/USyncQuery.js +21 -17
- package/lib/WAUSync/USyncUser.js +6 -2
- package/lib/WAUSync/index.js +36 -4
- package/lib/index.js +112 -12
- package/package.json +8 -6
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2
|
+
value: true
|
|
3
|
+
});
|
|
4
|
+
exports.makeMessagesSocket = void 0;
|
|
5
|
+
var _nodeCache = _interopRequireDefault(require("@cacheable/node-cache"));
|
|
6
|
+
var _boom = require("@hapi/boom");
|
|
7
|
+
var _index = require("../../WAProto/index.js");
|
|
8
|
+
var _index2 = require("../Defaults/index.js");
|
|
9
|
+
var _index3 = require("../Types/index.js");
|
|
10
|
+
var _index4 = require("../Utils/index.js");
|
|
11
|
+
var _extendedMessages = require("../Utils/extended-messages.js");
|
|
12
|
+
var _linkPreview = require("../Utils/link-preview.js");
|
|
13
|
+
var _makeMutex = require("../Utils/make-mutex.js");
|
|
14
|
+
var _index5 = require("../WABinary/index.js");
|
|
15
|
+
var _index6 = require("../WAUSync/index.js");
|
|
16
|
+
var _newsletter = require("./newsletter.js");
|
|
17
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
+
const makeMessagesSocket = config => {
|
|
14
19
|
const {
|
|
15
20
|
logger,
|
|
16
21
|
linkPreviewImageThumbnailWidth,
|
|
@@ -21,7 +26,7 @@ export const makeMessagesSocket = config => {
|
|
|
21
26
|
enableRecentMessageCache,
|
|
22
27
|
maxMsgRetryCount
|
|
23
28
|
} = config;
|
|
24
|
-
const sock = makeNewsletterSocket(config);
|
|
29
|
+
const sock = (0, _newsletter.makeNewsletterSocket)(config);
|
|
25
30
|
const {
|
|
26
31
|
ev,
|
|
27
32
|
authState,
|
|
@@ -34,15 +39,15 @@ export const makeMessagesSocket = config => {
|
|
|
34
39
|
groupMetadata,
|
|
35
40
|
groupToggleEphemeral
|
|
36
41
|
} = sock;
|
|
37
|
-
const userDevicesCache = config.userDevicesCache || new
|
|
38
|
-
stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
42
|
+
const userDevicesCache = config.userDevicesCache || new _nodeCache.default({
|
|
43
|
+
stdTTL: _index2.DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
39
44
|
// 5 minutes
|
|
40
45
|
useClones: false
|
|
41
46
|
});
|
|
42
47
|
// Initialize message retry manager if enabled
|
|
43
|
-
const messageRetryManager = enableRecentMessageCache ? new MessageRetryManager(logger, maxMsgRetryCount) : null;
|
|
48
|
+
const messageRetryManager = enableRecentMessageCache ? new _index4.MessageRetryManager(logger, maxMsgRetryCount) : null;
|
|
44
49
|
// Prevent race conditions in Signal session encryption by user
|
|
45
|
-
const encryptionMutex = makeKeyedMutex();
|
|
50
|
+
const encryptionMutex = (0, _makeMutex.makeKeyedMutex)();
|
|
46
51
|
let mediaConn;
|
|
47
52
|
const refreshMediaConn = async (forceGet = false) => {
|
|
48
53
|
const media = await mediaConn;
|
|
@@ -53,16 +58,16 @@ export const makeMessagesSocket = config => {
|
|
|
53
58
|
attrs: {
|
|
54
59
|
type: 'set',
|
|
55
60
|
xmlns: 'w:m',
|
|
56
|
-
to: S_WHATSAPP_NET
|
|
61
|
+
to: _index5.S_WHATSAPP_NET
|
|
57
62
|
},
|
|
58
63
|
content: [{
|
|
59
64
|
tag: 'media_conn',
|
|
60
65
|
attrs: {}
|
|
61
66
|
}]
|
|
62
67
|
});
|
|
63
|
-
const mediaConnNode = getBinaryNodeChild(result, 'media_conn');
|
|
68
|
+
const mediaConnNode = (0, _index5.getBinaryNodeChild)(result, 'media_conn');
|
|
64
69
|
const node = {
|
|
65
|
-
hosts: getBinaryNodeChildren(mediaConnNode, 'host').map(({
|
|
70
|
+
hosts: (0, _index5.getBinaryNodeChildren)(mediaConnNode, 'host').map(({
|
|
66
71
|
attrs
|
|
67
72
|
}) => ({
|
|
68
73
|
hostname: attrs.hostname,
|
|
@@ -84,7 +89,7 @@ export const makeMessagesSocket = config => {
|
|
|
84
89
|
* */
|
|
85
90
|
const sendReceipt = async (jid, participant, messageIds, type) => {
|
|
86
91
|
if (!messageIds || messageIds.length === 0) {
|
|
87
|
-
throw new Boom('missing ids in receipt');
|
|
92
|
+
throw new _boom.Boom('missing ids in receipt');
|
|
88
93
|
}
|
|
89
94
|
const node = {
|
|
90
95
|
tag: 'receipt',
|
|
@@ -94,9 +99,9 @@ export const makeMessagesSocket = config => {
|
|
|
94
99
|
};
|
|
95
100
|
const isReadReceipt = type === 'read' || type === 'read-self';
|
|
96
101
|
if (isReadReceipt) {
|
|
97
|
-
node.attrs.t = unixTimestampSeconds().toString();
|
|
102
|
+
node.attrs.t = (0, _index4.unixTimestampSeconds)().toString();
|
|
98
103
|
}
|
|
99
|
-
if (type === 'sender' && isPnUser(jid)) {
|
|
104
|
+
if (type === 'sender' && (0, _index5.isPnUser)(jid)) {
|
|
100
105
|
node.attrs.recipient = jid;
|
|
101
106
|
node.attrs.to = participant;
|
|
102
107
|
} else {
|
|
@@ -129,7 +134,7 @@ export const makeMessagesSocket = config => {
|
|
|
129
134
|
};
|
|
130
135
|
/** Correctly bulk send receipts to multiple chats, participants */
|
|
131
136
|
const sendReceipts = async (keys, type) => {
|
|
132
|
-
const recps = aggregateMessageKeysNotFromMe(keys);
|
|
137
|
+
const recps = (0, _index4.aggregateMessageKeysNotFromMe)(keys);
|
|
133
138
|
for (const {
|
|
134
139
|
jid,
|
|
135
140
|
participant,
|
|
@@ -155,14 +160,14 @@ export const makeMessagesSocket = config => {
|
|
|
155
160
|
// Collect all LID users
|
|
156
161
|
for (const jid of jids) {
|
|
157
162
|
if (jid.includes('@lid')) {
|
|
158
|
-
const user = jidDecode(jid)?.user;
|
|
163
|
+
const user = (0, _index5.jidDecode)(jid)?.user;
|
|
159
164
|
if (user) lidUsers.add(user);
|
|
160
165
|
}
|
|
161
166
|
}
|
|
162
167
|
// Filter out PN versions when LID exists
|
|
163
168
|
for (const jid of jids) {
|
|
164
169
|
if (jid.includes('@s.whatsapp.net')) {
|
|
165
|
-
const user = jidDecode(jid)?.user;
|
|
170
|
+
const user = (0, _index5.jidDecode)(jid)?.user;
|
|
166
171
|
if (user && lidUsers.has(user)) {
|
|
167
172
|
logger.debug({
|
|
168
173
|
jid
|
|
@@ -184,7 +189,7 @@ export const makeMessagesSocket = config => {
|
|
|
184
189
|
// Deduplicate and normalize JIDs
|
|
185
190
|
jids = deduplicateLidPnJids(Array.from(new Set(jids)));
|
|
186
191
|
for (let jid of jids) {
|
|
187
|
-
const decoded = jidDecode(jid);
|
|
192
|
+
const decoded = (0, _index5.jidDecode)(jid);
|
|
188
193
|
const user = decoded?.user;
|
|
189
194
|
const device = decoded?.device;
|
|
190
195
|
const isExplicitDevice = typeof device === 'number' && device >= 0;
|
|
@@ -198,14 +203,14 @@ export const makeMessagesSocket = config => {
|
|
|
198
203
|
continue;
|
|
199
204
|
}
|
|
200
205
|
// For user JIDs, normalize and prepare for device enumeration
|
|
201
|
-
jid = jidNormalizedUser(jid);
|
|
206
|
+
jid = (0, _index5.jidNormalizedUser)(jid);
|
|
202
207
|
if (useCache) {
|
|
203
208
|
const devices = userDevicesCache.get(user);
|
|
204
209
|
if (devices) {
|
|
205
210
|
const isLidJid = jid.includes('@lid');
|
|
206
211
|
const devicesWithWire = devices.map(d => ({
|
|
207
212
|
...d,
|
|
208
|
-
wireJid: isLidJid ? jidEncode(d.user, 'lid', d.device) : jidEncode(d.user, 's.whatsapp.net', d.device)
|
|
213
|
+
wireJid: isLidJid ? (0, _index5.jidEncode)(d.user, 'lid', d.device) : (0, _index5.jidEncode)(d.user, 's.whatsapp.net', d.device)
|
|
209
214
|
}));
|
|
210
215
|
deviceResults.push(...devicesWithWire);
|
|
211
216
|
logger.trace({
|
|
@@ -224,17 +229,17 @@ export const makeMessagesSocket = config => {
|
|
|
224
229
|
const requestedLidUsers = new Set();
|
|
225
230
|
for (const jid of toFetch) {
|
|
226
231
|
if (jid.includes('@lid')) {
|
|
227
|
-
const user = jidDecode(jid)?.user;
|
|
232
|
+
const user = (0, _index5.jidDecode)(jid)?.user;
|
|
228
233
|
if (user) requestedLidUsers.add(user);
|
|
229
234
|
}
|
|
230
235
|
}
|
|
231
|
-
const query = new USyncQuery().withContext('message').withDeviceProtocol();
|
|
236
|
+
const query = new _index6.USyncQuery().withContext('message').withDeviceProtocol();
|
|
232
237
|
for (const jid of toFetch) {
|
|
233
|
-
query.withUser(new USyncUser().withId(jid));
|
|
238
|
+
query.withUser(new _index6.USyncUser().withId(jid));
|
|
234
239
|
}
|
|
235
240
|
const result = await sock.executeUSyncQuery(query);
|
|
236
241
|
if (result) {
|
|
237
|
-
const extracted = extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices);
|
|
242
|
+
const extracted = (0, _index4.extractDeviceJids)(result?.list, authState.creds.me.id, ignoreZeroDevices);
|
|
238
243
|
const deviceMap = {};
|
|
239
244
|
for (const item of extracted) {
|
|
240
245
|
deviceMap[item.user] = deviceMap[item.user] || [];
|
|
@@ -245,7 +250,7 @@ export const makeMessagesSocket = config => {
|
|
|
245
250
|
const isLidUser = requestedLidUsers.has(user);
|
|
246
251
|
// Process all devices for this user
|
|
247
252
|
for (const item of userDevices) {
|
|
248
|
-
const finalWireJid = isLidUser ? jidEncode(user, 'lid', item.device) : jidEncode(item.user, 's.whatsapp.net', item.device);
|
|
253
|
+
const finalWireJid = isLidUser ? (0, _index5.jidEncode)(user, 'lid', item.device) : (0, _index5.jidEncode)(item.user, 's.whatsapp.net', item.device);
|
|
249
254
|
deviceResults.push({
|
|
250
255
|
...item,
|
|
251
256
|
wireJid: finalWireJid
|
|
@@ -317,7 +322,7 @@ export const makeMessagesSocket = config => {
|
|
|
317
322
|
// Group JIDs by user for bulk migration
|
|
318
323
|
const userGroups = new Map();
|
|
319
324
|
for (const jid of jids) {
|
|
320
|
-
const user = jidNormalizedUser(jid);
|
|
325
|
+
const user = (0, _index5.jidNormalizedUser)(jid);
|
|
321
326
|
if (!userGroups.has(user)) {
|
|
322
327
|
userGroups.set(user, []);
|
|
323
328
|
}
|
|
@@ -359,7 +364,7 @@ export const makeMessagesSocket = config => {
|
|
|
359
364
|
const migrateDeviceToLid = async (jid, lidForPN) => {
|
|
360
365
|
if (!jid.includes('@s.whatsapp.net')) return;
|
|
361
366
|
try {
|
|
362
|
-
const lidWithDevice = transferDevice(jid, lidForPN);
|
|
367
|
+
const lidWithDevice = (0, _index5.transferDevice)(jid, lidForPN);
|
|
363
368
|
await signalRepository.migrateSession(jid, lidWithDevice);
|
|
364
369
|
logger.debug({
|
|
365
370
|
fromJid: jid,
|
|
@@ -408,10 +413,10 @@ export const makeMessagesSocket = config => {
|
|
|
408
413
|
let jidToFetch = jid;
|
|
409
414
|
// Check if we should use migrated LID session instead
|
|
410
415
|
if (shouldMigrateUser && lidForPN && jid.includes('@s.whatsapp.net')) {
|
|
411
|
-
const originalDecoded = jidDecode(jid);
|
|
416
|
+
const originalDecoded = (0, _index5.jidDecode)(jid);
|
|
412
417
|
const deviceId = originalDecoded?.device || 0;
|
|
413
|
-
const lidDecoded = jidDecode(lidForPN);
|
|
414
|
-
const lidWithDevice = jidEncode(lidDecoded?.user, 'lid', deviceId);
|
|
418
|
+
const lidDecoded = (0, _index5.jidDecode)(lidForPN);
|
|
419
|
+
const lidWithDevice = (0, _index5.jidEncode)(lidDecoded?.user, 'lid', deviceId);
|
|
415
420
|
// Check if LID session exists
|
|
416
421
|
const lidSignalId = signalRepository.jidToSignalProtocolAddress(lidWithDevice);
|
|
417
422
|
const lidSessions = await authState.keys.get('session', [lidSignalId]);
|
|
@@ -447,7 +452,7 @@ export const makeMessagesSocket = config => {
|
|
|
447
452
|
const lidUsersBeingFetched = new Set();
|
|
448
453
|
const pnUsersBeingFetched = new Set();
|
|
449
454
|
for (const jid of jidsRequiringFetch) {
|
|
450
|
-
const user = jidDecode(jid)?.user;
|
|
455
|
+
const user = (0, _index5.jidDecode)(jid)?.user;
|
|
451
456
|
if (user) {
|
|
452
457
|
if (jid.includes('@lid')) {
|
|
453
458
|
lidUsersBeingFetched.add(user);
|
|
@@ -470,7 +475,7 @@ export const makeMessagesSocket = config => {
|
|
|
470
475
|
attrs: {
|
|
471
476
|
xmlns: 'encrypt',
|
|
472
477
|
type: 'get',
|
|
473
|
-
to: S_WHATSAPP_NET
|
|
478
|
+
to: _index5.S_WHATSAPP_NET
|
|
474
479
|
},
|
|
475
480
|
content: [{
|
|
476
481
|
tag: 'key',
|
|
@@ -483,7 +488,7 @@ export const makeMessagesSocket = config => {
|
|
|
483
488
|
}))
|
|
484
489
|
}]
|
|
485
490
|
});
|
|
486
|
-
await parseAndInjectE2ESessions(result, signalRepository);
|
|
491
|
+
await (0, _index4.parseAndInjectE2ESessions)(result, signalRepository);
|
|
487
492
|
didFetchNewSession = true;
|
|
488
493
|
}
|
|
489
494
|
return didFetchNewSession;
|
|
@@ -491,15 +496,15 @@ export const makeMessagesSocket = config => {
|
|
|
491
496
|
const sendPeerDataOperationMessage = async pdoMessage => {
|
|
492
497
|
//TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
|
|
493
498
|
if (!authState.creds.me?.id) {
|
|
494
|
-
throw new Boom('Not authenticated');
|
|
499
|
+
throw new _boom.Boom('Not authenticated');
|
|
495
500
|
}
|
|
496
501
|
const protocolMessage = {
|
|
497
502
|
protocolMessage: {
|
|
498
503
|
peerDataOperationRequestMessage: pdoMessage,
|
|
499
|
-
type: proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
504
|
+
type: _index.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
500
505
|
}
|
|
501
506
|
};
|
|
502
|
-
const meJid = jidNormalizedUser(authState.creds.me.id);
|
|
507
|
+
const meJid = (0, _index5.jidNormalizedUser)(authState.creds.me.id);
|
|
503
508
|
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
504
509
|
additionalAttributes: {
|
|
505
510
|
category: 'peer',
|
|
@@ -519,7 +524,7 @@ export const makeMessagesSocket = config => {
|
|
|
519
524
|
let shouldIncludeDeviceIdentity = false;
|
|
520
525
|
const meId = authState.creds.me.id;
|
|
521
526
|
const meLid = authState.creds.me?.lid;
|
|
522
|
-
const meLidUser = meLid ? jidDecode(meLid)?.user : null;
|
|
527
|
+
const meLidUser = meLid ? (0, _index5.jidDecode)(meLid)?.user : null;
|
|
523
528
|
const devicesByUser = new Map();
|
|
524
529
|
for (const patchedMessageWithJid of patched) {
|
|
525
530
|
const {
|
|
@@ -528,7 +533,7 @@ export const makeMessagesSocket = config => {
|
|
|
528
533
|
} = patchedMessageWithJid;
|
|
529
534
|
if (!wireJid) continue;
|
|
530
535
|
// Extract user from JID for grouping
|
|
531
|
-
const decoded = jidDecode(wireJid);
|
|
536
|
+
const decoded = (0, _index5.jidDecode)(wireJid);
|
|
532
537
|
const user = decoded?.user;
|
|
533
538
|
if (!user) continue;
|
|
534
539
|
if (!devicesByUser.has(user)) {
|
|
@@ -554,15 +559,15 @@ export const makeMessagesSocket = config => {
|
|
|
554
559
|
const lidForPN = await lidMapping.getLIDForPN(wireJid);
|
|
555
560
|
if (!lidForPN?.includes('@lid')) return wireJid;
|
|
556
561
|
// Preserve device ID from original wire JID
|
|
557
|
-
const wireDecoded = jidDecode(wireJid);
|
|
562
|
+
const wireDecoded = (0, _index5.jidDecode)(wireJid);
|
|
558
563
|
const deviceId = wireDecoded?.device || 0;
|
|
559
|
-
const lidDecoded = jidDecode(lidForPN);
|
|
560
|
-
const lidWithDevice = jidEncode(lidDecoded?.user, 'lid', deviceId);
|
|
564
|
+
const lidDecoded = (0, _index5.jidDecode)(lidForPN);
|
|
565
|
+
const lidWithDevice = (0, _index5.jidEncode)(lidDecoded?.user, 'lid', deviceId);
|
|
561
566
|
// Migrate session to LID for unified encryption layer
|
|
562
567
|
try {
|
|
563
568
|
await signalRepository.migrateSession(wireJid, lidWithDevice);
|
|
564
|
-
const recipientUser = jidNormalizedUser(wireJid);
|
|
565
|
-
const ownPnUser = jidNormalizedUser(meId);
|
|
569
|
+
const recipientUser = (0, _index5.jidNormalizedUser)(wireJid);
|
|
570
|
+
const ownPnUser = (0, _index5.jidNormalizedUser)(meId);
|
|
566
571
|
const isOwnDevice = recipientUser === ownPnUser;
|
|
567
572
|
logger.info({
|
|
568
573
|
wireJid,
|
|
@@ -607,10 +612,10 @@ export const makeMessagesSocket = config => {
|
|
|
607
612
|
if (dsmMessage) {
|
|
608
613
|
const {
|
|
609
614
|
user: targetUser
|
|
610
|
-
} = jidDecode(wireJid);
|
|
615
|
+
} = (0, _index5.jidDecode)(wireJid);
|
|
611
616
|
const {
|
|
612
617
|
user: ownPnUser
|
|
613
|
-
} = jidDecode(meId);
|
|
618
|
+
} = (0, _index5.jidDecode)(meId);
|
|
614
619
|
const ownLidUser = meLidUser;
|
|
615
620
|
// Check if this is our device (same user, different device)
|
|
616
621
|
const isOwnUser = targetUser === ownPnUser || ownLidUser && targetUser === ownLidUser;
|
|
@@ -624,7 +629,7 @@ export const makeMessagesSocket = config => {
|
|
|
624
629
|
}, 'Using DSM for own device');
|
|
625
630
|
}
|
|
626
631
|
}
|
|
627
|
-
const bytes = encodeWAMessage(messageToEncrypt);
|
|
632
|
+
const bytes = (0, _index4.encodeWAMessage)(messageToEncrypt);
|
|
628
633
|
// Get encryption JID with LID migration
|
|
629
634
|
const encryptionJid = await getEncryptionJid(wireJid);
|
|
630
635
|
// ENCRYPT: Use the determined encryption identity (prefers migrated LID)
|
|
@@ -687,7 +692,7 @@ export const makeMessagesSocket = config => {
|
|
|
687
692
|
const {
|
|
688
693
|
user,
|
|
689
694
|
server
|
|
690
|
-
} = jidDecode(jid);
|
|
695
|
+
} = (0, _index5.jidDecode)(jid);
|
|
691
696
|
const statusJid = 'status@broadcast';
|
|
692
697
|
const isGroup = server === 'g.us';
|
|
693
698
|
const isStatus = jid === statusJid;
|
|
@@ -709,7 +714,7 @@ export const makeMessagesSocket = config => {
|
|
|
709
714
|
ownId
|
|
710
715
|
}, 'Using PN identity for @s.whatsapp.net conversation');
|
|
711
716
|
}
|
|
712
|
-
msgId = msgId || generateMessageIDV2(sock.user?.id);
|
|
717
|
+
msgId = msgId || (0, _index4.generateMessageIDV2)(sock.user?.id);
|
|
713
718
|
useUserDevicesCache = useUserDevicesCache !== false;
|
|
714
719
|
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
|
|
715
720
|
const participants = [];
|
|
@@ -737,7 +742,7 @@ export const makeMessagesSocket = config => {
|
|
|
737
742
|
const {
|
|
738
743
|
user,
|
|
739
744
|
device
|
|
740
|
-
} = jidDecode(participant.jid);
|
|
745
|
+
} = (0, _index5.jidDecode)(participant.jid);
|
|
741
746
|
devices.push({
|
|
742
747
|
user,
|
|
743
748
|
device,
|
|
@@ -752,7 +757,7 @@ export const makeMessagesSocket = config => {
|
|
|
752
757
|
if (isNewsletter) {
|
|
753
758
|
// Patch message if needed, then encode as plaintext
|
|
754
759
|
const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
|
|
755
|
-
const bytes = encodeNewsletterMessage(patched);
|
|
760
|
+
const bytes = (0, _index4.encodeNewsletterMessage)(patched);
|
|
756
761
|
binaryNodeContent.push({
|
|
757
762
|
tag: 'plaintext',
|
|
758
763
|
attrs: {},
|
|
@@ -774,7 +779,7 @@ export const makeMessagesSocket = config => {
|
|
|
774
779
|
await sendNode(stanza);
|
|
775
780
|
return;
|
|
776
781
|
}
|
|
777
|
-
if (normalizeMessageContent(message)?.pinInChatMessage) {
|
|
782
|
+
if ((0, _index4.normalizeMessageContent)(message)?.pinInChatMessage) {
|
|
778
783
|
extraAttrs['decrypt-fail'] = 'hide';
|
|
779
784
|
}
|
|
780
785
|
if (isGroup || isStatus) {
|
|
@@ -802,7 +807,7 @@ export const makeMessagesSocket = config => {
|
|
|
802
807
|
participantsList.push(...statusJidList);
|
|
803
808
|
}
|
|
804
809
|
if (!isStatus) {
|
|
805
|
-
const groupAddressingMode = groupData?.addressingMode || (isLid ? WAMessageAddressingMode.LID : WAMessageAddressingMode.PN);
|
|
810
|
+
const groupAddressingMode = groupData?.addressingMode || (isLid ? _index3.WAMessageAddressingMode.LID : _index3.WAMessageAddressingMode.PN);
|
|
806
811
|
additionalAttributes = {
|
|
807
812
|
...additionalAttributes,
|
|
808
813
|
addressing_mode: groupAddressingMode
|
|
@@ -813,9 +818,9 @@ export const makeMessagesSocket = config => {
|
|
|
813
818
|
}
|
|
814
819
|
const patched = await patchMessageBeforeSending(message);
|
|
815
820
|
if (Array.isArray(patched)) {
|
|
816
|
-
throw new Boom('Per-jid patching is not supported in groups');
|
|
821
|
+
throw new _boom.Boom('Per-jid patching is not supported in groups');
|
|
817
822
|
}
|
|
818
|
-
const bytes = encodeWAMessage(patched);
|
|
823
|
+
const bytes = (0, _index4.encodeWAMessage)(patched);
|
|
819
824
|
// This should match the group's addressing mode and conversation context
|
|
820
825
|
const groupAddressingMode = groupData?.addressingMode || (isLid ? 'lid' : 'pn');
|
|
821
826
|
const groupSenderIdentity = groupAddressingMode === 'lid' && meLid ? meLid : meId;
|
|
@@ -872,35 +877,35 @@ export const makeMessagesSocket = config => {
|
|
|
872
877
|
} else {
|
|
873
878
|
const {
|
|
874
879
|
user: ownUser
|
|
875
|
-
} = jidDecode(ownId);
|
|
880
|
+
} = (0, _index5.jidDecode)(ownId);
|
|
876
881
|
if (!participant) {
|
|
877
882
|
const targetUserServer = isLid ? 'lid' : 's.whatsapp.net';
|
|
878
883
|
devices.push({
|
|
879
884
|
user,
|
|
880
885
|
device: 0,
|
|
881
|
-
wireJid: jidEncode(user, targetUserServer, 0)
|
|
886
|
+
wireJid: (0, _index5.jidEncode)(user, targetUserServer, 0)
|
|
882
887
|
});
|
|
883
888
|
// Own user matches conversation addressing mode
|
|
884
889
|
if (user !== ownUser) {
|
|
885
890
|
const ownUserServer = isLid ? 'lid' : 's.whatsapp.net';
|
|
886
|
-
const ownUserForAddressing = isLid && meLid ? jidDecode(meLid).user : jidDecode(meId).user;
|
|
891
|
+
const ownUserForAddressing = isLid && meLid ? (0, _index5.jidDecode)(meLid).user : (0, _index5.jidDecode)(meId).user;
|
|
887
892
|
devices.push({
|
|
888
893
|
user: ownUserForAddressing,
|
|
889
894
|
device: 0,
|
|
890
|
-
wireJid: jidEncode(ownUserForAddressing, ownUserServer, 0)
|
|
895
|
+
wireJid: (0, _index5.jidEncode)(ownUserForAddressing, ownUserServer, 0)
|
|
891
896
|
});
|
|
892
897
|
}
|
|
893
898
|
if (additionalAttributes?.['category'] !== 'peer') {
|
|
894
899
|
// Clear placeholders and enumerate actual devices
|
|
895
900
|
devices.length = 0;
|
|
896
901
|
// Use conversation-appropriate sender identity
|
|
897
|
-
const senderIdentity = isLid && meLid ? jidEncode(jidDecode(meLid)?.user, 'lid', undefined) : jidEncode(jidDecode(meId)?.user, 's.whatsapp.net', undefined);
|
|
902
|
+
const senderIdentity = isLid && meLid ? (0, _index5.jidEncode)((0, _index5.jidDecode)(meLid)?.user, 'lid', undefined) : (0, _index5.jidEncode)((0, _index5.jidDecode)(meId)?.user, 's.whatsapp.net', undefined);
|
|
898
903
|
// Enumerate devices for sender and target with consistent addressing
|
|
899
904
|
const sessionDevices = await getUSyncDevices([senderIdentity, jid], false, false);
|
|
900
905
|
devices.push(...sessionDevices);
|
|
901
906
|
logger.debug({
|
|
902
907
|
deviceCount: devices.length,
|
|
903
|
-
devices: devices.map(d => `${d.user}:${d.device}@${jidDecode(d.wireJid)?.server}`)
|
|
908
|
+
devices: devices.map(d => `${d.user}:${d.device}@${(0, _index5.jidDecode)(d.wireJid)?.server}`)
|
|
904
909
|
}, 'Device enumeration complete with unified addressing');
|
|
905
910
|
}
|
|
906
911
|
}
|
|
@@ -909,10 +914,10 @@ export const makeMessagesSocket = config => {
|
|
|
909
914
|
const otherJids = [];
|
|
910
915
|
const {
|
|
911
916
|
user: mePnUser
|
|
912
|
-
} = jidDecode(meId);
|
|
917
|
+
} = (0, _index5.jidDecode)(meId);
|
|
913
918
|
const {
|
|
914
919
|
user: meLidUser
|
|
915
|
-
} = meLid ? jidDecode(meLid) : {
|
|
920
|
+
} = meLid ? (0, _index5.jidDecode)(meLid) : {
|
|
916
921
|
user: null
|
|
917
922
|
};
|
|
918
923
|
for (const {
|
|
@@ -980,10 +985,10 @@ export const makeMessagesSocket = config => {
|
|
|
980
985
|
// ensure the message is only sent to that person
|
|
981
986
|
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
982
987
|
if (participant) {
|
|
983
|
-
if (isJidGroup(destinationJid)) {
|
|
988
|
+
if ((0, _index5.isJidGroup)(destinationJid)) {
|
|
984
989
|
stanza.attrs.to = destinationJid;
|
|
985
990
|
stanza.attrs.participant = participant.jid;
|
|
986
|
-
} else if (areJidsSameUser(participant.jid, meId)) {
|
|
991
|
+
} else if ((0, _index5.areJidsSameUser)(participant.jid, meId)) {
|
|
987
992
|
stanza.attrs.to = participant.jid;
|
|
988
993
|
stanza.attrs.recipient = destinationJid;
|
|
989
994
|
} else {
|
|
@@ -997,7 +1002,7 @@ export const makeMessagesSocket = config => {
|
|
|
997
1002
|
stanza.content.push({
|
|
998
1003
|
tag: 'device-identity',
|
|
999
1004
|
attrs: {},
|
|
1000
|
-
content: encodeSignedDeviceIdentity(authState.creds.account, true)
|
|
1005
|
+
content: (0, _index4.encodeSignedDeviceIdentity)(authState.creds.account, true)
|
|
1001
1006
|
});
|
|
1002
1007
|
logger.debug({
|
|
1003
1008
|
jid
|
|
@@ -1061,11 +1066,11 @@ export const makeMessagesSocket = config => {
|
|
|
1061
1066
|
}
|
|
1062
1067
|
};
|
|
1063
1068
|
const getPrivacyTokens = async jids => {
|
|
1064
|
-
const t = unixTimestampSeconds().toString();
|
|
1069
|
+
const t = (0, _index4.unixTimestampSeconds)().toString();
|
|
1065
1070
|
const result = await query({
|
|
1066
1071
|
tag: 'iq',
|
|
1067
1072
|
attrs: {
|
|
1068
|
-
to: S_WHATSAPP_NET,
|
|
1073
|
+
to: _index5.S_WHATSAPP_NET,
|
|
1069
1074
|
type: 'set',
|
|
1070
1075
|
xmlns: 'privacy'
|
|
1071
1076
|
},
|
|
@@ -1075,7 +1080,7 @@ export const makeMessagesSocket = config => {
|
|
|
1075
1080
|
content: jids.map(jid => ({
|
|
1076
1081
|
tag: 'token',
|
|
1077
1082
|
attrs: {
|
|
1078
|
-
jid: jidNormalizedUser(jid),
|
|
1083
|
+
jid: (0, _index5.jidNormalizedUser)(jid),
|
|
1079
1084
|
t,
|
|
1080
1085
|
type: 'trusted_contact'
|
|
1081
1086
|
}
|
|
@@ -1084,17 +1089,17 @@ export const makeMessagesSocket = config => {
|
|
|
1084
1089
|
});
|
|
1085
1090
|
return result;
|
|
1086
1091
|
};
|
|
1087
|
-
const waUploadToServer = getWAUploadToServer(config, refreshMediaConn);
|
|
1088
|
-
const extendedMessages = makeExtendedMessageHandlers({
|
|
1089
|
-
generateWAMessage,
|
|
1090
|
-
generateWAMessageContent,
|
|
1091
|
-
generateWAMessageFromContent,
|
|
1092
|
-
generateMessageID,
|
|
1093
|
-
prepareWAMessageMedia,
|
|
1092
|
+
const waUploadToServer = (0, _index4.getWAUploadToServer)(config, refreshMediaConn);
|
|
1093
|
+
const extendedMessages = (0, _extendedMessages.makeExtendedMessageHandlers)({
|
|
1094
|
+
generateWAMessage: _index4.generateWAMessage,
|
|
1095
|
+
generateWAMessageContent: _index4.generateWAMessageContent,
|
|
1096
|
+
generateWAMessageFromContent: _index4.generateWAMessageFromContent,
|
|
1097
|
+
generateMessageID: _index4.generateMessageID,
|
|
1098
|
+
prepareWAMessageMedia: _index4.prepareWAMessageMedia,
|
|
1094
1099
|
waUploadToServer,
|
|
1095
1100
|
relayMessage
|
|
1096
1101
|
});
|
|
1097
|
-
const waitForMsgMediaUpdate = bindWaitForEvent(ev, 'messages.media-update');
|
|
1102
|
+
const waitForMsgMediaUpdate = (0, _index4.bindWaitForEvent)(ev, 'messages.media-update');
|
|
1098
1103
|
return {
|
|
1099
1104
|
...sock,
|
|
1100
1105
|
getPrivacyTokens,
|
|
@@ -1111,10 +1116,10 @@ export const makeMessagesSocket = config => {
|
|
|
1111
1116
|
getUSyncDevices,
|
|
1112
1117
|
messageRetryManager,
|
|
1113
1118
|
updateMediaMessage: async message => {
|
|
1114
|
-
const content = assertMediaContent(message.message);
|
|
1119
|
+
const content = (0, _index4.assertMediaContent)(message.message);
|
|
1115
1120
|
const mediaKey = content.mediaKey;
|
|
1116
1121
|
const meId = authState.creds.me.id;
|
|
1117
|
-
const node = await encryptMediaRetryRequest(message.key, mediaKey, meId);
|
|
1122
|
+
const node = await (0, _index4.encryptMediaRetryRequest)(message.key, mediaKey, meId);
|
|
1118
1123
|
let error = undefined;
|
|
1119
1124
|
await Promise.all([sendNode(node), waitForMsgMediaUpdate(async update => {
|
|
1120
1125
|
const result = update.find(c => c.key.id === message.key.id);
|
|
@@ -1123,16 +1128,16 @@ export const makeMessagesSocket = config => {
|
|
|
1123
1128
|
error = result.error;
|
|
1124
1129
|
} else {
|
|
1125
1130
|
try {
|
|
1126
|
-
const media = await decryptMediaRetryData(result.media, mediaKey, result.key.id);
|
|
1127
|
-
if (media.result !== proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
1128
|
-
const resultStr = proto.MediaRetryNotification.ResultType[media.result];
|
|
1129
|
-
throw new Boom(`Media re-upload failed by device (${resultStr})`, {
|
|
1131
|
+
const media = await (0, _index4.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
|
|
1132
|
+
if (media.result !== _index.proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
1133
|
+
const resultStr = _index.proto.MediaRetryNotification.ResultType[media.result];
|
|
1134
|
+
throw new _boom.Boom(`Media re-upload failed by device (${resultStr})`, {
|
|
1130
1135
|
data: media,
|
|
1131
|
-
statusCode: getStatusCodeForMediaRetry(media.result) || 404
|
|
1136
|
+
statusCode: (0, _index4.getStatusCodeForMediaRetry)(media.result) || 404
|
|
1132
1137
|
});
|
|
1133
1138
|
}
|
|
1134
1139
|
content.directPath = media.directPath;
|
|
1135
|
-
content.url = getUrlFromDirectPath(content.directPath);
|
|
1140
|
+
content.url = (0, _index4.getUrlFromDirectPath)(content.directPath);
|
|
1136
1141
|
logger.debug({
|
|
1137
1142
|
directPath: media.directPath,
|
|
1138
1143
|
key: result.key
|
|
@@ -1157,9 +1162,9 @@ export const makeMessagesSocket = config => {
|
|
|
1157
1162
|
},
|
|
1158
1163
|
sendMessage: async (jid, content, options = {}) => {
|
|
1159
1164
|
const userJid = authState.creds.me.id;
|
|
1160
|
-
const extendedType = detectExtendedMessageType(content);
|
|
1165
|
+
const extendedType = (0, _extendedMessages.detectExtendedMessageType)(content);
|
|
1161
1166
|
if (extendedType) {
|
|
1162
|
-
const msgId = options.messageId || generateMessageIDV2(sock.user?.id);
|
|
1167
|
+
const msgId = options.messageId || (0, _index4.generateMessageIDV2)(sock.user?.id);
|
|
1163
1168
|
switch (extendedType) {
|
|
1164
1169
|
case 'PAYMENT':
|
|
1165
1170
|
{
|
|
@@ -1179,7 +1184,7 @@ export const makeMessagesSocket = config => {
|
|
|
1179
1184
|
case 'INTERACTIVE':
|
|
1180
1185
|
{
|
|
1181
1186
|
const interactiveContent = await extendedMessages.buildInteractiveContent(content, options);
|
|
1182
|
-
const interactiveMsg = generateWAMessageFromContent(jid, interactiveContent, {
|
|
1187
|
+
const interactiveMsg = (0, _index4.generateWAMessageFromContent)(jid, interactiveContent, {
|
|
1183
1188
|
quoted: options.quoted,
|
|
1184
1189
|
userJid
|
|
1185
1190
|
});
|
|
@@ -1196,17 +1201,17 @@ export const makeMessagesSocket = config => {
|
|
|
1196
1201
|
return await extendedMessages.sendGroupStoryMessage(jid, content, options.quoted);
|
|
1197
1202
|
}
|
|
1198
1203
|
}
|
|
1199
|
-
if (typeof content === 'object' && 'disappearingMessagesInChat' in content && typeof content['disappearingMessagesInChat'] !== 'undefined' && isJidGroup(jid)) {
|
|
1204
|
+
if (typeof content === 'object' && 'disappearingMessagesInChat' in content && typeof content['disappearingMessagesInChat'] !== 'undefined' && (0, _index5.isJidGroup)(jid)) {
|
|
1200
1205
|
const {
|
|
1201
1206
|
disappearingMessagesInChat
|
|
1202
1207
|
} = content;
|
|
1203
|
-
const value = typeof disappearingMessagesInChat === 'boolean' ? disappearingMessagesInChat ? WA_DEFAULT_EPHEMERAL : 0 : disappearingMessagesInChat;
|
|
1208
|
+
const value = typeof disappearingMessagesInChat === 'boolean' ? disappearingMessagesInChat ? _index2.WA_DEFAULT_EPHEMERAL : 0 : disappearingMessagesInChat;
|
|
1204
1209
|
await groupToggleEphemeral(jid, value);
|
|
1205
1210
|
} else {
|
|
1206
|
-
const fullMsg = await generateWAMessage(jid, content, {
|
|
1211
|
+
const fullMsg = await (0, _index4.generateWAMessage)(jid, content, {
|
|
1207
1212
|
logger,
|
|
1208
1213
|
userJid,
|
|
1209
|
-
getUrlInfo: text => getUrlInfo(text, {
|
|
1214
|
+
getUrlInfo: text => (0, _linkPreview.getUrlInfo)(text, {
|
|
1210
1215
|
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
1211
1216
|
fetchOpts: {
|
|
1212
1217
|
timeout: 3000,
|
|
@@ -1221,7 +1226,7 @@ export const makeMessagesSocket = config => {
|
|
|
1221
1226
|
upload: waUploadToServer,
|
|
1222
1227
|
mediaCache: config.mediaCache,
|
|
1223
1228
|
options: config.options,
|
|
1224
|
-
messageId: generateMessageIDV2(sock.user?.id),
|
|
1229
|
+
messageId: (0, _index4.generateMessageIDV2)(sock.user?.id),
|
|
1225
1230
|
...options
|
|
1226
1231
|
});
|
|
1227
1232
|
const isEventMsg = 'event' in content && !!content.event;
|
|
@@ -1234,7 +1239,7 @@ export const makeMessagesSocket = config => {
|
|
|
1234
1239
|
// required for delete
|
|
1235
1240
|
if (isDeleteMsg) {
|
|
1236
1241
|
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
1237
|
-
if (isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe) {
|
|
1242
|
+
if ((0, _index5.isJidGroup)(content.delete?.remoteJid) && !content.delete?.fromMe) {
|
|
1238
1243
|
additionalAttributes.edit = '8';
|
|
1239
1244
|
} else {
|
|
1240
1245
|
additionalAttributes.edit = '7';
|
|
@@ -1278,4 +1283,4 @@ export const makeMessagesSocket = config => {
|
|
|
1278
1283
|
}
|
|
1279
1284
|
};
|
|
1280
1285
|
};
|
|
1281
|
-
|
|
1286
|
+
exports.makeMessagesSocket = makeMessagesSocket;
|
package/lib/Socket/mex.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2
|
+
value: true
|
|
3
|
+
});
|
|
4
|
+
exports.executeWMexQuery = void 0;
|
|
5
|
+
var _boom = require("@hapi/boom");
|
|
6
|
+
var _index = require("../WABinary/index.js");
|
|
3
7
|
const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
4
8
|
return query({
|
|
5
9
|
tag: 'iq',
|
|
6
10
|
attrs: {
|
|
7
11
|
id: generateMessageTag(),
|
|
8
12
|
type: 'get',
|
|
9
|
-
to: S_WHATSAPP_NET,
|
|
13
|
+
to: _index.S_WHATSAPP_NET,
|
|
10
14
|
xmlns: 'w:mex'
|
|
11
15
|
},
|
|
12
16
|
content: [{
|
|
@@ -20,16 +24,16 @@ const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
|
20
24
|
}]
|
|
21
25
|
});
|
|
22
26
|
};
|
|
23
|
-
|
|
27
|
+
const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
24
28
|
const result = await wMexQuery(variables, queryId, query, generateMessageTag);
|
|
25
|
-
const child = getBinaryNodeChild(result, 'result');
|
|
29
|
+
const child = (0, _index.getBinaryNodeChild)(result, 'result');
|
|
26
30
|
if (child?.content) {
|
|
27
31
|
const data = JSON.parse(child.content.toString());
|
|
28
32
|
if (data.errors && data.errors.length > 0) {
|
|
29
33
|
const errorMessages = data.errors.map(err => err.message || 'Unknown error').join(', ');
|
|
30
34
|
const firstError = data.errors[0];
|
|
31
35
|
const errorCode = firstError.extensions?.error_code || 400;
|
|
32
|
-
throw new Boom(`GraphQL server error: ${errorMessages}`, {
|
|
36
|
+
throw new _boom.Boom(`GraphQL server error: ${errorMessages}`, {
|
|
33
37
|
statusCode: errorCode,
|
|
34
38
|
data: firstError
|
|
35
39
|
});
|
|
@@ -40,9 +44,9 @@ export const executeWMexQuery = async (variables, queryId, dataPath, query, gene
|
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
const action = (dataPath || '').startsWith('xwa2_') ? dataPath.substring(5).replace(/_/g, ' ') : dataPath?.replace(/_/g, ' ');
|
|
43
|
-
throw new Boom(`Failed to ${action}, unexpected response structure.`, {
|
|
47
|
+
throw new _boom.Boom(`Failed to ${action}, unexpected response structure.`, {
|
|
44
48
|
statusCode: 400,
|
|
45
49
|
data: result
|
|
46
50
|
});
|
|
47
51
|
};
|
|
48
|
-
|
|
52
|
+
exports.executeWMexQuery = executeWMexQuery;
|