yowtech 1.0.1-rv

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 (459) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +82 -0
  3. package/WAProto/W +1 -0
  4. package/WAProto/WAProto.proto +6035 -0
  5. package/WAProto/index.d.ts +15932 -0
  6. package/WAProto/index.js +115856 -0
  7. package/engine-requirements.js +13 -0
  8. package/lib/Defaults/D +1 -0
  9. package/lib/Defaults/index.d.ts +145 -0
  10. package/lib/Defaults/index.d.ts.map +1 -0
  11. package/lib/Defaults/index.js +152 -0
  12. package/lib/Defaults/index.js.map +1 -0
  13. package/lib/Signal/Group/G +1 -0
  14. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  15. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  16. package/lib/Signal/Group/ciphertext-message.js +12 -0
  17. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  18. package/lib/Signal/Group/group-session-builder.d.ts +8 -0
  19. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  20. package/lib/Signal/Group/group-session-builder.js +30 -0
  21. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  22. package/lib/Signal/Group/group_cipher.d.ts +11 -0
  23. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  24. package/lib/Signal/Group/group_cipher.js +82 -0
  25. package/lib/Signal/Group/group_cipher.js.map +1 -0
  26. package/lib/Signal/Group/index.d.ts +12 -0
  27. package/lib/Signal/Group/index.d.ts.map +1 -0
  28. package/lib/Signal/Group/index.js +12 -0
  29. package/lib/Signal/Group/index.js.map +1 -0
  30. package/lib/Signal/Group/keyhelper.d.ts +7 -0
  31. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  32. package/lib/Signal/Group/keyhelper.js +18 -0
  33. package/lib/Signal/Group/keyhelper.js.map +1 -0
  34. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  35. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  36. package/lib/Signal/Group/sender-chain-key.js +26 -0
  37. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  38. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  39. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  40. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  41. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  42. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  43. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  44. package/lib/Signal/Group/sender-key-message.js +66 -0
  45. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  46. package/lib/Signal/Group/sender-key-name.d.ts +12 -0
  47. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  48. package/lib/Signal/Group/sender-key-name.js +48 -0
  49. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  50. package/lib/Signal/Group/sender-key-record.d.ts +13 -0
  51. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  52. package/lib/Signal/Group/sender-key-record.js +41 -0
  53. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  54. package/lib/Signal/Group/sender-key-state.d.ts +17 -0
  55. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  56. package/lib/Signal/Group/sender-key-state.js +84 -0
  57. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  58. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  59. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  60. package/lib/Signal/Group/sender-message-key.js +26 -0
  61. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  62. package/lib/Signal/S +1 -0
  63. package/lib/Signal/libsignal.d.ts +55 -0
  64. package/lib/Signal/libsignal.d.ts.map +1 -0
  65. package/lib/Signal/libsignal.js +431 -0
  66. package/lib/Signal/libsignal.js.map +1 -0
  67. package/lib/Signal/lid-mapping.d.ts +21 -0
  68. package/lib/Signal/lid-mapping.d.ts.map +1 -0
  69. package/lib/Signal/lid-mapping.js +277 -0
  70. package/lib/Signal/lid-mapping.js.map +1 -0
  71. package/lib/Socket/Client/C +1 -0
  72. package/lib/Socket/Client/index.d.ts +3 -0
  73. package/lib/Socket/Client/index.d.ts.map +1 -0
  74. package/lib/Socket/Client/index.js +3 -0
  75. package/lib/Socket/Client/index.js.map +1 -0
  76. package/lib/Socket/Client/types.d.ts +6 -0
  77. package/lib/Socket/Client/types.d.ts.map +1 -0
  78. package/lib/Socket/Client/types.js +11 -0
  79. package/lib/Socket/Client/types.js.map +1 -0
  80. package/lib/Socket/Client/websocket.d.ts +13 -0
  81. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  82. package/lib/Socket/Client/websocket.js +54 -0
  83. package/lib/Socket/Client/websocket.js.map +1 -0
  84. package/lib/Socket/business.d.ts +395 -0
  85. package/lib/Socket/business.d.ts.map +1 -0
  86. package/lib/Socket/business.js +380 -0
  87. package/lib/Socket/business.js.map +1 -0
  88. package/lib/Socket/chats.d.ts +144 -0
  89. package/lib/Socket/chats.d.ts.map +1 -0
  90. package/lib/Socket/chats.js +1219 -0
  91. package/lib/Socket/chats.js.map +1 -0
  92. package/lib/Socket/communities.d.ts +562 -0
  93. package/lib/Socket/communities.d.ts.map +1 -0
  94. package/lib/Socket/communities.js +432 -0
  95. package/lib/Socket/communities.js.map +1 -0
  96. package/lib/Socket/groups.d.ts +286 -0
  97. package/lib/Socket/groups.d.ts.map +1 -0
  98. package/lib/Socket/groups.js +348 -0
  99. package/lib/Socket/groups.js.map +1 -0
  100. package/lib/Socket/index.d.ts +530 -0
  101. package/lib/Socket/index.d.ts.map +1 -0
  102. package/lib/Socket/index.js +22 -0
  103. package/lib/Socket/index.js.map +1 -0
  104. package/lib/Socket/messages-recv.d.ts +334 -0
  105. package/lib/Socket/messages-recv.d.ts.map +1 -0
  106. package/lib/Socket/messages-recv.js +1797 -0
  107. package/lib/Socket/messages-recv.js.map +1 -0
  108. package/lib/Socket/messages-send.d.ts +330 -0
  109. package/lib/Socket/messages-send.d.ts.map +1 -0
  110. package/lib/Socket/messages-send.js +1396 -0
  111. package/lib/Socket/messages-send.js.map +1 -0
  112. package/lib/Socket/mex.d.ts +2 -0
  113. package/lib/Socket/mex.d.ts.map +1 -0
  114. package/lib/Socket/mex.js +42 -0
  115. package/lib/Socket/mex.js.map +1 -0
  116. package/lib/Socket/newsletter.d.ts +283 -0
  117. package/lib/Socket/newsletter.d.ts.map +1 -0
  118. package/lib/Socket/newsletter.js +226 -0
  119. package/lib/Socket/newsletter.js.map +1 -0
  120. package/lib/Socket/socket.d.ts +61 -0
  121. package/lib/Socket/socket.d.ts.map +1 -0
  122. package/lib/Socket/socket.js +970 -0
  123. package/lib/Socket/socket.js.map +1 -0
  124. package/lib/Store/S +1 -0
  125. package/lib/Store/index.d.ts +4 -0
  126. package/lib/Store/index.d.ts.map +1 -0
  127. package/lib/Store/index.js +4 -0
  128. package/lib/Store/index.js.map +1 -0
  129. package/lib/Store/make-in-memory-store.d.ts +63 -0
  130. package/lib/Store/make-in-memory-store.d.ts.map +1 -0
  131. package/lib/Store/make-in-memory-store.js +421 -0
  132. package/lib/Store/make-in-memory-store.js.map +1 -0
  133. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  134. package/lib/Store/make-ordered-dictionary.d.ts.map +1 -0
  135. package/lib/Store/make-ordered-dictionary.js +79 -0
  136. package/lib/Store/make-ordered-dictionary.js.map +1 -0
  137. package/lib/Store/object-repository.d.ts +11 -0
  138. package/lib/Store/object-repository.d.ts.map +1 -0
  139. package/lib/Store/object-repository.js +24 -0
  140. package/lib/Store/object-repository.js.map +1 -0
  141. package/lib/Types/Auth.d.ts +2 -0
  142. package/lib/Types/Auth.d.ts.map +1 -0
  143. package/lib/Types/Auth.js +2 -0
  144. package/lib/Types/Auth.js.map +1 -0
  145. package/lib/Types/Bussines.d.ts +2 -0
  146. package/lib/Types/Bussines.d.ts.map +1 -0
  147. package/lib/Types/Bussines.js +2 -0
  148. package/lib/Types/Bussines.js.map +1 -0
  149. package/lib/Types/Call.d.ts +2 -0
  150. package/lib/Types/Call.d.ts.map +1 -0
  151. package/lib/Types/Call.js +2 -0
  152. package/lib/Types/Call.js.map +1 -0
  153. package/lib/Types/Chat.d.ts +2 -0
  154. package/lib/Types/Chat.d.ts.map +1 -0
  155. package/lib/Types/Chat.js +8 -0
  156. package/lib/Types/Chat.js.map +1 -0
  157. package/lib/Types/Contact.d.ts +2 -0
  158. package/lib/Types/Contact.d.ts.map +1 -0
  159. package/lib/Types/Contact.js +2 -0
  160. package/lib/Types/Contact.js.map +1 -0
  161. package/lib/Types/Events.d.ts +2 -0
  162. package/lib/Types/Events.d.ts.map +1 -0
  163. package/lib/Types/Events.js +2 -0
  164. package/lib/Types/Events.js.map +1 -0
  165. package/lib/Types/GroupMetadata.d.ts +2 -0
  166. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  167. package/lib/Types/GroupMetadata.js +2 -0
  168. package/lib/Types/GroupMetadata.js.map +1 -0
  169. package/lib/Types/Label.d.ts +3 -0
  170. package/lib/Types/Label.d.ts.map +1 -0
  171. package/lib/Types/Label.js +25 -0
  172. package/lib/Types/Label.js.map +1 -0
  173. package/lib/Types/LabelAssociation.d.ts +3 -0
  174. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  175. package/lib/Types/LabelAssociation.js +7 -0
  176. package/lib/Types/LabelAssociation.js.map +1 -0
  177. package/lib/Types/Message.d.ts +12 -0
  178. package/lib/Types/Message.d.ts.map +1 -0
  179. package/lib/Types/Message.js +18 -0
  180. package/lib/Types/Message.js.map +1 -0
  181. package/lib/Types/Mex.d.ts +3 -0
  182. package/lib/Types/Mex.d.ts.map +1 -0
  183. package/lib/Types/Mex.js +39 -0
  184. package/lib/Types/Mex.js.map +1 -0
  185. package/lib/Types/Product.d.ts +2 -0
  186. package/lib/Types/Product.d.ts.map +1 -0
  187. package/lib/Types/Product.js +2 -0
  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.map +1 -0
  193. package/lib/Types/Signal.d.ts +2 -0
  194. package/lib/Types/Signal.d.ts.map +1 -0
  195. package/lib/Types/Signal.js +2 -0
  196. package/lib/Types/Signal.js.map +1 -0
  197. package/lib/Types/Socket.d.ts +2 -0
  198. package/lib/Types/Socket.d.ts.map +1 -0
  199. package/lib/Types/Socket.js +2 -0
  200. package/lib/Types/Socket.js.map +1 -0
  201. package/lib/Types/State.d.ts +6 -0
  202. package/lib/Types/State.d.ts.map +1 -0
  203. package/lib/Types/State.js +56 -0
  204. package/lib/Types/State.js.map +1 -0
  205. package/lib/Types/T +1 -0
  206. package/lib/Types/USync.d.ts +2 -0
  207. package/lib/Types/USync.d.ts.map +1 -0
  208. package/lib/Types/USync.js +2 -0
  209. package/lib/Types/USync.js.map +1 -0
  210. package/lib/Types/index.d.ts +14 -0
  211. package/lib/Types/index.d.ts.map +1 -0
  212. package/lib/Types/index.js +26 -0
  213. package/lib/Types/index.js.map +1 -0
  214. package/lib/Utils/U +1 -0
  215. package/lib/Utils/advanced.js +89 -0
  216. package/lib/Utils/auth-utils.d.ts +58 -0
  217. package/lib/Utils/auth-utils.d.ts.map +1 -0
  218. package/lib/Utils/auth-utils.js +306 -0
  219. package/lib/Utils/auth-utils.js.map +1 -0
  220. package/lib/Utils/browser-utils.d.ts +10 -0
  221. package/lib/Utils/browser-utils.d.ts.map +1 -0
  222. package/lib/Utils/browser-utils.js +29 -0
  223. package/lib/Utils/browser-utils.js.map +1 -0
  224. package/lib/Utils/business.d.ts +50 -0
  225. package/lib/Utils/business.d.ts.map +1 -0
  226. package/lib/Utils/business.js +231 -0
  227. package/lib/Utils/business.js.map +1 -0
  228. package/lib/Utils/chat-utils.d.ts +409 -0
  229. package/lib/Utils/chat-utils.d.ts.map +1 -0
  230. package/lib/Utils/chat-utils.js +872 -0
  231. package/lib/Utils/chat-utils.js.map +1 -0
  232. package/lib/Utils/companion-reg-client-utils.d.ts +5 -0
  233. package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
  234. package/lib/Utils/companion-reg-client-utils.js +40 -0
  235. package/lib/Utils/companion-reg-client-utils.js.map +1 -0
  236. package/lib/Utils/crypto.d.ts +40 -0
  237. package/lib/Utils/crypto.d.ts.map +1 -0
  238. package/lib/Utils/crypto.js +118 -0
  239. package/lib/Utils/crypto.js.map +1 -0
  240. package/lib/Utils/decode-wa-message.d.ts +84 -0
  241. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  242. package/lib/Utils/decode-wa-message.js +317 -0
  243. package/lib/Utils/decode-wa-message.js.map +1 -0
  244. package/lib/Utils/enchanted-utils.js +93 -0
  245. package/lib/Utils/event-buffer.d.ts +13 -0
  246. package/lib/Utils/event-buffer.d.ts.map +1 -0
  247. package/lib/Utils/event-buffer.js +622 -0
  248. package/lib/Utils/event-buffer.js.map +1 -0
  249. package/lib/Utils/generics.d.ts +64 -0
  250. package/lib/Utils/generics.d.ts.map +1 -0
  251. package/lib/Utils/generics.js +395 -0
  252. package/lib/Utils/generics.js.map +1 -0
  253. package/lib/Utils/history.d.ts +76 -0
  254. package/lib/Utils/history.d.ts.map +1 -0
  255. package/lib/Utils/history.js +134 -0
  256. package/lib/Utils/history.js.map +1 -0
  257. package/lib/Utils/identity-change-handler.d.ts +14 -0
  258. package/lib/Utils/identity-change-handler.d.ts.map +1 -0
  259. package/lib/Utils/identity-change-handler.js +50 -0
  260. package/lib/Utils/identity-change-handler.js.map +1 -0
  261. package/lib/Utils/index.d.ts +25 -0
  262. package/lib/Utils/index.d.ts.map +1 -0
  263. package/lib/Utils/index.js +43 -0
  264. package/lib/Utils/index.js.map +1 -0
  265. package/lib/Utils/link-preview.d.ts +13 -0
  266. package/lib/Utils/link-preview.d.ts.map +1 -0
  267. package/lib/Utils/link-preview.js +85 -0
  268. package/lib/Utils/link-preview.js.map +1 -0
  269. package/lib/Utils/logger.d.ts +3 -0
  270. package/lib/Utils/logger.d.ts.map +1 -0
  271. package/lib/Utils/logger.js +3 -0
  272. package/lib/Utils/logger.js.map +1 -0
  273. package/lib/Utils/lt-hash.d.ts +7 -0
  274. package/lib/Utils/lt-hash.d.ts.map +1 -0
  275. package/lib/Utils/lt-hash.js +8 -0
  276. package/lib/Utils/lt-hash.js.map +1 -0
  277. package/lib/Utils/make-mutex.d.ts +7 -0
  278. package/lib/Utils/make-mutex.d.ts.map +1 -0
  279. package/lib/Utils/make-mutex.js +33 -0
  280. package/lib/Utils/make-mutex.js.map +1 -0
  281. package/lib/Utils/message-builder.js +198 -0
  282. package/lib/Utils/message-cache.js +144 -0
  283. package/lib/Utils/message-download-pipeline.js +216 -0
  284. package/lib/Utils/message-error.js +176 -0
  285. package/lib/Utils/message-framework.js +364 -0
  286. package/lib/Utils/message-logger.js +63 -0
  287. package/lib/Utils/message-metrics.js +173 -0
  288. package/lib/Utils/message-pipeline.js +236 -0
  289. package/lib/Utils/message-plugin.js +229 -0
  290. package/lib/Utils/message-queue.js +266 -0
  291. package/lib/Utils/message-retry-adaptive.js +216 -0
  292. package/lib/Utils/message-retry-manager.d.ts +80 -0
  293. package/lib/Utils/message-retry-manager.d.ts.map +1 -0
  294. package/lib/Utils/message-retry-manager.js +265 -0
  295. package/lib/Utils/message-retry-manager.js.map +1 -0
  296. package/lib/Utils/message-upload-pipeline.js +244 -0
  297. package/lib/Utils/messages-media.d.ts +137 -0
  298. package/lib/Utils/messages-media.d.ts.map +1 -0
  299. package/lib/Utils/messages-media.js +843 -0
  300. package/lib/Utils/messages-media.js.map +1 -0
  301. package/lib/Utils/messages.d.ts +46 -0
  302. package/lib/Utils/messages.d.ts.map +1 -0
  303. package/lib/Utils/messages.js +1840 -0
  304. package/lib/Utils/messages.js.map +1 -0
  305. package/lib/Utils/noise-handler.d.ts +21 -0
  306. package/lib/Utils/noise-handler.d.ts.map +1 -0
  307. package/lib/Utils/noise-handler.js +201 -0
  308. package/lib/Utils/noise-handler.js.map +1 -0
  309. package/lib/Utils/offline-node-processor.d.ts +10 -0
  310. package/lib/Utils/offline-node-processor.d.ts.map +1 -0
  311. package/lib/Utils/offline-node-processor.js +40 -0
  312. package/lib/Utils/offline-node-processor.js.map +1 -0
  313. package/lib/Utils/pre-key-manager.d.ts +26 -0
  314. package/lib/Utils/pre-key-manager.d.ts.map +1 -0
  315. package/lib/Utils/pre-key-manager.js +106 -0
  316. package/lib/Utils/pre-key-manager.js.map +1 -0
  317. package/lib/Utils/process-message.d.ts +84 -0
  318. package/lib/Utils/process-message.d.ts.map +1 -0
  319. package/lib/Utils/process-message.js +749 -0
  320. package/lib/Utils/process-message.js.map +1 -0
  321. package/lib/Utils/reliability.js +70 -0
  322. package/lib/Utils/reporting-utils.d.ts +13 -0
  323. package/lib/Utils/reporting-utils.d.ts.map +1 -0
  324. package/lib/Utils/reporting-utils.js +258 -0
  325. package/lib/Utils/reporting-utils.js.map +1 -0
  326. package/lib/Utils/rich-message-utils.d.ts +49 -0
  327. package/lib/Utils/rich-message-utils.d.ts.map +1 -0
  328. package/lib/Utils/rich-message-utils.js +370 -0
  329. package/lib/Utils/rich-message-utils.js.map +1 -0
  330. package/lib/Utils/signal.d.ts +83 -0
  331. package/lib/Utils/signal.d.ts.map +1 -0
  332. package/lib/Utils/signal.js +201 -0
  333. package/lib/Utils/signal.js.map +1 -0
  334. package/lib/Utils/stanza-ack.d.ts +17 -0
  335. package/lib/Utils/stanza-ack.d.ts.map +1 -0
  336. package/lib/Utils/stanza-ack.js +38 -0
  337. package/lib/Utils/stanza-ack.js.map +1 -0
  338. package/lib/Utils/sync-action-utils.d.ts +3 -0
  339. package/lib/Utils/sync-action-utils.d.ts.map +1 -0
  340. package/lib/Utils/sync-action-utils.js +49 -0
  341. package/lib/Utils/sync-action-utils.js.map +1 -0
  342. package/lib/Utils/tc-token-utils.d.ts +30 -0
  343. package/lib/Utils/tc-token-utils.d.ts.map +1 -0
  344. package/lib/Utils/tc-token-utils.js +164 -0
  345. package/lib/Utils/tc-token-utils.js.map +1 -0
  346. package/lib/Utils/use-multi-file-auth-state.d.ts +11 -0
  347. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  348. package/lib/Utils/use-multi-file-auth-state.js +121 -0
  349. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  350. package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
  351. package/lib/Utils/use-single-file-auth-state.d.ts.map +1 -0
  352. package/lib/Utils/use-single-file-auth-state.js +109 -0
  353. package/lib/Utils/use-single-file-auth-state.js.map +1 -0
  354. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  355. package/lib/Utils/use-sqlite-auth-state.d.ts.map +1 -0
  356. package/lib/Utils/use-sqlite-auth-state.js +109 -0
  357. package/lib/Utils/use-sqlite-auth-state.js.map +1 -0
  358. package/lib/Utils/validate-connection.d.ts +44 -0
  359. package/lib/Utils/validate-connection.d.ts.map +1 -0
  360. package/lib/Utils/validate-connection.js +210 -0
  361. package/lib/Utils/validate-connection.js.map +1 -0
  362. package/lib/WABinary/constants.d.ts +62 -0
  363. package/lib/WABinary/constants.d.ts.map +1 -0
  364. package/lib/WABinary/constants.js +1467 -0
  365. package/lib/WABinary/constants.js.map +1 -0
  366. package/lib/WABinary/decode.d.ts +10 -0
  367. package/lib/WABinary/decode.d.ts.map +1 -0
  368. package/lib/WABinary/decode.js +262 -0
  369. package/lib/WABinary/decode.js.map +1 -0
  370. package/lib/WABinary/enchanted-binary.js +38 -0
  371. package/lib/WABinary/encode.d.ts +3 -0
  372. package/lib/WABinary/encode.d.ts.map +1 -0
  373. package/lib/WABinary/encode.js +220 -0
  374. package/lib/WABinary/encode.js.map +1 -0
  375. package/lib/WABinary/generic-utils.d.ts +77 -0
  376. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  377. package/lib/WABinary/generic-utils.js +226 -0
  378. package/lib/WABinary/generic-utils.js.map +1 -0
  379. package/lib/WABinary/index.d.ts +6 -0
  380. package/lib/WABinary/index.d.ts.map +1 -0
  381. package/lib/WABinary/index.js +8 -0
  382. package/lib/WABinary/index.js.map +1 -0
  383. package/lib/WABinary/jid-utils.d.ts +29 -0
  384. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  385. package/lib/WABinary/jid-utils.js +96 -0
  386. package/lib/WABinary/jid-utils.js.map +1 -0
  387. package/lib/WABinary/types.d.ts +2 -0
  388. package/lib/WABinary/types.d.ts.map +1 -0
  389. package/lib/WABinary/types.js +2 -0
  390. package/lib/WABinary/types.js.map +1 -0
  391. package/lib/WABinary/w +1 -0
  392. package/lib/WAM/BinaryInfo.d.ts +8 -0
  393. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  394. package/lib/WAM/BinaryInfo.js +10 -0
  395. package/lib/WAM/BinaryInfo.js.map +1 -0
  396. package/lib/WAM/constants.d.ts +34927 -0
  397. package/lib/WAM/constants.d.ts.map +1 -0
  398. package/lib/WAM/constants.js +22853 -0
  399. package/lib/WAM/constants.js.map +1 -0
  400. package/lib/WAM/encode.d.ts +2 -0
  401. package/lib/WAM/encode.d.ts.map +1 -0
  402. package/lib/WAM/encode.js +150 -0
  403. package/lib/WAM/encode.js.map +1 -0
  404. package/lib/WAM/index.d.ts +4 -0
  405. package/lib/WAM/index.d.ts.map +1 -0
  406. package/lib/WAM/index.js +4 -0
  407. package/lib/WAM/index.js.map +1 -0
  408. package/lib/WAM/w +1 -0
  409. package/lib/WAUSync/Protocols/P +1 -0
  410. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +37 -0
  411. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  412. package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
  413. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  414. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  415. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  416. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
  417. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  418. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  419. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  420. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  421. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  422. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  423. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  424. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  425. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  426. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  427. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
  428. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
  429. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
  430. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
  431. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  432. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  433. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  434. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +15 -0
  435. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  436. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  437. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  438. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  439. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  440. package/lib/WAUSync/Protocols/index.js +6 -0
  441. package/lib/WAUSync/Protocols/index.js.map +1 -0
  442. package/lib/WAUSync/USyncQuery.d.ts +21 -0
  443. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  444. package/lib/WAUSync/USyncQuery.js +98 -0
  445. package/lib/WAUSync/USyncQuery.js.map +1 -0
  446. package/lib/WAUSync/USyncUser.d.ts +17 -0
  447. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  448. package/lib/WAUSync/USyncUser.js +31 -0
  449. package/lib/WAUSync/USyncUser.js.map +1 -0
  450. package/lib/WAUSync/W +1 -0
  451. package/lib/WAUSync/index.d.ts +4 -0
  452. package/lib/WAUSync/index.d.ts.map +1 -0
  453. package/lib/WAUSync/index.js +4 -0
  454. package/lib/WAUSync/index.js.map +1 -0
  455. package/lib/index.d.ts +12 -0
  456. package/lib/index.d.ts.map +1 -0
  457. package/lib/index.js +12 -0
  458. package/lib/index.js.map +1 -0
  459. package/package.json +80 -0
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Error System — Standarisasi semua error pada pipeline send/receive.
3
+ * Setiap error memiliki: code, type, category, retryable, originalError, stack, metadata.
4
+ */
5
+
6
+ export const ErrorCategory = Object.freeze({
7
+ VALIDATION: 'validation',
8
+ NETWORK: 'network',
9
+ ENCRYPTION: 'encryption',
10
+ MEDIA: 'media',
11
+ AUTH: 'auth',
12
+ RATE_LIMIT: 'rate_limit',
13
+ TIMEOUT: 'timeout',
14
+ QUEUE: 'queue',
15
+ PIPELINE: 'pipeline',
16
+ UNKNOWN: 'unknown',
17
+ });
18
+
19
+ export const ErrorType = Object.freeze({
20
+ SEND_FAILED: 'SEND_FAILED',
21
+ RECEIVE_FAILED: 'RECEIVE_FAILED',
22
+ ENCODE_FAILED: 'ENCODE_FAILED',
23
+ DECODE_FAILED: 'DECODE_FAILED',
24
+ ENCRYPT_FAILED: 'ENCRYPT_FAILED',
25
+ DECRYPT_FAILED: 'DECRYPT_FAILED',
26
+ UPLOAD_FAILED: 'UPLOAD_FAILED',
27
+ DOWNLOAD_FAILED: 'DOWNLOAD_FAILED',
28
+ VALIDATION_FAILED: 'VALIDATION_FAILED',
29
+ QUEUE_OVERFLOW: 'QUEUE_OVERFLOW',
30
+ RETRY_EXHAUSTED: 'RETRY_EXHAUSTED',
31
+ CANCELLED: 'CANCELLED',
32
+ TIMEOUT: 'TIMEOUT',
33
+ UNAUTHORIZED: 'UNAUTHORIZED',
34
+ RATE_LIMITED: 'RATE_LIMITED',
35
+ MEDIA_INVALID: 'MEDIA_INVALID',
36
+ MEDIA_TOO_LARGE: 'MEDIA_TOO_LARGE',
37
+ SESSION_INVALID: 'SESSION_INVALID',
38
+ UNKNOWN: 'UNKNOWN',
39
+ });
40
+
41
+ // ─────────────────────────────────────────────
42
+ // BASE PIPELINE ERROR CLASS
43
+ // ─────────────────────────────────────────────
44
+
45
+ export class PipelineError extends Error {
46
+ constructor(message, opts = {}) {
47
+ super(message);
48
+ this.name = 'PipelineError';
49
+ this.code = opts.code || 'ERR_PIPELINE_UNKNOWN';
50
+ this.type = opts.type || ErrorType.UNKNOWN;
51
+ this.category = opts.category || ErrorCategory.UNKNOWN;
52
+ this.retryable = opts.retryable !== undefined ? opts.retryable : false;
53
+ this.originalError = opts.originalError || null;
54
+ this.metadata = opts.metadata || {};
55
+ this.statusCode = opts.statusCode || 500;
56
+ this.timestamp = Date.now();
57
+ if (opts.originalError?.stack) {
58
+ this.stack = `${this.stack}\nCaused by: ${opts.originalError.stack}`;
59
+ }
60
+ }
61
+ toJSON() {
62
+ return {
63
+ name: this.name, message: this.message, code: this.code,
64
+ type: this.type, category: this.category, retryable: this.retryable,
65
+ statusCode: this.statusCode, metadata: this.metadata, timestamp: this.timestamp,
66
+ originalError: this.originalError
67
+ ? { message: this.originalError.message, name: this.originalError.name } : null,
68
+ };
69
+ }
70
+ }
71
+
72
+ export class SendError extends PipelineError {
73
+ constructor(message, opts = {}) {
74
+ super(message, { code: 'ERR_SEND', type: ErrorType.SEND_FAILED,
75
+ category: ErrorCategory.NETWORK, retryable: true, ...opts });
76
+ this.name = 'SendError';
77
+ }
78
+ }
79
+
80
+ export class ReceiveError extends PipelineError {
81
+ constructor(message, opts = {}) {
82
+ super(message, { code: 'ERR_RECEIVE', type: ErrorType.RECEIVE_FAILED,
83
+ category: ErrorCategory.NETWORK, retryable: false, ...opts });
84
+ this.name = 'ReceiveError';
85
+ }
86
+ }
87
+
88
+ export class EncodeError extends PipelineError {
89
+ constructor(message, opts = {}) {
90
+ super(message, { code: 'ERR_ENCODE', type: ErrorType.ENCODE_FAILED,
91
+ category: ErrorCategory.ENCRYPTION, retryable: false, ...opts });
92
+ this.name = 'EncodeError';
93
+ }
94
+ }
95
+
96
+ export class DecodeError extends PipelineError {
97
+ constructor(message, opts = {}) {
98
+ super(message, { code: 'ERR_DECODE', type: ErrorType.DECODE_FAILED,
99
+ category: ErrorCategory.ENCRYPTION, retryable: true, ...opts });
100
+ this.name = 'DecodeError';
101
+ }
102
+ }
103
+
104
+ export class MediaUploadError extends PipelineError {
105
+ constructor(message, opts = {}) {
106
+ super(message, { code: 'ERR_MEDIA_UPLOAD', type: ErrorType.UPLOAD_FAILED,
107
+ category: ErrorCategory.MEDIA, retryable: true, ...opts });
108
+ this.name = 'MediaUploadError';
109
+ }
110
+ }
111
+
112
+ export class MediaDownloadError extends PipelineError {
113
+ constructor(message, opts = {}) {
114
+ super(message, { code: 'ERR_MEDIA_DOWNLOAD', type: ErrorType.DOWNLOAD_FAILED,
115
+ category: ErrorCategory.MEDIA, retryable: true, ...opts });
116
+ this.name = 'MediaDownloadError';
117
+ }
118
+ }
119
+
120
+ export class ValidationError extends PipelineError {
121
+ constructor(message, opts = {}) {
122
+ super(message, { code: 'ERR_VALIDATION', type: ErrorType.VALIDATION_FAILED,
123
+ category: ErrorCategory.VALIDATION, retryable: false, statusCode: 400, ...opts });
124
+ this.name = 'ValidationError';
125
+ }
126
+ }
127
+
128
+ export class RetryExhaustedError extends PipelineError {
129
+ constructor(message, opts = {}) {
130
+ super(message, { code: 'ERR_RETRY_EXHAUSTED', type: ErrorType.RETRY_EXHAUSTED,
131
+ category: ErrorCategory.NETWORK, retryable: false, ...opts });
132
+ this.name = 'RetryExhaustedError';
133
+ }
134
+ }
135
+
136
+ export class QueueOverflowError extends PipelineError {
137
+ constructor(message, opts = {}) {
138
+ super(message, { code: 'ERR_QUEUE_OVERFLOW', type: ErrorType.QUEUE_OVERFLOW,
139
+ category: ErrorCategory.QUEUE, retryable: true, statusCode: 429, ...opts });
140
+ this.name = 'QueueOverflowError';
141
+ }
142
+ }
143
+
144
+ export class TimeoutError extends PipelineError {
145
+ constructor(message, opts = {}) {
146
+ super(message, { code: 'ERR_TIMEOUT', type: ErrorType.TIMEOUT,
147
+ category: ErrorCategory.TIMEOUT, retryable: true, statusCode: 408, ...opts });
148
+ this.name = 'TimeoutError';
149
+ }
150
+ }
151
+
152
+ export class RateLimitError extends PipelineError {
153
+ constructor(message, opts = {}) {
154
+ super(message, { code: 'ERR_RATE_LIMIT', type: ErrorType.RATE_LIMITED,
155
+ category: ErrorCategory.RATE_LIMIT, retryable: true, statusCode: 429, ...opts });
156
+ this.name = 'RateLimitError';
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Konversi error apapun menjadi PipelineError terstandarisasi.
162
+ */
163
+ export function normalizeToPipelineError(err, defaultOpts = {}) {
164
+ if (err instanceof PipelineError) return err;
165
+ if (err?.isBoom) {
166
+ const statusCode = err.output?.statusCode || 500;
167
+ const retryable = statusCode >= 500 || statusCode === 429 || statusCode === 408;
168
+ return new PipelineError(err.message, {
169
+ code: `ERR_BOOM_${statusCode}`,
170
+ type: statusCode >= 500 ? ErrorType.SEND_FAILED : ErrorType.VALIDATION_FAILED,
171
+ category: statusCode >= 500 ? ErrorCategory.NETWORK : ErrorCategory.VALIDATION,
172
+ retryable, statusCode, originalError: err, metadata: err.data || {}, ...defaultOpts,
173
+ });
174
+ }
175
+ return new PipelineError(err?.message || 'Unknown error', { originalError: err, ...defaultOpts });
176
+ }
@@ -0,0 +1,364 @@
1
+ /**
2
+ * MessageFramework — Entry point utama yang menggabungkan semua sistem:
3
+ * Pipeline, Hook, Queue, Cache, Metrics, Logger, Retry, Plugin, Builder.
4
+ *
5
+ * Digunakan oleh messages-send.js dan messages-recv.js sebagai fondasi framework.
6
+ */
7
+
8
+ import { PipelineRegistry, HookSystem, createMessageContext, LifecycleEvents } from './message-pipeline.js';
9
+ import { PipelineLogger, pipelineLogger } from './message-logger.js';
10
+ import { MetricsRegistry, globalMetrics } from './message-metrics.js';
11
+ import { MessageQueue, QueueManager, globalQueueManager } from './message-queue.js';
12
+ import { CacheRegistry, globalCache } from './message-cache.js';
13
+ import { AdaptiveRetryManager, DEFAULT_SEND_POLICY, DEFAULT_MEDIA_POLICY } from './message-retry-adaptive.js';
14
+ import { PluginManager, globalPluginManager } from './message-plugin.js';
15
+ import { MessageBuilder, globalMessageBuilder, createBuildContext } from './message-builder.js';
16
+ import { UploadPipeline, globalUploadPipeline, createUploadContext } from './message-upload-pipeline.js';
17
+ import { DownloadPipeline, globalDownloadPipeline, createDownloadContext } from './message-download-pipeline.js';
18
+ import { normalizeToPipelineError } from './message-error.js';
19
+
20
+ // ─────────────────────────────────────────────
21
+ // FRAMEWORK CLASS
22
+ // ─────────────────────────────────────────────
23
+
24
+ export class MessageFramework {
25
+ /**
26
+ * @param {object} config — Baileys socket config
27
+ */
28
+ constructor(config = {}) {
29
+ const logger = config.logger ?? null;
30
+
31
+ // ── Core Logger ───────────────────────────────────────────────────────
32
+ this.logger = new PipelineLogger({
33
+ logger,
34
+ prefix: '[protection]',
35
+ minLevel: config.frameworkLogLevel ?? 1, // DEBUG
36
+ });
37
+
38
+ // ── Metrics ───────────────────────────────────────────────────────────
39
+ this.metrics = new MetricsRegistry();
40
+
41
+ // ── Cache ─────────────────────────────────────────────────────────────
42
+ this.cache = new CacheRegistry({ adapter: config.frameworkCacheAdapter });
43
+
44
+ // ── Hook + Pipeline ───────────────────────────────────────────────────
45
+ this.hooks = new HookSystem();
46
+ this.pipeline = new PipelineRegistry();
47
+ this.pipeline.hooks = this.hooks;
48
+
49
+ // ── Queue Manager ─────────────────────────────────────────────────────
50
+ this.queue = new QueueManager();
51
+ this.sendQueue = this.queue.getQueue('send', {
52
+ maxSize: config.sendQueueMaxSize ?? 10_000,
53
+ concurrency: config.sendQueueConcurrency ?? 5,
54
+ rateLimitPerSec: config.sendQueueRateLimit ?? 20,
55
+ rateLimitBurst: config.sendQueueBurst ?? 30,
56
+ deduplication: config.sendQueueDedup !== false,
57
+ onError: (err, item) => {
58
+ this.logger.error(`Queue send error [${item.id}]: ${err?.message}`, { err });
59
+ this.metrics.inc('errors.total');
60
+ },
61
+ onMetrics: (event, data) => {
62
+ if (event === 'enqueued') this.metrics.inc('queue.enqueued');
63
+ if (event === 'dequeued') this.metrics.inc('queue.dequeued');
64
+ if (event === 'dropped') this.metrics.inc('queue.dropped');
65
+ if (data?.waitMs !== undefined) this.metrics.observe('queue.wait_ms', data.waitMs);
66
+ if (data?.size !== undefined) this.metrics.set('queue.size', data.size);
67
+ },
68
+ });
69
+
70
+ // ── Retry Manager ─────────────────────────────────────────────────────
71
+ this.retryManager = new AdaptiveRetryManager({
72
+ logger,
73
+ metrics: this.metrics,
74
+ hooks: this.hooks,
75
+ });
76
+
77
+ // ── Plugin Manager ────────────────────────────────────────────────────
78
+ this.plugins = new PluginManager({
79
+ logger,
80
+ hooks: this.hooks,
81
+ metrics: this.metrics,
82
+ });
83
+
84
+ // ── Message Builder ───────────────────────────────────────────────────
85
+ this.builder = new MessageBuilder({
86
+ logger,
87
+ hooks: this.hooks,
88
+ metrics: this.metrics,
89
+ plugins: this.plugins,
90
+ });
91
+
92
+ // ── Upload Pipeline ───────────────────────────────────────────────────
93
+ this.uploadPipeline = new UploadPipeline({
94
+ logger,
95
+ hooks: this.hooks,
96
+ metrics: this.metrics,
97
+ cache: this.cache,
98
+ retryPolicy: config.mediaRetryPolicy ?? DEFAULT_MEDIA_POLICY,
99
+ timeoutMs: config.mediaUploadTimeoutMs ?? 120_000,
100
+ });
101
+
102
+ // ── Download Pipeline ─────────────────────────────────────────────────
103
+ this.downloadPipeline = new DownloadPipeline({
104
+ logger,
105
+ hooks: this.hooks,
106
+ metrics: this.metrics,
107
+ cache: this.cache,
108
+ retryPolicy: config.mediaRetryPolicy ?? DEFAULT_MEDIA_POLICY,
109
+ timeoutMs: config.mediaDownloadTimeoutMs ?? 60_000,
110
+ });
111
+
112
+ // ── Retry Policies ────────────────────────────────────────────────────
113
+ this.sendPolicy = config.sendRetryPolicy ?? DEFAULT_SEND_POLICY;
114
+ this.mediaPolicy = config.mediaRetryPolicy ?? DEFAULT_MEDIA_POLICY;
115
+
116
+ this._config = config;
117
+ this._attached = false;
118
+ this.socket = null;
119
+ }
120
+
121
+ // ─────────────────────────────────────────
122
+ // ATTACH / TEARDOWN
123
+ // ─────────────────────────────────────────
124
+
125
+ /**
126
+ * Attach framework ke socket Baileys.
127
+ * Dipanggil dari makeMessagesSocket().
128
+ *
129
+ * @param {object} socket — partial atau full socket instance
130
+ */
131
+ attach(socket) {
132
+ if (this._attached) return this;
133
+ this.socket = socket;
134
+
135
+ // Wire plugins
136
+ if (socket?.ev) {
137
+ this.plugins.attach(socket, this.pipeline);
138
+ }
139
+
140
+ // Bridge framework logger ke socket logger
141
+ if (this._config.logger) {
142
+ this.logger.setCustomLogger((level, msg, data) => {
143
+ if (this._config.logger?.[level]) {
144
+ this._config.logger[level](data ?? {}, msg);
145
+ }
146
+ });
147
+ }
148
+
149
+ // Wire events ke metrics
150
+ if (socket?.ev) {
151
+ socket.ev.on('messages.upsert', ({ messages, type }) => {
152
+ if (type === 'notify') {
153
+ this.metrics.inc('messages.received.total', messages?.length ?? 1);
154
+ }
155
+ });
156
+ socket.ev.on('messages.update', (updates) => {
157
+ this.metrics.inc('messages.updated.total', updates?.length ?? 1);
158
+ });
159
+ socket.ev.on('connection.update', (update) => {
160
+ if (update.connection === 'open') this.metrics.gauge('connections.active').inc();
161
+ if (update.connection === 'close') this.metrics.gauge('connections.active').dec();
162
+ });
163
+ }
164
+
165
+ this._attached = true;
166
+ this.logger.info('MessageFramework berhasil di-attach ke socket');
167
+ return this;
168
+ }
169
+
170
+ /**
171
+ * Teardown — dipanggil saat socket ditutup.
172
+ */
173
+ async teardown() {
174
+ try {
175
+ this.sendQueue?.stop();
176
+ this.queue?.stopAll();
177
+ await this.plugins?.uninstallAll?.();
178
+ this.hooks?.removeAll();
179
+ this._attached = false;
180
+ this.logger.info('MessageFramework di-teardown');
181
+ } catch (_) {}
182
+ }
183
+
184
+ // ─────────────────────────────────────────
185
+ // CONTEXT FACTORIES
186
+ // ─────────────────────────────────────────
187
+
188
+ createContext(overrides = {}) {
189
+ return createMessageContext({ socket: this.socket, ...overrides });
190
+ }
191
+ createBuildContext(overrides = {}) { return createBuildContext(overrides); }
192
+ createUploadContext(overrides = {}) { return createUploadContext(overrides); }
193
+ createDownloadContext(overrides = {}) { return createDownloadContext(overrides); }
194
+
195
+ // ─────────────────────────────────────────
196
+ // PLUGIN / MIDDLEWARE / HOOK SHORTCUTS
197
+ // ─────────────────────────────────────────
198
+
199
+ /** Install plugin */
200
+ async use(plugin) { await this.plugins.install(plugin); return this; }
201
+
202
+ /** Daftarkan middleware pipeline */
203
+ middleware(pipelineName, fn, priority = 0) {
204
+ this.pipeline.use(pipelineName, fn, priority);
205
+ return this;
206
+ }
207
+
208
+ /** Daftarkan lifecycle hook */
209
+ hook(event, handler) { this.hooks.on(event, handler); return this; }
210
+
211
+ // ─────────────────────────────────────────
212
+ // QUEUE SEND
213
+ // ─────────────────────────────────────────
214
+
215
+ /**
216
+ * Tambahkan task ke send queue.
217
+ * @param {Function} sendFn — async () => result
218
+ * @param {object} opts — { priority, delayMs, dedupKey, jid }
219
+ */
220
+ queueSend(sendFn, opts = {}) {
221
+ return this.sendQueue.enqueue(sendFn, opts);
222
+ }
223
+
224
+ // ─────────────────────────────────────────
225
+ // METRICS
226
+ // ─────────────────────────────────────────
227
+
228
+ /** Ambil semua metrics */
229
+ getMetrics() {
230
+ return {
231
+ framework: this.metrics.getAll(),
232
+ queues: this.queue.getAllStats(),
233
+ cache: this.cache.stats,
234
+ retry: this.retryManager.getStats(),
235
+ plugins: this.plugins.list(),
236
+ };
237
+ }
238
+
239
+ // ─────────────────────────────────────────
240
+ // PIPELINE RUNNERS
241
+ // ─────────────────────────────────────────
242
+
243
+ /**
244
+ * Jalankan full send pipeline: before → relay → after + hooks.
245
+ */
246
+ async runSendPipeline(relayFn, ctx) {
247
+ const start = Date.now();
248
+ await this._emitHook(LifecycleEvents.SEND_START, ctx);
249
+
250
+ await this.pipeline.beforeSend.run(ctx, async () => {});
251
+ if (ctx.cancelled) {
252
+ this.logger.info(`[Framework] Send dibatalkan: ${ctx.jid}`);
253
+ return null;
254
+ }
255
+
256
+ let result;
257
+ try {
258
+ result = await this.retryManager.run(
259
+ relayFn,
260
+ this.sendPolicy,
261
+ ctx.metadata?.msgId,
262
+ { type: 'send', jid: ctx.jid }
263
+ );
264
+ this.metrics.inc('messages.sent.total');
265
+ this.metrics.observe('send.duration_ms', Date.now() - start);
266
+ ctx.result = result;
267
+ ctx.timestamps.sent = Date.now();
268
+ } catch (err) {
269
+ ctx.error = normalizeToPipelineError(err);
270
+ this.metrics.inc('messages.failed.total');
271
+ this.metrics.inc('errors.total');
272
+ await this._emitHook(LifecycleEvents.SEND_FAILED, ctx);
273
+ throw ctx.error;
274
+ }
275
+
276
+ await this.pipeline.afterSend.run(ctx, async () => {});
277
+ await this._emitHook(LifecycleEvents.SEND_FINISH, ctx);
278
+ return result;
279
+ }
280
+
281
+ /**
282
+ * Jalankan full receive pipeline.
283
+ */
284
+ async runReceivePipeline(processFn, ctx) {
285
+ const start = Date.now();
286
+ await this._emitHook(LifecycleEvents.MESSAGE_RECEIVE, ctx);
287
+
288
+ await this.pipeline.beforeReceive.run(ctx, async () => {});
289
+ if (ctx.cancelled) return null;
290
+
291
+ let result;
292
+ try {
293
+ result = await processFn();
294
+ this.metrics.inc('messages.received.total');
295
+ this.metrics.observe('receive.duration_ms', Date.now() - start);
296
+ ctx.result = result;
297
+ ctx.timestamps.received = Date.now();
298
+ } catch (err) {
299
+ ctx.error = normalizeToPipelineError(err);
300
+ this.metrics.inc('errors.total');
301
+ throw ctx.error;
302
+ }
303
+
304
+ await this.pipeline.afterReceive.run(ctx, async () => {});
305
+ return result;
306
+ }
307
+
308
+ /**
309
+ * Jalankan full decode pipeline.
310
+ */
311
+ async runDecodePipeline(decodeFn, ctx) {
312
+ const start = Date.now();
313
+ await this._emitHook(LifecycleEvents.MESSAGE_DECODE, ctx);
314
+
315
+ await this.pipeline.beforeDecode.run(ctx, async () => {});
316
+ if (ctx.cancelled) return null;
317
+
318
+ let result;
319
+ try {
320
+ result = await decodeFn();
321
+ this.metrics.inc('decode.total');
322
+ this.metrics.observe('decode.duration_ms', Date.now() - start);
323
+ ctx.timestamps.decoded = Date.now();
324
+ } catch (err) {
325
+ ctx.error = normalizeToPipelineError(err);
326
+ this.metrics.inc('errors.total');
327
+ throw ctx.error;
328
+ }
329
+
330
+ await this.pipeline.afterDecode.run(ctx, async () => {});
331
+ return result;
332
+ }
333
+
334
+ // ── Internal ──────────────────────────────
335
+
336
+ async _emitHook(event, ctx) {
337
+ if (this.hooks) {
338
+ try { await this.hooks.emit(event, ctx); } catch (_) {}
339
+ }
340
+ this.metrics.inc('hooks.fired');
341
+ }
342
+ }
343
+
344
+ // ─────────────────────────────────────────────
345
+ // FACTORY
346
+ // ─────────────────────────────────────────────
347
+
348
+ export function createMessageFramework(config) {
349
+ return new MessageFramework(config);
350
+ }
351
+
352
+ // Re-export semua subsystems untuk akses langsung
353
+ export {
354
+ PipelineRegistry, HookSystem, createMessageContext, LifecycleEvents,
355
+ PipelineLogger, pipelineLogger,
356
+ MetricsRegistry, globalMetrics,
357
+ MessageQueue, QueueManager, globalQueueManager,
358
+ CacheRegistry, globalCache,
359
+ AdaptiveRetryManager, DEFAULT_SEND_POLICY, DEFAULT_MEDIA_POLICY,
360
+ PluginManager, globalPluginManager,
361
+ MessageBuilder, globalMessageBuilder, createBuildContext,
362
+ UploadPipeline, globalUploadPipeline, createUploadContext,
363
+ DownloadPipeline, globalDownloadPipeline, createDownloadContext,
364
+ };
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Logger Integration — Internal logger dengan level lengkap dan custom logger support.
3
+ * Level: trace(0) debug(1) info(2) warn(3) error(4) fatal(5)
4
+ */
5
+
6
+ export const LogLevel = Object.freeze({
7
+ TRACE: 0, DEBUG: 1, INFO: 2, WARN: 3, ERROR: 4, FATAL: 5, SILENT: 99,
8
+ });
9
+
10
+ const LEVEL_NAMES = { 0:'trace', 1:'debug', 2:'info', 3:'warn', 4:'error', 5:'fatal' };
11
+
12
+ export class PipelineLogger {
13
+ constructor(opts = {}) {
14
+ this._logger = opts.logger || null;
15
+ this._prefix = opts.prefix || '[Pipeline]';
16
+ this._minLevel = opts.minLevel !== undefined ? opts.minLevel : LogLevel.DEBUG;
17
+ this._customFn = null;
18
+ }
19
+
20
+ setCustomLogger(fn) {
21
+ if (typeof fn !== 'function') throw new TypeError('Custom logger harus berupa function');
22
+ this._customFn = fn;
23
+ return this;
24
+ }
25
+
26
+ setLevel(level) { this._minLevel = level; return this; }
27
+
28
+ _log(level, msg, data) {
29
+ if (level < this._minLevel) return;
30
+ const lvName = LEVEL_NAMES[level] || 'debug';
31
+ const full = `${this._prefix} ${msg}`;
32
+
33
+ if (this._customFn) {
34
+ try { this._customFn(lvName, full, data); } catch (_) {}
35
+ return;
36
+ }
37
+ if (this._logger && typeof this._logger[lvName] === 'function') {
38
+ data !== undefined ? this._logger[lvName](data, full) : this._logger[lvName](full);
39
+ return;
40
+ }
41
+ const out = data !== undefined ? [full, data] : [full];
42
+ level >= LogLevel.ERROR ? console.error(...out)
43
+ : level >= LogLevel.WARN ? console.warn(...out)
44
+ : console.log(...out);
45
+ }
46
+
47
+ trace(msg, data) { this._log(LogLevel.TRACE, msg, data); }
48
+ debug(msg, data) { this._log(LogLevel.DEBUG, msg, data); }
49
+ info (msg, data) { this._log(LogLevel.INFO, msg, data); }
50
+ warn (msg, data) { this._log(LogLevel.WARN, msg, data); }
51
+ error(msg, data) { this._log(LogLevel.ERROR, msg, data); }
52
+ fatal(msg, data) { this._log(LogLevel.FATAL, msg, data); }
53
+
54
+ child(prefix) {
55
+ return new PipelineLogger({
56
+ logger: this._logger,
57
+ prefix: `${this._prefix}:${prefix}`,
58
+ minLevel: this._minLevel,
59
+ });
60
+ }
61
+ }
62
+
63
+ export const pipelineLogger = new PipelineLogger({ prefix: '[protection]' });