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.
Files changed (345) hide show
  1. shellzapy-0.1.0.dist-info/METADATA +112 -0
  2. shellzapy-0.1.0.dist-info/RECORD +345 -0
  3. shellzapy-0.1.0.dist-info/WHEEL +4 -0
  4. shellzapy-0.1.0.dist-info/licenses/LICENSE +21 -0
  5. shellzapy-0.1.0.dist-info/licenses/NOTICE +9 -0
  6. zapy/__init__.py +58 -0
  7. zapy/_appstate/__init__.py +59 -0
  8. zapy/_appstate/constants.py +82 -0
  9. zapy/_appstate/crypto/__init__.py +17 -0
  10. zapy/_appstate/crypto/app_state_crypto.py +401 -0
  11. zapy/_appstate/parsers/__init__.py +23 -0
  12. zapy/_appstate/parsers/encoding.py +157 -0
  13. zapy/_appstate/parsers/response_parser.py +135 -0
  14. zapy/_appstate/sync/__init__.py +11 -0
  15. zapy/_appstate/sync/sync_client.py +1559 -0
  16. zapy/_appstate/types.py +137 -0
  17. zapy/_appstate/utils.py +100 -0
  18. zapy/_auth/__init__.py +3 -0
  19. zapy/_auth/auth_client.py +618 -0
  20. zapy/_auth/credentials_flow.py +290 -0
  21. zapy/_auth/pairing/__init__.py +3 -0
  22. zapy/_auth/pairing/companion_host.py +239 -0
  23. zapy/_auth/pairing/flow.py +808 -0
  24. zapy/_auth/pairing/pairing_code_crypto.py +143 -0
  25. zapy/_auth/pairing/qr_flow.py +123 -0
  26. zapy/_auth/pairing/shortcake_crypto.py +122 -0
  27. zapy/_auth/pairing/shortcake_flow.py +393 -0
  28. zapy/_auth/types.py +110 -0
  29. zapy/_client/__init__.py +26 -0
  30. zapy/_client/client.py +972 -0
  31. zapy/_client/connection/__init__.py +6 -0
  32. zapy/_client/connection/manager.py +525 -0
  33. zapy/_client/connection/receipt_queue.py +74 -0
  34. zapy/_client/coordinators/__init__.py +81 -0
  35. zapy/_client/coordinators/ab_props.py +260 -0
  36. zapy/_client/coordinators/app_state_mutation.py +2538 -0
  37. zapy/_client/coordinators/bot.py +830 -0
  38. zapy/_client/coordinators/broadcast_list.py +101 -0
  39. zapy/_client/coordinators/business.py +247 -0
  40. zapy/_client/coordinators/email.py +158 -0
  41. zapy/_client/coordinators/group.py +1478 -0
  42. zapy/_client/coordinators/incoming_node.py +758 -0
  43. zapy/_client/coordinators/low_level.py +119 -0
  44. zapy/_client/coordinators/message.py +1153 -0
  45. zapy/_client/coordinators/message_dispatch.py +1637 -0
  46. zapy/_client/coordinators/newsletter.py +110 -0
  47. zapy/_client/coordinators/offline_resume.py +271 -0
  48. zapy/_client/coordinators/passive_tasks.py +447 -0
  49. zapy/_client/coordinators/presence.py +103 -0
  50. zapy/_client/coordinators/privacy.py +623 -0
  51. zapy/_client/coordinators/profile.py +1024 -0
  52. zapy/_client/coordinators/retry.py +1878 -0
  53. zapy/_client/coordinators/status.py +132 -0
  54. zapy/_client/coordinators/stream_control.py +260 -0
  55. zapy/_client/coordinators/trusted_contact_token.py +417 -0
  56. zapy/_client/events/__init__.py +266 -0
  57. zapy/_client/events/abprops.py +58 -0
  58. zapy/_client/events/appstate_mutation.py +248 -0
  59. zapy/_client/events/business.py +565 -0
  60. zapy/_client/events/call.py +144 -0
  61. zapy/_client/events/chatstate.py +41 -0
  62. zapy/_client/events/devices.py +122 -0
  63. zapy/_client/events/dirty.py +384 -0
  64. zapy/_client/events/group.py +655 -0
  65. zapy/_client/events/identity.py +40 -0
  66. zapy/_client/events/incoming.py +1079 -0
  67. zapy/_client/events/mex_notification.py +317 -0
  68. zapy/_client/events/offline.py +123 -0
  69. zapy/_client/events/picture.py +67 -0
  70. zapy/_client/events/presence.py +74 -0
  71. zapy/_client/events/privacy.py +187 -0
  72. zapy/_client/events/privacy_token.py +72 -0
  73. zapy/_client/events/receipt.py +109 -0
  74. zapy/_client/events/registration.py +70 -0
  75. zapy/_client/events/username.py +76 -0
  76. zapy/_client/factory.py +2020 -0
  77. zapy/_client/media.py +829 -0
  78. zapy/_client/newsletter/__init__.py +90 -0
  79. zapy/_client/newsletter/admin.py +323 -0
  80. zapy/_client/newsletter/content.py +499 -0
  81. zapy/_client/newsletter/discovery.py +233 -0
  82. zapy/_client/newsletter/messaging.py +396 -0
  83. zapy/_client/newsletter/mex.py +99 -0
  84. zapy/_client/newsletter/parse.py +406 -0
  85. zapy/_client/newsletter/types.py +393 -0
  86. zapy/_client/persistence/__init__.py +89 -0
  87. zapy/_client/persistence/companion_host.py +133 -0
  88. zapy/_client/persistence/ephemeral_setting.py +245 -0
  89. zapy/_client/persistence/group_history.py +361 -0
  90. zapy/_client/persistence/history_blob.py +169 -0
  91. zapy/_client/persistence/history_sync.py +646 -0
  92. zapy/_client/persistence/mailbox.py +232 -0
  93. zapy/_client/persistence/write_behind_persistence.py +368 -0
  94. zapy/_client/plugins/__init__.py +23 -0
  95. zapy/_client/plugins/define.py +44 -0
  96. zapy/_client/plugins/install.py +254 -0
  97. zapy/_client/plugins/types.py +64 -0
  98. zapy/_client/tokens/__init__.py +21 -0
  99. zapy/_client/tokens/cs_token.py +47 -0
  100. zapy/_client/tokens/tc_token.py +43 -0
  101. zapy/_client/types.py +988 -0
  102. zapy/_crypto/__init__.py +65 -0
  103. zapy/_crypto/core/__init__.py +62 -0
  104. zapy/_crypto/core/hkdf.py +41 -0
  105. zapy/_crypto/core/keys.py +51 -0
  106. zapy/_crypto/core/nonce.py +25 -0
  107. zapy/_crypto/core/primitives.py +179 -0
  108. zapy/_crypto/core/random.py +32 -0
  109. zapy/_crypto/core/xeddsa.py +72 -0
  110. zapy/_crypto/curves/__init__.py +3 -0
  111. zapy/_crypto/curves/constants.py +10 -0
  112. zapy/_crypto/curves/ed25519.py +61 -0
  113. zapy/_crypto/curves/types.py +18 -0
  114. zapy/_crypto/curves/x25519.py +117 -0
  115. zapy/_crypto/math/__init__.py +3 -0
  116. zapy/_crypto/math/constants.py +35 -0
  117. zapy/_crypto/math/edwards.py +174 -0
  118. zapy/_crypto/math/fe.py +120 -0
  119. zapy/_crypto/math/le.py +13 -0
  120. zapy/_crypto/math/mod.py +15 -0
  121. zapy/_crypto/math/prime.py +11 -0
  122. zapy/_crypto/math/types.py +25 -0
  123. zapy/_crypto/native_backend.py +40 -0
  124. zapy/_infra/__init__.py +3 -0
  125. zapy/_infra/log.py +142 -0
  126. zapy/_infra/perf.py +77 -0
  127. zapy/_media/__init__.py +64 -0
  128. zapy/_media/constants.py +133 -0
  129. zapy/_media/container.py +110 -0
  130. zapy/_media/crypto/__init__.py +19 -0
  131. zapy/_media/crypto/crypto.py +633 -0
  132. zapy/_media/crypto/media_retry.py +107 -0
  133. zapy/_media/processor.py +100 -0
  134. zapy/_media/sticker/__init__.py +8 -0
  135. zapy/_media/sticker/pack.py +188 -0
  136. zapy/_media/transfer/__init__.py +15 -0
  137. zapy/_media/transfer/client.py +635 -0
  138. zapy/_media/transfer/conn.py +48 -0
  139. zapy/_media/types.py +169 -0
  140. zapy/_message/__init__.py +121 -0
  141. zapy/_message/addons/__init__.py +5 -0
  142. zapy/_message/addons/link_preview/__init__.py +54 -0
  143. zapy/_message/addons/link_preview/builder.py +56 -0
  144. zapy/_message/addons/link_preview/detect.py +72 -0
  145. zapy/_message/addons/link_preview/fetcher.py +553 -0
  146. zapy/_message/addons/link_preview/types.py +100 -0
  147. zapy/_message/client.py +486 -0
  148. zapy/_message/context_info.py +424 -0
  149. zapy/_message/crypto/__init__.py +71 -0
  150. zapy/_message/crypto/addon_crypto.py +656 -0
  151. zapy/_message/crypto/icdc.py +138 -0
  152. zapy/_message/crypto/phash.py +87 -0
  153. zapy/_message/crypto/reporting_token.py +498 -0
  154. zapy/_message/crypto/use_case_secret.py +113 -0
  155. zapy/_message/encode/__init__.py +84 -0
  156. zapy/_message/encode/content.py +636 -0
  157. zapy/_message/encode/device_sent.py +88 -0
  158. zapy/_message/encode/media_payload.py +122 -0
  159. zapy/_message/encode/padding.py +27 -0
  160. zapy/_message/kinds/__init__.py +1 -0
  161. zapy/_message/kinds/bot.py +179 -0
  162. zapy/_message/kinds/group_history.py +206 -0
  163. zapy/_message/kinds/newsletter.py +388 -0
  164. zapy/_message/kinds/sticker_pack.py +74 -0
  165. zapy/_message/messaging/__init__.py +336 -0
  166. zapy/_message/messaging/companion_host.py +117 -0
  167. zapy/_message/messaging/fanout.py +311 -0
  168. zapy/_message/messaging/group_metadata.py +444 -0
  169. zapy/_message/messaging/ignore_key.py +264 -0
  170. zapy/_message/messaging/key_protocol.py +217 -0
  171. zapy/_message/messaging/link_preview.py +448 -0
  172. zapy/_message/messaging/messages.py +1429 -0
  173. zapy/_message/primitives/__init__.py +1 -0
  174. zapy/_message/primitives/ack.py +232 -0
  175. zapy/_message/primitives/incoming.py +1141 -0
  176. zapy/_message/primitives/media_retry.py +451 -0
  177. zapy/_message/primitives/peer_data_operation.py +271 -0
  178. zapy/_message/types.py +434 -0
  179. zapy/_proto/WAProto_pb2.py +2584 -0
  180. zapy/_proto/__init__.py +1 -0
  181. zapy/_protocol/__init__.py +3 -0
  182. zapy/_protocol/abprops_spec.py +6216 -0
  183. zapy/_protocol/auth.py +17 -0
  184. zapy/_protocol/browser.py +57 -0
  185. zapy/_protocol/defaults.py +38 -0
  186. zapy/_protocol/device_identity.py +54 -0
  187. zapy/_protocol/jid.py +241 -0
  188. zapy/_protocol/message.py +127 -0
  189. zapy/_protocol/nodes.py +144 -0
  190. zapy/_protocol/notification.py +18 -0
  191. zapy/_retry/__init__.py +77 -0
  192. zapy/_retry/codec.py +209 -0
  193. zapy/_retry/constants.py +28 -0
  194. zapy/_retry/parse.py +132 -0
  195. zapy/_retry/reason.py +65 -0
  196. zapy/_retry/replay.py +483 -0
  197. zapy/_retry/tracker.py +161 -0
  198. zapy/_retry/types.py +122 -0
  199. zapy/_signal/__init__.py +171 -0
  200. zapy/_signal/api/__init__.py +133 -0
  201. zapy/_signal/api/codec.py +164 -0
  202. zapy/_signal/api/constants.py +14 -0
  203. zapy/_signal/api/device_sync.py +915 -0
  204. zapy/_signal/api/digest_sync.py +363 -0
  205. zapy/_signal/api/identity_sync.py +250 -0
  206. zapy/_signal/api/missing_pre_keys_sync.py +267 -0
  207. zapy/_signal/api/prekeys.py +191 -0
  208. zapy/_signal/api/result_map.py +40 -0
  209. zapy/_signal/api/rotate_key.py +111 -0
  210. zapy/_signal/api/session_sync.py +297 -0
  211. zapy/_signal/attestation.py +145 -0
  212. zapy/_signal/constants.py +22 -0
  213. zapy/_signal/encoding.py +78 -0
  214. zapy/_signal/group/__init__.py +35 -0
  215. zapy/_signal/group/chain.py +139 -0
  216. zapy/_signal/group/codec.py +78 -0
  217. zapy/_signal/group/encoding.py +166 -0
  218. zapy/_signal/group/manager.py +361 -0
  219. zapy/_signal/registration/__init__.py +44 -0
  220. zapy/_signal/registration/keygen.py +46 -0
  221. zapy/_signal/registration/reg_encoding.py +66 -0
  222. zapy/_signal/registration/reg_utils.py +52 -0
  223. zapy/_signal/session/__init__.py +114 -0
  224. zapy/_signal/session/encoding.py +385 -0
  225. zapy/_signal/session/protocol.py +590 -0
  226. zapy/_signal/session/ratchet.py +381 -0
  227. zapy/_signal/session/resolver.py +630 -0
  228. zapy/_signal/session/serializer.py +96 -0
  229. zapy/_signal/session/session.py +272 -0
  230. zapy/_signal/types.py +214 -0
  231. zapy/_store/__init__.py +118 -0
  232. zapy/_store/cache/__init__.py +166 -0
  233. zapy/_store/cache/identity.py +130 -0
  234. zapy/_store/cache/privacy_token.py +116 -0
  235. zapy/_store/cache/sender_key.py +168 -0
  236. zapy/_store/cache/session.py +142 -0
  237. zapy/_store/contracts/__init__.py +84 -0
  238. zapy/_store/contracts/appstate.py +82 -0
  239. zapy/_store/contracts/auth.py +16 -0
  240. zapy/_store/contracts/chat_metadata.py +29 -0
  241. zapy/_store/contracts/contact.py +31 -0
  242. zapy/_store/contracts/device_list.py +35 -0
  243. zapy/_store/contracts/group_metadata.py +33 -0
  244. zapy/_store/contracts/identity.py +18 -0
  245. zapy/_store/contracts/message.py +36 -0
  246. zapy/_store/contracts/message_secret.py +41 -0
  247. zapy/_store/contracts/pre_key.py +32 -0
  248. zapy/_store/contracts/privacy_token.py +32 -0
  249. zapy/_store/contracts/retry.py +47 -0
  250. zapy/_store/contracts/sender_key.py +37 -0
  251. zapy/_store/contracts/session.py +21 -0
  252. zapy/_store/contracts/signal.py +23 -0
  253. zapy/_store/contracts/thread.py +35 -0
  254. zapy/_store/create_store.py +890 -0
  255. zapy/_store/locks.py +1154 -0
  256. zapy/_store/memory/__init__.py +40 -0
  257. zapy/_store/memory/appstate.py +200 -0
  258. zapy/_store/memory/auth.py +24 -0
  259. zapy/_store/memory/chat_metadata.py +124 -0
  260. zapy/_store/memory/contact.py +125 -0
  261. zapy/_store/memory/device_list.py +161 -0
  262. zapy/_store/memory/group_metadata.py +125 -0
  263. zapy/_store/memory/identity.py +86 -0
  264. zapy/_store/memory/message.py +85 -0
  265. zapy/_store/memory/message_secret.py +145 -0
  266. zapy/_store/memory/pre_key.py +112 -0
  267. zapy/_store/memory/privacy_token.py +103 -0
  268. zapy/_store/memory/retry.py +250 -0
  269. zapy/_store/memory/sender_key.py +162 -0
  270. zapy/_store/memory/session.py +111 -0
  271. zapy/_store/memory/signal.py +45 -0
  272. zapy/_store/memory/thread.py +66 -0
  273. zapy/_store/noop.py +279 -0
  274. zapy/_transport/__init__.py +3 -0
  275. zapy/_transport/binary/__init__.py +77 -0
  276. zapy/_transport/binary/constants.py +80 -0
  277. zapy/_transport/binary/decoder.py +260 -0
  278. zapy/_transport/binary/encoder.py +279 -0
  279. zapy/_transport/binary/tokens.py +1289 -0
  280. zapy/_transport/comms.py +759 -0
  281. zapy/_transport/keepalive/__init__.py +3 -0
  282. zapy/_transport/keepalive/keep_alive.py +252 -0
  283. zapy/_transport/node/__init__.py +3 -0
  284. zapy/_transport/node/builders/__init__.py +9 -0
  285. zapy/_transport/node/builders/abprops.py +33 -0
  286. zapy/_transport/node/builders/account_sync.py +120 -0
  287. zapy/_transport/node/builders/bot.py +56 -0
  288. zapy/_transport/node/builders/business.py +261 -0
  289. zapy/_transport/node/builders/chatstate.py +74 -0
  290. zapy/_transport/node/builders/community.py +116 -0
  291. zapy/_transport/node/builders/device.py +30 -0
  292. zapy/_transport/node/builders/email.py +181 -0
  293. zapy/_transport/node/builders/global_.py +74 -0
  294. zapy/_transport/node/builders/group.py +279 -0
  295. zapy/_transport/node/builders/media.py +21 -0
  296. zapy/_transport/node/builders/message.py +436 -0
  297. zapy/_transport/node/builders/mobile.py +227 -0
  298. zapy/_transport/node/builders/newsletter.py +293 -0
  299. zapy/_transport/node/builders/offline.py +20 -0
  300. zapy/_transport/node/builders/pairing.py +130 -0
  301. zapy/_transport/node/builders/passive.py +28 -0
  302. zapy/_transport/node/builders/prekeys.py +215 -0
  303. zapy/_transport/node/builders/presence.py +100 -0
  304. zapy/_transport/node/builders/privacy.py +243 -0
  305. zapy/_transport/node/builders/privacy_token.py +94 -0
  306. zapy/_transport/node/builders/profile.py +176 -0
  307. zapy/_transport/node/builders/retry.py +156 -0
  308. zapy/_transport/node/builders/shortcake.py +87 -0
  309. zapy/_transport/node/builders/tos.py +92 -0
  310. zapy/_transport/node/builders/usync.py +185 -0
  311. zapy/_transport/node/helpers.py +201 -0
  312. zapy/_transport/node/orchestrator.py +210 -0
  313. zapy/_transport/node/query.py +82 -0
  314. zapy/_transport/node/transport.py +105 -0
  315. zapy/_transport/node/usync.py +33 -0
  316. zapy/_transport/node/xml.py +38 -0
  317. zapy/_transport/noise/__init__.py +7 -0
  318. zapy/_transport/noise/cert.py +85 -0
  319. zapy/_transport/noise/client_payload.py +344 -0
  320. zapy/_transport/noise/constants.py +12 -0
  321. zapy/_transport/noise/frame_codec.py +120 -0
  322. zapy/_transport/noise/handshake.py +92 -0
  323. zapy/_transport/noise/session.py +493 -0
  324. zapy/_transport/noise/socket.py +45 -0
  325. zapy/_transport/noise/types.py +66 -0
  326. zapy/_transport/noise/version.json +3 -0
  327. zapy/_transport/proxy.py +35 -0
  328. zapy/_transport/types.py +19 -0
  329. zapy/_transport/wa_version_fetcher.py +159 -0
  330. zapy/_transport/web_socket.py +602 -0
  331. zapy/_util/__init__.py +3 -0
  332. zapy/_util/bytes.py +131 -0
  333. zapy/_util/coercion.py +29 -0
  334. zapy/_util/collections.py +45 -0
  335. zapy/_util/primitives.py +49 -0
  336. zapy/client.py +840 -0
  337. zapy/errors.py +148 -0
  338. zapy/events.py +564 -0
  339. zapy/jid.py +140 -0
  340. zapy/py.typed +0 -0
  341. zapy/stores/__init__.py +50 -0
  342. zapy/stores/base.py +1627 -0
  343. zapy/stores/json_file.py +359 -0
  344. zapy/stores/memory.py +322 -0
  345. zapy/stores/sqlite.py +343 -0
