@hansaka02/baileys 7.3.2 → 7.3.6

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 (210) hide show
  1. package/lib/Defaults/baileys-version.json +2 -2
  2. package/lib/Defaults/connection.js +51 -0
  3. package/lib/Defaults/constants.js +74 -0
  4. package/lib/Defaults/history.js +19 -0
  5. package/lib/Defaults/index.js +36 -142
  6. package/lib/Defaults/media.js +48 -0
  7. package/lib/Defaults/prefix.js +18 -0
  8. package/lib/Signal/Group/group-session-builder.js +10 -42
  9. package/lib/Signal/Group/group_cipher.js +9 -6
  10. package/lib/Signal/Group/index.js +39 -53
  11. package/lib/Signal/Group/keyhelper.js +8 -41
  12. package/lib/Signal/Group/sender-chain-key.js +5 -18
  13. package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
  14. package/lib/Signal/Group/sender-key-message.js +12 -8
  15. package/lib/Signal/Group/sender-key-record.js +7 -16
  16. package/lib/Signal/Group/sender-key-state.js +15 -61
  17. package/lib/Signal/Group/sender-message-key.js +2 -2
  18. package/lib/Signal/libsignal.js +237 -177
  19. package/lib/Signal/lid-mapping.js +128 -71
  20. package/lib/Socket/Client/types.js +2 -2
  21. package/lib/Socket/Client/websocket.js +25 -16
  22. package/lib/Socket/business.js +46 -33
  23. package/lib/Socket/chats.js +286 -170
  24. package/lib/Socket/community.js +215 -77
  25. package/lib/Socket/groups.js +77 -61
  26. package/lib/Socket/index.js +4 -4
  27. package/lib/Socket/messages-recv.js +629 -457
  28. package/lib/Socket/messages-send.js +645 -656
  29. package/lib/Socket/mex.js +61 -0
  30. package/lib/Socket/newsletter.js +166 -245
  31. package/lib/Socket/socket.js +396 -170
  32. package/lib/Store/index.js +27 -11
  33. package/lib/Store/make-cache-manager-store.js +14 -15
  34. package/lib/Store/make-in-memory-store.js +28 -24
  35. package/lib/Types/LabelAssociation.js +2 -2
  36. package/lib/Types/Message.js +6 -6
  37. package/lib/Types/MexUpdates.js +5 -5
  38. package/lib/Types/Newsletter.js +32 -25
  39. package/lib/Types/State.js +4 -4
  40. package/lib/Types/index.js +28 -12
  41. package/lib/Utils/auth-utils.js +212 -375
  42. package/lib/Utils/baileys-event-stream.js +68 -69
  43. package/lib/Utils/browser-utils.js +43 -0
  44. package/lib/Utils/business.js +63 -53
  45. package/lib/Utils/chat-utils.js +241 -106
  46. package/lib/Utils/crypto.js +25 -45
  47. package/lib/Utils/decode-wa-message.js +361 -311
  48. package/lib/Utils/event-buffer.js +97 -42
  49. package/lib/Utils/generics.js +90 -207
  50. package/lib/Utils/history.js +29 -27
  51. package/lib/Utils/index.js +28 -14
  52. package/lib/Utils/link-preview.js +24 -62
  53. package/lib/Utils/logger.js +5 -5
  54. package/lib/Utils/lt-hash.js +29 -23
  55. package/lib/Utils/make-mutex.js +26 -28
  56. package/lib/Utils/message-retry-manager.js +55 -7
  57. package/lib/Utils/messages-media.js +434 -247
  58. package/lib/Utils/messages.js +963 -917
  59. package/lib/Utils/noise-handler.js +60 -20
  60. package/lib/Utils/pre-key-manager.js +126 -0
  61. package/lib/Utils/process-message.js +216 -141
  62. package/lib/Utils/signal.js +75 -37
  63. package/lib/Utils/use-multi-file-auth-state.js +18 -22
  64. package/lib/Utils/validate-connection.js +96 -66
  65. package/lib/WABinary/constants.js +1268 -1268
  66. package/lib/WABinary/decode.js +62 -34
  67. package/lib/WABinary/encode.js +57 -36
  68. package/lib/WABinary/generic-utils.js +4 -4
  69. package/lib/WABinary/index.js +27 -11
  70. package/lib/WABinary/jid-utils.js +58 -11
  71. package/lib/WAM/constants.js +19064 -11563
  72. package/lib/WAM/encode.js +71 -14
  73. package/lib/WAM/index.js +27 -11
  74. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
  75. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  76. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
  77. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  78. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
  79. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
  80. package/lib/WAUSync/Protocols/index.js +27 -11
  81. package/lib/WAUSync/USyncQuery.js +51 -28
  82. package/lib/WAUSync/index.js +27 -11
  83. package/lib/index.js +60 -31
  84. package/package.json +12 -17
  85. package/WAProto/AICommon/AICommon.d.ts +0 -11702
  86. package/WAProto/Adv/Adv.d.ts +0 -643
  87. package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
  88. package/WAProto/Cert/Cert.d.ts +0 -613
  89. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
  90. package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
  91. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
  92. package/WAProto/E2E/E2E.d.ts +0 -41724
  93. package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
  94. package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
  95. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
  96. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
  97. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
  98. package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
  99. package/WAProto/Protocol/Protocol.d.ts +0 -270
  100. package/WAProto/Reporting/Reporting.d.ts +0 -371
  101. package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
  102. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
  103. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
  104. package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
  105. package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
  106. package/WAProto/UserPassword/UserPassword.d.ts +0 -363
  107. package/WAProto/VnameCert/VnameCert.d.ts +0 -821
  108. package/WAProto/Wa6/Wa6.d.ts +0 -2128
  109. package/WAProto/Web/Web.d.ts +0 -46383
  110. package/WAProto/index.d.ts +0 -55
  111. package/lib/Defaults/index.d.ts +0 -77
  112. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  113. package/lib/Signal/Group/group-session-builder.d.ts +0 -17
  114. package/lib/Signal/Group/group_cipher.d.ts +0 -19
  115. package/lib/Signal/Group/index.d.ts +0 -11
  116. package/lib/Signal/Group/keyhelper.d.ts +0 -16
  117. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  118. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  119. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  120. package/lib/Signal/Group/sender-key-name.d.ts +0 -19
  121. package/lib/Signal/Group/sender-key-record.d.ts +0 -32
  122. package/lib/Signal/Group/sender-key-state.d.ts +0 -44
  123. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  124. package/lib/Signal/libsignal.d.ts +0 -8
  125. package/lib/Signal/lid-mapping.d.ts +0 -28
  126. package/lib/Socket/Client/index.d.ts +0 -2
  127. package/lib/Socket/Client/types.d.ts +0 -16
  128. package/lib/Socket/Client/websocket.d.ts +0 -13
  129. package/lib/Socket/business.d.ts +0 -187
  130. package/lib/Socket/chats.d.ts +0 -97
  131. package/lib/Socket/community.d.ts +0 -129
  132. package/lib/Socket/groups.d.ts +0 -129
  133. package/lib/Socket/index.d.ts +0 -191
  134. package/lib/Socket/messages-recv.d.ts +0 -174
  135. package/lib/Socket/messages-send.d.ts +0 -165
  136. package/lib/Socket/newsletter.d.ts +0 -145
  137. package/lib/Socket/socket.d.ts +0 -45
  138. package/lib/Socket/usync.d.ts +0 -37
  139. package/lib/Socket/usync.js +0 -83
  140. package/lib/Store/index.d.ts +0 -4
  141. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  142. package/lib/Store/make-in-memory-store.d.ts +0 -123
  143. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  144. package/lib/Store/object-repository.d.ts +0 -10
  145. package/lib/Types/Auth.d.ts +0 -121
  146. package/lib/Types/Bussiness.d.ts +0 -28
  147. package/lib/Types/Call.d.ts +0 -14
  148. package/lib/Types/Chat.d.ts +0 -143
  149. package/lib/Types/Contact.d.ts +0 -23
  150. package/lib/Types/Events.d.ts +0 -226
  151. package/lib/Types/GroupMetadata.d.ts +0 -66
  152. package/lib/Types/Label.d.ts +0 -48
  153. package/lib/Types/LabelAssociation.d.ts +0 -35
  154. package/lib/Types/Message.d.ts +0 -484
  155. package/lib/Types/MexUpdates.d.ts +0 -9
  156. package/lib/Types/Newsletter.d.ts +0 -109
  157. package/lib/Types/Product.d.ts +0 -92
  158. package/lib/Types/Signal.d.ts +0 -98
  159. package/lib/Types/Socket.d.ts +0 -141
  160. package/lib/Types/State.d.ts +0 -41
  161. package/lib/Types/USync.d.ts +0 -26
  162. package/lib/Types/index.d.ts +0 -80
  163. package/lib/Utils/auth-utils.d.ts +0 -21
  164. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  165. package/lib/Utils/business.d.ts +0 -29
  166. package/lib/Utils/chat-utils.d.ts +0 -82
  167. package/lib/Utils/crypto.d.ts +0 -56
  168. package/lib/Utils/decode-wa-message.d.ts +0 -53
  169. package/lib/Utils/event-buffer.d.ts +0 -39
  170. package/lib/Utils/generics.d.ts +0 -117
  171. package/lib/Utils/history.d.ts +0 -23
  172. package/lib/Utils/index.d.ts +0 -20
  173. package/lib/Utils/link-preview.d.ts +0 -23
  174. package/lib/Utils/logger.d.ts +0 -13
  175. package/lib/Utils/lt-hash.d.ts +0 -14
  176. package/lib/Utils/make-mutex.d.ts +0 -9
  177. package/lib/Utils/message-retry-manager.d.ts +0 -88
  178. package/lib/Utils/messages-media.d.ts +0 -135
  179. package/lib/Utils/messages.d.ts +0 -105
  180. package/lib/Utils/noise-handler.d.ts +0 -20
  181. package/lib/Utils/process-message.d.ts +0 -49
  182. package/lib/Utils/signal.d.ts +0 -42
  183. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  184. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  185. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  186. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  187. package/lib/Utils/use-single-file-auth-state.js +0 -80
  188. package/lib/Utils/validate-connection.d.ts +0 -13
  189. package/lib/WABinary/constants.d.ts +0 -30
  190. package/lib/WABinary/decode.d.ts +0 -9
  191. package/lib/WABinary/encode.d.ts +0 -3
  192. package/lib/WABinary/generic-utils.d.ts +0 -28
  193. package/lib/WABinary/index.d.ts +0 -5
  194. package/lib/WABinary/jid-utils.d.ts +0 -58
  195. package/lib/WABinary/types.d.ts +0 -22
  196. package/lib/WAM/BinaryInfo.d.ts +0 -16
  197. package/lib/WAM/constants.d.ts +0 -47
  198. package/lib/WAM/encode.d.ts +0 -3
  199. package/lib/WAM/index.d.ts +0 -3
  200. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  201. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  202. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
  203. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
  204. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
  205. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
  206. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  207. package/lib/WAUSync/USyncQuery.d.ts +0 -31
  208. package/lib/WAUSync/USyncUser.d.ts +0 -12
  209. package/lib/WAUSync/index.d.ts +0 -3
  210. package/lib/index.d.ts +0 -13
