@baileys-md/baileys 10.1.0 → 11.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 (122) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1303 -2
  3. package/WAProto/GenerateStatics.sh +3 -0
  4. package/WAProto/WAProto.proto +4633 -0
  5. package/WAProto/fix-imports.js +29 -0
  6. package/WAProto/index.js +13516 -4182
  7. package/lib/Defaults/baileys-version.js +1 -0
  8. package/lib/Defaults/index.js +51 -72
  9. package/lib/Signal/Group/ciphertext-message.js +12 -0
  10. package/lib/Signal/Group/group-session-builder.js +30 -0
  11. package/lib/Signal/Group/group_cipher.js +94 -0
  12. package/lib/Signal/Group/index.js +12 -0
  13. package/lib/Signal/Group/keyhelper.js +19 -0
  14. package/lib/Signal/Group/queue-job.js +54 -0
  15. package/lib/Signal/Group/sender-chain-key.js +32 -0
  16. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  17. package/lib/Signal/Group/sender-key-message.js +67 -0
  18. package/lib/Signal/Group/sender-key-name.js +48 -0
  19. package/lib/Signal/Group/sender-key-record.js +50 -0
  20. package/lib/Signal/Group/sender-key-state.js +96 -0
  21. package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +4 -16
  22. package/lib/Signal/libsignal.js +41 -61
  23. package/lib/Socket/Client/index.js +3 -19
  24. package/lib/Socket/Client/types.js +11 -0
  25. package/lib/Socket/Client/websocket.js +50 -0
  26. package/lib/Socket/business.js +37 -42
  27. package/lib/Socket/chats.js +194 -187
  28. package/lib/Socket/communities.js +351 -0
  29. package/lib/Socket/groups.js +87 -90
  30. package/lib/Socket/index.js +7 -8
  31. package/lib/Socket/messages-recv.js +360 -335
  32. package/lib/Socket/messages-send.js +156 -279
  33. package/lib/Socket/mex.js +42 -0
  34. package/lib/Socket/newsletter.js +144 -213
  35. package/lib/Socket/socket.js +128 -161
  36. package/lib/Socket/usync.js +19 -26
  37. package/lib/Types/Auth.js +2 -2
  38. package/lib/Types/Call.js +2 -2
  39. package/lib/Types/Chat.js +8 -4
  40. package/lib/Types/Contact.js +2 -2
  41. package/lib/Types/Events.js +2 -2
  42. package/lib/Types/GroupMetadata.js +2 -2
  43. package/lib/Types/Label.js +3 -5
  44. package/lib/Types/LabelAssociation.js +3 -5
  45. package/lib/Types/Message.js +7 -7
  46. package/lib/Types/Newsletter.js +30 -17
  47. package/lib/Types/Product.js +2 -2
  48. package/lib/Types/Signal.js +2 -2
  49. package/lib/Types/Socket.js +3 -2
  50. package/lib/Types/State.js +2 -2
  51. package/lib/Types/USync.js +2 -2
  52. package/lib/Types/index.js +15 -31
  53. package/lib/Utils/auth-utils.js +31 -47
  54. package/lib/Utils/baileys-event-stream.js +15 -22
  55. package/lib/Utils/business.js +66 -69
  56. package/lib/Utils/chat-utils.js +200 -195
  57. package/lib/Utils/crypto.js +70 -85
  58. package/lib/Utils/decode-wa-message.js +47 -51
  59. package/lib/Utils/event-buffer.js +36 -46
  60. package/lib/Utils/generics.js +116 -188
  61. package/lib/Utils/history.js +37 -46
  62. package/lib/Utils/index.js +19 -33
  63. package/lib/Utils/link-preview.js +14 -55
  64. package/lib/Utils/logger.js +3 -7
  65. package/lib/Utils/lt-hash.js +23 -26
  66. package/lib/{Store → Utils}/make-in-memory-store.js +19 -27
  67. package/lib/Utils/make-mutex.js +7 -10
  68. package/lib/{Store → Utils}/make-ordered-dictionary.js +1 -3
  69. package/lib/Utils/messages-media.js +236 -368
  70. package/lib/Utils/messages.js +278 -510
  71. package/lib/Utils/noise-handler.js +22 -31
  72. package/lib/{Store → Utils}/object-repository.js +1 -4
  73. package/lib/Utils/process-message.js +144 -148
  74. package/lib/Utils/signal.js +71 -64
  75. package/lib/Utils/use-multi-file-auth-state.js +112 -84
  76. package/lib/Utils/validate-connection.js +72 -115
  77. package/lib/WABinary/constants.js +1281 -20
  78. package/lib/WABinary/decode.js +15 -52
  79. package/lib/WABinary/encode.js +14 -48
  80. package/lib/WABinary/generic-utils.js +31 -39
  81. package/lib/WABinary/index.js +6 -21
  82. package/lib/WABinary/jid-utils.js +23 -40
  83. package/lib/WABinary/types.js +2 -2
  84. package/lib/WAM/BinaryInfo.js +2 -5
  85. package/lib/WAM/constants.js +2257 -2366
  86. package/lib/WAM/encode.js +17 -21
  87. package/lib/WAM/index.js +4 -19
  88. package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -11
  89. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
  90. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
  91. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
  92. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
  93. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -6
  94. package/lib/WAUSync/Protocols/index.js +5 -20
  95. package/lib/WAUSync/USyncQuery.js +34 -32
  96. package/lib/WAUSync/USyncUser.js +2 -5
  97. package/lib/WAUSync/index.js +4 -19
  98. package/lib/index.js +11 -33
  99. package/package.json +25 -54
  100. package/WASignalGroup/GroupProtocol.js +0 -1697
  101. package/WASignalGroup/ciphertext_message.js +0 -16
  102. package/WASignalGroup/group_cipher.js +0 -120
  103. package/WASignalGroup/group_session_builder.js +0 -46
  104. package/WASignalGroup/index.js +0 -5
  105. package/WASignalGroup/keyhelper.js +0 -21
  106. package/WASignalGroup/protobufs.js +0 -3
  107. package/WASignalGroup/queue_job.js +0 -69
  108. package/WASignalGroup/sender_chain_key.js +0 -50
  109. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  110. package/WASignalGroup/sender_key_message.js +0 -92
  111. package/WASignalGroup/sender_key_name.js +0 -70
  112. package/WASignalGroup/sender_key_record.js +0 -56
  113. package/WASignalGroup/sender_key_state.js +0 -129
  114. package/lib/Defaults/baileys-version.json +0 -3
  115. package/lib/Defaults/phonenumber-mcc.json +0 -223
  116. package/lib/Socket/Client/abstract-socket-client.js +0 -13
  117. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  118. package/lib/Socket/Client/web-socket-client.js +0 -62
  119. package/lib/Socket/registration.js +0 -166
  120. package/lib/Store/index.js +0 -8
  121. package/lib/Store/make-cache-manager-store.js +0 -83
  122. package/lib/Store/make-mongo-store.js +0 -567
