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.
- package/LICENSE +22 -0
- package/README.md +82 -0
- package/WAProto/W +1 -0
- package/WAProto/WAProto.proto +6035 -0
- package/WAProto/index.d.ts +15932 -0
- package/WAProto/index.js +115856 -0
- package/engine-requirements.js +13 -0
- package/lib/Defaults/D +1 -0
- package/lib/Defaults/index.d.ts +145 -0
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +152 -0
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Signal/Group/G +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/Group/group-session-builder.d.ts +8 -0
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +11 -0
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +82 -0
- package/lib/Signal/Group/group_cipher.js.map +1 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.d.ts.map +1 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/index.js.map +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +7 -0
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +12 -0
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +13 -0
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +17 -0
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/S +1 -0
- package/lib/Signal/libsignal.d.ts +55 -0
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +431 -0
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Signal/lid-mapping.d.ts +21 -0
- package/lib/Signal/lid-mapping.d.ts.map +1 -0
- package/lib/Signal/lid-mapping.js +277 -0
- package/lib/Signal/lid-mapping.js.map +1 -0
- package/lib/Socket/Client/C +1 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +6 -0
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +54 -0
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +395 -0
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +380 -0
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +144 -0
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +1219 -0
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +562 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +432 -0
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +286 -0
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +348 -0
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +530 -0
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +22 -0
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +334 -0
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +1797 -0
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +330 -0
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +1396 -0
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +2 -0
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +283 -0
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +226 -0
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +61 -0
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +970 -0
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Store/S +1 -0
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.d.ts.map +1 -0
- package/lib/Store/index.js +4 -0
- package/lib/Store/index.js.map +1 -0
- package/lib/Store/make-in-memory-store.d.ts +63 -0
- package/lib/Store/make-in-memory-store.d.ts.map +1 -0
- package/lib/Store/make-in-memory-store.js +421 -0
- package/lib/Store/make-in-memory-store.js.map +1 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.d.ts.map +1 -0
- package/lib/Store/make-ordered-dictionary.js +79 -0
- package/lib/Store/make-ordered-dictionary.js.map +1 -0
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Store/object-repository.d.ts.map +1 -0
- package/lib/Store/object-repository.js +24 -0
- package/lib/Store/object-repository.js.map +1 -0
- package/lib/Types/Auth.d.ts +2 -0
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Auth.js.map +1 -0
- package/lib/Types/Bussines.d.ts +2 -0
- package/lib/Types/Bussines.d.ts.map +1 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts +2 -0
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +2 -0
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +2 -0
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +2 -0
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +2 -0
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +3 -0
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +3 -0
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +12 -0
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +18 -0
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Mex.d.ts +3 -0
- package/lib/Types/Mex.d.ts.map +1 -0
- package/lib/Types/Mex.js +39 -0
- package/lib/Types/Mex.js.map +1 -0
- package/lib/Types/Product.d.ts +2 -0
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/RichType.d.ts +3 -0
- package/lib/Types/RichType.d.ts.map +1 -0
- package/lib/Types/RichType.js +23 -0
- package/lib/Types/RichType.js.map +1 -0
- package/lib/Types/Signal.d.ts +2 -0
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +2 -0
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +6 -0
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +56 -0
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/T +1 -0
- package/lib/Types/USync.d.ts +2 -0
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +14 -0
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +26 -0
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/U +1 -0
- package/lib/Utils/advanced.js +89 -0
- package/lib/Utils/auth-utils.d.ts +58 -0
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +306 -0
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/browser-utils.d.ts +10 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -0
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts +50 -0
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +409 -0
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +872 -0
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +5 -0
- package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
- package/lib/Utils/companion-reg-client-utils.js +40 -0
- package/lib/Utils/companion-reg-client-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +118 -0
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +84 -0
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +317 -0
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/enchanted-utils.js +93 -0
- package/lib/Utils/event-buffer.d.ts +13 -0
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +622 -0
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +64 -0
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +395 -0
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +76 -0
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +134 -0
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/identity-change-handler.d.ts +14 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/identity-change-handler.js.map +1 -0
- package/lib/Utils/index.d.ts +25 -0
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +43 -0
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +13 -0
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +85 -0
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +3 -0
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +7 -0
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +8 -0
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-builder.js +198 -0
- package/lib/Utils/message-cache.js +144 -0
- package/lib/Utils/message-download-pipeline.js +216 -0
- package/lib/Utils/message-error.js +176 -0
- package/lib/Utils/message-framework.js +364 -0
- package/lib/Utils/message-logger.js +63 -0
- package/lib/Utils/message-metrics.js +173 -0
- package/lib/Utils/message-pipeline.js +236 -0
- package/lib/Utils/message-plugin.js +229 -0
- package/lib/Utils/message-queue.js +266 -0
- package/lib/Utils/message-retry-adaptive.js +216 -0
- package/lib/Utils/message-retry-manager.d.ts +80 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/message-upload-pipeline.js +244 -0
- package/lib/Utils/messages-media.d.ts +137 -0
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +843 -0
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +46 -0
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +1840 -0
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +201 -0
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/offline-node-processor.d.ts +10 -0
- package/lib/Utils/offline-node-processor.d.ts.map +1 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/offline-node-processor.js.map +1 -0
- package/lib/Utils/pre-key-manager.d.ts +26 -0
- package/lib/Utils/pre-key-manager.d.ts.map +1 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/pre-key-manager.js.map +1 -0
- package/lib/Utils/process-message.d.ts +84 -0
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +749 -0
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/reliability.js +70 -0
- package/lib/Utils/reporting-utils.d.ts +13 -0
- package/lib/Utils/reporting-utils.d.ts.map +1 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/reporting-utils.js.map +1 -0
- package/lib/Utils/rich-message-utils.d.ts +49 -0
- package/lib/Utils/rich-message-utils.d.ts.map +1 -0
- package/lib/Utils/rich-message-utils.js +370 -0
- package/lib/Utils/rich-message-utils.js.map +1 -0
- package/lib/Utils/signal.d.ts +83 -0
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +201 -0
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/stanza-ack.d.ts +17 -0
- package/lib/Utils/stanza-ack.d.ts.map +1 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/stanza-ack.js.map +1 -0
- package/lib/Utils/sync-action-utils.d.ts +3 -0
- package/lib/Utils/sync-action-utils.d.ts.map +1 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/sync-action-utils.js.map +1 -0
- package/lib/Utils/tc-token-utils.d.ts +30 -0
- package/lib/Utils/tc-token-utils.d.ts.map +1 -0
- package/lib/Utils/tc-token-utils.js +164 -0
- package/lib/Utils/tc-token-utils.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-single-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-single-file-auth-state.js +109 -0
- package/lib/Utils/use-single-file-auth-state.js.map +1 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-sqlite-auth-state.js +109 -0
- package/lib/Utils/use-sqlite-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +44 -0
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +210 -0
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +62 -0
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1467 -0
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +10 -0
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +262 -0
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/enchanted-binary.js +38 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +220 -0
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +77 -0
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +226 -0
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +8 -0
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +29 -0
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +96 -0
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +2 -0
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WABinary/w +1 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +34927 -0
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAM/w +1 -0
- package/lib/WAUSync/Protocols/P +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +37 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +15 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +6 -0
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +21 -0
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +98 -0
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +31 -0
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/W +1 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +12 -0
- package/lib/index.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metrics System — Counter, Gauge, Histogram + Registry.
|
|
3
|
+
* Expose via getMetrics() API.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export class Counter {
|
|
7
|
+
constructor(name, description = '') {
|
|
8
|
+
this.name = name; this.description = description;
|
|
9
|
+
this._value = 0; this._labels = new Map();
|
|
10
|
+
}
|
|
11
|
+
inc(amount = 1, labels = {}) {
|
|
12
|
+
this._value += amount;
|
|
13
|
+
const key = JSON.stringify(labels);
|
|
14
|
+
this._labels.set(key, (this._labels.get(key) || 0) + amount);
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
get value() { return this._value; }
|
|
18
|
+
reset() { this._value = 0; this._labels.clear(); return this; }
|
|
19
|
+
toJSON() { return { name: this.name, value: this._value, description: this.description }; }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class Gauge {
|
|
23
|
+
constructor(name, description = '') {
|
|
24
|
+
this.name = name; this.description = description; this._value = 0;
|
|
25
|
+
}
|
|
26
|
+
set(v) { this._value = v; return this; }
|
|
27
|
+
inc(v = 1) { this._value += v; return this; }
|
|
28
|
+
dec(v = 1) { this._value -= v; return this; }
|
|
29
|
+
get value() { return this._value; }
|
|
30
|
+
toJSON() { return { name: this.name, value: this._value, description: this.description }; }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class Histogram {
|
|
34
|
+
constructor(name, description = '', buckets = [5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000]) {
|
|
35
|
+
this.name = name; this.description = description;
|
|
36
|
+
this._buckets = buckets;
|
|
37
|
+
this._counts = new Array(buckets.length + 1).fill(0);
|
|
38
|
+
this._sum = 0; this._total = 0;
|
|
39
|
+
this._min = Infinity; this._max = -Infinity;
|
|
40
|
+
}
|
|
41
|
+
observe(value) {
|
|
42
|
+
this._sum += value; this._total++;
|
|
43
|
+
if (value < this._min) this._min = value;
|
|
44
|
+
if (value > this._max) this._max = value;
|
|
45
|
+
let placed = false;
|
|
46
|
+
for (let i = 0; i < this._buckets.length; i++) {
|
|
47
|
+
if (value <= this._buckets[i]) { this._counts[i]++; placed = true; break; }
|
|
48
|
+
}
|
|
49
|
+
if (!placed) this._counts[this._counts.length - 1]++;
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
get avg() { return this._total === 0 ? 0 : this._sum / this._total; }
|
|
53
|
+
get p50() { return this._percentile(50); }
|
|
54
|
+
get p95() { return this._percentile(95); }
|
|
55
|
+
get p99() { return this._percentile(99); }
|
|
56
|
+
_percentile(pct) {
|
|
57
|
+
if (this._total === 0) return 0;
|
|
58
|
+
const target = Math.ceil(this._total * pct / 100);
|
|
59
|
+
let cum = 0;
|
|
60
|
+
for (let i = 0; i < this._buckets.length; i++) {
|
|
61
|
+
cum += this._counts[i];
|
|
62
|
+
if (cum >= target) return this._buckets[i];
|
|
63
|
+
}
|
|
64
|
+
return this._max;
|
|
65
|
+
}
|
|
66
|
+
toJSON() {
|
|
67
|
+
return {
|
|
68
|
+
name: this.name, description: this.description,
|
|
69
|
+
count: this._total, sum: this._sum, avg: this.avg,
|
|
70
|
+
min: this._min === Infinity ? 0 : this._min,
|
|
71
|
+
max: this._max === -Infinity ? 0 : this._max,
|
|
72
|
+
p50: this.p50, p95: this.p95, p99: this.p99,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ─────────────────────────────────────────────
|
|
78
|
+
// METRICS REGISTRY
|
|
79
|
+
// ─────────────────────────────────────────────
|
|
80
|
+
|
|
81
|
+
export class MetricsRegistry {
|
|
82
|
+
constructor() {
|
|
83
|
+
this._counters = new Map();
|
|
84
|
+
this._gauges = new Map();
|
|
85
|
+
this._histograms = new Map();
|
|
86
|
+
|
|
87
|
+
// Pre-define standard metrics
|
|
88
|
+
const counters = [
|
|
89
|
+
'messages.sent.total', 'messages.received.total', 'messages.failed.total',
|
|
90
|
+
'messages.retry.total', 'messages.cancelled.total', 'messages.updated.total',
|
|
91
|
+
'media.upload.total', 'media.upload.failed', 'media.download.total', 'media.download.failed',
|
|
92
|
+
'encode.total', 'decode.total', 'hooks.fired',
|
|
93
|
+
'queue.enqueued', 'queue.dequeued', 'queue.dropped',
|
|
94
|
+
'errors.total', 'retries.total',
|
|
95
|
+
];
|
|
96
|
+
for (const name of counters) this._counters.set(name, new Counter(name));
|
|
97
|
+
|
|
98
|
+
const gauges = ['connections.active', 'queue.size'];
|
|
99
|
+
for (const name of gauges) this._gauges.set(name, new Gauge(name));
|
|
100
|
+
|
|
101
|
+
const histograms = [
|
|
102
|
+
'send.duration_ms', 'receive.duration_ms', 'encode.duration_ms',
|
|
103
|
+
'decode.duration_ms', 'upload.duration_ms', 'download.duration_ms',
|
|
104
|
+
'retry.delay_ms', 'queue.wait_ms',
|
|
105
|
+
];
|
|
106
|
+
for (const name of histograms) this._histograms.set(name, new Histogram(name));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ── Counter shortcuts ─────────────────────
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Inc a counter by name. Auto-creates if missing.
|
|
113
|
+
*/
|
|
114
|
+
inc(name, amount = 1, labels = {}) {
|
|
115
|
+
if (!this._counters.has(name)) this._counters.set(name, new Counter(name));
|
|
116
|
+
this._counters.get(name).inc(amount, labels);
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
counter(name) {
|
|
121
|
+
if (!this._counters.has(name)) this._counters.set(name, new Counter(name));
|
|
122
|
+
return this._counters.get(name);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ── Gauge shortcuts ───────────────────────
|
|
126
|
+
|
|
127
|
+
set(name, value) {
|
|
128
|
+
if (!this._gauges.has(name)) this._gauges.set(name, new Gauge(name));
|
|
129
|
+
this._gauges.get(name).set(value);
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
gauge(name) {
|
|
134
|
+
if (!this._gauges.has(name)) this._gauges.set(name, new Gauge(name));
|
|
135
|
+
return this._gauges.get(name);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ── Histogram shortcuts ───────────────────
|
|
139
|
+
|
|
140
|
+
observe(name, value) {
|
|
141
|
+
if (!this._histograms.has(name)) this._histograms.set(name, new Histogram(name));
|
|
142
|
+
this._histograms.get(name).observe(value);
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
histogram(name) {
|
|
147
|
+
if (!this._histograms.has(name)) this._histograms.set(name, new Histogram(name));
|
|
148
|
+
return this._histograms.get(name);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ── Get all metrics ───────────────────────
|
|
152
|
+
|
|
153
|
+
getAll() {
|
|
154
|
+
const result = {};
|
|
155
|
+
for (const [k, v] of this._counters) result[k] = v.toJSON();
|
|
156
|
+
for (const [k, v] of this._gauges) result[k] = v.toJSON();
|
|
157
|
+
for (const [k, v] of this._histograms) result[k] = v.toJSON();
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
reset() {
|
|
162
|
+
for (const c of this._counters.values()) c.reset();
|
|
163
|
+
for (const g of this._gauges.values()) g.set(0);
|
|
164
|
+
for (const h of this._histograms.values()) {
|
|
165
|
+
h._sum = 0; h._total = 0;
|
|
166
|
+
h._min = Infinity; h._max = -Infinity;
|
|
167
|
+
h._counts = new Array(h._buckets.length + 1).fill(0);
|
|
168
|
+
}
|
|
169
|
+
return this;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export const globalMetrics = new MetricsRegistry();
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message Pipeline — Middleware & Hook System
|
|
3
|
+
* Menyediakan pipeline middleware yang dapat diintervensi setiap tahap
|
|
4
|
+
* pengiriman dan penerimaan pesan.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// ─────────────────────────────────────────────
|
|
8
|
+
// MESSAGE CONTEXT
|
|
9
|
+
// ─────────────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
export function createMessageContext(overrides = {}) {
|
|
12
|
+
return {
|
|
13
|
+
socket: null, jid: null, sender: null, participant: null,
|
|
14
|
+
message: null, payload: null, options: {}, metadata: {},
|
|
15
|
+
timestamps: {
|
|
16
|
+
created: Date.now(), prepared: null, encoded: null,
|
|
17
|
+
sent: null, received: null, decoded: null, decrypted: null,
|
|
18
|
+
},
|
|
19
|
+
retry: { count: 0, maxCount: 5, history: [], lastError: null, policy: null },
|
|
20
|
+
upload: {
|
|
21
|
+
started: null, finished: null, url: null, directPath: null,
|
|
22
|
+
mediaKey: null, fileEncSha256: null, fileSha256: null,
|
|
23
|
+
fileLength: null, mediaType: null, mediaKeyTimestamp: null,
|
|
24
|
+
},
|
|
25
|
+
media: {
|
|
26
|
+
type: null, mimetype: null, thumbnail: null,
|
|
27
|
+
cached: false, compressed: false, width: null, height: null, duration: null,
|
|
28
|
+
},
|
|
29
|
+
cancelled: false, cancelReason: null, result: null, error: null,
|
|
30
|
+
tags: new Set(),
|
|
31
|
+
...overrides,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ─────────────────────────────────────────────
|
|
36
|
+
// MIDDLEWARE PIPELINE
|
|
37
|
+
// ─────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
export class MiddlewarePipeline {
|
|
40
|
+
constructor(name = 'unnamed') {
|
|
41
|
+
this.name = name;
|
|
42
|
+
this._middlewares = [];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
use(fn, priority = 0) {
|
|
46
|
+
if (typeof fn !== 'function')
|
|
47
|
+
throw new TypeError(`[MiddlewarePipeline:${this.name}] Middleware harus berupa function`);
|
|
48
|
+
this._middlewares.push({ fn, priority });
|
|
49
|
+
this._middlewares.sort((a, b) => b.priority - a.priority);
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
remove(fn) {
|
|
54
|
+
const idx = this._middlewares.findIndex(m => m.fn === fn);
|
|
55
|
+
if (idx !== -1) this._middlewares.splice(idx, 1);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async run(ctx, finalHandler) {
|
|
60
|
+
const fns = this._middlewares.map(m => m.fn);
|
|
61
|
+
let index = -1;
|
|
62
|
+
const dispatch = async (i) => {
|
|
63
|
+
if (i <= index)
|
|
64
|
+
throw new Error(`[MiddlewarePipeline:${this.name}] next() dipanggil lebih dari satu kali`);
|
|
65
|
+
index = i;
|
|
66
|
+
if (ctx.cancelled) return;
|
|
67
|
+
let fn = fns[i];
|
|
68
|
+
if (i === fns.length) fn = finalHandler;
|
|
69
|
+
if (!fn) return;
|
|
70
|
+
await fn(ctx, () => dispatch(i + 1));
|
|
71
|
+
};
|
|
72
|
+
return dispatch(0);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
clear() { this._middlewares = []; return this; }
|
|
76
|
+
get size() { return this._middlewares.length; }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ─────────────────────────────────────────────
|
|
80
|
+
// HOOK SYSTEM
|
|
81
|
+
// ─────────────────────────────────────────────
|
|
82
|
+
|
|
83
|
+
export class HookSystem {
|
|
84
|
+
constructor() {
|
|
85
|
+
this._hooks = new Map();
|
|
86
|
+
this._wildcardHooks = [];
|
|
87
|
+
this._maxListeners = 100;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
on(event, handler) {
|
|
91
|
+
if (typeof handler !== 'function')
|
|
92
|
+
throw new TypeError('[HookSystem] Handler harus berupa function');
|
|
93
|
+
if (!this._hooks.has(event)) this._hooks.set(event, []);
|
|
94
|
+
const list = this._hooks.get(event);
|
|
95
|
+
if (list.length >= this._maxListeners)
|
|
96
|
+
console.warn(`[HookSystem] Terlalu banyak handler untuk "${event}"`);
|
|
97
|
+
list.push(handler);
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
once(event, handler) {
|
|
102
|
+
const wrapper = async (ctx, ev) => { this.off(event, wrapper); return handler(ctx, ev); };
|
|
103
|
+
return this.on(event, wrapper);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
onAny(handler) {
|
|
107
|
+
if (typeof handler !== 'function')
|
|
108
|
+
throw new TypeError('[HookSystem] Handler harus berupa function');
|
|
109
|
+
this._wildcardHooks.push(handler);
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
off(event, handler) {
|
|
114
|
+
const handlers = this._hooks.get(event);
|
|
115
|
+
if (!handlers) return this;
|
|
116
|
+
const idx = handlers.indexOf(handler);
|
|
117
|
+
if (idx !== -1) handlers.splice(idx, 1);
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async emit(event, ctx) {
|
|
122
|
+
const handlers = this._hooks.get(event) || [];
|
|
123
|
+
const wildcards = this._wildcardHooks;
|
|
124
|
+
const all = [
|
|
125
|
+
...handlers.map(h => this._safeCall(h, ctx, event)),
|
|
126
|
+
...wildcards.map(h => this._safeCall(h, ctx, event)),
|
|
127
|
+
];
|
|
128
|
+
if (all.length === 0) return;
|
|
129
|
+
await Promise.allSettled(all);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async _safeCall(fn, ctx, event) {
|
|
133
|
+
try { return await fn(ctx, event); }
|
|
134
|
+
catch (err) { console.warn(`[HookSystem] Hook "${event}" error:`, err?.message); }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
removeAll(event) {
|
|
138
|
+
if (event) this._hooks.delete(event);
|
|
139
|
+
else { this._hooks.clear(); this._wildcardHooks = []; }
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
listEvents() { return [...this._hooks.keys()]; }
|
|
144
|
+
getHandlerCount(event) { return this._hooks.get(event)?.length ?? 0; }
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ─────────────────────────────────────────────
|
|
148
|
+
// PIPELINE REGISTRY
|
|
149
|
+
// ─────────────────────────────────────────────
|
|
150
|
+
|
|
151
|
+
export class PipelineRegistry {
|
|
152
|
+
constructor() {
|
|
153
|
+
this.hooks = new HookSystem();
|
|
154
|
+
|
|
155
|
+
// Send
|
|
156
|
+
this.beforeSend = new MiddlewarePipeline('before-send');
|
|
157
|
+
this.afterSend = new MiddlewarePipeline('after-send');
|
|
158
|
+
|
|
159
|
+
// Receive
|
|
160
|
+
this.beforeReceive = new MiddlewarePipeline('before-receive');
|
|
161
|
+
this.afterReceive = new MiddlewarePipeline('after-receive');
|
|
162
|
+
|
|
163
|
+
// Decode
|
|
164
|
+
this.beforeDecode = new MiddlewarePipeline('before-decode');
|
|
165
|
+
this.afterDecode = new MiddlewarePipeline('after-decode');
|
|
166
|
+
|
|
167
|
+
// Upload media
|
|
168
|
+
this.beforeUploadMedia = new MiddlewarePipeline('before-upload-media');
|
|
169
|
+
this.afterUploadMedia = new MiddlewarePipeline('after-upload-media');
|
|
170
|
+
|
|
171
|
+
// Download media
|
|
172
|
+
this.beforeDownloadMedia = new MiddlewarePipeline('before-download-media');
|
|
173
|
+
this.afterDownloadMedia = new MiddlewarePipeline('after-download-media');
|
|
174
|
+
|
|
175
|
+
// Encrypt / Decrypt
|
|
176
|
+
this.beforeEncrypt = new MiddlewarePipeline('before-encrypt');
|
|
177
|
+
this.afterEncrypt = new MiddlewarePipeline('after-encrypt');
|
|
178
|
+
this.beforeDecrypt = new MiddlewarePipeline('before-decrypt');
|
|
179
|
+
this.afterDecrypt = new MiddlewarePipeline('after-decrypt');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
use(name, fn, priority = 0) {
|
|
183
|
+
if (!this[name] || !(this[name] instanceof MiddlewarePipeline))
|
|
184
|
+
throw new Error(`[PipelineRegistry] Pipeline "${name}" tidak dikenal`);
|
|
185
|
+
this[name].use(fn, priority);
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
hook(event, handler) { this.hooks.on(event, handler); return this; }
|
|
190
|
+
|
|
191
|
+
clearAll() {
|
|
192
|
+
for (const key of Object.keys(this))
|
|
193
|
+
if (this[key] instanceof MiddlewarePipeline) this[key].clear();
|
|
194
|
+
this.hooks.removeAll();
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export const globalPipeline = new PipelineRegistry();
|
|
200
|
+
|
|
201
|
+
// ─────────────────────────────────────────────
|
|
202
|
+
// LIFECYCLE EVENTS
|
|
203
|
+
// ─────────────────────────────────────────────
|
|
204
|
+
|
|
205
|
+
export const LifecycleEvents = Object.freeze({
|
|
206
|
+
MESSAGE_CREATE: 'message:create',
|
|
207
|
+
MESSAGE_PREPARE: 'message:prepare',
|
|
208
|
+
MESSAGE_ENCODE: 'message:encode',
|
|
209
|
+
MESSAGE_SEND: 'message:send',
|
|
210
|
+
MESSAGE_SUCCESS: 'message:success',
|
|
211
|
+
MESSAGE_ERROR: 'message:error',
|
|
212
|
+
MESSAGE_RETRY: 'message:retry',
|
|
213
|
+
|
|
214
|
+
MESSAGE_RECEIVE: 'message:receive',
|
|
215
|
+
MESSAGE_DECODE: 'message:decode',
|
|
216
|
+
MESSAGE_DECRYPT: 'message:decrypt',
|
|
217
|
+
MESSAGE_UPDATE: 'message:update',
|
|
218
|
+
MESSAGE_DELETE: 'message:delete',
|
|
219
|
+
|
|
220
|
+
SEND_START: 'send:start',
|
|
221
|
+
SEND_FINISH: 'send:finish',
|
|
222
|
+
SEND_RETRY: 'send:retry',
|
|
223
|
+
SEND_FAILED: 'send:failed',
|
|
224
|
+
|
|
225
|
+
MEDIA_UPLOAD_START: 'media:upload:start',
|
|
226
|
+
MEDIA_UPLOAD_END: 'media:upload:end',
|
|
227
|
+
MEDIA_DOWNLOAD_START: 'media:download:start',
|
|
228
|
+
MEDIA_DOWNLOAD_END: 'media:download:end',
|
|
229
|
+
|
|
230
|
+
MESSAGE_PREPARED: 'message:prepared',
|
|
231
|
+
MESSAGE_VALIDATED: 'message:validated',
|
|
232
|
+
MESSAGE_QUEUED: 'message:queued',
|
|
233
|
+
MESSAGE_DEQUEUED: 'message:dequeued',
|
|
234
|
+
MESSAGE_ENCRYPTED: 'message:encrypted',
|
|
235
|
+
MESSAGE_DECRYPTED: 'message:decrypted',
|
|
236
|
+
});
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin System — Plugin dapat memodifikasi payload/metadata, replace media/caption,
|
|
3
|
+
* tambah button, block message, audit — tanpa menyentuh kode inti.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// ─────────────────────────────────────────────
|
|
7
|
+
// PLUGIN BASE CLASS
|
|
8
|
+
// ─────────────────────────────────────────────
|
|
9
|
+
|
|
10
|
+
export class BasePlugin {
|
|
11
|
+
/** @param {string} name — nama unik plugin */
|
|
12
|
+
constructor(name) {
|
|
13
|
+
if (!name) throw new Error('Plugin harus memiliki nama');
|
|
14
|
+
this.name = name;
|
|
15
|
+
this.version = '1.0.0';
|
|
16
|
+
this.enabled = true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Dipanggil saat plugin di-install. Override untuk inisialisasi. */
|
|
20
|
+
async install(context) {}
|
|
21
|
+
|
|
22
|
+
/** Dipanggil saat plugin di-uninstall. Override untuk cleanup. */
|
|
23
|
+
async uninstall() {}
|
|
24
|
+
|
|
25
|
+
/** Middleware send: (ctx, next) => {} */
|
|
26
|
+
async onSend(ctx, next) { return next(); }
|
|
27
|
+
|
|
28
|
+
/** Middleware receive: (ctx, next) => {} */
|
|
29
|
+
async onReceive(ctx, next) { return next(); }
|
|
30
|
+
|
|
31
|
+
/** Hook lifecycle: (ctx, event) => {} */
|
|
32
|
+
async onHook(ctx, event) {}
|
|
33
|
+
|
|
34
|
+
enable() { this.enabled = true; return this; }
|
|
35
|
+
disable() { this.enabled = false; return this; }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ─────────────────────────────────────────────
|
|
39
|
+
// PLUGIN MANAGER
|
|
40
|
+
// ─────────────────────────────────────────────
|
|
41
|
+
|
|
42
|
+
export class PluginManager {
|
|
43
|
+
/**
|
|
44
|
+
* @param {object} opts
|
|
45
|
+
* @param {object} opts.logger
|
|
46
|
+
* @param {object} opts.hooks — HookSystem
|
|
47
|
+
* @param {object} opts.metrics — MetricsRegistry
|
|
48
|
+
*/
|
|
49
|
+
constructor(opts = {}) {
|
|
50
|
+
this._logger = opts.logger ?? console;
|
|
51
|
+
this._hooks = opts.hooks ?? null;
|
|
52
|
+
this._metrics = opts.metrics ?? null;
|
|
53
|
+
this._plugins = new Map(); // name → plugin instance
|
|
54
|
+
this._socket = null;
|
|
55
|
+
this._pipeline = null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Attach ke socket & pipeline — dipanggil dari framework.attach()
|
|
60
|
+
*/
|
|
61
|
+
attach(socket, pipeline) {
|
|
62
|
+
this._socket = socket;
|
|
63
|
+
this._pipeline = pipeline;
|
|
64
|
+
|
|
65
|
+
// Wire semua plugin yang sudah di-install ke pipeline
|
|
66
|
+
for (const plugin of this._plugins.values()) {
|
|
67
|
+
if (plugin.enabled) this._wireToPipeline(plugin);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Install plugin.
|
|
73
|
+
* @param {BasePlugin|object} plugin
|
|
74
|
+
*/
|
|
75
|
+
async install(plugin) {
|
|
76
|
+
if (!plugin?.name) throw new Error('[PluginManager] Plugin harus memiliki properti "name"');
|
|
77
|
+
if (this._plugins.has(plugin.name)) {
|
|
78
|
+
this._log('warn', `Plugin "${plugin.name}" sudah di-install, skip`);
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
if (typeof plugin.install === 'function') {
|
|
84
|
+
await plugin.install({
|
|
85
|
+
socket: this._socket,
|
|
86
|
+
pipeline: this._pipeline,
|
|
87
|
+
hooks: this._hooks,
|
|
88
|
+
metrics: this._metrics,
|
|
89
|
+
logger: this._logger,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
this._plugins.set(plugin.name, plugin);
|
|
93
|
+
|
|
94
|
+
// Wire ke pipeline jika sudah ada
|
|
95
|
+
if (this._pipeline && plugin.enabled) {
|
|
96
|
+
this._wireToPipeline(plugin);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Wire ke hook system
|
|
100
|
+
if (this._hooks && typeof plugin.onHook === 'function') {
|
|
101
|
+
this._hooks.onAny(async (ctx, event) => {
|
|
102
|
+
if (plugin.enabled) {
|
|
103
|
+
await plugin.onHook(ctx, event);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this._log('info', `Plugin "${plugin.name}" v${plugin.version ?? '?'} berhasil di-install`);
|
|
109
|
+
if (this._metrics) this._metrics.inc('plugins.installed');
|
|
110
|
+
} catch (err) {
|
|
111
|
+
this._log('error', `Gagal install plugin "${plugin.name}": ${err?.message}`, { err });
|
|
112
|
+
throw err;
|
|
113
|
+
}
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Uninstall plugin.
|
|
119
|
+
*/
|
|
120
|
+
async uninstall(nameOrPlugin) {
|
|
121
|
+
const name = typeof nameOrPlugin === 'string' ? nameOrPlugin : nameOrPlugin?.name;
|
|
122
|
+
const plugin = this._plugins.get(name);
|
|
123
|
+
if (!plugin) return this;
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
if (typeof plugin.uninstall === 'function') await plugin.uninstall();
|
|
127
|
+
this._plugins.delete(name);
|
|
128
|
+
this._log('info', `Plugin "${name}" di-uninstall`);
|
|
129
|
+
} catch (err) {
|
|
130
|
+
this._log('warn', `Error saat uninstall plugin "${name}": ${err?.message}`);
|
|
131
|
+
}
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Uninstall semua plugin */
|
|
136
|
+
async uninstallAll() {
|
|
137
|
+
for (const name of [...this._plugins.keys()]) await this.uninstall(name);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Ambil plugin berdasarkan nama */
|
|
141
|
+
get(name) { return this._plugins.get(name); }
|
|
142
|
+
|
|
143
|
+
/** List semua plugin yang ter-install */
|
|
144
|
+
list() {
|
|
145
|
+
return [...this._plugins.values()].map(p => ({
|
|
146
|
+
name: p.name, version: p.version, enabled: p.enabled,
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Enable plugin */
|
|
151
|
+
enablePlugin(name) { const p = this._plugins.get(name); if (p) p.enable(); return this; }
|
|
152
|
+
|
|
153
|
+
/** Disable plugin */
|
|
154
|
+
disablePlugin(name) { const p = this._plugins.get(name); if (p) p.disable(); return this; }
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Jalankan semua plugin onSend terhadap context.
|
|
158
|
+
* Dipanggil dari relayMessageWithPipeline sebelum send.
|
|
159
|
+
*/
|
|
160
|
+
async applyToSend(ctx) {
|
|
161
|
+
for (const plugin of this._plugins.values()) {
|
|
162
|
+
if (!plugin.enabled) continue;
|
|
163
|
+
if (typeof plugin.onSend !== 'function') continue;
|
|
164
|
+
if (ctx.cancelled) break;
|
|
165
|
+
try {
|
|
166
|
+
await new Promise(async (resolve, reject) => {
|
|
167
|
+
try {
|
|
168
|
+
await plugin.onSend(ctx, resolve);
|
|
169
|
+
} catch (err) {
|
|
170
|
+
reject(err);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
} catch (err) {
|
|
174
|
+
this._log('warn', `Plugin "${plugin.name}" onSend error: ${err?.message}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Jalankan semua plugin onReceive terhadap context.
|
|
181
|
+
*/
|
|
182
|
+
async applyToReceive(ctx) {
|
|
183
|
+
for (const plugin of this._plugins.values()) {
|
|
184
|
+
if (!plugin.enabled) continue;
|
|
185
|
+
if (typeof plugin.onReceive !== 'function') continue;
|
|
186
|
+
if (ctx.cancelled) break;
|
|
187
|
+
try {
|
|
188
|
+
await new Promise(async (resolve, reject) => {
|
|
189
|
+
try {
|
|
190
|
+
await plugin.onReceive(ctx, resolve);
|
|
191
|
+
} catch (err) {
|
|
192
|
+
reject(err);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
} catch (err) {
|
|
196
|
+
this._log('warn', `Plugin "${plugin.name}" onReceive error: ${err?.message}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// ── Internal ──────────────────────────────
|
|
202
|
+
|
|
203
|
+
_wireToPipeline(plugin) {
|
|
204
|
+
if (!this._pipeline) return;
|
|
205
|
+
// Wire onSend sebagai middleware before-send
|
|
206
|
+
if (typeof plugin.onSend === 'function') {
|
|
207
|
+
this._pipeline.beforeSend.use(
|
|
208
|
+
(ctx, next) => plugin.enabled ? plugin.onSend(ctx, next) : next(),
|
|
209
|
+
plugin.priority ?? 0
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
// Wire onReceive sebagai middleware before-receive
|
|
213
|
+
if (typeof plugin.onReceive === 'function') {
|
|
214
|
+
this._pipeline.beforeReceive.use(
|
|
215
|
+
(ctx, next) => plugin.enabled ? plugin.onReceive(ctx, next) : next(),
|
|
216
|
+
plugin.priority ?? 0
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
_log(level, msg, data) {
|
|
222
|
+
const prefix = '[PluginManager]';
|
|
223
|
+
if (this._logger?.[level]) this._logger[level](data ?? {}, `${prefix} ${msg}`);
|
|
224
|
+
else if (level === 'error') console.error(`${prefix} ${msg}`, data);
|
|
225
|
+
else console.log(`${prefix} ${msg}`, data);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export const globalPluginManager = new PluginManager();
|