package/lib/WAM/encode.js CHANGED
@@ -2,27 +2,38 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const constants_1 = require("./constants")
5
+ const {
6
+ FLAG_BYTE,
7
+ FLAG_EVENT,
8
+ FLAG_EXTENDED,
9
+ FLAG_FIELD,
10
+ FLAG_GLOBAL,
11
+ WEB_EVENTS,
12
+ WEB_GLOBALS
13
+ } = require("./constants")
6
14
  const getHeaderBitLength = (key) => (key < 256 ? 2 : 3)
7
15
 
8
16
  const encodeWAM = (binaryInfo) => {
9
17
  binaryInfo.buffer = []
10
18
  encodeWAMHeader(binaryInfo)
11
19
  encodeEvents(binaryInfo)
12
- const totalSize = binaryInfo.buffer
13
- .map((a) => a.length)
14
- .reduce((a, b) => a + b)
20
+
21
+ const totalSize = binaryInfo.buffer.map(a => a.length).reduce((a, b) => a + b)
15
22
  const buffer = Buffer.alloc(totalSize)
23
+
16
24
  let offset = 0
25
+
17
26
  for (const buffer_ of binaryInfo.buffer) {
18
27
  buffer_.copy(buffer, offset)
19
28
  offset += buffer_.length
20
29
  }
30
+
21
31
  return buffer
22
32
  }
