@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.
Files changed (102) hide show
  1. package/WAProto/fix-imports.js +7 -16
  2. package/WAProto/index.js +1 -37306
  3. package/lib/Defaults/index.js +37 -33
  4. package/lib/Signal/Group/ciphertext-message.js +6 -2
  5. package/lib/Signal/Group/group-session-builder.js +12 -7
  6. package/lib/Signal/Group/group_cipher.js +18 -13
  7. package/lib/Signal/Group/index.js +77 -12
  8. package/lib/Signal/Group/keyhelper.js +15 -8
  9. package/lib/Signal/Group/queue-job.js +7 -2
  10. package/lib/Signal/Group/sender-chain-key.js +11 -6
  11. package/lib/Signal/Group/sender-key-distribution-message.js +10 -6
  12. package/lib/Signal/Group/sender-key-message.js +14 -9
  13. package/lib/Signal/Group/sender-key-name.js +6 -2
  14. package/lib/Signal/Group/sender-key-record.js +13 -9
  15. package/lib/Signal/Group/sender-key-state.js +10 -6
  16. package/lib/Signal/Group/sender-message-key.js +9 -4
  17. package/lib/Signal/libsignal.js +34 -28
  18. package/lib/Signal/lid-mapping.js +24 -19
  19. package/lib/Socket/Client/index.js +25 -3
  20. package/lib/Socket/Client/types.js +8 -4
  21. package/lib/Socket/Client/websocket.js +16 -11
  22. package/lib/Socket/business.js +38 -34
  23. package/lib/Socket/chats.js +100 -95
  24. package/lib/Socket/communities.js +55 -49
  25. package/lib/Socket/groups.js +56 -51
  26. package/lib/Socket/index.js +9 -6
  27. package/lib/Socket/messages-recv.js +150 -145
  28. package/lib/Socket/messages-send.js +109 -104
  29. package/lib/Socket/mex.js +12 -8
  30. package/lib/Socket/newsletter.js +27 -23
  31. package/lib/Socket/socket.js +111 -107
  32. package/lib/Store/index.js +47 -4
  33. package/lib/Store/make-cache-manager-store.js +17 -11
  34. package/lib/Store/make-in-memory-store.js +31 -29
  35. package/lib/Store/make-ordered-dictionary.js +7 -2
  36. package/lib/Store/object-repository.js +7 -2
  37. package/lib/Types/Auth.js +3 -2
  38. package/lib/Types/Bussines.js +3 -2
  39. package/lib/Types/Call.js +3 -2
  40. package/lib/Types/Chat.js +5 -2
  41. package/lib/Types/Contact.js +3 -2
  42. package/lib/Types/Events.js +1 -2
  43. package/lib/Types/GroupMetadata.js +3 -2
  44. package/lib/Types/Label.js +6 -3
  45. package/lib/Types/LabelAssociation.js +6 -3
  46. package/lib/Types/Message.js +16 -7
  47. package/lib/Types/Newsletter.js +8 -5
  48. package/lib/Types/Product.js +3 -2
  49. package/lib/Types/Signal.js +1 -2
  50. package/lib/Types/Socket.js +2 -3
  51. package/lib/Types/State.js +7 -4
  52. package/lib/Types/USync.js +1 -2
  53. package/lib/Types/index.js +153 -15
  54. package/lib/Utils/auth-utils.js +32 -25
  55. package/lib/Utils/baileys-event-stream.js +21 -15
  56. package/lib/Utils/business.js +71 -61
  57. package/lib/Utils/chat-utils.js +91 -77
  58. package/lib/Utils/crypto.js +54 -32
  59. package/lib/Utils/decode-wa-message.js +46 -39
  60. package/lib/Utils/event-buffer.js +24 -19
  61. package/lib/Utils/extended-messages.js +14 -9
  62. package/lib/Utils/generics.js +100 -64
  63. package/lib/Utils/history.js +30 -23
  64. package/lib/Utils/index.js +234 -22
  65. package/lib/Utils/lid-resolver.js +12 -5
  66. package/lib/Utils/link-preview.js +11 -7
  67. package/lib/Utils/logger.js +8 -4
  68. package/lib/Utils/lt-hash.js +8 -5
  69. package/lib/Utils/make-mutex.js +8 -3
  70. package/lib/Utils/mention.js +12 -4
  71. package/lib/Utils/message-retry-manager.js +10 -6
  72. package/lib/Utils/messages-media.js +127 -95
  73. package/lib/Utils/messages.js +122 -98
  74. package/lib/Utils/noise-handler.js +25 -21
  75. package/lib/Utils/process-message.js +72 -63
  76. package/lib/Utils/signal.js +45 -33
  77. package/lib/Utils/use-multi-file-auth-state.js +24 -20
  78. package/lib/Utils/validate-connection.js +54 -47
  79. package/lib/WABinary/constants.js +9 -6
  80. package/lib/WABinary/decode.js +17 -10
  81. package/lib/WABinary/encode.js +11 -6
  82. package/lib/WABinary/generic-utils.js +31 -17
  83. package/lib/WABinary/index.js +58 -6
  84. package/lib/WABinary/jid-utils.js +36 -20
  85. package/lib/WABinary/types.js +2 -2
  86. package/lib/WAM/BinaryInfo.js +6 -2
  87. package/lib/WAM/constants.js +1 -1
  88. package/lib/WAM/encode.js +16 -12
  89. package/lib/WAM/index.js +36 -4
  90. package/lib/WAUSync/Protocols/USyncContactProtocol.js +9 -5
  91. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -6
  92. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +8 -4
  93. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +8 -4
  94. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +9 -4
  95. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +23 -19
  96. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -2
  97. package/lib/WAUSync/Protocols/index.js +58 -6
  98. package/lib/WAUSync/USyncQuery.js +21 -17
  99. package/lib/WAUSync/USyncUser.js +6 -2
  100. package/lib/WAUSync/index.js +36 -4
  101. package/lib/index.js +112 -12
  102. package/package.json +8 -6
