(rawBody: string)
| 127 | }; |
| 128 | |
| 129 | const parseResendBody = (rawBody: string): IResendEventBase => { |
| 130 | let parsed: unknown; |
| 131 | |
| 132 | try { |
| 133 | parsed = JSON.parse(rawBody); |
| 134 | } catch (error: unknown) { |
| 135 | throw ApiErrors.validation( |
| 136 | `Resend webhook body is not a valid JSON event: ${ |
| 137 | error instanceof Error ? error.message : "unknown" |
| 138 | }` |
| 139 | ); |
| 140 | } |
| 141 | |
| 142 | if (!isResendEventShape(parsed)) { |
| 143 | throw ApiErrors.validation( |
| 144 | "Resend webhook body is missing a string `type` field" |
| 145 | ); |
| 146 | } |
| 147 | |
| 148 | return parsed; |
| 149 | }; |
| 150 | |
| 151 | const isResendEventShape = (value: unknown): value is IResendEventBase => { |
| 152 | if (value === null || typeof value !== "object") { |
no test coverage detected