@pontalabs/baileys 1.0.4 → 1.0.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 (447) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +267 -839
  3. package/WAProto/GenerateStatics.sh +3 -4
  4. package/WAProto/WAProto.proto +1215 -511
  5. package/WAProto/fix-imports.js +85 -0
  6. package/WAProto/index.d.ts +14017 -55
  7. package/WAProto/index.js +97689 -29
  8. package/engine-requirements.js +10 -0
  9. package/lib/Defaults/index.d.ts +72 -74
  10. package/lib/Defaults/index.d.ts.map +1 -0
  11. package/lib/Defaults/index.js +94 -108
  12. package/lib/Defaults/index.js.map +1 -0
  13. package/lib/Signal/Group/ciphertext-message.d.ts +8 -7
  14. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  15. package/lib/Signal/Group/ciphertext-message.js +9 -16
  16. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  17. package/lib/Signal/Group/group-session-builder.d.ts +11 -13
  18. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  19. package/lib/Signal/Group/group-session-builder.js +19 -61
  20. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  21. package/lib/Signal/Group/group_cipher.d.ts +14 -16
  22. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  23. package/lib/Signal/Group/group_cipher.js +41 -70
  24. package/lib/Signal/Group/group_cipher.js.map +1 -0
  25. package/lib/Signal/Group/index.d.ts +12 -11
  26. package/lib/Signal/Group/index.d.ts.map +1 -0
  27. package/lib/Signal/Group/index.js +12 -61
  28. package/lib/Signal/Group/index.js.map +1 -0
  29. package/lib/Signal/Group/keyhelper.d.ts +9 -14
  30. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  31. package/lib/Signal/Group/keyhelper.js +10 -58
  32. package/lib/Signal/Group/keyhelper.js.map +1 -0
  33. package/lib/Signal/Group/sender-chain-key.d.ts +13 -13
  34. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  35. package/lib/Signal/Group/sender-chain-key.js +13 -34
  36. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  37. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -16
  38. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  39. package/lib/Signal/Group/sender-key-distribution-message.js +28 -36
  40. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  41. package/lib/Signal/Group/sender-key-message.d.ts +18 -18
  42. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  43. package/lib/Signal/Group/sender-key-message.js +38 -45
  44. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  45. package/lib/Signal/Group/sender-key-name.d.ts +14 -15
  46. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  47. package/lib/Signal/Group/sender-key-name.js +20 -31
  48. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  49. package/lib/Signal/Group/sender-key-record.d.ts +24 -25
  50. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  51. package/lib/Signal/Group/sender-key-record.js +18 -35
  52. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  53. package/lib/Signal/Group/sender-key-state.d.ts +29 -34
  54. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  55. package/lib/Signal/Group/sender-key-state.js +37 -100
  56. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  57. package/lib/Signal/Group/sender-message-key.d.ts +11 -10
  58. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  59. package/lib/Signal/Group/sender-message-key.js +15 -22
  60. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  61. package/lib/Signal/libsignal.d.ts +5 -8
  62. package/lib/Signal/libsignal.d.ts.map +1 -0
  63. package/lib/Signal/libsignal.js +279 -121
  64. package/lib/Signal/libsignal.js.map +1 -0
  65. package/lib/Signal/lid-mapping.d.ts +23 -28
  66. package/lib/Signal/lid-mapping.d.ts.map +1 -0
  67. package/lib/Signal/lid-mapping.js +277 -184
  68. package/lib/Signal/lid-mapping.js.map +1 -0
  69. package/lib/Socket/Client/index.d.ts +3 -2
  70. package/lib/Socket/Client/index.d.ts.map +1 -0
  71. package/lib/Socket/Client/index.js +3 -22
  72. package/lib/Socket/Client/index.js.map +1 -0
  73. package/lib/Socket/Client/types.d.ts +15 -15
  74. package/lib/Socket/Client/types.d.ts.map +1 -0
  75. package/lib/Socket/Client/types.js +8 -15
  76. package/lib/Socket/Client/types.js.map +1 -0
  77. package/lib/Socket/Client/websocket.d.ts +12 -12
  78. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  79. package/lib/Socket/Client/websocket.js +29 -37
  80. package/lib/Socket/Client/websocket.js.map +1 -0
  81. package/lib/Socket/business.d.ts +208 -178
  82. package/lib/Socket/business.d.ts.map +1 -0
  83. package/lib/Socket/business.js +91 -127
  84. package/lib/Socket/business.js.map +1 -0
  85. package/lib/Socket/chats.d.ts +120 -93
  86. package/lib/Socket/chats.d.ts.map +1 -0
  87. package/lib/Socket/chats.js +727 -652
  88. package/lib/Socket/chats.js.map +1 -0
  89. package/lib/Socket/communities.d.ts +273 -0
  90. package/lib/Socket/communities.d.ts.map +1 -0
  91. package/lib/Socket/communities.js +431 -0
  92. package/lib/Socket/communities.js.map +1 -0
  93. package/lib/Socket/dugong.js +261 -0
  94. package/lib/Socket/dugong.js.bak +204 -0
  95. package/lib/Socket/groups.d.ts +143 -111
  96. package/lib/Socket/groups.d.ts.map +1 -0
  97. package/lib/Socket/groups.js +165 -177
  98. package/lib/Socket/groups.js.map +1 -0
  99. package/lib/Socket/index.d.ts +252 -183
  100. package/lib/Socket/index.d.ts.map +1 -0
  101. package/lib/Socket/index.js +38 -18
  102. package/lib/Socket/index.js.bak +44 -0
  103. package/lib/Socket/index.js.map +1 -0
  104. package/lib/Socket/messages-recv.d.ts +196 -167
  105. package/lib/Socket/messages-recv.d.ts.map +1 -0
  106. package/lib/Socket/messages-recv.js +1443 -1563
  107. package/lib/Socket/messages-recv.js.map +1 -0
  108. package/lib/Socket/messages-send.d.ts +192 -158
  109. package/lib/Socket/messages-send.d.ts.map +1 -0
  110. package/lib/Socket/messages-send.js +1102 -1208
  111. package/lib/Socket/messages-send.js.bak +1400 -0
  112. package/lib/Socket/messages-send.js.map +1 -0
  113. package/lib/Socket/mex.d.ts +3 -0
  114. package/lib/Socket/mex.d.ts.map +1 -0
  115. package/lib/Socket/mex.js +42 -0
  116. package/lib/Socket/mex.js.map +1 -0
  117. package/lib/Socket/newsletter.d.ts +163 -138
  118. package/lib/Socket/newsletter.d.ts.map +1 -0
  119. package/lib/Socket/newsletter.js +153 -249
  120. package/lib/Socket/newsletter.js.map +1 -0
  121. package/lib/Socket/socket.d.ts +50 -36
  122. package/lib/Socket/socket.d.ts.map +1 -0
  123. package/lib/Socket/socket.js +749 -820
  124. package/lib/Socket/socket.js.map +1 -0
  125. package/lib/Store/index.d.ts +4 -4
  126. package/lib/Store/index.d.ts.map +1 -0
  127. package/lib/Store/index.js +4 -24
  128. package/lib/Store/index.js.map +1 -0
  129. package/lib/Store/make-in-memory-store.d.ts +44 -104
  130. package/lib/Store/make-in-memory-store.d.ts.map +1 -0
  131. package/lib/Store/make-in-memory-store.js +199 -213
  132. package/lib/Store/make-in-memory-store.js.map +1 -0
  133. package/lib/Store/make-ordered-dictionary.d.ts +13 -12
  134. package/lib/Store/make-ordered-dictionary.d.ts.map +1 -0
  135. package/lib/Store/make-ordered-dictionary.js +38 -45
  136. package/lib/Store/make-ordered-dictionary.js.map +1 -0
  137. package/lib/Store/object-repository.d.ts +11 -10
  138. package/lib/Store/object-repository.d.ts.map +1 -0
  139. package/lib/Store/object-repository.js +9 -16
  140. package/lib/Store/object-repository.js.map +1 -0
  141. package/lib/Types/Auth.d.ts +93 -97
  142. package/lib/Types/Auth.d.ts.map +1 -0
  143. package/lib/Types/Auth.js +2 -3
  144. package/lib/Types/Auth.js.map +1 -0
  145. package/lib/Types/Bussines.d.ts +25 -0
  146. package/lib/Types/Bussines.d.ts.map +1 -0
  147. package/lib/Types/Bussines.js +2 -3
  148. package/lib/Types/Bussines.js.map +1 -0
  149. package/lib/Types/Call.d.ts +14 -13
  150. package/lib/Types/Call.d.ts.map +1 -0
  151. package/lib/Types/Call.js +2 -3
  152. package/lib/Types/Call.js.map +1 -0
  153. package/lib/Types/Chat.d.ts +78 -97
  154. package/lib/Types/Chat.d.ts.map +1 -0
  155. package/lib/Types/Chat.js +8 -9
  156. package/lib/Types/Chat.js.map +1 -0
  157. package/lib/Types/Contact.d.ts +12 -9
  158. package/lib/Types/Contact.d.ts.map +1 -0
  159. package/lib/Types/Contact.js +2 -3
  160. package/lib/Types/Contact.js.map +1 -0
  161. package/lib/Types/Events.d.ts +206 -176
  162. package/lib/Types/Events.d.ts.map +1 -0
  163. package/lib/Types/Events.js +2 -3
  164. package/lib/Types/Events.js.map +1 -0
  165. package/lib/Types/GroupMetadata.d.ts +53 -48
  166. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  167. package/lib/Types/GroupMetadata.js +2 -3
  168. package/lib/Types/GroupMetadata.js.map +1 -0
  169. package/lib/Types/Label.d.ts +13 -14
  170. package/lib/Types/Label.d.ts.map +1 -0
  171. package/lib/Types/Label.js +24 -30
  172. package/lib/Types/Label.js.map +1 -0
  173. package/lib/Types/LabelAssociation.d.ts +15 -20
  174. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  175. package/lib/Types/LabelAssociation.js +6 -12
  176. package/lib/Types/LabelAssociation.js.map +1 -0
  177. package/lib/Types/Message.d.ts +248 -412
  178. package/lib/Types/Message.d.ts.map +1 -0
  179. package/lib/Types/Message.js +17 -19
  180. package/lib/Types/Message.js.map +1 -0
  181. package/lib/Types/Mex.d.ts +141 -0
  182. package/lib/Types/Mex.d.ts.map +1 -0
  183. package/lib/Types/Mex.js +37 -0
  184. package/lib/Types/Mex.js.map +1 -0
  185. package/lib/Types/Product.d.ts +58 -71
  186. package/lib/Types/Product.d.ts.map +1 -0
  187. package/lib/Types/Product.js +2 -3
  188. package/lib/Types/Product.js.map +1 -0
  189. package/lib/Types/RichType.d.ts +3 -0
  190. package/lib/Types/RichType.d.ts.map +1 -0
  191. package/lib/Types/RichType.js +23 -0
  192. package/lib/Types/RichType.js.bak +23 -0
  193. package/lib/Types/RichType.js.map +1 -0
  194. package/lib/Types/Signal.d.ts +71 -82
  195. package/lib/Types/Signal.d.ts.map +1 -0
  196. package/lib/Types/Signal.js +2 -3
  197. package/lib/Types/Signal.js.map +1 -0
  198. package/lib/Types/Socket.d.ts +76 -81
  199. package/lib/Types/Socket.d.ts.map +1 -0
  200. package/lib/Types/Socket.js +3 -3
  201. package/lib/Types/Socket.js.map +1 -0
  202. package/lib/Types/State.d.ts +75 -19
  203. package/lib/Types/State.d.ts.map +1 -0
  204. package/lib/Types/State.js +56 -14
  205. package/lib/Types/State.js.map +1 -0
  206. package/lib/Types/USync.d.ts +8 -8
  207. package/lib/Types/USync.d.ts.map +1 -0
  208. package/lib/Types/USync.js +2 -3
  209. package/lib/Types/USync.js.map +1 -0
  210. package/lib/Types/index.d.ts +47 -62
  211. package/lib/Types/index.d.ts.map +1 -0
  212. package/lib/Types/index.js +26 -50
  213. package/lib/Types/index.js.map +1 -0
  214. package/lib/Utils/auth-utils.d.ts +13 -10
  215. package/lib/Utils/auth-utils.d.ts.map +1 -0
  216. package/lib/Utils/auth-utils.js +213 -454
  217. package/lib/Utils/auth-utils.js.map +1 -0
  218. package/lib/Utils/browser-utils.d.ts +4 -0
  219. package/lib/Utils/browser-utils.d.ts.map +1 -0
  220. package/lib/Utils/browser-utils.js +28 -0
  221. package/lib/Utils/browser-utils.js.map +1 -0
  222. package/lib/Utils/business.d.ts +14 -20
  223. package/lib/Utils/business.d.ts.map +1 -0
  224. package/lib/Utils/business.js +110 -134
  225. package/lib/Utils/business.js.map +1 -0
  226. package/lib/Utils/chat-utils.d.ts +88 -70
  227. package/lib/Utils/chat-utils.d.ts.map +1 -0
  228. package/lib/Utils/chat-utils.js +466 -403
  229. package/lib/Utils/chat-utils.js.map +1 -0
  230. package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
  231. package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
  232. package/lib/Utils/companion-reg-client-utils.js +35 -0
  233. package/lib/Utils/companion-reg-client-utils.js.map +1 -0
  234. package/lib/Utils/crypto.d.ts +27 -46
  235. package/lib/Utils/crypto.d.ts.map +1 -0
  236. package/lib/Utils/crypto.js +117 -188
  237. package/lib/Utils/crypto.js.map +1 -0
  238. package/lib/Utils/decode-wa-message.d.ts +58 -45
  239. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  240. package/lib/Utils/decode-wa-message.js +213 -303
  241. package/lib/Utils/decode-wa-message.js.map +1 -0
  242. package/lib/Utils/event-buffer.d.ts +14 -17
  243. package/lib/Utils/event-buffer.d.ts.map +1 -0
  244. package/lib/Utils/event-buffer.js +321 -296
  245. package/lib/Utils/event-buffer.js.map +1 -0
  246. package/lib/Utils/generics.d.ts +66 -92
  247. package/lib/Utils/generics.d.ts.map +1 -0
  248. package/lib/Utils/generics.js +270 -436
  249. package/lib/Utils/generics.js.map +1 -0
  250. package/lib/Utils/history.d.ts +24 -23
  251. package/lib/Utils/history.d.ts.map +1 -0
  252. package/lib/Utils/history.js +106 -76
  253. package/lib/Utils/history.js.map +1 -0
  254. package/lib/Utils/identity-change-handler.d.ts +44 -0
  255. package/lib/Utils/identity-change-handler.d.ts.map +1 -0
  256. package/lib/Utils/identity-change-handler.js +50 -0
  257. package/lib/Utils/identity-change-handler.js.map +1 -0
  258. package/lib/Utils/index.d.ts +24 -21
  259. package/lib/Utils/index.d.ts.map +1 -0
  260. package/lib/Utils/index.js +24 -41
  261. package/lib/Utils/index.js.map +1 -0
  262. package/lib/Utils/link-preview.d.ts +12 -14
  263. package/lib/Utils/link-preview.d.ts.map +1 -0
  264. package/lib/Utils/link-preview.js +40 -75
  265. package/lib/Utils/link-preview.js.map +1 -0
  266. package/lib/Utils/logger.d.ts +10 -11
  267. package/lib/Utils/logger.d.ts.map +1 -0
  268. package/lib/Utils/logger.js +3 -7
  269. package/lib/Utils/logger.js.map +1 -0
  270. package/lib/Utils/lt-hash.d.ts +8 -14
  271. package/lib/Utils/lt-hash.d.ts.map +1 -0
  272. package/lib/Utils/lt-hash.js +3 -53
  273. package/lib/Utils/lt-hash.js.map +1 -0
  274. package/lib/Utils/make-mutex.d.ts +7 -7
  275. package/lib/Utils/make-mutex.d.ts.map +1 -0
  276. package/lib/Utils/make-mutex.js +28 -44
  277. package/lib/Utils/make-mutex.js.map +1 -0
  278. package/lib/Utils/message-retry-manager.d.ts +115 -88
  279. package/lib/Utils/message-retry-manager.d.ts.map +1 -0
  280. package/lib/Utils/message-retry-manager.js +265 -160
  281. package/lib/Utils/message-retry-manager.js.map +1 -0
  282. package/lib/Utils/messages-media.d.ts +105 -107
  283. package/lib/Utils/messages-media.d.ts.map +1 -0
  284. package/lib/Utils/messages-media.js +548 -619
  285. package/lib/Utils/messages-media.js.bak +786 -0
  286. package/lib/Utils/messages-media.js.map +1 -0
  287. package/lib/Utils/messages.d.ts +52 -66
  288. package/lib/Utils/messages.d.ts.map +1 -0
  289. package/lib/Utils/messages.js +1730 -1558
  290. package/lib/Utils/messages.js.backup +1768 -0
  291. package/lib/Utils/messages.js.bak +1809 -0
  292. package/lib/Utils/messages.js.bak2 +893 -0
  293. package/lib/Utils/messages.js.bak3 +1183 -0
  294. package/lib/Utils/messages.js.map +1 -0
  295. package/lib/Utils/noise-handler.d.ts +18 -18
  296. package/lib/Utils/noise-handler.d.ts.map +1 -0
  297. package/lib/Utils/noise-handler.js +176 -130
  298. package/lib/Utils/noise-handler.js.map +1 -0
  299. package/lib/Utils/offline-node-processor.d.ts +17 -0
  300. package/lib/Utils/offline-node-processor.d.ts.map +1 -0
  301. package/lib/Utils/offline-node-processor.js +40 -0
  302. package/lib/Utils/offline-node-processor.js.map +1 -0
  303. package/lib/Utils/pre-key-manager.d.ts +28 -0
  304. package/lib/Utils/pre-key-manager.d.ts.map +1 -0
  305. package/lib/Utils/pre-key-manager.js +106 -0
  306. package/lib/Utils/pre-key-manager.js.map +1 -0
  307. package/lib/Utils/process-message.d.ts +43 -32
  308. package/lib/Utils/process-message.d.ts.map +1 -0
  309. package/lib/Utils/process-message.js +484 -282
  310. package/lib/Utils/process-message.js.map +1 -0
  311. package/lib/Utils/reporting-utils.d.ts +11 -0
  312. package/lib/Utils/reporting-utils.d.ts.map +1 -0
  313. package/lib/Utils/reporting-utils.js +258 -0
  314. package/lib/Utils/reporting-utils.js.map +1 -0
  315. package/lib/Utils/rich-message-utils.d.ts +49 -0
  316. package/lib/Utils/rich-message-utils.d.ts.map +1 -0
  317. package/lib/Utils/rich-message-utils.js +1220 -724
  318. package/lib/Utils/rich-message-utils.js.backup +706 -0
  319. package/lib/Utils/rich-message-utils.js.bak +246 -0
  320. package/lib/Utils/rich-message-utils.js.map +1 -0
  321. package/lib/Utils/rich-message-utils.js.original +1332 -0
  322. package/lib/Utils/signal.d.ts +37 -32
  323. package/lib/Utils/signal.d.ts.map +1 -0
  324. package/lib/Utils/signal.js +140 -105
  325. package/lib/Utils/signal.js.map +1 -0
  326. package/lib/Utils/stanza-ack.d.ts +11 -0
  327. package/lib/Utils/stanza-ack.d.ts.map +1 -0
  328. package/lib/Utils/stanza-ack.js +38 -0
  329. package/lib/Utils/stanza-ack.js.map +1 -0
  330. package/lib/Utils/sync-action-utils.d.ts +19 -0
  331. package/lib/Utils/sync-action-utils.d.ts.map +1 -0
  332. package/lib/Utils/sync-action-utils.js +49 -0
  333. package/lib/Utils/sync-action-utils.js.map +1 -0
  334. package/lib/Utils/tc-token-utils.d.ts +37 -0
  335. package/lib/Utils/tc-token-utils.d.ts.map +1 -0
  336. package/lib/Utils/tc-token-utils.js +163 -0
  337. package/lib/Utils/tc-token-utils.js.map +1 -0
  338. package/lib/Utils/use-multi-file-auth-state.d.ts +5 -5
  339. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  340. package/lib/Utils/use-multi-file-auth-state.js +70 -120
  341. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  342. package/lib/Utils/use-single-file-auth-state.d.ts +11 -13
  343. package/lib/Utils/use-single-file-auth-state.d.ts.map +1 -0
  344. package/lib/Utils/use-single-file-auth-state.js +92 -66
  345. package/lib/Utils/use-single-file-auth-state.js.map +1 -0
  346. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  347. package/lib/Utils/use-sqlite-auth-state.d.ts.map +1 -0
  348. package/lib/Utils/use-sqlite-auth-state.js +109 -0
  349. package/lib/Utils/use-sqlite-auth-state.js.map +1 -0
  350. package/lib/Utils/validate-connection.d.ts +11 -13
  351. package/lib/Utils/validate-connection.d.ts.map +1 -0
  352. package/lib/Utils/validate-connection.js +128 -113
  353. package/lib/Utils/validate-connection.js.map +1 -0
  354. package/lib/WABinary/constants.d.ts +25 -27
  355. package/lib/WABinary/constants.d.ts.map +1 -0
  356. package/lib/WABinary/constants.js +1451 -1292
  357. package/lib/WABinary/constants.js.bak +1373 -0
  358. package/lib/WABinary/constants.js.map +1 -0
  359. package/lib/WABinary/decode.d.ts +7 -9
  360. package/lib/WABinary/decode.d.ts.map +1 -0
  361. package/lib/WABinary/decode.js +163 -189
  362. package/lib/WABinary/decode.js.map +1 -0
  363. package/lib/WABinary/encode.d.ts +3 -3
  364. package/lib/WABinary/encode.d.ts.map +1 -0
  365. package/lib/WABinary/encode.js +110 -155
  366. package/lib/WABinary/encode.js.map +1 -0
  367. package/lib/WABinary/generic-utils.d.ts +14 -27
  368. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  369. package/lib/WABinary/generic-utils.js +177 -105
  370. package/lib/WABinary/generic-utils.js.map +1 -0
  371. package/lib/WABinary/index.d.ts +6 -5
  372. package/lib/WABinary/index.d.ts.map +1 -0
  373. package/lib/WABinary/index.js +6 -25
  374. package/lib/WABinary/index.js.map +1 -0
  375. package/lib/WABinary/jid-utils.d.ts +41 -51
  376. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  377. package/lib/WABinary/jid-utils.js +83 -120
  378. package/lib/WABinary/jid-utils.js.map +1 -0
  379. package/lib/WABinary/types.d.ts +10 -13
  380. package/lib/WABinary/types.d.ts.map +1 -0
  381. package/lib/WABinary/types.js +2 -3
  382. package/lib/WABinary/types.js.map +1 -0
  383. package/lib/WAM/BinaryInfo.d.ts +8 -15
  384. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  385. package/lib/WAM/BinaryInfo.js +7 -14
  386. package/lib/WAM/BinaryInfo.js.map +1 -0
  387. package/lib/WAM/constants.d.ts +30 -37
  388. package/lib/WAM/constants.d.ts.map +1 -0
  389. package/lib/WAM/constants.js +19193 -11711
  390. package/lib/WAM/constants.js.map +1 -0
  391. package/lib/WAM/encode.d.ts +3 -3
  392. package/lib/WAM/encode.d.ts.map +1 -0
  393. package/lib/WAM/encode.js +95 -109
  394. package/lib/WAM/encode.js.map +1 -0
  395. package/lib/WAM/index.d.ts +4 -3
  396. package/lib/WAM/index.d.ts.map +1 -0
  397. package/lib/WAM/index.js +4 -23
  398. package/lib/WAM/index.js.map +1 -0
  399. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
  400. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  401. package/lib/WAUSync/Protocols/USyncContactProtocol.js +37 -21
  402. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  403. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +19 -22
  404. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  405. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +18 -26
  406. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  407. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +11 -12
  408. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  409. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -20
  410. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  411. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +11 -12
  412. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  413. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +16 -24
  414. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  415. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  416. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
  417. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
  418. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
  419. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  420. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  421. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  422. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  423. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  424. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  425. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  426. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  427. package/lib/WAUSync/Protocols/index.d.ts +6 -6
  428. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  429. package/lib/WAUSync/Protocols/index.js +6 -26
  430. package/lib/WAUSync/Protocols/index.js.map +1 -0
  431. package/lib/WAUSync/USyncQuery.d.ts +27 -28
  432. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  433. package/lib/WAUSync/USyncQuery.js +68 -62
  434. package/lib/WAUSync/USyncQuery.js.map +1 -0
  435. package/lib/WAUSync/USyncUser.d.ts +15 -10
  436. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  437. package/lib/WAUSync/USyncUser.js +20 -19
  438. package/lib/WAUSync/USyncUser.js.map +1 -0
  439. package/lib/WAUSync/index.d.ts +4 -3
  440. package/lib/WAUSync/index.d.ts.map +1 -0
  441. package/lib/WAUSync/index.js +4 -23
  442. package/lib/WAUSync/index.js.map +1 -0
  443. package/lib/index.d.ts +11 -12
  444. package/lib/index.d.ts.map +1 -0
  445. package/lib/index.js +12 -39
  446. package/lib/index.js.map +1 -0
  447. package/package.json +86 -42
