-
Notifications
You must be signed in to change notification settings - Fork 8
Add Suppressions API support (add + list + get + remove + batch) #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e80767e
Add Suppressions API support (add + list + get + remove + batch)
felipefreitag 173c724
Suppressions: reject blank identifiers, derive origin query value fro…
felipefreitag 8b42c42
Mock server: reject blank suppression batch entries instead of crashing
felipefreitag c8bb622
Json: allow enum aliases, reject conflicting wire values
felipefreitag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| using System.Reflection; | ||
|
|
||
| namespace Resend; | ||
|
|
||
| /// <summary> | ||
| /// Wire values of <typeparamref name="T"/>, as declared by <see cref="JsonStringValueAttribute"/>. | ||
| /// </summary> | ||
| internal static class JsonStringEnumValue<T> | ||
| where T : struct, Enum | ||
| { | ||
| /// <summary /> | ||
| static JsonStringEnumValue() | ||
| { | ||
| var tt = typeof( T ); | ||
|
|
||
| var names = tt.GetEnumNames(); | ||
| var values = tt.GetEnumValues(); | ||
|
|
||
| var fwd = new Dictionary<T, string>( names.Length ); | ||
| var rev = new Dictionary<string, T>( names.Length ); | ||
|
|
||
| for ( var i = 0; i < names.Length; i++ ) | ||
| { | ||
| var name = names[ i ]; | ||
| var field = tt.GetField( name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static )!; | ||
|
|
||
| var str = field.GetCustomAttribute<JsonStringValueAttribute>()?.Value ?? name; | ||
| var val = (T) values.GetValue( i )!; | ||
|
|
||
| fwd.Add( val, str ); | ||
| rev.Add( str, val ); | ||
| } | ||
|
|
||
| Forward = fwd; | ||
| Reverse = rev; | ||
| } | ||
|
|
||
|
|
||
| /// <summary /> | ||
| public static IReadOnlyDictionary<T, string> Forward { get; } | ||
|
|
||
|
|
||
| /// <summary /> | ||
| public static IReadOnlyDictionary<string, T> Reverse { get; } | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Wire value of <paramref name="value"/>, for use outside of JSON serialization -- eg. in | ||
| /// query string parameters. | ||
| /// </summary> | ||
| /// <param name="value">Enumeration value.</param> | ||
| /// <returns>Wire value.</returns> | ||
| /// <exception cref="ArgumentOutOfRangeException"> | ||
| /// Thrown when <paramref name="value"/> is not a member of <typeparamref name="T"/>. | ||
| /// </exception> | ||
| public static string Of( T value ) | ||
| { | ||
| if ( Forward.TryGetValue( value, out var str ) == false ) | ||
| throw new ArgumentOutOfRangeException( nameof( value ), $"Invalid '{typeof( T ).Name}' value: '{value}'" ); | ||
|
|
||
| return str; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Resend.Payloads; | ||
|
|
||
| /// <summary> | ||
| /// Request object to add a suppression. | ||
| /// </summary> | ||
| public class SuppressionAddRequest | ||
| { | ||
| /// <summary> | ||
| /// Email address to suppress. | ||
| /// </summary> | ||
| [JsonPropertyName( "email" )] | ||
| public string Email { get; set; } = default!; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Resend.Payloads; | ||
|
|
||
| /// <summary> | ||
| /// Request object to add up to 100 suppressions at once. | ||
| /// </summary> | ||
| public class SuppressionBatchAddRequest | ||
| { | ||
| /// <summary> | ||
| /// Email addresses to suppress. | ||
| /// </summary> | ||
| [JsonPropertyName( "emails" )] | ||
| public List<string> Emails { get; set; } = default!; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Resend.Payloads; | ||
|
|
||
| /// <summary> | ||
| /// Request object to remove up to 100 suppressions at once. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The API accepts either <see cref="Emails"/> or <see cref="Ids"/>, never both, and | ||
| /// rejects an explicit null -- hence the unset one is omitted from the payload rather | ||
| /// than written as null. | ||
| /// </remarks> | ||
| public class SuppressionBatchRemoveRequest | ||
| { | ||
| /// <summary> | ||
| /// Email addresses to remove from the suppression list. | ||
| /// </summary> | ||
| [JsonPropertyName( "emails" )] | ||
| [JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )] | ||
| public List<string>? Emails { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Suppression identifiers to remove from the suppression list. | ||
| /// </summary> | ||
| [JsonPropertyName( "ids" )] | ||
| [JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )] | ||
| public List<Guid>? Ids { get; set; } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.