buzzkit 0.2.0__tar.gz → 0.2.1__tar.gz

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 (36) hide show
  1. {buzzkit-0.2.0 → buzzkit-0.2.1}/Cargo.lock +1 -1
  2. {buzzkit-0.2.0 → buzzkit-0.2.1}/Cargo.toml +1 -1
  3. {buzzkit-0.2.0 → buzzkit-0.2.1}/PKG-INFO +1 -1
  4. {buzzkit-0.2.0 → buzzkit-0.2.1}/pyproject.toml +1 -1
  5. {buzzkit-0.2.0 → buzzkit-0.2.1}/python/buzzkit/client.py +27 -12
  6. {buzzkit-0.2.0 → buzzkit-0.2.1}/src/lib.rs +4 -2
  7. buzzkit-0.2.1/tests/test_client.py +27 -0
  8. {buzzkit-0.2.0 → buzzkit-0.2.1}/.cargo/config.toml +0 -0
  9. {buzzkit-0.2.0 → buzzkit-0.2.1}/.github/workflows/CI.yml +0 -0
  10. {buzzkit-0.2.0 → buzzkit-0.2.1}/.github/workflows/release.yml +0 -0
  11. {buzzkit-0.2.0 → buzzkit-0.2.1}/.gitignore +0 -0
  12. {buzzkit-0.2.0 → buzzkit-0.2.1}/LICENSE +0 -0
  13. {buzzkit-0.2.0 → buzzkit-0.2.1}/LICENSE-APACHE +0 -0
  14. {buzzkit-0.2.0 → buzzkit-0.2.1}/NOTICE +0 -0
  15. {buzzkit-0.2.0 → buzzkit-0.2.1}/README.md +0 -0
  16. {buzzkit-0.2.0 → buzzkit-0.2.1}/build-support/vendored-libopus.cmake +0 -0
  17. {buzzkit-0.2.0 → buzzkit-0.2.1}/examples/_shared.py +0 -0
  18. {buzzkit-0.2.0 → buzzkit-0.2.1}/examples/analyze_audio_tap.py +0 -0
  19. {buzzkit-0.2.0 → buzzkit-0.2.1}/examples/claim_invite.py +0 -0
  20. {buzzkit-0.2.0 → buzzkit-0.2.1}/examples/huddle_echo.py +0 -0
  21. {buzzkit-0.2.0 → buzzkit-0.2.1}/examples/huddle_wire_recorder.py +0 -0
  22. {buzzkit-0.2.0 → buzzkit-0.2.1}/examples/list_channels.py +0 -0
  23. {buzzkit-0.2.0 → buzzkit-0.2.1}/examples/offline_sign.py +0 -0
  24. {buzzkit-0.2.0 → buzzkit-0.2.1}/examples/send_message.py +0 -0
  25. {buzzkit-0.2.0 → buzzkit-0.2.1}/examples/set_profile.py +0 -0
  26. {buzzkit-0.2.0 → buzzkit-0.2.1}/examples/subscribe.py +0 -0
  27. {buzzkit-0.2.0 → buzzkit-0.2.1}/python/buzzkit/__init__.py +0 -0
  28. {buzzkit-0.2.0 → buzzkit-0.2.1}/python/buzzkit/_native.pyi +0 -0
  29. {buzzkit-0.2.0 → buzzkit-0.2.1}/python/buzzkit/agents.py +0 -0
  30. {buzzkit-0.2.0 → buzzkit-0.2.1}/python/buzzkit/huddle.py +0 -0
  31. {buzzkit-0.2.0 → buzzkit-0.2.1}/python/buzzkit/py.typed +0 -0
  32. {buzzkit-0.2.0 → buzzkit-0.2.1}/src/huddle.rs +0 -0
  33. {buzzkit-0.2.0 → buzzkit-0.2.1}/tests/test_agents.py +0 -0
  34. {buzzkit-0.2.0 → buzzkit-0.2.1}/tests/test_huddle.py +0 -0
  35. {buzzkit-0.2.0 → buzzkit-0.2.1}/tests/test_live_relay.py +0 -0
  36. {buzzkit-0.2.0 → buzzkit-0.2.1}/tests/test_signing.py +0 -0