package/lib/WAM/encode.js CHANGED
@@ -1,25 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeWAM = void 0;
4
- const constants_1 = require("./constants");
1
+ import { BinaryInfo } from './BinaryInfo.js';
2
+ import { FLAG_BYTE, FLAG_EVENT, FLAG_EXTENDED, FLAG_FIELD, FLAG_GLOBAL, WEB_EVENTS, WEB_GLOBALS } from './constants.js';
5
3
  const getHeaderBitLength = (key) => (key < 256 ? 2 : 3);
6
- const encodeWAM = (binaryInfo) => {
4
+ export const encodeWAM = (binaryInfo) => {
7
5
  binaryInfo.buffer = [];
8
6
  encodeWAMHeader(binaryInfo);
9
7
  encodeEvents(binaryInfo);
10
8
  console.log(binaryInfo.buffer);
11
- const totalSize = binaryInfo.buffer
12
- .map((a) => a.length)
13
- .reduce((a, b) => a + b);
9
+ const totalSize = binaryInfo.buffer.map(a => a.length).reduce((a, b) => a + b);
14
10
  const buffer = Buffer.alloc(totalSize);
15
11
  let offset = 0;
16
- binaryInfo.buffer.forEach((buffer_) => {
12
+ for (const buffer_ of binaryInfo.buffer) {
17
13
  buffer_.copy(buffer, offset);
18
14
  offset += buffer_.length;
19
- });
15
+ }
20
16
  return buffer;
21
17
  };
22
- exports.encodeWAM = encodeWAM;
23
18
  function encodeWAMHeader(binaryInfo) {
24
19
  const headerBuffer = Buffer.alloc(8); // starting buffer
25
20
  headerBuffer.write('WAM', 0, 'utf8');
@@ -31,34 +26,34 @@ function encodeWAMHeader(binaryInfo) {
31
26
  }
32
27
  function encodeGlobalAttributes(binaryInfo, globals) {
33
28
  for (const [key, _value] of Object.entries(globals)) {
34
- const id = constants_1.WEB_GLOBALS.find(a => (a === null || a === void 0 ? void 0 : a.name) === key).id;
29
+ const id = WEB_GLOBALS.find(a => a?.name === key).id;
35
30
  let value = _value;
36
31
  if (typeof value === 'boolean') {
37
32
  value = value ? 1 : 0;
38
33
  }
39
- binaryInfo.buffer.push(serializeData(id, value, constants_1.FLAG_GLOBAL));
34
+ binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL));
40
35
  }
41
36
  }
