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