Webhooks send POST requests to the same endpoint (based on event-literal). Someone on discord wanna separate this logic into different functions based on event.
Pseudo code:
const customerCreated = new Elysia({ name: "created" })
.if(({ body }) => body.event === "customer.created")
.post("/", () => console.log("customer created!"));
const customerUpdated = new Elysia({ name: "updated" })
.if(({ body }) => body.event === "customer.updated")
.post("/", () => console.log("customer updated!"));
const stripeWebhook = new Elysia().use(customerCreated).use(customerUpdated);
What is the feature you are proposing to solve the problem?
Allow something like this to work with the same path (/):
What is the problem this feature would solve?
Webhooks send
POST
requests to the same endpoint (based onevent
-literal). Someone on discord wanna separate this logic into different functions based onevent
.Pseudo code:
What is the feature you are proposing to solve the problem?
Allow something like this to work with the same path (
/
):At the moment it throws a validation error:
Click to expand
```json { "type": "validation", "on": "body", "summary": "Property 'propUpdated' is missing", "property": "/propUpdated", "message": "Required property", "expected": { "event": "customer.updated", "propUpdated": "" }, "found": { "event": "customer.created" }, "errors": [ { "type": 45, "schema": { "type": "string" }, "path": "/propUpdated", "message": "Required property", "summary": "Property 'propUpdated' is missing" }, { "summary": "Expected 'customer.updated'", "type": 32, "schema": { "const": "customer.updated", "type": "string" }, "path": "/event", "value": "customer.created", "message": "Expected 'customer.updated'" }, { "type": 54, "schema": { "type": "string" }, "path": "/propUpdated", "message": "Expected string", "summary": "Expected property 'propUpdated' to be string but found: undefined" } ] } ```If i send this body:
What alternatives have you considered?
I considered this, but it has a lot of unnecessary code:
This is not easy for newbies and i've to do
isCustomerUpdated
, ... checks because of typescript type guard limitation with nested unions.Click to expand
```ts import { t, Elysia, type Static, type Context, type TSchema, type InputSchema, } from "elysia"; const customerCreated = t.Object({ event: t.Literal("customer.created"), propCreated: t.String(), }); type CustomerCreatedContext = StaticContextExclude< typeof customerWebhooks, Static