@@ -1,66 +1,55 @@
1
- "use strict"
2
-
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod }
5
- }
6
-
7
- Object.defineProperty(exports, "__esModule", { value: true })
8
-
9
- const WAProto_1 = require("../../WAProto")
10
- const Defaults_1 = require("../Defaults")
11
- const LabelAssociation_1 = require("../Types/LabelAssociation")
12
- const Utils_1 = require("../Utils")
13
- const WABinary_1 = require("../WABinary")
14
- const Store_1 = require("./make-ordered-dictionary")
15
- const object_repository_1 = require("./object-repository")
16
-
17
- const waChatKey = (pin) => ({
1
+ import keyedDB from '@adiwajshing/keyed-db';
2
+ import { writeFileSync, readFileSync, existsSync } from 'fs';
3
+ import { WAProto } from '../Types/index.js';
4
+ import { LabelAssociationType } from '../Types/LabelAssociation.js';
5
+ import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
6
+ import { md5, toNumber, updateMessageWithReceipt, updateMessageWithReaction } from '../Utils/index.js';
7
+ import { jidDecode, jidNormalizedUser } from '../WABinary/index.js';
8
+ import { makeOrderedDictionary } from './make-ordered-dictionary.js';
9
+ import { ObjectRepository } from './object-repository.js';
10
+ export const waChatKey = (pin) => ({
18
11
  key: (c) => (pin ? (c.pinned ? '1' : '0') : '') + (c.archived ? '0' : '1') + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') + c.id,
19
12
  compare: (k1, k2) => k2.localeCompare(k1)
20
- })
21
-
22
- const waMessageID = (m) => m.key.id || ''
23
-
24
- const waLabelAssociationKey = {
25
- key: (la) => (la.type === LabelAssociation_1.LabelAssociationType.Chat ? la.chatId + la.labelId : la.chatId + la.messageId + la.labelId),
13
+ });
14
+ export const waMessageID = (m) => m.key.id || '';
15
+ export const waLabelAssociationKey = {
16
+ key: (la) => (la.type === LabelAssociationType.Chat ? la.chatId + la.labelId : la.chatId + la.messageId + la.labelId),
26
17
  compare: (k1, k2) => k2.localeCompare(k1)
27
- }
28
-
29
- const makeMessagesDictionary = () => Store_1.makeOrderedDictionary(waMessageID)
30
-
31
- const makeInMemoryStore = (config) => {
32
- const socket = config.socket
33
- const chatKey = config.chatKey || waChatKey(true)
34
- const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey
35
- const logger = config.logger || Defaults_1.DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' })
36
- const KeyedDB = require('@adiwajshing/keyed-db').default
37
- const chats = new KeyedDB(chatKey, c => c.id)
38
- const messages = {}
39
- const contacts = {}
40
- const groupMetadata = {}
41
- const presences = {}
42
- const state = { connection: 'close' }
43
- const labels = new object_repository_1.ObjectRepository()
44
- const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key)
18
+ };
19
+ const makeMessagesDictionary = () => makeOrderedDictionary(waMessageID);
20
+ export const makeInMemoryStore = (config = {}) => {
21
+ const socket = config.socket;
22
+ const chatKey = config.chatKey || waChatKey(true);
23
+ const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey;
24
+ const logger = config.logger || DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
25
+ const KeyedDB = keyedDB?.default ?? keyedDB;
26
+ const chats = new KeyedDB(chatKey, c => c.id);
27
+ const messages = {};
28
+ const contacts = {};
29
+ const groupMetadata = {};
30
+ const presences = {};
31
+ const state = { connection: 'close' };
32
+ const labels = new ObjectRepository();
33
+ const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key);
45
34
  const assertMessageList = (jid) => {
46
35
  if (!messages[jid]) {
47
- messages[jid] = makeMessagesDictionary()
36
+ messages[jid] = makeMessagesDictionary();
48
37
  }
49
- return messages[jid]
50
- }
38
+ return messages[jid];
39
+ };
51
40
  const contactsUpsert = (newContacts) => {
52
- const oldContacts = new Set(Object.keys(contacts))
41
+ const oldContacts = new Set(Object.keys(contacts));
53
42
  for (const contact of newContacts) {
54
- oldContacts.delete(contact.id)
55
- contacts[contact.id] = Object.assign(contacts[contact.id] || {}, contact)
43
+ oldContacts.delete(contact.id);
44
+ contacts[contact.id] = Object.assign(contacts[contact.id] || {}, contact);
56
45
  }
57
- return oldContacts
58
- }
46
+ return oldContacts;
47
+ };
59
48
  const labelsUpsert = (newLabels) => {
60
49
  for (const label of newLabels) {
61
- labels.upsertById(label.id, label)
50
+ labels.upsertById(label.id, label);
62
51
  }
63
- }
52
+ };
64
53
  /**
65
54
  * binds to a BaileysEventEmitter.
66
55
  * It listens to all events and constructs a state that you can query accurate data from.
@@ -69,237 +58,252 @@ const makeInMemoryStore = (config) => {
69
58
  */
