diff --git a/src/Resend/Domain.cs b/src/Resend/Domain.cs index 04797dd..628203c 100644 --- a/src/Resend/Domain.cs +++ b/src/Resend/Domain.cs @@ -21,7 +21,7 @@ public class Domain /// Validation status. /// [JsonPropertyName( "status" )] - public ValidationStatus Status { get; set; } + public DomainStatus Status { get; set; } /// /// Moment when the domain was created. diff --git a/src/Resend/DomainRecord.cs b/src/Resend/DomainRecord.cs index c012d0b..6d8317a 100644 --- a/src/Resend/DomainRecord.cs +++ b/src/Resend/DomainRecord.cs @@ -49,5 +49,5 @@ public class DomainRecord /// Validation status of individual DNS record. /// [JsonPropertyName( "status" )] - public ValidationStatus Status { get; set; } + public DomainRecordStatus Status { get; set; } } diff --git a/src/Resend/DomainRecordStatus.cs b/src/Resend/DomainRecordStatus.cs new file mode 100644 index 0000000..fd71de2 --- /dev/null +++ b/src/Resend/DomainRecordStatus.cs @@ -0,0 +1,49 @@ +using System.Text.Json.Serialization; + +namespace Resend; + +/// +/// +/// +[JsonConverter( typeof( JsonStringEnumValueConverter ) )] +public enum DomainRecordStatus +{ + /// + /// Record validation hasn't been explicitly requested. + /// + [JsonStringValue( "not_started" )] + NotStarted, + + /// + /// Record validation has been started and is currently executing. + /// + [JsonStringValue( "pending" )] + Pending, + + /// + /// Record validation has failed: Resend was unable to detect the + /// necessary DNS record within 72h. + /// + [JsonStringValue( "failed" )] + Failed, + + /// + /// Previously verified DNS record no longer resolves. + /// + /// + /// For a previously verified record, Resend will periodically check for the DNS + /// record required for verification. If at some point, Resend is unable to detect + /// the record, the status would change to “”. Resend will + /// recheck for the DNS record for 72 hours, and if it’s unable to detect the + /// record, the record status would change to “”. If it’s able to detect + /// the record, the record status would change to “”. + /// + [JsonStringValue( "temporary_failure" )] + TemporaryFailure, + + /// + /// DNS record is successfully verified. + /// + [JsonStringValue( "verified" )] + Verified, +} diff --git a/src/Resend/DomainStatus.cs b/src/Resend/DomainStatus.cs new file mode 100644 index 0000000..38fdeae --- /dev/null +++ b/src/Resend/DomainStatus.cs @@ -0,0 +1,56 @@ +using System.Text.Json.Serialization; + +namespace Resend; + +/// +/// +/// +[JsonConverter( typeof( JsonStringEnumValueConverter ) )] +public enum DomainStatus +{ + /// + /// Domain has been created, but validation hasn't been explicitly requested. + /// + /// + /// Validation can be initiated by calling the + /// method. + /// + [JsonStringValue( "not_started" )] + NotStarted, + + /// + /// Validation has been started and is currently executing. + /// + /// + /// May take up to 72h to conclude. + /// + [JsonStringValue( "pending" )] + Pending, + + /// + /// Validation has failed: Resend was unable to detect necessary DNS + /// records within 72h. + /// + [JsonStringValue( "failed" )] + Failed, + + /// + /// Domain is successfully verified for sending in Resend. + /// + [JsonStringValue( "verified" )] + Verified, + + /// + /// Domain is partially verified: some capabilities (for example, + /// sending) are verified while others are still pending. + /// + [JsonStringValue( "partially_verified" )] + PartiallyVerified, + + /// + /// Domain is partially failed: some capabilities are verified while + /// others have failed validation. + /// + [JsonStringValue( "partially_failed" )] + PartiallyFailed, +} diff --git a/tests/Resend.Tests/DomainTests.cs b/tests/Resend.Tests/DomainTests.cs index 4a20515..474da45 100644 --- a/tests/Resend.Tests/DomainTests.cs +++ b/tests/Resend.Tests/DomainTests.cs @@ -125,7 +125,59 @@ public void Domain_deserializes_tracking_caa_record() Assert.Equal( "0 issue \"amazon.com\"", trackingCaa.Value ); Assert.Equal( "CAA", trackingCaa.RecordType ); Assert.Equal( "Auto", trackingCaa.TimeToLive ); - Assert.Equal( ValidationStatus.Verified, trackingCaa.Status ); + Assert.Equal( DomainRecordStatus.Verified, trackingCaa.Status ); + } + + + /// + [Fact] + public void Domain_deserializes_partially_verified_status() + { + const string json = """ + { + "id": "fd61172c-cafc-40f5-b049-b45947779a29", + "name": "resend.com", + "status": "partially_verified", + "created_at": "2023-06-21T06:10:36.144Z", + "region": "us-east-1", + "click_tracking": true, + "tracking_subdomain": "track", + "capabilities": { + "sending": "enabled", + "receiving": "disabled" + }, + "records": [] + } + """; + + var domain = JsonSerializer.Deserialize( json ); + Assert.NotNull( domain ); + Assert.Equal( DomainStatus.PartiallyVerified, domain!.Status ); + } + + + /// + [Fact] + public void Domain_deserializes_partially_failed_status() + { + const string json = """ + { + "id": "fd61172c-cafc-40f5-b049-b45947779a29", + "name": "resend.com", + "status": "partially_failed", + "created_at": "2023-06-21T06:10:36.144Z", + "region": "us-east-1", + "capabilities": { + "sending": "enabled", + "receiving": "enabled" + }, + "records": [] + } + """; + + var domain = JsonSerializer.Deserialize( json ); + Assert.NotNull( domain ); + Assert.Equal( DomainStatus.PartiallyFailed, domain!.Status ); } diff --git a/tools/Resend.ApiServer/Controllers/DomainController.cs b/tools/Resend.ApiServer/Controllers/DomainController.cs index 48e125a..37f7201 100644 --- a/tools/Resend.ApiServer/Controllers/DomainController.cs +++ b/tools/Resend.ApiServer/Controllers/DomainController.cs @@ -29,7 +29,7 @@ public Domain DomainAdd( [FromBody] DomainAddData request ) Id = Guid.NewGuid(), Name = "example.com", Region = DeliveryRegion.UsEast1, - Status = ValidationStatus.NotStarted, + Status = DomainStatus.NotStarted, MomentCreated = DateTime.UtcNow, Records = new List() { @@ -39,7 +39,7 @@ public Domain DomainAdd( [FromBody] DomainAddData request ) RecordType = "TXT", Name = "bounces", TimeToLive = "Auto", - Status = ValidationStatus.NotStarted, + Status = DomainRecordStatus.NotStarted, Value = "feedback-smtp.us-east-1.amazonses.com", }, }, @@ -59,7 +59,7 @@ public Domain DomainRetrieve( [FromRoute] Guid id ) Id = id, Name = "example.com", Region = DeliveryRegion.UsEast1, - Status = ValidationStatus.NotStarted, + Status = DomainStatus.NotStarted, MomentCreated = DateTime.UtcNow, Records = new List() { @@ -69,7 +69,7 @@ public Domain DomainRetrieve( [FromRoute] Guid id ) RecordType = "TXT", Name = "bounces", TimeToLive = "Auto", - Status = ValidationStatus.NotStarted, + Status = DomainRecordStatus.NotStarted, Value = "feedback-smtp.us-east-1.amazonses.com", }, }, @@ -123,7 +123,7 @@ public ListOf DomainList() Id = Guid.NewGuid(), Name = "example.com", Region = DeliveryRegion.UsEast1, - Status = ValidationStatus.NotStarted, + Status = DomainStatus.NotStarted, MomentCreated = DateTime.UtcNow, }, new Domain() @@ -131,7 +131,7 @@ public ListOf DomainList() Id = Guid.NewGuid(), Name = "amazing.com", Region = DeliveryRegion.EuWest1, - Status = ValidationStatus.Pending, + Status = DomainStatus.Pending, MomentCreated = DateTime.UtcNow, } },