23
33
 
24
34
  function encodeWAMHeader(binaryInfo) {
25
35
  const headerBuffer = Buffer.alloc(8) // starting buffer
36
+
26
37
  headerBuffer.write('WAM', 0, 'utf8')
27
38
  headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3)
28
39
  headerBuffer.writeUInt8(1, 4) //random flag
@@ -33,35 +44,49 @@ function encodeWAMHeader(binaryInfo) {
33
44
 
34
45
  function encodeGlobalAttributes(binaryInfo, globals) {
35
46
  for (const [key, _value] of Object.entries(globals)) {
36
- const id = constants_1.WEB_GLOBALS.find(a => a?.name === key)?.id
47
+ const id = WEB_GLOBALS.find(a => a?.name === key).id
48
+
37
49
  let value = _value
50
+
38
51
  if (typeof value === 'boolean') {
39
52
  value = value ? 1 : 0
40
53
  }
41
- binaryInfo.buffer.push(serializeData(id, value, constants_1.FLAG_GLOBAL))
54
+
55
+ binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL))
42
56
  }
43
57
  }
44
58
 
45
59
  function encodeEvents(binaryInfo) {
46
- for (const [name, { props, globals },] of binaryInfo.events.map((a) => Object.entries(a)[0])) {
60
+ for (const [name, { props, globals }] of binaryInfo.events.map(a => Object.entries(a)[0])) {
47
61
  encodeGlobalAttributes(binaryInfo, globals)
48
- const event = constants_1.WEB_EVENTS.find((a) => a.name === name)
62
+
63
+ const event = WEB_EVENTS.find(a => a.name === name)
49
64
  const props_ = Object.entries(props)
65
+
50
66
  let extended = false
67
+
51
68
  for (const [, value] of props_) {
52
69
  extended || (extended = value !== null)
53
70
  }
54
- const eventFlag = extended ? constants_1.FLAG_EVENT : constants_1.FLAG_EVENT | constants_1.FLAG_EXTENDED
71
+
72
+ const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED
73
+
55
74
  binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag))
75
+
56
76
  for (let i = 0; i < props_.length; i++) {
57
77
  const [key, _value] = props_[i]
58
- const id = (event.props)[key][0]
59
- extended = i < (props_.length - 1)
78
+ const id = event.props[key]?.[0]
79
+
80
+ extended = i < props_.length - 1
81
+
60
82
  let value = _value
83
+
61
84
  if (typeof value === 'boolean') {
62
85
  value = value ? 1 : 0
63
86
  }
64
- const fieldFlag = extended ? constants_1.FLAG_EVENT : constants_1.FLAG_FIELD | constants_1.FLAG_EXTENDED
87
+
88
+ const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED
89
+
65
90
  binaryInfo.buffer.push(serializeData(id, value, fieldFlag))
66
91
  }
67
92
  }
