From 5cdc6085dcc2e1dfa41cb5f5269a098da0d617c4 Mon Sep 17 00:00:00 2001 From: mayankbohradev Date: Wed, 8 Jul 2026 15:44:13 +0530 Subject: [PATCH] fix: return api key delete response --- resend/api_keys/_api_keys.py | 47 +++++++++++++++++++++++++++--------- tests/api_keys_async_test.py | 18 +++++++++++--- tests/api_keys_test.py | 18 +++++++++----- 3 files changed, 61 insertions(+), 22 deletions(-) diff --git a/resend/api_keys/_api_keys.py b/resend/api_keys/_api_keys.py index c6abe49..3a48801 100644 --- a/resend/api_keys/_api_keys.py +++ b/resend/api_keys/_api_keys.py @@ -57,6 +57,29 @@ class CreateApiKeyResponse(BaseResponse): The token of the created API key """ + class DeleteApiKeyResponse(BaseResponse): + """ + DeleteApiKeyResponse is the type that wraps the deleted API key response. + + Attributes: + object (str): The object type, always "api_key" + id (str): The ID of the deleted API key + deleted (bool): Whether the API key was deleted + """ + + object: str + """ + The object type, always "api_key" + """ + id: str + """ + The ID of the deleted API key + """ + deleted: bool + """ + Whether the API key was deleted + """ + class ListParams(TypedDict): limit: NotRequired[int] """ @@ -134,7 +157,7 @@ def list(cls, params: Optional[ListParams] = None) -> ListResponse: return resp @classmethod - def remove(cls, api_key_id: str) -> None: + def remove(cls, api_key_id: str) -> DeleteApiKeyResponse: """ Remove an existing API key. see more: https://resend.com/docs/api-reference/api-keys/delete-api-key @@ -143,13 +166,13 @@ def remove(cls, api_key_id: str) -> None: api_key_id (str): The ID of the API key to remove Returns: - None + DeleteApiKeyResponse: The deleted API key response """ path = f"/api-keys/{api_key_id}" - - # This would raise if failed - request.Request[None](path=path, params={}, verb="delete").perform() - return None + resp = request.Request[ApiKeys.DeleteApiKeyResponse]( + path=path, params={}, verb="delete" + ).perform_with_content() + return resp @classmethod async def create_async(cls, params: CreateParams) -> CreateApiKeyResponse: @@ -190,7 +213,7 @@ async def list_async(cls, params: Optional[ListParams] = None) -> ListResponse: return resp @classmethod - async def remove_async(cls, api_key_id: str) -> None: + async def remove_async(cls, api_key_id: str) -> DeleteApiKeyResponse: """ Remove an existing API key (async). see more: https://resend.com/docs/api-reference/api-keys/delete-api-key @@ -199,10 +222,10 @@ async def remove_async(cls, api_key_id: str) -> None: api_key_id (str): The ID of the API key to remove Returns: - None + DeleteApiKeyResponse: The deleted API key response """ path = f"/api-keys/{api_key_id}" - - # This would raise if failed - await AsyncRequest[None](path=path, params={}, verb="delete").perform() - return None + resp = await AsyncRequest[ApiKeys.DeleteApiKeyResponse]( + path=path, params={}, verb="delete" + ).perform_with_content() + return resp diff --git a/tests/api_keys_async_test.py b/tests/api_keys_async_test.py index 89610a5..c258805 100644 --- a/tests/api_keys_async_test.py +++ b/tests/api_keys_async_test.py @@ -61,9 +61,19 @@ async def test_should_list_api_key_async_raise_exception_when_no_content( _ = await resend.ApiKeys.list_async() async def test_api_keys_remove_async(self) -> None: - self.set_mock_text("") + self.set_mock_json( + { + "object": "api_key", + "id": "4ef9a417-02e9-4d39-ad75-9611e0fcc33c", + "deleted": True, + } + ) - # Remove operation returns None, verify no exceptions raised - await resend.ApiKeys.remove_async( - api_key_id="4ef9a417-02e9-4d39-ad75-9611e0fcc33c", + deleted_key: resend.ApiKeys.DeleteApiKeyResponse = ( + await resend.ApiKeys.remove_async( + api_key_id="4ef9a417-02e9-4d39-ad75-9611e0fcc33c", + ) ) + assert deleted_key["object"] == "api_key" + assert deleted_key["id"] == "4ef9a417-02e9-4d39-ad75-9611e0fcc33c" + assert deleted_key["deleted"] is True diff --git a/tests/api_keys_test.py b/tests/api_keys_test.py index ed94283..f9e1e42 100644 --- a/tests/api_keys_test.py +++ b/tests/api_keys_test.py @@ -128,11 +128,17 @@ def test_api_keys_list_with_before_param(self) -> None: assert keys["data"][0]["id"] == "test-key-3" def test_api_keys_remove(self) -> None: - self.set_mock_text("") + self.set_mock_json( + { + "object": "api_key", + "id": "4ef9a417-02e9-4d39-ad75-9611e0fcc33c", + "deleted": True, + } + ) - assert ( - resend.ApiKeys.remove( - api_key_id="4ef9a417-02e9-4d39-ad75-9611e0fcc33c", - ) - is None + deleted_key: resend.ApiKeys.DeleteApiKeyResponse = resend.ApiKeys.remove( + api_key_id="4ef9a417-02e9-4d39-ad75-9611e0fcc33c", ) + assert deleted_key["object"] == "api_key" + assert deleted_key["id"] == "4ef9a417-02e9-4d39-ad75-9611e0fcc33c" + assert deleted_key["deleted"] is True