Verify Increase webhook deliveries. Increase signs with Standard
Webhooks (webhook-id, webhook-timestamp, webhook-signature; see
::increase::standard-webhooks), keyed with the raw bytes of the
Event Subscription's shared_secret, as Increase's own SDKs do.
Deliveries older or newer than five minutes are rejected.
After verifying, parse the Event with ::increase::events/parse-event
and re-fetch its object with fetch-associated-object; return 2xx
fast and process asynchronously. Increase retries failed deliveries
for about three days (not at all in the sandbox), so deduplicate on
the webhook-id header (the Event id).
Context Vars
increase.webhook.secret
Functions
construct-event
fn (request: Map): Any
fn (request: Map, secret: Str): Any
Verify a delivery (see verify-request) and return its
::increase::events/Event, or an Err when the signature or timestamp
doesn't verify. The 2-arity form takes an explicit secret.
Example
HttpResponse ::hot::http/HttpResponse
on-increase-delivery
meta {webhook: {service: "increase", path: "/increase/webhook"}}
fn (request) {
event ::increase::webhooks/construct-event(request)
cond {
is-err(event) => { HttpResponse({status: 401, body: "invalid signature"}) }
=> { HttpResponse({status: 200, body: {received: event.id}}) }
}
}
increase.webhook.secret
signing-key
fn (secret: Str): Bytes
The HMAC key for an Increase shared secret: its raw UTF-8 bytes.
Increase's SDKs verify with new Webhook("whsec_" + base64(secret)),
which decodes back to these bytes. Exposed for testing.
Example
length(::increase::webhooks/signing-key("test-secret")) // 11
verify-request
fn (request: Map): Bool
fn (request: Map, secret: Str): Bool
fn (request: Map, secret: Str, tolerance-seconds: Int): Bool
True when an inbound request is a genuine, fresh Increase delivery.
The 1-arity form reads increase.webhook.secret and fails the run
when it is unset; an explicit empty secret never verifies. The
3-arity form sets the tolerance in seconds (default 300).
Example
HttpResponse ::hot::http/HttpResponse
increase-webhook
meta {webhook: {service: "increase", path: "/increase/webhook"}}
fn (request) {
cond {
not(::increase::webhooks/verify-request(request)) => {
HttpResponse({status: 401, body: "invalid signature"})
}
=> {
event ::increase::events/parse-event(::hot::http/raw-body(request))
// enqueue event.id / event.category for processing
HttpResponse({status: 200, body: {received: true}})
}
}
}
increase.webhook.secret