Vector 0.3.0 is out. @sweberdev/vector 0.3.0 is on npm under the MIT licence, and it is a drop-in update from 0.2.
The problem
One event, several receivers, and not all of them want the same body. A partner wants only three fields, a chat service wants its own message format, and one endpoint should not get debug events at all. Until now the answer was a second event type or a copy of the payload per receiver.
The transform hook
transform is called once per delivery, right before the request is signed. It sees the message, the endpoint and the default body, and returns what should change:
const vector = createVector({
store,
transform: ({ message, endpoint, body }) => {
if (endpoint.metadata.audience === "partner") {
return { body: { id: message.id, type: message.eventType } }
}
if (message.eventType.startsWith("debug.")) {
return { skip: "debug events are internal" }
}
return { headers: { "x-tenant": message.tenant ?? "" } }
},
})
bodyreplaces the body for this delivery. It must be JSON.headersare added to the request. Vector's ownwebhook-*headers cannot be overridden.skipcancels the delivery for that endpoint and records the reason in the log.- Returning nothing leaves the delivery as it is.
The stored message is never changed, so replays and the delivery log still show the original event. The new body is signed like any other, so receivers verify it with the usual Standard Webhooks library. If your function throws, the attempt fails and is retried like any other failure, and the log shows Transform failed: ....
Chat formats with Vector Pro
The hook is the building block. Vector Pro 0.4.0 uses it for Slack, Teams, Discord and Google Chat messages.
Update
pnpm add @sweberdev/vector@latest
The guide is in the documentation. Vector is free; Vector Pro adds the customer portal, event catalog, operations tooling, inbound webhooks and chat formats.