diff --git a/examples/async/domains_async.py b/examples/async/domains_async.py index 0c37ffb..ee12b08 100644 --- a/examples/async/domains_async.py +++ b/examples/async/domains_async.py @@ -32,7 +32,9 @@ async def main() -> None: "tls": "enforced", } - updated_domain: resend.Domain = await resend.Domains.update_async(update_params) + updated_domain: resend.Domains.UpdateDomainResponse = ( + await resend.Domains.update_async(update_params) + ) print(f"Updated domain: {updated_domain['id']}") domains: resend.Domains.ListResponse = await resend.Domains.list_async() @@ -41,13 +43,15 @@ async def main() -> None: for d in domains["data"]: print(d) - verified_domain: resend.Domain = await resend.Domains.verify_async( - domain_id=domain["id"] + verified_domain: resend.Domains.VerifyDomainResponse = ( + await resend.Domains.verify_async(domain_id=domain["id"]) ) - print("Verified") + print("Verification requested") print(verified_domain) - rm_domain: resend.Domain = await resend.Domains.remove_async(domain_id=domain["id"]) + rm_domain: resend.Domains.RemoveDomainResponse = await resend.Domains.remove_async( + domain_id=domain["id"] + ) print(rm_domain) diff --git a/examples/domains.py b/examples/domains.py index 520c5c7..a7d0a24 100644 --- a/examples/domains.py +++ b/examples/domains.py @@ -29,7 +29,9 @@ "tls": "enforced", } -updated_domain: resend.Domain = resend.Domains.update(update_params) +updated_domain: resend.Domains.UpdateDomainResponse = resend.Domains.update( + update_params +) print(f"Updated domain: {updated_domain['id']}") domains: resend.Domains.ListResponse = resend.Domains.list() @@ -54,9 +56,13 @@ else: print("No domains available for pagination example") -verified_domain: resend.Domain = resend.Domains.verify(domain_id=domain["id"]) -print(f"Verified") +verified_domain: resend.Domains.VerifyDomainResponse = resend.Domains.verify( + domain_id=domain["id"] +) +print("Verification requested") print(verified_domain) -rm_domain: resend.Domain = resend.Domains.remove(domain_id=domain["id"]) +rm_domain: resend.Domains.RemoveDomainResponse = resend.Domains.remove( + domain_id=domain["id"] +) print(rm_domain) diff --git a/resend/domains/_domains.py b/resend/domains/_domains.py index aa5f2ca..c59806f 100644 --- a/resend/domains/_domains.py +++ b/resend/domains/_domains.py @@ -117,6 +117,25 @@ class CreateDomainResponse(BaseResponse): The custom subdomain used for click and open tracking links (e.g., "links") """ + class UpdateDomainResponse(BaseResponse): + """Response from updating a domain.""" + + object: str + id: str + + class VerifyDomainResponse(BaseResponse): + """Response from requesting verification of a domain.""" + + object: str + id: str + + class RemoveDomainResponse(BaseResponse): + """Response from removing a domain.""" + + object: str + id: str + deleted: bool + class UpdateParams(TypedDict): id: str """ @@ -194,7 +213,7 @@ def create(cls, params: CreateParams) -> CreateDomainResponse: return resp @classmethod - def update(cls, params: UpdateParams) -> Domain: + def update(cls, params: UpdateParams) -> UpdateDomainResponse: """ Update an existing domain. see more: https://resend.com/docs/api-reference/domains/update-domain @@ -203,10 +222,10 @@ def update(cls, params: UpdateParams) -> Domain: params (UpdateParams): The domain update parameters Returns: - Domain: The updated domain object + UpdateDomainResponse: The domain update acknowledgment """ path = f"/domains/{params['id']}" - resp = request.Request[Domain]( + resp = request.Request[Domains.UpdateDomainResponse]( path=path, params=cast(Dict[Any, Any], params), verb="patch" ).perform_with_content() return resp @@ -254,7 +273,7 @@ def list(cls, params: Optional[ListParams] = None) -> ListResponse: return resp @classmethod - def remove(cls, domain_id: str) -> Domain: + def remove(cls, domain_id: str) -> RemoveDomainResponse: """ Remove an existing domain. see more: https://resend.com/docs/api-reference/domains/delete-domain @@ -263,28 +282,28 @@ def remove(cls, domain_id: str) -> Domain: domain_id (str): The domain ID Returns: - Domain: The removed domain object + RemoveDomainResponse: The domain ID and deletion result """ path = f"/domains/{domain_id}" - resp = request.Request[Domain]( + resp = request.Request[Domains.RemoveDomainResponse]( path=path, params={}, verb="delete" ).perform_with_content() return resp @classmethod - def verify(cls, domain_id: str) -> Domain: + def verify(cls, domain_id: str) -> VerifyDomainResponse: """ - Verify an existing domain. + Request verification of an existing domain. see more: https://resend.com/docs/api-reference/domains/verify-domain Args: domain_id (str): The domain ID Returns: - Domain: The verified domain object + VerifyDomainResponse: The domain verification acknowledgment """ path = f"/domains/{domain_id}/verify" - resp = request.Request[Domain]( + resp = request.Request[Domains.VerifyDomainResponse]( path=path, params={}, verb="post" ).perform_with_content() return resp @@ -308,7 +327,7 @@ async def create_async(cls, params: CreateParams) -> CreateDomainResponse: return resp @classmethod - async def update_async(cls, params: UpdateParams) -> Domain: + async def update_async(cls, params: UpdateParams) -> UpdateDomainResponse: """ Update an existing domain (async). see more: https://resend.com/docs/api-reference/domains/update-domain @@ -317,10 +336,10 @@ async def update_async(cls, params: UpdateParams) -> Domain: params (UpdateParams): The domain update parameters Returns: - Domain: The updated domain object + UpdateDomainResponse: The domain update acknowledgment """ path = f"/domains/{params['id']}" - resp = await AsyncRequest[Domain]( + resp = await AsyncRequest[Domains.UpdateDomainResponse]( path=path, params=cast(Dict[Any, Any], params), verb="patch" ).perform_with_content() return resp @@ -364,7 +383,7 @@ async def list_async(cls, params: Optional[ListParams] = None) -> ListResponse: return resp @classmethod - async def remove_async(cls, domain_id: str) -> Domain: + async def remove_async(cls, domain_id: str) -> RemoveDomainResponse: """ Remove an existing domain (async). see more: https://resend.com/docs/api-reference/domains/delete-domain @@ -373,28 +392,28 @@ async def remove_async(cls, domain_id: str) -> Domain: domain_id (str): The domain ID Returns: - Domain: The removed domain object + RemoveDomainResponse: The domain ID and deletion result """ path = f"/domains/{domain_id}" - resp = await AsyncRequest[Domain]( + resp = await AsyncRequest[Domains.RemoveDomainResponse]( path=path, params={}, verb="delete" ).perform_with_content() return resp @classmethod - async def verify_async(cls, domain_id: str) -> Domain: + async def verify_async(cls, domain_id: str) -> VerifyDomainResponse: """ - Verify an existing domain (async). + Request verification of an existing domain (async). see more: https://resend.com/docs/api-reference/domains/verify-domain Args: domain_id (str): The domain ID Returns: - Domain: The verified domain object + VerifyDomainResponse: The domain verification acknowledgment """ path = f"/domains/{domain_id}/verify" - resp = await AsyncRequest[Domain]( + resp = await AsyncRequest[Domains.VerifyDomainResponse]( path=path, params={}, verb="post" ).perform_with_content() return resp diff --git a/tests/domains_async_test.py b/tests/domains_async_test.py index c9f900b..f91a3a5 100644 --- a/tests/domains_async_test.py +++ b/tests/domains_async_test.py @@ -1,4 +1,5 @@ import pytest +from typing_extensions import assert_type import resend from resend.exceptions import NoContentError @@ -265,10 +266,6 @@ async def test_domains_update_async(self) -> None: { "object": "domain", "id": "d91cd9bd-1176-453e-8fc1-35364d380206", - "name": "example.com", - "status": "not_started", - "created_at": "2023-04-26 20:21:26.347412+00", - "region": "us-east-1", } ) @@ -279,11 +276,9 @@ async def test_domains_update_async(self) -> None: "tls": "enforced", } domain = await resend.Domains.update_async(params=update_params) + assert_type(domain, resend.Domains.UpdateDomainResponse) + assert domain["object"] == "domain" assert domain["id"] == "d91cd9bd-1176-453e-8fc1-35364d380206" - assert domain["name"] == "example.com" - assert domain["status"] == "not_started" - assert domain["created_at"] == "2023-04-26 20:21:26.347412+00" - assert domain["region"] == "us-east-1" async def test_domains_update_async_with_tracking_subdomain(self) -> None: self.set_mock_json( @@ -315,22 +310,18 @@ async def test_domains_remove_async(self) -> None: self.set_mock_json( { "object": "domain", + "deleted": True, "id": "d91cd9bd-1176-453e-8fc1-35364d380206", - "name": "example.com", - "status": "not_started", - "created_at": "2023-04-26 20:21:26.347412+00", - "region": "us-east-1", } ) domain = await resend.Domains.remove_async( domain_id="d91cd9bd-1176-453e-8fc1-35364d380206", ) + assert_type(domain, resend.Domains.RemoveDomainResponse) + assert domain["object"] == "domain" assert domain["id"] == "d91cd9bd-1176-453e-8fc1-35364d380206" - assert domain["name"] == "example.com" - assert domain["status"] == "not_started" - assert domain["created_at"] == "2023-04-26 20:21:26.347412+00" - assert domain["region"] == "us-east-1" + assert domain["deleted"] is True async def test_should_remove_domains_async_raise_exception_when_no_content( self, @@ -346,21 +337,15 @@ async def test_domains_verify_async(self) -> None: { "object": "domain", "id": "d91cd9bd-1176-453e-8fc1-35364d380206", - "name": "example.com", - "status": "verified", - "created_at": "2023-04-26 20:21:26.347412+00", - "region": "us-east-1", } ) domain = await resend.Domains.verify_async( domain_id="d91cd9bd-1176-453e-8fc1-35364d380206", ) + assert_type(domain, resend.Domains.VerifyDomainResponse) + assert domain["object"] == "domain" assert domain["id"] == "d91cd9bd-1176-453e-8fc1-35364d380206" - assert domain["name"] == "example.com" - assert domain["status"] == "verified" - assert domain["created_at"] == "2023-04-26 20:21:26.347412+00" - assert domain["region"] == "us-east-1" async def test_should_verify_domains_async_raise_exception_when_no_content( self, diff --git a/tests/domains_test.py b/tests/domains_test.py index 53ae913..cf6863b 100644 --- a/tests/domains_test.py +++ b/tests/domains_test.py @@ -1,3 +1,5 @@ +from typing_extensions import assert_type + import resend from resend.exceptions import NoContentError from tests.conftest import ResendBaseTest @@ -154,6 +156,8 @@ def test_domains_remove(self) -> None: domain_id="4ef9a417-02e9-4d39-ad75-9611e0fcc33c", ) assert domain["deleted"] is True + assert_type(domain, resend.Domains.RemoveDomainResponse) + assert domain["object"] == "domain" assert domain["id"] == "4ef9a417-02e9-4d39-ad75-9611e0fcc33c" def test_should_remove_domains_raise_exception_when_no_content(self) -> None: @@ -171,6 +175,8 @@ def test_domains_verify(self) -> None: domain = resend.Domains.verify( domain_id="d91cd9bd-1176-453e-8fc1-35364d380206", ) + assert_type(domain, resend.Domains.VerifyDomainResponse) + assert domain["object"] == "domain" assert domain["id"] == "d91cd9bd-1176-453e-8fc1-35364d380206" def test_should_verify_domains_raise_exception_when_no_content(self) -> None: @@ -311,6 +317,8 @@ def test_domains_update(self) -> None: "tls": "opportunistic", } domain = resend.Domains.update(params) + assert_type(domain, resend.Domains.UpdateDomainResponse) + assert domain["object"] == "domain" assert domain["id"] == "479e3145-dd38-476b-932c-529ceb705947" def test_domains_update_with_tracking_subdomain(self) -> None: