fix(broadcasts): accept preview_text and topic_id in create and update params

Merged
RA
10d ago
+77-0

Summary

The broadcasts create and update endpoints accept preview_text and topic_id, and Broadcast already returns preview_text. Broadcasts.CreateParams and Broadcasts.UpdateParams declare neither key, so with the repository's strict mypy settings a call such as the following fails type checking with Extra keys ("preview_text", "topic_id") for TypedDict "CreateParams":

params: resend.Broadcasts.CreateParams = {
    "segment_id": "78b8d3bc-a55a-45a3-aee6-6ec0a5e13d7e",
    "from": "hi@example.com",
    "subject": "Hello, world!",
    "preview_text": "Product updates for this month",
    "topic_id": "b6d24b8e-af0b-4c3c-be0c-359bbd97381e",
}

This change adds preview_text and topic_id as NotRequired[str] to both TypedDicts, with the descriptions from the API reference. The request code already sends the params dict as the body, so no runtime change is needed.

Testing

  • TestBroadcastsRequestBody in tests/broadcasts_test.py creates and updates a broadcast with both keys through a mocked HTTP client, and checks that both reach the JSON body.
  • Without the source change, mypy --ignore-missing-imports resend/ examples/ tests/ reports the two typeddict-unknown-key errors on the new tests. With the change, those errors are gone. The tests pass at runtime either way, because TypedDicts are not enforced at runtime.
  • pytest tests (703 passed) and flake8 --max-line-length=130 ./resend/ pass.

Summary by cubic

Adds preview_text and topic_id to Broadcasts.CreateParams and UpdateParams so calls using these keys pass mypy type checking. topic_id is NotRequired[Union[str, None]] to match the API, where null removes the topic from the broadcast on update.

Adds tests verifying both keys reach the JSON body for create and update requests, including a null topic_id on update.