feat: Function triggers — schedule, inbound hook, domain events

Migration 00016: function_id on scheduled_jobs/inbound_hooks,
event_pattern on functions, 'event' in the run-trigger enum.

- Jobs deliver to a function instead of HTTP when function_id is set;
  the run's status_code mirrors the process exit code. Clearing the
  field returns the job to URL delivery.
- Inbound hooks gain mode "function" — received body becomes stdin
  payload, acked immediately, run recorded async.
- event_pattern (document.*, *, exact type) fires the function detached
  on matching publishEvent — never blocks realtime/webhook fan-out.
- One executeFunction path serves manual/schedule/hook/event; run rows
  record the trigger source.
- Backend image now ships bun 1.3.14 so Functions work under compose.

Dashboard: job target picker, hook function mode, event-pattern field.

Verified live: job run → success (status_code 0), hook POST → run,
document.created → event run with correct payload.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Tomas DvorakandDevin committed 2026-09-24 20:28:04 +02:00
1 parent c094afad65
commit a84049b8fc
40 files changed
+716 -157

No files matched your search

@@ -6,6 +6,10 @@ export type CreateFunctionRequest = {
name: string;
code: string;
runtime?: CreateFunctionRequest.runtime;
/**
* Optional — "document.*", "*", or an exact event type.
*/
event_pattern?: string;
};
export namespace CreateFunctionRequest {
export enum runtime {
@@ -9,6 +9,10 @@ export type CreateInboundHookRequest = {
* Required when mode=job — scheduled job to trigger.
*/
job_id?: string;
/**
* Required when mode=function — invoked with the received body.
*/
function_id?: string;
/**
* Optional — stored encrypted; callers must then sign bodies with X-Primora-Signature.
*/
@@ -19,6 +23,7 @@ export namespace CreateInboundHookRequest {
export enum mode {
EVENT = 'event',
JOB = 'job',
FUNCTION = 'function',
}
}
@@ -8,7 +8,14 @@ export type CreateScheduledJobRequest = {
* Cron expression, e.g. "*15 * * * *", or descriptor like "@every 1h".
*/
schedule: string;
url: string;
/**
* Delivery target. Required unless function_id is set.
*/
url?: string;
/**
* Invoke this function on schedule instead of POSTing url.
*/
function_id?: string;
/**
* HMAC key for X-Primora-Signature. Generated when omitted.
*/
@@ -7,6 +7,10 @@ export type Function = {
name: string;
runtime: Function.runtime;
enabled: boolean;
/**
* Domain-event pattern that triggers this function — "document.*", "*", exact type. Empty = never.
*/
event_pattern?: string;
created_at: string;
updated_at: string;
};
@@ -17,6 +17,7 @@ export namespace FunctionRun {
MANUAL = 'manual',
SCHEDULE = 'schedule',
HOOK = 'hook',
EVENT = 'event',
}
export enum status {
SUCCESS = 'success',
@@ -13,6 +13,7 @@ export type InboundHook = {
url: string;
mode: InboundHook.mode;
job_id?: string;
function_id?: string;
has_secret: boolean;
enabled: boolean;
last_received_at?: string | null;
@@ -22,6 +23,7 @@ export namespace InboundHook {
export enum mode {
EVENT = 'event',
JOB = 'job',
FUNCTION = 'function',
}
}
@@ -11,6 +11,10 @@ export type ScheduledJob = {
*/
schedule: string;
url: string;
/**
* When set, the schedule invokes this function instead of POSTing url.
*/
function_id?: string | null;
/**
* Static JSON payload merged into every delivery's data field.
*/
@@ -5,5 +5,9 @@
export type UpdateFunctionRequest = {
code?: string;
enabled?: boolean;
/**
* Replace the trigger pattern; "" disables event triggers.
*/
event_pattern?: string;
};
@@ -6,6 +6,10 @@ export type UpdateScheduledJobRequest = {
name?: string;
schedule?: string;
url?: string;
/**
* Set to retarget at a function; send "" to clear back to url delivery.
*/
function_id?: string | null;
/**
* Replace the signing secret. Omit to keep the current one.
*/
@@ -15,5 +15,9 @@ export const $CreateFunctionRequest = {
runtime: {
type: 'Enum',
},
event_pattern: {
type: 'string',
description: `Optional — "document.*", "*", or an exact event type.`,
},
},
} as const;
@@ -15,6 +15,10 @@ export const $CreateInboundHookRequest = {
type: 'string',
description: `Required when mode=job — scheduled job to trigger.`,
},
function_id: {
type: 'string',
description: `Required when mode=function — invoked with the received body.`,
},
secret: {
type: 'string',
description: `Optional — stored encrypted; callers must then sign bodies with X-Primora-Signature.`,
@@ -16,9 +16,14 @@ export const $CreateScheduledJobRequest = {
},
url: {
type: 'string',
isRequired: true,
description: `Delivery target. Required unless function_id is set.`,
format: 'uri',
},
function_id: {
type: 'string',
description: `Invoke this function on schedule instead of POSTing url.`,
format: 'uuid',
},
secret: {
type: 'string',
description: `HMAC key for X-Primora-Signature. Generated when omitted.`,
@@ -21,6 +21,10 @@ export const $Function = {
type: 'boolean',
isRequired: true,
},
event_pattern: {
type: 'string',
description: `Domain-event pattern that triggers this function — "document.*", "*", exact type. Empty = never.`,
},
created_at: {
type: 'string',
isRequired: true,
@@ -34,6 +34,9 @@ export const $InboundHook = {
job_id: {
type: 'string',
},
function_id: {
type: 'string',
},
has_secret: {
type: 'boolean',
isRequired: true,
@@ -27,6 +27,12 @@ export const $ScheduledJob = {
type: 'string',
isRequired: true,
},
function_id: {
type: 'string',
description: `When set, the schedule invokes this function instead of POSTing url.`,
isNullable: true,
format: 'uuid',
},
payload: {
type: 'dictionary',
contains: {
@@ -10,5 +10,9 @@ export const $UpdateFunctionRequest = {
enabled: {
type: 'boolean',
},
event_pattern: {
type: 'string',
description: `Replace the trigger pattern; "" disables event triggers.`,
},
},
} as const;
@@ -15,6 +15,12 @@ export const $UpdateScheduledJobRequest = {
type: 'string',
format: 'uri',
},
function_id: {
type: 'string',
description: `Set to retarget at a function; send "" to clear back to url delivery.`,
isNullable: true,
format: 'uuid',
},
secret: {
type: 'string',
description: `Replace the signing secret. Omit to keep the current one.`,