@@ -69,77 +94,107 @@ function encodeEvents(binaryInfo) {
69
94
 
70
95
  function serializeData(key, value, flag) {
71
96
  const bufferLength = getHeaderBitLength(key)
97
+
72
98
  let buffer
73
99
  let offset = 0
100
+
74
101
  if (value === null) {
75
- if (flag === constants_1.FLAG_GLOBAL) {
102
+ if (flag === FLAG_GLOBAL) {
76
103
  buffer = Buffer.alloc(bufferLength)
77
104
  offset = serializeHeader(buffer, offset, key, flag)
105
+
78
106
  return buffer
79
107
  }
80
108
  }
109
+
81
110
  else if (typeof value === 'number' && Number.isInteger(value)) {
82
111
  // is number
83
112
  if (value === 0 || value === 1) {
84
113
  buffer = Buffer.alloc(bufferLength)
85
114
  offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4))
115
+
86
116
  return buffer
87
117
  }
118
+
88
119
  else if (-128 <= value && value < 128) {
89
120
  buffer = Buffer.alloc(bufferLength + 1)
90
121
  offset = serializeHeader(buffer, offset, key, flag | (3 << 4))
122
+
91
123
  buffer.writeInt8(value, offset)
124
+
92
125
  return buffer
93
126
  }
127
+
94
128
  else if (-32768 <= value && value < 32768) {
95
129
  buffer = Buffer.alloc(bufferLength + 2)
96
130
  offset = serializeHeader(buffer, offset, key, flag | (4 << 4))
131
+
97
132
  buffer.writeInt16LE(value, offset)
133
+
98
134
  return buffer
99
135
  }
136
+
100
137
  else if (-2147483648 <= value && value < 2147483648) {
101
138
  buffer = Buffer.alloc(bufferLength + 4)
102
139
  offset = serializeHeader(buffer, offset, key, flag | (5 << 4))
140
+
103
141
  buffer.writeInt32LE(value, offset)
142
+
104
143
  return buffer
105
144
  }
145
+
106
146
  else {
107
147
  buffer = Buffer.alloc(bufferLength + 8)
108
148
  offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
149
+
109
150
  buffer.writeDoubleLE(value, offset)
151
+
110
152
  return buffer
111
153
  }
112
154
  }
155
+
113
156
  else if (typeof value === 'number') {
114
157
  // is float
115
158
  buffer = Buffer.alloc(bufferLength + 8)
116
159
  offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
160
+
117
161
  buffer.writeDoubleLE(value, offset)
162
+
118
163
  return buffer
119
164
  }
165
+
120
166
  else if (typeof value === 'string') {
121
167
  // is string
122
168
  const utf8Bytes = Buffer.byteLength(value, 'utf8')
169
+
123
170
  if (utf8Bytes < 256) {
124
171
  buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes)
125
172
  offset = serializeHeader(buffer, offset, key, flag | (8 << 4))
173
+
126
174
  buffer.writeUint8(utf8Bytes, offset++)
127
175
  }
176
+
128
177
  else if (utf8Bytes < 65536) {
129
178
  buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes)
130
179
  offset = serializeHeader(buffer, offset, key, flag | (9 << 4))
180
+
131
181
  buffer.writeUInt16LE(utf8Bytes, offset)
132
182
  offset += 2
133
183
  }
