| | | 1 | | namespace Kestrun.Callback; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents a request to perform a callback operation. |
| | | 5 | | /// </summary> |
| | | 6 | | public class CallbackRequest |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Stable id for tracking |
| | | 10 | | /// </summary> |
| | 4 | 11 | | public string CallbackId { get; } // stable id for tracking |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// E.g. createPayment |
| | | 15 | | /// </summary> |
| | 29 | 16 | | public string OperationId { get; set; } // e.g. createPayment |
| | | 17 | | /// <summary> |
| | | 18 | | /// The URL to which the callback request will be sent |
| | | 19 | | /// </summary> |
| | 37 | 20 | | public Uri TargetUrl { get; set; } |
| | | 21 | | /// <summary> |
| | | 22 | | /// HTTP method to use for the callback (e.g., POST, PUT) |
| | | 23 | | /// </summary> |
| | 7 | 24 | | public string HttpMethod { get; } // POST, PUT, etc. |
| | | 25 | | /// <summary> |
| | | 26 | | /// HTTP headers to include in the callback request |
| | | 27 | | /// </summary> |
| | 36 | 28 | | public IDictionary<string, string> Headers { get; set; } |
| | | 29 | | /// <summary> |
| | | 30 | | /// The content type of the callback request body |
| | | 31 | | /// </summary> |
| | 5 | 32 | | public string ContentType { get; } |
| | | 33 | | /// <summary> |
| | | 34 | | /// The body of the callback request |
| | | 35 | | /// </summary> |
| | 39 | 36 | | public byte[]? Body { get; set; } |
| | | 37 | | /// <summary> |
| | | 38 | | /// Trace or correlation identifier |
| | | 39 | | /// </summary> |
| | 34 | 40 | | public string CorrelationId { get; set; } // trace/correlation |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Key for receiver deduplication |
| | | 44 | | /// </summary> |
| | 35 | 45 | | public string IdempotencyKey { get; set; } // for receiver dedupe |
| | | 46 | | /// <summary> |
| | | 47 | | /// Attempt number, starting at 0 |
| | | 48 | | /// </summary> |
| | 51 | 49 | | public int Attempt { get; set; } // starts at 0 |
| | | 50 | | /// <summary> |
| | | 51 | | /// Timestamp when the callback request was created |
| | | 52 | | /// </summary> |
| | 30 | 53 | | public DateTimeOffset CreatedAt { get; } |
| | | 54 | | /// <summary> |
| | | 55 | | /// Timestamp for the next attempt |
| | | 56 | | /// </summary> |
| | 41 | 57 | | public DateTimeOffset NextAttemptAt { get; set; } |
| | | 58 | | /// <summary> |
| | | 59 | | /// Timeout duration for the callback request |
| | | 60 | | /// </summary> |
| | 34 | 61 | | public TimeSpan Timeout { get; set; } |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// Initializes a new instance of the <see cref="CallbackRequest"/> class. |
| | | 65 | | /// </summary> |
| | | 66 | | /// <param name="callbackId"> </param> |
| | | 67 | | /// <param name="operationId"></param> |
| | | 68 | | /// <param name="targetUrl"></param> |
| | | 69 | | /// <param name="httpMethod"></param> |
| | | 70 | | /// <param name="headers"></param> |
| | | 71 | | /// <param name="contentType"></param> |
| | | 72 | | /// <param name="body"></param> |
| | | 73 | | /// <param name="correlationId"></param> |
| | | 74 | | /// <param name="idempotencyKey"></param> |
| | | 75 | | /// <param name="timeout"></param> |
| | 28 | 76 | | public CallbackRequest( |
| | 28 | 77 | | string callbackId, |
| | 28 | 78 | | string operationId, |
| | 28 | 79 | | Uri targetUrl, |
| | 28 | 80 | | string httpMethod, |
| | 28 | 81 | | IDictionary<string, string> headers, |
| | 28 | 82 | | string contentType, |
| | 28 | 83 | | byte[]? body, |
| | 28 | 84 | | string correlationId, |
| | 28 | 85 | | string idempotencyKey, |
| | 28 | 86 | | TimeSpan timeout) |
| | | 87 | | { |
| | 28 | 88 | | CallbackId = callbackId; |
| | 28 | 89 | | OperationId = operationId; |
| | 28 | 90 | | TargetUrl = targetUrl; |
| | 28 | 91 | | HttpMethod = httpMethod; |
| | | 92 | | |
| | 28 | 93 | | Headers = headers; |
| | 28 | 94 | | ContentType = contentType; |
| | 28 | 95 | | Body = body; |
| | | 96 | | |
| | 28 | 97 | | CorrelationId = correlationId; |
| | 28 | 98 | | IdempotencyKey = idempotencyKey; |
| | | 99 | | |
| | 28 | 100 | | Attempt = 0; |
| | 28 | 101 | | CreatedAt = DateTimeOffset.UtcNow; |
| | 28 | 102 | | NextAttemptAt = CreatedAt; |
| | 28 | 103 | | Timeout = timeout; |
| | 28 | 104 | | } |
| | | 105 | | } |