@@ -0,0 +1,565 @@
1
+ """Business notification parser (``src/client/events/business.ts``)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+ from typing import TYPE_CHECKING, Any
7
+
8
+ from zapy._proto import WAProto_pb2
9
+ from zapy._protocol.nodes import WA_NODE_TAGS
10
+ from zapy._protocol.notification import WA_NOTIFICATION_TYPES
11
+ from zapy._transport.node.helpers import (
12
+ find_node_child,
13
+ get_node_bytes_content,
14
+ get_node_children,
15
+ get_node_children_by_tag,
16
+ get_node_text_content,
17
+ )
18
+ from zapy._transport.types import BinaryNode
19
+ from zapy._util.primitives import parse_optional_int
20
+
21
+ if TYPE_CHECKING:
22
+ from zapy._client.events.incoming import WaIncomingUnhandledStanzaEvent
23
+
24
+ # Mirrors ``WA_BUSINESS_NOTIFICATION_TAGS`` in ``src/protocol/notification.ts``.
25
+ _BIZ_TAGS = {
26
+ "VERIFIED_NAME": "verified_name",
27
+ "REMOVE": "remove",
28
+ "PROFILE": "profile",
29
+ "PRODUCT_CATALOG": "product_catalog",
30
+ "SUBSCRIPTIONS": "subscriptions",
31
+ "FEATURE_FLAGS": "feature_flags",
32
+ }
33
+
34
+ _VN_ISSUER_API = "ent:wa"
35
+ _VN_ISSUER_SMB = "smb:wa"
36
+
37
+
38
+ @dataclass(frozen=True, slots=True)
39
+ class WaBusinessCategory:
40
+ """One business category entry."""
41
+
42
+ id: str
43
+ name: str
44
+
45
+
46
+ @dataclass(frozen=True, slots=True)
47
+ class WaBusinessHoursEntry:
48
+ """One day's opening-hours config."""
49
+
50
+ day_of_week: str
51
+ mode: str
52
+ open_time: int | None = None
53
+ close_time: int | None = None
54
+
55
+
56
+ @dataclass(frozen=True, slots=True)
57
+ class WaBusinessHours:
58
+ """Timezone plus per-day opening-hours config."""
59
+
60
+ timezone: str | None = None
61
+ config: list[WaBusinessHoursEntry] = field(default_factory=list)
62
+
63
+
64
+ @dataclass(frozen=True, slots=True)
65
+ class WaBusinessWebsite:
66
+ """One business website URL."""
67
+
68
+ url: str
69
+
70
+
71
+ @dataclass(frozen=True, slots=True)
72
+ class WaBusinessProfileResult:
73
+ """Decoded ``<profile>`` business payload."""
74
+
75
+ jid: str
76
+ tag: str | None = None
77
+ description: str | None = None
78
+ address: str | None = None
79
+ email: str | None = None
80
+ websites: list[WaBusinessWebsite] | None = None
81
+ categories: list[WaBusinessCategory] | None = None
82
+ business_hours: WaBusinessHours | None = None
83
+ latitude: float | None = None
84
+ longitude: float | None = None
85
+ profile_options: dict[str, str] | None = None
86
+
87
+
88
+ @dataclass(frozen=True, slots=True)
89
+ class WaVerifiedNamePrivacyMode:
90
+ """Privacy-mode counters attached to a verified-name update."""
91
+
92
+ actual_actors: int
93
+ host_storage: int
94
+ privacy_mode_ts: int
95
+
96
+
97
+ @dataclass(frozen=True, slots=True)
98
+ class WaVerifiedNameResult:
99
+ """Decoded ``<verified_name>`` payload."""
100
+
101
+ is_api: bool = False
102
+ is_smb: bool = False
103
+ name: str | None = None
104
+ level: str | None = None
105
+ serial: str | None = None
106
+ privacy_mode: WaVerifiedNamePrivacyMode | None = None
107
+
108
+
109
+ @dataclass(frozen=True, slots=True)
110
+ class WaBusinessCollectionUpdate:
111
+ """One product-collection status update."""
112
+
113
+ id: str
114
+ review_status: str | None = None
115
+ reject_reason: str | None = None
116
+ commerce_url: str | None = None
117
+
118
+
119
+ @dataclass(frozen=True, slots=True)
120
+ class WaBusinessSubscription:
121
+ """One business subscription entry."""
122
+
123
+ id: str
124
+ status: str
125
+ tier: int | None = None
126
+ source: str | None = None
127
+ start_time: int | None = None
128
+ creation_time: int | None = None
129
+ expiration_date: int | None = None
130
+
131
+
132
+ @dataclass(frozen=True, slots=True)
133
+ class WaBusinessFeatureFlag:
134
+ """One business feature flag entry."""
135
+
136
+ name: str
137
+ enabled: bool = False
138
+ expiration_time: int | None = None
139
+ limit: int | None = None
140
+
141
+
142
+ @dataclass(frozen=True, slots=True)
143
+ class WaBusinessEvent:
144
+ """A typed business notification plus the raw stanza."""
145
+
146
+ raw_node: BinaryNode
147
+ stanza_id: str | None
148
+ chat_jid: str | None
149
+ stanza_type: str | None
150
+ offline: bool
151
+ action: str
152
+ timestamp_seconds: int | None = None
153
+ biz_jid: str | None = None
154
+ biz_hash: str | None = None
155
+ verified_name: WaVerifiedNameResult | None = None
156
+ product_ids: list[str] | None = None
157
+ collections: list[WaBusinessCollectionUpdate] | None = None
158
+ subscriptions: list[WaBusinessSubscription] | None = None
159
+ feature_flags: list[WaBusinessFeatureFlag] | None = None
160
+
161
+
162
+ @dataclass(frozen=True, slots=True)
163
+ class WaParseBusinessNotificationResult:
164
+ """Outcome of ``parse_business_notification_events``."""
165
+
166
+ events: list[WaBusinessEvent]
167
+ unhandled: list[WaIncomingUnhandledStanzaEvent]
168
+
169
+
170
+ def _parse_certificate_content(content_bytes: bytes) -> dict[str, Any] | None:
171
+ try:
172
+ cert = WAProto_pb2.VerifiedNameCertificate()
173
+ cert.ParseFromString(content_bytes)
174
+ if not cert.details:
175
+ return None
176
+ details = WAProto_pb2.VerifiedNameCertificate.Details()
177
+ details.ParseFromString(cert.details)
178
+ return {
179
+ "name": details.verifiedName if details.verifiedName else None,
180
+ "serial": str(details.serial),
181
+ "is_api": details.issuer == _VN_ISSUER_API,
182
+ "is_smb": details.issuer == _VN_ISSUER_SMB,
183
+ }
184
+ except Exception:
185
+ return None
186
+
187
+
188
+ def parse_verified_name_node(node: BinaryNode) -> WaVerifiedNameResult | None:
189
+ """Parse a ``<verified_name>`` child; ``None`` when the tag does not match."""
190
+ if node.tag != _BIZ_TAGS["VERIFIED_NAME"]:
191
+ return None
192
+ content_bytes = get_node_bytes_content(node)
193
+ cert_data = (
194
+ _parse_certificate_content(content_bytes) if content_bytes is not None else None
195
+ )
196
+ privacy_mode: WaVerifiedNamePrivacyMode | None = None
197
+ actual_actors = node.attrs.get("actual_actors")
198
+ host_storage = node.attrs.get("host_storage")
199
+ privacy_mode_ts = node.attrs.get("privacy_mode_ts")
200
+ if (
201
+ actual_actors is not None
202
+ and host_storage is not None
203
+ and privacy_mode_ts is not None
204
+ ):
205
+ privacy_mode = WaVerifiedNamePrivacyMode(
206
+ actual_actors=int(actual_actors),
207
+ host_storage=int(host_storage),
208
+ privacy_mode_ts=int(privacy_mode_ts),
209
+ )
210
+ is_api = bool(cert_data and cert_data["is_api"])
211
+ is_smb = bool(cert_data and cert_data["is_smb"])
212
+ name = cert_data["name"] if cert_data else None
213
+ serial: str | None = node.attrs.get("serial")
214
+ if serial is None and cert_data is not None:
215
+ serial = cert_data["serial"]
216
+ return WaVerifiedNameResult(
217
+ name=name,
218
+ level=node.attrs.get("verified_level"),
219
+ serial=serial,
220
+ is_api=is_api,
221
+ is_smb=is_smb,
222
+ privacy_mode=privacy_mode,
223
+ )
224
+
225
+
226
+ def _parse_business_categories(node: BinaryNode) -> list[WaBusinessCategory]:
227
+ categories: list[WaBusinessCategory] = []
228
+ for child in get_node_children(node):
229
+ if child.tag != "category":
230
+ continue
231
+ category_id = child.attrs.get("id")
232
+ if not category_id:
233
+ continue
234
+ categories.append(
235
+ WaBusinessCategory(id=category_id, name=get_node_text_content(child) or "")
236
+ )
237
+ return categories
238
+
239
+
240
+ def _parse_business_hours_node(node: BinaryNode) -> WaBusinessHours:
241
+ config: list[WaBusinessHoursEntry] = []
242
+ for child in get_node_children(node):
243
+ if child.tag != "business_hours_config":
244
+ continue
245
+ day_of_week = child.attrs.get("day_of_week")
246
+ mode = child.attrs.get("mode")
247
+ if not day_of_week or not mode:
248
+ continue
249
+ open_time = child.attrs.get("open_time")
250
+ close_time = child.attrs.get("close_time")
251
+ config.append(
252
+ WaBusinessHoursEntry(
253
+ day_of_week=day_of_week,
254
+ mode=mode,
255
+ open_time=int(open_time) if open_time else None,
256
+ close_time=int(close_time) if close_time else None,
257
+ )
258
+ )
259
+ return WaBusinessHours(timezone=node.attrs.get("timezone"), config=config)
260
+
261
+
262
+ def _parse_profile_options(node: BinaryNode) -> dict[str, str]:
263
+ options: dict[str, str] = {}
264
+ for child in get_node_children(node):
265
+ text = get_node_text_content(child)
266
+ if text is not None:
267
+ options[child.tag] = text
268
+ return options
269
+
270
+
271
+ def parse_business_profile_node(node: BinaryNode) -> WaBusinessProfileResult | None:
272
+ """Parse a ``<profile>`` business child; ``None`` when the tag does not match."""
273
+ if node.tag != _BIZ_TAGS["PROFILE"]:
274
+ return None
275
+ jid = node.attrs.get("jid")
276
+ if not jid:
277
+ return None
278
+ entry = WaBusinessProfileResult(jid=jid, tag=node.attrs.get("tag"))
279
+ children = node.content
280
+ if not isinstance(children, list):
281
+ return entry
282
+ websites: list[WaBusinessWebsite] = []
283
+ description: str | None = None
284
+ address: str | None = None
285
+ email: str | None = None
286
+ categories: list[WaBusinessCategory] | None = None
287
+ business_hours: WaBusinessHours | None = None
288
+ latitude: float | None = None
289
+ longitude: float | None = None
290
+ profile_options: dict[str, str] | None = None
291
+ for child in children:
292
+ text = get_node_text_content(child)
293
+ if child.tag == "description":
294
+ if text is not None:
295
+ description = text
296
+ elif child.tag == "address":
297
+ if text is not None:
298
+ address = text
299
+ elif child.tag == "email":
300
+ if text is not None:
301
+ email = text
302
+ elif child.tag == "website":
303
+ if text is not None:
304
+ websites.append(WaBusinessWebsite(url=text))
305
+ elif child.tag == "latitude":
306
+ if text is not None:
307
+ try:
308
+ value = float(text)
309
+ except ValueError:
310
+ value = float("nan")
311
+ if value == value:
312
+ latitude = value
313
+ elif child.tag == "longitude":
314
+ if text is not None:
315
+ try:
316
+ value = float(text)
317
+ except ValueError:
318
+ value = float("nan")
319
+ if value == value:
320
+ longitude = value
321
+ elif child.tag == "categories":
322
+ categories = _parse_business_categories(child)
323
+ elif child.tag == "business_hours":
324
+ business_hours = _parse_business_hours_node(child)
325
+ elif child.tag == "profile_options":
326
+ profile_options = _parse_profile_options(child)
327
+ return WaBusinessProfileResult(
328
+ jid=jid,
329
+ tag=entry.tag,
330
+ description=description,
331
+ address=address,
332
+ email=email,
333
+ websites=websites or None,
334
+ categories=categories,
335
+ business_hours=business_hours,
336
+ latitude=latitude,
337
+ longitude=longitude,
338
+ profile_options=profile_options,
339
+ )
340
+
341
+
342
+ def _parse_subscriptions_list(node: BinaryNode) -> list[WaBusinessSubscription]:
343
+ subs: list[WaBusinessSubscription] = []
344
+ for sub in get_node_children_by_tag(node, "subscription"):
345
+ sub_id = sub.attrs.get("id")
346
+ status = sub.attrs.get("status")
347
+ if not sub_id or not status:
348
+ continue
349
+ subs.append(
350
+ WaBusinessSubscription(
351
+ id=sub_id,
352
+ status=status,
353
+ tier=parse_optional_int(sub.attrs.get("subscription_tier")),
354
+ source=sub.attrs.get("source"),
355
+ start_time=parse_optional_int(sub.attrs.get("subscription_start_time")),
356
+ creation_time=parse_optional_int(
357
+ sub.attrs.get("subscription_creation_time")
358
+ ),
359
+ expiration_date=parse_optional_int(
360
+ sub.attrs.get("subscription_end_time")
361
+ ),
362
+ )
363
+ )
364
+ return subs
365
+
366
+
367
+ def _parse_feature_flags_list(node: BinaryNode) -> list[WaBusinessFeatureFlag]:
368
+ flags: list[WaBusinessFeatureFlag] = []
369
+ for flag in get_node_children_by_tag(node, "feature_flag"):
370
+ name = flag.attrs.get("name")
371
+ if not name:
372
+ continue
373
+ enabled = (flag.attrs.get("enabled") or "").lower() == "true"
374
+ flags.append(
375
+ WaBusinessFeatureFlag(
376
+ name=name,
377
+ enabled=enabled,
378
+ expiration_time=parse_optional_int(flag.attrs.get("expiration_time")),
379
+ limit=parse_optional_int(flag.attrs.get("limit")),
380
+ )
381
+ )
382
+ return flags
383
+
384
+
385
+ def _parse_product_ids(catalog_node: BinaryNode) -> list[str]:
386
+ ids: list[str] = []
387
+ for product in get_node_children_by_tag(catalog_node, "product"):
388
+ id_node = find_node_child(product, WA_NODE_TAGS["ID"])
389
+ if id_node is None:
390
+ continue
391
+ text = get_node_text_content(id_node)
392
+ if text:
393
+ ids.append(text)
394
+ return ids
395
+
396
+
397
+ def _parse_collection_updates(
398
+ catalog_node: BinaryNode,
399
+ ) -> list[WaBusinessCollectionUpdate]:
400
+ collections: list[WaBusinessCollectionUpdate] = []
401
+ for collection in get_node_children_by_tag(catalog_node, "collection"):
402
+ collection_id = collection.attrs.get("id")
403
+ if not collection_id:
404
+ continue
405
+ review_status: str | None = None
406
+ reject_reason: str | None = None
407
+ commerce_url: str | None = None
408
+ status_info = find_node_child(collection, "status_info")
409
+ if status_info is not None:
410
+ status_node = find_node_child(status_info, WA_NODE_TAGS["STATUS"])
411
+ if status_node is not None:
412
+ text = get_node_text_content(status_node)
413
+ if text:
414
+ review_status = text
415
+ reject_node = find_node_child(status_info, "reject_reason")
416
+ if reject_node is not None:
417
+ text = get_node_text_content(reject_node)
418
+ if text:
419
+ reject_reason = text
420
+ commerce_node = find_node_child(status_info, "commerce_url")
421
+ if commerce_node is not None:
422
+ text = get_node_text_content(commerce_node)
423
+ if text:
424
+ commerce_url = text
425
+ collections.append(
426
+ WaBusinessCollectionUpdate(
427
+ id=collection_id,
428
+ review_status=review_status,
429
+ reject_reason=reject_reason,
430
+ commerce_url=commerce_url,
431
+ )
432
+ )
433
+ return collections
434
+
435
+
436
+ def _parse_single_business_event(
437
+ notification_node: BinaryNode,
438
+ ) -> WaBusinessEvent | None:
439
+ base: dict[str, Any] = {
440
+ "raw_node": notification_node,
441
+ "stanza_id": notification_node.attrs.get("id"),
442
+ "chat_jid": notification_node.attrs.get("from"),
443
+ "stanza_type": notification_node.attrs.get("type"),
444
+ "offline": "offline" in notification_node.attrs,
445
+ "timestamp_seconds": parse_optional_int(notification_node.attrs.get("t")),
446
+ }
447
+
448
+ verified_name = find_node_child(notification_node, _BIZ_TAGS["VERIFIED_NAME"])
449
+ if verified_name is not None:
450
+ vn_jid = verified_name.attrs.get("jid")
451
+ if vn_jid:
452
+ parsed = parse_verified_name_node(verified_name)
453
+ if parsed is None:
454
+ return None
455
+ return WaBusinessEvent(
456
+ action="verified_name_update",
457
+ biz_jid=vn_jid,
458
+ verified_name=parsed,
459
+ **base,
460
+ )
461
+ vn_hash = verified_name.attrs.get("hash")
462
+ if vn_hash:
463
+ return WaBusinessEvent(
464
+ action="verified_name_stale", biz_hash=vn_hash, **base
465
+ )
466
+ return None
467
+
468
+ remove = find_node_child(notification_node, _BIZ_TAGS["REMOVE"])
469
+ if remove is not None:
470
+ rm_jid = remove.attrs.get("jid")
471
+ if rm_jid:
472
+ return WaBusinessEvent(action="business_removed", biz_jid=rm_jid, **base)
473
+ rm_hash = remove.attrs.get("hash")
474
+ if rm_hash:
475
+ return WaBusinessEvent(action="business_removed", biz_hash=rm_hash, **base)
476
+ return None
477
+
478
+ profile = find_node_child(notification_node, _BIZ_TAGS["PROFILE"])
479
+ if profile is not None:
480
+ profile_hash = profile.attrs.get("hash")
481
+ if profile_hash:
482
+ return WaBusinessEvent(
483
+ action="profile_update", biz_hash=profile_hash, **base
484
+ )
485
+ return WaBusinessEvent(
486
+ action="profile_update", biz_jid=notification_node.attrs.get("from"), **base
487
+ )
488
+
489
+ catalog = find_node_child(notification_node, _BIZ_TAGS["PRODUCT_CATALOG"])
490
+ if catalog is not None:
491
+ from_jid = notification_node.attrs.get("from")
492
+ if find_node_child(catalog, "product") is not None:
493
+ return WaBusinessEvent(
494
+ action="product_update",
495
+ biz_jid=from_jid,
496
+ product_ids=_parse_product_ids(catalog),
497
+ **base,
498
+ )
499
+ if find_node_child(catalog, "collection") is not None:
500
+ return WaBusinessEvent(
501
+ action="collection_update",
502
+ biz_jid=from_jid,
503
+ collections=_parse_collection_updates(catalog),
504
+ **base,
505
+ )
506
+ return None
507
+
508
+ subscriptions = find_node_child(notification_node, _BIZ_TAGS["SUBSCRIPTIONS"])
509
+ feature_flags = find_node_child(notification_node, _BIZ_TAGS["FEATURE_FLAGS"])
510
+ if subscriptions is not None or feature_flags is not None:
511
+ return WaBusinessEvent(
512
+ action="subscriptions_update",
513
+ biz_jid=notification_node.attrs.get("from"),
514
+ subscriptions=_parse_subscriptions_list(subscriptions)
515
+ if subscriptions is not None
516
+ else [],
517
+ feature_flags=_parse_feature_flags_list(feature_flags)
518
+ if feature_flags is not None
519
+ else [],
520
+ **base,
521
+ )
522
+ return None
523
+
524
+
525
+ def parse_business_notification_events(
526
+ notification_node: BinaryNode,
527
+ ) -> WaParseBusinessNotificationResult:
528
+ """Parse a ``business`` notification into typed events plus unhandled stanzas."""
529
+ from zapy._client.events.incoming import WaIncomingUnhandledStanzaEvent
530
+
531
+ if (
532
+ notification_node.tag != WA_NODE_TAGS["NOTIFICATION"]
533
+ or notification_node.attrs.get("type") != WA_NOTIFICATION_TYPES["BUSINESS"]
534
+ ):
535
+ return WaParseBusinessNotificationResult(events=[], unhandled=[])
536
+
537
+ def _unhandled(reason: str) -> WaIncomingUnhandledStanzaEvent:
538
+ return WaIncomingUnhandledStanzaEvent(
539
+ raw_node=notification_node,
540
+ stanza_id=notification_node.attrs.get("id"),
541
+ chat_jid=notification_node.attrs.get("from"),
542
+ stanza_type=notification_node.attrs.get("type"),
543
+ offline="offline" in notification_node.attrs,
544
+ reason=reason,
545
+ )
546
+
547
+ try:
548
+ event = _parse_single_business_event(notification_node)
549
+ if event is not None:
550
+ return WaParseBusinessNotificationResult(events=[event], unhandled=[])
551
+ children = get_node_children(notification_node)
552
+ child_tag = children[0].tag if children else "empty"
553
+ stanza_type = notification_node.attrs.get("type") or "undefined"
554
+ return WaParseBusinessNotificationResult(
555
+ events=[],
556
+ unhandled=[
557
+ _unhandled(f"notification.{stanza_type}.{child_tag}.not_supported")
558
+ ],
559
+ )
560
+ except Exception:
561
+ stanza_type = notification_node.attrs.get("type") or "undefined"
562
+ return WaParseBusinessNotificationResult(
563
+ events=[],
564
+ unhandled=[_unhandled(f"notification.{stanza_type}.parse_failed")],
565
+ )
@@ -0,0 +1,144 @@
1
+ """Call stanza parser (``src/client/events/call.ts``)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+
7
+ from zapy._transport.node.helpers import (
8
+ find_node_child,
9
+ get_first_node_child,
10
+ get_node_children,
11
+ has_node_child,
12
+ )
13
+ from zapy._transport.types import BinaryNode
14
+ from zapy._util.primitives import parse_optional_int
15
+
16
+ # Mirrors ``WA_CALL_PAYLOAD_TAGS`` in ``src/protocol/call.ts``.
17
+ _CALL_PAYLOAD_TAGS = frozenset(
18
+ {
19
+ "offer",
20
+ "offer_notice",
21
+ "accept",
22
+ "preaccept",
23
+ "reject",
24
+ "terminate",
25
+ "transport",
26
+ "mute",
27
+ "video_state",
28
+ "group_info",
29
+ "group_update",
30
+ "enc_rekey",
31
+ "peer_state",
32
+ "flow_control",
33
+ "web_client",
34
+ }
35
+ )
36
+
37
+ # Payload tags that wa-web answers with a typed ``<receipt>`` child instead of
38
+ # a plain ``<ack class="call"/>``. Source: ``WAWebHandleVoipCall.js``.
39
+ CALL_RECEIPT_PAYLOAD_TAGS = frozenset({"offer", "accept", "reject", "enc_rekey"})
40
+
41
+ # Mirrors ``WA_CALL_NODE_ATTRS`` / ``WA_CALL_CHILD_TAGS`` in ``src/protocol/call.ts``.
42
+ _CALL_ID = "call-id"
43
+ _CALL_CREATOR = "call-creator"
44
+ _GROUP_JID = "group-jid"
45
+ _CALLER_PN = "caller_pn"
46
+ _CALLER_COUNTRY_CODE = "caller_country_code"
47
+ _USERNAME = "username"
48
+ _NOTIFY = "notify"
49
+ _SENDER_LID = "sender_lid"
50
+ _PLATFORM = "platform"
51
+ _VERSION = "version"
52
+ _REASON = "reason"
53
+ _USER_PN = "user_pn"
54
+ _GUEST_NAME = "guest_name"
55
+ _VIDEO = "video"
56
+ _SILENCE = "silence"
57
+ _GROUP_INFO = "group_info"
58
+
59
+
60
+ @dataclass(frozen=True, slots=True)
61
+ class WaCallGroupParticipant:
62
+ """One participant snapshot inside a call ``<group_info>`` block."""
63
+
64
+ jid: str
65
+ user_pn_jid: str | None = None
66
+ username: str | None = None
67
+ guest_name: str | None = None
68
+
69
+
70
+ @dataclass(frozen=True, slots=True)
71
+ class ParsedCall:
72
+ """A ``<call>`` stanza: typed payload discriminator plus caller metadata."""
73
+
74
+ type: str
75
+ is_video: bool = False
76
+ payload_tag: str | None = None
77
+ call_id: str | None = None
78
+ call_creator_jid: str | None = None
79
+ sender_lid_jid: str | None = None
80
+ caller_pn_jid: str | None = None
81
+ group_jid: str | None = None
82
+ caller_username: str | None = None
83
+ caller_country_code: str | None = None
84
+ caller_push_name: str | None = None
85
+ peer_platform: str | None = None
86
+ peer_app_version: str | None = None
87
+ timestamp_seconds: int | None = None
88
+ end_timestamp_seconds: int | None = None
89
+ silence_reason: str | None = None
90
+ group_info: list[WaCallGroupParticipant] | None = field(default=None)
91
+
92
+
93
+ def _parse_group_info(node: BinaryNode) -> list[WaCallGroupParticipant] | None:
94
+ children = get_node_children(node)
95
+ if not children:
96
+ return None
97
+ out: list[WaCallGroupParticipant] = []
98
+ for child in children:
99
+ jid = child.attrs.get("jid")
100
+ if not jid:
101
+ continue
102
+ out.append(
103
+ WaCallGroupParticipant(
104
+ jid=jid,
105
+ user_pn_jid=child.attrs.get(_USER_PN),
106
+ username=child.attrs.get(_USERNAME),
107
+ guest_name=child.attrs.get(_GUEST_NAME),
108
+ )
109
+ )
110
+ return out if out else None
111
+
112
+
113
+ def parse_call_node(node: BinaryNode) -> ParsedCall:
114
+ """Parse a ``<call>`` stanza into its typed payload plus caller metadata."""
115
+ payload = get_first_node_child(node)
116
+ if payload is None:
117
+ return ParsedCall(type="unknown", is_video=False)
118
+ payload_tag = payload.tag
119
+ call_type = payload_tag if payload_tag in _CALL_PAYLOAD_TAGS else "unknown"
120
+ group_info_node = find_node_child(payload, _GROUP_INFO)
121
+ silence_node = find_node_child(payload, _SILENCE)
122
+ return ParsedCall(
123
+ type=call_type,
124
+ payload_tag=payload_tag,
125
+ call_id=payload.attrs.get(_CALL_ID),
126
+ call_creator_jid=payload.attrs.get(_CALL_CREATOR),
127
+ sender_lid_jid=node.attrs.get(_SENDER_LID),
128
+ caller_pn_jid=payload.attrs.get(_CALLER_PN),
129
+ group_jid=payload.attrs.get(_GROUP_JID),
130
+ is_video=has_node_child(payload, _VIDEO),
131
+ caller_username=payload.attrs.get(_USERNAME),
132
+ caller_country_code=payload.attrs.get(_CALLER_COUNTRY_CODE),
133
+ caller_push_name=payload.attrs.get(_NOTIFY),
134
+ peer_platform=node.attrs.get(_PLATFORM),
135
+ peer_app_version=node.attrs.get(_VERSION),
136
+ timestamp_seconds=parse_optional_int(node.attrs.get("t")),
137
+ end_timestamp_seconds=parse_optional_int(node.attrs.get("e")),
138
+ silence_reason=silence_node.attrs.get(_REASON)
139
+ if silence_node is not None
140
+ else None,
141
+ group_info=_parse_group_info(group_info_node)
142
+ if group_info_node is not None
143
+ else None,
144
+ )