@eduh_dev021/baileys 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +1843 -2
- package/WAProto/index.d.ts +22220 -0
- package/WAProto/index.js +5 -0
- package/cjs/WAProto/index.d.ts +22220 -0
- package/cjs/WAProto/index.js +60125 -0
- package/cjs/engine-requirements.js +12 -0
- package/cjs/lib/Addon/cache.js +179 -0
- package/cjs/lib/Addon/crc32.js +41 -0
- package/cjs/lib/Addon/file-type.js +217 -0
- package/cjs/lib/Addon/get-file.js +99 -0
- package/cjs/lib/Addon/http-error.d.ts +18 -0
- package/cjs/lib/Addon/http-error.js +66 -0
- package/cjs/lib/Addon/index.d.ts +96 -0
- package/cjs/lib/Addon/index.js +58 -0
- package/cjs/lib/Addon/keyed-db.d.ts +14 -0
- package/cjs/lib/Addon/keyed-db.js +264 -0
- package/cjs/lib/Addon/link-preview.d.ts +15 -0
- package/cjs/lib/Addon/link-preview.js +104 -0
- package/cjs/lib/Addon/media-info.js +98 -0
- package/cjs/lib/Addon/mutex.js +78 -0
- package/cjs/lib/Addon/qr.js +464 -0
- package/cjs/lib/Addon/queue.js +54 -0
- package/cjs/lib/Addon/waveform.js +130 -0
- package/cjs/lib/Addon/zip.js +136 -0
- package/cjs/lib/Defaults/index.d.ts +184 -0
- package/cjs/lib/Defaults/index.js +292 -0
- package/cjs/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/cjs/lib/Signal/Group/ciphertext-message.js +37 -0
- package/cjs/lib/Signal/Group/group-cipher.d.ts +10 -0
- package/cjs/lib/Signal/Group/group-cipher.js +105 -0
- package/cjs/lib/Signal/Group/group-session-builder.d.ts +7 -0
- package/cjs/lib/Signal/Group/group-session-builder.js +65 -0
- package/cjs/lib/Signal/Group/index.d.ts +11 -0
- package/cjs/lib/Signal/Group/index.js +67 -0
- package/cjs/lib/Signal/Group/keyhelper.d.ts +6 -0
- package/cjs/lib/Signal/Group/keyhelper.js +47 -0
- package/cjs/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/cjs/lib/Signal/Group/sender-chain-key.js +51 -0
- package/cjs/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/cjs/lib/Signal/Group/sender-key-distribution-message.js +80 -0
- package/cjs/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/cjs/lib/Signal/Group/sender-key-message.js +87 -0
- package/cjs/lib/Signal/Group/sender-key-name.d.ts +11 -0
- package/cjs/lib/Signal/Group/sender-key-name.js +73 -0
- package/cjs/lib/Signal/Group/sender-key-record.d.ts +12 -0
- package/cjs/lib/Signal/Group/sender-key-record.js +66 -0
- package/cjs/lib/Signal/Group/sender-key-state.d.ts +16 -0
- package/cjs/lib/Signal/Group/sender-key-state.js +106 -0
- package/cjs/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/cjs/lib/Signal/Group/sender-message-key.js +51 -0
- package/cjs/lib/Signal/libsignal.d.ts +54 -0
- package/cjs/lib/Signal/libsignal.js +421 -0
- package/cjs/lib/Signal/lid-mapping.d.ts +20 -0
- package/cjs/lib/Signal/lid-mapping.js +292 -0
- package/cjs/lib/Socket/Client/index.d.ts +2 -0
- package/cjs/lib/Socket/Client/index.js +23 -0
- package/cjs/lib/Socket/Client/types.d.ts +5 -0
- package/cjs/lib/Socket/Client/types.js +36 -0
- package/cjs/lib/Socket/Client/websocket.d.ts +12 -0
- package/cjs/lib/Socket/Client/websocket.js +143 -0
- package/cjs/lib/Socket/business.d.ts +387 -0
- package/cjs/lib/Socket/business.js +402 -0
- package/cjs/lib/Socket/chats.d.ts +144 -0
- package/cjs/lib/Socket/chats.js +1118 -0
- package/cjs/lib/Socket/communities.d.ts +554 -0
- package/cjs/lib/Socket/communities.js +456 -0
- package/cjs/lib/Socket/groups.d.ts +286 -0
- package/cjs/lib/Socket/groups.js +366 -0
- package/cjs/lib/Socket/index.d.ts +522 -0
- package/cjs/lib/Socket/index.js +32 -0
- package/cjs/lib/Socket/messages-recv.d.ts +326 -0
- package/cjs/lib/Socket/messages-recv.js +1670 -0
- package/cjs/lib/Socket/messages-send.d.ts +321 -0
- package/cjs/lib/Socket/messages-send.js +1252 -0
- package/cjs/lib/Socket/mex.d.ts +1 -0
- package/cjs/lib/Socket/mex.js +65 -0
- package/cjs/lib/Socket/newsletter.d.ts +283 -0
- package/cjs/lib/Socket/newsletter.js +243 -0
- package/cjs/lib/Socket/socket.d.ts +61 -0
- package/cjs/lib/Socket/socket.js +908 -0
- package/cjs/lib/Store/index.d.ts +3 -0
- package/cjs/lib/Store/index.js +25 -0
- package/cjs/lib/Store/make-in-memory-store.d.ts +63 -0
- package/cjs/lib/Store/make-in-memory-store.js +431 -0
- package/cjs/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/cjs/lib/Store/make-ordered-dictionary.js +101 -0
- package/cjs/lib/Store/object-repository.d.ts +10 -0
- package/cjs/lib/Store/object-repository.js +49 -0
- package/cjs/lib/Transport/crypto.d.ts +6 -0
- package/cjs/lib/Transport/crypto.js +107 -0
- package/cjs/lib/Transport/curve.d.ts +8 -0
- package/cjs/lib/Transport/curve.js +94 -0
- package/cjs/lib/Transport/index.d.ts +16 -0
- package/cjs/lib/Transport/index.js +67 -0
- package/cjs/lib/Transport/internals.d.ts +57 -0
- package/cjs/lib/Transport/internals.js +203 -0
- package/cjs/lib/Transport/session-builder.d.ts +40 -0
- package/cjs/lib/Transport/session-builder.js +169 -0
- package/cjs/lib/Transport/session-cipher.d.ts +26 -0
- package/cjs/lib/Transport/session-cipher.js +328 -0
- package/cjs/lib/Transport/session-record.d.ts +55 -0
- package/cjs/lib/Transport/session-record.js +289 -0
- package/cjs/lib/Types/Auth.d.ts +1 -0
- package/cjs/lib/Types/Auth.js +15 -0
- package/cjs/lib/Types/Bussines.d.ts +1 -0
- package/cjs/lib/Types/Bussines.js +15 -0
- package/cjs/lib/Types/Call.d.ts +1 -0
- package/cjs/lib/Types/Call.js +15 -0
- package/cjs/lib/Types/Chat.d.ts +1 -0
- package/cjs/lib/Types/Chat.js +33 -0
- package/cjs/lib/Types/Contact.d.ts +1 -0
- package/cjs/lib/Types/Contact.js +15 -0
- package/cjs/lib/Types/Events.d.ts +1 -0
- package/cjs/lib/Types/Events.js +1 -0
- package/cjs/lib/Types/GroupMetadata.d.ts +1 -0
- package/cjs/lib/Types/GroupMetadata.js +15 -0
- package/cjs/lib/Types/Label.d.ts +2 -0
- package/cjs/lib/Types/Label.js +49 -0
- package/cjs/lib/Types/LabelAssociation.d.ts +2 -0
- package/cjs/lib/Types/LabelAssociation.js +31 -0
- package/cjs/lib/Types/Message.d.ts +11 -0
- package/cjs/lib/Types/Message.js +58 -0
- package/cjs/lib/Types/Mex.d.ts +2 -0
- package/cjs/lib/Types/Mex.js +66 -0
- package/cjs/lib/Types/Product.d.ts +1 -0
- package/cjs/lib/Types/Product.js +15 -0
- package/cjs/lib/Types/RichType.d.ts +2 -0
- package/cjs/lib/Types/RichType.js +50 -0
- package/cjs/lib/Types/Signal.d.ts +1 -0
- package/cjs/lib/Types/Signal.js +1 -0
- package/cjs/lib/Types/Socket.d.ts +1 -0
- package/cjs/lib/Types/Socket.js +1 -0
- package/cjs/lib/Types/State.d.ts +5 -0
- package/cjs/lib/Types/State.js +83 -0
- package/cjs/lib/Types/USync.d.ts +1 -0
- package/cjs/lib/Types/USync.js +1 -0
- package/cjs/lib/Types/index.d.ts +13 -0
- package/cjs/lib/Types/index.js +64 -0
- package/cjs/lib/Utils/auth-utils.d.ts +58 -0
- package/cjs/lib/Utils/auth-utils.js +275 -0
- package/cjs/lib/Utils/browser-utils.d.ts +9 -0
- package/cjs/lib/Utils/browser-utils.js +56 -0
- package/cjs/lib/Utils/business.d.ts +49 -0
- package/cjs/lib/Utils/business.js +259 -0
- package/cjs/lib/Utils/chat-utils.d.ts +408 -0
- package/cjs/lib/Utils/chat-utils.js +821 -0
- package/cjs/lib/Utils/companion-reg-client-utils.d.ts +4 -0
- package/cjs/lib/Utils/companion-reg-client-utils.js +71 -0
- package/cjs/lib/Utils/crypto.d.ts +39 -0
- package/cjs/lib/Utils/crypto.js +155 -0
- package/cjs/lib/Utils/decode-wa-message.d.ts +83 -0
- package/cjs/lib/Utils/decode-wa-message.js +316 -0
- package/cjs/lib/Utils/event-buffer.d.ts +12 -0
- package/cjs/lib/Utils/event-buffer.js +605 -0
- package/cjs/lib/Utils/generics.d.ts +63 -0
- package/cjs/lib/Utils/generics.js +440 -0
- package/cjs/lib/Utils/history.d.ts +75 -0
- package/cjs/lib/Utils/history.js +153 -0
- package/cjs/lib/Utils/identity-change-handler.d.ts +13 -0
- package/cjs/lib/Utils/identity-change-handler.js +73 -0
- package/cjs/lib/Utils/index.d.ts +24 -0
- package/cjs/lib/Utils/index.js +67 -0
- package/cjs/lib/Utils/link-preview.d.ts +13 -0
- package/cjs/lib/Utils/link-preview.js +87 -0
- package/cjs/lib/Utils/logger.d.ts +12 -0
- package/cjs/lib/Utils/logger.js +40 -0
- package/cjs/lib/Utils/lt-hash.d.ts +6 -0
- package/cjs/lib/Utils/lt-hash.js +28 -0
- package/cjs/lib/Utils/make-mutex.d.ts +6 -0
- package/cjs/lib/Utils/make-mutex.js +58 -0
- package/cjs/lib/Utils/message-retry-manager.d.ts +79 -0
- package/cjs/lib/Utils/message-retry-manager.js +274 -0
- package/cjs/lib/Utils/messages-media.d.ts +134 -0
- package/cjs/lib/Utils/messages-media.js +799 -0
- package/cjs/lib/Utils/messages.d.ts +47 -0
- package/cjs/lib/Utils/messages.js +1667 -0
- package/cjs/lib/Utils/noise-handler.d.ts +20 -0
- package/cjs/lib/Utils/noise-handler.js +223 -0
- package/cjs/lib/Utils/offline-node-processor.d.ts +10 -0
- package/cjs/lib/Utils/offline-node-processor.js +60 -0
- package/cjs/lib/Utils/pre-key-manager.d.ts +25 -0
- package/cjs/lib/Utils/pre-key-manager.js +116 -0
- package/cjs/lib/Utils/process-message.d.ts +83 -0
- package/cjs/lib/Utils/process-message.js +607 -0
- package/cjs/lib/Utils/reporting-utils.d.ts +12 -0
- package/cjs/lib/Utils/reporting-utils.js +282 -0
- package/cjs/lib/Utils/rich-message-utils.d.ts +48 -0
- package/cjs/lib/Utils/rich-message-utils.js +381 -0
- package/cjs/lib/Utils/signal.d.ts +82 -0
- package/cjs/lib/Utils/signal.js +232 -0
- package/cjs/lib/Utils/stanza-ack.d.ts +16 -0
- package/cjs/lib/Utils/stanza-ack.js +53 -0
- package/cjs/lib/Utils/sync-action-utils.d.ts +2 -0
- package/cjs/lib/Utils/sync-action-utils.js +68 -0
- package/cjs/lib/Utils/tc-token-utils.d.ts +29 -0
- package/cjs/lib/Utils/tc-token-utils.js +182 -0
- package/cjs/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
- package/cjs/lib/Utils/use-multi-file-auth-state.js +135 -0
- package/cjs/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/cjs/lib/Utils/use-single-file-auth-state.js +115 -0
- package/cjs/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/cjs/lib/Utils/use-sqlite-auth-state.js +140 -0
- package/cjs/lib/Utils/validate-connection.d.ts +44 -0
- package/cjs/lib/Utils/validate-connection.js +229 -0
- package/cjs/lib/WABinary/constants.d.ts +61 -0
- package/cjs/lib/WABinary/constants.js +1992 -0
- package/cjs/lib/WABinary/decode.d.ts +9 -0
- package/cjs/lib/WABinary/decode.js +292 -0
- package/cjs/lib/WABinary/encode.d.ts +2 -0
- package/cjs/lib/WABinary/encode.js +240 -0
- package/cjs/lib/WABinary/generic-utils.d.ts +79 -0
- package/cjs/lib/WABinary/generic-utils.js +252 -0
- package/cjs/lib/WABinary/index.d.ts +5 -0
- package/cjs/lib/WABinary/index.js +29 -0
- package/cjs/lib/WABinary/jid-utils.d.ts +28 -0
- package/cjs/lib/WABinary/jid-utils.js +151 -0
- package/cjs/lib/WABinary/types.d.ts +1 -0
- package/cjs/lib/WABinary/types.js +23 -0
- package/cjs/lib/WACrypto/appstate-keys.js +39 -0
- package/cjs/lib/WACrypto/curves/constants.js +37 -0
- package/cjs/lib/WACrypto/hkdf.js +38 -0
- package/cjs/lib/WACrypto/index.js +51 -0
- package/cjs/lib/WACrypto/lthash.js +59 -0
- package/cjs/lib/WACrypto/math/constants.js +53 -0
- package/cjs/lib/WACrypto/math/edwards.js +206 -0
- package/cjs/lib/WACrypto/math/fe.js +449 -0
- package/cjs/lib/WACrypto/math/le.js +44 -0
- package/cjs/lib/WACrypto/math/mod.js +36 -0
- package/cjs/lib/WACrypto/util/bytes.js +348 -0
- package/cjs/lib/WACrypto/x25519.js +157 -0
- package/cjs/lib/WACrypto/xeddsa.js +134 -0
- package/cjs/lib/WAM/BinaryInfo.d.ts +7 -0
- package/cjs/lib/WAM/BinaryInfo.js +35 -0
- package/cjs/lib/WAM/constants.d.ts +34926 -0
- package/cjs/lib/WAM/constants.js +22890 -0
- package/cjs/lib/WAM/encode.d.ts +1 -0
- package/cjs/lib/WAM/encode.js +162 -0
- package/cjs/lib/WAM/index.d.ts +3 -0
- package/cjs/lib/WAM/index.js +25 -0
- package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.js +77 -0
- package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.js +76 -0
- package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +52 -0
- package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.js +61 -0
- package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.js +50 -0
- package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +76 -0
- package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.js +53 -0
- package/cjs/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/cjs/lib/WAUSync/Protocols/index.js +29 -0
- package/cjs/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/cjs/lib/WAUSync/USyncQuery.js +113 -0
- package/cjs/lib/WAUSync/USyncUser.d.ts +16 -0
- package/cjs/lib/WAUSync/USyncUser.js +56 -0
- package/cjs/lib/WAUSync/index.d.ts +3 -0
- package/cjs/lib/WAUSync/index.js +25 -0
- package/cjs/lib/index.d.ts +11 -0
- package/cjs/lib/index.js +56 -0
- package/cjs/package.json +3 -0
- package/engine-requirements.js +12 -0
- package/lib/Addon/cache.js +201 -0
- package/lib/Addon/crc32.js +21 -0
- package/lib/Addon/file-type.js +198 -0
- package/lib/Addon/get-file.js +98 -0
- package/lib/Addon/http-error.d.ts +18 -0
- package/lib/Addon/http-error.js +40 -0
- package/lib/Addon/index.d.ts +96 -0
- package/lib/Addon/index.js +26 -0
- package/lib/Addon/keyed-db.d.ts +14 -0
- package/lib/Addon/keyed-db.js +241 -0
- package/lib/Addon/link-preview.d.ts +15 -0
- package/lib/Addon/link-preview.js +79 -0
- package/lib/Addon/media-info.js +96 -0
- package/lib/Addon/mutex.js +76 -0
- package/lib/Addon/qr.js +531 -0
- package/lib/Addon/queue.js +44 -0
- package/lib/Addon/waveform.js +135 -0
- package/lib/Addon/zip.js +144 -0
- package/lib/Defaults/index.d.ts +184 -0
- package/lib/Defaults/index.js +181 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +11 -0
- package/lib/Signal/Group/group-cipher.d.ts +10 -0
- package/lib/Signal/Group/group-cipher.js +81 -0
- package/lib/Signal/Group/group-session-builder.d.ts +7 -0
- package/lib/Signal/Group/group-session-builder.js +29 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +6 -0
- package/lib/Signal/Group/keyhelper.js +17 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +25 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +65 -0
- package/lib/Signal/Group/sender-key-name.d.ts +11 -0
- package/lib/Signal/Group/sender-key-name.js +47 -0
- package/lib/Signal/Group/sender-key-record.d.ts +12 -0
- package/lib/Signal/Group/sender-key-record.js +40 -0
- package/lib/Signal/Group/sender-key-state.d.ts +16 -0
- package/lib/Signal/Group/sender-key-state.js +83 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +25 -0
- package/lib/Signal/libsignal.d.ts +54 -0
- package/lib/Signal/libsignal.js +426 -0
- package/lib/Signal/lid-mapping.d.ts +20 -0
- package/lib/Signal/lid-mapping.js +274 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +2 -0
- package/lib/Socket/Client/types.d.ts +5 -0
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +119 -0
- package/lib/Socket/business.d.ts +387 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/chats.d.ts +144 -0
- package/lib/Socket/chats.js +1216 -0
- package/lib/Socket/communities.d.ts +554 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/groups.d.ts +286 -0
- package/lib/Socket/groups.js +347 -0
- package/lib/Socket/index.d.ts +522 -0
- package/lib/Socket/index.js +11 -0
- package/lib/Socket/messages-recv.d.ts +326 -0
- package/lib/Socket/messages-recv.js +1822 -0
- package/lib/Socket/messages-send.d.ts +321 -0
- package/lib/Socket/messages-send.js +1378 -0
- package/lib/Socket/mex.d.ts +1 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.d.ts +283 -0
- package/lib/Socket/newsletter.js +225 -0
- package/lib/Socket/socket.d.ts +61 -0
- package/lib/Socket/socket.js +992 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +3 -0
- package/lib/Store/make-in-memory-store.d.ts +63 -0
- package/lib/Store/make-in-memory-store.js +419 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +23 -0
- package/lib/Transport/crypto.d.ts +6 -0
- package/lib/Transport/crypto.js +61 -0
- package/lib/Transport/curve.d.ts +8 -0
- package/lib/Transport/curve.js +66 -0
- package/lib/Transport/index.d.ts +16 -0
- package/lib/Transport/index.js +9 -0
- package/lib/Transport/internals.d.ts +57 -0
- package/lib/Transport/internals.js +155 -0
- package/lib/Transport/session-builder.d.ts +40 -0
- package/lib/Transport/session-builder.js +143 -0
- package/lib/Transport/session-cipher.d.ts +26 -0
- package/lib/Transport/session-cipher.js +301 -0
- package/lib/Transport/session-record.d.ts +55 -0
- package/lib/Transport/session-record.js +272 -0
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.d.ts +1 -0
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.d.ts +1 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +1 -0
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Contact.d.ts +1 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +1 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +1 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +2 -0
- package/lib/Types/Label.js +24 -0
- package/lib/Types/LabelAssociation.d.ts +2 -0
- package/lib/Types/LabelAssociation.js +6 -0
- package/lib/Types/Message.d.ts +11 -0
- package/lib/Types/Message.js +17 -0
- package/lib/Types/Mex.d.ts +2 -0
- package/lib/Types/Mex.js +38 -0
- package/lib/Types/Product.d.ts +1 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/RichType.d.ts +2 -0
- package/lib/Types/RichType.js +22 -0
- package/lib/Types/Signal.d.ts +1 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +1 -0
- package/lib/Types/Socket.js +1 -0
- package/lib/Types/State.d.ts +5 -0
- package/lib/Types/State.js +54 -0
- package/lib/Types/USync.d.ts +1 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +13 -0
- package/lib/Types/index.js +25 -0
- package/lib/Utils/auth-utils.d.ts +58 -0
- package/lib/Utils/auth-utils.js +316 -0
- package/lib/Utils/browser-utils.d.ts +9 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.d.ts +49 -0
- package/lib/Utils/business.js +230 -0
- package/lib/Utils/chat-utils.d.ts +408 -0
- package/lib/Utils/chat-utils.js +871 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
- package/lib/Utils/companion-reg-client-utils.js +39 -0
- package/lib/Utils/crypto.d.ts +39 -0
- package/lib/Utils/crypto.js +117 -0
- package/lib/Utils/decode-wa-message.d.ts +83 -0
- package/lib/Utils/decode-wa-message.js +316 -0
- package/lib/Utils/event-buffer.d.ts +12 -0
- package/lib/Utils/event-buffer.js +621 -0
- package/lib/Utils/generics.d.ts +63 -0
- package/lib/Utils/generics.js +394 -0
- package/lib/Utils/history.d.ts +75 -0
- package/lib/Utils/history.js +133 -0
- package/lib/Utils/identity-change-handler.d.ts +13 -0
- package/lib/Utils/identity-change-handler.js +48 -0
- package/lib/Utils/index.d.ts +24 -0
- package/lib/Utils/index.js +24 -0
- package/lib/Utils/link-preview.d.ts +13 -0
- package/lib/Utils/link-preview.js +73 -0
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.js +12 -0
- package/lib/Utils/lt-hash.d.ts +6 -0
- package/lib/Utils/lt-hash.js +7 -0
- package/lib/Utils/make-mutex.d.ts +6 -0
- package/lib/Utils/make-mutex.js +32 -0
- package/lib/Utils/message-retry-manager.d.ts +79 -0
- package/lib/Utils/message-retry-manager.js +259 -0
- package/lib/Utils/messages-media.d.ts +134 -0
- package/lib/Utils/messages-media.js +802 -0
- package/lib/Utils/messages.d.ts +47 -0
- package/lib/Utils/messages.js +1907 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +200 -0
- package/lib/Utils/offline-node-processor.d.ts +10 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.d.ts +25 -0
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.d.ts +83 -0
- package/lib/Utils/process-message.js +748 -0
- package/lib/Utils/reporting-utils.d.ts +12 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-message-utils.d.ts +48 -0
- package/lib/Utils/rich-message-utils.js +366 -0
- package/lib/Utils/signal.d.ts +82 -0
- package/lib/Utils/signal.js +200 -0
- package/lib/Utils/stanza-ack.d.ts +16 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/sync-action-utils.d.ts +2 -0
- package/lib/Utils/sync-action-utils.js +48 -0
- package/lib/Utils/tc-token-utils.d.ts +29 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
- package/lib/Utils/use-multi-file-auth-state.js +116 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-single-file-auth-state.js +94 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.js +109 -0
- package/lib/Utils/validate-connection.d.ts +44 -0
- package/lib/Utils/validate-connection.js +210 -0
- package/lib/WABinary/constants.d.ts +61 -0
- package/lib/WABinary/constants.js +1466 -0
- package/lib/WABinary/decode.d.ts +9 -0
- package/lib/WABinary/decode.js +261 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +219 -0
- package/lib/WABinary/generic-utils.d.ts +79 -0
- package/lib/WABinary/generic-utils.js +226 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +5 -0
- package/lib/WABinary/jid-utils.d.ts +28 -0
- package/lib/WABinary/jid-utils.js +95 -0
- package/lib/WABinary/types.d.ts +1 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WACrypto/appstate-keys.js +26 -0
- package/lib/WACrypto/curves/constants.js +12 -0
- package/lib/WACrypto/hkdf.js +27 -0
- package/lib/WACrypto/index.js +20 -0
- package/lib/WACrypto/lthash.js +54 -0
- package/lib/WACrypto/math/constants.js +24 -0
- package/lib/WACrypto/math/edwards.js +194 -0
- package/lib/WACrypto/math/fe.js +698 -0
- package/lib/WACrypto/math/le.js +23 -0
- package/lib/WACrypto/math/mod.js +15 -0
- package/lib/WACrypto/util/bytes.js +339 -0
- package/lib/WACrypto/x25519.js +145 -0
- package/lib/WACrypto/xeddsa.js +92 -0
- package/lib/WAM/BinaryInfo.d.ts +7 -0
- package/lib/WAM/BinaryInfo.js +9 -0
- package/lib/WAM/constants.d.ts +34926 -0
- package/lib/WAM/constants.js +22852 -0
- package/lib/WAM/encode.d.ts +1 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.js +5 -0
- package/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/lib/WAUSync/USyncQuery.js +97 -0
- package/lib/WAUSync/USyncUser.d.ts +16 -0
- package/lib/WAUSync/USyncUser.js +30 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +11 -0
- package/package.json +74 -5
- package/tests/addon-test.mjs +162 -0
- package/tests/differential-test.mjs +90 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Addon utilities — a small, dependency-free toolkit used by the library
|
|
3
|
+
* internals and exported for public use:
|
|
4
|
+
*
|
|
5
|
+
* - createCache TTL + LRU in-memory cache
|
|
6
|
+
* - createMutex async mutual-exclusion lock
|
|
7
|
+
* - createQueue bounded-concurrency task queue
|
|
8
|
+
* - createZip in-memory ZIP archive builder
|
|
9
|
+
* - detectFileType magic-byte file type detection
|
|
10
|
+
* - detectMediaInfo width/height/duration probing via ffprobe
|
|
11
|
+
* - encodeQR QR Code encoder (terminal ASCII + PNG)
|
|
12
|
+
* - getAudioWaveform 64-bar audio waveform via ffmpeg
|
|
13
|
+
* - getFile normalize any media source to a local path
|
|
14
|
+
*/
|
|
15
|
+
export { createCache } from './cache.js';
|
|
16
|
+
export { createMutex } from './mutex.js';
|
|
17
|
+
export { createQueue } from './queue.js';
|
|
18
|
+
export { createZip } from './zip.js';
|
|
19
|
+
export { detectFileType } from './file-type.js';
|
|
20
|
+
export { detectMediaInfo } from './media-info.js';
|
|
21
|
+
export { encodeQR } from './qr.js';
|
|
22
|
+
export { getAudioWaveform } from './waveform.js';
|
|
23
|
+
export { getFile } from './get-file.js';
|
|
24
|
+
export * from './http-error.js';
|
|
25
|
+
export * from './keyed-db.js';
|
|
26
|
+
export * from './link-preview.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class KeyedDB {
|
|
2
|
+
constructor(key: any, id: any);
|
|
3
|
+
clear(): void;
|
|
4
|
+
insertIfAbsent(...values: any[]): any[];
|
|
5
|
+
upsert(...values: any[]): any[];
|
|
6
|
+
update(id: any, callback: any): 1 | 2 | undefined;
|
|
7
|
+
get(id: any): any;
|
|
8
|
+
deleteById(id: any, assertPresent?: boolean): any;
|
|
9
|
+
delete(value: any): any;
|
|
10
|
+
filter(predicate?: () => boolean): KeyedDB;
|
|
11
|
+
all(): any[];
|
|
12
|
+
toJSON(): any[];
|
|
13
|
+
#private;
|
|
14
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _KeyedDB_instances, _KeyedDB_spec, _KeyedDB_idGetter, _KeyedDB_items, _KeyedDB_byId, _KeyedDB_key, _KeyedDB_id, _KeyedDB_lowerBound, _KeyedDB_sameKey, _KeyedDB_insertNew;
|
|
13
|
+
function snapshotProperties(value) {
|
|
14
|
+
if (value === null || (typeof value !== 'object' && typeof value !== 'function')) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return Object.getOwnPropertyDescriptors(value);
|
|
18
|
+
}
|
|
19
|
+
function restoreProperties(value, snapshot) {
|
|
20
|
+
if (!snapshot) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
24
|
+
if (!Object.prototype.hasOwnProperty.call(snapshot, key)) {
|
|
25
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
26
|
+
if (descriptor?.configurable) {
|
|
27
|
+
Reflect.deleteProperty(value, key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
Object.defineProperties(value, snapshot);
|
|
32
|
+
}
|
|
33
|
+
export class KeyedDB {
|
|
34
|
+
constructor(key, id) {
|
|
35
|
+
_KeyedDB_instances.add(this);
|
|
36
|
+
_KeyedDB_spec.set(this, void 0);
|
|
37
|
+
_KeyedDB_idGetter.set(this, void 0);
|
|
38
|
+
_KeyedDB_items.set(this, []);
|
|
39
|
+
_KeyedDB_byId.set(this, new Map());
|
|
40
|
+
if (typeof key?.key !== 'function' || typeof key?.compare !== 'function') {
|
|
41
|
+
throw new TypeError('key must provide key(value) and compare(a, b) functions');
|
|
42
|
+
}
|
|
43
|
+
if (id !== undefined && typeof id !== 'function') {
|
|
44
|
+
throw new TypeError('id must be a function');
|
|
45
|
+
}
|
|
46
|
+
__classPrivateFieldSet(this, _KeyedDB_spec, key, "f");
|
|
47
|
+
__classPrivateFieldSet(this, _KeyedDB_idGetter, id, "f");
|
|
48
|
+
}
|
|
49
|
+
clear() {
|
|
50
|
+
__classPrivateFieldGet(this, _KeyedDB_items, "f").length = 0;
|
|
51
|
+
__classPrivateFieldGet(this, _KeyedDB_byId, "f").clear();
|
|
52
|
+
}
|
|
53
|
+
insertIfAbsent(...values) {
|
|
54
|
+
const inserted = [];
|
|
55
|
+
for (const value of values) {
|
|
56
|
+
if (!value) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const id = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_id).call(this, value);
|
|
60
|
+
if (__classPrivateFieldGet(this, _KeyedDB_byId, "f").has(id)) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const key = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_key).call(this, value);
|
|
64
|
+
const index = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_lowerBound).call(this, key);
|
|
65
|
+
if (index < __classPrivateFieldGet(this, _KeyedDB_items, "f").length && __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_sameKey).call(this, __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_key).call(this, __classPrivateFieldGet(this, _KeyedDB_items, "f")[index]), key)) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
__classPrivateFieldGet(this, _KeyedDB_items, "f").splice(index, 0, value);
|
|
69
|
+
__classPrivateFieldGet(this, _KeyedDB_byId, "f").set(id, value);
|
|
70
|
+
inserted.push(value);
|
|
71
|
+
}
|
|
72
|
+
return inserted;
|
|
73
|
+
}
|
|
74
|
+
upsert(...values) {
|
|
75
|
+
const updated = [];
|
|
76
|
+
for (const value of values) {
|
|
77
|
+
if (!value) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const id = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_id).call(this, value);
|
|
81
|
+
const previous = __classPrivateFieldGet(this, _KeyedDB_byId, "f").get(id);
|
|
82
|
+
const exists = __classPrivateFieldGet(this, _KeyedDB_byId, "f").has(id);
|
|
83
|
+
const key = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_key).call(this, value);
|
|
84
|
+
const index = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_lowerBound).call(this, key);
|
|
85
|
+
if (index < __classPrivateFieldGet(this, _KeyedDB_items, "f").length && __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_sameKey).call(this, __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_key).call(this, __classPrivateFieldGet(this, _KeyedDB_items, "f")[index]), key) && __classPrivateFieldGet(this, _KeyedDB_items, "f")[index] !== previous) {
|
|
86
|
+
throw new Error(`duplicate key: ${String(key)}`);
|
|
87
|
+
}
|
|
88
|
+
if (!exists) {
|
|
89
|
+
__classPrivateFieldGet(this, _KeyedDB_items, "f").splice(index, 0, value);
|
|
90
|
+
__classPrivateFieldGet(this, _KeyedDB_byId, "f").set(id, value);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const oldKey = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_key).call(this, previous);
|
|
94
|
+
const oldIndex = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_lowerBound).call(this, oldKey);
|
|
95
|
+
if (__classPrivateFieldGet(this, _KeyedDB_items, "f")[oldIndex] !== previous) {
|
|
96
|
+
throw new Error('KeyedDB index is inconsistent');
|
|
97
|
+
}
|
|
98
|
+
if (__classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_sameKey).call(this, oldKey, key)) {
|
|
99
|
+
__classPrivateFieldGet(this, _KeyedDB_items, "f")[oldIndex] = value;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
__classPrivateFieldGet(this, _KeyedDB_items, "f").splice(oldIndex, 1);
|
|
103
|
+
__classPrivateFieldGet(this, _KeyedDB_items, "f").splice(__classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_lowerBound).call(this, key), 0, value);
|
|
104
|
+
}
|
|
105
|
+
__classPrivateFieldGet(this, _KeyedDB_byId, "f").set(id, value);
|
|
106
|
+
updated.push(value);
|
|
107
|
+
}
|
|
108
|
+
return updated;
|
|
109
|
+
}
|
|
110
|
+
update(id, callback) {
|
|
111
|
+
if (typeof callback !== 'function') {
|
|
112
|
+
throw new TypeError('update must be a function');
|
|
113
|
+
}
|
|
114
|
+
if (!__classPrivateFieldGet(this, _KeyedDB_byId, "f").has(id)) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
const value = __classPrivateFieldGet(this, _KeyedDB_byId, "f").get(id);
|
|
118
|
+
const oldId = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_id).call(this, value);
|
|
119
|
+
const oldKey = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_key).call(this, value);
|
|
120
|
+
const oldIndex = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_lowerBound).call(this, oldKey);
|
|
121
|
+
if (__classPrivateFieldGet(this, _KeyedDB_items, "f")[oldIndex] !== value) {
|
|
122
|
+
throw new Error('KeyedDB index is inconsistent');
|
|
123
|
+
}
|
|
124
|
+
const snapshot = snapshotProperties(value);
|
|
125
|
+
let removed = false;
|
|
126
|
+
try {
|
|
127
|
+
callback(value);
|
|
128
|
+
const nextId = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_id).call(this, value);
|
|
129
|
+
const nextKey = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_key).call(this, value);
|
|
130
|
+
if (!Object.is(nextId, oldId) && __classPrivateFieldGet(this, _KeyedDB_byId, "f").has(nextId)) {
|
|
131
|
+
throw new Error(`duplicate ID: ${String(nextId)}`);
|
|
132
|
+
}
|
|
133
|
+
if (__classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_sameKey).call(this, oldKey, nextKey)) {
|
|
134
|
+
if (!Object.is(nextId, oldId)) {
|
|
135
|
+
__classPrivateFieldGet(this, _KeyedDB_byId, "f").delete(oldId);
|
|
136
|
+
__classPrivateFieldGet(this, _KeyedDB_byId, "f").set(nextId, value);
|
|
137
|
+
}
|
|
138
|
+
return 1;
|
|
139
|
+
}
|
|
140
|
+
__classPrivateFieldGet(this, _KeyedDB_items, "f").splice(oldIndex, 1);
|
|
141
|
+
removed = true;
|
|
142
|
+
const nextIndex = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_lowerBound).call(this, nextKey);
|
|
143
|
+
if (nextIndex < __classPrivateFieldGet(this, _KeyedDB_items, "f").length && __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_sameKey).call(this, __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_key).call(this, __classPrivateFieldGet(this, _KeyedDB_items, "f")[nextIndex]), nextKey)) {
|
|
144
|
+
throw new Error(`duplicate key: ${String(nextKey)}`);
|
|
145
|
+
}
|
|
146
|
+
__classPrivateFieldGet(this, _KeyedDB_items, "f").splice(nextIndex, 0, value);
|
|
147
|
+
removed = false;
|
|
148
|
+
if (!Object.is(nextId, oldId)) {
|
|
149
|
+
__classPrivateFieldGet(this, _KeyedDB_byId, "f").delete(oldId);
|
|
150
|
+
__classPrivateFieldGet(this, _KeyedDB_byId, "f").set(nextId, value);
|
|
151
|
+
}
|
|
152
|
+
return 2;
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
restoreProperties(value, snapshot);
|
|
156
|
+
if (removed) {
|
|
157
|
+
__classPrivateFieldGet(this, _KeyedDB_items, "f").splice(oldIndex, 0, value);
|
|
158
|
+
}
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
get(id) {
|
|
163
|
+
return __classPrivateFieldGet(this, _KeyedDB_byId, "f").get(id);
|
|
164
|
+
}
|
|
165
|
+
deleteById(id, assertPresent = true) {
|
|
166
|
+
if (!__classPrivateFieldGet(this, _KeyedDB_byId, "f").has(id)) {
|
|
167
|
+
if (assertPresent) {
|
|
168
|
+
throw new Error('Value not found');
|
|
169
|
+
}
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
return this.delete(__classPrivateFieldGet(this, _KeyedDB_byId, "f").get(id));
|
|
173
|
+
}
|
|
174
|
+
delete(value) {
|
|
175
|
+
if (value == null) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
const key = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_key).call(this, value);
|
|
179
|
+
const index = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_lowerBound).call(this, key);
|
|
180
|
+
if (index >= __classPrivateFieldGet(this, _KeyedDB_items, "f").length || !__classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_sameKey).call(this, __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_key).call(this, __classPrivateFieldGet(this, _KeyedDB_items, "f")[index]), key)) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
const removed = __classPrivateFieldGet(this, _KeyedDB_items, "f").splice(index, 1)[0];
|
|
184
|
+
__classPrivateFieldGet(this, _KeyedDB_byId, "f").delete(__classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_id).call(this, removed));
|
|
185
|
+
return removed;
|
|
186
|
+
}
|
|
187
|
+
filter(predicate = () => true) {
|
|
188
|
+
if (typeof predicate !== 'function') {
|
|
189
|
+
throw new TypeError('predicate must be a function');
|
|
190
|
+
}
|
|
191
|
+
const result = new KeyedDB(__classPrivateFieldGet(this, _KeyedDB_spec, "f"), __classPrivateFieldGet(this, _KeyedDB_idGetter, "f"));
|
|
192
|
+
for (let index = 0; index < __classPrivateFieldGet(this, _KeyedDB_items, "f").length; index++) {
|
|
193
|
+
const value = __classPrivateFieldGet(this, _KeyedDB_items, "f")[index];
|
|
194
|
+
if (predicate(value, index)) {
|
|
195
|
+
__classPrivateFieldGet(result, _KeyedDB_items, "f").push(value);
|
|
196
|
+
__classPrivateFieldGet(result, _KeyedDB_byId, "f").set(__classPrivateFieldGet(result, _KeyedDB_instances, "m", _KeyedDB_id).call(result, value), value);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
all() {
|
|
202
|
+
return __classPrivateFieldGet(this, _KeyedDB_items, "f").slice();
|
|
203
|
+
}
|
|
204
|
+
toJSON() {
|
|
205
|
+
return __classPrivateFieldGet(this, _KeyedDB_items, "f");
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
_KeyedDB_spec = new WeakMap(), _KeyedDB_idGetter = new WeakMap(), _KeyedDB_items = new WeakMap(), _KeyedDB_byId = new WeakMap(), _KeyedDB_instances = new WeakSet(), _KeyedDB_key = function _KeyedDB_key(value) {
|
|
209
|
+
return __classPrivateFieldGet(this, _KeyedDB_spec, "f").key(value);
|
|
210
|
+
}, _KeyedDB_id = function _KeyedDB_id(value) {
|
|
211
|
+
const id = __classPrivateFieldGet(this, _KeyedDB_idGetter, "f") ? __classPrivateFieldGet(this, _KeyedDB_idGetter, "f").call(this, value) : String(__classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_key).call(this, value));
|
|
212
|
+
if (id == null) {
|
|
213
|
+
throw new TypeError('ID must not be null or undefined');
|
|
214
|
+
}
|
|
215
|
+
return id;
|
|
216
|
+
}, _KeyedDB_lowerBound = function _KeyedDB_lowerBound(key) {
|
|
217
|
+
let low = 0;
|
|
218
|
+
let high = __classPrivateFieldGet(this, _KeyedDB_items, "f").length;
|
|
219
|
+
while (low < high) {
|
|
220
|
+
const mid = low + ((high - low) >>> 1);
|
|
221
|
+
if (__classPrivateFieldGet(this, _KeyedDB_spec, "f").compare(__classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_key).call(this, __classPrivateFieldGet(this, _KeyedDB_items, "f")[mid]), key) < 0) {
|
|
222
|
+
low = mid + 1;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
high = mid;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return low;
|
|
229
|
+
}, _KeyedDB_sameKey = function _KeyedDB_sameKey(a, b) {
|
|
230
|
+
return __classPrivateFieldGet(this, _KeyedDB_spec, "f").compare(a, b) === 0;
|
|
231
|
+
}, _KeyedDB_insertNew = function _KeyedDB_insertNew(value, id = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_id).call(this, value), key = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_key).call(this, value)) {
|
|
232
|
+
if (__classPrivateFieldGet(this, _KeyedDB_byId, "f").has(id)) {
|
|
233
|
+
throw new Error(`duplicate ID: ${String(id)}`);
|
|
234
|
+
}
|
|
235
|
+
const index = __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_lowerBound).call(this, key);
|
|
236
|
+
if (index < __classPrivateFieldGet(this, _KeyedDB_items, "f").length && __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_sameKey).call(this, __classPrivateFieldGet(this, _KeyedDB_instances, "m", _KeyedDB_key).call(this, __classPrivateFieldGet(this, _KeyedDB_items, "f")[index]), key)) {
|
|
237
|
+
throw new Error(`duplicate key: ${String(key)}`);
|
|
238
|
+
}
|
|
239
|
+
__classPrivateFieldGet(this, _KeyedDB_items, "f").splice(index, 0, value);
|
|
240
|
+
__classPrivateFieldGet(this, _KeyedDB_byId, "f").set(id, value);
|
|
241
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function getLinkPreview(url: any, timeout?: number): Promise<{
|
|
2
|
+
url: string;
|
|
3
|
+
title?: undefined;
|
|
4
|
+
description?: undefined;
|
|
5
|
+
favicon?: undefined;
|
|
6
|
+
image?: undefined;
|
|
7
|
+
video?: undefined;
|
|
8
|
+
} | {
|
|
9
|
+
url: string;
|
|
10
|
+
title: any;
|
|
11
|
+
description: any;
|
|
12
|
+
favicon: any;
|
|
13
|
+
image: any;
|
|
14
|
+
video: any;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { TEXT_DECODER } from '../Defaults/index.js';
|
|
2
|
+
import { HttpError } from './http-error.js';
|
|
3
|
+
const MAX = 262144;
|
|
4
|
+
const TAG = /<(meta|link)\b([^>]*)>|<title[^>]*>([^<]*)/gi;
|
|
5
|
+
const ATTR = /([\w:-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/g;
|
|
6
|
+
const ENT = /&(?:#(\d+)|#x([\da-f]+)|(amp|lt|gt|quot|apos));/gi;
|
|
7
|
+
const MAP = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'" };
|
|
8
|
+
const txt = s => s && s.replace(ENT, (_, d, h, n) => {
|
|
9
|
+
if (n)
|
|
10
|
+
return MAP[n.toLowerCase()];
|
|
11
|
+
const c = d ? +d : parseInt(h, 16);
|
|
12
|
+
return c <= 0x10FFFF ? String.fromCodePoint(c) : '';
|
|
13
|
+
}).replace(/\s+/g, ' ').trim();
|
|
14
|
+
async function readHead(res) {
|
|
15
|
+
let html = '';
|
|
16
|
+
for await (const chunk of res.body) {
|
|
17
|
+
html += TEXT_DECODER.decode(chunk, { stream: true });
|
|
18
|
+
const i = html.search(/<\/head>|<body/i);
|
|
19
|
+
if (i !== -1)
|
|
20
|
+
return html.slice(0, i);
|
|
21
|
+
if (html.length > MAX)
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
return html;
|
|
25
|
+
}
|
|
26
|
+
export async function getLinkPreview(url, timeout = 3000) {
|
|
27
|
+
const res = await fetch(url, {
|
|
28
|
+
signal: AbortSignal.timeout(timeout),
|
|
29
|
+
headers: {
|
|
30
|
+
Accept: 'text/html',
|
|
31
|
+
'Accept-Language': 'en-US,en;q=0.9',
|
|
32
|
+
'User-Agent': 'Mozilla/5.0 (compatible; Discordbot/2.0; +https://discordapp.com)'
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
if (!res.ok)
|
|
36
|
+
throw new HttpError(`HTTP ${res.status} ${res.statusText}`);
|
|
37
|
+
if (!/html/i.test(res.headers.get('content-type') ?? '')) {
|
|
38
|
+
await res.body?.cancel();
|
|
39
|
+
return { url: res.url };
|
|
40
|
+
}
|
|
41
|
+
const base = res.url;
|
|
42
|
+
const abs = v => {
|
|
43
|
+
try {
|
|
44
|
+
return v && new URL(v, base).href;
|
|
45
|
+
}
|
|
46
|
+
catch { }
|
|
47
|
+
};
|
|
48
|
+
const m = {};
|
|
49
|
+
let title, icon;
|
|
50
|
+
for (const [, kind, attrs, t] of (await readHead(res)).matchAll(TAG)) {
|
|
51
|
+
if (t !== undefined) {
|
|
52
|
+
title ?? (title = t);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const a = {};
|
|
56
|
+
for (const x of attrs.matchAll(ATTR))
|
|
57
|
+
a[x[1].toLowerCase()] = x[2] ?? x[3] ?? x[4];
|
|
58
|
+
if (kind.toLowerCase() === 'meta') {
|
|
59
|
+
const k = (a.property ?? a.name ?? a.itemprop)?.toLowerCase();
|
|
60
|
+
if (k && a.content)
|
|
61
|
+
m[k] ?? (m[k] = a.content);
|
|
62
|
+
}
|
|
63
|
+
else if (a.href) {
|
|
64
|
+
const r = a.rel?.toLowerCase() ?? '';
|
|
65
|
+
if (/(^|\s)icon(\s|$)/.test(r))
|
|
66
|
+
icon ?? (icon = a.href);
|
|
67
|
+
else if (r === 'image_src')
|
|
68
|
+
m.image_src ?? (m.image_src = a.href);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
url: base,
|
|
73
|
+
title: txt(m['og:title'] ?? m['twitter:title'] ?? title),
|
|
74
|
+
description: txt(m['og:description'] ?? m['twitter:description'] ?? m.description),
|
|
75
|
+
favicon: abs(icon ?? '/favicon.ico'),
|
|
76
|
+
image: abs(m['og:image'] ?? m['og:image:secure_url'] ?? m['twitter:image'] ?? m['twitter:image:src'] ?? m.image ?? m.image_src),
|
|
77
|
+
video: abs(m['og:video'] ?? m['og:video:secure_url'] ?? m['og:video:url'] ?? m['twitter:player:stream'])
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `detectMediaInfo` — light-weight media probing on top of the system
|
|
3
|
+
* `ffprobe` binary (ships with ffmpeg). Returns the dimensions and/or
|
|
4
|
+
* duration of an image, audio or video file:
|
|
5
|
+
*
|
|
6
|
+
* await detectMediaInfo('/tmp/photo.jpg'); // -> { width: 640, height: 480, durationSeconds: 0 }
|
|
7
|
+
* await detectMediaInfo(voiceNoteBuffer); // -> { durationSeconds: 12 }
|
|
8
|
+
* await detectMediaInfo('/tmp/clip.mp4'); // -> { durationSeconds: 9, width: 1280, height: 720 }
|
|
9
|
+
*
|
|
10
|
+
* Buffers are probed through stdin, paths are probed directly. Resolves to
|
|
11
|
+
* `{}` when the container cannot be parsed and throws (with ffprobe's stderr)
|
|
12
|
+
* when the input is not recognizable media at all.
|
|
13
|
+
*/
|
|
14
|
+
import { spawn } from 'node:child_process';
|
|
15
|
+
|
|
16
|
+
const PROBE_TIMEOUT_MS = 15_000;
|
|
17
|
+
|
|
18
|
+
function runFfprobe(args, stdinData) {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
const child = spawn('ffprobe', [
|
|
21
|
+
'-v', 'quiet',
|
|
22
|
+
'-print_format', 'json',
|
|
23
|
+
'-show_format',
|
|
24
|
+
'-show_streams',
|
|
25
|
+
...args
|
|
26
|
+
], { stdio: stdinData ? ['pipe', 'pipe', 'pipe'] : ['ignore', 'pipe', 'pipe'] });
|
|
27
|
+
|
|
28
|
+
let stdout = '';
|
|
29
|
+
let stderr = '';
|
|
30
|
+
const timer = setTimeout(() => {
|
|
31
|
+
child.kill('SIGKILL');
|
|
32
|
+
reject(new Error('ffprobe timed out'));
|
|
33
|
+
}, PROBE_TIMEOUT_MS);
|
|
34
|
+
|
|
35
|
+
child.stdout.on('data', c => (stdout += c));
|
|
36
|
+
child.stderr.on('data', c => (stderr += c));
|
|
37
|
+
child.on('error', err => { clearTimeout(timer); reject(err); });
|
|
38
|
+
child.on('close', code => {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
if (code !== 0) {
|
|
41
|
+
reject(new Error(stderr.trim() || `ffprobe exited with code ${code}`));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
resolve(JSON.parse(stdout));
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
resolve({});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
if (stdinData) {
|
|
53
|
+
child.stdin.on('error', () => { /* ffprobe may close stdin early — ignore */ });
|
|
54
|
+
child.stdin.end(stdinData);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Maps an ffprobe JSON report onto the compact info shape. */
|
|
60
|
+
function mapProbeReport(report) {
|
|
61
|
+
const info = {};
|
|
62
|
+
const duration = Number(report?.format?.duration);
|
|
63
|
+
if (Number.isFinite(duration)) {
|
|
64
|
+
info.durationSeconds = Math.round(duration);
|
|
65
|
+
}
|
|
66
|
+
const streams = Array.isArray(report?.streams) ? report.streams : [];
|
|
67
|
+
const video = streams.find(s => (s.width && s.height) || s.codec_type === 'video');
|
|
68
|
+
if (video?.width && video?.height) {
|
|
69
|
+
info.width = video.width;
|
|
70
|
+
info.height = video.height;
|
|
71
|
+
}
|
|
72
|
+
return info;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Probes a Buffer/Uint8Array or a path and resolves to
|
|
77
|
+
* `{ width?, height?, durationSeconds? }` (fields only appear when reported).
|
|
78
|
+
*/
|
|
79
|
+
export async function detectMediaInfo(input) {
|
|
80
|
+
let args;
|
|
81
|
+
let stdinData;
|
|
82
|
+
|
|
83
|
+
if (typeof input === 'string') {
|
|
84
|
+
args = [input];
|
|
85
|
+
}
|
|
86
|
+
else if (Buffer.isBuffer(input) || input instanceof Uint8Array) {
|
|
87
|
+
args = ['-i', 'pipe:0'];
|
|
88
|
+
stdinData = Buffer.from(input.buffer, input.byteOffset, input.byteLength);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new TypeError('detectMediaInfo: expects a Buffer, Uint8Array or a file path');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const report = await runFfprobe(args, stdinData);
|
|
95
|
+
return mapProbeReport(report);
|
|
96
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createMutex` — an async mutual-exclusion lock, API-compatible with the
|
|
3
|
+
* widely used async-mutex library:
|
|
4
|
+
*
|
|
5
|
+
* const mutex = createMutex();
|
|
6
|
+
* const result = await mutex.runExclusive(async () => { ... }); // serialized
|
|
7
|
+
* if (!mutex.isLocked()) { ... }
|
|
8
|
+
* const release = await mutex.acquire(); // manual acquire/release
|
|
9
|
+
* release();
|
|
10
|
+
* const release2 = mutex.tryLock(); // undefined when already locked
|
|
11
|
+
*
|
|
12
|
+
* Waiters are served strictly in FIFO order. If a task throws or rejects, the
|
|
13
|
+
* lock is released and the error propagates to its caller only — the mutex
|
|
14
|
+
* stays healthy for the next waiter.
|
|
15
|
+
*/
|
|
16
|
+
export function createMutex() {
|
|
17
|
+
let locked = false;
|
|
18
|
+
const queue = []; // pending { resolve, reject } — resolve receives a release fn
|
|
19
|
+
|
|
20
|
+
function dispatchNext() {
|
|
21
|
+
const next = queue.shift();
|
|
22
|
+
if (next) {
|
|
23
|
+
next.resolve(release);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
locked = false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function release() {
|
|
31
|
+
dispatchNext();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function acquire() {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
if (!locked) {
|
|
37
|
+
locked = true;
|
|
38
|
+
resolve(release);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
queue.push({ resolve, reject });
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function tryAcquire() {
|
|
47
|
+
if (locked) return undefined;
|
|
48
|
+
locked = true;
|
|
49
|
+
return release;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function runExclusive(task) {
|
|
53
|
+
const releaseFn = await acquire();
|
|
54
|
+
try {
|
|
55
|
+
return await task();
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
releaseFn();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
/** Alias of acquire(). */
|
|
64
|
+
lock: acquire,
|
|
65
|
+
/** Acquires the lock, resolving to a release function. */
|
|
66
|
+
acquire,
|
|
67
|
+
/** Acquires without waiting: returns a release function, or undefined when locked. */
|
|
68
|
+
tryAcquire,
|
|
69
|
+
/** Alias of tryAcquire(). */
|
|
70
|
+
tryLock: tryAcquire,
|
|
71
|
+
/** Runs `task` while holding the lock; resolves/rejects with the task result. */
|
|
72
|
+
runExclusive,
|
|
73
|
+
/** True while the lock is held. */
|
|
74
|
+
isLocked: () => locked
|
|
75
|
+
};
|
|
76
|
+
}
|