70
59
  const bind = (ev) => {
71
60
  ev.on('connection.update', update => {
72
- Object.assign(state, update)
73
- })
61
+ Object.assign(state, update);
62
+ });
74
63
  ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
75
- if (syncType === WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
76
- return // FOR NOW,
64
+ if (syncType === WAProto.HistorySync.HistorySyncType.ON_DEMAND) {
65
+ return; // FOR NOW,
77
66
  //TODO: HANDLE
78
67
  }
79
68
  if (isLatest) {
80
- chats.clear()
69
+ chats.clear();
81
70
  for (const id in messages) {
82
- delete messages[id]
71
+ delete messages[id];
83
72
  }
84
73
  }
85
- const chatsAdded = chats.insertIfAbsent(...newChats).length
86
- logger.debug({ chatsAdded }, 'synced chats')
87
- const oldContacts = contactsUpsert(newContacts)
74
+ const chatsAdded = chats.insertIfAbsent(...newChats).length;
75
+ logger.debug({ chatsAdded }, 'synced chats');
76
+ const oldContacts = contactsUpsert(newContacts);
88
77
  if (isLatest) {
89
78
  for (const jid of oldContacts) {
90
- delete contacts[jid]
79
+ delete contacts[jid];
91
80
  }
92
81
  }
93
- logger.debug({ deletedContacts: isLatest ? oldContacts.size : 0, newContacts }, 'synced contacts')
82
+ logger.debug({ deletedContacts: isLatest ? oldContacts.size : 0, newContacts }, 'synced contacts');
94
83
  for (const msg of newMessages) {
95
- const jid = msg.key.remoteJid
96
- const list = assertMessageList(jid)
97
- list.upsert(msg, 'prepend')
84
+ const jid = msg.key.remoteJidAlt || msg.key.remoteJid;
85
+ const list = assertMessageList(jid);
86
+ list.upsert(msg, 'prepend');
98
87
  }
99
- logger.debug({ messages: newMessages.length }, 'synced messages')
100
- })
88
+ logger.debug({ messages: newMessages.length }, 'synced messages');
89
+ });
101
90
  ev.on('contacts.upsert', contacts => {
102
- contactsUpsert(contacts)
103
- })
91
+ contactsUpsert(contacts);
92
+ });
104
93
  ev.on('contacts.update', async (updates) => {
94
+ var _a;
105
95
  for (const update of updates) {
106
- let contact
96
+ let contact;
107
97
  if (contacts[update.id]) {
108
- contact = contacts[update.id]
98
+ contact = contacts[update.id];
109
99
  }
110
100
  else {
111
101
  const contactHashes = await Promise.all(Object.keys(contacts).map(async (contactId) => {
112
- const { user } = WABinary_1.jidDecode(contactId)
113
- return [contactId, (await Utils_1.md5(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)]
114
- }))
115
- contact = contacts[contactHashes.find(([, b]) => b === update.id?.[0]) || ''] // find contact by attrs.hash, when user is not saved as a contact
102
+ const { user } = jidDecode(contactId);
103
+ return [contactId, (await md5(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)];
104
+ }));
105
+ contact = contacts[((_a = contactHashes.find(([, b]) => b === update.id)) === null || _a === void 0 ? void 0 : _a[0]) || '']; // find contact by attrs.hash, when user is not saved as a contact
116
106
  }
117
107
  if (contact) {
118
108
  if (update.imgUrl === 'changed') {
119
- contact.imgUrl = socket ? await socket.profilePictureUrl(contact.id) : undefined
109
+ contact.imgUrl = socket ? await (socket === null || socket === void 0 ? void 0 : socket.profilePictureUrl(contact.id)) : undefined;
120
110
  }
121
111
  else if (update.imgUrl === 'removed') {
122
- delete contact.imgUrl
112
+ delete contact.imgUrl;
123
113
  }
124
114
  }
125
115
  else {
126
- return logger.debug({ update }, 'got update for non-existant contact')
116
+ return logger.debug({ update }, 'got update for non-existant contact');
127
117
  }
128
- Object.assign(contacts[contact.id], contact)
118
+ Object.assign(contacts[contact.id], contact);
129
119
  }
130
- })
120
+ });
131
121
  ev.on('chats.upsert', newChats => {
132
- chats.upsert(...newChats)
133
- })
122
+ chats.upsert(...newChats);
123
+ });
134
124
  ev.on('chats.update', updates => {
135
125
  for (let update of updates) {
136
126
  const result = chats.update(update.id, chat => {
137
127
  if (update.unreadCount > 0) {
138
- update = { ...update }
139
- update.unreadCount = (chat.unreadCount || 0) + update.unreadCount
128
+ update = { ...update };
129
+ update.unreadCount = (chat.unreadCount || 0) + update.unreadCount;
140
130
  }
141
- Object.assign(chat, update)
142
- })
131
+ Object.assign(chat, update);
132
+ });
143
133
  if (!result) {
144
- logger.debug({ update }, 'got update for non-existant chat')
134
+ logger.debug({ update }, 'got update for non-existant chat');
145
135
  }
146
136
  }
