shellzapy 0.1.0__py3-none-any.whl
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.
- shellzapy-0.1.0.dist-info/METADATA +112 -0
- shellzapy-0.1.0.dist-info/RECORD +345 -0
- shellzapy-0.1.0.dist-info/WHEEL +4 -0
- shellzapy-0.1.0.dist-info/licenses/LICENSE +21 -0
- shellzapy-0.1.0.dist-info/licenses/NOTICE +9 -0
- zapy/__init__.py +58 -0
- zapy/_appstate/__init__.py +59 -0
- zapy/_appstate/constants.py +82 -0
- zapy/_appstate/crypto/__init__.py +17 -0
- zapy/_appstate/crypto/app_state_crypto.py +401 -0
- zapy/_appstate/parsers/__init__.py +23 -0
- zapy/_appstate/parsers/encoding.py +157 -0
- zapy/_appstate/parsers/response_parser.py +135 -0
- zapy/_appstate/sync/__init__.py +11 -0
- zapy/_appstate/sync/sync_client.py +1559 -0
- zapy/_appstate/types.py +137 -0
- zapy/_appstate/utils.py +100 -0
- zapy/_auth/__init__.py +3 -0
- zapy/_auth/auth_client.py +618 -0
- zapy/_auth/credentials_flow.py +290 -0
- zapy/_auth/pairing/__init__.py +3 -0
- zapy/_auth/pairing/companion_host.py +239 -0
- zapy/_auth/pairing/flow.py +808 -0
- zapy/_auth/pairing/pairing_code_crypto.py +143 -0
- zapy/_auth/pairing/qr_flow.py +123 -0
- zapy/_auth/pairing/shortcake_crypto.py +122 -0
- zapy/_auth/pairing/shortcake_flow.py +393 -0
- zapy/_auth/types.py +110 -0
- zapy/_client/__init__.py +26 -0
- zapy/_client/client.py +972 -0
- zapy/_client/connection/__init__.py +6 -0
- zapy/_client/connection/manager.py +525 -0
- zapy/_client/connection/receipt_queue.py +74 -0
- zapy/_client/coordinators/__init__.py +81 -0
- zapy/_client/coordinators/ab_props.py +260 -0
- zapy/_client/coordinators/app_state_mutation.py +2538 -0
- zapy/_client/coordinators/bot.py +830 -0
- zapy/_client/coordinators/broadcast_list.py +101 -0
- zapy/_client/coordinators/business.py +247 -0
- zapy/_client/coordinators/email.py +158 -0
- zapy/_client/coordinators/group.py +1478 -0
- zapy/_client/coordinators/incoming_node.py +758 -0
- zapy/_client/coordinators/low_level.py +119 -0
- zapy/_client/coordinators/message.py +1153 -0
- zapy/_client/coordinators/message_dispatch.py +1637 -0
- zapy/_client/coordinators/newsletter.py +110 -0
- zapy/_client/coordinators/offline_resume.py +271 -0
- zapy/_client/coordinators/passive_tasks.py +447 -0
- zapy/_client/coordinators/presence.py +103 -0
- zapy/_client/coordinators/privacy.py +623 -0
- zapy/_client/coordinators/profile.py +1024 -0
- zapy/_client/coordinators/retry.py +1878 -0
- zapy/_client/coordinators/status.py +132 -0
- zapy/_client/coordinators/stream_control.py +260 -0
- zapy/_client/coordinators/trusted_contact_token.py +417 -0
- zapy/_client/events/__init__.py +266 -0
- zapy/_client/events/abprops.py +58 -0
- zapy/_client/events/appstate_mutation.py +248 -0
- zapy/_client/events/business.py +565 -0
- zapy/_client/events/call.py +144 -0
- zapy/_client/events/chatstate.py +41 -0
- zapy/_client/events/devices.py +122 -0
- zapy/_client/events/dirty.py +384 -0
- zapy/_client/events/group.py +655 -0
- zapy/_client/events/identity.py +40 -0
- zapy/_client/events/incoming.py +1079 -0
- zapy/_client/events/mex_notification.py +317 -0
- zapy/_client/events/offline.py +123 -0
- zapy/_client/events/picture.py +67 -0
- zapy/_client/events/presence.py +74 -0
- zapy/_client/events/privacy.py +187 -0
- zapy/_client/events/privacy_token.py +72 -0
- zapy/_client/events/receipt.py +109 -0
- zapy/_client/events/registration.py +70 -0
- zapy/_client/events/username.py +76 -0
- zapy/_client/factory.py +2020 -0
- zapy/_client/media.py +829 -0
- zapy/_client/newsletter/__init__.py +90 -0
- zapy/_client/newsletter/admin.py +323 -0
- zapy/_client/newsletter/content.py +499 -0
- zapy/_client/newsletter/discovery.py +233 -0
- zapy/_client/newsletter/messaging.py +396 -0
- zapy/_client/newsletter/mex.py +99 -0
- zapy/_client/newsletter/parse.py +406 -0
- zapy/_client/newsletter/types.py +393 -0
- zapy/_client/persistence/__init__.py +89 -0
- zapy/_client/persistence/companion_host.py +133 -0
- zapy/_client/persistence/ephemeral_setting.py +245 -0
- zapy/_client/persistence/group_history.py +361 -0
- zapy/_client/persistence/history_blob.py +169 -0
- zapy/_client/persistence/history_sync.py +646 -0
- zapy/_client/persistence/mailbox.py +232 -0
- zapy/_client/persistence/write_behind_persistence.py +368 -0
- zapy/_client/plugins/__init__.py +23 -0
- zapy/_client/plugins/define.py +44 -0
- zapy/_client/plugins/install.py +254 -0
- zapy/_client/plugins/types.py +64 -0
- zapy/_client/tokens/__init__.py +21 -0
- zapy/_client/tokens/cs_token.py +47 -0
- zapy/_client/tokens/tc_token.py +43 -0
- zapy/_client/types.py +988 -0
- zapy/_crypto/__init__.py +65 -0
- zapy/_crypto/core/__init__.py +62 -0
- zapy/_crypto/core/hkdf.py +41 -0
- zapy/_crypto/core/keys.py +51 -0
- zapy/_crypto/core/nonce.py +25 -0
- zapy/_crypto/core/primitives.py +179 -0
- zapy/_crypto/core/random.py +32 -0
- zapy/_crypto/core/xeddsa.py +72 -0
- zapy/_crypto/curves/__init__.py +3 -0
- zapy/_crypto/curves/constants.py +10 -0
- zapy/_crypto/curves/ed25519.py +61 -0
- zapy/_crypto/curves/types.py +18 -0
- zapy/_crypto/curves/x25519.py +117 -0
- zapy/_crypto/math/__init__.py +3 -0
- zapy/_crypto/math/constants.py +35 -0
- zapy/_crypto/math/edwards.py +174 -0
- zapy/_crypto/math/fe.py +120 -0
- zapy/_crypto/math/le.py +13 -0
- zapy/_crypto/math/mod.py +15 -0
- zapy/_crypto/math/prime.py +11 -0
- zapy/_crypto/math/types.py +25 -0
- zapy/_crypto/native_backend.py +40 -0
- zapy/_infra/__init__.py +3 -0
- zapy/_infra/log.py +142 -0
- zapy/_infra/perf.py +77 -0
- zapy/_media/__init__.py +64 -0
- zapy/_media/constants.py +133 -0
- zapy/_media/container.py +110 -0
- zapy/_media/crypto/__init__.py +19 -0
- zapy/_media/crypto/crypto.py +633 -0
- zapy/_media/crypto/media_retry.py +107 -0
- zapy/_media/processor.py +100 -0
- zapy/_media/sticker/__init__.py +8 -0
- zapy/_media/sticker/pack.py +188 -0
- zapy/_media/transfer/__init__.py +15 -0
- zapy/_media/transfer/client.py +635 -0
- zapy/_media/transfer/conn.py +48 -0
- zapy/_media/types.py +169 -0
- zapy/_message/__init__.py +121 -0
- zapy/_message/addons/__init__.py +5 -0
- zapy/_message/addons/link_preview/__init__.py +54 -0
- zapy/_message/addons/link_preview/builder.py +56 -0
- zapy/_message/addons/link_preview/detect.py +72 -0
- zapy/_message/addons/link_preview/fetcher.py +553 -0
- zapy/_message/addons/link_preview/types.py +100 -0
- zapy/_message/client.py +486 -0
- zapy/_message/context_info.py +424 -0
- zapy/_message/crypto/__init__.py +71 -0
- zapy/_message/crypto/addon_crypto.py +656 -0
- zapy/_message/crypto/icdc.py +138 -0
- zapy/_message/crypto/phash.py +87 -0
- zapy/_message/crypto/reporting_token.py +498 -0
- zapy/_message/crypto/use_case_secret.py +113 -0
- zapy/_message/encode/__init__.py +84 -0
- zapy/_message/encode/content.py +636 -0
- zapy/_message/encode/device_sent.py +88 -0
- zapy/_message/encode/media_payload.py +122 -0
- zapy/_message/encode/padding.py +27 -0
- zapy/_message/kinds/__init__.py +1 -0
- zapy/_message/kinds/bot.py +179 -0
- zapy/_message/kinds/group_history.py +206 -0
- zapy/_message/kinds/newsletter.py +388 -0
- zapy/_message/kinds/sticker_pack.py +74 -0
- zapy/_message/messaging/__init__.py +336 -0
- zapy/_message/messaging/companion_host.py +117 -0
- zapy/_message/messaging/fanout.py +311 -0
- zapy/_message/messaging/group_metadata.py +444 -0
- zapy/_message/messaging/ignore_key.py +264 -0
- zapy/_message/messaging/key_protocol.py +217 -0
- zapy/_message/messaging/link_preview.py +448 -0
- zapy/_message/messaging/messages.py +1429 -0
- zapy/_message/primitives/__init__.py +1 -0
- zapy/_message/primitives/ack.py +232 -0
- zapy/_message/primitives/incoming.py +1141 -0
- zapy/_message/primitives/media_retry.py +451 -0
- zapy/_message/primitives/peer_data_operation.py +271 -0
- zapy/_message/types.py +434 -0
- zapy/_proto/WAProto_pb2.py +2584 -0
- zapy/_proto/__init__.py +1 -0
- zapy/_protocol/__init__.py +3 -0
- zapy/_protocol/abprops_spec.py +6216 -0
- zapy/_protocol/auth.py +17 -0
- zapy/_protocol/browser.py +57 -0
- zapy/_protocol/defaults.py +38 -0
- zapy/_protocol/device_identity.py +54 -0
- zapy/_protocol/jid.py +241 -0
- zapy/_protocol/message.py +127 -0
- zapy/_protocol/nodes.py +144 -0
- zapy/_protocol/notification.py +18 -0
- zapy/_retry/__init__.py +77 -0
- zapy/_retry/codec.py +209 -0
- zapy/_retry/constants.py +28 -0
- zapy/_retry/parse.py +132 -0
- zapy/_retry/reason.py +65 -0
- zapy/_retry/replay.py +483 -0
- zapy/_retry/tracker.py +161 -0
- zapy/_retry/types.py +122 -0
- zapy/_signal/__init__.py +171 -0
- zapy/_signal/api/__init__.py +133 -0
- zapy/_signal/api/codec.py +164 -0
- zapy/_signal/api/constants.py +14 -0
- zapy/_signal/api/device_sync.py +915 -0
- zapy/_signal/api/digest_sync.py +363 -0
- zapy/_signal/api/identity_sync.py +250 -0
- zapy/_signal/api/missing_pre_keys_sync.py +267 -0
- zapy/_signal/api/prekeys.py +191 -0
- zapy/_signal/api/result_map.py +40 -0
- zapy/_signal/api/rotate_key.py +111 -0
- zapy/_signal/api/session_sync.py +297 -0
- zapy/_signal/attestation.py +145 -0
- zapy/_signal/constants.py +22 -0
- zapy/_signal/encoding.py +78 -0
- zapy/_signal/group/__init__.py +35 -0
- zapy/_signal/group/chain.py +139 -0
- zapy/_signal/group/codec.py +78 -0
- zapy/_signal/group/encoding.py +166 -0
- zapy/_signal/group/manager.py +361 -0
- zapy/_signal/registration/__init__.py +44 -0
- zapy/_signal/registration/keygen.py +46 -0
- zapy/_signal/registration/reg_encoding.py +66 -0
- zapy/_signal/registration/reg_utils.py +52 -0
- zapy/_signal/session/__init__.py +114 -0
- zapy/_signal/session/encoding.py +385 -0
- zapy/_signal/session/protocol.py +590 -0
- zapy/_signal/session/ratchet.py +381 -0
- zapy/_signal/session/resolver.py +630 -0
- zapy/_signal/session/serializer.py +96 -0
- zapy/_signal/session/session.py +272 -0
- zapy/_signal/types.py +214 -0
- zapy/_store/__init__.py +118 -0
- zapy/_store/cache/__init__.py +166 -0
- zapy/_store/cache/identity.py +130 -0
- zapy/_store/cache/privacy_token.py +116 -0
- zapy/_store/cache/sender_key.py +168 -0
- zapy/_store/cache/session.py +142 -0
- zapy/_store/contracts/__init__.py +84 -0
- zapy/_store/contracts/appstate.py +82 -0
- zapy/_store/contracts/auth.py +16 -0
- zapy/_store/contracts/chat_metadata.py +29 -0
- zapy/_store/contracts/contact.py +31 -0
- zapy/_store/contracts/device_list.py +35 -0
- zapy/_store/contracts/group_metadata.py +33 -0
- zapy/_store/contracts/identity.py +18 -0
- zapy/_store/contracts/message.py +36 -0
- zapy/_store/contracts/message_secret.py +41 -0
- zapy/_store/contracts/pre_key.py +32 -0
- zapy/_store/contracts/privacy_token.py +32 -0
- zapy/_store/contracts/retry.py +47 -0
- zapy/_store/contracts/sender_key.py +37 -0
- zapy/_store/contracts/session.py +21 -0
- zapy/_store/contracts/signal.py +23 -0
- zapy/_store/contracts/thread.py +35 -0
- zapy/_store/create_store.py +890 -0
- zapy/_store/locks.py +1154 -0
- zapy/_store/memory/__init__.py +40 -0
- zapy/_store/memory/appstate.py +200 -0
- zapy/_store/memory/auth.py +24 -0
- zapy/_store/memory/chat_metadata.py +124 -0
- zapy/_store/memory/contact.py +125 -0
- zapy/_store/memory/device_list.py +161 -0
- zapy/_store/memory/group_metadata.py +125 -0
- zapy/_store/memory/identity.py +86 -0
- zapy/_store/memory/message.py +85 -0
- zapy/_store/memory/message_secret.py +145 -0
- zapy/_store/memory/pre_key.py +112 -0
- zapy/_store/memory/privacy_token.py +103 -0
- zapy/_store/memory/retry.py +250 -0
- zapy/_store/memory/sender_key.py +162 -0
- zapy/_store/memory/session.py +111 -0
- zapy/_store/memory/signal.py +45 -0
- zapy/_store/memory/thread.py +66 -0
- zapy/_store/noop.py +279 -0
- zapy/_transport/__init__.py +3 -0
- zapy/_transport/binary/__init__.py +77 -0
- zapy/_transport/binary/constants.py +80 -0
- zapy/_transport/binary/decoder.py +260 -0
- zapy/_transport/binary/encoder.py +279 -0
- zapy/_transport/binary/tokens.py +1289 -0
- zapy/_transport/comms.py +759 -0
- zapy/_transport/keepalive/__init__.py +3 -0
- zapy/_transport/keepalive/keep_alive.py +252 -0
- zapy/_transport/node/__init__.py +3 -0
- zapy/_transport/node/builders/__init__.py +9 -0
- zapy/_transport/node/builders/abprops.py +33 -0
- zapy/_transport/node/builders/account_sync.py +120 -0
- zapy/_transport/node/builders/bot.py +56 -0
- zapy/_transport/node/builders/business.py +261 -0
- zapy/_transport/node/builders/chatstate.py +74 -0
- zapy/_transport/node/builders/community.py +116 -0
- zapy/_transport/node/builders/device.py +30 -0
- zapy/_transport/node/builders/email.py +181 -0
- zapy/_transport/node/builders/global_.py +74 -0
- zapy/_transport/node/builders/group.py +279 -0
- zapy/_transport/node/builders/media.py +21 -0
- zapy/_transport/node/builders/message.py +436 -0
- zapy/_transport/node/builders/mobile.py +227 -0
- zapy/_transport/node/builders/newsletter.py +293 -0
- zapy/_transport/node/builders/offline.py +20 -0
- zapy/_transport/node/builders/pairing.py +130 -0
- zapy/_transport/node/builders/passive.py +28 -0
- zapy/_transport/node/builders/prekeys.py +215 -0
- zapy/_transport/node/builders/presence.py +100 -0
- zapy/_transport/node/builders/privacy.py +243 -0
- zapy/_transport/node/builders/privacy_token.py +94 -0
- zapy/_transport/node/builders/profile.py +176 -0
- zapy/_transport/node/builders/retry.py +156 -0
- zapy/_transport/node/builders/shortcake.py +87 -0
- zapy/_transport/node/builders/tos.py +92 -0
- zapy/_transport/node/builders/usync.py +185 -0
- zapy/_transport/node/helpers.py +201 -0
- zapy/_transport/node/orchestrator.py +210 -0
- zapy/_transport/node/query.py +82 -0
- zapy/_transport/node/transport.py +105 -0
- zapy/_transport/node/usync.py +33 -0
- zapy/_transport/node/xml.py +38 -0
- zapy/_transport/noise/__init__.py +7 -0
- zapy/_transport/noise/cert.py +85 -0
- zapy/_transport/noise/client_payload.py +344 -0
- zapy/_transport/noise/constants.py +12 -0
- zapy/_transport/noise/frame_codec.py +120 -0
- zapy/_transport/noise/handshake.py +92 -0
- zapy/_transport/noise/session.py +493 -0
- zapy/_transport/noise/socket.py +45 -0
- zapy/_transport/noise/types.py +66 -0
- zapy/_transport/noise/version.json +3 -0
- zapy/_transport/proxy.py +35 -0
- zapy/_transport/types.py +19 -0
- zapy/_transport/wa_version_fetcher.py +159 -0
- zapy/_transport/web_socket.py +602 -0
- zapy/_util/__init__.py +3 -0
- zapy/_util/bytes.py +131 -0
- zapy/_util/coercion.py +29 -0
- zapy/_util/collections.py +45 -0
- zapy/_util/primitives.py +49 -0
- zapy/client.py +840 -0
- zapy/errors.py +148 -0
- zapy/events.py +564 -0
- zapy/jid.py +140 -0
- zapy/py.typed +0 -0
- zapy/stores/__init__.py +50 -0
- zapy/stores/base.py +1627 -0
- zapy/stores/json_file.py +359 -0
- zapy/stores/memory.py +322 -0
- zapy/stores/sqlite.py +343 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Broadcast-list coordinator (mirrors ``WaBroadcastListCoordinator``).
|
|
2
|
+
|
|
3
|
+
Business-only: lists are backed by the ``BusinessBroadcastList`` app-state
|
|
4
|
+
schema; the server rejects the mutation IQs on regular accounts.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import copy
|
|
10
|
+
from collections.abc import Awaitable, Callable, Mapping
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from typing import Any, Protocol
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class WaAppStateMutationsLike(Protocol):
|
|
16
|
+
"""App-state mutation surface used by broadcast lists and status."""
|
|
17
|
+
|
|
18
|
+
async def set_broadcast_list(self, input: object) -> None: ...
|
|
19
|
+
async def remove_broadcast_list(self, id: str) -> None: ...
|
|
20
|
+
async def set_status_privacy(self, input: object) -> None: ...
|
|
21
|
+
async def set_user_status_mute(self, jid: str, muted: bool) -> None: ...
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class WaMessageBuildResultLike(Protocol):
|
|
25
|
+
"""Message build output: proto payload plus optional media upload."""
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def message(self) -> object: ...
|
|
29
|
+
@property
|
|
30
|
+
def upload(self) -> object: ...
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass(frozen=True, slots=True)
|
|
34
|
+
class WaSendBroadcastListMessageInput:
|
|
35
|
+
"""Broadcast send: list JID, content, recipients, and send options."""
|
|
36
|
+
|
|
37
|
+
list_jid: str = ""
|
|
38
|
+
content: object = None
|
|
39
|
+
recipients: tuple[str, ...] = ()
|
|
40
|
+
options: object = None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class WaBroadcastListCoordinator(Protocol):
|
|
44
|
+
"""Broadcast-list surface: define/remove lists and send into one."""
|
|
45
|
+
|
|
46
|
+
async def set_list(self, input: object) -> None: ...
|
|
47
|
+
async def remove_list(self, id: str) -> None: ...
|
|
48
|
+
async def send(self, input: WaSendBroadcastListMessageInput) -> object: ...
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def create_broadcast_list_coordinator(
|
|
52
|
+
*,
|
|
53
|
+
app_state_mutations: WaAppStateMutationsLike,
|
|
54
|
+
build_message_content: Callable[[object], Awaitable[Any]],
|
|
55
|
+
publish_broadcast_list_message: Callable[..., Awaitable[Any]],
|
|
56
|
+
) -> WaBroadcastListCoordinator:
|
|
57
|
+
"""Build a broadcast-list coordinator from its dependencies."""
|
|
58
|
+
|
|
59
|
+
class _Coordinator:
|
|
60
|
+
async def set_list(self, input: object) -> None:
|
|
61
|
+
await app_state_mutations.set_broadcast_list(input)
|
|
62
|
+
|
|
63
|
+
async def remove_list(self, id: str) -> None:
|
|
64
|
+
await app_state_mutations.remove_broadcast_list(id)
|
|
65
|
+
|
|
66
|
+
async def send(self, input: WaSendBroadcastListMessageInput) -> object:
|
|
67
|
+
built = await build_message_content(input.content)
|
|
68
|
+
if isinstance(built, Mapping):
|
|
69
|
+
message = built["message"]
|
|
70
|
+
upload = built.get("upload")
|
|
71
|
+
else:
|
|
72
|
+
message = built.message
|
|
73
|
+
upload = getattr(built, "upload", None)
|
|
74
|
+
published = await publish_broadcast_list_message(
|
|
75
|
+
list_jid=input.list_jid,
|
|
76
|
+
message=message,
|
|
77
|
+
recipients=input.recipients,
|
|
78
|
+
options=input.options,
|
|
79
|
+
)
|
|
80
|
+
if upload is None:
|
|
81
|
+
return published
|
|
82
|
+
return _with_upload(published, upload)
|
|
83
|
+
|
|
84
|
+
return _Coordinator()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _with_upload(published: Any, upload: Any) -> Any:
|
|
88
|
+
"""Spread-merge ``upload`` into a publish result (mirrors ``{...}``)."""
|
|
89
|
+
if isinstance(published, Mapping):
|
|
90
|
+
return {**published, "upload": upload}
|
|
91
|
+
merged = copy.copy(published)
|
|
92
|
+
merged.upload = upload
|
|
93
|
+
return merged
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
__all__ = [
|
|
97
|
+
"WaBroadcastListCoordinator",
|
|
98
|
+
"WaMessageBuildResultLike",
|
|
99
|
+
"WaSendBroadcastListMessageInput",
|
|
100
|
+
"create_broadcast_list_coordinator",
|
|
101
|
+
]
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"""Business coordinator (mirrors ``WaBusinessCoordinator``).
|
|
2
|
+
|
|
3
|
+
Reads/writes WhatsApp Business profiles, verified names, and cover photos.
|
|
4
|
+
Reads work from any account; writes are business-only and the server rejects
|
|
5
|
+
them on regular accounts.
|
|
6
|
+
|
|
7
|
+
DEVIATION: the business-profile/verified-name event parsers
|
|
8
|
+
(``src/client/events/business.ts``), the plaintext media upload helpers
|
|
9
|
+
(``src/client/media.ts``), and the usync log plumbing live in sibling layers
|
|
10
|
+
that arrive as injected callables
|
|
11
|
+
(``parse_business_profile``, ``parse_verified_name``,
|
|
12
|
+
``upload_cover_photo_bytes``) so this module stays decoupled until those
|
|
13
|
+
layers land; the IQ shapes already match the canonical ones.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from collections.abc import Awaitable, Callable, Mapping, Sequence
|
|
19
|
+
from dataclasses import dataclass
|
|
20
|
+
from typing import Any, Protocol
|
|
21
|
+
|
|
22
|
+
from zapy._infra.log import Logger
|
|
23
|
+
from zapy._transport.node.builders.business import (
|
|
24
|
+
BuildCoverPhotoDeleteInput,
|
|
25
|
+
BuildCoverPhotoUpdateInput,
|
|
26
|
+
WaEditBusinessProfileInput,
|
|
27
|
+
build_cover_photo_iq,
|
|
28
|
+
build_edit_business_profile_iq,
|
|
29
|
+
build_get_business_profile_iq,
|
|
30
|
+
build_get_business_usync_query_node,
|
|
31
|
+
build_get_verified_name_iq,
|
|
32
|
+
)
|
|
33
|
+
from zapy._transport.node.builders.usync import (
|
|
34
|
+
BuildUsyncIqInput,
|
|
35
|
+
BuildUsyncUserNodeInput,
|
|
36
|
+
build_usync_iq,
|
|
37
|
+
iterate_usync_users,
|
|
38
|
+
log_usync_protocol_errors,
|
|
39
|
+
parse_usync_result_envelope,
|
|
40
|
+
)
|
|
41
|
+
from zapy._transport.node.helpers import find_node_child, get_node_children
|
|
42
|
+
from zapy._transport.node.query import assert_iq_result
|
|
43
|
+
from zapy._transport.types import BinaryNode
|
|
44
|
+
|
|
45
|
+
# Verbatim ``src/protocol/notification.ts`` (business tags).
|
|
46
|
+
BUSINESS_PROFILE_TAG: str = "business_profile"
|
|
47
|
+
VERIFIED_NAME_TAG: str = "verified_name"
|
|
48
|
+
ERROR_TAG: str = "error"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass(frozen=True, slots=True)
|
|
52
|
+
class WaVerifiedNameBatchEntry:
|
|
53
|
+
"""One verified-name lookup result: JID plus record (or ``None``)."""
|
|
54
|
+
|
|
55
|
+
jid: str = ""
|
|
56
|
+
verified_name: object = None
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class WaBusinessCoordinator(Protocol):
|
|
60
|
+
"""Business-profile surface: reads, edits, and cover photos."""
|
|
61
|
+
|
|
62
|
+
async def get_business_profile(
|
|
63
|
+
self, jids: Sequence[str]
|
|
64
|
+
) -> Sequence[Mapping[str, Any]]: ...
|
|
65
|
+
async def edit_business_profile(
|
|
66
|
+
self, input: WaEditBusinessProfileInput
|
|
67
|
+
) -> None: ...
|
|
68
|
+
async def get_verified_name(self, jid: str) -> Mapping[str, Any] | None: ...
|
|
69
|
+
async def get_verified_names(
|
|
70
|
+
self, jids: Sequence[str]
|
|
71
|
+
) -> Sequence[WaVerifiedNameBatchEntry]: ...
|
|
72
|
+
async def update_cover_photo(self, media: bytes) -> Mapping[str, str]: ...
|
|
73
|
+
async def delete_cover_photo(self, id: str) -> None: ...
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _parse_business_profiles(
|
|
77
|
+
result: BinaryNode,
|
|
78
|
+
parse_business_profile: Callable[[BinaryNode], Mapping[str, Any] | None],
|
|
79
|
+
) -> list[Mapping[str, Any]]:
|
|
80
|
+
biz_node = find_node_child(result, BUSINESS_PROFILE_TAG)
|
|
81
|
+
if biz_node is None:
|
|
82
|
+
return []
|
|
83
|
+
out: list[Mapping[str, Any]] = []
|
|
84
|
+
for profile_node in get_node_children(biz_node):
|
|
85
|
+
parsed = parse_business_profile(profile_node)
|
|
86
|
+
if parsed is not None:
|
|
87
|
+
out.append(parsed)
|
|
88
|
+
return out
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _parse_verified_name(
|
|
92
|
+
result: BinaryNode,
|
|
93
|
+
parse_verified_name_node: Callable[[BinaryNode], Mapping[str, Any] | None],
|
|
94
|
+
) -> Mapping[str, Any] | None:
|
|
95
|
+
vn_node = find_node_child(result, VERIFIED_NAME_TAG)
|
|
96
|
+
if vn_node is None:
|
|
97
|
+
return None
|
|
98
|
+
return parse_verified_name_node(vn_node)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _parse_usync_verified_names(
|
|
102
|
+
result: BinaryNode,
|
|
103
|
+
parse_verified_name_node: Callable[[BinaryNode], Mapping[str, Any] | None],
|
|
104
|
+
) -> list[WaVerifiedNameBatchEntry]:
|
|
105
|
+
user_nodes = iterate_usync_users(result) or []
|
|
106
|
+
out: list[WaVerifiedNameBatchEntry] = []
|
|
107
|
+
for user_node in user_nodes:
|
|
108
|
+
jid = user_node.attrs.get("jid")
|
|
109
|
+
if not jid:
|
|
110
|
+
continue
|
|
111
|
+
business_node = find_node_child(user_node, "business")
|
|
112
|
+
error_node = (
|
|
113
|
+
find_node_child(business_node, ERROR_TAG)
|
|
114
|
+
if business_node is not None
|
|
115
|
+
else None
|
|
116
|
+
)
|
|
117
|
+
vn_node = (
|
|
118
|
+
find_node_child(business_node, VERIFIED_NAME_TAG)
|
|
119
|
+
if business_node is not None and error_node is None
|
|
120
|
+
else None
|
|
121
|
+
)
|
|
122
|
+
out.append(
|
|
123
|
+
WaVerifiedNameBatchEntry(
|
|
124
|
+
jid=jid,
|
|
125
|
+
verified_name=(
|
|
126
|
+
parse_verified_name_node(vn_node) if vn_node is not None else None
|
|
127
|
+
),
|
|
128
|
+
)
|
|
129
|
+
)
|
|
130
|
+
return out
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def create_business_coordinator(
|
|
134
|
+
*,
|
|
135
|
+
query_with_context: Callable[..., Awaitable[BinaryNode]],
|
|
136
|
+
get_media_conn: Callable[[], Awaitable[object]],
|
|
137
|
+
logger: Logger,
|
|
138
|
+
generate_sid: Callable[[], Awaitable[str]],
|
|
139
|
+
parse_business_profile: Callable[[BinaryNode], Mapping[str, Any] | None],
|
|
140
|
+
parse_verified_name_node: Callable[[BinaryNode], Mapping[str, Any] | None],
|
|
141
|
+
upload_cover_photo_bytes: Callable[[bytes, object], Awaitable[Mapping[str, Any]]],
|
|
142
|
+
) -> WaBusinessCoordinator:
|
|
143
|
+
"""Build a business coordinator from its IQ/media dependencies."""
|
|
144
|
+
|
|
145
|
+
class _Coordinator:
|
|
146
|
+
async def get_business_profile(
|
|
147
|
+
self, jids: Sequence[str]
|
|
148
|
+
) -> Sequence[Mapping[str, Any]]:
|
|
149
|
+
if len(jids) == 0:
|
|
150
|
+
return []
|
|
151
|
+
node = build_get_business_profile_iq(list(jids))
|
|
152
|
+
result = await query_with_context(
|
|
153
|
+
"business.getProfile", node, None, {"count": len(jids)}
|
|
154
|
+
)
|
|
155
|
+
assert_iq_result(result, "business.getProfile")
|
|
156
|
+
return _parse_business_profiles(result, parse_business_profile)
|
|
157
|
+
|
|
158
|
+
async def edit_business_profile(
|
|
159
|
+
self, input: WaEditBusinessProfileInput
|
|
160
|
+
) -> None:
|
|
161
|
+
node = build_edit_business_profile_iq(input)
|
|
162
|
+
result = await query_with_context("business.editProfile", node)
|
|
163
|
+
assert_iq_result(result, "business.editProfile")
|
|
164
|
+
|
|
165
|
+
async def get_verified_name(self, jid: str) -> Mapping[str, Any] | None:
|
|
166
|
+
node = build_get_verified_name_iq(jid)
|
|
167
|
+
result = await query_with_context(
|
|
168
|
+
"business.getVerifiedName", node, None, {"jid": jid}
|
|
169
|
+
)
|
|
170
|
+
assert_iq_result(result, "business.getVerifiedName")
|
|
171
|
+
return _parse_verified_name(result, parse_verified_name_node)
|
|
172
|
+
|
|
173
|
+
async def get_verified_names(
|
|
174
|
+
self, jids: Sequence[str]
|
|
175
|
+
) -> Sequence[WaVerifiedNameBatchEntry]:
|
|
176
|
+
if len(jids) == 0:
|
|
177
|
+
return []
|
|
178
|
+
sid = await generate_sid()
|
|
179
|
+
usync_node = build_usync_iq(
|
|
180
|
+
BuildUsyncIqInput(
|
|
181
|
+
sid=sid,
|
|
182
|
+
query_protocol_nodes=(build_get_business_usync_query_node(),),
|
|
183
|
+
users=tuple(BuildUsyncUserNodeInput(jid=jid) for jid in jids),
|
|
184
|
+
)
|
|
185
|
+
)
|
|
186
|
+
result = await query_with_context(
|
|
187
|
+
"business.getVerifiedNames", usync_node, None, {"count": len(jids)}
|
|
188
|
+
)
|
|
189
|
+
assert_iq_result(result, "business.getVerifiedNames")
|
|
190
|
+
log_usync_protocol_errors(
|
|
191
|
+
parse_usync_result_envelope(result), logger, "business.getVerifiedNames"
|
|
192
|
+
)
|
|
193
|
+
return _parse_usync_verified_names(result, parse_verified_name_node)
|
|
194
|
+
|
|
195
|
+
async def update_cover_photo(self, media: bytes) -> Mapping[str, str]:
|
|
196
|
+
media_conn = await get_media_conn()
|
|
197
|
+
upload = await upload_cover_photo_bytes(bytes(media), media_conn)
|
|
198
|
+
status = upload.get("status")
|
|
199
|
+
response_bytes = upload.get("response_bytes")
|
|
200
|
+
if status != "ok" or not isinstance(response_bytes, (bytes, bytearray)):
|
|
201
|
+
raise ValueError("business cover photo upload failed")
|
|
202
|
+
parsed = _parse_upload_response_json(bytes(response_bytes))
|
|
203
|
+
fbid = parsed.get("fbid")
|
|
204
|
+
ts = parsed.get("ts")
|
|
205
|
+
token = parsed.get("meta_hmac")
|
|
206
|
+
if not fbid or not ts or not token:
|
|
207
|
+
raise ValueError(
|
|
208
|
+
"business cover photo upload response missing fbid/ts/meta_hmac"
|
|
209
|
+
)
|
|
210
|
+
node = build_cover_photo_iq(
|
|
211
|
+
BuildCoverPhotoUpdateInput(
|
|
212
|
+
id=str(fbid), timestamp=str(ts), token=str(token)
|
|
213
|
+
)
|
|
214
|
+
)
|
|
215
|
+
result = await query_with_context(
|
|
216
|
+
"business.updateCoverPhoto", node, None, {"id": str(fbid)}
|
|
217
|
+
)
|
|
218
|
+
assert_iq_result(result, "business.updateCoverPhoto")
|
|
219
|
+
return {"id": str(fbid)}
|
|
220
|
+
|
|
221
|
+
async def delete_cover_photo(self, id: str) -> None:
|
|
222
|
+
node = build_cover_photo_iq(BuildCoverPhotoDeleteInput(id=id))
|
|
223
|
+
result = await query_with_context(
|
|
224
|
+
"business.deleteCoverPhoto", node, None, {"id": id}
|
|
225
|
+
)
|
|
226
|
+
assert_iq_result(result, "business.deleteCoverPhoto")
|
|
227
|
+
|
|
228
|
+
return _Coordinator()
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def _parse_upload_response_json(response_bytes: bytes) -> Mapping[str, Any]:
|
|
232
|
+
import json
|
|
233
|
+
|
|
234
|
+
try:
|
|
235
|
+
parsed = json.loads(response_bytes.decode("utf-8"))
|
|
236
|
+
except (ValueError, UnicodeDecodeError) as error:
|
|
237
|
+
raise ValueError("business cover photo upload response is not JSON") from error
|
|
238
|
+
if not isinstance(parsed, dict):
|
|
239
|
+
raise ValueError("business cover photo upload response is not an object")
|
|
240
|
+
return parsed
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
__all__ = [
|
|
244
|
+
"WaBusinessCoordinator",
|
|
245
|
+
"WaVerifiedNameBatchEntry",
|
|
246
|
+
"create_business_coordinator",
|
|
247
|
+
]
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""Email coordinator (mirrors ``WaEmailCoordinator``).
|
|
2
|
+
|
|
3
|
+
Coordinates the email-on-account flow: read state, bind/unbind, request a
|
|
4
|
+
verification code, submit it, and confirm. Mobile-only: every method throws
|
|
5
|
+
against a regular Web/companion connection because the server rejects the IQ.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from collections.abc import Awaitable, Callable
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from typing import Protocol
|
|
13
|
+
|
|
14
|
+
from zapy._transport.node.builders.email import (
|
|
15
|
+
WA_EMAIL_TAGS,
|
|
16
|
+
BuildRequestEmailVerificationCodeInput,
|
|
17
|
+
build_confirm_email_iq,
|
|
18
|
+
build_get_email_iq,
|
|
19
|
+
build_request_email_verification_code_iq,
|
|
20
|
+
build_set_email_iq,
|
|
21
|
+
build_verify_email_code_iq,
|
|
22
|
+
)
|
|
23
|
+
from zapy._transport.node.helpers import find_node_child, get_node_text_content
|
|
24
|
+
from zapy._transport.node.query import assert_iq_result
|
|
25
|
+
from zapy._transport.types import BinaryNode
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True, slots=True)
|
|
29
|
+
class WaEmailStatus:
|
|
30
|
+
"""Bound email address plus verified/confirmed flags."""
|
|
31
|
+
|
|
32
|
+
email: str | None = None
|
|
33
|
+
verified: bool = False
|
|
34
|
+
confirmed: bool = False
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass(frozen=True, slots=True)
|
|
38
|
+
class WaEmailVerifyCodeResult:
|
|
39
|
+
"""Verification-code outcome: verified flag plus failure details."""
|
|
40
|
+
|
|
41
|
+
verified: bool = False
|
|
42
|
+
auto_verify_failed: bool = False
|
|
43
|
+
email: str | None = None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class WaEmailCoordinator(Protocol):
|
|
47
|
+
"""Email-on-account flow: status, bind, code request, verify, confirm."""
|
|
48
|
+
|
|
49
|
+
async def get_status(self) -> WaEmailStatus: ...
|
|
50
|
+
async def set_email(
|
|
51
|
+
self, email: str, context: str | None = None
|
|
52
|
+
) -> WaEmailStatus: ...
|
|
53
|
+
async def request_verification_code(
|
|
54
|
+
self, input: BuildRequestEmailVerificationCodeInput
|
|
55
|
+
) -> None: ...
|
|
56
|
+
async def verify_code(self, code: str) -> WaEmailVerifyCodeResult: ...
|
|
57
|
+
async def confirm(self, context: str | None = None) -> None: ...
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _parse_email_status(result: BinaryNode) -> WaEmailStatus:
|
|
61
|
+
email_node = find_node_child(result, WA_EMAIL_TAGS["EMAIL"])
|
|
62
|
+
if email_node is None:
|
|
63
|
+
return WaEmailStatus(email=None, verified=False, confirmed=False)
|
|
64
|
+
address_node = find_node_child(email_node, WA_EMAIL_TAGS["EMAIL_ADDRESS"])
|
|
65
|
+
confirmed_node = find_node_child(email_node, WA_EMAIL_TAGS["CONFIRMED"])
|
|
66
|
+
return WaEmailStatus(
|
|
67
|
+
email=get_node_text_content(address_node),
|
|
68
|
+
verified=email_node.attrs.get("verified") == "true",
|
|
69
|
+
confirmed=(
|
|
70
|
+
get_node_text_content(confirmed_node) == "true"
|
|
71
|
+
if confirmed_node is not None
|
|
72
|
+
else False
|
|
73
|
+
),
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _parse_verify_code_result(result: BinaryNode) -> WaEmailVerifyCodeResult:
|
|
78
|
+
email_node = find_node_child(result, WA_EMAIL_TAGS["EMAIL"])
|
|
79
|
+
if email_node is None:
|
|
80
|
+
return WaEmailVerifyCodeResult(
|
|
81
|
+
verified=False, auto_verify_failed=False, email=None
|
|
82
|
+
)
|
|
83
|
+
auto_verify_node = find_node_child(email_node, WA_EMAIL_TAGS["AUTO_VERIFY"])
|
|
84
|
+
address_node = find_node_child(email_node, WA_EMAIL_TAGS["EMAIL_ADDRESS"])
|
|
85
|
+
return WaEmailVerifyCodeResult(
|
|
86
|
+
verified=email_node.attrs.get("do_verify") == "true",
|
|
87
|
+
auto_verify_failed=(
|
|
88
|
+
get_node_text_content(auto_verify_node) == "fail"
|
|
89
|
+
if auto_verify_node is not None
|
|
90
|
+
else False
|
|
91
|
+
),
|
|
92
|
+
email=get_node_text_content(address_node),
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def create_email_coordinator(
|
|
97
|
+
*,
|
|
98
|
+
query_with_context: Callable[..., Awaitable[BinaryNode]],
|
|
99
|
+
) -> WaEmailCoordinator:
|
|
100
|
+
"""Build an email coordinator backed by the given IQ query function."""
|
|
101
|
+
|
|
102
|
+
class _Coordinator:
|
|
103
|
+
async def get_status(self) -> WaEmailStatus:
|
|
104
|
+
result = await query_with_context("email.getStatus", build_get_email_iq())
|
|
105
|
+
assert_iq_result(result, "email.getStatus")
|
|
106
|
+
return _parse_email_status(result)
|
|
107
|
+
|
|
108
|
+
async def set_email(
|
|
109
|
+
self, email: str, context: str | None = None
|
|
110
|
+
) -> WaEmailStatus:
|
|
111
|
+
result = await query_with_context(
|
|
112
|
+
"email.set",
|
|
113
|
+
build_set_email_iq(email, context),
|
|
114
|
+
None,
|
|
115
|
+
{"context": context} if context is not None else {},
|
|
116
|
+
)
|
|
117
|
+
assert_iq_result(result, "email.set")
|
|
118
|
+
return _parse_email_status(result)
|
|
119
|
+
|
|
120
|
+
async def request_verification_code(
|
|
121
|
+
self, input: BuildRequestEmailVerificationCodeInput
|
|
122
|
+
) -> None:
|
|
123
|
+
result = await query_with_context(
|
|
124
|
+
"email.requestCode",
|
|
125
|
+
build_request_email_verification_code_iq(input),
|
|
126
|
+
None,
|
|
127
|
+
{
|
|
128
|
+
"languageCode": input.language_code,
|
|
129
|
+
"localeCode": input.locale_code,
|
|
130
|
+
},
|
|
131
|
+
)
|
|
132
|
+
assert_iq_result(result, "email.requestCode")
|
|
133
|
+
|
|
134
|
+
async def verify_code(self, code: str) -> WaEmailVerifyCodeResult:
|
|
135
|
+
result = await query_with_context(
|
|
136
|
+
"email.verifyCode", build_verify_email_code_iq(code)
|
|
137
|
+
)
|
|
138
|
+
assert_iq_result(result, "email.verifyCode")
|
|
139
|
+
return _parse_verify_code_result(result)
|
|
140
|
+
|
|
141
|
+
async def confirm(self, context: str | None = None) -> None:
|
|
142
|
+
result = await query_with_context(
|
|
143
|
+
"email.confirm",
|
|
144
|
+
build_confirm_email_iq(context),
|
|
145
|
+
None,
|
|
146
|
+
{"context": context} if context is not None else {},
|
|
147
|
+
)
|
|
148
|
+
assert_iq_result(result, "email.confirm")
|
|
149
|
+
|
|
150
|
+
return _Coordinator()
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
__all__ = [
|
|
154
|
+
"WaEmailCoordinator",
|
|
155
|
+
"WaEmailStatus",
|
|
156
|
+
"WaEmailVerifyCodeResult",
|
|
157
|
+
"create_email_coordinator",
|
|
158
|
+
]
|