42
37
  function encodeEvents(binaryInfo) {
43
- for (const [name, { props, globals },] of binaryInfo.events.map((a) => Object.entries(a)[0])) {
38
+ for (const [name, { props, globals }] of binaryInfo.events.map(a => Object.entries(a)[0])) {
44
39
  encodeGlobalAttributes(binaryInfo, globals);
45
- const event = constants_1.WEB_EVENTS.find((a) => a.name === name);
40
+ const event = WEB_EVENTS.find(a => a.name === name);
46
41
  const props_ = Object.entries(props);
47
42
  let extended = false;
48
43
  for (const [, value] of props_) {
49
44
  extended || (extended = value !== null);
50
45
  }
51
- const eventFlag = extended ? constants_1.FLAG_EVENT : constants_1.FLAG_EVENT | constants_1.FLAG_EXTENDED;
46
+ const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED;
52
47
  binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag));
53
48
  for (let i = 0; i < props_.length; i++) {
54
49
  const [key, _value] = props_[i];
55
- const id = (event.props)[key][0];
56
- extended = i < (props_.length - 1);
50
+ const id = event.props[key]?.[0];
51
+ extended = i < props_.length - 1;
57
52
  let value = _value;
58
53
  if (typeof value === 'boolean') {
59
54
  value = value ? 1 : 0;
60
55
  }
61
- const fieldFlag = extended ? constants_1.FLAG_EVENT : constants_1.FLAG_FIELD | constants_1.FLAG_EXTENDED;
56
+ const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED;
62
57
  binaryInfo.buffer.push(serializeData(id, value, fieldFlag));
63
58
  }
64
59
  }
