Skip to main content
A reaction is a mutation with 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
Each source takes { 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 include email and an exp timestamp in seconds when you issue the token with signJwt.
bijection/unsubscribe.ts
The Request is { method, path, headers, query, body, file }:
  • headers are by lower-case name, without the authorization the host verified;
  • query holds each name once, and a repeated name refuses RepeatedQuery;
  • body is the JSON or form value, or null;
  • file is an upload: a non-JSON body the host stored at ingress under the reaction’s label. Keep the File point in a t.file field. It is null for a JSON body. See Uploading files.
A route reaction declares no 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):
The path is relative to the app that holds the reaction. A reaction with 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
The change is { 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.