147
- })
137
+ });
148
138
  ev.on('labels.edit', (label) => {
149
139
  if (label.deleted) {
150
- return labels.deleteById(label.id)
140
+ return labels.deleteById(label.id);
151
141
  }
152
142
  // WhatsApp can store only up to 20 labels
153
143
  if (labels.count() < 20) {
154
- return labels.upsertById(label.id, label)
144
+ return labels.upsertById(label.id, label);
155
145
  }
156
- logger.error('Labels count exceed')
157
- })
146
+ logger.error('Labels count exceed');
147
+ });
158
148
  ev.on('labels.association', ({ type, association }) => {
159
149
  switch (type) {
160
150
  case 'add':
161
- labelAssociations.upsert(association)
162
- break
151
+ labelAssociations.upsert(association);
152
+ break;
163
153
  case 'remove':
164
- labelAssociations.delete(association)
165
- break
154
+ labelAssociations.delete(association);
155
+ break;
166
156
  default:
167
- console.error(`unknown operation type [${type}]`)
157
+ console.error(`unknown operation type [${type}]`);
168
158
  }
169
- })
159
+ });
170
160
  ev.on('presence.update', ({ id, presences: update }) => {
171
- presences[id] = presences[id] || {}
172
- Object.assign(presences[id], update)
173
- })
161
+ presences[id] = presences[id] || {};
162
+ Object.assign(presences[id], update);
163
+ });
174
164
  ev.on('chats.delete', deletions => {
175
165
  for (const item of deletions) {
176
166
  if (chats.get(item)) {
177
- chats.deleteById(item)
167
+ chats.deleteById(item);
178
168
  }
179
169
  }
180
- })
170
+ });
181
171
  ev.on('messages.upsert', ({ messages: newMessages, type }) => {
182
172
  switch (type) {
183
173
  case 'append':
184
174
  case 'notify':
185
175
  for (const msg of newMessages) {
186
- const jid = WABinary_1.jidNormalizedUser(msg.key.remoteJid)
187
- const list = assertMessageList(jid)
188
- list.upsert(msg, 'append')
176
+ const jid = jidNormalizedUser(msg.key.remoteJidAlt || msg.key.remoteJid);
177
+ const list = assertMessageList(jid);
178
+ list.upsert(msg, 'append');
189
179
  if (type === 'notify' && !chats.get(jid)) {
190
180
  ev.emit('chats.upsert', [
191
181
  {
192
182
  id: jid,
193
- conversationTimestamp: Utils_1.toNumber(msg.messageTimestamp),
183
+ conversationTimestamp: toNumber(msg.messageTimestamp),
194
184
  unreadCount: 1
195
185
  }
196
- ])
186
+ ]);
197
187
  }
198
188
  }
199
- break
189
+ break;
200
190
  }