@@ -68,7 +63,7 @@ function serializeData(key, value, flag) {
68
63
  let buffer;
69
64
  let offset = 0;
70
65
  if (value === null) {
71
- if (flag === constants_1.FLAG_GLOBAL) {
66
+ if (flag === FLAG_GLOBAL) {
72
67
  buffer = Buffer.alloc(bufferLength);
73
68
  offset = serializeHeader(buffer, offset, key, flag);
74
69
  return buffer;
@@ -146,10 +141,11 @@ function serializeHeader(buffer, offset, key, flag) {
146
141
  offset += 1;
147
142
  }
148
143
  else {
149
- buffer.writeUInt8(flag | constants_1.FLAG_BYTE, offset);
144
+ buffer.writeUInt8(flag | FLAG_BYTE, offset);
150
145
  offset += 1;
151
146
  buffer.writeUInt16LE(key, offset);
152
147
  offset += 2;
153
148
  }
154
149
  return offset;
155
150
  }
151
+ //# sourceMappingURL=encode.js.map
package/lib/WAM/index.js CHANGED
@@ -1,19 +1,4 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./constants"), exports);
18
- __exportStar(require("./encode"), exports);
19
- __exportStar(require("./BinaryInfo"), exports);
1
+ export * from './constants.js';
2
+ export * from './encode.js';
3
+ export * from './BinaryInfo.js';
4
+ //# sourceMappingURL=index.js.map
@@ -1,15 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.USyncContactProtocol = void 0;
4
- const WABinary_1 = require("../../WABinary");
5
- class USyncContactProtocol {
1
+ import { assertNodeErrorFree } from '../../WABinary/index.js';
2
+ import { USyncUser } from '../USyncUser.js';
3
+ export class USyncContactProtocol {
6
4
  constructor() {
7
5
  this.name = 'contact';
8
6
  }
9
7
  getQueryElement() {
10
8
  return {
11
9
  tag: 'contact',
12
- attrs: {},
10
+ attrs: {}
13
11
  };
14
12
  }
15
13
  getUserElement(user) {
@@ -17,16 +15,15 @@ class USyncContactProtocol {
17
15
  return {
18
16
  tag: 'contact',
19
17
  attrs: {},
20
- content: user.phone,
18
+ content: user.phone
21
19
  };
22
20
  }
23
21
  parser(node) {
24
- var _a;
25
22
  if (node.tag === 'contact') {
26
- (0, WABinary_1.assertNodeErrorFree)(node);
27
- return ((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.type) === 'in';
23
+ assertNodeErrorFree(node);
24
+ return node?.attrs?.type === 'in';
28
25
  }
29
26
  return false;
30
27
  }
31
28
  }
32
- exports.USyncContactProtocol = USyncContactProtocol;
29
+ //# sourceMappingURL=USyncContactProtocol.js.map
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.USyncDeviceProtocol = void 0;
4
- const WABinary_1 = require("../../WABinary");
5
- class USyncDeviceProtocol {
1
+ import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js';
2
+ export class USyncDeviceProtocol {
6
3
  constructor() {
7
4
  this.name = 'devices';
8
5
  }
@@ -10,8 +7,8 @@ class USyncDeviceProtocol {
10
7
  return {
11
8
  tag: 'devices',
12
9
  attrs: {
13
- version: '2',
14
- },
10
+ version: '2'
11
+ }
15
12
  };
16
13
  }
17
14
  getUserElement( /* user: USyncUser */) {
@@ -24,10 +21,10 @@ class USyncDeviceProtocol {
24
21
  const deviceList = [];
25
22
  let keyIndex = undefined;
26
23
  if (node.tag === 'devices') {
27
- (0, WABinary_1.assertNodeErrorFree)(node);
28
- const deviceListNode = (0, WABinary_1.getBinaryNodeChild)(node, 'device-list');
29
- const keyIndexNode = (0, WABinary_1.getBinaryNodeChild)(node, 'key-index-list');
30
- if (Array.isArray(deviceListNode === null || deviceListNode === void 0 ? void 0 : deviceListNode.content)) {
24
+ assertNodeErrorFree(node);
25
+ const deviceListNode = getBinaryNodeChild(node, 'device-list');
26
+ const keyIndexNode = getBinaryNodeChild(node, 'key-index-list');
27
+ if (Array.isArray(deviceListNode?.content)) {
31
28
  for (const { tag, attrs } of deviceListNode.content) {
32
29
  const id = +attrs.id;
33
30
  const keyIndex = +attrs['key-index'];
@@ -40,10 +37,10 @@ class USyncDeviceProtocol {
40
37
  }
41
38
  }
42
39
  }
43
- if ((keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.tag) === 'key-index-list') {
40
+ if (keyIndexNode?.tag === 'key-index-list') {
44
41
  keyIndex = {
45
42
  timestamp: +keyIndexNode.attrs['ts'],
46
- signedKeyIndex: keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.content,
43
+ signedKeyIndex: keyIndexNode?.content,
47
44
  expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
48
45
  };
49
46
  }
@@ -54,4 +51,4 @@ class USyncDeviceProtocol {
54
51
  };
55
52
  }
56
53
  }
57
- exports.USyncDeviceProtocol = USyncDeviceProtocol;
54
+ //# sourceMappingURL=USyncDeviceProtocol.js.map
@@ -1,30 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.USyncDisappearingModeProtocol = void 0;
4
- const WABinary_1 = require("../../WABinary");
5
- class USyncDisappearingModeProtocol {
1
+ import { assertNodeErrorFree } from '../../WABinary/index.js';
2
+ export class USyncDisappearingModeProtocol {
6
3
  constructor() {
7
4
  this.name = 'disappearing_mode';
8
5
  }
9
6
  getQueryElement() {
10
7
  return {
11
8
  tag: 'disappearing_mode',
12
- attrs: {},
9
+ attrs: {}
13
10
  };
14
11
  }
15
12
  getUserElement() {
16
13
  return null;
17
14
  }
18
15
  parser(node) {
19
- if (node.tag === 'status') {
20
- (0, WABinary_1.assertNodeErrorFree)(node);
21
- const duration = +(node === null || node === void 0 ? void 0 : node.attrs.duration);
22
- const setAt = new Date(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
16
+ if (node.tag === 'disappearing_mode') {
17
+ assertNodeErrorFree(node);
18
+ const duration = +node?.attrs.duration;
19
+ const setAt = new Date(+(node?.attrs.t || 0) * 1000);
23
20
  return {
24
21
  duration,
25
- setAt,
22
+ setAt
26
23
  };
27
24
  }
28
25
  }
29
26
  }
30
- exports.USyncDisappearingModeProtocol = USyncDisappearingModeProtocol;
27
+ //# sourceMappingURL=USyncDisappearingModeProtocol.js.map
@@ -1,28 +1,24 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.USyncStatusProtocol = void 0;
4
- const WABinary_1 = require("../../WABinary");
5
- class USyncStatusProtocol {
1
+ import { assertNodeErrorFree } from '../../WABinary/index.js';
2
+ export class USyncStatusProtocol {
6
3
  constructor() {
7
4
  this.name = 'status';
8
5
  }
9
6
  getQueryElement() {
10
7
  return {
11
8
  tag: 'status',
12
- attrs: {},
9
+ attrs: {}
13
10
  };
14
11
  }
15
12
  getUserElement() {
16
13
  return null;
17
14
  }
18
15
  parser(node) {
19
- var _a;
20
16
  if (node.tag === 'status') {
21
- (0, WABinary_1.assertNodeErrorFree)(node);
22
- let status = node === null || node === void 0 ? void 0 : node.content.toString();
23
- const setAt = new Date(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
17
+ assertNodeErrorFree(node);
18
+ let status = node?.content?.toString() ?? null;
19
+ const setAt = new Date(+(node?.attrs.t || 0) * 1000);
24
20
  if (!status) {
25
- if (+((_a = node.attrs) === null || _a === void 0 ? void 0 : _a.code) === 401) {
21
+ if (node.attrs?.code && +node.attrs.code === 401) {
26
22
  status = '';
27
23
  }
28
24
  else {
@@ -34,9 +30,9 @@ class USyncStatusProtocol {
34
30
  }
35
31
  return {
36
32
  status,
37
- setAt,
33
+ setAt
38
34
  };
39
35
  }
40
36
  }
41
37
  }
42
- exports.USyncStatusProtocol = USyncStatusProtocol;
38
+ //# sourceMappingURL=USyncStatusProtocol.js.map
@@ -1,8 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.USyncBotProfileProtocol = void 0;
4
- const WABinary_1 = require("../../WABinary");
5
- class USyncBotProfileProtocol {
1
+ import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString } from '../../WABinary/index.js';
2
+ import { USyncUser } from '../USyncUser.js';
3
+ export class USyncBotProfileProtocol {
6
4
  constructor() {
7
5
  this.name = 'bot';
8
6
  }
@@ -17,37 +15,37 @@ class USyncBotProfileProtocol {
17
15
  return {
18
16
  tag: 'bot',
19
17
  attrs: {},
20
- content: [{ tag: 'profile', attrs: { 'persona_id': user.personaId } }]
18
+ content: [{ tag: 'profile', attrs: { persona_id: user.personaId } }]
21
19
  };
22
20
  }
23
21
  parser(node) {
24
- const botNode = (0, WABinary_1.getBinaryNodeChild)(node, 'bot');
25
- const profile = (0, WABinary_1.getBinaryNodeChild)(botNode, 'profile');
26
- const commandsNode = (0, WABinary_1.getBinaryNodeChild)(profile, 'commands');
27
- const promptsNode = (0, WABinary_1.getBinaryNodeChild)(profile, 'prompts');
22
+ const botNode = getBinaryNodeChild(node, 'bot');
23
+ const profile = getBinaryNodeChild(botNode, 'profile');
24
+ const commandsNode = getBinaryNodeChild(profile, 'commands');
25
+ const promptsNode = getBinaryNodeChild(profile, 'prompts');
28
26
  const commands = [];
29
27
  const prompts = [];
30
- for (const command of (0, WABinary_1.getBinaryNodeChildren)(commandsNode, 'command')) {
28
+ for (const command of getBinaryNodeChildren(commandsNode, 'command')) {
31
29
  commands.push({
32
- name: (0, WABinary_1.getBinaryNodeChildString)(command, 'name'),
33
- description: (0, WABinary_1.getBinaryNodeChildString)(command, 'description')
30
+ name: getBinaryNodeChildString(command, 'name'),
31
+ description: getBinaryNodeChildString(command, 'description')
34
32
  });
35
33
  }
36
- for (const prompt of (0, WABinary_1.getBinaryNodeChildren)(promptsNode, 'prompt')) {
37
- prompts.push(`${(0, WABinary_1.getBinaryNodeChildString)(prompt, 'emoji')} ${(0, WABinary_1.getBinaryNodeChildString)(prompt, 'text')}`);
34
+ for (const prompt of getBinaryNodeChildren(promptsNode, 'prompt')) {
35
+ prompts.push(`${getBinaryNodeChildString(prompt, 'emoji')} ${getBinaryNodeChildString(prompt, 'text')}`);
38
36
  }
39
37
  return {
40
- isDefault: !!(0, WABinary_1.getBinaryNodeChild)(profile, 'default'),
38
+ isDefault: !!getBinaryNodeChild(profile, 'default'),
41
39
  jid: node.attrs.jid,
42
- name: (0, WABinary_1.getBinaryNodeChildString)(profile, 'name'),
43
- attributes: (0, WABinary_1.getBinaryNodeChildString)(profile, 'attributes'),
44
- description: (0, WABinary_1.getBinaryNodeChildString)(profile, 'description'),
45
- category: (0, WABinary_1.getBinaryNodeChildString)(profile, 'category'),
40
+ name: getBinaryNodeChildString(profile, 'name'),
41
+ attributes: getBinaryNodeChildString(profile, 'attributes'),
42
+ description: getBinaryNodeChildString(profile, 'description'),
43
+ category: getBinaryNodeChildString(profile, 'category'),
46
44
  personaId: profile.attrs['persona_id'],
47
- commandsDescription: (0, WABinary_1.getBinaryNodeChildString)(commandsNode, 'description'),
45
+ commandsDescription: getBinaryNodeChildString(commandsNode, 'description'),
48
46
  commands,
49
47
  prompts
50
48
  };
51
49
  }
52
50
  }
53
- exports.USyncBotProfileProtocol = USyncBotProfileProtocol;
51
+ //# sourceMappingURL=UsyncBotProfileProtocol.js.map
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.USyncLIDProtocol = void 0;
4
- class USyncLIDProtocol {
1
+ export class USyncLIDProtocol {
5
2
  constructor() {
6
3
  this.name = 'lid';
7
4
  }
8
5
  getQueryElement() {
9
6
  return {
10
7
  tag: 'lid',
11
- attrs: {},
8
+ attrs: {}
12
9
  };
13
10
  }
14
11
  getUserElement() {
@@ -21,4 +18,4 @@ class USyncLIDProtocol {
21
18
  return null;
22
19
  }
23
20
  }
24
- exports.USyncLIDProtocol = USyncLIDProtocol;
21
+ //# sourceMappingURL=UsyncLIDProtocol.js.map
@@ -1,20 +1,5 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./USyncDeviceProtocol"), exports);
18
- __exportStar(require("./USyncContactProtocol"), exports);
19
- __exportStar(require("./USyncStatusProtocol"), exports);
20
- __exportStar(require("./USyncDisappearingModeProtocol"), exports);
1
+ export * from './USyncDeviceProtocol.js';
2
+ export * from './USyncContactProtocol.js';
3
+ export * from './USyncStatusProtocol.js';
4
+ export * from './USyncDisappearingModeProtocol.js';
5
+ //# sourceMappingURL=index.js.map
@@ -1,11 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.USyncQuery = void 0;
4
- const WABinary_1 = require("../WABinary");
5
- const UsyncBotProfileProtocol_1 = require("./Protocols/UsyncBotProfileProtocol");
6
- const UsyncLIDProtocol_1 = require("./Protocols/UsyncLIDProtocol");
7
- const Protocols_1 = require("./Protocols");
8
- class USyncQuery {
1
+ import { getBinaryNodeChild } from '../WABinary/index.js';
2
+ import { USyncBotProfileProtocol } from './Protocols/UsyncBotProfileProtocol.js';
3
+ import { USyncLIDProtocol } from './Protocols/UsyncLIDProtocol.js';
4
+ import { USyncContactProtocol, USyncDeviceProtocol, USyncDisappearingModeProtocol, USyncStatusProtocol } from './Protocols/index.js';
5
+ import { USyncUser } from './USyncUser.js';
6
+ export class USyncQuery {
9
7
  constructor() {
10
8
  this.protocols = [];
11
9
  this.users = [];
@@ -28,32 +26,36 @@ class USyncQuery {
28
26
  if (result.attrs.type !== 'result') {
29
27
  return;
30
28
  }
31
- const protocolMap = Object.fromEntries(this.protocols.map((protocol) => {
29
+ const protocolMap = Object.fromEntries(this.protocols.map(protocol => {
32
30
  return [protocol.name, protocol.parser];
33
31
  }));
34
32
  const queryResult = {
35
33
  // TODO: implement errors etc.
36
34
  list: [],
37
- sideList: [],
35
+ sideList: []
38
36
  };
39
- const usyncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'usync');
37
+ const usyncNode = getBinaryNodeChild(result, 'usync');
40
38
  //TODO: implement error backoff, refresh etc.
41
39
  //TODO: see if there are any errors in the result node
42
40
  //const resultNode = getBinaryNodeChild(usyncNode, 'result')
43
- const listNode = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list');
44
- if (Array.isArray(listNode === null || listNode === void 0 ? void 0 : listNode.content) && typeof listNode !== 'undefined') {
45
- queryResult.list = listNode.content.map((node) => {
46
- const id = node === null || node === void 0 ? void 0 : node.attrs.jid;
47
- const data = Array.isArray(node === null || node === void 0 ? void 0 : node.content) ? Object.fromEntries(node.content.map((content) => {
48
- const protocol = content.tag;
49
- const parser = protocolMap[protocol];
50
- if (parser) {
51
- return [protocol, parser(content)];
52
- }
53
- else {
54
- return [protocol, null];
55
- }
56
- }).filter(([, b]) => b !== null)) : {};
41
+ const listNode = getBinaryNodeChild(usyncNode, 'list');
42
+ if (Array.isArray(listNode?.content) && typeof listNode !== 'undefined') {
43
+ queryResult.list = listNode.content.map(node => {
44
+ const id = node?.attrs.jid;
45
+ const data = Array.isArray(node?.content)
46
+ ? Object.fromEntries(node.content
47
+ .map(content => {
48
+ const protocol = content.tag;
49
+ const parser = protocolMap[protocol];
50
+ if (parser) {
51
+ return [protocol, parser(content)];
52
+ }
53
+ else {
54
+ return [protocol, null];
55
+ }
56
+ })
57
+ .filter(([, b]) => b !== null))
58
+ : {};
57
59
  return { ...data, id };
58
60
  });
59
61
  }
@@ -62,28 +64,28 @@ class USyncQuery {
62
64
  return queryResult;
63
65
  }
64
66
  withDeviceProtocol() {
65
- this.protocols.push(new Protocols_1.USyncDeviceProtocol());
67
+ this.protocols.push(new USyncDeviceProtocol());
66
68
  return this;
67
69
  }
68
70
  withContactProtocol() {
69
- this.protocols.push(new Protocols_1.USyncContactProtocol());
71
+ this.protocols.push(new USyncContactProtocol());
70
72
  return this;
71
73
  }
72
74
  withStatusProtocol() {
73
- this.protocols.push(new Protocols_1.USyncStatusProtocol());
75
+ this.protocols.push(new USyncStatusProtocol());
74
76
  return this;
75
77
  }
76
78
  withDisappearingModeProtocol() {
77
- this.protocols.push(new Protocols_1.USyncDisappearingModeProtocol());
79
+ this.protocols.push(new USyncDisappearingModeProtocol());
78
80
  return this;
79
81
  }
80
82
  withBotProfileProtocol() {
81
- this.protocols.push(new UsyncBotProfileProtocol_1.USyncBotProfileProtocol());
83
+ this.protocols.push(new USyncBotProfileProtocol());
82
84
  return this;
83
85
  }
84
86
  withLIDProtocol() {
85
- this.protocols.push(new UsyncLIDProtocol_1.USyncLIDProtocol());
87
+ this.protocols.push(new USyncLIDProtocol());
86
88
  return this;
87
89
  }
88
90
  }
89
- exports.USyncQuery = USyncQuery;
91
+ //# sourceMappingURL=USyncQuery.js.map
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.USyncUser = void 0;
4
- class USyncUser {
1
+ export class USyncUser {
5
2
  withId(id) {
6
3
  this.id = id;
7
4
  return this;
@@ -23,4 +20,4 @@ class USyncUser {
23
20
  return this;
24
21
  }
25
22
  }
26
- exports.USyncUser = USyncUser;
23
+ //# sourceMappingURL=USyncUser.js.map
@@ -1,19 +1,4 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Protocols"), exports);
18
- __exportStar(require("./USyncQuery"), exports);
19
- __exportStar(require("./USyncUser"), exports);
1
+ export * from './Protocols/index.js';
2
+ export * from './USyncQuery.js';
3
+ export * from './USyncUser.js';
4
+ //# sourceMappingURL=index.js.map
package/lib/index.js CHANGED
@@ -1,33 +1,11 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.proto = exports.makeWASocket = void 0;
21
- const WAProto_1 = require("../WAProto");
22
- Object.defineProperty(exports, "proto", { enumerable: true, get: function () { return WAProto_1.proto; } });
23
- const Socket_1 = __importDefault(require("./Socket"));
24
- exports.makeWASocket = Socket_1.default;
25
- __exportStar(require("../WAProto"), exports);
26
- __exportStar(require("./Utils"), exports);
27
- __exportStar(require("./Types"), exports);
28
- __exportStar(require("./Store"), exports);
29
- __exportStar(require("./Defaults"), exports);
30
- __exportStar(require("./WABinary"), exports);
31
- __exportStar(require("./WAM"), exports);
32
- __exportStar(require("./WAUSync"), exports);
33
- exports.default = Socket_1.default;
1
+ import makeWASocket from './Socket/index.js';
2
+ export * from '../WAProto/index.js';
3
+ export * from './Utils/index.js';
4
+ export * from './Types/index.js';
5
+ export * from './Defaults/index.js';
6
+ export * from './WABinary/index.js';
7
+ export * from './WAM/index.js';
8
+ export * from './WAUSync/index.js';
9
+ export { makeWASocket };
10
+ export default makeWASocket;
11
+ //# sourceMappingURL=index.js.map