@@ -1,15 +1,22 @@
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.makeLibSignalRepository = makeLibSignalRepository;
5
+ var libsignal = _interopRequireWildcard(require("libsignal"));
6
+ var _lruCache = require("lru-cache");
7
+ var _index = require("../Utils/index.js");
8
+ var _index2 = require("../WABinary/index.js");
9
+ var _senderKeyName = require("./Group/sender-key-name.js");
10
+ var _senderKeyRecord = require("./Group/sender-key-record.js");
11
+ var _index3 = require("./Group/index.js");
12
+ var _lidMapping = require("./lid-mapping.js");
13
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
1
14
  /* @ts-ignore */
2
- import * as libsignal from 'libsignal';
15
+
3
16
  /* @ts-ignore */
4
- import { LRUCache } from 'lru-cache';
5
- import { generateSignalPubKey } from '../Utils/index.js';
6
- import { jidDecode } from '../WABinary/index.js';
7
- import { SenderKeyName } from './Group/sender-key-name.js';
8
- import { SenderKeyRecord } from './Group/sender-key-record.js';
9
- import { GroupCipher, GroupSessionBuilder, SenderKeyDistributionMessage } from './Group/index.js';
10
- import { LIDMappingStore } from './lid-mapping.js';
11
- export function makeLibSignalRepository(auth, onWhatsAppFunc) {
12
- const lidMapping = new LIDMappingStore(auth.keys, onWhatsAppFunc);
17
+
18
+ function makeLibSignalRepository(auth, onWhatsAppFunc) {
19
+ const lidMapping = new _lidMapping.LIDMappingStore(auth.keys, onWhatsAppFunc);
13
20
  const storage = signalStorage(auth, lidMapping);
14
21
  const parsedKeys = auth.keys;
15
22
  function isLikelySyncMessage(addr) {
@@ -23,7 +30,7 @@ export function makeLibSignalRepository(auth, onWhatsAppFunc) {
23
30
  key.includes('@newsletter');
24
31
  }
25
32
  // Simple operation-level deduplication (5 minutes)
26
- const recentMigrations = new LRUCache({
33
+ const recentMigrations = new _lruCache.LRUCache({
27
34
  max: 500,
28
35
  ttl: 5 * 60 * 1000
29
36
  });
@@ -34,7 +41,7 @@ export function makeLibSignalRepository(auth, onWhatsAppFunc) {
34
41
  msg
35
42
  }) {
36
43
  const senderName = jidToSignalSenderKeyName(group, authorJid);
37
- const cipher = new GroupCipher(storage, senderName);
44
+ const cipher = new _index3.GroupCipher(storage, senderName);
38
45
  // Use transaction to ensure atomicity
39
46
  return parsedKeys.transaction(async () => {
40
47
  return cipher.decrypt(msg);
@@ -44,25 +51,25 @@ export function makeLibSignalRepository(auth, onWhatsAppFunc) {
44
51
  item,
45
52
  authorJid
46
53
  }) {
47
- const builder = new GroupSessionBuilder(storage);
54
+ const builder = new _index3.GroupSessionBuilder(storage);
48
55
  if (!item.groupId) {
49
56
  throw new Error('Group ID is required for sender key distribution message');
50
57
  }
51
58
  const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
52
- const senderMsg = new SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
59
+ const senderMsg = new _index3.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
53
60
  const senderNameStr = senderName.toString();
54
61
  const {
55
62
  [senderNameStr]: senderKey
56
63
  } = await auth.keys.get('sender-key', [senderNameStr]);
57
64
  if (!senderKey) {
58
- await storage.storeSenderKey(senderName, new SenderKeyRecord());
65
+ await storage.storeSenderKey(senderName, new _senderKeyRecord.SenderKeyRecord());
59
66
  }
60
67
  return parsedKeys.transaction(async () => {
61
68
  const {
62
69
  [senderNameStr]: senderKey
63
70
  } = await auth.keys.get('sender-key', [senderNameStr]);
64
71
  if (!senderKey) {
65
- await storage.storeSenderKey(senderName, new SenderKeyRecord());
72
+ await storage.storeSenderKey(senderName, new _senderKeyRecord.SenderKeyRecord());
66
73
  }
67
74
  await builder.process(senderName, senderMsg);
68
75
  }, item.groupId);
@@ -149,17 +156,17 @@ export function makeLibSignalRepository(auth, onWhatsAppFunc) {
149
156
  data
150
157
  }) {
151
158
  const senderName = jidToSignalSenderKeyName(group, meId);
152
- const builder = new GroupSessionBuilder(storage);
159
+ const builder = new _index3.GroupSessionBuilder(storage);
153
160
  const senderNameStr = senderName.toString();
154
161
  return parsedKeys.transaction(async () => {
155
162
  const {
156
163
  [senderNameStr]: senderKey
157
164
  } = await auth.keys.get('sender-key', [senderNameStr]);
158
165
  if (!senderKey) {
159
- await storage.storeSenderKey(senderName, new SenderKeyRecord());
166
+ await storage.storeSenderKey(senderName, new _senderKeyRecord.SenderKeyRecord());
160
167
  }
161
168
  const senderKeyDistributionMessage = await builder.create(senderName);
162
- const session = new GroupCipher(storage, senderName);
169
+ const session = new _index3.GroupCipher(storage, senderName);
163
170
  const ciphertext = await session.encrypt(data);
164
171
  return {
165
172
  ciphertext,
@@ -226,8 +233,8 @@ export function makeLibSignalRepository(auth, onWhatsAppFunc) {
226
233
  if (!fromJid.includes('@s.whatsapp.net') || !toJid.includes('@lid')) {
227
234
  return;
228
235
  }
229
- const fromDecoded = jidDecode(fromJid);
230
- const toDecoded = jidDecode(toJid);
236
+ const fromDecoded = (0, _index2.jidDecode)(fromJid);
237
+ const toDecoded = (0, _index2.jidDecode)(toJid);
231
238
  if (!fromDecoded || !toDecoded) return;
232
239
  const deviceId = fromDecoded.device || 0;
233
240
  const migrationKey = `${fromDecoded.user}.${deviceId}→${toDecoded.user}.${deviceId}`;
@@ -287,7 +294,7 @@ export function makeLibSignalRepository(auth, onWhatsAppFunc) {
287
294
  return repository;
288
295
  }
289
296
  const jidToSignalProtocolAddress = jid => {
290
- const decoded = jidDecode(jid);
297
+ const decoded = (0, _index2.jidDecode)(jid);
291
298
  const {
292
299
  user,
293
300
  device,
@@ -299,7 +306,7 @@ const jidToSignalProtocolAddress = jid => {
299
306
  return new libsignal.ProtocolAddress(signalUser, finalDevice);
300
307
  };
301
308
  const jidToSignalSenderKeyName = (group, user) => {
302
- return new SenderKeyName(group, jidToSignalProtocolAddress(user));
309
+ return new _senderKeyName.SenderKeyName(group, jidToSignalProtocolAddress(user));
303
310
  };
304
311
  function signalStorage({
305
312
  creds,
@@ -381,9 +388,9 @@ function signalStorage({
381
388
  [keyId]: key
382
389
  } = await keys.get('sender-key', [keyId]);
383
390
  if (key) {
384
- return SenderKeyRecord.deserialize(key);
391
+ return _senderKeyRecord.SenderKeyRecord.deserialize(key);
385
392
  }
386
- return new SenderKeyRecord();
393
+ return new _senderKeyRecord.SenderKeyRecord();
387
394
  },
388
395
  storeSenderKey: async (senderKeyName, key) => {
389
396
  const keyId = senderKeyName.toString();
@@ -401,9 +408,8 @@ function signalStorage({
401
408
  } = creds;
402
409
  return {
403
410
  privKey: Buffer.from(signedIdentityKey.private),
404
- pubKey: generateSignalPubKey(signedIdentityKey.public)
411
+ pubKey: (0, _index.generateSignalPubKey)(signedIdentityKey.public)
405
412
  };
406
413
  }
407
414
  };
408
- }
409
- //# sourceMappingURL=libsignal.js.map
415
+ }
@@ -1,7 +1,12 @@
1
- import logger from '../Utils/logger.js';
2
- import { isLidUser, isPnUser, jidDecode } from '../WABinary/index.js';
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.LIDMappingStore = void 0;
5
+ var _logger = _interopRequireDefault(require("../Utils/logger.js"));
6
+ var _index = require("../WABinary/index.js");
7
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
3
8
  //TODO: Caching
4
- export class LIDMappingStore {
9
+ class LIDMappingStore {
5
10
  constructor(keys, onWhatsAppFunc) {
6
11
  this.keys = keys;
7
12
  this.onWhatsAppFunc = onWhatsAppFunc; // needed to get LID from PN if not found
@@ -25,19 +30,19 @@ export class LIDMappingStore {
25
30
  lid,
26
31
  pn
27
32
  } of pairs) {
28
- if (!(isLidUser(lid) && isPnUser(pn) || isPnUser(lid) && isLidUser(pn))) {
29
- logger.warn(`Invalid LID-PN mapping: ${lid}, ${pn}`);
33
+ if (!((0, _index.isLidUser)(lid) && (0, _index.isPnUser)(pn) || (0, _index.isPnUser)(lid) && (0, _index.isLidUser)(pn))) {
34
+ _logger.default.warn(`Invalid LID-PN mapping: ${lid}, ${pn}`);
30
35
  continue;
31
36
  }
32
- const [lidJid, pnJid] = isLidUser(lid) ? [lid, pn] : [pn, lid];
33
- const lidDecoded = jidDecode(lidJid);
34
- const pnDecoded = jidDecode(pnJid);
37
+ const [lidJid, pnJid] = (0, _index.isLidUser)(lid) ? [lid, pn] : [pn, lid];
38
+ const lidDecoded = (0, _index.jidDecode)(lidJid);
39
+ const pnDecoded = (0, _index.jidDecode)(pnJid);
35
40
  if (!lidDecoded || !pnDecoded) return;
36
41
  const pnUser = pnDecoded.user;
37
42
  const lidUser = lidDecoded.user;
38
43
  pairMap[pnUser] = lidUser;
39
44
  }
40
- logger.trace({
45
+ _logger.default.trace({
41
46
  pairMap
42
47
  }, `Storing ${Object.keys(pairMap).length} pn mappings`);
43
48
  await this.keys.transaction(async () => {
@@ -56,21 +61,21 @@ export class LIDMappingStore {
56
61
  * Get LID for PN - Returns device-specific LID based on user mapping
57
62
  */
58
63
  async getLIDForPN(pn) {
59
- if (!isPnUser(pn)) return null;
60
- const decoded = jidDecode(pn);
64
+ if (!(0, _index.isPnUser)(pn)) return null;
65
+ const decoded = (0, _index.jidDecode)(pn);
61
66
  if (!decoded) return null;
62
67
  // Look up user-level mapping (whatsmeow approach)
63
68
  const pnUser = decoded.user;
64
69
  const stored = await this.keys.get('lid-mapping', [pnUser]);
65
70
  let lidUser = stored[pnUser];
66
71
  if (!lidUser) {
67
- logger.trace(`No LID mapping found for PN user ${pnUser}; getting from USync`);
72
+ _logger.default.trace(`No LID mapping found for PN user ${pnUser}; getting from USync`);
68
73
  const {
69
74
  exists,
70
75
  lid
71
76
  } = (await this.onWhatsAppFunc?.(pn))?.[0];
72
77
  if (exists) {
73
- lidUser = jidDecode(lid)?.user;
78
+ lidUser = (0, _index.jidDecode)(lid)?.user;
74
79
  } else {
75
80
  return null;
76
81
  }
@@ -79,29 +84,29 @@ export class LIDMappingStore {
79
84
  // Push the PN device ID to the LID to maintain device separation
80
85
  const pnDevice = decoded.device !== undefined ? decoded.device : 0;
81
86
  const deviceSpecificLid = `${lidUser}:${pnDevice}@lid`;
82
- logger.trace(`getLIDForPN: ${pn} → ${deviceSpecificLid} (user mapping with device ${pnDevice})`);
87
+ _logger.default.trace(`getLIDForPN: ${pn} → ${deviceSpecificLid} (user mapping with device ${pnDevice})`);
83
88
  return deviceSpecificLid;
84
89
  }
85
90
  /**
86
91
  * Get PN for LID - USER LEVEL with device construction
87
92
  */
88
93
  async getPNForLID(lid) {
89
- if (!isLidUser(lid)) return null;
90
- const decoded = jidDecode(lid);
94
+ if (!(0, _index.isLidUser)(lid)) return null;
95
+ const decoded = (0, _index.jidDecode)(lid);
91
96
  if (!decoded) return null;
92
97
  // Look up reverse user mapping
93
98
  const lidUser = decoded.user;
94
99
  const stored = await this.keys.get('lid-mapping', [`${lidUser}_reverse`]);
95
100
  const pnUser = stored[`${lidUser}_reverse`];
96
101
  if (!pnUser || typeof pnUser !== 'string') {
97
- logger.trace(`No reverse mapping found for LID user: ${lidUser}`);
102
+ _logger.default.trace(`No reverse mapping found for LID user: ${lidUser}`);
98
103
  return null;
99
104
  }
100
105
  // Construct device-specific PN JID
101
106
  const lidDevice = decoded.device !== undefined ? decoded.device : 0;
102
107
  const pnJid = `${pnUser}:${lidDevice}@s.whatsapp.net`;
103
- logger.trace(`Found reverse mapping: ${lid} → ${pnJid}`);
108
+ _logger.default.trace(`Found reverse mapping: ${lid} → ${pnJid}`);
104
109
  return pnJid;
105
110
  }
106
111
  }
107
- //# sourceMappingURL=lid-mapping.js.map
112
+ exports.LIDMappingStore = LIDMappingStore;
@@ -1,3 +1,25 @@
1
- export * from './types.js';
2
- export * from './websocket.js';
3
- //# sourceMappingURL=index.js.map
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ var _types = require("./types.js");
5
+ Object.keys(_types).forEach(function (key) {
6
+ if (key === "default" || key === "__esModule") return;
7
+ if (key in exports && exports[key] === _types[key]) return;
8
+ Object.defineProperty(exports, key, {
9
+ enumerable: true,
10
+ get: function () {
11
+ return _types[key];
12
+ }
13
+ });
14
+ });
15
+ var _websocket = require("./websocket.js");
16
+ Object.keys(_websocket).forEach(function (key) {
17
+ if (key === "default" || key === "__esModule") return;
18
+ if (key in exports && exports[key] === _websocket[key]) return;
19
+ Object.defineProperty(exports, key, {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _websocket[key];
23
+ }
24
+ });
25
+ });
@@ -1,6 +1,10 @@
1
- import { EventEmitter } from 'events';
2
- import { URL } from 'url';
3
- export class AbstractSocketClient extends EventEmitter {
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.AbstractSocketClient = void 0;
5
+ var _events = require("events");
6
+ var _url = require("url");
7
+ class AbstractSocketClient extends _events.EventEmitter {
4
8
  constructor(url, config) {
5
9
  super();
6
10
  this.url = url;
@@ -8,4 +12,4 @@ export class AbstractSocketClient extends EventEmitter {
8
12
  this.setMaxListeners(0);
9
13
  }
10
14
  }
11
- //# sourceMappingURL=types.js.map
15
+ exports.AbstractSocketClient = AbstractSocketClient;
@@ -1,29 +1,34 @@
1
- import WebSocket from 'ws';
2
- import { DEFAULT_ORIGIN } from '../../Defaults/index.js';
3
- import { AbstractSocketClient } from './types.js';
4
- export class WebSocketClient extends AbstractSocketClient {
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.WebSocketClient = void 0;
5
+ var _ws = _interopRequireDefault(require("ws"));
6
+ var _index = require("../../Defaults/index.js");
7
+ var _types = require("./types.js");
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ class WebSocketClient extends _types.AbstractSocketClient {
5
10
  constructor() {
6
11
  super(...arguments);
7
12
  this.socket = null;
8
13
  }
9
14
  get isOpen() {
10
- return this.socket?.readyState === WebSocket.OPEN;
15
+ return this.socket?.readyState === _ws.default.OPEN;
11
16
  }
12
17
  get isClosed() {
13
- return this.socket === null || this.socket?.readyState === WebSocket.CLOSED;
18
+ return this.socket === null || this.socket?.readyState === _ws.default.CLOSED;
14
19
  }
15
20
  get isClosing() {
16
- return this.socket === null || this.socket?.readyState === WebSocket.CLOSING;
21
+ return this.socket === null || this.socket?.readyState === _ws.default.CLOSING;
17
22
  }
18
23
  get isConnecting() {
19
- return this.socket?.readyState === WebSocket.CONNECTING;
24
+ return this.socket?.readyState === _ws.default.CONNECTING;
20
25
  }
21
26
  async connect() {
22
27
  if (this.socket) {
23
28
  return;
24
29
  }
25
- this.socket = new WebSocket(this.url, {
26
- origin: DEFAULT_ORIGIN,
30
+ this.socket = new _ws.default(this.url, {
31
+ origin: _index.DEFAULT_ORIGIN,
27
32
  headers: this.config.options?.headers,
28
33
  handshakeTimeout: this.config.connectTimeoutMs,
29
34
  timeout: this.config.connectTimeoutMs,
@@ -47,4 +52,4 @@ export class WebSocketClient extends AbstractSocketClient {
47
52
  return Boolean(this.socket);
48
53
  }
49
54
  }
50
- //# sourceMappingURL=websocket.js.map
55
+ exports.WebSocketClient = WebSocketClient;
@@ -1,10 +1,14 @@
1
- import { getRawMediaUploadData } from '../Utils/index.js';
2
- import { parseCatalogNode, parseCollectionsNode, parseOrderDetailsNode, parseProductNode, toProductNode, uploadingNecessaryImagesOfProduct } from '../Utils/business.js';
3
- import { jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
4
- import { getBinaryNodeChild } from '../WABinary/generic-utils.js';
5
- import { makeMessagesRecvSocket } from './messages-recv.js';
6
- export const makeBusinessSocket = config => {
7
- const sock = makeMessagesRecvSocket(config);
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.makeBusinessSocket = void 0;
5
+ var _index = require("../Utils/index.js");
6
+ var _business = require("../Utils/business.js");
7
+ var _index2 = require("../WABinary/index.js");
8
+ var _genericUtils = require("../WABinary/generic-utils.js");
9
+ var _messagesRecv = require("./messages-recv.js");
10
+ const makeBusinessSocket = config => {
11
+ const sock = (0, _messagesRecv.makeMessagesRecvSocket)(config);
8
12
  const {
9
13
  authState,
10
14
  query,
@@ -56,7 +60,7 @@ export const makeBusinessSocket = config => {
56
60
  const result = await query({
57
61
  tag: 'iq',
58
62
  attrs: {
59
- to: S_WHATSAPP_NET,
63
+ to: _index2.S_WHATSAPP_NET,
60
64
  type: 'set',
61
65
  xmlns: 'w:biz'
62
66
  },
@@ -75,7 +79,7 @@ export const makeBusinessSocket = config => {
75
79
  const {
76
80
  fileSha256,
77
81
  filePath
78
- } = await getRawMediaUploadData(photo, 'biz-cover-photo');
82
+ } = await (0, _index.getRawMediaUploadData)(photo, 'biz-cover-photo');
79
83
  const fileSha256B64 = fileSha256.toString('base64');
80
84
  const {
81
85
  meta_hmac,
@@ -88,7 +92,7 @@ export const makeBusinessSocket = config => {
88
92
  await query({
89
93
  tag: 'iq',
90
94
  attrs: {
91
- to: S_WHATSAPP_NET,
95
+ to: _index2.S_WHATSAPP_NET,
92
96
  type: 'set',
93
97
  xmlns: 'w:biz'
94
98
  },
@@ -115,7 +119,7 @@ export const makeBusinessSocket = config => {
115
119
  return await query({
116
120
  tag: 'iq',
117
121
  attrs: {
118
- to: S_WHATSAPP_NET,
122
+ to: _index2.S_WHATSAPP_NET,
119
123
  type: 'set',
120
124
  xmlns: 'w:biz'
121
125
  },
@@ -141,7 +145,7 @@ export const makeBusinessSocket = config => {
141
145
  cursor
142
146
  }) => {
143
147
  jid = jid || authState.creds.me?.id;
144
- jid = jidNormalizedUser(jid);
148
+ jid = (0, _index2.jidNormalizedUser)(jid);
145
149
  const queryParamNodes = [{
146
150
  tag: 'limit',
147
151
  attrs: {},
@@ -165,7 +169,7 @@ export const makeBusinessSocket = config => {
165
169
  const result = await query({
166
170
  tag: 'iq',
167
171
  attrs: {
168
- to: S_WHATSAPP_NET,
172
+ to: _index2.S_WHATSAPP_NET,
169
173
  type: 'get',
170
174
  xmlns: 'w:biz:catalog'
171
175
  },
@@ -178,15 +182,15 @@ export const makeBusinessSocket = config => {
178
182
  content: queryParamNodes
179
183
  }]
180
184
  });
181
- return parseCatalogNode(result);
185
+ return (0, _business.parseCatalogNode)(result);
182
186
  };
183
187
  const getCollections = async (jid, limit = 51) => {
184
188
  jid = jid || authState.creds.me?.id;
185
- jid = jidNormalizedUser(jid);
189
+ jid = (0, _index2.jidNormalizedUser)(jid);
186
190
  const result = await query({
187
191
  tag: 'iq',
188
192
  attrs: {
189
- to: S_WHATSAPP_NET,
193
+ to: _index2.S_WHATSAPP_NET,
190
194
  type: 'get',
191
195
  xmlns: 'w:biz:catalog',
192
196
  smax_id: '35'
@@ -215,13 +219,13 @@ export const makeBusinessSocket = config => {
215
219
  }]
216
220
  }]
217
221
  });
218
- return parseCollectionsNode(result);
222
+ return (0, _business.parseCollectionsNode)(result);
219
223
  };
220
224
  const getOrderDetails = async (orderId, tokenBase64) => {
221
225
  const result = await query({
222
226
  tag: 'iq',
223
227
  attrs: {
224
- to: S_WHATSAPP_NET,
228
+ to: _index2.S_WHATSAPP_NET,
225
229
  type: 'get',
226
230
  xmlns: 'fb:thrift_iq',
227
231
  smax_id: '5'
@@ -251,15 +255,15 @@ export const makeBusinessSocket = config => {
251
255
  }]
252
256
  }]
253
257
  });
254
- return parseOrderDetailsNode(result);
258
+ return (0, _business.parseOrderDetailsNode)(result);
255
259
  };
256
260
  const productUpdate = async (productId, update) => {
257
- update = await uploadingNecessaryImagesOfProduct(update, waUploadToServer);
258
- const editNode = toProductNode(productId, update);
261
+ update = await (0, _business.uploadingNecessaryImagesOfProduct)(update, waUploadToServer);
262
+ const editNode = (0, _business.toProductNode)(productId, update);
259
263
  const result = await query({
260
264
  tag: 'iq',
261
265
  attrs: {
262
- to: S_WHATSAPP_NET,
266
+ to: _index2.S_WHATSAPP_NET,
263
267
  type: 'set',
264
268
  xmlns: 'w:biz:catalog'
265
269
  },
@@ -279,19 +283,19 @@ export const makeBusinessSocket = config => {
279
283
  }]
280
284
  }]
281
285
  });
282
- const productCatalogEditNode = getBinaryNodeChild(result, 'product_catalog_edit');
283
- const productNode = getBinaryNodeChild(productCatalogEditNode, 'product');
284
- return parseProductNode(productNode);
286
+ const productCatalogEditNode = (0, _genericUtils.getBinaryNodeChild)(result, 'product_catalog_edit');
287
+ const productNode = (0, _genericUtils.getBinaryNodeChild)(productCatalogEditNode, 'product');
288
+ return (0, _business.parseProductNode)(productNode);
285
289
  };
286
290
  const productCreate = async create => {
287
291
  // ensure isHidden is defined
288
292
  create.isHidden = !!create.isHidden;
289
- create = await uploadingNecessaryImagesOfProduct(create, waUploadToServer);
290
- const createNode = toProductNode(undefined, create);
293
+ create = await (0, _business.uploadingNecessaryImagesOfProduct)(create, waUploadToServer);
294
+ const createNode = (0, _business.toProductNode)(undefined, create);
291
295
  const result = await query({
292
296
  tag: 'iq',
293
297
  attrs: {
294
- to: S_WHATSAPP_NET,
298
+ to: _index2.S_WHATSAPP_NET,
295
299
  type: 'set',
296
300
  xmlns: 'w:biz:catalog'
297
301
  },
@@ -311,15 +315,15 @@ export const makeBusinessSocket = config => {
311
315
  }]
312
316
  }]
313
317
  });
314
- const productCatalogAddNode = getBinaryNodeChild(result, 'product_catalog_add');
315
- const productNode = getBinaryNodeChild(productCatalogAddNode, 'product');
316
- return parseProductNode(productNode);
318
+ const productCatalogAddNode = (0, _genericUtils.getBinaryNodeChild)(result, 'product_catalog_add');
319
+ const productNode = (0, _genericUtils.getBinaryNodeChild)(productCatalogAddNode, 'product');
320
+ return (0, _business.parseProductNode)(productNode);
317
321
  };
318
322
  const productDelete = async productIds => {
319
323
  const result = await query({
320
324
  tag: 'iq',
321
325
  attrs: {
322
- to: S_WHATSAPP_NET,
326
+ to: _index2.S_WHATSAPP_NET,
323
327
  type: 'set',
324
328
  xmlns: 'w:biz:catalog'
325
329
  },
@@ -339,7 +343,7 @@ export const makeBusinessSocket = config => {
339
343
  }))
340
344
  }]
341
345
  });
342
- const productCatalogDelNode = getBinaryNodeChild(result, 'product_catalog_delete');
346
+ const productCatalogDelNode = (0, _genericUtils.getBinaryNodeChild)(result, 'product_catalog_delete');
343
347
  return {
344
348
  deleted: +(productCatalogDelNode?.attrs.deleted_count || 0)
345
349
  };
@@ -358,4 +362,4 @@ export const makeBusinessSocket = config => {
358
362
  removeCoverPhoto
359
363
  };
360
364
  };
361
- //# sourceMappingURL=business.js.map
365
+ exports.makeBusinessSocket = makeBusinessSocket;