From f85528f75ec470c9fd68cfc3b3be3eac8acede06 Mon Sep 17 00:00:00 2001
From: Paul Visscher
Date: Mon, 11 Dec 2023 14:33:58 +0100
Subject: [PATCH] fix: add coercion on http handler
---
package.json | 2 +-
src/lib/event-horizon/http/http.ts | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 42d8f89..ff8d275 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@skyleague/event-horizon-dev",
- "version": "4.0.4",
+ "version": "4.0.11",
"description": "The accompanying development package for @skyleague/event-horizon.",
"repository": {
"type": "git",
diff --git a/src/lib/event-horizon/http/http.ts b/src/lib/event-horizon/http/http.ts
index 061627b..9ec9e91 100644
--- a/src/lib/event-horizon/http/http.ts
+++ b/src/lib/event-horizon/http/http.ts
@@ -42,6 +42,13 @@ export function httpEvent<
event.raw.isBase64Encoded ? Buffer.from(b.toString()).toString('base64') : b
) as typeof event.raw.body
}
+
+ // force coercion
+ http.schema.body?.is(event.body)
+ http.schema.headers?.is(event.headers)
+ http.schema.query?.is(event.query)
+ http.schema.path?.is(event.path)
+
event.raw.headers ??= (event.headers as typeof event.raw.headers) ?? {}
event.raw.queryStringParameters ??= (event.query as typeof event.raw.queryStringParameters) ?? {}
const rawEvent = event.raw