zapo-js 0.2.0 → 0.3.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 +7 -3
- package/dist/appstate/WaAppStateCrypto.js +49 -41
- package/dist/appstate/WaAppStateSyncClient.js +79 -42
- package/dist/appstate/index.js +2 -2
- package/dist/auth/WaAuthClient.js +20 -11
- package/dist/auth/{flow/WaAuthCredentialsFlow.js → credentials-flow.js} +83 -18
- package/dist/auth/pairing/WaPairingFlow.js +26 -29
- package/dist/auth/pairing/{WaPairingCodeCrypto.js → pairing-code-crypto.js} +29 -13
- package/dist/client/WaClient.js +115 -75
- package/dist/client/WaClientFactory.js +113 -30
- package/dist/client/connection/WaConnectionManager.js +4 -1
- package/dist/client/coordinators/WaAbPropsCoordinator.js +141 -0
- package/dist/client/coordinators/WaBusinessCoordinator.js +3 -12
- package/dist/client/coordinators/WaEmailCoordinator.js +63 -0
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +33 -8
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +55 -25
- package/dist/client/coordinators/WaOfflineResumeCoordinator.js +114 -0
- package/dist/client/coordinators/WaPassiveTasksCoordinator.js +38 -20
- package/dist/client/coordinators/WaProfileCoordinator.js +3 -1
- package/dist/client/coordinators/WaRetryCoordinator.js +11 -9
- package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +22 -4
- package/dist/client/dirty.js +1 -1
- package/dist/client/events/abprops.js +43 -0
- package/dist/client/events/privacy-token.js +1 -2
- package/dist/client/events/registration.js +42 -0
- package/dist/client/incoming.js +37 -0
- package/dist/client/mailbox.js +17 -1
- package/dist/client/media.js +243 -0
- package/dist/client/messages.js +163 -86
- package/dist/crypto/core/index.js +4 -1
- package/dist/crypto/core/random.js +3 -9
- package/dist/crypto/core/xeddsa.js +57 -0
- package/dist/crypto/curves/X25519.js +18 -0
- package/dist/crypto/curves/constants.js +2 -1
- package/dist/esm/appstate/WaAppStateCrypto.js +39 -31
- package/dist/esm/appstate/WaAppStateSyncClient.js +68 -31
- package/dist/esm/appstate/index.js +1 -1
- package/dist/esm/appstate/{WaAppStateSyncResponseParser.js → response-parser.js} +1 -1
- package/dist/esm/auth/WaAuthClient.js +17 -8
- package/dist/esm/auth/{flow/WaAuthCredentialsFlow.js → credentials-flow.js} +83 -18
- package/dist/esm/auth/pairing/WaPairingFlow.js +25 -28
- package/dist/esm/auth/pairing/{WaPairingCodeCrypto.js → pairing-code-crypto.js} +20 -6
- package/dist/esm/client/WaClient.js +116 -76
- package/dist/esm/client/WaClientFactory.js +114 -31
- package/dist/esm/client/connection/WaConnectionManager.js +4 -1
- package/dist/esm/client/coordinators/WaAbPropsCoordinator.js +137 -0
- package/dist/esm/client/coordinators/WaBusinessCoordinator.js +4 -13
- package/dist/esm/client/coordinators/WaEmailCoordinator.js +60 -0
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +35 -10
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +47 -17
- package/dist/esm/client/coordinators/WaOfflineResumeCoordinator.js +110 -0
- package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +38 -20
- package/dist/esm/client/coordinators/WaProfileCoordinator.js +3 -1
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +11 -9
- package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +24 -6
- package/dist/esm/client/dirty.js +1 -1
- package/dist/esm/client/events/abprops.js +40 -0
- package/dist/esm/client/events/privacy-token.js +1 -2
- package/dist/esm/client/events/registration.js +39 -0
- package/dist/esm/client/incoming.js +36 -0
- package/dist/esm/client/mailbox.js +17 -1
- package/dist/esm/client/media.js +234 -0
- package/dist/esm/client/messages.js +162 -85
- package/dist/esm/crypto/core/index.js +1 -0
- package/dist/esm/crypto/core/random.js +2 -7
- package/dist/esm/crypto/core/xeddsa.js +53 -0
- package/dist/esm/crypto/curves/X25519.js +20 -2
- package/dist/esm/crypto/curves/constants.js +1 -0
- package/dist/esm/infra/perf/StoreLock.js +7 -4
- package/dist/esm/media/WaMediaCrypto.js +257 -62
- package/dist/esm/media/WaMediaTransferClient.js +47 -190
- package/dist/esm/media/constants.js +2 -0
- package/dist/esm/media/processor.js +1 -0
- package/dist/esm/message/addon-crypto.js +130 -3
- package/dist/esm/message/content.js +12 -6
- package/dist/esm/message/icdc.js +8 -8
- package/dist/esm/message/incoming.js +14 -12
- package/dist/esm/message/phash.js +32 -12
- package/dist/esm/message/reporting-token.js +3 -3
- package/dist/esm/message/use-case-secret.js +1 -1
- package/dist/esm/protocol/abprops.js +159 -0
- package/dist/esm/protocol/browser.js +14 -0
- package/dist/esm/protocol/constants.js +3 -1
- package/dist/esm/protocol/email.js +30 -0
- package/dist/esm/protocol/jid.js +44 -10
- package/dist/esm/protocol/nodes.js +6 -2
- package/dist/esm/protocol/notification.js +7 -1
- package/dist/esm/retry/reason.js +1 -1
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +5 -2
- package/dist/esm/signal/api/SignalDigestSyncApi.js +8 -6
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +4 -4
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +1 -1
- package/dist/esm/signal/api/SignalSessionSyncApi.js +1 -1
- package/dist/esm/signal/crypto/WaAdvSignature.js +5 -51
- package/dist/esm/signal/crypto/constants.js +0 -4
- package/dist/esm/signal/encoding.js +11 -54
- package/dist/esm/signal/group/SenderKeyChain.js +3 -3
- package/dist/esm/signal/group/SenderKeyCodec.js +5 -6
- package/dist/esm/signal/group/SenderKeyManager.js +13 -10
- package/dist/esm/signal/registration/keygen.js +2 -3
- package/dist/esm/signal/registration/utils.js +2 -2
- package/dist/esm/signal/session/SignalProtocol.js +18 -17
- package/dist/esm/signal/session/SignalRatchet.js +21 -10
- package/dist/esm/signal/session/SignalSerializer.js +5 -6
- package/dist/esm/signal/session/SignalSession.js +11 -9
- package/dist/esm/signal/session/resolver.js +6 -6
- package/dist/esm/store/contracts/identity.store.js +1 -0
- package/dist/esm/store/contracts/message-secret.store.js +1 -0
- package/dist/esm/store/contracts/pre-key.store.js +1 -0
- package/dist/esm/store/contracts/session.store.js +1 -0
- package/dist/esm/store/createStore.js +48 -12
- package/dist/esm/store/index.js +4 -0
- package/dist/esm/store/locks/identity.lock.js +16 -0
- package/dist/esm/store/locks/message-secret.lock.js +17 -0
- package/dist/esm/store/locks/pre-key.lock.js +27 -0
- package/dist/esm/store/locks/session.lock.js +19 -0
- package/dist/esm/store/locks/signal.lock.js +0 -24
- package/dist/esm/store/noop.store.js +20 -0
- package/dist/esm/store/providers/memory/device-list.store.js +3 -0
- package/dist/esm/store/providers/memory/identity.store.js +31 -0
- package/dist/esm/store/providers/memory/message-secret.store.js +81 -0
- package/dist/esm/store/providers/memory/participants.store.js +3 -0
- package/dist/esm/store/providers/memory/pre-key.store.js +97 -0
- package/dist/esm/store/providers/memory/retry.store.js +25 -11
- package/dist/esm/store/providers/memory/session.store.js +45 -0
- package/dist/esm/store/providers/memory/signal.store.js +1 -164
- package/dist/esm/transport/WaComms.js +4 -3
- package/dist/esm/transport/WaWebSocket.js +9 -1
- package/dist/esm/transport/index.js +6 -0
- package/dist/esm/transport/keepalive/WaKeepAlive.js +17 -8
- package/dist/esm/transport/node/WaMobileTcpSocket.js +114 -0
- package/dist/esm/transport/node/WaNodeOrchestrator.js +17 -8
- package/dist/esm/transport/node/builders/abprops.js +20 -0
- package/dist/esm/transport/node/builders/device.js +11 -0
- package/dist/esm/transport/node/builders/email.js +65 -0
- package/dist/esm/transport/node/builders/offline.js +14 -0
- package/dist/esm/transport/node/builders/prekeys.js +37 -40
- package/dist/esm/transport/node/builders/presence.js +13 -0
- package/dist/esm/transport/node/builders/privacy-token.js +19 -23
- package/dist/esm/transport/node/builders/retry.js +1 -1
- package/dist/esm/transport/node/helpers.js +24 -0
- package/dist/esm/transport/node/mex/argo-decoder.js +152 -0
- package/dist/esm/transport/node/mex/client.js +83 -0
- package/dist/esm/transport/node/mex/persist-ids.js +10 -0
- package/dist/esm/transport/noise/WaClientPayload.js +15 -10
- package/dist/esm/transport/noise/WaFrameCodec.js +2 -2
- package/dist/esm/transport/noise/WaMobileClientPayload.js +53 -0
- package/dist/esm/transport/noise/WaNoiseCert.js +9 -27
- package/dist/esm/transport/noise/WaNoiseSession.js +12 -11
- package/dist/infra/perf/StoreLock.js +7 -4
- package/dist/media/WaMediaCrypto.js +253 -58
- package/dist/media/WaMediaTransferClient.js +50 -223
- package/dist/media/constants.js +3 -1
- package/dist/media/processor.js +2 -0
- package/dist/message/addon-crypto.js +131 -0
- package/dist/message/content.js +13 -5
- package/dist/message/icdc.js +8 -8
- package/dist/message/incoming.js +14 -12
- package/dist/message/phash.js +32 -12
- package/dist/message/reporting-token.js +2 -2
- package/dist/message/use-case-secret.js +1 -1
- package/dist/protocol/abprops.js +163 -0
- package/dist/protocol/browser.js +15 -0
- package/dist/protocol/constants.js +14 -2
- package/dist/protocol/email.js +33 -0
- package/dist/protocol/jid.js +45 -10
- package/dist/protocol/nodes.js +6 -2
- package/dist/protocol/notification.js +8 -2
- package/dist/retry/reason.js +1 -1
- package/dist/signal/api/SignalDeviceSyncApi.js +5 -2
- package/dist/signal/api/SignalDigestSyncApi.js +8 -6
- package/dist/signal/api/SignalIdentitySyncApi.js +4 -4
- package/dist/signal/crypto/WaAdvSignature.js +2 -50
- package/dist/signal/crypto/constants.js +1 -5
- package/dist/signal/encoding.js +11 -49
- package/dist/signal/group/SenderKeyChain.js +2 -2
- package/dist/signal/group/SenderKeyCodec.js +4 -5
- package/dist/signal/group/SenderKeyManager.js +12 -9
- package/dist/signal/registration/keygen.js +1 -2
- package/dist/signal/registration/utils.js +2 -2
- package/dist/signal/session/SignalProtocol.js +18 -17
- package/dist/signal/session/SignalRatchet.js +19 -8
- package/dist/signal/session/SignalSerializer.js +5 -6
- package/dist/signal/session/SignalSession.js +11 -9
- package/dist/signal/session/resolver.js +6 -6
- package/dist/store/contracts/identity.store.js +2 -0
- package/dist/store/contracts/message-secret.store.js +2 -0
- package/dist/store/contracts/pre-key.store.js +2 -0
- package/dist/store/contracts/session.store.js +2 -0
- package/dist/store/createStore.js +47 -11
- package/dist/store/index.js +9 -1
- package/dist/store/locks/identity.lock.js +19 -0
- package/dist/store/locks/message-secret.lock.js +20 -0
- package/dist/store/locks/pre-key.lock.js +30 -0
- package/dist/store/locks/session.lock.js +22 -0
- package/dist/store/locks/signal.lock.js +0 -24
- package/dist/store/noop.store.js +21 -1
- package/dist/store/providers/memory/device-list.store.js +3 -0
- package/dist/store/providers/memory/identity.store.js +35 -0
- package/dist/store/providers/memory/message-secret.store.js +85 -0
- package/dist/store/providers/memory/participants.store.js +3 -0
- package/dist/store/providers/memory/pre-key.store.js +101 -0
- package/dist/store/providers/memory/retry.store.js +24 -10
- package/dist/store/providers/memory/session.store.js +49 -0
- package/dist/store/providers/memory/signal.store.js +1 -164
- package/dist/transport/WaComms.js +4 -3
- package/dist/transport/WaWebSocket.js +9 -1
- package/dist/transport/index.js +17 -1
- package/dist/transport/keepalive/WaKeepAlive.js +17 -8
- package/dist/transport/node/WaMobileTcpSocket.js +118 -0
- package/dist/transport/node/WaNodeOrchestrator.js +16 -7
- package/dist/transport/node/builders/abprops.js +23 -0
- package/dist/transport/node/builders/device.js +14 -0
- package/dist/transport/node/builders/email.js +72 -0
- package/dist/transport/node/builders/offline.js +17 -0
- package/dist/transport/node/builders/prekeys.js +36 -39
- package/dist/transport/node/builders/presence.js +16 -0
- package/dist/transport/node/builders/privacy-token.js +18 -22
- package/dist/transport/node/builders/retry.js +1 -1
- package/dist/transport/node/helpers.js +26 -0
- package/dist/transport/node/mex/argo-decoder.js +189 -0
- package/dist/transport/node/mex/client.js +86 -0
- package/dist/transport/node/mex/persist-ids.js +13 -0
- package/dist/transport/noise/WaClientPayload.js +14 -9
- package/dist/transport/noise/WaFrameCodec.js +1 -1
- package/dist/transport/noise/WaMobileClientPayload.js +56 -0
- package/dist/transport/noise/WaNoiseCert.js +8 -26
- package/dist/transport/noise/WaNoiseSession.js +11 -10
- package/dist/types/appstate/WaAppStateCrypto.d.ts +11 -8
- package/dist/types/appstate/WaAppStateSyncClient.d.ts +6 -2
- package/dist/types/appstate/index.d.ts +1 -1
- package/dist/types/appstate/{WaAppStateSyncResponseParser.d.ts → response-parser.d.ts} +1 -1
- package/dist/types/appstate/types.d.ts +1 -1
- package/dist/types/auth/WaAuthClient.d.ts +9 -3
- package/dist/types/auth/credentials-flow.d.ts +20 -0
- package/dist/types/auth/pairing/WaPairingFlow.d.ts +3 -2
- package/dist/types/auth/pairing/{WaPairingCodeCrypto.d.ts → pairing-code-crypto.d.ts} +6 -1
- package/dist/types/auth/types.d.ts +40 -0
- package/dist/types/client/WaClient.d.ts +19 -8
- package/dist/types/client/WaClientFactory.d.ts +10 -4
- package/dist/types/client/coordinators/WaAbPropsCoordinator.d.ts +26 -0
- package/dist/types/client/coordinators/WaBusinessCoordinator.d.ts +1 -1
- package/dist/types/client/coordinators/WaEmailCoordinator.d.ts +24 -0
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +6 -1
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +15 -2
- package/dist/types/client/coordinators/WaOfflineResumeCoordinator.d.ts +31 -0
- package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +13 -2
- package/dist/types/client/coordinators/WaPrivacyCoordinator.d.ts +1 -1
- package/dist/types/client/coordinators/WaProfileCoordinator.d.ts +4 -2
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +6 -0
- package/dist/types/client/coordinators/WaTrustedContactTokenCoordinator.d.ts +11 -1
- package/dist/types/client/dirty.d.ts +3 -1
- package/dist/types/client/events/abprops.d.ts +14 -0
- package/dist/types/client/events/registration.d.ts +17 -0
- package/dist/types/client/incoming.d.ts +6 -1
- package/dist/types/client/mailbox.d.ts +2 -0
- package/dist/types/client/media.d.ts +31 -0
- package/dist/types/client/messages.d.ts +2 -0
- package/dist/types/client/persistence/WriteBehindPersistence.d.ts +1 -1
- package/dist/types/client/types.d.ts +100 -1
- package/dist/types/crypto/core/index.d.ts +1 -0
- package/dist/types/crypto/core/primitives.d.ts +1 -1
- package/dist/types/crypto/core/random.d.ts +1 -1
- package/dist/types/crypto/core/xeddsa.d.ts +2 -0
- package/dist/types/crypto/curves/constants.d.ts +1 -0
- package/dist/types/crypto/index.d.ts +1 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/infra/log/ConsoleLogger.d.ts +1 -1
- package/dist/types/infra/log/PinoLogger.d.ts +1 -1
- package/dist/types/infra/perf/StoreLock.d.ts +1 -0
- package/dist/types/media/WaMediaCrypto.d.ts +15 -6
- package/dist/types/media/WaMediaTransferClient.d.ts +3 -11
- package/dist/types/media/constants.d.ts +2 -0
- package/dist/types/media/index.d.ts +1 -0
- package/dist/types/media/processor.d.ts +28 -0
- package/dist/types/media/types.d.ts +9 -3
- package/dist/types/message/addon-crypto.d.ts +34 -3
- package/dist/types/message/content.d.ts +3 -1
- package/dist/types/message/icdc.d.ts +4 -4
- package/dist/types/message/types.d.ts +16 -24
- package/dist/types/protocol/abprops.d.ts +142 -0
- package/dist/types/protocol/browser.d.ts +1 -0
- package/dist/types/protocol/constants.d.ts +5 -1
- package/dist/types/protocol/email.d.ts +32 -0
- package/dist/types/protocol/jid.d.ts +1 -0
- package/dist/types/protocol/nodes.d.ts +4 -0
- package/dist/types/protocol/notification.d.ts +6 -0
- package/dist/types/protocol/stream.d.ts +1 -0
- package/dist/types/retry/reason.d.ts +1 -1
- package/dist/types/signal/api/SignalDigestSyncApi.d.ts +3 -0
- package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +3 -3
- package/dist/types/signal/crypto/WaAdvSignature.d.ts +0 -2
- package/dist/types/signal/crypto/constants.d.ts +0 -1
- package/dist/types/signal/encoding.d.ts +7 -1
- package/dist/types/signal/group/SenderKeyChain.d.ts +1 -1
- package/dist/types/signal/group/SenderKeyManager.d.ts +7 -2
- package/dist/types/signal/registration/utils.d.ts +2 -1
- package/dist/types/signal/session/SignalProtocol.d.ts +11 -2
- package/dist/types/signal/session/SignalSerializer.d.ts +2 -1
- package/dist/types/signal/session/resolver.d.ts +4 -2
- package/dist/types/signal/types.d.ts +16 -4
- package/dist/types/store/contracts/identity.store.d.ts +11 -0
- package/dist/types/store/contracts/message-secret.store.d.ts +16 -0
- package/dist/types/store/contracts/pre-key.store.d.ts +13 -0
- package/dist/types/store/contracts/session.store.d.ts +14 -0
- package/dist/types/store/contracts/signal.store.d.ts +1 -34
- package/dist/types/store/index.d.ts +9 -1
- package/dist/types/store/locks/identity.lock.d.ts +3 -0
- package/dist/types/store/locks/message-secret.lock.d.ts +3 -0
- package/dist/types/store/locks/pre-key.lock.d.ts +3 -0
- package/dist/types/store/locks/session.lock.d.ts +3 -0
- package/dist/types/store/noop.store.d.ts +4 -0
- package/dist/types/store/providers/memory/identity.store.d.ts +18 -0
- package/dist/types/store/providers/memory/message-secret.store.d.ts +21 -0
- package/dist/types/store/providers/memory/pre-key.store.d.ts +23 -0
- package/dist/types/store/providers/memory/retry.store.d.ts +7 -1
- package/dist/types/store/providers/memory/session.store.d.ts +21 -0
- package/dist/types/store/providers/memory/signal.store.d.ts +3 -45
- package/dist/types/store/providers/memory/thread.store.d.ts +1 -1
- package/dist/types/store/types.d.ts +21 -1
- package/dist/types/transport/WaWebSocket.d.ts +1 -0
- package/dist/types/transport/index.d.ts +8 -1
- package/dist/types/transport/keepalive/WaKeepAlive.d.ts +4 -1
- package/dist/types/transport/node/WaMobileTcpSocket.d.ts +18 -0
- package/dist/types/transport/node/WaNodeOrchestrator.d.ts +6 -2
- package/dist/types/transport/node/builders/abprops.d.ts +5 -0
- package/dist/types/transport/node/builders/device.d.ts +2 -0
- package/dist/types/transport/node/builders/email.d.ts +11 -0
- package/dist/types/transport/node/builders/offline.d.ts +2 -0
- package/dist/types/transport/node/builders/prekeys.d.ts +4 -3
- package/dist/types/transport/node/builders/presence.d.ts +6 -0
- package/dist/types/transport/node/helpers.d.ts +3 -0
- package/dist/types/transport/node/mex/argo-decoder.d.ts +11 -0
- package/dist/types/transport/node/mex/client.d.ts +18 -0
- package/dist/types/transport/node/mex/persist-ids.d.ts +14 -0
- package/dist/types/transport/noise/WaMobileClientPayload.d.ts +29 -0
- package/dist/types/transport/noise/WaNoiseCert.d.ts +7 -1
- package/dist/types/transport/noise/WaNoiseSession.d.ts +1 -0
- package/dist/types/transport/types.d.ts +8 -0
- package/package.json +6 -4
- package/dist/auth/pairing/constants.js +0 -5
- package/dist/client/connection/WaKeyShareCoordinator.js +0 -63
- package/dist/esm/auth/pairing/constants.js +0 -2
- package/dist/esm/client/connection/WaKeyShareCoordinator.js +0 -59
- package/dist/esm/transport/node/builders/index.js +0 -11
- package/dist/transport/node/builders/index.js +0 -51
- package/dist/types/auth/flow/WaAuthCredentialsFlow.d.ts +0 -14
- package/dist/types/auth/pairing/constants.d.ts +0 -2
- package/dist/types/client/connection/WaKeyShareCoordinator.d.ts +0 -14
- package/dist/types/transport/node/builders/index.d.ts +0 -11
- /package/dist/appstate/{WaAppStateSyncResponseParser.js → response-parser.js} +0 -0
|
@@ -5,13 +5,15 @@ exports.buildWaClientDependencies = buildWaClientDependencies;
|
|
|
5
5
|
const WaAppStateSyncClient_1 = require("../appstate/WaAppStateSyncClient");
|
|
6
6
|
const WaAuthClient_1 = require("../auth/WaAuthClient");
|
|
7
7
|
const WaConnectionManager_1 = require("./connection/WaConnectionManager");
|
|
8
|
-
const WaKeyShareCoordinator_1 = require("./connection/WaKeyShareCoordinator");
|
|
9
8
|
const WaReceiptQueue_1 = require("./connection/WaReceiptQueue");
|
|
9
|
+
const WaAbPropsCoordinator_1 = require("./coordinators/WaAbPropsCoordinator");
|
|
10
10
|
const WaAppStateMutationCoordinator_1 = require("./coordinators/WaAppStateMutationCoordinator");
|
|
11
11
|
const WaBusinessCoordinator_1 = require("./coordinators/WaBusinessCoordinator");
|
|
12
|
+
const WaEmailCoordinator_1 = require("./coordinators/WaEmailCoordinator");
|
|
12
13
|
const WaGroupCoordinator_1 = require("./coordinators/WaGroupCoordinator");
|
|
13
14
|
const WaIncomingNodeCoordinator_1 = require("./coordinators/WaIncomingNodeCoordinator");
|
|
14
15
|
const WaMessageDispatchCoordinator_1 = require("./coordinators/WaMessageDispatchCoordinator");
|
|
16
|
+
const WaOfflineResumeCoordinator_1 = require("./coordinators/WaOfflineResumeCoordinator");
|
|
15
17
|
const WaPassiveTasksCoordinator_1 = require("./coordinators/WaPassiveTasksCoordinator");
|
|
16
18
|
const WaPrivacyCoordinator_1 = require("./coordinators/WaPrivacyCoordinator");
|
|
17
19
|
const WaProfileCoordinator_1 = require("./coordinators/WaProfileCoordinator");
|
|
@@ -43,6 +45,7 @@ const resolver_1 = require("../signal/session/resolver");
|
|
|
43
45
|
const SignalProtocol_1 = require("../signal/session/SignalProtocol");
|
|
44
46
|
const WaKeepAlive_1 = require("../transport/keepalive/WaKeepAlive");
|
|
45
47
|
const global_1 = require("../transport/node/builders/global");
|
|
48
|
+
const presence_1 = require("../transport/node/builders/presence");
|
|
46
49
|
const helpers_1 = require("../transport/node/helpers");
|
|
47
50
|
const usync_1 = require("../transport/node/usync");
|
|
48
51
|
const WaNodeOrchestrator_1 = require("../transport/node/WaNodeOrchestrator");
|
|
@@ -132,6 +135,8 @@ function createIncomingNodeRuntime(input) {
|
|
|
132
135
|
emitIncomingFailure: (event) => emitEvent('failure', event),
|
|
133
136
|
emitIncomingErrorStanza: (event) => emitEvent('stanza_error', event),
|
|
134
137
|
emitIncomingNotification: (event) => emitEvent('notification', event),
|
|
138
|
+
emitRegistrationCode: (event) => emitEvent('registration_code_received', event),
|
|
139
|
+
emitAccountTakeoverNotice: (event) => emitEvent('account_takeover_notice', event),
|
|
135
140
|
emitGroupEvent: (event) => {
|
|
136
141
|
emitEvent('group_event', event);
|
|
137
142
|
void messageDispatch.mutateParticipantsCacheFromGroupEvent(event).catch((error) => {
|
|
@@ -155,7 +160,7 @@ function createIncomingNodeRuntime(input) {
|
|
|
155
160
|
};
|
|
156
161
|
}
|
|
157
162
|
function createPassiveTasksRuntime(input) {
|
|
158
|
-
const { queryWithContext, authClient, nodeOrchestrator, receiptQueue, getCurrentCredentials } = input;
|
|
163
|
+
const { queryWithContext, authClient, nodeOrchestrator, receiptQueue, getCurrentCredentials, abPropsCoordinator } = input;
|
|
159
164
|
return {
|
|
160
165
|
queryWithContext,
|
|
161
166
|
getCurrentCredentials,
|
|
@@ -163,14 +168,18 @@ function createPassiveTasksRuntime(input) {
|
|
|
163
168
|
sendNodeDirect: (node) => nodeOrchestrator.sendNode(node),
|
|
164
169
|
takeDanglingReceipts: () => receiptQueue.take(),
|
|
165
170
|
requeueDanglingReceipt: (node) => receiptQueue.enqueue(node),
|
|
166
|
-
shouldQueueDanglingReceipt: (node, error) => receiptQueue.shouldQueue(node, error)
|
|
171
|
+
shouldQueueDanglingReceipt: (node, error) => receiptQueue.shouldQueue(node, error),
|
|
172
|
+
syncAbProps: () => abPropsCoordinator.sync(),
|
|
173
|
+
sendPresenceAvailable: async () => {
|
|
174
|
+
const credentials = getCurrentCredentials();
|
|
175
|
+
await nodeOrchestrator.sendNode((0, presence_1.buildPresenceNode)({ name: credentials?.meDisplayName ?? undefined }), false);
|
|
176
|
+
}
|
|
167
177
|
};
|
|
168
178
|
}
|
|
169
179
|
function buildWaClientDependencies(input) {
|
|
170
180
|
const { base, runtime } = input;
|
|
171
181
|
const { options, logger, sessionStore } = base;
|
|
172
182
|
const receiptQueue = new WaReceiptQueue_1.WaReceiptQueue();
|
|
173
|
-
const keyShareCoordinator = new WaKeyShareCoordinator_1.WaKeyShareCoordinator();
|
|
174
183
|
let connectionManager = null;
|
|
175
184
|
let passiveTasks = null;
|
|
176
185
|
let mediaConnCacheFallback = null;
|
|
@@ -180,23 +189,24 @@ function buildWaClientDependencies(input) {
|
|
|
180
189
|
sendNode: async (node) => nodeTransport.sendNode(node),
|
|
181
190
|
logger,
|
|
182
191
|
defaultTimeoutMs: options.nodeQueryTimeoutMs,
|
|
183
|
-
hostDomain: constants_1.WA_DEFAULTS.HOST_DOMAIN
|
|
192
|
+
hostDomain: constants_1.WA_DEFAULTS.HOST_DOMAIN,
|
|
193
|
+
mobileIqIdFormat: options.mobileTransport !== undefined
|
|
184
194
|
});
|
|
185
195
|
const keepAlive = new WaKeepAlive_1.WaKeepAlive({
|
|
186
196
|
logger,
|
|
187
197
|
nodeOrchestrator,
|
|
188
198
|
getComms: () => connectionManager?.getComms() ?? null,
|
|
189
199
|
intervalMs: options.keepAliveIntervalMs,
|
|
200
|
+
getIntervalMs: () => abPropsCoordinator.getConfigValue('heartbeat_interval_s') * 1000,
|
|
190
201
|
timeoutMs: options.deadSocketTimeoutMs,
|
|
191
202
|
hostDomain: constants_1.WA_DEFAULTS.HOST_DOMAIN
|
|
192
203
|
});
|
|
193
204
|
const mediaTransfer = new WaMediaTransferClient_1.WaMediaTransferClient({
|
|
194
205
|
logger,
|
|
195
206
|
defaultTimeoutMs: options.mediaTimeoutMs,
|
|
196
|
-
defaultUploadDispatcher: (0, proxy_1.toProxyDispatcher)(options.proxy?.mediaUpload),
|
|
197
|
-
defaultDownloadDispatcher: (0, proxy_1.toProxyDispatcher)(options.proxy?.mediaDownload),
|
|
198
207
|
defaultUploadAgent: (0, proxy_1.toProxyAgent)(options.proxy?.mediaUpload),
|
|
199
|
-
defaultDownloadAgent: (0, proxy_1.toProxyAgent)(options.proxy?.mediaDownload)
|
|
208
|
+
defaultDownloadAgent: (0, proxy_1.toProxyAgent)(options.proxy?.mediaDownload),
|
|
209
|
+
skipMacVerification: options.dangerous?.disableMediaMacVerification
|
|
200
210
|
});
|
|
201
211
|
const mediaMessageBuildOptions = {
|
|
202
212
|
logger,
|
|
@@ -212,7 +222,8 @@ function buildWaClientDependencies(input) {
|
|
|
212
222
|
setMediaConnCache: (mediaConn) => {
|
|
213
223
|
mediaConnCacheFallback = mediaConn;
|
|
214
224
|
connectionManager?.setMediaConnCache(mediaConn);
|
|
215
|
-
}
|
|
225
|
+
},
|
|
226
|
+
media: options.media
|
|
216
227
|
};
|
|
217
228
|
const messageClient = new WaMessageClient_1.WaMessageClient({
|
|
218
229
|
logger,
|
|
@@ -222,12 +233,22 @@ function buildWaClientDependencies(input) {
|
|
|
222
233
|
defaultMaxAttempts: options.messageMaxAttempts,
|
|
223
234
|
defaultRetryDelayMs: options.messageRetryDelayMs
|
|
224
235
|
});
|
|
225
|
-
const senderKeyManager = new SenderKeyManager_1.SenderKeyManager(sessionStore.senderKey
|
|
226
|
-
|
|
236
|
+
const senderKeyManager = new SenderKeyManager_1.SenderKeyManager(sessionStore.senderKey, {
|
|
237
|
+
getFutureMessagesMax: () => abPropsCoordinator.getConfigValue('web_signal_future_messages_max'),
|
|
238
|
+
skipSignatureVerification: options.dangerous?.disableSenderKeySignatureVerification
|
|
239
|
+
});
|
|
240
|
+
const signalProtocol = new SignalProtocol_1.SignalProtocol({
|
|
241
|
+
signal: sessionStore.signal,
|
|
242
|
+
preKey: sessionStore.preKey,
|
|
243
|
+
session: sessionStore.session,
|
|
244
|
+
identity: sessionStore.identity
|
|
245
|
+
}, logger);
|
|
246
|
+
const signalSystemQuery = (node, timeoutMs) => runtime.query(node, timeoutMs, { useSystemId: true });
|
|
227
247
|
const signalDigestSync = new SignalDigestSyncApi_1.SignalDigestSyncApi({
|
|
228
248
|
logger,
|
|
229
|
-
query:
|
|
249
|
+
query: signalSystemQuery,
|
|
230
250
|
signalStore: sessionStore.signal,
|
|
251
|
+
preKeyStore: sessionStore.preKey,
|
|
231
252
|
defaultTimeoutMs: options.signalFetchKeyBundlesTimeoutMs
|
|
232
253
|
});
|
|
233
254
|
const generateUsyncSid = (0, usync_1.createUsyncSidGenerator)();
|
|
@@ -240,24 +261,24 @@ function buildWaClientDependencies(input) {
|
|
|
240
261
|
});
|
|
241
262
|
const signalIdentitySync = new SignalIdentitySyncApi_1.SignalIdentitySyncApi({
|
|
242
263
|
logger,
|
|
243
|
-
query:
|
|
244
|
-
|
|
264
|
+
query: signalSystemQuery,
|
|
265
|
+
identityStore: sessionStore.identity,
|
|
245
266
|
defaultTimeoutMs: options.signalFetchKeyBundlesTimeoutMs
|
|
246
267
|
});
|
|
247
268
|
const signalMissingPreKeysSync = new SignalMissingPreKeysSyncApi_1.SignalMissingPreKeysSyncApi({
|
|
248
269
|
logger,
|
|
249
|
-
query:
|
|
270
|
+
query: signalSystemQuery,
|
|
250
271
|
defaultTimeoutMs: options.signalFetchKeyBundlesTimeoutMs
|
|
251
272
|
});
|
|
252
273
|
const signalRotateKey = new SignalRotateKeyApi_1.SignalRotateKeyApi({
|
|
253
274
|
logger,
|
|
254
|
-
query:
|
|
275
|
+
query: signalSystemQuery,
|
|
255
276
|
signalStore: sessionStore.signal,
|
|
256
277
|
defaultTimeoutMs: options.signalFetchKeyBundlesTimeoutMs
|
|
257
278
|
});
|
|
258
279
|
const signalSessionSync = new SignalSessionSyncApi_1.SignalSessionSyncApi({
|
|
259
280
|
logger,
|
|
260
|
-
query:
|
|
281
|
+
query: signalSystemQuery,
|
|
261
282
|
defaultTimeoutMs: options.signalFetchKeyBundlesTimeoutMs
|
|
262
283
|
});
|
|
263
284
|
const authClient = new WaAuthClient_1.WaAuthClient({
|
|
@@ -265,11 +286,14 @@ function buildWaClientDependencies(input) {
|
|
|
265
286
|
deviceOsDisplayName: options.deviceOsDisplayName,
|
|
266
287
|
devicePlatform: options.devicePlatform,
|
|
267
288
|
requireFullSync: options.requireFullSync,
|
|
268
|
-
version: options.version
|
|
289
|
+
version: options.version,
|
|
290
|
+
dangerous: options.dangerous,
|
|
291
|
+
mobileTransport: options.mobileTransport
|
|
269
292
|
}, {
|
|
270
293
|
logger,
|
|
271
294
|
authStore: sessionStore.auth,
|
|
272
295
|
signalStore: sessionStore.signal,
|
|
296
|
+
preKeyStore: sessionStore.preKey,
|
|
273
297
|
socket: {
|
|
274
298
|
sendNode: runtime.sendNode,
|
|
275
299
|
query: runtime.query
|
|
@@ -302,13 +326,17 @@ function buildWaClientDependencies(input) {
|
|
|
302
326
|
const businessCoordinator = (0, WaBusinessCoordinator_1.createBusinessCoordinator)({
|
|
303
327
|
queryWithContext: runtime.queryWithContext
|
|
304
328
|
});
|
|
329
|
+
const emailCoordinator = (0, WaEmailCoordinator_1.createEmailCoordinator)({
|
|
330
|
+
queryWithContext: runtime.queryWithContext
|
|
331
|
+
});
|
|
305
332
|
const retryTracker = (0, tracker_1.createOutboundRetryTracker)({
|
|
306
333
|
retryStore: sessionStore.retry,
|
|
307
334
|
logger
|
|
308
335
|
});
|
|
309
336
|
const sessionResolver = (0, resolver_1.createSignalSessionResolver)({
|
|
310
337
|
signalProtocol,
|
|
311
|
-
|
|
338
|
+
sessionStore: sessionStore.session,
|
|
339
|
+
identityStore: sessionStore.identity,
|
|
312
340
|
signalIdentitySync,
|
|
313
341
|
signalSessionSync,
|
|
314
342
|
logger
|
|
@@ -343,7 +371,19 @@ function buildWaClientDependencies(input) {
|
|
|
343
371
|
numBuckets: options.privacyToken?.tcTokenNumBuckets,
|
|
344
372
|
senderDurationS: options.privacyToken?.tcTokenSenderDurationS,
|
|
345
373
|
senderNumBuckets: options.privacyToken?.tcTokenSenderNumBuckets,
|
|
346
|
-
maxDurationS: options.privacyToken?.tcTokenMaxDurationS
|
|
374
|
+
maxDurationS: options.privacyToken?.tcTokenMaxDurationS,
|
|
375
|
+
getConfigOverrides: () => ({
|
|
376
|
+
durationS: abPropsCoordinator.getConfigValue('tctoken_duration'),
|
|
377
|
+
numBuckets: abPropsCoordinator.getConfigValue('tctoken_num_buckets'),
|
|
378
|
+
senderDurationS: abPropsCoordinator.getConfigValue('tctoken_duration_sender'),
|
|
379
|
+
senderNumBuckets: abPropsCoordinator.getConfigValue('tctoken_num_buckets_sender')
|
|
380
|
+
})
|
|
381
|
+
});
|
|
382
|
+
const abPropsCoordinator = new WaAbPropsCoordinator_1.WaAbPropsCoordinator({
|
|
383
|
+
logger,
|
|
384
|
+
runtime: {
|
|
385
|
+
queryWithContext: runtime.queryWithContext
|
|
386
|
+
}
|
|
347
387
|
});
|
|
348
388
|
let messageDispatch;
|
|
349
389
|
const appStateSyncKeyProtocol = (0, key_protocol_1.createAppStateSyncKeyProtocol)({
|
|
@@ -365,7 +405,10 @@ function buildWaClientDependencies(input) {
|
|
|
365
405
|
senderKeyManager,
|
|
366
406
|
signalProtocol,
|
|
367
407
|
signalStore: sessionStore.signal,
|
|
408
|
+
sessionStore: sessionStore.session,
|
|
409
|
+
identityStore: sessionStore.identity,
|
|
368
410
|
deviceListStore: sessionStore.deviceList,
|
|
411
|
+
messageSecretStore: sessionStore.messageSecret,
|
|
369
412
|
getCurrentMeJid,
|
|
370
413
|
getCurrentMeLid,
|
|
371
414
|
getCurrentSignedIdentity,
|
|
@@ -375,12 +418,16 @@ function buildWaClientDependencies(input) {
|
|
|
375
418
|
to: recipientJid,
|
|
376
419
|
message: (0, primitives_1.toError)(err).message
|
|
377
420
|
}));
|
|
378
|
-
}
|
|
421
|
+
},
|
|
422
|
+
getIcdcHashLength: () => abPropsCoordinator.getConfigValue('md_icdc_hash_length'),
|
|
423
|
+
mobileMessageIdFormat: options.mobileTransport !== undefined
|
|
379
424
|
});
|
|
380
425
|
const retryCoordinator = new WaRetryCoordinator_1.WaRetryCoordinator({
|
|
381
426
|
logger,
|
|
382
427
|
retryStore: sessionStore.retry,
|
|
383
428
|
signalStore: sessionStore.signal,
|
|
429
|
+
preKeyStore: sessionStore.preKey,
|
|
430
|
+
sessionStore: sessionStore.session,
|
|
384
431
|
senderKeyStore: sessionStore.senderKey,
|
|
385
432
|
signalProtocol,
|
|
386
433
|
signalDeviceSync,
|
|
@@ -399,7 +446,9 @@ function buildWaClientDependencies(input) {
|
|
|
399
446
|
store: sessionStore.appState,
|
|
400
447
|
onMissingKeys: async ({ keyIds }) => {
|
|
401
448
|
await messageDispatch.requestAppStateSyncKeys(keyIds);
|
|
402
|
-
}
|
|
449
|
+
},
|
|
450
|
+
skipMacVerification: options.dangerous?.disableAppStateMacVerification,
|
|
451
|
+
mobilePrimary: options.mobileTransport !== undefined
|
|
403
452
|
});
|
|
404
453
|
const appStateMutations = new WaAppStateMutationCoordinator_1.WaAppStateMutationCoordinator({
|
|
405
454
|
logger,
|
|
@@ -421,7 +470,8 @@ function buildWaClientDependencies(input) {
|
|
|
421
470
|
}
|
|
422
471
|
scheduleReconnectAfterPairing = () => connectionManager?.scheduleReconnectAfterPairing();
|
|
423
472
|
const disconnectWithClientSideEffects = async (reason, isLogout, code) => {
|
|
424
|
-
|
|
473
|
+
abPropsCoordinator.reset();
|
|
474
|
+
offlineResume.reset();
|
|
425
475
|
await connectionManager?.disconnect();
|
|
426
476
|
runtime.emitEvent('connection', {
|
|
427
477
|
status: 'close',
|
|
@@ -478,8 +528,16 @@ function buildWaClientDependencies(input) {
|
|
|
478
528
|
syncAppState: runtime.syncAppState,
|
|
479
529
|
generateUsyncSid
|
|
480
530
|
}, dirtyBits);
|
|
531
|
+
const offlineResume = new WaOfflineResumeCoordinator_1.WaOfflineResumeCoordinator({
|
|
532
|
+
logger,
|
|
533
|
+
runtime: {
|
|
534
|
+
sendNode: (node) => nodeOrchestrator.sendNode(node, false),
|
|
535
|
+
emitOfflineResume: (event) => runtime.emitEvent('offline_resume', event)
|
|
536
|
+
}
|
|
537
|
+
});
|
|
481
538
|
const incomingNode = new WaIncomingNodeCoordinator_1.WaIncomingNodeCoordinator({
|
|
482
539
|
logger,
|
|
540
|
+
offlineResume,
|
|
483
541
|
runtime: createIncomingNodeRuntime({
|
|
484
542
|
logger,
|
|
485
543
|
emitEvent: runtime.emitEvent,
|
|
@@ -582,12 +640,12 @@ function buildWaClientDependencies(input) {
|
|
|
582
640
|
return true;
|
|
583
641
|
}
|
|
584
642
|
}
|
|
585
|
-
const oldIdentity = await sessionStore.
|
|
643
|
+
const oldIdentity = await sessionStore.identity.getRemoteIdentity(address);
|
|
586
644
|
if (oldIdentity) {
|
|
587
645
|
logger.info('identity-change: clearing session', {
|
|
588
646
|
jid: parsed.fromJid
|
|
589
647
|
});
|
|
590
|
-
await sessionStore.
|
|
648
|
+
await sessionStore.session.deleteSession(address);
|
|
591
649
|
const userJid = (0, jid_1.toUserJid)(parsed.fromJid);
|
|
592
650
|
await trustedContactToken.reissueOnIdentityChange(userJid).catch((error) => {
|
|
593
651
|
logger.warn('identity-change: reissue tc token failed', {
|
|
@@ -638,7 +696,7 @@ function buildWaClientDependencies(input) {
|
|
|
638
696
|
server: baseAddress.server,
|
|
639
697
|
device: device.deviceId
|
|
640
698
|
};
|
|
641
|
-
await sessionStore.
|
|
699
|
+
await sessionStore.session.deleteSession(address).catch((error) => {
|
|
642
700
|
logger.warn('devices-notification: delete session failed', {
|
|
643
701
|
message: (0, primitives_1.toError)(error).message
|
|
644
702
|
});
|
|
@@ -700,9 +758,30 @@ function buildWaClientDependencies(input) {
|
|
|
700
758
|
return true;
|
|
701
759
|
}
|
|
702
760
|
});
|
|
761
|
+
// AB Props: sync after successful login and on server notification
|
|
762
|
+
incomingNode.registerIncomingHandler({
|
|
763
|
+
tag: constants_1.WA_NODE_TAGS.NOTIFICATION,
|
|
764
|
+
subtype: constants_1.WA_NOTIFICATION_TYPES.SERVER,
|
|
765
|
+
prepend: true,
|
|
766
|
+
handler: async (node) => {
|
|
767
|
+
const firstChild = (0, helpers_1.getFirstNodeChild)(node);
|
|
768
|
+
if (!firstChild || firstChild.tag !== constants_1.WA_NODE_TAGS.ABPROPS) {
|
|
769
|
+
return false;
|
|
770
|
+
}
|
|
771
|
+
const ackNode = (0, global_1.buildAckNode)({
|
|
772
|
+
kind: 'notification',
|
|
773
|
+
node,
|
|
774
|
+
includeType: false
|
|
775
|
+
});
|
|
776
|
+
await runtime.sendNode(ackNode);
|
|
777
|
+
abPropsCoordinator.sync();
|
|
778
|
+
return true;
|
|
779
|
+
}
|
|
780
|
+
});
|
|
703
781
|
passiveTasks = new WaPassiveTasksCoordinator_1.WaPassiveTasksCoordinator({
|
|
704
782
|
logger,
|
|
705
783
|
signalStore: sessionStore.signal,
|
|
784
|
+
preKeyStore: sessionStore.preKey,
|
|
706
785
|
signalDigestSync,
|
|
707
786
|
signalRotateKey,
|
|
708
787
|
runtime: createPassiveTasksRuntime({
|
|
@@ -710,8 +789,11 @@ function buildWaClientDependencies(input) {
|
|
|
710
789
|
authClient,
|
|
711
790
|
nodeOrchestrator,
|
|
712
791
|
receiptQueue,
|
|
713
|
-
getCurrentCredentials
|
|
714
|
-
|
|
792
|
+
getCurrentCredentials,
|
|
793
|
+
abPropsCoordinator
|
|
794
|
+
}),
|
|
795
|
+
mobilePrimary: options.mobileTransport !== undefined,
|
|
796
|
+
appStateSync
|
|
715
797
|
});
|
|
716
798
|
return {
|
|
717
799
|
nodeTransport,
|
|
@@ -740,9 +822,10 @@ function buildWaClientDependencies(input) {
|
|
|
740
822
|
privacyCoordinator,
|
|
741
823
|
profileCoordinator,
|
|
742
824
|
businessCoordinator,
|
|
825
|
+
emailCoordinator,
|
|
743
826
|
receiptQueue,
|
|
744
|
-
keyShareCoordinator,
|
|
745
827
|
connectionManager,
|
|
746
|
-
trustedContactToken
|
|
828
|
+
trustedContactToken,
|
|
829
|
+
abPropsCoordinator
|
|
747
830
|
};
|
|
748
831
|
}
|
|
@@ -203,7 +203,10 @@ class WaConnectionManager {
|
|
|
203
203
|
this.logger.debug('starting comms with credentials', {
|
|
204
204
|
registered: credentials.meJid !== null && credentials.meJid !== undefined
|
|
205
205
|
});
|
|
206
|
-
const commsConfig = this.authClient.buildCommsConfig(this.options
|
|
206
|
+
const commsConfig = this.authClient.buildCommsConfig(this.options, {
|
|
207
|
+
noiseTrustedRootCa: this.options.testHooks?.noiseRootCa,
|
|
208
|
+
disableNoiseCertificateChainVerification: this.options.dangerous?.disableNoiseCertificateChainVerification
|
|
209
|
+
});
|
|
207
210
|
const comms = new WaComms_1.WaComms(commsConfig, this.logger);
|
|
208
211
|
this.pendingComms = comms;
|
|
209
212
|
this.mediaConnCache = null;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WaAbPropsCoordinator = void 0;
|
|
4
|
+
const abprops_1 = require("../events/abprops");
|
|
5
|
+
const abprops_2 = require("../../protocol/abprops");
|
|
6
|
+
const constants_1 = require("../../protocol/constants");
|
|
7
|
+
const abprops_3 = require("../../transport/node/builders/abprops");
|
|
8
|
+
const primitives_1 = require("../../util/primitives");
|
|
9
|
+
class WaAbPropsCoordinator {
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.logger = options.logger;
|
|
12
|
+
this.runtime = options.runtime;
|
|
13
|
+
this.cache = new Map();
|
|
14
|
+
this.syncState = { hash: null, abKey: null, refreshId: null };
|
|
15
|
+
this.syncPromise = null;
|
|
16
|
+
this.syncEpoch = 0;
|
|
17
|
+
this.pendingSync = false;
|
|
18
|
+
}
|
|
19
|
+
getConfigValue(name) {
|
|
20
|
+
const cached = this.cache.get(name);
|
|
21
|
+
if (cached !== undefined) {
|
|
22
|
+
return cached;
|
|
23
|
+
}
|
|
24
|
+
return abprops_2.AB_PROP_CONFIGS[name].defaultValue;
|
|
25
|
+
}
|
|
26
|
+
sync() {
|
|
27
|
+
if (this.syncPromise) {
|
|
28
|
+
this.pendingSync = true;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
this.startSync();
|
|
32
|
+
}
|
|
33
|
+
reset() {
|
|
34
|
+
this.cache.clear();
|
|
35
|
+
this.syncState.hash = null;
|
|
36
|
+
this.syncState.abKey = null;
|
|
37
|
+
this.syncState.refreshId = null;
|
|
38
|
+
this.syncPromise = null;
|
|
39
|
+
this.pendingSync = false;
|
|
40
|
+
this.syncEpoch += 1;
|
|
41
|
+
}
|
|
42
|
+
startSync() {
|
|
43
|
+
const epoch = this.syncEpoch;
|
|
44
|
+
this.pendingSync = false;
|
|
45
|
+
this.syncPromise = this.executeSyncWithRetry(epoch)
|
|
46
|
+
.catch((error) => {
|
|
47
|
+
this.logger.warn('ab props sync failed', {
|
|
48
|
+
message: (0, primitives_1.toError)(error).message
|
|
49
|
+
});
|
|
50
|
+
})
|
|
51
|
+
.finally(() => {
|
|
52
|
+
if (this.syncEpoch !== epoch) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
this.syncPromise = null;
|
|
56
|
+
if (this.pendingSync) {
|
|
57
|
+
this.startSync();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
async executeSyncWithRetry(epoch) {
|
|
62
|
+
const maxRetries = 3;
|
|
63
|
+
for (let attempt = 0; attempt < maxRetries; attempt += 1) {
|
|
64
|
+
if (this.syncEpoch !== epoch) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
await this.executeSync(epoch);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (attempt === maxRetries - 1) {
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
this.logger.debug('ab props sync retrying', {
|
|
76
|
+
attempt: attempt + 1,
|
|
77
|
+
message: (0, primitives_1.toError)(error).message
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async executeSync(epoch) {
|
|
83
|
+
const iqNode = (0, abprops_3.buildGetAbPropsIq)({
|
|
84
|
+
hash: this.syncState.hash,
|
|
85
|
+
refreshId: this.syncState.refreshId
|
|
86
|
+
});
|
|
87
|
+
const response = await this.runtime.queryWithContext('abprops.sync', iqNode, constants_1.WA_DEFAULTS.IQ_TIMEOUT_MS);
|
|
88
|
+
if (this.syncEpoch !== epoch) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const result = (0, abprops_1.parseAbPropsIqResult)(response);
|
|
92
|
+
if (result.abKey !== null) {
|
|
93
|
+
this.syncState.abKey = result.abKey;
|
|
94
|
+
}
|
|
95
|
+
if (result.hash !== null) {
|
|
96
|
+
this.syncState.hash = result.hash;
|
|
97
|
+
}
|
|
98
|
+
if (result.refreshId !== null) {
|
|
99
|
+
this.syncState.refreshId = result.refreshId;
|
|
100
|
+
}
|
|
101
|
+
if (!result.isDeltaUpdate) {
|
|
102
|
+
this.cache.clear();
|
|
103
|
+
}
|
|
104
|
+
let applied = 0;
|
|
105
|
+
for (let i = 0; i < result.props.length; i += 1) {
|
|
106
|
+
const entry = result.props[i];
|
|
107
|
+
const name = (0, abprops_2.resolveAbPropNameByCode)(entry.configCode);
|
|
108
|
+
if (!name) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const config = abprops_2.AB_PROP_CONFIGS[name];
|
|
112
|
+
const parsed = parseConfigValue(entry.configValue, config.type, config.defaultValue);
|
|
113
|
+
this.cache.set(name, parsed);
|
|
114
|
+
applied += 1;
|
|
115
|
+
}
|
|
116
|
+
this.logger.info('ab props synced', {
|
|
117
|
+
received: result.props.length,
|
|
118
|
+
applied,
|
|
119
|
+
isDelta: result.isDeltaUpdate,
|
|
120
|
+
abKey: result.abKey,
|
|
121
|
+
refresh: result.refresh !== null ? clampRefresh(result.refresh) : null
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.WaAbPropsCoordinator = WaAbPropsCoordinator;
|
|
126
|
+
function parseConfigValue(value, type, defaultValue) {
|
|
127
|
+
if (value === null) {
|
|
128
|
+
return defaultValue;
|
|
129
|
+
}
|
|
130
|
+
if (type === 'bool') {
|
|
131
|
+
return value === '1' || value === 'true' || value === 'True';
|
|
132
|
+
}
|
|
133
|
+
if (type === 'int') {
|
|
134
|
+
const parsed = Number.parseInt(value, 10);
|
|
135
|
+
return Number.isSafeInteger(parsed) ? parsed : defaultValue;
|
|
136
|
+
}
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
function clampRefresh(seconds) {
|
|
140
|
+
return Math.max(abprops_2.WA_ABPROPS_REFRESH_BOUNDS.MIN_S, Math.min(abprops_2.WA_ABPROPS_REFRESH_BOUNDS.MAX_S, seconds));
|
|
141
|
+
}
|
|
@@ -5,16 +5,7 @@ const _proto_1 = require("../../proto.js");
|
|
|
5
5
|
const business_1 = require("../../transport/node/builders/business");
|
|
6
6
|
const helpers_1 = require("../../transport/node/helpers");
|
|
7
7
|
const query_1 = require("../../transport/node/query");
|
|
8
|
-
const bytes_1 = require("../../util/bytes");
|
|
9
8
|
const primitives_1 = require("../../util/primitives");
|
|
10
|
-
function readTextContent(node) {
|
|
11
|
-
const content = node.content;
|
|
12
|
-
if (content instanceof Uint8Array)
|
|
13
|
-
return bytes_1.TEXT_DECODER.decode(content);
|
|
14
|
-
if (typeof content === 'string')
|
|
15
|
-
return content;
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
9
|
function parseBusinessProfiles(result) {
|
|
19
10
|
const bizNode = (0, helpers_1.findNodeChild)(result, 'business_profile');
|
|
20
11
|
if (!bizNode) {
|
|
@@ -43,7 +34,7 @@ function parseBusinessProfiles(result) {
|
|
|
43
34
|
const websites = [];
|
|
44
35
|
for (let j = 0; j < children.length; j += 1) {
|
|
45
36
|
const child = children[j];
|
|
46
|
-
const text =
|
|
37
|
+
const text = (0, helpers_1.getNodeTextContent)(child);
|
|
47
38
|
switch (child.tag) {
|
|
48
39
|
case 'description':
|
|
49
40
|
if (text !== undefined)
|
|
@@ -105,7 +96,7 @@ function parseBusinessCategories(node) {
|
|
|
105
96
|
const id = child.attrs.id;
|
|
106
97
|
if (!id)
|
|
107
98
|
continue;
|
|
108
|
-
categories[count] = { id, name:
|
|
99
|
+
categories[count] = { id, name: (0, helpers_1.getNodeTextContent)(child) ?? '' };
|
|
109
100
|
count += 1;
|
|
110
101
|
}
|
|
111
102
|
categories.length = count;
|
|
@@ -142,7 +133,7 @@ function parseProfileOptions(node) {
|
|
|
142
133
|
const options = {};
|
|
143
134
|
for (let i = 0; i < children.length; i += 1) {
|
|
144
135
|
const child = children[i];
|
|
145
|
-
const text =
|
|
136
|
+
const text = (0, helpers_1.getNodeTextContent)(child);
|
|
146
137
|
if (text !== undefined) {
|
|
147
138
|
options[child.tag] = text;
|
|
148
139
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEmailCoordinator = createEmailCoordinator;
|
|
4
|
+
const email_1 = require("../../protocol/email");
|
|
5
|
+
const email_2 = require("../../transport/node/builders/email");
|
|
6
|
+
const helpers_1 = require("../../transport/node/helpers");
|
|
7
|
+
const query_1 = require("../../transport/node/query");
|
|
8
|
+
function createEmailCoordinator(options) {
|
|
9
|
+
const { queryWithContext } = options;
|
|
10
|
+
return {
|
|
11
|
+
getStatus: async () => {
|
|
12
|
+
const result = await queryWithContext('email.getStatus', (0, email_2.buildGetEmailIq)());
|
|
13
|
+
(0, query_1.assertIqResult)(result, 'email.getStatus');
|
|
14
|
+
return parseEmailStatus(result);
|
|
15
|
+
},
|
|
16
|
+
setEmail: async (email, context) => {
|
|
17
|
+
const result = await queryWithContext('email.set', (0, email_2.buildSetEmailIq)(email, context), undefined, context !== undefined ? { context } : {});
|
|
18
|
+
(0, query_1.assertIqResult)(result, 'email.set');
|
|
19
|
+
return parseEmailStatus(result);
|
|
20
|
+
},
|
|
21
|
+
requestVerificationCode: async (input) => {
|
|
22
|
+
const result = await queryWithContext('email.requestCode', (0, email_2.buildRequestEmailVerificationCodeIq)(input), undefined, { languageCode: input.languageCode, localeCode: input.localeCode });
|
|
23
|
+
(0, query_1.assertIqResult)(result, 'email.requestCode');
|
|
24
|
+
},
|
|
25
|
+
verifyCode: async (code) => {
|
|
26
|
+
const result = await queryWithContext('email.verifyCode', (0, email_2.buildVerifyEmailCodeIq)(code));
|
|
27
|
+
(0, query_1.assertIqResult)(result, 'email.verifyCode');
|
|
28
|
+
return parseVerifyCodeResult(result);
|
|
29
|
+
},
|
|
30
|
+
confirm: async (context) => {
|
|
31
|
+
const result = await queryWithContext('email.confirm', (0, email_2.buildConfirmEmailIq)(context), undefined, context !== undefined ? { context } : {});
|
|
32
|
+
(0, query_1.assertIqResult)(result, 'email.confirm');
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function parseEmailStatus(result) {
|
|
37
|
+
const emailNode = (0, helpers_1.findNodeChild)(result, email_1.WA_EMAIL_TAGS.EMAIL);
|
|
38
|
+
if (!emailNode) {
|
|
39
|
+
return { email: null, verified: false, confirmed: false };
|
|
40
|
+
}
|
|
41
|
+
const verifiedAttr = emailNode.attrs.verified;
|
|
42
|
+
const addressNode = (0, helpers_1.findNodeChild)(emailNode, email_1.WA_EMAIL_TAGS.EMAIL_ADDRESS);
|
|
43
|
+
const confirmedNode = (0, helpers_1.findNodeChild)(emailNode, email_1.WA_EMAIL_TAGS.CONFIRMED);
|
|
44
|
+
return {
|
|
45
|
+
email: addressNode ? ((0, helpers_1.getNodeTextContent)(addressNode) ?? null) : null,
|
|
46
|
+
verified: verifiedAttr === 'true',
|
|
47
|
+
confirmed: confirmedNode ? (0, helpers_1.getNodeTextContent)(confirmedNode) === 'true' : false
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function parseVerifyCodeResult(result) {
|
|
51
|
+
const emailNode = (0, helpers_1.findNodeChild)(result, email_1.WA_EMAIL_TAGS.EMAIL);
|
|
52
|
+
if (!emailNode) {
|
|
53
|
+
return { verified: false, autoVerifyFailed: false, email: null };
|
|
54
|
+
}
|
|
55
|
+
const doVerify = emailNode.attrs.do_verify;
|
|
56
|
+
const autoVerifyNode = (0, helpers_1.findNodeChild)(emailNode, email_1.WA_EMAIL_TAGS.AUTO_VERIFY);
|
|
57
|
+
const addressNode = (0, helpers_1.findNodeChild)(emailNode, email_1.WA_EMAIL_TAGS.EMAIL_ADDRESS);
|
|
58
|
+
return {
|
|
59
|
+
verified: doVerify === 'true',
|
|
60
|
+
autoVerifyFailed: autoVerifyNode ? (0, helpers_1.getNodeTextContent)(autoVerifyNode) === 'fail' : false,
|
|
61
|
+
email: addressNode ? ((0, helpers_1.getNodeTextContent)(addressNode) ?? null) : null
|
|
62
|
+
};
|
|
63
|
+
}
|