@@ -180,7 +180,7 @@ dependencies = [
180
180
 
181
181
  [[package]]
182
182
  name = "buzzkit"
183
- version = "0.2.0"
183
+ version = "0.2.1"
184
184
  dependencies = [
185
185
  "base64",
186
186
  "buzz-core",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "buzzkit"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  edition = "2021"
5
5
  publish = false
6
6
  description = "PyO3 bindings over Block's Buzz zero-I/O crates (buzz-core / buzz-sdk)"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: buzzkit
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Classifier: Development Status :: 3 - Alpha
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: License :: OSI Approved :: MIT License
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "buzzkit"
7
- version = "0.2.0"
7
+ version = "0.2.1"
8
8
  description = "Python bindings + async client for Block's Buzz (Nostr) protocol, backed by Rust buzz-core/buzz-sdk"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -37,6 +37,17 @@ _OK_TIMEOUT = 20.0
37
37
  _MAX_FRAME = 1 << 20 # 1 MiB — matches the relay's max frame size
38
38
 
39
39
 
40
+ def _checked(r: httpx.Response) -> httpx.Response:
41
+ """Raise a readable error carrying the relay's response body on 4xx/5xx.
42
+
43
+ The bridge explains rejections in the body (e.g. ``{"error": "invalid:
44
+ edit target event not found"}``); a bare ``raise_for_status`` hides it.
45
+ """
46
+ if r.status_code >= 400:
47
+ raise RuntimeError(f"HTTP bridge error {r.status_code} on {r.url.path}: {r.text}")
48
+ return r
49
+
50
+
40
51
  def _to_http(relay_url: str) -> str:
41
52
  u = relay_url.rstrip("/")
42
53
  if u.startswith("wss://"):
@@ -83,7 +94,12 @@ class BuzzClient:
83
94
  return _native.sign_nip98(self._secret, method, url, body)
84
95
 
85
96
  async def post_event(self, event_json: str) -> dict:
86
- """POST a signed event to the HTTP bridge (non-ephemeral kinds only)."""
97
+ """POST a signed event to the HTTP bridge (non-ephemeral kinds only).
98
+
99
+ The bridge acknowledges before the event is fully indexed: a revision
100
+ (edit/delete/reaction) sent immediately after its target can be
101
+ rejected with "target event not found". Retrying is the caller's call.
102
+ """
87
103
  url = f"{self._http}/events"
88
104
  body = event_json.encode("utf-8")
89
105
  headers = {
@@ -91,9 +107,7 @@ class BuzzClient:
91
107
  "Content-Type": "application/json",
92
108
  }
93
109
  async with httpx.AsyncClient(timeout=20.0) as c:
94
- r = await c.post(url, content=body, headers=headers)
95
- r.raise_for_status()
96
- return r.json()
110
+ return _checked(await c.post(url, content=body, headers=headers)).json()
97
111
 
98
112
  async def send_message(
99
113
  self,
@@ -133,7 +147,12 @@ class BuzzClient:
133
147
  self, channel_id: str, target_event_id: str, *, reason: str | None = None
134
148
  ) -> dict:
135
149
  """Delete a message (kind 9005 tombstone). Management kind — needs
136
- :meth:`connect` first; ``reason`` is shown room-facing."""
150
+ :meth:`connect` first.
151
+
152
+ ``reason`` (the room-facing ``public_reason``) marks the tombstone as
153
+ a MODERATION action: the relay then requires channel owner/admin
154
+ rights, and rejects it even for the message's own author. Omit it to
155
+ delete your own message."""
137
156
  ev = _native.build_delete_message_event(self._secret, channel_id, target_event_id, reason)
138
157
  return await self.publish(ev)
139
158
 
@@ -234,9 +253,7 @@ class BuzzClient:
234
253
  "Content-Type": "application/json",
235
254
  }
236
255
  async with httpx.AsyncClient(timeout=20.0) as c:
237
- r = await c.post(url, content=body, headers=headers)
238
- r.raise_for_status()
239
- data = r.json()
256
+ data = _checked(await c.post(url, content=body, headers=headers)).json()
240
257
  return data if isinstance(data, list) else []
241
258
 
242
259
  async def list_channels(self) -> list[dict]:
@@ -323,8 +340,7 @@ class BuzzClient:
323
340
  "age_confirmed": True,
324
341
  },
325
342
  )
326
- rp.raise_for_status()
327
- receipt = rp.json()["receipt"]
343
+ receipt = _checked(rp).json()["receipt"]
328
344
  payload: dict = {"code": code}
329
345
  if receipt:
330
346
  payload["policy_receipt"] = receipt
@@ -335,8 +351,7 @@ class BuzzClient:
335
351
  "Content-Type": "application/json",
336
352
  }
337
353
  rc = await c.post(url, content=body, headers=headers)
338
- rc.raise_for_status()
339
- return rc.json()
354
+ return _checked(rc).json()
340
355
 
341
356
  # ------------------------------------------------------------- WebSocket
342
357
 
@@ -136,8 +136,10 @@ fn build_edit_event(
136
136
  }
137
137
 
138
138
  /// Build and sign a message delete tombstone (kind 9005). `reason`, when
139
- /// given, becomes the room-facing `public_reason` tag. Management kind —
140
- /// publish over the WebSocket.
139
+ /// given, becomes the room-facing `public_reason` tag — which marks the
140
+ /// tombstone as a moderation action the relay only accepts from a channel
141
+ /// owner/admin (authors deleting their own message must omit it).
142
+ /// Management kind — publish over the WebSocket.
141
143
  #[pyfunction]
142
144
  #[pyo3(signature = (secret, channel_id, target_event_id, reason=None))]
143
145
  fn build_delete_message_event(
@@ -0,0 +1,27 @@
1
+ """Offline tests for BuzzClient's HTTP bridge error surfacing."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import uuid
6
+
7
+ import buzzkit
8
+ import httpx
9
+ import pytest
10
+ from buzzkit.client import BuzzClient
11
+
12
+
13
+ async def test_post_event_surfaces_relay_error_body(monkeypatch):
14
+ def handler(request: httpx.Request) -> httpx.Response:
15
+ return httpx.Response(400, json={"error": "invalid: edit target event not found"})
16
+
17
+ real = httpx.AsyncClient
18
+ monkeypatch.setattr(
19
+ httpx,
20
+ "AsyncClient",
21
+ lambda **kw: real(transport=httpx.MockTransport(handler), timeout=1),
22
+ )
23
+ nsec, _, _ = buzzkit.generate_keypair()
24
+ bz = BuzzClient("wss://relay.example", nsec)
25
+ ev = buzzkit.build_message_event(nsec, str(uuid.uuid4()), "x")
26
+ with pytest.raises(RuntimeError, match="edit target event not found"):
27
+ await bz.post_event(ev)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes