Channel subscriptions
Relay outbox row events to eve channel subscriptions with supabaseSubscriptions, scoped to the subscriber's tenant and re-checked on each delivery.
eve 1.6 lets a channel declare experimental.subscriptions. A session
subscribes with eve__subscribe, and the channel emits an occurrence to every
subscription whose scope equals the one it sends. supabaseSubscriptions
fills that slot from the outbox: app tables that set
events already write <table>.created, .updated and .deleted.
import { createOutbox } from "better-supabase/blocks/outbox";
import { supabaseSubscriptions } from "better-supabase/eve";
import { defineChannel } from "eve/channels";
import { transport } from "../lib/blocks";
const subs = supabaseSubscriptions({
outbox: createOutbox({ transport, source: "https://app.example" }),
events: [{ type: "deal.updated", description: "A deal changed" }],
});
export default defineChannel({
experimental: { subscriptions: subs.definition },
routes: [subs.relayRoute],
});onSubscribe keeps the scope inside the session's tenant (the tenantId
attribute principalOf writes). A session with no tenant, or one that asks
for another tenant, gets an error from the tool. Pass authorization to
re-check read access to the subject's table, on subscribe and again on each
delivery: captured session auth is not revalidated. onEvent returns null
when the check fails, so the session hears nothing. format replaces the
default one-line message.
The relay is POST /subscriptions. A cron or the outbox kick
calls it. A schedule does not receive emit, so the example's minute
schedule posts to that route on APP_URL. relaySubscriptions(emit) is the
same relay for a caller that already holds emit. Each outbox event is
emitted twice when it has a subject, once for { tenant } and once for
{ tenant, subject }, because eve
matches a scope by equality. The event id is the occurrence id, so a
redelivery reaches each subscriber once. The consumer name is
eve-subscriptions.
Without secret, the route relays any caller. Set secret and send it as a
bearer token, or keep the route off a public URL.
A live delivery on Vercel has not been run. The local eve-world suite covers one subscribe, one inserted row and the message that comes back.
Last updated on
Sessions in the chat tables
Project eve sessions into the chat tables from a stored cursor with createSessionSync, sweepSessions, resolve and sessionHistory, purge runs without losing unread ones and end stranded sessions before an eve upgrade.
The inbox on eve
Hand inbox conversations in bot mode to eve, run their tools as a service user, send replies as bot messages or ai drafts, and accept channel events without Chat SDK.