@deffa5556/bail 1.0.6 → 1.0.7

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 (314) hide show
  1. package/cjs/WAProto/index.cjs +106053 -0
  2. package/cjs/deffa/config.cjs +14 -0
  3. package/cjs/deffa/plugins/ai/deepseekr1.cjs +35 -0
  4. package/cjs/deffa/plugins/ai/gita.cjs +26 -0
  5. package/cjs/deffa/plugins/ai/glm47flash.cjs +35 -0
  6. package/cjs/deffa/plugins/ai/gptoss120b.cjs +35 -0
  7. package/cjs/deffa/plugins/ai/qwq32b.cjs +35 -0
  8. package/cjs/deffa/plugins/berita/antara.cjs +25 -0
  9. package/cjs/deffa/plugins/berita/cnbcindonesia.cjs +25 -0
  10. package/cjs/deffa/plugins/berita/cnn.cjs +25 -0
  11. package/cjs/deffa/plugins/berita/kompas.cjs +25 -0
  12. package/cjs/deffa/plugins/berita/liputan6.cjs +25 -0
  13. package/cjs/deffa/plugins/berita/merdeka.cjs +25 -0
  14. package/cjs/deffa/plugins/berita/sindonews.cjs +25 -0
  15. package/cjs/deffa/plugins/berita/tribunnews.cjs +25 -0
  16. package/cjs/deffa/plugins/downloader/douyin.cjs +30 -0
  17. package/cjs/deffa/plugins/downloader/facebook.cjs +30 -0
  18. package/cjs/deffa/plugins/downloader/github.cjs +35 -0
  19. package/cjs/deffa/plugins/downloader/lahelu.cjs +30 -0
  20. package/cjs/deffa/plugins/downloader/snackvideo.cjs +30 -0
  21. package/cjs/deffa/plugins/downloader/soundcloud.cjs +30 -0
  22. package/cjs/deffa/plugins/downloader/tiktok.cjs +30 -0
  23. package/cjs/deffa/plugins/downloader/tiktokhd.cjs +30 -0
  24. package/cjs/deffa/plugins/downloader/twitter.cjs +30 -0
  25. package/cjs/deffa/plugins/downloader/ummy.cjs +36 -0
  26. package/cjs/deffa/plugins/index.cjs +213 -0
  27. package/cjs/deffa/plugins/info/bmkg.cjs +34 -0
  28. package/cjs/deffa/plugins/info/cuaca.cjs +31 -0
  29. package/cjs/deffa/plugins/info/jadwaltv.cjs +29 -0
  30. package/cjs/deffa/plugins/maker/brat.cjs +45 -0
  31. package/cjs/deffa/plugins/maker/bratvid.cjs +52 -0
  32. package/cjs/deffa/plugins/search/8font.cjs +28 -0
  33. package/cjs/deffa/plugins/search/applemusic.cjs +28 -0
  34. package/cjs/deffa/plugins/search/bimg.cjs +30 -0
  35. package/cjs/deffa/plugins/search/brave.cjs +34 -0
  36. package/cjs/deffa/plugins/search/duckduckgo.cjs +28 -0
  37. package/cjs/deffa/plugins/search/lahelu.cjs +28 -0
  38. package/cjs/deffa/plugins/search/mangatoon.cjs +28 -0
  39. package/cjs/deffa/plugins/search/mcpedl.cjs +28 -0
  40. package/cjs/deffa/plugins/search/myinstants.cjs +28 -0
  41. package/cjs/deffa/plugins/search/otakotaku.cjs +28 -0
  42. package/cjs/deffa/plugins/search/pinterest.cjs +30 -0
  43. package/cjs/deffa/plugins/search/resep.cjs +28 -0
  44. package/cjs/deffa/plugins/search/seegore.cjs +30 -0
  45. package/cjs/deffa/plugins/search/soundcloud.cjs +28 -0
  46. package/cjs/deffa/plugins/search/youtube.cjs +28 -0
  47. package/cjs/deffa/plugins/stalk/github.cjs +38 -0
  48. package/cjs/deffa/plugins/stalk/pinterest.cjs +37 -0
  49. package/cjs/deffa/plugins/stalk/threads.cjs +34 -0
  50. package/cjs/deffa/plugins/stalk/tiktok.cjs +37 -0
  51. package/cjs/deffa/plugins/stalk/twitter.cjs +37 -0
  52. package/cjs/deffa/plugins/stalk/youtube.cjs +37 -0
  53. package/cjs/lib/Defaults/index.cjs +158 -0
  54. package/cjs/lib/Discord/Client.cjs +263 -0
  55. package/cjs/lib/Discord/Constants.cjs +1842 -0
  56. package/cjs/lib/Discord/connect-dc.cjs +11 -0
  57. package/cjs/lib/Discord/esm-bridge.cjs +136 -0
  58. package/cjs/lib/Discord/gateway/Dispatcher.cjs +93 -0
  59. package/cjs/lib/Discord/gateway/Shard.cjs +695 -0
  60. package/cjs/lib/Discord/gateway/ShardManager.cjs +344 -0
  61. package/cjs/lib/Discord/gateway/compression/base.cjs +13 -0
  62. package/cjs/lib/Discord/gateway/compression/config.cjs +47 -0
  63. package/cjs/lib/Discord/gateway/compression/pako.cjs +44 -0
  64. package/cjs/lib/Discord/gateway/compression/zlib-native.cjs +47 -0
  65. package/cjs/lib/Discord/gateway/compression/zlib-sync.cjs +31 -0
  66. package/cjs/lib/Discord/gateway/compression/zstd-napi.cjs +80 -0
  67. package/cjs/lib/Discord/gateway/compression/zstd-native.cjs +46 -0
  68. package/cjs/lib/Discord/gateway/events.cjs +956 -0
  69. package/cjs/lib/Discord/index.cjs +238 -0
  70. package/cjs/lib/Discord/rest/Bucket.cjs +69 -0
  71. package/cjs/lib/Discord/rest/DiscordHTTPError.cjs +63 -0
  72. package/cjs/lib/Discord/rest/DiscordRESTError.cjs +84 -0
  73. package/cjs/lib/Discord/rest/OAuthHelper.cjs +226 -0
  74. package/cjs/lib/Discord/rest/RESTManager.cjs +116 -0
  75. package/cjs/lib/Discord/rest/RequestHandler.cjs +320 -0
  76. package/cjs/lib/Discord/rest/SequentialBucket.cjs +69 -0
  77. package/cjs/lib/Discord/routes/Applications.cjs +625 -0
  78. package/cjs/lib/Discord/routes/Channels.cjs +1199 -0
  79. package/cjs/lib/Discord/routes/Guilds.cjs +1792 -0
  80. package/cjs/lib/Discord/routes/Interactions.cjs +212 -0
  81. package/cjs/lib/Discord/routes/Lobbies.cjs +197 -0
  82. package/cjs/lib/Discord/routes/Miscellaneous.cjs +120 -0
  83. package/cjs/lib/Discord/routes/OAuth.cjs +350 -0
  84. package/cjs/lib/Discord/routes/Users.cjs +107 -0
  85. package/cjs/lib/Discord/routes/Webhooks.cjs +308 -0
  86. package/cjs/lib/Discord/structures/AnnouncementChannel.cjs +46 -0
  87. package/cjs/lib/Discord/structures/AnnouncementThreadChannel.cjs +28 -0
  88. package/cjs/lib/Discord/structures/Application.cjs +345 -0
  89. package/cjs/lib/Discord/structures/ApplicationCommand.cjs +109 -0
  90. package/cjs/lib/Discord/structures/Attachment.cjs +46 -0
  91. package/cjs/lib/Discord/structures/AuditLogEntry.cjs +41 -0
  92. package/cjs/lib/Discord/structures/AutoModerationRule.cjs +117 -0
  93. package/cjs/lib/Discord/structures/AutocompleteInteraction.cjs +90 -0
  94. package/cjs/lib/Discord/structures/Base.cjs +56 -0
  95. package/cjs/lib/Discord/structures/BaseEntitlement.cjs +40 -0
  96. package/cjs/lib/Discord/structures/CategoryChannel.cjs +102 -0
  97. package/cjs/lib/Discord/structures/Channel.cjs +89 -0
  98. package/cjs/lib/Discord/structures/ClientApplication.cjs +269 -0
  99. package/cjs/lib/Discord/structures/CommandInteraction.cjs +294 -0
  100. package/cjs/lib/Discord/structures/ComponentInteraction.cjs +306 -0
  101. package/cjs/lib/Discord/structures/Entitlement.cjs +24 -0
  102. package/cjs/lib/Discord/structures/ExtendedUser.cjs +48 -0
  103. package/cjs/lib/Discord/structures/ForumChannel.cjs +20 -0
  104. package/cjs/lib/Discord/structures/GroupChannel.cjs +160 -0
  105. package/cjs/lib/Discord/structures/Guild.cjs +1289 -0
  106. package/cjs/lib/Discord/structures/GuildChannel.cjs +82 -0
  107. package/cjs/lib/Discord/structures/GuildPreview.cjs +141 -0
  108. package/cjs/lib/Discord/structures/GuildScheduledEvent.cjs +166 -0
  109. package/cjs/lib/Discord/structures/GuildTemplate.cjs +96 -0
  110. package/cjs/lib/Discord/structures/Integration.cjs +123 -0
  111. package/cjs/lib/Discord/structures/Interaction.cjs +78 -0
  112. package/cjs/lib/Discord/structures/InteractionResolvedChannel.cjs +36 -0
  113. package/cjs/lib/Discord/structures/Invite.cjs +196 -0
  114. package/cjs/lib/Discord/structures/InviteGuild.cjs +117 -0
  115. package/cjs/lib/Discord/structures/InviteRole.cjs +88 -0
  116. package/cjs/lib/Discord/structures/Lobby.cjs +84 -0
  117. package/cjs/lib/Discord/structures/LobbyMember.cjs +30 -0
  118. package/cjs/lib/Discord/structures/MediaChannel.cjs +20 -0
  119. package/cjs/lib/Discord/structures/Member.cjs +300 -0
  120. package/cjs/lib/Discord/structures/Message.cjs +553 -0
  121. package/cjs/lib/Discord/structures/ModalSubmitInteraction.cjs +263 -0
  122. package/cjs/lib/Discord/structures/OAuthApplication.cjs +203 -0
  123. package/cjs/lib/Discord/structures/OAuthGuild.cjs +98 -0
  124. package/cjs/lib/Discord/structures/PartialApplication.cjs +97 -0
  125. package/cjs/lib/Discord/structures/Permission.cjs +61 -0
  126. package/cjs/lib/Discord/structures/PermissionOverwrite.cjs +46 -0
  127. package/cjs/lib/Discord/structures/PingInteraction.cjs +27 -0
  128. package/cjs/lib/Discord/structures/Poll.cjs +69 -0
  129. package/cjs/lib/Discord/structures/PrimaryGuild.cjs +93 -0
  130. package/cjs/lib/Discord/structures/PrivateChannel.cjs +131 -0
  131. package/cjs/lib/Discord/structures/PrivateThreadChannel.cjs +28 -0
  132. package/cjs/lib/Discord/structures/PublicThreadChannel.cjs +36 -0
  133. package/cjs/lib/Discord/structures/Role.cjs +126 -0
  134. package/cjs/lib/Discord/structures/SKU.cjs +58 -0
  135. package/cjs/lib/Discord/structures/Soundboard.cjs +58 -0
  136. package/cjs/lib/Discord/structures/StageChannel.cjs +45 -0
  137. package/cjs/lib/Discord/structures/StageInstance.cjs +80 -0
  138. package/cjs/lib/Discord/structures/Subscription.cjs +21 -0
  139. package/cjs/lib/Discord/structures/Team.cjs +70 -0
  140. package/cjs/lib/Discord/structures/TestEntitlement.cjs +22 -0
  141. package/cjs/lib/Discord/structures/TextChannel.cjs +48 -0
  142. package/cjs/lib/Discord/structures/TextableChannel.cjs +265 -0
  143. package/cjs/lib/Discord/structures/TextableVoiceChannel.cjs +70 -0
  144. package/cjs/lib/Discord/structures/ThreadChannel.cjs +276 -0
  145. package/cjs/lib/Discord/structures/ThreadOnlyChannel.cjs +205 -0
  146. package/cjs/lib/Discord/structures/ThreadableChannel.cjs +57 -0
  147. package/cjs/lib/Discord/structures/UnavailableGuild.cjs +21 -0
  148. package/cjs/lib/Discord/structures/User.cjs +223 -0
  149. package/cjs/lib/Discord/structures/VoiceChannel.cjs +34 -0
  150. package/cjs/lib/Discord/structures/VoiceState.cjs +113 -0
  151. package/cjs/lib/Discord/structures/Webhook.cjs +224 -0
  152. package/cjs/lib/Discord/util/Collection.cjs +77 -0
  153. package/cjs/lib/Discord/util/Errors.cjs +81 -0
  154. package/cjs/lib/Discord/util/QueryBuilder.cjs +20 -0
  155. package/cjs/lib/Discord/util/Routes.cjs +293 -0
  156. package/cjs/lib/Discord/util/SimpleCollection.cjs +78 -0
  157. package/cjs/lib/Discord/util/Time.cjs +92 -0
  158. package/cjs/lib/Discord/util/TypedCollection.cjs +78 -0
  159. package/cjs/lib/Discord/util/TypedEmitter.cjs +20 -0
  160. package/cjs/lib/Discord/util/Util.cjs +906 -0
  161. package/cjs/lib/Discord/util/interactions/InteractionOptionsWrapper.cjs +207 -0
  162. package/cjs/lib/Discord/util/interactions/MessageInteractionResponse.cjs +26 -0
  163. package/cjs/lib/Discord/util/interactions/ModalSubmitInteractionComponentsWrapper.cjs +98 -0
  164. package/cjs/lib/Discord/util/interactions/SelectMenuValuesWrapper.cjs +77 -0
  165. package/cjs/lib/Discord/util/interactions/shared.cjs +20 -0
  166. package/cjs/lib/Discord/util/warning.cjs +34 -0
  167. package/cjs/lib/Signal/Group/ciphertext-message.cjs +16 -0
  168. package/cjs/lib/Signal/Group/group-session-builder.cjs +67 -0
  169. package/cjs/lib/Signal/Group/group_cipher.cjs +86 -0
  170. package/cjs/lib/Signal/Group/index.cjs +58 -0
  171. package/cjs/lib/Signal/Group/keyhelper.cjs +56 -0
  172. package/cjs/lib/Signal/Group/sender-chain-key.cjs +30 -0
  173. package/cjs/lib/Signal/Group/sender-key-distribution-message.cjs +67 -0
  174. package/cjs/lib/Signal/Group/sender-key-message.cjs +70 -0
  175. package/cjs/lib/Signal/Group/sender-key-name.cjs +52 -0
  176. package/cjs/lib/Signal/Group/sender-key-record.cjs +45 -0
  177. package/cjs/lib/Signal/Group/sender-key-state.cjs +88 -0
  178. package/cjs/lib/Signal/Group/sender-message-key.cjs +30 -0
  179. package/cjs/lib/Signal/libsignal.cjs +467 -0
  180. package/cjs/lib/Signal/lid-mapping.cjs +281 -0
  181. package/cjs/lib/Socket/Client/index.cjs +19 -0
  182. package/cjs/lib/Socket/Client/types.cjs +15 -0
  183. package/cjs/lib/Socket/Client/websocket.cjs +61 -0
  184. package/cjs/lib/Socket/business.cjs +384 -0
  185. package/cjs/lib/Socket/chats.cjs +1221 -0
  186. package/cjs/lib/Socket/communities.cjs +440 -0
  187. package/cjs/lib/Socket/groups.cjs +353 -0
  188. package/cjs/lib/Socket/index.cjs +14 -0
  189. package/cjs/lib/Socket/messages-recv.cjs +1772 -0
  190. package/cjs/lib/Socket/messages-send.cjs +1376 -0
  191. package/cjs/lib/Socket/mex.cjs +46 -0
  192. package/cjs/lib/Socket/newsletter.cjs +230 -0
  193. package/cjs/lib/Socket/socket.cjs +976 -0
  194. package/cjs/lib/Store/index.cjs +20 -0
  195. package/cjs/lib/Store/make-in-memory-store.cjs +470 -0
  196. package/cjs/lib/Store/make-ordered-dictionary.cjs +82 -0
  197. package/cjs/lib/Store/object-repository.cjs +28 -0
  198. package/cjs/lib/Telegram/button.cjs +147 -0
  199. package/cjs/lib/Telegram/composer.cjs +582 -0
  200. package/cjs/lib/Telegram/context.cjs +853 -0
  201. package/cjs/lib/Telegram/core/helpers/args.cjs +57 -0
  202. package/cjs/lib/Telegram/core/helpers/check.cjs +55 -0
  203. package/cjs/lib/Telegram/core/helpers/compact.cjs +16 -0
  204. package/cjs/lib/Telegram/core/helpers/deunionize.cjs +12 -0
  205. package/cjs/lib/Telegram/core/helpers/formatting.cjs +91 -0
  206. package/cjs/lib/Telegram/core/helpers/util.cjs +50 -0
  207. package/cjs/lib/Telegram/core/network/client.cjs +338 -0
  208. package/cjs/lib/Telegram/core/network/error.cjs +21 -0
  209. package/cjs/lib/Telegram/core/network/multipart-stream.cjs +79 -0
  210. package/cjs/lib/Telegram/core/network/polling.cjs +87 -0
  211. package/cjs/lib/Telegram/core/network/webhook.cjs +54 -0
  212. package/cjs/lib/Telegram/core/types/typegram.cjs +31 -0
  213. package/cjs/lib/Telegram/deffa-telegraf.cjs +264 -0
  214. package/cjs/lib/Telegram/esm-bridge.cjs +20 -0
  215. package/cjs/lib/Telegram/filters.cjs +69 -0
  216. package/cjs/lib/Telegram/format.cjs +58 -0
  217. package/cjs/lib/Telegram/future.cjs +140 -0
  218. package/cjs/lib/Telegram/index.cjs +67 -0
  219. package/cjs/lib/Telegram/input.cjs +61 -0
  220. package/cjs/lib/Telegram/markup.cjs +129 -0
  221. package/cjs/lib/Telegram/middleware.cjs +2 -0
  222. package/cjs/lib/Telegram/reactions.cjs +84 -0
  223. package/cjs/lib/Telegram/router.cjs +46 -0
  224. package/cjs/lib/Telegram/scenes/base.cjs +39 -0
  225. package/cjs/lib/Telegram/scenes/context.cjs +104 -0
  226. package/cjs/lib/Telegram/scenes/index.cjs +21 -0
  227. package/cjs/lib/Telegram/scenes/stage.cjs +49 -0
  228. package/cjs/lib/Telegram/scenes/wizard/context.cjs +31 -0
  229. package/cjs/lib/Telegram/scenes/wizard/index.cjs +45 -0
  230. package/cjs/lib/Telegram/scenes.cjs +21 -0
  231. package/cjs/lib/Telegram/session.cjs +166 -0
  232. package/cjs/lib/Telegram/telegram-types.cjs +6 -0
  233. package/cjs/lib/Telegram/telegram.cjs +945 -0
  234. package/cjs/lib/Telegram/types.cjs +2 -0
  235. package/cjs/lib/Telegram/utils.cjs +5 -0
  236. package/cjs/lib/Types/Auth.cjs +3 -0
  237. package/cjs/lib/Types/Bussines.cjs +3 -0
  238. package/cjs/lib/Types/Call.cjs +3 -0
  239. package/cjs/lib/Types/Chat.cjs +11 -0
  240. package/cjs/lib/Types/Contact.cjs +3 -0
  241. package/cjs/lib/Types/Events.cjs +4 -0
  242. package/cjs/lib/Types/GroupMetadata.cjs +3 -0
  243. package/cjs/lib/Types/Label.cjs +26 -0
  244. package/cjs/lib/Types/LabelAssociation.cjs +8 -0
  245. package/cjs/lib/Types/Message.cjs +19 -0
  246. package/cjs/lib/Types/Mex.cjs +40 -0
  247. package/cjs/lib/Types/Product.cjs +3 -0
  248. package/cjs/lib/Types/RichType.cjs +24 -0
  249. package/cjs/lib/Types/Signal.cjs +4 -0
  250. package/cjs/lib/Types/Socket.cjs +4 -0
  251. package/cjs/lib/Types/State.cjs +54 -0
  252. package/cjs/lib/Types/USync.cjs +4 -0
  253. package/cjs/lib/Types/index.cjs +42 -0
  254. package/cjs/lib/Utils/auth-utils.cjs +312 -0
  255. package/cjs/lib/Utils/browser-utils.cjs +39 -0
  256. package/cjs/lib/Utils/business.cjs +241 -0
  257. package/cjs/lib/Utils/chat-utils.cjs +890 -0
  258. package/cjs/lib/Utils/companion-reg-client-utils.cjs +51 -0
  259. package/cjs/lib/Utils/crypto.cjs +170 -0
  260. package/cjs/lib/Utils/decode-wa-message.cjs +330 -0
  261. package/cjs/lib/Utils/event-buffer.cjs +629 -0
  262. package/cjs/lib/Utils/generics.cjs +427 -0
  263. package/cjs/lib/Utils/history.cjs +141 -0
  264. package/cjs/lib/Utils/identity-change-handler.cjs +56 -0
  265. package/cjs/lib/Utils/index.cjs +43 -0
  266. package/cjs/lib/Utils/link-preview.cjs +122 -0
  267. package/cjs/lib/Utils/logger.cjs +8 -0
  268. package/cjs/lib/Utils/lt-hash.cjs +11 -0
  269. package/cjs/lib/Utils/make-mutex.cjs +38 -0
  270. package/cjs/lib/Utils/message-retry-manager.cjs +267 -0
  271. package/cjs/lib/Utils/messages-media.cjs +906 -0
  272. package/cjs/lib/Utils/messages.cjs +1909 -0
  273. package/cjs/lib/Utils/noise-handler.cjs +205 -0
  274. package/cjs/lib/Utils/offline-node-processor.cjs +43 -0
  275. package/cjs/lib/Utils/pre-key-manager.cjs +113 -0
  276. package/cjs/lib/Utils/process-message.cjs +755 -0
  277. package/cjs/lib/Utils/reporting-utils.cjs +263 -0
  278. package/cjs/lib/Utils/rich-message-utils.cjs +434 -0
  279. package/cjs/lib/Utils/session-guard.cjs +163 -0
  280. package/cjs/lib/Utils/signal.cjs +214 -0
  281. package/cjs/lib/Utils/stanza-ack.cjs +41 -0
  282. package/cjs/lib/Utils/sync-action-utils.cjs +54 -0
  283. package/cjs/lib/Utils/tc-token-utils.cjs +174 -0
  284. package/cjs/lib/Utils/text-sticker.cjs +174 -0
  285. package/cjs/lib/Utils/use-multi-file-auth-state.cjs +125 -0
  286. package/cjs/lib/Utils/use-single-file-auth-state.cjs +113 -0
  287. package/cjs/lib/Utils/use-sqlite-auth-state.cjs +145 -0
  288. package/cjs/lib/Utils/validate-connection.cjs +210 -0
  289. package/cjs/lib/WABinary/constants.cjs +1470 -0
  290. package/cjs/lib/WABinary/decode.cjs +301 -0
  291. package/cjs/lib/WABinary/encode.cjs +257 -0
  292. package/cjs/lib/WABinary/generic-utils.cjs +240 -0
  293. package/cjs/lib/WABinary/index.cjs +22 -0
  294. package/cjs/lib/WABinary/jid-utils.cjs +114 -0
  295. package/cjs/lib/WABinary/types.cjs +37 -0
  296. package/cjs/lib/WAM/BinaryInfo.cjs +14 -0
  297. package/cjs/lib/WAM/constants.cjs +22856 -0
  298. package/cjs/lib/WAM/encode.cjs +154 -0
  299. package/cjs/lib/WAM/index.cjs +20 -0
  300. package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.cjs +56 -0
  301. package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.cjs +58 -0
  302. package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.cjs +31 -0
  303. package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.cjs +42 -0
  304. package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.cjs +29 -0
  305. package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.cjs +55 -0
  306. package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.cjs +33 -0
  307. package/cjs/lib/WAUSync/Protocols/index.cjs +22 -0
  308. package/cjs/lib/WAUSync/USyncQuery.cjs +102 -0
  309. package/cjs/lib/WAUSync/USyncUser.cjs +35 -0
  310. package/cjs/lib/WAUSync/index.cjs +20 -0
  311. package/cjs/lib/index.cjs +372 -0
  312. package/cjs/lib/plugins/loader.cjs +117 -0
  313. package/lib/Defaults/index.js +1 -1
  314. package/package.json +11 -6