201
- })
191
+ });
202
192
  ev.on('messages.update', updates => {
193
+ var _a;
203
194
  for (const { update, key } of updates) {
204
- const list = assertMessageList(WABinary_1.jidNormalizedUser(key.remoteJid))
205
- if (update?.status) {
206
- const listStatus = list.get(key.id)?.status
207
- if (listStatus && update?.status <= listStatus) {
208
- logger.debug({ update, storedStatus: listStatus }, 'status stored newer then update')
209
- delete update.status
210
- logger.debug({ update }, 'new update object')
195
+ const list = assertMessageList(jidNormalizedUser(key.remoteJid));
196
+ if (update === null || update === void 0 ? void 0 : update.status) {
197
+ const listStatus = (_a = list.get(key.id)) === null || _a === void 0 ? void 0 : _a.status;
198
+ if (listStatus && (update === null || update === void 0 ? void 0 : update.status) <= listStatus) {
199
+ logger.debug({ update, storedStatus: listStatus }, 'status stored newer then update');
200
+ delete update.status;
201
+ logger.debug({ update }, 'new update object');
211
202
  }
212
203
  }
213
- const result = list.updateAssign(key.id, update)
204
+ const result = list.updateAssign(key.id, update);
214
205
  if (!result) {
215
- logger.debug({ update }, 'got update for non-existent message')
206
+ logger.debug({ update }, 'got update for non-existent message');
216
207
  }
217
208
  }
218
- })
209
+ });
219
210
  ev.on('messages.delete', item => {
220
211
  if ('all' in item) {
221
- const list = messages[item.jid]
222
- list?.clear()
212
+ const list = messages[item.jid];
213
+ list === null || list === void 0 ? void 0 : list.clear();
223
214
  }
224
215
  else {
225
- const jid = item.keys[0].remoteJid
226
- const list = messages[jid]
216
+ const jid = item.keys[0].remoteJidAlt || item.keys[0].remoteJid;
217
+ const list = messages[jid];
227
218
  if (list) {
228
- const idSet = new Set(item.keys.map(k => k.id))
229
- list.filter(m => !idSet.has(m.key.id))
219
+ const idSet = new Set(item.keys.map(k => k.id));
220
+ list.filter(m => !idSet.has(m.key.id));
230
221
  }
231
222
  }
232
- })
223
+ });
233
224
  ev.on('groups.update', updates => {
234
225
  for (const update of updates) {
235
- const id = update.id
226
+ const id = update.id;
236
227
  if (groupMetadata[id]) {
237
- Object.assign(groupMetadata[id], update)
228
+ Object.assign(groupMetadata[id], update);
238
229
  }
239
230
  else {
240
- logger.debug({ update }, 'got update for non-existant group metadata')
231
+ logger.debug({ update }, 'got update for non-existant group metadata');
241
232
  }
242
233
  }
243
- })
234
+ });
244
235
  ev.on('group-participants.update', ({ id, participants, action }) => {
245
- const metadata = groupMetadata[id]
236
+ const metadata = groupMetadata[id];
246
237
  if (metadata) {
247
238
  switch (action) {
248
239
  case 'add':
249
- metadata.participants.push(...participants.map(id => ({ id, isAdmin: false, isSuperAdmin: false })))
250
- break
240
+ metadata.participants.push(...participants.map(participant => ({ id: participant.id, phoneNumber: participant.phoneNumber, admin: participant.admin })));
241
+ break;
251
242
  case 'demote':
252
243
  case 'promote':
253
244
  for (const participant of metadata.participants) {
254
- if (participants.includes(participant.id)) {
255
- participant.isAdmin = action === 'promote'
245
+ for (const participantData of participants) {
246
+ if (participantData.id === participant.id || participantData.phoneNumber === participant.phoneNumber) {
247
+ participant.admin = action === 'promote' && 'admin';
248
+ }
256
249
  }
257
250
  }
258
- break
251
+ break;
259
252
  case 'remove':
260
- metadata.participants = metadata.participants.filter(p => !participants.includes(p.id))
261
- break
253
+ const removeSet = new Set();
254
+ for (const p of participants) {
255
+ if (p.id)
256
+ removeSet.add(p.id);
257
+ if (p.phoneNumber)
258
+ removeSet.add(p.phoneNumber);
259
+ }
260
+ metadata.participants = metadata.participants.reduce((acc, p) => {
261
+ if (!removeSet.has(p.id) && !removeSet.has(p.phoneNumber))
262
+ acc.push(p);
263
+ return acc;
264
+ }, []);
265
+ break;
262
266
  }
263
267
  }
264
- })
268
+ });
265
269
  ev.on('message-receipt.update', updates => {
266
270
  for (const { key, receipt } of updates) {
267
- const obj = messages[key.remoteJid]
268
- const msg = obj?.get(key.id)
271
+ const obj = messages[key.remoteJidAlt || key.remoteJid];
272
+ const msg = obj === null || obj === void 0 ? void 0 : obj.get(key.id);
269
273
  if (msg) {
270
- Utils_1.updateMessageWithReceipt(msg, receipt)
274
+ updateMessageWithReceipt(msg, receipt);
271
275
  }
272
276
  }
273
- })
277
+ });
274
278
  ev.on('messages.reaction', (reactions) => {
275
279
  for (const { key, reaction } of reactions) {
276
- const obj = messages[key.remoteJid]
277
- const msg = obj?.get(key.id)
280
+ const obj = messages[key.remoteJidAlt || key.remoteJid];
281
+ const msg = obj === null || obj === void 0 ? void 0 : obj.get(key.id);
278
282
  if (msg) {
279
- Utils_1.updateMessageWithReaction(msg, reaction)
283
+ updateMessageWithReaction(msg, reaction);
280
284
  }
281
285
  }
282
- })
283
- }
286
+ });
287
+ };
284
288
  const toJSON = () => ({
285
289
  chats,
286
290
  contacts,
287
291
  messages,
288
292
  labels,
289
293
  labelAssociations
290
- })
294
+ });
291
295
  const fromJSON = (json) => {
292
- chats.upsert(...json.chats)
293
- labelAssociations.upsert(...json.labelAssociations || [])
294
- contactsUpsert(Object.values(json.contacts))
295
- labelsUpsert(Object.values(json.labels || {}))
296
+ chats.upsert(...json.chats);
297
+ labelAssociations.upsert(...json.labelAssociations || []);
298
+ contactsUpsert(Object.values(json.contacts));
299
+ labelsUpsert(Object.values(json.labels || {}));
296
300
  for (const jid in json.messages) {
297
- const list = assertMessageList(jid)
301
+ const list = assertMessageList(jid);
298
302
  for (const msg of json.messages[jid]) {
299
- list.upsert(WAProto_1.proto.WebMessageInfo.fromObject(msg), 'append')
303
+ list.upsert(WAProto.WebMessageInfo.fromObject(msg), 'append');
300
304
  }
301
305
  }
302
- }
306
+ };
303
307
  return {
304
308
  chats,
305
309
  contacts,
@@ -312,28 +316,28 @@ const makeInMemoryStore = (config) => {
312
316
  bind,
313
317
  /** loads messages from the store, if not found -- uses the legacy connection */
314
318
  loadMessages: async (jid, count, cursor) => {
315
- const list = assertMessageList(jid)
316
- const mode = !cursor || 'before' in cursor ? 'before' : 'after'
317
- const cursorKey = !!cursor ? ('before' in cursor ? cursor.before : cursor.after) : undefined
318
- const cursorValue = cursorKey ? list.get(cursorKey.id) : undefined
319
- let messages
319
+ const list = assertMessageList(jid);
320
+ const mode = !cursor || 'before' in cursor ? 'before' : 'after';
321
+ const cursorKey = !!cursor ? ('before' in cursor ? cursor.before : cursor.after) : undefined;
322
+ const cursorValue = cursorKey ? list.get(cursorKey.id) : undefined;
323
+ let messages;
320
324
  if (list && mode === 'before' && (!cursorKey || cursorValue)) {
321
325
  if (cursorValue) {
322
- const msgIdx = list.array.findIndex(m => m.key.id === cursorKey?.id)
323
- messages = list.array.slice(0, msgIdx)
326
+ const msgIdx = list.array.findIndex(m => m.key.id === (cursorKey === null || cursorKey === void 0 ? void 0 : cursorKey.id));
327
+ messages = list.array.slice(0, msgIdx);
324
328
  }
325
329
  else {
326
- messages = list.array
330
+ messages = list.array;
327
331
  }
328
- const diff = count - messages.length
332
+ const diff = count - messages.length;
329
333
  if (diff < 0) {
330
- messages = messages.slice(-count) // get the last X messages
334
+ messages = messages.slice(-count); // get the last X messages
331
335
  }
332
336
  }
333
337
  else {
334
- messages = []
338
+ messages = [];
335
339
  }
336
- return messages
340
+ return messages;
337
341
  },
338
342
  /**
339
343
  * Get all available labels for profile
@@ -342,7 +346,7 @@ const makeInMemoryStore = (config) => {
342
346
  * that were "caught" during their editing.
343
347
  */
344
348
  getLabels: () => {
345
- return labels
349
+ return labels;
346
350
  },
347
351
  /**
348
352
  * Get labels for chat
@@ -350,7 +354,7 @@ const makeInMemoryStore = (config) => {
350
354
  * @returns Label IDs
351
355
  **/
352
356
  getChatLabels: (chatId) => {
353
- return labelAssociations.filter((la) => la.chatId === chatId).all()
357
+ return labelAssociations.filter((la) => la.chatId === chatId).all();
354
358
  },
355
359
  /**
356
360
  * Get labels for message
@@ -360,70 +364,52 @@ const makeInMemoryStore = (config) => {
360
364
  getMessageLabels: (messageId) => {
361
365
  const associations = labelAssociations
362
366
  .filter((la) => la.messageId === messageId)
363
- .all()
364
- return associations.map(({ labelId }) => labelId)
367
+ .all();
368
+ return associations.map(({ labelId }) => labelId);
365
369
  },
366
- loadMessage: async (jid, id) => messages[jid]?.get(id),
370
+ loadMessage: async (jid, id) => { var _a; return (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.get(id); },
367
371
  mostRecentMessage: async (jid) => {
368
- const message = messages[jid]?.array.slice(-1)[0]
369
- return message
372
+ var _a;
373
+ const message = (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.array.slice(-1)[0];
374
+ return message;
370
375
  },
371
376
  fetchImageUrl: async (jid, sock) => {
372
- const contact = contacts[jid]
377
+ const contact = contacts[jid];
373
378
  if (!contact) {
374
- return sock?.profilePictureUrl(jid)
379
+ return sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid);
375
380
  }
376
381
  if (typeof contact.imgUrl === 'undefined') {
377
- contact.imgUrl = await sock?.profilePictureUrl(jid)
382
+ contact.imgUrl = await (sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid));
378
383
  }
379
- return contact.imgUrl
384
+ return contact.imgUrl;
380
385
  },
381
386
  fetchGroupMetadata: async (jid, sock) => {
382
387
  if (!groupMetadata[jid]) {
383
- const metadata = await sock?.groupMetadata(jid)
388
+ const metadata = await (sock === null || sock === void 0 ? void 0 : sock.groupMetadata(jid));
384
389
  if (metadata) {
385
- groupMetadata[jid] = metadata
390
+ groupMetadata[jid] = metadata;
386
391
  }
387
392
  }
388
- return groupMetadata[jid]
393
+ return groupMetadata[jid];
389
394
  },
390
- // fetchBroadcastListInfo: async(jid: string, sock: WASocket | undefined) => {
391
- // if(!groupMetadata[jid]) {
392
- // const metadata = await sock?.getBroadcastListInfo(jid)
393
- // if(metadata) {
394
- // groupMetadata[jid] = metadata
395
- // }
396
- // }
397
- // return groupMetadata[jid]
398
- // },
399
395
  fetchMessageReceipts: async ({ remoteJid, id }) => {
400
- const list = messages[remoteJid]
401
- const msg = list?.get(id)
402
- return msg?.userReceipt
396
+ const list = messages[remoteJid];
397
+ const msg = list === null || list === void 0 ? void 0 : list.get(id);
398
+ return msg === null || msg === void 0 ? void 0 : msg.userReceipt;
403
399
  },
404
400
  toJSON,
405
401
  fromJSON,
406
402
  writeToFile: (path) => {
407
- // require fs here so that in case "fs" is not available -- the app does not crash
408
- const { writeFileSync } = require('fs')
409
- writeFileSync(path, JSON.stringify(toJSON()))
403
+ writeFileSync(path, JSON.stringify(toJSON()));
410
404
  },
411
405
  readFromFile: (path) => {
412
- // require fs here so that in case "fs" is not available -- the app does not crash
413
- const { readFileSync, existsSync } = require('fs')
414
406
  if (existsSync(path)) {
415
- logger.debug({ path }, 'reading from file')
416
- const jsonStr = readFileSync(path, { encoding: 'utf-8' })
417
- const json = JSON.parse(jsonStr)
418
- fromJSON(json)
407
+ logger.debug({ path }, 'reading from file');
408
+ const jsonStr = readFileSync(path, { encoding: 'utf-8' });
409
+ const json = JSON.parse(jsonStr);
410
+ fromJSON(json);
419
411
  }
420
412
  }
421
- }
422
- }
423
-
424
- module.exports = {
425
- waChatKey,
426
- waMessageID,
427
- waLabelAssociationKey,
428
- makeInMemoryStore
429
- }
413
+ };
414
+ };
415
+ //# sourceMappingURL=make-in-memory-store.js.map