184
+
134
185
  else {
135
186
  buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes)
136
187
  offset = serializeHeader(buffer, offset, key, flag | (10 << 4))
188
+
137
189
  buffer.writeUInt32LE(utf8Bytes, offset)
138
190
  offset += 4
139
191
  }
192
+
140
193
  buffer.write(value, offset, 'utf8')
194
+
141
195
  return buffer
142
196
  }
197
+
143
198
  throw 'missing'
144
199
  }
145
200
 
@@ -150,12 +205,14 @@ function serializeHeader(buffer, offset, key, flag) {
150
205
  buffer.writeUInt8(key, offset)
151
206
  offset += 1
152
207
  }
208
+
153
209
  else {
154
- buffer.writeUInt8(flag | constants_1.FLAG_BYTE, offset)
210
+ buffer.writeUInt8(flag | FLAG_BYTE, offset)
155
211
  offset += 1
156
212
  buffer.writeUInt16LE(key, offset)
157
213
  offset += 2
158
214
  }
215
+
159
216
  return offset
160
217
  }
161
218
 
package/lib/WAM/index.js CHANGED
@@ -1,22 +1,38 @@
1
1
  "use strict"
2
2
 
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ const __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k
5
- var desc = Object.getOwnPropertyDescriptor(m, k)
5
+
6
+ let desc = Object.getOwnPropertyDescriptor(m, k)
7
+
6
8
  if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k] } }
9
+ desc = {
10
+ enumerable: true,
11
+ get: function() {
12
+ return m[k]
13
+ }
14
+ }
8
15
  }
9
- Object.defineProperty(o, k2, desc)
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k
12
- o[k2] = m[k]
13
- }))
14
16
 
15
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
17
+ Object.defineProperty(o, k2, desc)
18
+
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k
21
+ o[k2] = m[k]
22
+ }
23
+ ))
24
+
25
+ const __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) {
27
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
28
+ __createBinding(exports, m, p)
29
+ }
30
+ }
17
31
  }
18
32
 
19
- Object.defineProperty(exports, "__esModule", { value: true })
33
+ Object.defineProperty(exports, "__esModule", {
34
+ value: true
35
+ })
20
36
 
21
37
  __exportStar(require("./constants"), exports)
22
38
  __exportStar(require("./encode"), exports)
@@ -2,7 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const WABinary_1 = require("../../WABinary")
5
+ const {
6
+ getBinaryNodeChild,
7
+ getBinaryNodeChildren,
8
+ getBinaryNodeChildString
9
+ } = require("../../WABinary")
6
10
 
