( method: string, body: Record<string, unknown> | undefined, requestId: string, path: string )
| 169 | * before a webhook row exists and therefore before provider lookup is possible. |
| 170 | */ |
| 171 | export async function handlePreLookupWebhookVerification( |
| 172 | method: string, |
| 173 | body: Record<string, unknown> | undefined, |
| 174 | requestId: string, |
| 175 | path: string |
| 176 | ): Promise<NextResponse | null> { |
| 177 | const pendingVerification = await getPendingWebhookVerification(path) |
| 178 | if (!pendingVerification) { |
| 179 | return null |
| 180 | } |
| 181 | |
| 182 | if (!matchesPendingWebhookVerificationProbe(pendingVerification, { method, body })) { |
| 183 | return null |
| 184 | } |
| 185 | |
| 186 | logger.info( |
| 187 | `[${requestId}] Returning 200 for pending ${pendingVerification.provider} webhook verification on path: ${path}` |
| 188 | ) |
| 189 | |
| 190 | return NextResponse.json({ status: 'ok', message: 'Webhook endpoint verified' }) |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Handle provider-specific reachability tests that occur AFTER webhook lookup. |
no test coverage detected