(event: HandlerEvent<"HTTP">, logger: Logger)
| 293 | } |
| 294 | |
| 295 | async function webhookHandler(event: HandlerEvent<"HTTP">, logger: Logger) { |
| 296 | logger.debug("[inside typeform integration] Handling typeform webhook handler"); |
| 297 | |
| 298 | const { rawEvent: request, source } = event; |
| 299 | |
| 300 | if (!request.body) { |
| 301 | logger.debug("[inside typeform integration] No body found"); |
| 302 | |
| 303 | return; |
| 304 | } |
| 305 | |
| 306 | const rawBody = await request.text(); |
| 307 | |
| 308 | const signature = request.headers.get("typeform-signature"); |
| 309 | |
| 310 | if (!signature) { |
| 311 | logger.debug("[inside typeform integration] No signature found"); |
| 312 | |
| 313 | return { events: [] }; |
| 314 | } |
| 315 | |
| 316 | const hash = createHmac("sha256", source.secret).update(rawBody).digest("base64"); |
| 317 | |
| 318 | const actualSig = `sha256=${hash}`; |
| 319 | |
| 320 | if (signature !== actualSig) { |
| 321 | logger.debug("[inside typeform integration] Signature does not match, ignoring"); |
| 322 | |
| 323 | return { events: [] }; |
| 324 | } |
| 325 | |
| 326 | const payload = safeParseBody(rawBody); |
| 327 | |
| 328 | return { |
| 329 | events: [ |
| 330 | { |
| 331 | id: payload.event_id, |
| 332 | name: payload.event_type, |
| 333 | source: SOURCE, |
| 334 | payload, |
| 335 | context: {}, |
| 336 | }, |
| 337 | ], |
| 338 | }; |
| 339 | } |
| 340 | |
| 341 | function isWebhookData(data: any): data is GetWebhookResponse { |
| 342 | return typeof data === "object" && data !== null && typeof data.id === "string"; |
nothing calls this directly
no test coverage detected
searching dependent graphs…