on: the host runs it for each firing of a
standing source. Nobody calls it, so it has no allow (a route reaction is the
one exception, below). It runs as the installation holding the roles it
declares, with ctx.frame.on carrying { kind: "source", source }.
A target is never a source. To act on a task’s result, name a continuation
with
then when you submit it.
Clocks
bijection/digests.ts
{ lateness, coalesce }. lateness is how long after its
instant a firing may still run: the interval by default, at most one day.
Later, the firing is skipped. coalesce: true, the default, runs missed
firings once; false runs each in turn.
Keep a firing’s work bounded. Work that takes more than one transaction is a
task the reaction submits.
Routes
A route reaction receives the inbound request and its return value is the reply. A signed unsubscribe link carries a token issued for one email address. Use a dedicated signing key and includeemail and an exp timestamp
in seconds when you issue the token with signJwt.
bijection/unsubscribe.ts
Request is { method, path, headers, query, body, file }:
headersare by lower-case name, without theauthorizationthe host verified;queryholds each name once, and a repeated name refusesRepeatedQuery;bodyis the JSON or form value, ornull;fileis an upload: a non-JSON body the host stored at ingress under the reaction’s label. Keep theFilepoint in at.filefield. It isnullfor a JSON body. See Uploading files.
args: everything it receives is the request.
Its return value is a JSON 200 body, or a string as text/plain. To set the
status and headers, return exactly { status, headers, body }: status is
200 to 599, headers at most 32 by lower-case name, and body a string or a
JSON value (empty for 204, 205 and 304):
route.post("/operator/plan", verifier.session()) in an app mounted at mail serves
/mail/operator/plan; a root app’s reaction serves its path as written.
route.path(reaction) from @bijectionhq/bijection answers the full
path, to build a public URL to an app’s own route.
Verify a route
Name the verifier as the second argument of every route. The SDK provides these verifiers:
Webhook verifiers for particular senders come with the
integrations that receive them. For Stripe, use
route.post("/stripe", providerWebhooks.stripe(stripeSigning)) with
providerWebhooks from @bijectionhq/library-connectors/webhooks.
Change sources
.changes on a table, a selection or a point is its change log, and as a
source it fires once per change:
bijection/decisions.ts
{ key, before, after, version }: the fact before and after the
commit (null for an insert or a removal) and the version that committed it.
On a family table, one member’s selection is
t.of(family.of(key)).where({ … }).changes.
Authority
A reaction runs as the installation.roles are the roles it holds while it
runs: they decide what it clears and which guards see it (a guard sees
a.offer.role for the grant the act runs through). A reaction with no roles holds
none.
Each firing commits in its own transaction and is decided afresh: a
reaction’s acts are checked against what its roles allow at that moment.
Test reactions
The test kernel’s clock runs what falls due:k.advance({ hours: 1 }) fires
every and cron reactions, and committed changes run change reactions.
k.route(reaction, { method, body, headers, query, as }) delivers a request to a
route as the host does once its verifier passed, and answers a Result. See
Testing.