7
11
  class USyncBotProfileProtocol {
8
12
  constructor() {
@@ -23,41 +27,41 @@ class USyncBotProfileProtocol {
23
27
  }
24
28
  }
25
29
  parser(node) {
26
- const botNode = WABinary_1.getBinaryNodeChild(node, 'bot')
27
- const profile = WABinary_1.getBinaryNodeChild(botNode, 'profile')
30
+ const botNode = getBinaryNodeChild(node, 'bot')
31
+ const profile = getBinaryNodeChild(botNode, 'profile')
28
32
 
29
- const commandsNode = WABinary_1.getBinaryNodeChild(profile, 'commands')
30
- const promptsNode = WABinary_1.getBinaryNodeChild(profile, 'prompts')
33
+ const commandsNode = getBinaryNodeChild(profile, 'commands')
34
+ const promptsNode = getBinaryNodeChild(profile, 'prompts')
31
35
 
32
36
  const commands = []
33
37
  const prompts = []
34
38
 
35
39
  if (commandsNode) {
36
- for (const command of WABinary_1.getBinaryNodeChildren(commandsNode, 'command')) {
40
+ for (const command of getBinaryNodeChildren(commandsNode, 'command')) {
37
41
  commands.push({
38
- name: WABinary_1.getBinaryNodeChildString(command, 'name') || '',
39
- description: WABinary_1.getBinaryNodeChildString(command, 'description') || ''
42
+ name: getBinaryNodeChildString(command, 'name') || '',
43
+ description: getBinaryNodeChildString(command, 'description') || ''
40
44
  })
41
45
  }
42
46
  }
43
47
 
44
48
  if (promptsNode) {
45
- for (const prompt of WABinary_1.getBinaryNodeChildren(promptsNode, 'prompt')) {
49
+ for (const prompt of getBinaryNodeChildren(promptsNode, 'prompt')) {
46
50
  prompts.push(
47
- `${WABinary_1.getBinaryNodeChildString(prompt, 'emoji') || ''} ${WABinary_1.getBinaryNodeChildString(prompt, 'text') || ''}`
51
+ `${getBinaryNodeChildString(prompt, 'emoji') || ''} ${getBinaryNodeChildString(prompt, 'text') || ''}`
48
52
  )
49
53
  }
50
54
  }
51
55
 
52
56
  return {
53
- isDefault: !!WABinary_1.getBinaryNodeChild(profile, 'default'),
57
+ isDefault: !!getBinaryNodeChild(profile, 'default'),
54
58
  jid: node.attrs.jid,
55
- name: WABinary_1.getBinaryNodeChildString(profile, 'name') || '',
56
- attributes: WABinary_1.getBinaryNodeChildString(profile, 'attributes') || '',
57
- description: WABinary_1.getBinaryNodeChildString(profile, 'description') || '',
58
- category: WABinary_1.getBinaryNodeChildString(profile, 'category') || '',
59
+ name: getBinaryNodeChildString(profile, 'name') || '',
60
+ attributes: getBinaryNodeChildString(profile, 'attributes') || '',
61
+ description: getBinaryNodeChildString(profile, 'description') || '',
62
+ category: getBinaryNodeChildString(profile, 'category') || '',
59
63
  personaId: profile.attrs['persona_id'] || '',
60
- commandsDescription: WABinary_1.getBinaryNodeChildString(commandsNode, 'description') || '',
64
+ commandsDescription: getBinaryNodeChildString(commandsNode, 'description') || '',
61
65
  commands,
62
66
  prompts
63
67
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const WABinary_1 = require("../../WABinary")
5
+ const { assertNodeErrorFree } = require("../../WABinary")
6
6
 
7
7
  class USyncContactProtocol {
8
8
  constructor() {
@@ -24,7 +24,7 @@ class USyncContactProtocol {
24
24
  }
25
25
  parser(node) {
26
26
  if (node.tag === 'contact') {
27
- WABinary_1.assertNodeErrorFree(node)
27
+ assertNodeErrorFree(node)
28
28
  return node?.attrs?.type === 'in'
29
29
  }
30
30
  return false
@@ -2,7 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const WABinary_1 = require("../../WABinary")
5
+ const {
6
+ getBinaryNodeChild,
7
+ assertNodeErrorFree
8
+ } = require("../../WABinary")
6
9
 
7
10
  class USyncDeviceProtocol {
8
11
  constructor() {
@@ -26,9 +29,9 @@ class USyncDeviceProtocol {
26
29
  const deviceList = []
27
30
  let keyIndex = undefined
28
31
  if (node.tag === 'devices') {
29
- WABinary_1.assertNodeErrorFree(node)
30
- const deviceListNode = WABinary_1.getBinaryNodeChild(node, 'device-list')
31
- const keyIndexNode = WABinary_1.getBinaryNodeChild(node, 'key-index-list')
32
+ assertNodeErrorFree(node)
33
+ const deviceListNode = getBinaryNodeChild(node, 'device-list')
34
+ const keyIndexNode = getBinaryNodeChild(node, 'key-index-list')
32
35
  if (Array.isArray(deviceListNode?.content)) {
33
36
  for (const { tag, attrs } of deviceListNode.content) {
34
37
  const id = +attrs.id
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const WABinary_1 = require("../../WABinary")
5
+ const { assertNodeErrorFree } = require("../../WABinary")
6
6
 
7
7
  class USyncDisappearingModeProtocol {
8
8
  constructor() {
@@ -19,7 +19,7 @@ class USyncDisappearingModeProtocol {
19
19
  }
20
20
  parser(node) {
21
21
  if (node.tag === 'disappearing_mode') {
22
- WABinary_1.assertNodeErrorFree(node)
22
+ assertNodeErrorFree(node)
23
23
  const duration = +node?.attrs?.duration
24
24
  const setAt = new Date(+(node?.attrs?.t || 0) * 1000)
25
25
  return {
@@ -2,8 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const WABinary_1 = require("../../WABinary")
6
-
7
5
  class USyncLIDProtocol {
8
6
  constructor() {
9
7
  this.name = 'lid'
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const WABinary_1 = require("../../WABinary")
5
+ const { assertNodeErrorFree } = require("../../WABinary")
6
6
 
7
7
  class USyncStatusProtocol {
8
8
  constructor() {
@@ -19,7 +19,7 @@ class USyncStatusProtocol {
19
19
  }
20
20
  parser(node) {
21
21
  if (node.tag === 'status') {
22
- WABinary_1.assertNodeErrorFree(node)
22
+ assertNodeErrorFree(node)
23
23
  let status = node?.content?.toString() || null
24
24
  const setAt = new Date(+(node?.attrs?.t || 0) * 1000)
25
25
  if (!status) {
@@ -1,22 +1,38 @@
1
1
  "use strict"
2
2
 
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ const __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k
5
- var desc = Object.getOwnPropertyDescriptor(m, k)
5
+
6
+ let desc = Object.getOwnPropertyDescriptor(m, k)
7
+
6
8
  if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k] } }
9
+ desc = {
10
+ enumerable: true,
11
+ get: function() {
12
+ return m[k]
13
+ }
14
+ }
8
15
  }
9
- Object.defineProperty(o, k2, desc)
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k
12
- o[k2] = m[k]
13
- }))
14
16
 
15
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
17
+ Object.defineProperty(o, k2, desc)
18
+
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k
21
+ o[k2] = m[k]
22
+ }
23
+ ))
24
+
25
+ const __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) {
27
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
28
+ __createBinding(exports, m, p)
29
+ }
30
+ }
17
31
  }
18
32
 
19
- Object.defineProperty(exports, "__esModule", { value: true })
33
+ Object.defineProperty(exports, "__esModule", {
34
+ value: true
35
+ })
20
36
 
21
37
  __exportStar(require("./USyncBotProfileProtocol"), exports)
22
38
  __exportStar(require("./USyncContactProtocol"), exports)
@@ -2,8 +2,15 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const WABinary_1 = require("../WABinary")
6
- const Protocols_1 = require("./Protocols")
5
+ const { getBinaryNodeChild } = require("../WABinary")
6
+ const {
7
+ USyncLIDProtocol,
8
+ USyncDeviceProtocol,
9
+ USyncContactProtocol,
10
+ USyncStatusProtocol,
11
+ USyncBotProfileProtocol,
12
+ USyncDisappearingModeProtocol
13
+ } = require("./Protocols")
7
14
 
8
15
  class USyncQuery {
9
16
  constructor() {
@@ -25,64 +32,80 @@ class USyncQuery {
25
32
  return this
26
33
  }
27
34
  parseUSyncQueryResult(result) {
28
- if (result.attrs.type !== 'result') {
35
+ if (!result || result.attrs.type !== 'result') {
29
36
  return
30
37
  }
31
- const protocolMap = Object.fromEntries(this.protocols.map((protocol) => {
38
+
39
+ const protocolMap = Object.fromEntries(this.protocols.map(protocol => {
32
40
  return [protocol.name, protocol.parser]
33
41
  }))
42
+
34
43
  const queryResult = {
35
44
  // TODO: implement errors etc.
36
45
  list: [],
37
- sideList: [],
46
+ sideList: []
38
47
  }
39
- const usyncNode = WABinary_1.getBinaryNodeChild(result, 'usync')
48
+
49
+ const usyncNode = getBinaryNodeChild(result, 'usync')
50
+
40
51
  //TODO: implement error backoff, refresh etc.
41
52
  //TODO: see if there are any errors in the result node
42
53
  //const resultNode = getBinaryNodeChild(usyncNode, 'result')
43
- const listNode = WABinary_1.getBinaryNodeChild(usyncNode, 'list')
44
- if (Array.isArray(listNode?.content) && typeof listNode !== 'undefined') {
45
- queryResult.list = listNode.content.map((node) => {
46
- const id = node?.attrs?.jid
47
- const data = Array.isArray(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)) : {}
57
- return { ...data, id }
58
- })
54
+ const listNode = usyncNode ? getBinaryNodeChild(usyncNode, 'list') : undefined
55
+
56
+ if (listNode?.content && Array.isArray(listNode.content)) {
57
+ queryResult.list = listNode.content.reduce((acc, node) => {
58
+ const id = node?.attrs.jid
59
+
60
+ if (id) {
61
+ const data = Array.isArray(node?.content)
62
+ ? Object.fromEntries(node.content
63
+ .map(content => {
64
+ const protocol = content.tag
65
+ const parser = protocolMap[protocol]
66
+
67
+ if (parser) {
68
+ return [protocol, parser(content)]
69
+ }
70
+
71
+ else {
72
+ return [protocol, null]
73
+ }
74
+ }).filter(([, b]) => b !== null))
75
+ : {};
76
+ acc.push({ ...data, id })
77
+ }
78
+
79
+ return acc
80
+ }, [])
59
81
  }
82
+
60
83
  //TODO: implement side list
61
84
  //const sideListNode = getBinaryNodeChild(usyncNode, 'side_list')
62
85
  return queryResult
63
86
  }
64
87
  withLIDProtocol() {
65
- this.protocols.push(new Protocols_1.USyncLIDProtocol())
88
+ this.protocols.push(new USyncLIDProtocol())
66
89
  return this
67
90
  }
68
91
  withDeviceProtocol() {
69
- this.protocols.push(new Protocols_1.USyncDeviceProtocol())
92
+ this.protocols.push(new USyncDeviceProtocol())
70
93
  return this
71
94
  }
72
95
  withContactProtocol() {
73
- this.protocols.push(new Protocols_1.USyncContactProtocol())
96
+ this.protocols.push(new USyncContactProtocol())
74
97
  return this
75
98
  }
76
99
  withStatusProtocol() {
77
- this.protocols.push(new Protocols_1.USyncStatusProtocol())
100
+ this.protocols.push(new USyncStatusProtocol())
78
101
  return this
79
102
  }
80
103
  withBotProfileProtocol() {
81
- this.protocols.push(new Protocols_1.USyncBotProfileProtocol())
104
+ this.protocols.push(new USyncBotProfileProtocol())
82
105
  return this
83
106
  }
84
107
  withDisappearingModeProtocol() {
85
- this.protocols.push(new Protocols_1.USyncDisappearingModeProtocol())
108
+ this.protocols.push(new USyncDisappearingModeProtocol())
86
109
  return this
87
110
  }
88
111
  }
@@ -1,22 +1,38 @@
1
1
  "use strict"
2
2
 
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ const __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k
5
- var desc = Object.getOwnPropertyDescriptor(m, k)
5
+
6
+ let desc = Object.getOwnPropertyDescriptor(m, k)
7
+
6
8
  if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k] } }
9
+ desc = {
10
+ enumerable: true,
11
+ get: function() {
12
+ return m[k]
13
+ }
14
+ }
8
15
  }
9
- Object.defineProperty(o, k2, desc)
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k
12
- o[k2] = m[k]
13
- }))
14
16
 
15
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
17
+ Object.defineProperty(o, k2, desc)
18
+
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k
21
+ o[k2] = m[k]
22
+ }
23
+ ))
24
+
25
+ const __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) {
27
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
28
+ __createBinding(exports, m, p)
29
+ }
30
+ }
17
31
  }
18
32
 
19
- Object.defineProperty(exports, "__esModule", { value: true })
33
+ Object.defineProperty(exports, "__esModule", {
34
+ value: true
35
+ })
20
36
 
21
37
  __exportStar(require("./Protocols"), exports)
22
38
  __exportStar(require("./USyncQuery"), exports)