@@ -0,0 +1,890 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processSyncAction = exports.chatModificationToAppPatch = exports.decodePatches = exports.decodeSyncdSnapshot = exports.downloadExternalPatch = exports.downloadExternalBlob = exports.extractSyncdPatches = exports.decodeSyncdPatch = exports.decodeSyncdMutations = exports.encodeSyncdPatch = exports.isAppStateSyncIrrecoverable = exports.isMissingKeyError = exports.MAX_SYNC_ATTEMPTS = exports.ensureLTHashStateVersion = exports.newLTHashState = exports.makeLtHashGenerator = void 0;
4
+ const boom_1 = require("@hapi/boom");
5
+ const whatsapp_rust_bridge_1 = require("whatsapp-rust-bridge");
6
+ const index_js_1 = require("../../WAProto/index.cjs");
7
+ const LabelAssociation_js_1 = require("../Types/LabelAssociation.cjs");
8
+ const index_js_2 = require("../WABinary/index.cjs");
9
+ const crypto_js_1 = require("./crypto.cjs");
10
+ const generics_js_1 = require("./generics.cjs");
11
+ const lt_hash_js_1 = require("./lt-hash.cjs");
12
+ const messages_media_js_1 = require("./messages-media.cjs");
13
+ const sync_action_utils_js_1 = require("./sync-action-utils.cjs");
14
+ const mutationKeys = (keydata) => {
15
+ const keys = (0, whatsapp_rust_bridge_1.expandAppStateKeys)(keydata);
16
+ return {
17
+ indexKey: keys.indexKey,
18
+ valueEncryptionKey: keys.valueEncryptionKey,
19
+ valueMacKey: keys.valueMacKey,
20
+ snapshotMacKey: keys.snapshotMacKey,
21
+ patchMacKey: keys.patchMacKey
22
+ };
23
+ };
24
+ const generateMac = (operation, data, keyId, key) => {
25
+ const opByte = operation === index_js_1.proto.SyncdMutation.SyncdOperation.SET ? 0x01 : 0x02;
26
+ const keyIdBuffer = typeof keyId === 'string' ? Buffer.from(keyId, 'base64') : keyId;
27
+ const keyData = new Uint8Array(1 + keyIdBuffer.length);
28
+ keyData[0] = opByte;
29
+ keyData.set(keyIdBuffer, 1);
30
+ const last = new Uint8Array(8);
31
+ last[7] = keyData.length;
32
+ const total = new Uint8Array(keyData.length + data.length + last.length);
33
+ total.set(keyData, 0);
34
+ total.set(data, keyData.length);
35
+ total.set(last, keyData.length + data.length);
36
+ const hmac = (0, crypto_js_1.hmacSign)(total, key, 'sha512');
37
+ return hmac.subarray(0, 32);
38
+ };
39
+ const to64BitNetworkOrder = (e) => {
40
+ const buff = Buffer.alloc(8);
41
+ buff.writeUint32BE(e, 4);
42
+ return buff;
43
+ };
44
+ const makeLtHashGenerator = ({ indexValueMap, hash }) => {
45
+ indexValueMap = { ...indexValueMap };
46
+ const addBuffs = [];
47
+ const subBuffs = [];
48
+ return {
49
+ mix: ({ indexMac, valueMac, operation }) => {
50
+ const indexMacBase64 = Buffer.from(indexMac).toString('base64');
51
+ const prevOp = indexValueMap[indexMacBase64];
52
+ if (operation === index_js_1.proto.SyncdMutation.SyncdOperation.REMOVE) {
53
+ if (!prevOp) {
54
+ // WA Web does not throw here — it logs a warning and skips the subtract.
55
+ // The missing REMOVE will cause an LTHash mismatch, which is handled
56
+ // by the MAC validation layer (snapshot recovery or retry).
57
+ return;
58
+ }
59
+ // remove from index value mac, since this mutation is erased
60
+ delete indexValueMap[indexMacBase64];
61
+ }
62
+ else {
63
+ addBuffs.push(valueMac);
64
+ // add this index into the history map
65
+ indexValueMap[indexMacBase64] = { valueMac };
66
+ }
67
+ if (prevOp) {
68
+ subBuffs.push(prevOp.valueMac);
69
+ }
70
+ },
71
+ finish: () => {
72
+ const result = lt_hash_js_1.LT_HASH_ANTI_TAMPERING.subtractThenAdd(hash, subBuffs, addBuffs);
73
+ return {
74
+ hash: Buffer.from(result),
75
+ indexValueMap
76
+ };
77
+ }
78
+ };
79
+ };
80
+ exports.makeLtHashGenerator = makeLtHashGenerator;
81
+ const generateSnapshotMac = (lthash, version, name, key) => {
82
+ const total = Buffer.concat([lthash, to64BitNetworkOrder(version), Buffer.from(name, 'utf-8')]);
83
+ return (0, crypto_js_1.hmacSign)(total, key, 'sha256');
84
+ };
85
+ const generatePatchMac = (snapshotMac, valueMacs, version, type, key) => {
86
+ const total = Buffer.concat([snapshotMac, ...valueMacs, to64BitNetworkOrder(version), Buffer.from(type, 'utf-8')]);
87
+ return (0, crypto_js_1.hmacSign)(total, key);
88
+ };
89
+ const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} });
90
+ exports.newLTHashState = newLTHashState;
91
+ const ensureLTHashStateVersion = (state) => {
92
+ if (typeof state.version !== 'number' || isNaN(state.version)) {
93
+ state.version = 0;
94
+ }
95
+ return state;
96
+ };
97
+ exports.ensureLTHashStateVersion = ensureLTHashStateVersion;
98
+ exports.MAX_SYNC_ATTEMPTS = 2;
99
+ /**
100
+ * Check if an error is a missing app state sync key.
101
+ * WA Web treats these as "Blocked" (waits for key arrival), not fatal.
102
+ * In Baileys we retry with a snapshot which may use a different key.
103
+ */
104
+ const isMissingKeyError = (error) => {
105
+ return error?.data?.isMissingKey === true;
106
+ };
107
+ exports.isMissingKeyError = isMissingKeyError;
108
+ /**
109
+ * Determines if an app state sync error is unrecoverable.
110
+ * TypeError indicates a WASM crash; otherwise we give up after MAX_SYNC_ATTEMPTS.
111
+ * Missing keys are NOT checked here — they are handled separately as "Blocked".
112
+ */
113
+ const isAppStateSyncIrrecoverable = (error, attempts) => {
114
+ return attempts >= exports.MAX_SYNC_ATTEMPTS || error?.name === 'TypeError';
115
+ };
116
+ exports.isAppStateSyncIrrecoverable = isAppStateSyncIrrecoverable;
117
+ const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) => {
118
+ const key = !!myAppStateKeyId ? await getAppStateSyncKey(myAppStateKeyId) : undefined;
119
+ if (!key) {
120
+ throw new boom_1.Boom(`myAppStateKey ("${myAppStateKeyId}") not present`, { data: { isMissingKey: true } });
121
+ }
122
+ const encKeyId = Buffer.from(myAppStateKeyId, 'base64');
123
+ state = { ...state, indexValueMap: { ...state.indexValueMap } };
124
+ const indexBuffer = Buffer.from(JSON.stringify(index));
125
+ const dataProto = index_js_1.proto.SyncActionData.fromObject({
126
+ index: indexBuffer,
127
+ value: syncAction,
128
+ padding: new Uint8Array(0),
129
+ version: apiVersion
130
+ });
131
+ const encoded = index_js_1.proto.SyncActionData.encode(dataProto).finish();
132
+ const keyValue = mutationKeys(key.keyData);
133
+ const encValue = (0, crypto_js_1.aesEncrypt)(encoded, keyValue.valueEncryptionKey);
134
+ const valueMac = generateMac(operation, encValue, encKeyId, keyValue.valueMacKey);
135
+ const indexMac = (0, crypto_js_1.hmacSign)(indexBuffer, keyValue.indexKey);
136
+ // update LT hash
137
+ const generator = (0, exports.makeLtHashGenerator)(state);
138
+ generator.mix({ indexMac, valueMac, operation });
139
+ Object.assign(state, generator.finish());
140
+ state.version += 1;
141
+ const snapshotMac = generateSnapshotMac(state.hash, state.version, type, keyValue.snapshotMacKey);
142
+ const patch = {
143
+ patchMac: generatePatchMac(snapshotMac, [valueMac], state.version, type, keyValue.patchMacKey),
144
+ snapshotMac: snapshotMac,
145
+ keyId: { id: encKeyId },
146
+ mutations: [
147
+ {
148
+ operation: operation,
149
+ record: {
150
+ index: {
151
+ blob: indexMac
152
+ },
153
+ value: {
154
+ blob: Buffer.concat([encValue, valueMac])
155
+ },
156
+ keyId: { id: encKeyId }
157
+ }
158
+ }
159
+ ]
160
+ };
161
+ const base64Index = indexMac.toString('base64');
162
+ state.indexValueMap[base64Index] = { valueMac };
163
+ return { patch, state };
164
+ };
165
+ exports.encodeSyncdPatch = encodeSyncdPatch;
166
+ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
167
+ const ltGenerator = (0, exports.makeLtHashGenerator)(initialState);
168
+ const derivedKeyCache = new Map();
169
+ // indexKey used to HMAC sign record.index.blob
170
+ // valueEncryptionKey used to AES-256-CBC encrypt record.value.blob[0:-32]
171
+ // the remaining record.value.blob[0:-32] is the mac, it the HMAC sign of key.keyId + decoded proto data + length of bytes in keyId
172
+ for (const msgMutation of msgMutations) {
173
+ // if it's a syncdmutation, get the operation property
174
+ // otherwise, if it's only a record -- it'll be a SET mutation
175
+ const operation = 'operation' in msgMutation ? msgMutation.operation : index_js_1.proto.SyncdMutation.SyncdOperation.SET;
176
+ const record = 'record' in msgMutation && !!msgMutation.record ? msgMutation.record : msgMutation;
177
+ let key;
178
+ try {
179
+ key = await getKey(record.keyId.id);
180
+ }
181
+ catch (err) {
182
+ // Missing-key errors must propagate so the orchestrator can park the
183
+ // collection (Blocked) and retry when APP_STATE_SYNC_KEY_SHARE arrives.
184
+ // Other errors → individual record corruption, skip and keep going.
185
+ if ((0, exports.isMissingKeyError)(err))
186
+ throw err;
187
+ continue;
188
+ }
189
+ const content = record.value.blob;
190
+ const encContent = content.subarray(0, -32);
191
+ const ogValueMac = content.subarray(-32);
192
+ if (validateMacs) {
193
+ const contentHmac = generateMac(operation, encContent, record.keyId.id, key.valueMacKey);
194
+ if (Buffer.compare(contentHmac, ogValueMac) !== 0) {
195
+ // HMAC verification failed — skip this record
196
+ continue;
197
+ }
198
+ }
199
+ let result;
200
+ try {
201
+ result = (0, crypto_js_1.aesDecrypt)(encContent, key.valueEncryptionKey);
202
+ }
203
+ catch {
204
+ // decrypt failed — skip this record instead of aborting
205
+ continue;
206
+ }
207
+ const syncAction = index_js_1.proto.SyncActionData.decode(result);
208
+ if (validateMacs) {
209
+ const hmac = (0, crypto_js_1.hmacSign)(syncAction.index, key.indexKey);
210
+ if (Buffer.compare(hmac, record.index.blob) !== 0) {
211
+ throw new boom_1.Boom('HMAC index verification failed');
212
+ }
213
+ }
214
+ const indexStr = Buffer.from(syncAction.index).toString();
215
+ onMutation({ syncAction, index: JSON.parse(indexStr) });
216
+ ltGenerator.mix({
217
+ indexMac: record.index.blob,
218
+ valueMac: ogValueMac,
219
+ operation: operation
220
+ });
221
+ }
222
+ return ltGenerator.finish();
223
+ async function getKey(keyId) {
224
+ const base64Key = Buffer.from(keyId).toString('base64');
225
+ const cached = derivedKeyCache.get(base64Key);
226
+ if (cached) {
227
+ return cached;
228
+ }
229
+ const keyEnc = await getAppStateSyncKey(base64Key);
230
+ if (!keyEnc) {
231
+ throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`, {
232
+ data: { isMissingKey: true, msgMutations }
233
+ });
234
+ }
235
+ const keys = mutationKeys(keyEnc.keyData);
236
+ derivedKeyCache.set(base64Key, keys);
237
+ return keys;
238
+ }
239
+ };
240
+ exports.decodeSyncdMutations = decodeSyncdMutations;
241
+ const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
242
+ if (validateMacs) {
243
+ const base64Key = Buffer.from(msg.keyId.id).toString('base64');
244
+ const mainKeyObj = await getAppStateSyncKey(base64Key);
245
+ if (!mainKeyObj) {
246
+ throw new boom_1.Boom(`failed to find key "${base64Key}" to decode patch`, { data: { isMissingKey: true, msg } });
247
+ }
248
+ const mainKey = mutationKeys(mainKeyObj.keyData);
249
+ const mutationmacs = msg.mutations.map(mutation => mutation.record.value.blob.slice(-32));
250
+ const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs, (0, generics_js_1.toNumber)(msg.version.version), name, mainKey.patchMacKey);
251
+ if (Buffer.compare(patchMac, msg.patchMac) !== 0) {
252
+ throw new boom_1.Boom('Invalid patch mac');
253
+ }
254
+ }
255
+ const result = await (0, exports.decodeSyncdMutations)(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs);
256
+ return result;
257
+ };
258
+ exports.decodeSyncdPatch = decodeSyncdPatch;
259
+ const extractSyncdPatches = async (result, options) => {
260
+ const syncNode = (0, index_js_2.getBinaryNodeChild)(result, 'sync');
261
+ const collectionNodes = (0, index_js_2.getBinaryNodeChildren)(syncNode, 'collection');
262
+ const final = {};
263
+ await Promise.all(collectionNodes.map(async (collectionNode) => {
264
+ const patchesNode = (0, index_js_2.getBinaryNodeChild)(collectionNode, 'patches');
265
+ const patches = (0, index_js_2.getBinaryNodeChildren)(patchesNode || collectionNode, 'patch');
266
+ const snapshotNode = (0, index_js_2.getBinaryNodeChild)(collectionNode, 'snapshot');
267
+ const syncds = [];
268
+ const name = collectionNode.attrs.name;
269
+ const hasMorePatches = collectionNode.attrs.has_more_patches === 'true';
270
+ let snapshot = undefined;
271
+ if (snapshotNode && !!snapshotNode.content) {
272
+ if (!Buffer.isBuffer(snapshotNode)) {
273
+ snapshotNode.content = Buffer.from(Object.values(snapshotNode.content));
274
+ }
275
+ const blobRef = index_js_1.proto.ExternalBlobReference.decode(snapshotNode.content);
276
+ const data = await (0, exports.downloadExternalBlob)(blobRef, options);
277
+ snapshot = index_js_1.proto.SyncdSnapshot.decode(data);
278
+ }
279
+ for (let { content } of patches) {
280
+ if (content) {
281
+ if (!Buffer.isBuffer(content)) {
282
+ content = Buffer.from(Object.values(content));
283
+ }
284
+ const syncd = index_js_1.proto.SyncdPatch.decode(content);
285
+ if (!syncd.version) {
286
+ syncd.version = { version: +collectionNode.attrs.version + 1 };
287
+ }
288
+ syncds.push(syncd);
289
+ }
290
+ }
291
+ final[name] = { patches: syncds, hasMorePatches, snapshot };
292
+ }));
293
+ return final;
294
+ };
295
+ exports.extractSyncdPatches = extractSyncdPatches;
296
+ const downloadExternalBlob = async (blob, options) => {
297
+ const stream = await (0, messages_media_js_1.downloadContentFromMessage)(blob, 'md-app-state', { options });
298
+ const bufferArray = [];
299
+ for await (const chunk of stream) {
300
+ bufferArray.push(chunk);
301
+ }
302
+ return Buffer.concat(bufferArray);
303
+ };
304
+ exports.downloadExternalBlob = downloadExternalBlob;
305
+ const downloadExternalPatch = async (blob, options) => {
306
+ const buffer = await (0, exports.downloadExternalBlob)(blob, options);
307
+ const syncData = index_js_1.proto.SyncdMutations.decode(buffer);
308
+ return syncData;
309
+ };
310
+ exports.downloadExternalPatch = downloadExternalPatch;
311
+ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVersionNumber, validateMacs = true, logger) => {
312
+ const newState = (0, exports.newLTHashState)();
313
+ newState.version = (0, generics_js_1.toNumber)(snapshot.version.version);
314
+ const mutationMap = {};
315
+ const areMutationsRequired = typeof minimumVersionNumber === 'undefined' || newState.version > minimumVersionNumber;
316
+ const { hash, indexValueMap } = await (0, exports.decodeSyncdMutations)(snapshot.records, newState, getAppStateSyncKey, areMutationsRequired
317
+ ? mutation => {
318
+ const index = mutation.syncAction.index?.toString();
319
+ mutationMap[index] = mutation;
320
+ }
321
+ : () => { }, validateMacs);
322
+ newState.hash = hash;
323
+ newState.indexValueMap = indexValueMap;
324
+ if (validateMacs) {
325
+ const base64Key = Buffer.from(snapshot.keyId.id).toString('base64');
326
+ const keyEnc = await getAppStateSyncKey(base64Key);
327
+ if (!keyEnc) {
328
+ throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`, { data: { isMissingKey: true } });
329
+ }
330
+ const result = mutationKeys(keyEnc.keyData);
331
+ const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
332
+ if (Buffer.compare(snapshot.mac, computedSnapshotMac) !== 0) {
333
+ // LTHash verification may fail when decodeSyncdMutations skipped undecryptable
334
+ // records (poisoned server-side snapshot); the aggregate client hash diverges
335
+ // from the server-computed mac. Fall through with a warning so the session stays
336
+ // alive with partial state, symmetric to how decodePatches handles its own
337
+ // LTHash mismatch a few lines below.
338
+ logger?.warn({ name, version: newState.version }, 'LTHash verification failed on snapshot, continuing with partial state');
339
+ }
340
+ }
341
+ return {
342
+ state: newState,
343
+ mutationMap
344
+ };
345
+ };
346
+ exports.decodeSyncdSnapshot = decodeSyncdSnapshot;
347
+ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
348
+ const newState = {
349
+ ...initial,
350
+ indexValueMap: { ...initial.indexValueMap }
351
+ };
352
+ const mutationMap = {};
353
+ for (const syncd of syncds) {
354
+ const { version, keyId, snapshotMac } = syncd;
355
+ if (syncd.externalMutations) {
356
+ logger?.trace({ name, version }, 'downloading external patch');
357
+ const ref = await (0, exports.downloadExternalPatch)(syncd.externalMutations, options);
358
+ logger?.debug({ name, version, mutations: ref.mutations.length }, 'downloaded external patch');
359
+ syncd.mutations?.push(...ref.mutations);
360
+ }
361
+ const patchVersion = (0, generics_js_1.toNumber)(version.version);
362
+ newState.version = patchVersion;
363
+ const shouldMutate = typeof minimumVersionNumber === 'undefined' || patchVersion > minimumVersionNumber;
364
+ let decodeResult;
365
+ try {
366
+ decodeResult = await (0, exports.decodeSyncdPatch)(syncd, name, newState, getAppStateSyncKey, shouldMutate
367
+ ? mutation => {
368
+ const index = mutation.syncAction.index?.toString();
369
+ mutationMap[index] = mutation;
370
+ }
371
+ : () => { }, validateMacs);
372
+ }
373
+ catch (err) {
374
+ if ((0, exports.isMissingKeyError)(err))
375
+ throw err;
376
+ logger?.warn({ name, version: patchVersion, error: err.message }, 'failed to decode patch, skipping');
377
+ continue;
378
+ }
379
+ newState.hash = decodeResult.hash;
380
+ newState.indexValueMap = decodeResult.indexValueMap;
381
+ if (validateMacs) {
382
+ const base64Key = Buffer.from(keyId.id).toString('base64');
383
+ const keyEnc = await getAppStateSyncKey(base64Key);
384
+ if (!keyEnc) {
385
+ throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`, { data: { isMissingKey: true } });
386
+ }
387
+ const result = mutationKeys(keyEnc.keyData);
388
+ const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
389
+ if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
390
+ logger?.warn({ name, version: newState.version }, 'LTHash verification failed, skipping remaining patches');
391
+ break;
392
+ }
393
+ }
394
+ // clear memory used up by the mutations
395
+ syncd.mutations = [];
396
+ }
397
+ return { state: newState, mutationMap };
398
+ };
399
+ exports.decodePatches = decodePatches;
400
+ const chatModificationToAppPatch = (mod, jid) => {
401
+ const OP = index_js_1.proto.SyncdMutation.SyncdOperation;
402
+ const getMessageRange = (lastMessages) => {
403
+ let messageRange;
404
+ if (Array.isArray(lastMessages)) {
405
+ const lastMsg = lastMessages[lastMessages.length - 1];
406
+ messageRange = {
407
+ lastMessageTimestamp: lastMsg?.messageTimestamp,
408
+ messages: lastMessages?.length
409
+ ? lastMessages.map(m => {
410
+ if (!m.key?.id || !m.key?.remoteJid) {
411
+ throw new boom_1.Boom('Incomplete key', { statusCode: 400, data: m });
412
+ }
413
+ if ((0, index_js_2.isJidGroup)(m.key.remoteJid) && !m.key.fromMe && !m.key.participant) {
414
+ throw new boom_1.Boom('Expected not from me message to have participant', { statusCode: 400, data: m });
415
+ }
416
+ if (!m.messageTimestamp || !(0, generics_js_1.toNumber)(m.messageTimestamp)) {
417
+ throw new boom_1.Boom('Missing timestamp in last message list', { statusCode: 400, data: m });
418
+ }
419
+ if (m.key.participant) {
420
+ m.key.participant = (0, index_js_2.jidNormalizedUser)(m.key.participant);
421
+ }
422
+ return m;
423
+ })
424
+ : undefined
425
+ };
426
+ }
427
+ else {
428
+ messageRange = lastMessages;
429
+ }
430
+ return messageRange;
431
+ };
432
+ let patch;
433
+ if ('mute' in mod) {
434
+ patch = {
435
+ syncAction: {
436
+ muteAction: {
437
+ muted: !!mod.mute,
438
+ muteEndTimestamp: mod.mute || undefined
439
+ }
440
+ },
441
+ index: ['mute', jid],
442
+ type: 'regular_high',
443
+ apiVersion: 2,
444
+ operation: OP.SET
445
+ };
446
+ }
447
+ else if ('archive' in mod) {
448
+ patch = {
449
+ syncAction: {
450
+ archiveChatAction: {
451
+ archived: !!mod.archive,
452
+ messageRange: getMessageRange(mod.lastMessages)
453
+ }
454
+ },
455
+ index: ['archive', jid],
456
+ type: 'regular_low',
457
+ apiVersion: 3,
458
+ operation: OP.SET
459
+ };
460
+ }
461
+ else if ('markRead' in mod) {
462
+ patch = {
463
+ syncAction: {
464
+ markChatAsReadAction: {
465
+ read: mod.markRead,
466
+ messageRange: getMessageRange(mod.lastMessages)
467
+ }
468
+ },
469
+ index: ['markChatAsRead', jid],
470
+ type: 'regular_low',
471
+ apiVersion: 3,
472
+ operation: OP.SET
473
+ };
474
+ }
475
+ else if ('deleteForMe' in mod) {
476
+ const { timestamp, key, deleteMedia } = mod.deleteForMe;
477
+ patch = {
478
+ syncAction: {
479
+ deleteMessageForMeAction: {
480
+ deleteMedia,
481
+ messageTimestamp: timestamp
482
+ }
483
+ },
484
+ index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
485
+ type: 'regular_high',
486
+ apiVersion: 3,
487
+ operation: OP.SET
488
+ };
489
+ }
490
+ else if ('clear' in mod) {
491
+ patch = {
492
+ syncAction: {
493
+ clearChatAction: {
494
+ messageRange: getMessageRange(mod.lastMessages)
495
+ }
496
+ },
497
+ index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
498
+ type: 'regular_high',
499
+ apiVersion: 6,
500
+ operation: OP.SET
501
+ };
502
+ }
503
+ else if ('pin' in mod) {
504
+ patch = {
505
+ syncAction: {
506
+ pinAction: {
507
+ pinned: !!mod.pin
508
+ }
509
+ },
510
+ index: ['pin_v1', jid],
511
+ type: 'regular_low',
512
+ apiVersion: 5,
513
+ operation: OP.SET
514
+ };
515
+ }
516
+ else if ('contact' in mod) {
517
+ patch = {
518
+ syncAction: {
519
+ contactAction: mod.contact || {}
520
+ },
521
+ index: ['contact', jid],
522
+ type: 'critical_unblock_low',
523
+ apiVersion: 2,
524
+ operation: mod.contact ? OP.SET : OP.REMOVE
525
+ };
526
+ }
527
+ else if ('disableLinkPreviews' in mod) {
528
+ patch = {
529
+ syncAction: {
530
+ privacySettingDisableLinkPreviewsAction: mod.disableLinkPreviews || {}
531
+ },
532
+ index: ['setting_disableLinkPreviews'],
533
+ type: 'regular',
534
+ apiVersion: 8,
535
+ operation: OP.SET
536
+ };
537
+ }
538
+ else if ('star' in mod) {
539
+ const key = mod.star.messages[0];
540
+ patch = {
541
+ syncAction: {
542
+ starAction: {
543
+ starred: !!mod.star.star
544
+ }
545
+ },
546
+ index: ['star', jid, key.id, key.fromMe ? '1' : '0', '0'],
547
+ type: 'regular_low',
548
+ apiVersion: 2,
549
+ operation: OP.SET
550
+ };
551
+ }
552
+ else if ('delete' in mod) {
553
+ patch = {
554
+ syncAction: {
555
+ deleteChatAction: {
556
+ messageRange: getMessageRange(mod.lastMessages)
557
+ }
558
+ },
559
+ index: ['deleteChat', jid, '1'],
560
+ type: 'regular_high',
561
+ apiVersion: 6,
562
+ operation: OP.SET
563
+ };
564
+ }
565
+ else if ('pushNameSetting' in mod) {
566
+ patch = {
567
+ syncAction: {
568
+ pushNameSetting: {
569
+ name: mod.pushNameSetting
570
+ }
571
+ },
572
+ index: ['setting_pushName'],
573
+ type: 'critical_block',
574
+ apiVersion: 1,
575
+ operation: OP.SET
576
+ };
577
+ }
578
+ else if ('quickReply' in mod) {
579
+ patch = {
580
+ syncAction: {
581
+ quickReplyAction: {
582
+ count: 0,
583
+ deleted: mod.quickReply.deleted || false,
584
+ keywords: [],
585
+ message: mod.quickReply.message || '',
586
+ shortcut: mod.quickReply.shortcut || ''
587
+ }
588
+ },
589
+ index: ['quick_reply', mod.quickReply.timestamp || String(Math.floor(Date.now() / 1000))],
590
+ type: 'regular',
591
+ apiVersion: 2,
592
+ operation: OP.SET
593
+ };
594
+ }
595
+ else if ('addLabel' in mod) {
596
+ patch = {
597
+ syncAction: {
598
+ labelEditAction: {
599
+ name: mod.addLabel.name,
600
+ color: mod.addLabel.color,
601
+ predefinedId: mod.addLabel.predefinedId,
602
+ deleted: mod.addLabel.deleted
603
+ }
604
+ },
605
+ index: ['label_edit', mod.addLabel.id],
606
+ type: 'regular',
607
+ apiVersion: 3,
608
+ operation: OP.SET
609
+ };
610
+ }
611
+ else if ('addChatLabel' in mod) {
612
+ patch = {
613
+ syncAction: {
614
+ labelAssociationAction: {
615
+ labeled: true
616
+ }
617
+ },
618
+ index: [LabelAssociation_js_1.LabelAssociationType.Chat, mod.addChatLabel.labelId, jid],
619
+ type: 'regular',
620
+ apiVersion: 3,
621
+ operation: OP.SET
622
+ };
623
+ }
624
+ else if ('removeChatLabel' in mod) {
625
+ patch = {
626
+ syncAction: {
627
+ labelAssociationAction: {
628
+ labeled: false
629
+ }
630
+ },
631
+ index: [LabelAssociation_js_1.LabelAssociationType.Chat, mod.removeChatLabel.labelId, jid],
632
+ type: 'regular',
633
+ apiVersion: 3,
634
+ operation: OP.SET
635
+ };
636
+ }
637
+ else if ('addMessageLabel' in mod) {
638
+ patch = {
639
+ syncAction: {
640
+ labelAssociationAction: {
641
+ labeled: true
642
+ }
643
+ },
644
+ index: [LabelAssociation_js_1.LabelAssociationType.Message, mod.addMessageLabel.labelId, jid, mod.addMessageLabel.messageId, '0', '0'],
645
+ type: 'regular',
646
+ apiVersion: 3,
647
+ operation: OP.SET
648
+ };
649
+ }
650
+ else if ('removeMessageLabel' in mod) {
651
+ patch = {
652
+ syncAction: {
653
+ labelAssociationAction: {
654
+ labeled: false
655
+ }
656
+ },
657
+ index: [
658
+ LabelAssociation_js_1.LabelAssociationType.Message,
659
+ mod.removeMessageLabel.labelId,
660
+ jid,
661
+ mod.removeMessageLabel.messageId,
662
+ '0',
663
+ '0'
664
+ ],
665
+ type: 'regular',
666
+ apiVersion: 3,
667
+ operation: OP.SET
668
+ };
669
+ }
670
+ else {
671
+ throw new boom_1.Boom('not supported');
672
+ }
673
+ patch.syncAction.timestamp = Date.now();
674
+ return patch;
675
+ };
676
+ exports.chatModificationToAppPatch = chatModificationToAppPatch;
677
+ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
678
+ const isInitialSync = !!initialSyncOpts;
679
+ const accountSettings = initialSyncOpts?.accountSettings;
680
+ logger?.trace({ syncAction, initialSync: !!initialSyncOpts }, 'processing sync action');
681
+ const { syncAction: { value: action }, index: [type, id, msgId, fromMe] } = syncAction;
682
+ if (action?.muteAction) {
683
+ ev.emit('chats.update', [
684
+ {
685
+ id,
686
+ muteEndTime: action.muteAction?.muted ? (0, generics_js_1.toNumber)(action.muteAction.muteEndTimestamp) : null,
687
+ conditional: getChatUpdateConditional(id, undefined)
688
+ }
689
+ ]);
690
+ }
691
+ else if (action?.archiveChatAction || type === 'archive' || type === 'unarchive') {
692
+ // okay so we've to do some annoying computation here
693
+ // when we're initially syncing the app state
694
+ // there are a few cases we need to handle
695
+ // 1. if the account unarchiveChats setting is true
696
+ // a. if the chat is archived, and no further messages have been received -- simple, keep archived
697
+ // b. if the chat was archived, and the user received messages from the other person afterwards
698
+ // then the chat should be marked unarchved --
699
+ // we compare the timestamp of latest message from the other person to determine this
700
+ // 2. if the account unarchiveChats setting is false -- then it doesn't matter,
701
+ // it'll always take an app state action to mark in unarchived -- which we'll get anyway
702
+ const archiveAction = action?.archiveChatAction;
703
+ const isArchived = archiveAction ? archiveAction.archived : type === 'archive';
704
+ // // basically we don't need to fire an "archive" update if the chat is being marked unarchvied
705
+ // // this only applies for the initial sync
706
+ // if(isInitialSync && !isArchived) {
707
+ // isArchived = false
708
+ // }
709
+ const msgRange = !accountSettings?.unarchiveChats ? undefined : archiveAction?.messageRange;
710
+ // logger?.debug({ chat: id, syncAction }, 'message range archive')
711
+ ev.emit('chats.update', [
712
+ {
713
+ id,
714
+ archived: isArchived,
715
+ conditional: getChatUpdateConditional(id, msgRange)
716
+ }
717
+ ]);
718
+ }
719
+ else if (action?.markChatAsReadAction) {
720
+ const markReadAction = action.markChatAsReadAction;
721
+ // basically we don't need to fire an "read" update if the chat is being marked as read
722
+ // because the chat is read by default
723
+ // this only applies for the initial sync
724
+ const isNullUpdate = isInitialSync && markReadAction.read;
725
+ ev.emit('chats.update', [
726
+ {
727
+ id,
728
+ unreadCount: isNullUpdate ? null : !!markReadAction?.read ? 0 : -1,
729
+ conditional: getChatUpdateConditional(id, markReadAction?.messageRange)
730
+ }
731
+ ]);
732
+ }
733
+ else if (action?.deleteMessageForMeAction || type === 'deleteMessageForMe') {
734
+ ev.emit('messages.delete', {
735
+ keys: [
736
+ {
737
+ remoteJid: id,
738
+ id: msgId,
739
+ fromMe: fromMe === '1'
740
+ }
741
+ ]
742
+ });
743
+ }
744
+ else if (action?.contactAction) {
745
+ const results = (0, sync_action_utils_js_1.processContactAction)(action.contactAction, id, logger);
746
+ (0, sync_action_utils_js_1.emitSyncActionResults)(ev, results);
747
+ }
748
+ else if (action?.pushNameSetting) {
749
+ const name = action?.pushNameSetting?.name;
750
+ if (name && me?.name !== name) {
751
+ ev.emit('creds.update', { me: { ...me, name } });
752
+ }
753
+ }
754
+ else if (action?.pinAction) {
755
+ ev.emit('chats.update', [
756
+ {
757
+ id,
758
+ pinned: action.pinAction?.pinned ? (0, generics_js_1.toNumber)(action.timestamp) : null,
759
+ conditional: getChatUpdateConditional(id, undefined)
760
+ }
761
+ ]);
762
+ }
763
+ else if (action?.unarchiveChatsSetting) {
764
+ const unarchiveChats = !!action.unarchiveChatsSetting.unarchiveChats;
765
+ ev.emit('creds.update', { accountSettings: { unarchiveChats } });
766
+ logger?.info(`archive setting updated => '${action.unarchiveChatsSetting.unarchiveChats}'`);
767
+ if (accountSettings) {
768
+ accountSettings.unarchiveChats = unarchiveChats;
769
+ }
770
+ }
771
+ else if (action?.starAction || type === 'star') {
772
+ let starred = action?.starAction?.starred;
773
+ if (typeof starred !== 'boolean') {
774
+ starred = syncAction.index[syncAction.index.length - 1] === '1';
775
+ }
776
+ ev.emit('messages.update', [
777
+ {
778
+ key: { remoteJid: id, id: msgId, fromMe: fromMe === '1' },
779
+ update: { starred }
780
+ }
781
+ ]);
782
+ }
783
+ else if (action?.deleteChatAction || type === 'deleteChat') {
784
+ if (!isInitialSync) {
785
+ ev.emit('chats.delete', [id]);
786
+ }
787
+ }
788
+ else if (action?.labelEditAction) {
789
+ const { name, color, deleted, predefinedId } = action.labelEditAction;
790
+ ev.emit('labels.edit', {
791
+ id: id,
792
+ name: name,
793
+ color: color,
794
+ deleted: deleted,
795
+ predefinedId: predefinedId ? String(predefinedId) : undefined
796
+ });
797
+ }
798
+ else if (action?.labelAssociationAction) {
799
+ ev.emit('labels.association', {
800
+ type: action.labelAssociationAction.labeled ? 'add' : 'remove',
801
+ association: type === LabelAssociation_js_1.LabelAssociationType.Chat
802
+ ? {
803
+ type: LabelAssociation_js_1.LabelAssociationType.Chat,
804
+ chatId: syncAction.index[2],
805
+ labelId: syncAction.index[1]
806
+ }
807
+ : {
808
+ type: LabelAssociation_js_1.LabelAssociationType.Message,
809
+ chatId: syncAction.index[2],
810
+ messageId: syncAction.index[3],
811
+ labelId: syncAction.index[1]
812
+ }
813
+ });
814
+ }
815
+ else if (action?.localeSetting?.locale) {
816
+ ev.emit('settings.update', { setting: 'locale', value: action.localeSetting.locale });
817
+ }
818
+ else if (action?.timeFormatAction) {
819
+ ev.emit('settings.update', { setting: 'timeFormat', value: action.timeFormatAction });
820
+ }
821
+ else if (action?.pnForLidChatAction) {
822
+ if (action.pnForLidChatAction.pnJid) {
823
+ ev.emit('lid-mapping.update', { lid: id, pn: action.pnForLidChatAction.pnJid });
824
+ }
825
+ }
826
+ else if (action?.privacySettingRelayAllCalls) {
827
+ ev.emit('settings.update', {
828
+ setting: 'privacySettingRelayAllCalls',
829
+ value: action.privacySettingRelayAllCalls
830
+ });
831
+ }
832
+ else if (action?.statusPrivacy) {
833
+ ev.emit('settings.update', { setting: 'statusPrivacy', value: action.statusPrivacy });
834
+ }
835
+ else if (action?.lockChatAction) {
836
+ ev.emit('chats.lock', { id: id, locked: !!action.lockChatAction.locked });
837
+ }
838
+ else if (action?.privacySettingDisableLinkPreviewsAction) {
839
+ ev.emit('settings.update', {
840
+ setting: 'disableLinkPreviews',
841
+ value: action.privacySettingDisableLinkPreviewsAction
842
+ });
843
+ }
844
+ else if (action?.notificationActivitySettingAction?.notificationActivitySetting) {
845
+ ev.emit('settings.update', {
846
+ setting: 'notificationActivitySetting',
847
+ value: action.notificationActivitySettingAction.notificationActivitySetting
848
+ });
849
+ }
850
+ else if (action?.lidContactAction) {
851
+ ev.emit('contacts.upsert', [
852
+ {
853
+ id: id,
854
+ name: action.lidContactAction.fullName ||
855
+ action.lidContactAction.firstName ||
856
+ action.lidContactAction.username ||
857
+ undefined,
858
+ username: action.lidContactAction.username || undefined,
859
+ lid: id,
860
+ phoneNumber: undefined
861
+ }
862
+ ]);
863
+ }
864
+ else if (action?.privacySettingChannelsPersonalisedRecommendationAction) {
865
+ ev.emit('settings.update', {
866
+ setting: 'channelsPersonalisedRecommendation',
867
+ value: action.privacySettingChannelsPersonalisedRecommendationAction
868
+ });
869
+ }
870
+ else {
871
+ logger?.debug({ syncAction, id }, 'unprocessable update');
872
+ }
873
+ function getChatUpdateConditional(id, msgRange) {
874
+ return isInitialSync
875
+ ? data => {
876
+ const chat = data.historySets.chats[id] || data.chatUpserts[id];
877
+ if (chat) {
878
+ return msgRange ? isValidPatchBasedOnMessageRange(chat, msgRange) : true;
879
+ }
880
+ }
881
+ : undefined;
882
+ }
883
+ function isValidPatchBasedOnMessageRange(chat, msgRange) {
884
+ const lastMsgTimestamp = Number(msgRange?.lastMessageTimestamp || msgRange?.lastSystemMessageTimestamp || 0);
885
+ const chatLastMsgTimestamp = Number(chat?.lastMessageRecvTimestamp || 0);
886
+ return lastMsgTimestamp >= chatLastMsgTimestamp;
887
+ }
888
+ };
889
+ exports.processSyncAction = processSyncAction;
890
+ //# sourceMappingURL=chat-utils.js.map