zapo-js 0.1.1 → 0.2.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/README.md +20 -4
- package/dist/appstate/WaAppStateCrypto.js +19 -26
- package/dist/appstate/WaAppStateSyncClient.js +293 -181
- package/dist/appstate/WaAppStateSyncResponseParser.js +16 -5
- package/dist/appstate/constants.js +4 -3
- package/dist/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/appstate/index.js +8 -6
- package/dist/appstate/utils.js +9 -34
- package/dist/auth/WaAuthClient.js +43 -61
- package/dist/auth/flow/WaAuthCredentialsFlow.js +22 -15
- package/dist/auth/index.js +1 -8
- package/dist/auth/pairing/WaPairingCodeCrypto.js +6 -4
- package/dist/auth/pairing/WaPairingFlow.js +34 -26
- package/dist/auth/pairing/WaQrFlow.js +37 -24
- package/dist/client/WaClient.js +275 -324
- package/dist/client/WaClientFactory.js +500 -133
- package/dist/client/connection/WaConnectionManager.js +301 -0
- package/dist/client/connection/WaKeyShareCoordinator.js +63 -0
- package/dist/client/connection/WaReceiptQueue.js +51 -0
- package/dist/client/coordinators/WaAppStateMutationCoordinator.js +471 -0
- package/dist/client/coordinators/WaBusinessCoordinator.js +241 -0
- package/dist/client/coordinators/WaGroupCoordinator.js +30 -16
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +21 -27
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +439 -701
- package/dist/client/coordinators/WaPassiveTasksCoordinator.js +74 -31
- package/dist/client/coordinators/WaPrivacyCoordinator.js +134 -0
- package/dist/client/coordinators/WaProfileCoordinator.js +212 -0
- package/dist/client/coordinators/WaRetryCoordinator.js +242 -57
- package/dist/client/coordinators/WaStreamControlCoordinator.js +18 -11
- package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +166 -0
- package/dist/client/dirty.js +74 -48
- package/dist/client/events/chat.js +4 -3
- package/dist/client/events/devices.js +72 -0
- package/dist/client/events/group.js +62 -47
- package/dist/client/events/identity.js +22 -0
- package/dist/client/events/privacy-token.js +39 -0
- package/dist/client/history-sync.js +94 -63
- package/dist/client/incoming.js +60 -27
- package/dist/client/mailbox.js +24 -23
- package/dist/client/messages.js +107 -31
- package/dist/client/messaging/fanout.js +199 -0
- package/dist/client/messaging/key-protocol.js +130 -0
- package/dist/client/messaging/participants.js +193 -0
- package/dist/client/persistence/WriteBehindPersistence.js +129 -0
- package/dist/client/tokens/cs-token.js +50 -0
- package/dist/client/tokens/tc-token.js +25 -0
- package/dist/crypto/core/hkdf.js +3 -8
- package/dist/crypto/core/index.js +2 -5
- package/dist/crypto/core/keys.js +6 -7
- package/dist/crypto/core/nonce.js +2 -0
- package/dist/crypto/core/primitives.js +12 -23
- package/dist/crypto/core/random.js +26 -23
- package/dist/crypto/curves/Ed25519.js +7 -8
- package/dist/crypto/curves/X25519.js +38 -22
- package/dist/crypto/index.js +1 -3
- package/dist/crypto/math/constants.js +13 -36
- package/dist/crypto/math/edwards.js +171 -44
- package/dist/crypto/math/fe.js +706 -0
- package/dist/crypto/math/mod.js +10 -3
- package/dist/esm/appstate/WaAppStateCrypto.js +7 -14
- package/dist/esm/appstate/WaAppStateSyncClient.js +284 -172
- package/dist/esm/appstate/WaAppStateSyncResponseParser.js +17 -6
- package/dist/esm/appstate/constants.js +3 -2
- package/dist/esm/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/esm/appstate/index.js +2 -2
- package/dist/esm/appstate/utils.js +8 -30
- package/dist/esm/auth/WaAuthClient.js +43 -61
- package/dist/esm/auth/flow/WaAuthCredentialsFlow.js +22 -15
- package/dist/esm/auth/index.js +0 -3
- package/dist/esm/auth/pairing/WaPairingCodeCrypto.js +6 -4
- package/dist/esm/auth/pairing/WaPairingFlow.js +28 -20
- package/dist/esm/auth/pairing/WaQrFlow.js +37 -24
- package/dist/esm/client/WaClient.js +275 -324
- package/dist/esm/client/WaClientFactory.js +501 -134
- package/dist/esm/client/connection/WaConnectionManager.js +297 -0
- package/dist/esm/client/connection/WaKeyShareCoordinator.js +59 -0
- package/dist/esm/client/connection/WaReceiptQueue.js +47 -0
- package/dist/esm/client/coordinators/WaAppStateMutationCoordinator.js +467 -0
- package/dist/esm/client/coordinators/WaBusinessCoordinator.js +238 -0
- package/dist/esm/client/coordinators/WaGroupCoordinator.js +23 -9
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +21 -27
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +443 -705
- package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +74 -31
- package/dist/esm/client/coordinators/WaPrivacyCoordinator.js +131 -0
- package/dist/esm/client/coordinators/WaProfileCoordinator.js +209 -0
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +244 -59
- package/dist/esm/client/coordinators/WaStreamControlCoordinator.js +19 -12
- package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +162 -0
- package/dist/esm/client/dirty.js +69 -43
- package/dist/esm/client/events/chat.js +4 -3
- package/dist/esm/client/events/devices.js +68 -0
- package/dist/esm/client/events/group.js +53 -39
- package/dist/esm/client/events/identity.js +19 -0
- package/dist/esm/client/events/privacy-token.js +36 -0
- package/dist/esm/client/history-sync.js +91 -60
- package/dist/esm/client/incoming.js +61 -28
- package/dist/esm/client/mailbox.js +24 -23
- package/dist/esm/client/messages.js +108 -32
- package/dist/esm/client/messaging/fanout.js +196 -0
- package/dist/esm/client/messaging/key-protocol.js +127 -0
- package/dist/esm/client/messaging/participants.js +190 -0
- package/dist/esm/client/persistence/WriteBehindPersistence.js +125 -0
- package/dist/esm/client/tokens/cs-token.js +46 -0
- package/dist/esm/client/tokens/tc-token.js +18 -0
- package/dist/esm/crypto/core/hkdf.js +3 -8
- package/dist/esm/crypto/core/index.js +2 -3
- package/dist/esm/crypto/core/keys.js +3 -4
- package/dist/esm/crypto/core/nonce.js +2 -0
- package/dist/esm/crypto/core/primitives.js +12 -22
- package/dist/esm/crypto/core/random.js +25 -23
- package/dist/esm/crypto/curves/Ed25519.js +4 -5
- package/dist/esm/crypto/curves/X25519.js +35 -19
- package/dist/esm/crypto/index.js +0 -1
- package/dist/esm/crypto/math/constants.js +12 -35
- package/dist/esm/crypto/math/edwards.js +174 -47
- package/dist/esm/crypto/math/fe.js +691 -0
- package/dist/esm/crypto/math/mod.js +10 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/infra/log/ConsoleLogger.js +18 -17
- package/dist/esm/infra/log/PinoLogger.js +15 -9
- package/dist/esm/infra/log/types.js +11 -1
- package/dist/esm/infra/perf/BackgroundQueue.js +478 -0
- package/dist/esm/infra/perf/BoundedTaskQueue.js +16 -18
- package/dist/esm/infra/perf/PromiseDedup.js +20 -0
- package/dist/esm/infra/perf/SharedExclusiveGate.js +109 -0
- package/dist/esm/infra/perf/StoreLock.js +77 -0
- package/dist/esm/media/WaMediaCrypto.js +96 -16
- package/dist/esm/media/WaMediaTransferClient.js +251 -91
- package/dist/esm/media/conn.js +10 -6
- package/dist/esm/media/constants.js +6 -2
- package/dist/esm/message/WaMessageClient.js +30 -32
- package/dist/esm/message/ack.js +6 -6
- package/dist/esm/message/addon-crypto.js +59 -0
- package/dist/esm/message/content.js +195 -9
- package/dist/esm/message/icdc.js +76 -0
- package/dist/esm/message/incoming.js +129 -122
- package/dist/esm/message/index.js +2 -0
- package/dist/esm/message/phash.js +3 -1
- package/dist/esm/message/reporting-token.js +425 -0
- package/dist/esm/message/use-case-secret.js +49 -0
- package/dist/esm/protocol/appstate.js +27 -0
- package/dist/esm/protocol/browser.js +10 -18
- package/dist/esm/protocol/constants.js +6 -3
- package/dist/esm/protocol/defaults.js +6 -0
- package/dist/esm/protocol/index.js +2 -11
- package/dist/esm/protocol/jid.js +133 -52
- package/dist/esm/protocol/media.js +3 -3
- package/dist/esm/protocol/message.js +61 -1
- package/dist/esm/protocol/nodes.js +4 -0
- package/dist/esm/protocol/notification.js +3 -1
- package/dist/esm/protocol/privacy-token.js +17 -0
- package/dist/esm/protocol/privacy.js +55 -0
- package/dist/esm/protocol/stream.js +26 -1
- package/dist/esm/protocol/usync.js +11 -0
- package/dist/esm/retry/codec.js +216 -0
- package/dist/esm/retry/constants.js +1 -1
- package/dist/esm/retry/index.js +3 -2
- package/dist/esm/retry/parse.js +88 -86
- package/dist/esm/retry/replay.js +54 -51
- package/dist/esm/retry/tracker.js +94 -0
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +276 -92
- package/dist/esm/signal/api/SignalDigestSyncApi.js +17 -8
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +67 -37
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +86 -67
- package/dist/esm/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/esm/signal/api/SignalSessionSyncApi.js +36 -34
- package/dist/esm/signal/api/result-map.js +10 -0
- package/dist/esm/signal/constants.js +0 -4
- package/dist/esm/signal/crypto/WaAdvSignature.js +13 -9
- package/dist/esm/signal/{store/sqlite.js → encoding.js} +93 -60
- package/dist/esm/signal/group/SenderKeyChain.js +28 -23
- package/dist/esm/signal/group/SenderKeyCodec.js +5 -6
- package/dist/esm/signal/group/SenderKeyManager.js +144 -115
- package/dist/esm/signal/index.js +2 -0
- package/dist/esm/signal/registration/keygen.js +6 -2
- package/dist/esm/signal/registration/utils.js +1 -0
- package/dist/esm/signal/session/SignalProtocol.js +164 -53
- package/dist/esm/signal/session/SignalRatchet.js +24 -15
- package/dist/esm/signal/session/SignalSession.js +14 -9
- package/dist/esm/signal/session/resolver.js +221 -0
- package/dist/esm/store/contracts/privacy-token.store.js +1 -0
- package/dist/esm/store/createStore.js +100 -188
- package/dist/esm/store/index.js +1 -10
- package/dist/esm/store/locks/appstate.lock.js +26 -0
- package/dist/esm/store/locks/auth.lock.js +15 -0
- package/dist/esm/store/locks/contact.lock.js +20 -0
- package/dist/esm/store/locks/device-list.lock.js +20 -0
- package/dist/esm/store/locks/message.lock.js +21 -0
- package/dist/esm/store/locks/participants.lock.js +20 -0
- package/dist/esm/store/locks/privacy-token.lock.js +18 -0
- package/dist/esm/store/locks/retry.lock.js +29 -0
- package/dist/esm/store/locks/sender-key.lock.js +52 -0
- package/dist/esm/store/locks/signal.lock.js +63 -0
- package/dist/esm/store/locks/thread.lock.js +21 -0
- package/dist/esm/store/noop.store.js +4 -7
- package/dist/esm/store/providers/memory/appstate.store.js +38 -16
- package/dist/esm/store/providers/memory/contact.store.js +5 -0
- package/dist/esm/store/providers/memory/device-list.store.js +12 -34
- package/dist/esm/store/providers/memory/message.store.js +11 -5
- package/dist/esm/store/providers/memory/participants.store.js +1 -8
- package/dist/esm/store/providers/memory/privacy-token.store.js +43 -0
- package/dist/esm/store/providers/memory/retry.store.js +77 -2
- package/dist/esm/store/providers/memory/sender-key.store.js +11 -8
- package/dist/esm/store/providers/memory/signal.store.js +47 -18
- package/dist/esm/store/providers/memory/thread.store.js +5 -0
- package/dist/esm/transport/WaComms.js +28 -24
- package/dist/esm/transport/WaWebSocket.js +115 -18
- package/dist/esm/transport/binary/constants.js +0 -30
- package/dist/esm/transport/binary/decoder.js +8 -8
- package/dist/esm/transport/binary/encoder.js +10 -9
- package/dist/esm/transport/binary/index.js +0 -1
- package/dist/esm/transport/index.js +1 -0
- package/dist/esm/transport/keepalive/WaKeepAlive.js +2 -8
- package/dist/esm/transport/node/WaNodeOrchestrator.js +25 -21
- package/dist/esm/transport/node/WaNodeTransport.js +0 -3
- package/dist/esm/transport/node/builders/{accountSync.js → account-sync.js} +16 -36
- package/dist/esm/transport/node/builders/business.js +129 -0
- package/dist/esm/transport/node/builders/global.js +370 -0
- package/dist/esm/transport/node/builders/index.js +7 -3
- package/dist/esm/transport/node/builders/message.js +63 -230
- package/dist/esm/transport/node/builders/pairing.js +2 -27
- package/dist/esm/transport/node/builders/privacy-token.js +41 -0
- package/dist/esm/transport/node/builders/privacy.js +48 -0
- package/dist/esm/transport/node/builders/profile.js +70 -0
- package/dist/esm/transport/node/builders/retry.js +10 -22
- package/dist/esm/transport/node/builders/usync.js +45 -0
- package/dist/esm/transport/node/helpers.js +125 -5
- package/dist/esm/transport/node/usync.js +5 -0
- package/dist/esm/transport/node/xml.js +35 -14
- package/dist/esm/transport/noise/WaClientPayload.js +10 -10
- package/dist/esm/transport/noise/WaFrameCodec.js +48 -33
- package/dist/esm/transport/noise/WaNoiseCert.js +4 -7
- package/dist/esm/transport/noise/WaNoiseSession.js +77 -29
- package/dist/esm/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/esm/transport/proxy.js +27 -0
- package/dist/esm/transport/stream/parse.js +17 -48
- package/dist/esm/util/bytes.js +67 -45
- package/dist/esm/util/coercion.js +6 -14
- package/dist/esm/util/index.js +5 -0
- package/dist/esm/util/primitives.js +40 -14
- package/dist/index.js +7 -1
- package/dist/infra/log/ConsoleLogger.js +18 -17
- package/dist/infra/log/PinoLogger.js +15 -9
- package/dist/infra/log/types.js +12 -0
- package/dist/infra/perf/BackgroundQueue.js +482 -0
- package/dist/infra/perf/BoundedTaskQueue.js +16 -18
- package/dist/infra/perf/PromiseDedup.js +24 -0
- package/dist/infra/perf/SharedExclusiveGate.js +113 -0
- package/dist/infra/perf/StoreLock.js +81 -0
- package/dist/media/WaMediaCrypto.js +95 -15
- package/dist/media/WaMediaTransferClient.js +284 -91
- package/dist/media/conn.js +10 -6
- package/dist/media/constants.js +6 -2
- package/dist/message/WaMessageClient.js +31 -33
- package/dist/message/ack.js +6 -6
- package/dist/message/addon-crypto.js +65 -0
- package/dist/message/content.js +198 -9
- package/dist/message/icdc.js +81 -0
- package/dist/message/incoming.js +127 -120
- package/dist/message/index.js +2 -0
- package/dist/message/phash.js +3 -1
- package/dist/message/reporting-token.js +429 -0
- package/dist/message/use-case-secret.js +55 -0
- package/dist/protocol/appstate.js +28 -1
- package/dist/protocol/browser.js +10 -18
- package/dist/protocol/constants.js +26 -1
- package/dist/protocol/defaults.js +6 -0
- package/dist/protocol/index.js +23 -42
- package/dist/protocol/jid.js +140 -52
- package/dist/protocol/media.js +3 -3
- package/dist/protocol/message.js +62 -2
- package/dist/protocol/nodes.js +4 -0
- package/dist/protocol/notification.js +3 -1
- package/dist/protocol/privacy-token.js +20 -0
- package/dist/protocol/privacy.js +58 -0
- package/dist/protocol/stream.js +27 -2
- package/dist/protocol/usync.js +14 -0
- package/dist/retry/codec.js +220 -0
- package/dist/retry/constants.js +1 -1
- package/dist/retry/index.js +7 -5
- package/dist/retry/parse.js +88 -85
- package/dist/retry/replay.js +52 -49
- package/dist/retry/tracker.js +97 -0
- package/dist/signal/api/SignalDeviceSyncApi.js +273 -89
- package/dist/signal/api/SignalDigestSyncApi.js +17 -8
- package/dist/signal/api/SignalIdentitySyncApi.js +66 -36
- package/dist/signal/api/SignalMissingPreKeysSyncApi.js +82 -63
- package/dist/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/signal/api/SignalSessionSyncApi.js +36 -34
- package/dist/signal/api/result-map.js +13 -0
- package/dist/signal/constants.js +1 -5
- package/dist/signal/crypto/WaAdvSignature.js +11 -7
- package/dist/signal/{store/sqlite.js → encoding.js} +94 -61
- package/dist/signal/group/SenderKeyChain.js +27 -22
- package/dist/signal/group/SenderKeyCodec.js +5 -6
- package/dist/signal/group/SenderKeyManager.js +144 -115
- package/dist/signal/index.js +15 -1
- package/dist/signal/registration/keygen.js +6 -2
- package/dist/signal/registration/utils.js +1 -0
- package/dist/signal/session/SignalProtocol.js +164 -53
- package/dist/signal/session/SignalRatchet.js +24 -15
- package/dist/signal/session/SignalSession.js +14 -9
- package/dist/signal/session/resolver.js +224 -0
- package/dist/store/contracts/privacy-token.store.js +2 -0
- package/dist/store/createStore.js +100 -188
- package/dist/store/index.js +15 -33
- package/dist/store/locks/appstate.lock.js +29 -0
- package/dist/store/locks/auth.lock.js +18 -0
- package/dist/store/locks/contact.lock.js +23 -0
- package/dist/store/locks/device-list.lock.js +23 -0
- package/dist/store/locks/message.lock.js +24 -0
- package/dist/store/locks/participants.lock.js +23 -0
- package/dist/store/locks/privacy-token.lock.js +21 -0
- package/dist/store/locks/retry.lock.js +32 -0
- package/dist/store/locks/sender-key.lock.js +55 -0
- package/dist/store/locks/signal.lock.js +66 -0
- package/dist/store/locks/thread.lock.js +24 -0
- package/dist/store/noop.store.js +4 -7
- package/dist/store/providers/memory/appstate.store.js +36 -14
- package/dist/store/providers/memory/contact.store.js +5 -0
- package/dist/store/providers/memory/device-list.store.js +12 -34
- package/dist/store/providers/memory/message.store.js +11 -5
- package/dist/store/providers/memory/participants.store.js +1 -8
- package/dist/store/providers/memory/privacy-token.store.js +47 -0
- package/dist/store/providers/memory/retry.store.js +77 -2
- package/dist/store/providers/memory/sender-key.store.js +14 -11
- package/dist/store/providers/memory/signal.store.js +54 -25
- package/dist/store/providers/memory/thread.store.js +5 -0
- package/dist/transport/WaComms.js +30 -26
- package/dist/transport/WaWebSocket.js +148 -18
- package/dist/transport/binary/constants.js +1 -31
- package/dist/transport/binary/decoder.js +8 -8
- package/dist/transport/binary/encoder.js +10 -9
- package/dist/transport/binary/index.js +0 -4
- package/dist/transport/index.js +7 -1
- package/dist/transport/keepalive/WaKeepAlive.js +1 -7
- package/dist/transport/node/WaNodeOrchestrator.js +25 -21
- package/dist/transport/node/WaNodeTransport.js +0 -3
- package/dist/transport/node/builders/{accountSync.js → account-sync.js} +15 -35
- package/dist/transport/node/builders/business.js +137 -0
- package/dist/transport/node/builders/global.js +375 -0
- package/dist/transport/node/builders/index.js +29 -17
- package/dist/transport/node/builders/message.js +64 -236
- package/dist/transport/node/builders/pairing.js +2 -29
- package/dist/transport/node/builders/privacy-token.js +46 -0
- package/dist/transport/node/builders/privacy.js +55 -0
- package/dist/transport/node/builders/profile.js +78 -0
- package/dist/transport/node/builders/retry.js +9 -21
- package/dist/transport/node/builders/usync.js +49 -0
- package/dist/transport/node/helpers.js +131 -4
- package/dist/transport/node/usync.js +8 -0
- package/dist/transport/node/xml.js +35 -14
- package/dist/transport/noise/WaClientPayload.js +13 -13
- package/dist/transport/noise/WaFrameCodec.js +47 -32
- package/dist/transport/noise/WaNoiseCert.js +5 -8
- package/dist/transport/noise/WaNoiseSession.js +77 -29
- package/dist/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/transport/proxy.js +34 -0
- package/dist/transport/stream/parse.js +20 -52
- package/dist/types/appstate/WaAppStateCrypto.d.ts +0 -1
- package/dist/types/appstate/WaAppStateSyncClient.d.ts +5 -2
- package/dist/types/appstate/constants.d.ts +1 -0
- package/dist/types/appstate/encoding.d.ts +7 -0
- package/dist/types/appstate/index.d.ts +3 -3
- package/dist/types/appstate/utils.d.ts +0 -3
- package/dist/types/auth/WaAuthClient.d.ts +10 -12
- package/dist/types/auth/flow/WaAuthCredentialsFlow.d.ts +1 -1
- package/dist/types/auth/index.d.ts +0 -4
- package/dist/types/auth/pairing/WaQrFlow.d.ts +1 -1
- package/dist/types/auth/types.d.ts +7 -9
- package/dist/types/client/WaClient.d.ts +42 -25
- package/dist/types/client/WaClientFactory.d.ts +33 -26
- package/dist/types/client/connection/WaConnectionManager.d.ts +66 -0
- package/dist/types/client/connection/WaKeyShareCoordinator.d.ts +14 -0
- package/dist/types/client/connection/WaReceiptQueue.d.ts +13 -0
- package/dist/types/client/coordinators/WaAppStateMutationCoordinator.d.ts +46 -0
- package/dist/types/client/coordinators/WaBusinessCoordinator.d.ts +57 -0
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +3 -2
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +29 -38
- package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +4 -0
- package/dist/types/client/coordinators/WaPrivacyCoordinator.d.ts +26 -0
- package/dist/types/client/coordinators/WaProfileCoordinator.d.ts +36 -0
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +8 -0
- package/dist/types/client/coordinators/WaStreamControlCoordinator.d.ts +3 -2
- package/dist/types/client/coordinators/WaTrustedContactTokenCoordinator.d.ts +45 -0
- package/dist/types/client/dirty.d.ts +1 -0
- package/dist/types/client/events/devices.d.ts +20 -0
- package/dist/types/client/events/group.d.ts +2 -1
- package/dist/types/client/events/identity.d.ts +9 -0
- package/dist/types/client/events/privacy-token.d.ts +7 -0
- package/dist/types/client/history-sync.d.ts +9 -6
- package/dist/types/client/incoming.d.ts +3 -1
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/mailbox.d.ts +3 -5
- package/dist/types/client/messages.d.ts +1 -2
- package/dist/types/client/messaging/fanout.d.ts +14 -0
- package/dist/types/client/messaging/key-protocol.d.ts +18 -0
- package/dist/types/client/messaging/participants.d.ts +13 -0
- package/dist/types/client/persistence/WriteBehindPersistence.d.ts +34 -0
- package/dist/types/client/tokens/cs-token.d.ts +10 -0
- package/dist/types/client/tokens/tc-token.d.ts +5 -0
- package/dist/types/client/types.d.ts +75 -4
- package/dist/types/crypto/core/hkdf.d.ts +0 -6
- package/dist/types/crypto/core/index.d.ts +2 -3
- package/dist/types/crypto/core/nonce.d.ts +2 -0
- package/dist/types/crypto/core/primitives.d.ts +0 -1
- package/dist/types/crypto/core/random.d.ts +2 -7
- package/dist/types/crypto/index.d.ts +0 -1
- package/dist/types/crypto/math/constants.d.ts +4 -2
- package/dist/types/crypto/math/fe.d.ts +30 -0
- package/dist/types/crypto/math/mod.d.ts +0 -2
- package/dist/types/crypto/math/types.d.ts +11 -4
- package/dist/types/index.d.ts +5 -3
- package/dist/types/infra/log/ConsoleLogger.d.ts +2 -1
- package/dist/types/infra/log/PinoLogger.d.ts +1 -1
- package/dist/types/infra/log/types.d.ts +1 -0
- package/dist/types/infra/perf/BackgroundQueue.d.ts +58 -0
- package/dist/types/infra/perf/BoundedTaskQueue.d.ts +1 -1
- package/dist/types/infra/perf/PromiseDedup.d.ts +4 -0
- package/dist/types/infra/perf/SharedExclusiveGate.d.ts +17 -0
- package/dist/types/infra/perf/StoreLock.d.ts +10 -0
- package/dist/types/media/WaMediaCrypto.d.ts +3 -2
- package/dist/types/media/WaMediaTransferClient.d.ts +16 -15
- package/dist/types/media/constants.d.ts +1 -1
- package/dist/types/media/index.d.ts +1 -1
- package/dist/types/media/types.d.ts +15 -2
- package/dist/types/message/addon-crypto.d.ts +25 -0
- package/dist/types/message/content.d.ts +8 -0
- package/dist/types/message/icdc.d.ts +13 -0
- package/dist/types/message/index.d.ts +2 -0
- package/dist/types/message/reporting-token.d.ts +18 -0
- package/dist/types/message/types.d.ts +45 -6
- package/dist/types/message/use-case-secret.d.ts +20 -0
- package/dist/types/protocol/appstate.d.ts +47 -0
- package/dist/types/protocol/constants.d.ts +8 -3
- package/dist/types/protocol/defaults.d.ts +6 -0
- package/dist/types/protocol/index.d.ts +2 -11
- package/dist/types/protocol/jid.d.ts +22 -5
- package/dist/types/protocol/message.d.ts +60 -0
- package/dist/types/protocol/nodes.d.ts +4 -0
- package/dist/types/protocol/notification.d.ts +2 -0
- package/dist/types/protocol/privacy-token.d.ts +17 -0
- package/dist/types/protocol/privacy.d.ts +75 -0
- package/dist/types/protocol/stream.d.ts +30 -0
- package/dist/types/protocol/usync.d.ts +11 -0
- package/dist/types/retry/codec.d.ts +3 -0
- package/dist/types/retry/index.d.ts +4 -3
- package/dist/types/retry/parse.d.ts +5 -2
- package/dist/types/retry/replay.d.ts +0 -4
- package/dist/types/retry/tracker.d.ts +20 -0
- package/dist/types/retry/types.d.ts +10 -4
- package/dist/types/signal/api/SignalDeviceSyncApi.d.ts +15 -2
- package/dist/types/signal/api/SignalDigestSyncApi.d.ts +6 -0
- package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +2 -0
- package/dist/types/signal/api/SignalRotateKeyApi.d.ts +4 -5
- package/dist/types/signal/api/SignalSessionSyncApi.d.ts +8 -6
- package/dist/types/signal/api/result-map.d.ts +1 -0
- package/dist/types/signal/constants.d.ts +0 -3
- package/dist/types/signal/{store/sqlite.d.ts → encoding.d.ts} +3 -3
- package/dist/types/signal/group/SenderKeyCodec.d.ts +4 -6
- package/dist/types/signal/group/SenderKeyManager.d.ts +10 -5
- package/dist/types/signal/index.d.ts +3 -0
- package/dist/types/signal/session/SignalProtocol.d.ts +19 -4
- package/dist/types/signal/session/resolver.d.ts +22 -0
- package/dist/types/store/contracts/appstate.store.d.ts +4 -1
- package/dist/types/store/contracts/contact.store.d.ts +1 -0
- package/dist/types/store/contracts/device-list.store.d.ts +0 -3
- package/dist/types/store/contracts/message.store.d.ts +1 -0
- package/dist/types/store/contracts/participants.store.d.ts +0 -1
- package/dist/types/store/contracts/privacy-token.store.d.ts +16 -0
- package/dist/types/store/contracts/retry.store.d.ts +7 -0
- package/dist/types/store/contracts/sender-key.store.d.ts +0 -1
- package/dist/types/store/contracts/signal.store.d.ts +13 -0
- package/dist/types/store/contracts/thread.store.d.ts +1 -0
- package/dist/types/store/createStore.d.ts +1 -1
- package/dist/types/store/index.d.ts +5 -13
- package/dist/types/store/locks/appstate.lock.d.ts +3 -0
- package/dist/types/store/locks/auth.lock.d.ts +3 -0
- package/dist/types/store/locks/contact.lock.d.ts +3 -0
- package/dist/types/store/locks/device-list.lock.d.ts +2 -0
- package/dist/types/store/locks/message.lock.d.ts +3 -0
- package/dist/types/store/locks/participants.lock.d.ts +2 -0
- package/dist/types/store/locks/privacy-token.lock.d.ts +2 -0
- package/dist/types/store/locks/retry.lock.d.ts +2 -0
- package/dist/types/store/locks/sender-key.lock.d.ts +3 -0
- package/dist/types/store/locks/signal.lock.d.ts +3 -0
- package/dist/types/store/locks/thread.lock.d.ts +3 -0
- package/dist/types/store/providers/memory/appstate.store.d.ts +3 -1
- package/dist/types/store/providers/memory/contact.store.d.ts +1 -0
- package/dist/types/store/providers/memory/device-list.store.d.ts +0 -3
- package/dist/types/store/providers/memory/message.store.d.ts +1 -0
- package/dist/types/store/providers/memory/participants.store.d.ts +0 -1
- package/dist/types/store/providers/memory/privacy-token.store.d.ts +13 -0
- package/dist/types/store/providers/memory/retry.store.d.ts +8 -0
- package/dist/types/store/providers/memory/sender-key.store.d.ts +0 -1
- package/dist/types/store/providers/memory/signal.store.d.ts +8 -1
- package/dist/types/store/providers/memory/thread.store.d.ts +1 -0
- package/dist/types/store/types.d.ts +49 -58
- package/dist/types/transport/WaWebSocket.d.ts +3 -1
- package/dist/types/transport/binary/constants.d.ts +0 -30
- package/dist/types/transport/binary/index.d.ts +0 -1
- package/dist/types/transport/index.d.ts +2 -1
- package/dist/types/transport/keepalive/WaKeepAlive.d.ts +0 -1
- package/dist/types/transport/node/WaNodeOrchestrator.d.ts +3 -4
- package/dist/types/transport/node/WaNodeTransport.d.ts +0 -9
- package/dist/types/transport/node/builders/business.d.ts +29 -0
- package/dist/types/transport/node/builders/global.d.ts +102 -0
- package/dist/types/transport/node/builders/group.d.ts +4 -6
- package/dist/types/transport/node/builders/index.d.ts +7 -3
- package/dist/types/transport/node/builders/message.d.ts +20 -30
- package/dist/types/transport/node/builders/pairing.d.ts +0 -2
- package/dist/types/transport/node/builders/privacy-token.d.ts +9 -0
- package/dist/types/transport/node/builders/privacy.d.ts +7 -0
- package/dist/types/transport/node/builders/profile.d.ts +8 -0
- package/dist/types/transport/node/builders/retry.d.ts +2 -5
- package/dist/types/transport/node/builders/usync.d.ts +21 -0
- package/dist/types/transport/node/helpers.d.ts +13 -0
- package/dist/types/transport/node/usync.d.ts +2 -0
- package/dist/types/transport/noise/WaFrameCodec.d.ts +3 -0
- package/dist/types/transport/noise/WaNoiseSession.d.ts +4 -2
- package/dist/types/transport/noise/WaNoiseSocket.d.ts +4 -2
- package/dist/types/transport/proxy.d.ts +6 -0
- package/dist/types/transport/stream/parse.d.ts +0 -1
- package/dist/types/transport/types.d.ts +18 -1
- package/dist/types/util/bytes.d.ts +5 -0
- package/dist/types/util/index.d.ts +5 -0
- package/dist/types/util/primitives.d.ts +2 -0
- package/dist/util/bytes.js +72 -46
- package/dist/util/coercion.js +6 -14
- package/dist/util/index.js +23 -0
- package/dist/util/primitives.js +42 -14
- package/package.json +52 -9
- package/proto/index.js +1 -1
- package/dist/crypto/core/constants.js +0 -4
- package/dist/crypto/core/encoding.js +0 -29
- package/dist/esm/crypto/core/constants.js +0 -1
- package/dist/esm/crypto/core/encoding.js +0 -25
- package/dist/esm/retry/outbound.js +0 -83
- package/dist/esm/store/providers/sqlite/BaseSqliteStore.js +0 -37
- package/dist/esm/store/providers/sqlite/appstate.store.js +0 -169
- package/dist/esm/store/providers/sqlite/auth.store.js +0 -176
- package/dist/esm/store/providers/sqlite/connection.js +0 -240
- package/dist/esm/store/providers/sqlite/contact.store.js +0 -61
- package/dist/esm/store/providers/sqlite/device-list.store.js +0 -155
- package/dist/esm/store/providers/sqlite/message.store.js +0 -119
- package/dist/esm/store/providers/sqlite/migrations.js +0 -347
- package/dist/esm/store/providers/sqlite/participants.store.js +0 -85
- package/dist/esm/store/providers/sqlite/retry.store.js +0 -144
- package/dist/esm/store/providers/sqlite/sender-key.store.js +0 -203
- package/dist/esm/store/providers/sqlite/signal.store.js +0 -353
- package/dist/esm/store/providers/sqlite/thread.store.js +0 -72
- package/dist/esm/util/base64.js +0 -18
- package/dist/esm/util/signal-address.js +0 -5
- package/dist/retry/outbound.js +0 -88
- package/dist/store/providers/sqlite/BaseSqliteStore.js +0 -41
- package/dist/store/providers/sqlite/appstate.store.js +0 -173
- package/dist/store/providers/sqlite/auth.store.js +0 -180
- package/dist/store/providers/sqlite/connection.js +0 -276
- package/dist/store/providers/sqlite/contact.store.js +0 -65
- package/dist/store/providers/sqlite/device-list.store.js +0 -159
- package/dist/store/providers/sqlite/message.store.js +0 -123
- package/dist/store/providers/sqlite/migrations.js +0 -350
- package/dist/store/providers/sqlite/participants.store.js +0 -89
- package/dist/store/providers/sqlite/retry.store.js +0 -148
- package/dist/store/providers/sqlite/sender-key.store.js +0 -207
- package/dist/store/providers/sqlite/signal.store.js +0 -357
- package/dist/store/providers/sqlite/thread.store.js +0 -76
- package/dist/types/appstate/store/sqlite.d.ts +0 -21
- package/dist/types/crypto/core/constants.d.ts +0 -1
- package/dist/types/crypto/core/encoding.d.ts +0 -11
- package/dist/types/retry/outbound.d.ts +0 -4
- package/dist/types/store/providers/sqlite/BaseSqliteStore.d.ts +0 -12
- package/dist/types/store/providers/sqlite/appstate.store.d.ts +0 -15
- package/dist/types/store/providers/sqlite/auth.store.d.ts +0 -10
- package/dist/types/store/providers/sqlite/connection.d.ts +0 -10
- package/dist/types/store/providers/sqlite/contact.store.d.ts +0 -10
- package/dist/types/store/providers/sqlite/device-list.store.d.ts +0 -18
- package/dist/types/store/providers/sqlite/message.store.d.ts +0 -11
- package/dist/types/store/providers/sqlite/migrations.d.ts +0 -3
- package/dist/types/store/providers/sqlite/participants.store.d.ts +0 -13
- package/dist/types/store/providers/sqlite/retry.store.d.ts +0 -16
- package/dist/types/store/providers/sqlite/sender-key.store.d.ts +0 -25
- package/dist/types/store/providers/sqlite/signal.store.d.ts +0 -46
- package/dist/types/store/providers/sqlite/thread.store.d.ts +0 -11
- package/dist/types/util/base64.d.ts +0 -4
- package/dist/types/util/signal-address.d.ts +0 -2
- package/dist/util/base64.js +0 -24
- package/dist/util/signal-address.js +0 -8
- /package/dist/types/transport/node/builders/{accountSync.d.ts → account-sync.d.ts} +0 -0
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseParticipants = parseParticipants;
|
|
3
4
|
exports.parseGroupNotificationEvents = parseGroupNotificationEvents;
|
|
5
|
+
const incoming_1 = require("../incoming");
|
|
4
6
|
const constants_1 = require("../../protocol/constants");
|
|
5
7
|
const nodes_1 = require("../../protocol/nodes");
|
|
6
8
|
const helpers_1 = require("../../transport/node/helpers");
|
|
7
|
-
const parse_1 = require("../../transport/stream/parse");
|
|
8
9
|
const bytes_1 = require("../../util/bytes");
|
|
10
|
+
const primitives_1 = require("../../util/primitives");
|
|
9
11
|
function readNodeTextContent(node) {
|
|
10
12
|
if (!node) {
|
|
11
13
|
return undefined;
|
|
@@ -19,30 +21,42 @@ function readNodeTextContent(node) {
|
|
|
19
21
|
return undefined;
|
|
20
22
|
}
|
|
21
23
|
function parseParticipants(node) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
const participants = [];
|
|
25
|
+
for (const participantNode of (0, helpers_1.getNodeChildrenByTag)(node, nodes_1.WA_NODE_TAGS.PARTICIPANT)) {
|
|
26
|
+
participants.push({
|
|
27
|
+
jid: participantNode.attrs.jid,
|
|
28
|
+
role: participantNode.attrs.type,
|
|
29
|
+
lidJid: participantNode.attrs.lid,
|
|
30
|
+
phoneJid: participantNode.attrs.phone_number,
|
|
31
|
+
displayName: participantNode.attrs.display_name,
|
|
32
|
+
username: participantNode.attrs.username,
|
|
33
|
+
expirationSeconds: (0, primitives_1.parseOptionalInt)(participantNode.attrs.expiration)
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return participants;
|
|
31
37
|
}
|
|
32
38
|
function parseLinkedGroups(node) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
const groups = [];
|
|
40
|
+
for (const groupNode of (0, helpers_1.getNodeChildrenByTag)(node, nodes_1.WA_NODE_TAGS.GROUP)) {
|
|
41
|
+
groups.push({
|
|
42
|
+
jid: groupNode.attrs.jid,
|
|
43
|
+
subject: groupNode.attrs.subject,
|
|
44
|
+
subjectTimestampSeconds: (0, primitives_1.parseOptionalInt)(groupNode.attrs.s_t),
|
|
45
|
+
hiddenSubgroup: (0, helpers_1.findNodeChild)(groupNode, 'hidden_group') !== undefined
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return groups;
|
|
39
49
|
}
|
|
40
50
|
function parseMembershipRequests(node) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
const requests = [];
|
|
52
|
+
for (const requestNode of (0, helpers_1.getNodeChildrenByTag)(node, 'requested_user')) {
|
|
53
|
+
requests.push({
|
|
54
|
+
jid: requestNode.attrs.jid,
|
|
55
|
+
username: requestNode.attrs.username,
|
|
56
|
+
phoneJid: requestNode.attrs.phone_number
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return requests;
|
|
46
60
|
}
|
|
47
61
|
function parseSubgroupSuggestion(node) {
|
|
48
62
|
const subjectNode = (0, helpers_1.findNodeChild)(node, nodes_1.WA_NODE_TAGS.SUBJECT);
|
|
@@ -57,20 +71,26 @@ function parseSubgroupSuggestion(node) {
|
|
|
57
71
|
ownerJid: node.attrs.creator,
|
|
58
72
|
subject: readNodeTextContent(subjectNode),
|
|
59
73
|
description: readNodeTextContent(descriptionBodyNode),
|
|
60
|
-
timestampSeconds: (0,
|
|
74
|
+
timestampSeconds: (0, primitives_1.parseOptionalInt)(node.attrs.creation),
|
|
61
75
|
isExistingGroup: readNodeTextContent(isExistingGroupNode) === undefined
|
|
62
76
|
? undefined
|
|
63
77
|
: readNodeTextContent(isExistingGroupNode) === 'true',
|
|
64
78
|
participantCount: participantCountNode
|
|
65
|
-
? (0,
|
|
79
|
+
? (0, primitives_1.parseOptionalInt)(readNodeTextContent(participantCountNode))
|
|
66
80
|
: undefined,
|
|
67
81
|
reason: node.attrs.reason
|
|
68
82
|
};
|
|
69
83
|
}
|
|
70
84
|
function parseSubgroupSuggestions(node) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
85
|
+
const suggestions = [];
|
|
86
|
+
for (const suggestionNode of (0, helpers_1.getNodeChildrenByTag)(node, 'sub_group_suggestion')) {
|
|
87
|
+
const suggestion = parseSubgroupSuggestion(suggestionNode);
|
|
88
|
+
if (!suggestion) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
suggestions.push(suggestion);
|
|
92
|
+
}
|
|
93
|
+
return suggestions;
|
|
74
94
|
}
|
|
75
95
|
function createBaseGroupEvent(notificationNode, actionNode) {
|
|
76
96
|
return {
|
|
@@ -81,16 +101,7 @@ function createBaseGroupEvent(notificationNode, actionNode) {
|
|
|
81
101
|
stanzaType: notificationNode.attrs.type,
|
|
82
102
|
groupJid: notificationNode.attrs.from,
|
|
83
103
|
authorJid: notificationNode.attrs.participant,
|
|
84
|
-
timestampSeconds: (0,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
function createUnhandledStanzaEvent(notificationNode, reason) {
|
|
88
|
-
return {
|
|
89
|
-
rawNode: notificationNode,
|
|
90
|
-
stanzaId: notificationNode.attrs.id,
|
|
91
|
-
chatJid: notificationNode.attrs.from,
|
|
92
|
-
stanzaType: notificationNode.attrs.type,
|
|
93
|
-
reason
|
|
104
|
+
timestampSeconds: (0, primitives_1.parseOptionalInt)(notificationNode.attrs.t)
|
|
94
105
|
};
|
|
95
106
|
}
|
|
96
107
|
function parseCreateGroupAction(notificationNode, actionNode) {
|
|
@@ -121,7 +132,7 @@ function parseCreateGroupAction(notificationNode, actionNode) {
|
|
|
121
132
|
creatorPhoneJid: groupNode.attrs.creator_pn,
|
|
122
133
|
creatorUsername: groupNode.attrs.creator_username,
|
|
123
134
|
creatorCountryCode: groupNode.attrs.creator_country_code,
|
|
124
|
-
creationSeconds: (0,
|
|
135
|
+
creationSeconds: (0, primitives_1.parseOptionalInt)(groupNode.attrs.creation),
|
|
125
136
|
announceEnabled: (0, helpers_1.findNodeChild)(groupNode, nodes_1.WA_NODE_TAGS.ANNOUNCEMENT) !== undefined,
|
|
126
137
|
restrictEnabled: (0, helpers_1.findNodeChild)(groupNode, nodes_1.WA_NODE_TAGS.LOCKED) !== undefined,
|
|
127
138
|
noFrequentlyForwardedEnabled: (0, helpers_1.findNodeChild)(groupNode, constants_1.WA_GROUP_NOTIFICATION_TAGS.NO_FREQUENTLY_FORWARDED) !==
|
|
@@ -135,12 +146,11 @@ function parseCreateGroupAction(notificationNode, actionNode) {
|
|
|
135
146
|
hasCapi: (0, helpers_1.findNodeChild)(groupNode, 'capi') !== undefined,
|
|
136
147
|
limitSharingEnabled: (0, helpers_1.findNodeChild)(groupNode, constants_1.WA_GROUP_NOTIFICATION_TAGS.LIMIT_SHARING_ENABLED) !==
|
|
137
148
|
undefined,
|
|
138
|
-
size: (0,
|
|
139
|
-
ephemeralDuration: (0,
|
|
149
|
+
size: (0, primitives_1.parseOptionalInt)(groupNode.attrs.size),
|
|
150
|
+
ephemeralDuration: (0, primitives_1.parseOptionalInt)((0, helpers_1.findNodeChild)(groupNode, nodes_1.WA_NODE_TAGS.EPHEMERAL)?.attrs.expiration),
|
|
140
151
|
disappearingTrigger: (0, helpers_1.findNodeChild)(groupNode, nodes_1.WA_NODE_TAGS.EPHEMERAL)?.attrs.trigger,
|
|
141
152
|
membershipApprovalEnabled: groupJoinNode?.attrs.state === 'on',
|
|
142
|
-
allowNonAdminSubGroupCreation: (0, helpers_1.findNodeChild)(groupNode, constants_1.WA_GROUP_NOTIFICATION_TAGS.ALLOW_NON_ADMIN_SUB_GROUP_CREATION) !==
|
|
143
|
-
undefined,
|
|
153
|
+
allowNonAdminSubGroupCreation: (0, helpers_1.findNodeChild)(groupNode, constants_1.WA_GROUP_NOTIFICATION_TAGS.ALLOW_NON_ADMIN_SUB_GROUP_CREATION) !== undefined,
|
|
144
154
|
linkedParentGroupJid: (0, helpers_1.findNodeChild)(groupNode, 'linked_parent')?.attrs.jid ??
|
|
145
155
|
(0, helpers_1.findNodeChild)(groupNode, 'parent')?.attrs.jid
|
|
146
156
|
}
|
|
@@ -212,7 +222,7 @@ function parseGroupActionNode(notificationNode, actionNode) {
|
|
|
212
222
|
details: {
|
|
213
223
|
subjectOwnerPhoneJid: actionNode.attrs.s_o_pn,
|
|
214
224
|
subjectOwnerUsername: actionNode.attrs.s_o_username,
|
|
215
|
-
subjectTimestampSeconds: (0,
|
|
225
|
+
subjectTimestampSeconds: (0, primitives_1.parseOptionalInt)(actionNode.attrs.s_t)
|
|
216
226
|
}
|
|
217
227
|
};
|
|
218
228
|
case constants_1.WA_GROUP_NOTIFICATION_TAGS.DESCRIPTION: {
|
|
@@ -227,7 +237,12 @@ function parseGroupActionNode(notificationNode, actionNode) {
|
|
|
227
237
|
};
|
|
228
238
|
}
|
|
229
239
|
case constants_1.WA_GROUP_NOTIFICATION_TAGS.LOCKED:
|
|
230
|
-
return {
|
|
240
|
+
return {
|
|
241
|
+
...baseEvent,
|
|
242
|
+
action: 'restrict',
|
|
243
|
+
enabled: true,
|
|
244
|
+
mode: actionNode.attrs.threshold
|
|
245
|
+
};
|
|
231
246
|
case constants_1.WA_GROUP_NOTIFICATION_TAGS.UNLOCKED:
|
|
232
247
|
return { ...baseEvent, action: 'restrict', enabled: false };
|
|
233
248
|
case constants_1.WA_GROUP_NOTIFICATION_TAGS.ANNOUNCEMENT:
|
|
@@ -244,7 +259,7 @@ function parseGroupActionNode(notificationNode, actionNode) {
|
|
|
244
259
|
return {
|
|
245
260
|
...baseEvent,
|
|
246
261
|
action: 'ephemeral',
|
|
247
|
-
expirationSeconds: (0,
|
|
262
|
+
expirationSeconds: (0, primitives_1.parseOptionalInt)(actionNode.attrs.expiration),
|
|
248
263
|
mode: actionNode.attrs.trigger
|
|
249
264
|
};
|
|
250
265
|
case constants_1.WA_GROUP_NOTIFICATION_TAGS.NOT_EPHEMERAL:
|
|
@@ -263,7 +278,7 @@ function parseGroupActionNode(notificationNode, actionNode) {
|
|
|
263
278
|
return {
|
|
264
279
|
...baseEvent,
|
|
265
280
|
action: 'growth_locked',
|
|
266
|
-
expirationSeconds: (0,
|
|
281
|
+
expirationSeconds: (0, primitives_1.parseOptionalInt)(actionNode.attrs.expiration),
|
|
267
282
|
mode: actionNode.attrs.type
|
|
268
283
|
};
|
|
269
284
|
case constants_1.WA_GROUP_NOTIFICATION_TAGS.GROWTH_UNLOCKED:
|
|
@@ -394,13 +409,13 @@ function parseGroupNotificationEvents(notificationNode) {
|
|
|
394
409
|
try {
|
|
395
410
|
const parsedEvent = parseGroupActionNode(notificationNode, actionNode);
|
|
396
411
|
if (!parsedEvent) {
|
|
397
|
-
unhandled.push(
|
|
412
|
+
unhandled.push((0, incoming_1.createUnhandledIncomingNodeEvent)(notificationNode, `notification.${constants_1.WA_NOTIFICATION_TYPES.GROUP}.${actionNode.tag}.not_supported`));
|
|
398
413
|
continue;
|
|
399
414
|
}
|
|
400
415
|
events.push(parsedEvent);
|
|
401
416
|
}
|
|
402
417
|
catch {
|
|
403
|
-
unhandled.push(
|
|
418
|
+
unhandled.push((0, incoming_1.createUnhandledIncomingNodeEvent)(notificationNode, `notification.${constants_1.WA_NOTIFICATION_TYPES.GROUP}.${actionNode.tag}.parse_failed`));
|
|
404
419
|
}
|
|
405
420
|
}
|
|
406
421
|
return {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseIdentityChangeNotification = parseIdentityChangeNotification;
|
|
4
|
+
const helpers_1 = require("../../transport/node/helpers");
|
|
5
|
+
function parseIdentityChangeNotification(node) {
|
|
6
|
+
const child = (0, helpers_1.getFirstNodeChild)(node);
|
|
7
|
+
if (!child || child.tag !== 'identity') {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const fromJid = node.attrs.from;
|
|
11
|
+
const stanzaId = node.attrs.id;
|
|
12
|
+
if (!fromJid || !stanzaId) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
fromJid,
|
|
17
|
+
stanzaId,
|
|
18
|
+
displayName: node.attrs.display_name,
|
|
19
|
+
lid: node.attrs.lid,
|
|
20
|
+
offline: node.attrs.offline
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePrivacyTokenNotification = parsePrivacyTokenNotification;
|
|
4
|
+
const privacy_token_1 = require("../../protocol/privacy-token");
|
|
5
|
+
const helpers_1 = require("../../transport/node/helpers");
|
|
6
|
+
const bytes_1 = require("../../util/bytes");
|
|
7
|
+
const coercion_1 = require("../../util/coercion");
|
|
8
|
+
function parsePrivacyTokenNotification(node) {
|
|
9
|
+
const tokensNode = (0, helpers_1.findNodeChild)(node, privacy_token_1.WA_PRIVACY_TOKEN_TAGS.TOKENS);
|
|
10
|
+
if (!tokensNode) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
const children = (0, helpers_1.getNodeChildren)(tokensNode);
|
|
14
|
+
const result = [];
|
|
15
|
+
for (let i = 0; i < children.length; i += 1) {
|
|
16
|
+
const child = children[i];
|
|
17
|
+
if (child.tag !== privacy_token_1.WA_PRIVACY_TOKEN_TAGS.TOKEN) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const type = child.attrs.type;
|
|
21
|
+
if (!type) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const rawTimestamp = child.attrs.t;
|
|
25
|
+
if (!rawTimestamp) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const content = child.content;
|
|
29
|
+
if (!(content instanceof Uint8Array)) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
result[result.length] = {
|
|
33
|
+
type,
|
|
34
|
+
tokenBytes: (0, bytes_1.toBytesView)(content),
|
|
35
|
+
timestampS: (0, coercion_1.asNumber)(Number(rawTimestamp), 'privacy_token.t')
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
@@ -4,7 +4,6 @@ exports.processHistorySyncNotification = processHistorySyncNotification;
|
|
|
4
4
|
const node_util_1 = require("node:util");
|
|
5
5
|
const node_zlib_1 = require("node:zlib");
|
|
6
6
|
const _proto_1 = require("../proto.js");
|
|
7
|
-
const base64_1 = require("../util/base64");
|
|
8
7
|
const bytes_1 = require("../util/bytes");
|
|
9
8
|
const primitives_1 = require("../util/primitives");
|
|
10
9
|
const unzipAsync = (0, node_util_1.promisify)(node_zlib_1.unzip);
|
|
@@ -14,6 +13,7 @@ const HANDLED_SYNC_TYPES = new Set([
|
|
|
14
13
|
_proto_1.proto.Message.HistorySyncType.FULL,
|
|
15
14
|
_proto_1.proto.Message.HistorySyncType.PUSH_NAME
|
|
16
15
|
]);
|
|
16
|
+
const HISTORY_SYNC_MAX_PENDING_WRITES = 1024;
|
|
17
17
|
async function processHistorySyncNotification(deps, notification) {
|
|
18
18
|
const syncType = notification.syncType;
|
|
19
19
|
if (syncType === null || syncType === undefined || !HANDLED_SYNC_TYPES.has(syncType)) {
|
|
@@ -31,15 +31,85 @@ async function processHistorySyncNotification(deps, notification) {
|
|
|
31
31
|
pushnames: historySync.pushnames.length
|
|
32
32
|
});
|
|
33
33
|
const nowMs = Date.now();
|
|
34
|
+
const pendingWrites = [];
|
|
35
|
+
for (const pn of historySync.pushnames) {
|
|
36
|
+
if (!pn.id) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
pendingWrites[pendingWrites.length] = deps.writeBehind.persistContactAsync({
|
|
40
|
+
jid: pn.id,
|
|
41
|
+
pushName: pn.pushname ?? undefined,
|
|
42
|
+
lastUpdatedMs: nowMs
|
|
43
|
+
});
|
|
44
|
+
if (pendingWrites.length >= HISTORY_SYNC_MAX_PENDING_WRITES) {
|
|
45
|
+
await flushPendingWrites(pendingWrites);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
34
48
|
let messagesCount = 0;
|
|
35
|
-
const conversationPromises = [];
|
|
36
49
|
for (const conversation of historySync.conversations) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
50
|
+
const threadJid = conversation.id;
|
|
51
|
+
if (!threadJid) {
|
|
52
|
+
deps.logger.debug('skipping history sync conversation without thread jid');
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
pendingWrites[pendingWrites.length] = deps.writeBehind.persistThreadAsync({
|
|
56
|
+
jid: threadJid,
|
|
57
|
+
name: conversation.name ?? undefined,
|
|
58
|
+
unreadCount: conversation.unreadCount ?? undefined,
|
|
59
|
+
archived: conversation.archived ?? undefined,
|
|
60
|
+
pinned: conversation.pinned ?? undefined,
|
|
61
|
+
muteEndMs: (0, primitives_1.longToNumber)(conversation.muteEndTime) || undefined,
|
|
62
|
+
markedAsUnread: conversation.markedAsUnread ?? undefined,
|
|
63
|
+
ephemeralExpiration: conversation.ephemeralExpiration ?? undefined
|
|
64
|
+
});
|
|
65
|
+
if (pendingWrites.length >= HISTORY_SYNC_MAX_PENDING_WRITES) {
|
|
66
|
+
await flushPendingWrites(pendingWrites);
|
|
67
|
+
}
|
|
68
|
+
for (const histMsg of conversation.messages ?? []) {
|
|
69
|
+
const webMsg = histMsg.message;
|
|
70
|
+
if (!webMsg?.key?.id) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const timestampMs = (0, primitives_1.longToNumber)(webMsg.messageTimestamp) * 1000;
|
|
74
|
+
pendingWrites[pendingWrites.length] = deps.writeBehind.persistMessageAsync({
|
|
75
|
+
id: webMsg.key.id,
|
|
76
|
+
threadJid,
|
|
77
|
+
senderJid: webMsg.key.participant ?? undefined,
|
|
78
|
+
fromMe: webMsg.key.fromMe === true,
|
|
79
|
+
timestampMs: timestampMs || undefined,
|
|
80
|
+
messageBytes: webMsg.message
|
|
81
|
+
? _proto_1.proto.Message.encode(webMsg.message).finish()
|
|
82
|
+
: undefined
|
|
83
|
+
});
|
|
84
|
+
if (pendingWrites.length >= HISTORY_SYNC_MAX_PENDING_WRITES) {
|
|
85
|
+
await flushPendingWrites(pendingWrites);
|
|
86
|
+
}
|
|
87
|
+
messagesCount += 1;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (deps.onPrivacyTokens) {
|
|
91
|
+
const tokenConversations = [];
|
|
92
|
+
for (const conversation of historySync.conversations) {
|
|
93
|
+
if (!conversation.id)
|
|
94
|
+
continue;
|
|
95
|
+
if (conversation.tcToken ||
|
|
96
|
+
conversation.tcTokenTimestamp ||
|
|
97
|
+
conversation.tcTokenSenderTimestamp) {
|
|
98
|
+
tokenConversations[tokenConversations.length] = {
|
|
99
|
+
jid: conversation.id,
|
|
100
|
+
tcToken: conversation.tcToken,
|
|
101
|
+
tcTokenTimestamp: (0, primitives_1.longToNumber)(conversation.tcTokenTimestamp) || undefined,
|
|
102
|
+
tcTokenSenderTimestamp: (0, primitives_1.longToNumber)(conversation.tcTokenSenderTimestamp) || undefined
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (tokenConversations.length > 0) {
|
|
107
|
+
pendingWrites[pendingWrites.length] = deps.onPrivacyTokens(tokenConversations);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (deps.onNctSalt && historySync.nctSalt) {
|
|
111
|
+
pendingWrites[pendingWrites.length] = deps.onNctSalt(historySync.nctSalt);
|
|
40
112
|
}
|
|
41
|
-
const pushnamePromise = persistPushnames(deps, historySync.pushnames, nowMs);
|
|
42
|
-
await Promise.all([...conversationPromises, pushnamePromise]);
|
|
43
113
|
const event = {
|
|
44
114
|
syncType,
|
|
45
115
|
messagesCount,
|
|
@@ -48,18 +118,31 @@ async function processHistorySyncNotification(deps, notification) {
|
|
|
48
118
|
chunkOrder: historySync.chunkOrder ?? undefined,
|
|
49
119
|
progress: historySync.progress ?? undefined
|
|
50
120
|
};
|
|
121
|
+
await flushPendingWrites(pendingWrites);
|
|
51
122
|
deps.emitEvent('history_sync_chunk', event);
|
|
52
123
|
}
|
|
124
|
+
async function flushPendingWrites(pendingWrites) {
|
|
125
|
+
if (pendingWrites.length === 0) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const pendingCount = pendingWrites.length;
|
|
129
|
+
const batch = new Array(pendingCount);
|
|
130
|
+
for (let index = 0; index < pendingCount; index += 1) {
|
|
131
|
+
batch[index] = pendingWrites[index];
|
|
132
|
+
}
|
|
133
|
+
pendingWrites.length = 0;
|
|
134
|
+
await Promise.all(batch);
|
|
135
|
+
}
|
|
53
136
|
async function downloadHistorySyncBlob(deps, notification) {
|
|
54
137
|
if (notification.initialHistBootstrapInlinePayload) {
|
|
55
|
-
return (0,
|
|
138
|
+
return (0, bytes_1.decodeProtoBytes)(notification.initialHistBootstrapInlinePayload, 'initialHistBootstrapInlinePayload');
|
|
56
139
|
}
|
|
57
140
|
if (!notification.directPath) {
|
|
58
141
|
throw new Error('history sync notification missing directPath');
|
|
59
142
|
}
|
|
60
|
-
const mediaKey = (0,
|
|
61
|
-
const fileSha256 = (0,
|
|
62
|
-
const fileEncSha256 = (0,
|
|
143
|
+
const mediaKey = (0, bytes_1.decodeProtoBytes)(notification.mediaKey, 'history sync mediaKey');
|
|
144
|
+
const fileSha256 = (0, bytes_1.decodeProtoBytes)(notification.fileSha256, 'history sync fileSha256');
|
|
145
|
+
const fileEncSha256 = (0, bytes_1.decodeProtoBytes)(notification.fileEncSha256, 'history sync fileEncSha256');
|
|
63
146
|
return deps.mediaTransfer.downloadAndDecrypt({
|
|
64
147
|
directPath: notification.directPath,
|
|
65
148
|
mediaType: 'history',
|
|
@@ -68,55 +151,3 @@ async function downloadHistorySyncBlob(deps, notification) {
|
|
|
68
151
|
fileEncSha256
|
|
69
152
|
});
|
|
70
153
|
}
|
|
71
|
-
async function persistConversation(deps, conversation, _nowMs) {
|
|
72
|
-
const threadJid = conversation.id;
|
|
73
|
-
if (!threadJid) {
|
|
74
|
-
deps.logger.debug('skipping history sync conversation without thread jid');
|
|
75
|
-
return 0;
|
|
76
|
-
}
|
|
77
|
-
const messages = conversation.messages ?? [];
|
|
78
|
-
const messageRecords = [];
|
|
79
|
-
for (const histMsg of messages) {
|
|
80
|
-
const webMsg = histMsg.message;
|
|
81
|
-
if (!webMsg?.key?.id) {
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
const timestampMs = (0, primitives_1.longToNumber)(webMsg.messageTimestamp) * 1000;
|
|
85
|
-
const messageBytes = webMsg.message
|
|
86
|
-
? _proto_1.proto.Message.encode(webMsg.message).finish()
|
|
87
|
-
: undefined;
|
|
88
|
-
messageRecords.push({
|
|
89
|
-
id: webMsg.key.id,
|
|
90
|
-
threadJid,
|
|
91
|
-
senderJid: webMsg.key.participant ?? undefined,
|
|
92
|
-
fromMe: webMsg.key.fromMe === true,
|
|
93
|
-
timestampMs: timestampMs || undefined,
|
|
94
|
-
messageBytes
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
const threadPromise = deps.threadStore.upsert({
|
|
98
|
-
jid: threadJid,
|
|
99
|
-
name: conversation.name ?? undefined,
|
|
100
|
-
unreadCount: conversation.unreadCount ?? undefined,
|
|
101
|
-
archived: conversation.archived ?? undefined,
|
|
102
|
-
pinned: conversation.pinned ?? undefined,
|
|
103
|
-
muteEndMs: (0, primitives_1.longToNumber)(conversation.muteEndTime) || undefined,
|
|
104
|
-
markedAsUnread: conversation.markedAsUnread ?? undefined,
|
|
105
|
-
ephemeralExpiration: conversation.ephemeralExpiration ?? undefined
|
|
106
|
-
});
|
|
107
|
-
const messagePromises = messageRecords.map((record) => deps.messageStore.upsert(record));
|
|
108
|
-
await Promise.all([threadPromise, ...messagePromises]);
|
|
109
|
-
return messageRecords.length;
|
|
110
|
-
}
|
|
111
|
-
async function persistPushnames(deps, pushnames, nowMs) {
|
|
112
|
-
if (pushnames.length === 0) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
await Promise.all(pushnames
|
|
116
|
-
.filter((pn) => !!pn.id)
|
|
117
|
-
.map((pn) => deps.contactStore.upsert({
|
|
118
|
-
jid: pn.id,
|
|
119
|
-
pushName: pn.pushname ?? undefined,
|
|
120
|
-
lastUpdatedMs: nowMs
|
|
121
|
-
})));
|
|
122
|
-
}
|
package/dist/client/incoming.js
CHANGED
|
@@ -9,11 +9,17 @@ exports.createInfoBulletinNotificationEvent = createInfoBulletinNotificationEven
|
|
|
9
9
|
exports.createUnhandledIncomingNodeEvent = createUnhandledIncomingNodeEvent;
|
|
10
10
|
const group_1 = require("./events/group");
|
|
11
11
|
const constants_1 = require("../protocol/constants");
|
|
12
|
-
const
|
|
13
|
-
const pairing_1 = require("../transport/node/builders/pairing");
|
|
12
|
+
const global_1 = require("../transport/node/builders/global");
|
|
14
13
|
const helpers_1 = require("../transport/node/helpers");
|
|
15
|
-
const parse_1 = require("../transport/stream/parse");
|
|
16
14
|
const primitives_1 = require("../util/primitives");
|
|
15
|
+
const FAILURE_REASON_TO_DISCONNECT = {
|
|
16
|
+
401: constants_1.WA_DISCONNECT_REASONS.FAILURE_NOT_AUTHORIZED,
|
|
17
|
+
403: constants_1.WA_DISCONNECT_REASONS.FAILURE_LOCKED,
|
|
18
|
+
406: constants_1.WA_DISCONNECT_REASONS.FAILURE_BANNED,
|
|
19
|
+
405: constants_1.WA_DISCONNECT_REASONS.FAILURE_CLIENT_TOO_OLD,
|
|
20
|
+
409: constants_1.WA_DISCONNECT_REASONS.FAILURE_BAD_USER_AGENT,
|
|
21
|
+
503: constants_1.WA_DISCONNECT_REASONS.FAILURE_SERVICE_UNAVAILABLE
|
|
22
|
+
};
|
|
17
23
|
const LOGOUT_FAILURE_REASONS = new Set([401, 403, 406]);
|
|
18
24
|
const DISCONNECT_FAILURE_REASONS = new Set([405, 409, 503]);
|
|
19
25
|
const CORE_NOTIFICATION_TYPES = new Set([
|
|
@@ -40,6 +46,8 @@ const OUT_OF_SCOPE_NOTIFICATION_TYPES = new Set([
|
|
|
40
46
|
'waffle',
|
|
41
47
|
'hosted'
|
|
42
48
|
]);
|
|
49
|
+
const NOTIFICATION_TYPES_WITH_PARTICIPANT_ACK = new Set(['mediaretry', 'psa']);
|
|
50
|
+
const NOTIFICATION_TYPES_WITHOUT_TYPE_ACK = new Set(['encrypt', 'devices']);
|
|
43
51
|
function createIncomingBaseEvent(node) {
|
|
44
52
|
return {
|
|
45
53
|
rawNode: node,
|
|
@@ -73,7 +81,9 @@ function classifyNotificationType(notificationType) {
|
|
|
73
81
|
}
|
|
74
82
|
async function applyFailureAction(options, reason, clearStoredCredentials) {
|
|
75
83
|
try {
|
|
76
|
-
|
|
84
|
+
options.stopComms();
|
|
85
|
+
const disconnectReason = FAILURE_REASON_TO_DISCONNECT[reason] ?? constants_1.WA_DISCONNECT_REASONS.STREAM_ERROR_OTHER;
|
|
86
|
+
await options.disconnect(disconnectReason, clearStoredCredentials, reason);
|
|
77
87
|
if (clearStoredCredentials) {
|
|
78
88
|
await options.clearStoredCredentials();
|
|
79
89
|
}
|
|
@@ -118,18 +128,26 @@ function createIncomingReceiptHandler(options) {
|
|
|
118
128
|
await options.handleIncomingRetryReceipt(node);
|
|
119
129
|
}
|
|
120
130
|
else {
|
|
121
|
-
await sendSafeAck(options.logger, options.sendNode, (0,
|
|
131
|
+
await sendSafeAck(options.logger, options.sendNode, (0, global_1.buildAckNode)({
|
|
132
|
+
kind: 'receipt',
|
|
133
|
+
node,
|
|
134
|
+
retryType: true
|
|
135
|
+
}));
|
|
122
136
|
}
|
|
123
137
|
return true;
|
|
124
138
|
}
|
|
125
|
-
await sendSafeAck(options.logger, options.sendNode, (0,
|
|
139
|
+
await sendSafeAck(options.logger, options.sendNode, (0, global_1.buildAckNode)({
|
|
140
|
+
kind: 'receipt',
|
|
141
|
+
node,
|
|
142
|
+
includeParticipant: receiptType !== 'server-error'
|
|
143
|
+
}));
|
|
126
144
|
return true;
|
|
127
145
|
};
|
|
128
146
|
}
|
|
129
147
|
function createIncomingFailureHandler(options) {
|
|
130
148
|
return async (node) => {
|
|
131
|
-
const reason = (0,
|
|
132
|
-
const code = (0,
|
|
149
|
+
const reason = (0, primitives_1.parseOptionalInt)(node.attrs.reason);
|
|
150
|
+
const code = (0, primitives_1.parseOptionalInt)(node.attrs.code);
|
|
133
151
|
options.emitIncomingFailure({
|
|
134
152
|
...createIncomingBaseEvent(node),
|
|
135
153
|
failureReason: reason,
|
|
@@ -148,49 +166,59 @@ function createIncomingFailureHandler(options) {
|
|
|
148
166
|
function createIncomingNotificationHandler(options) {
|
|
149
167
|
return async (node) => {
|
|
150
168
|
const notificationType = node.attrs.type ?? '';
|
|
169
|
+
const includeParticipantInAck = NOTIFICATION_TYPES_WITH_PARTICIPANT_ACK.has(notificationType);
|
|
170
|
+
const includeTypeInAck = !NOTIFICATION_TYPES_WITHOUT_TYPE_ACK.has(notificationType);
|
|
151
171
|
const classification = classifyNotificationType(notificationType);
|
|
152
172
|
const firstChildTag = (0, helpers_1.getFirstNodeChild)(node)?.tag;
|
|
173
|
+
const baseEvent = createIncomingBaseEvent(node);
|
|
153
174
|
const serverSyncCollections = notificationType === 'server_sync'
|
|
154
|
-
? (0, helpers_1.
|
|
155
|
-
.map((collectionNode) => collectionNode.attrs.name)
|
|
156
|
-
.filter((name) => typeof name === 'string' && name.length > 0)
|
|
175
|
+
? (0, helpers_1.getNodeChildrenNonEmptyAttrValuesByTag)(node, constants_1.WA_NODE_TAGS.COLLECTION, 'name')
|
|
157
176
|
: [];
|
|
177
|
+
let details;
|
|
178
|
+
if (firstChildTag || serverSyncCollections.length > 0) {
|
|
179
|
+
details = {};
|
|
180
|
+
if (firstChildTag) {
|
|
181
|
+
details.firstChildTag = firstChildTag;
|
|
182
|
+
}
|
|
183
|
+
if (serverSyncCollections.length > 0) {
|
|
184
|
+
details.collections = serverSyncCollections;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
158
187
|
options.emitIncomingNotification({
|
|
159
|
-
...
|
|
188
|
+
...baseEvent,
|
|
160
189
|
notificationType,
|
|
161
190
|
classification,
|
|
162
|
-
details
|
|
163
|
-
? {
|
|
164
|
-
...(firstChildTag ? { firstChildTag } : {}),
|
|
165
|
-
...(serverSyncCollections.length > 0
|
|
166
|
-
? { collections: serverSyncCollections }
|
|
167
|
-
: {})
|
|
168
|
-
}
|
|
169
|
-
: undefined
|
|
191
|
+
details
|
|
170
192
|
});
|
|
171
193
|
if (classification === 'out_of_scope') {
|
|
172
194
|
options.emitUnhandledStanza({
|
|
173
|
-
...
|
|
195
|
+
...baseEvent,
|
|
174
196
|
reason: `notification.${notificationType}.out_of_scope`
|
|
175
197
|
});
|
|
176
198
|
}
|
|
177
199
|
else if (classification === 'unknown') {
|
|
178
200
|
options.emitUnhandledStanza({
|
|
179
|
-
...
|
|
201
|
+
...baseEvent,
|
|
180
202
|
reason: `notification.${notificationType || 'unknown'}.not_supported`
|
|
181
203
|
});
|
|
182
204
|
}
|
|
183
|
-
await sendSafeAck(options.logger, options.sendNode, (0,
|
|
205
|
+
await sendSafeAck(options.logger, options.sendNode, (0, global_1.buildAckNode)({
|
|
206
|
+
kind: 'notification',
|
|
207
|
+
node,
|
|
208
|
+
includeParticipant: includeParticipantInAck,
|
|
209
|
+
includeType: includeTypeInAck
|
|
210
|
+
}));
|
|
184
211
|
if (notificationType === 'server_sync' && serverSyncCollections.length > 0) {
|
|
212
|
+
const collectionsCsv = serverSyncCollections.join(',');
|
|
185
213
|
if (!options.syncAppState) {
|
|
186
214
|
options.logger.warn('received server_sync notification without app-state sync runtime', {
|
|
187
|
-
collections:
|
|
215
|
+
collections: collectionsCsv
|
|
188
216
|
});
|
|
189
217
|
return true;
|
|
190
218
|
}
|
|
191
219
|
void options.syncAppState().catch((error) => {
|
|
192
220
|
options.logger.warn('failed to sync app-state after server_sync notification', {
|
|
193
|
-
collections:
|
|
221
|
+
collections: collectionsCsv,
|
|
194
222
|
message: (0, primitives_1.toError)(error).message
|
|
195
223
|
});
|
|
196
224
|
});
|
|
@@ -203,6 +231,7 @@ function createIncomingGroupNotificationHandler(options) {
|
|
|
203
231
|
if (node.attrs.type !== constants_1.WA_NOTIFICATION_TYPES.GROUP) {
|
|
204
232
|
return false;
|
|
205
233
|
}
|
|
234
|
+
const baseEvent = createIncomingBaseEvent(node);
|
|
206
235
|
const parsed = (0, group_1.parseGroupNotificationEvents)(node);
|
|
207
236
|
for (const event of parsed.events) {
|
|
208
237
|
options.emitGroupEvent(event);
|
|
@@ -212,11 +241,15 @@ function createIncomingGroupNotificationHandler(options) {
|
|
|
212
241
|
}
|
|
213
242
|
if (parsed.events.length === 0 && parsed.unhandled.length === 0) {
|
|
214
243
|
options.emitUnhandledStanza({
|
|
215
|
-
...
|
|
244
|
+
...baseEvent,
|
|
216
245
|
reason: `notification.${constants_1.WA_NOTIFICATION_TYPES.GROUP}.empty`
|
|
217
246
|
});
|
|
218
247
|
}
|
|
219
|
-
await sendSafeAck(options.logger, options.sendNode, (0,
|
|
248
|
+
await sendSafeAck(options.logger, options.sendNode, (0, global_1.buildAckNode)({
|
|
249
|
+
kind: 'notification',
|
|
250
|
+
node,
|
|
251
|
+
includeParticipant: true
|
|
252
|
+
}));
|
|
220
253
|
return true;
|
|
221
254
|
};
|
|
222
255
|
}
|