The Coline App SDK: apps, tools, file types and surfaces that run inside Coline workspaces, and public websites with Coline Sites. TypeScript, with an in-memory test workspace. MIT.
| * |
| 6 | * Webhook subscriptions ride the existing delivery pipeline |
| 7 | * (`app_deliveries`: retry + dead-letter). Schedules dispatch into the |
| 8 | * app's logic (hosted or external) without the developer running a |
| 9 | * scheduler. |
| 10 | */ |
| 11 |
| 12 | const webhookEventSchema = z |
| 13 | .string() |
| 14 | .trim() |
| 15 | .regex( |
| 16 | /^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$/, |
| 17 | "Webhook events are dotted lowercase identifiers (e.g. `file.created`).", |
| 18 | ) |
| 19 | .max(160); |
| 20 |
| 21 | const cronFieldPattern = "[0-9*,/-]+"; |
| 22 | const cronExpressionSchema = z |
| 23 | .string() |
| 24 | .trim() |
| 25 | .regex( |
| 26 | new RegExp(`^${cronFieldPattern}( ${cronFieldPattern}){4}$`), |
| 27 | "Schedules use 5-field cron expressions.", |
| 28 | ) |
| 29 | .max(120); |
| 30 |
| 31 | export const appScheduleSchema = z.strictObject({ |
| 32 | id: z |
| 33 | .string() |
| 34 | .trim() |
| 35 | .regex(/^[a-z][a-z0-9-]*$/, "Schedule ids are lowercase kebab-case.") |
| 36 | .max(120), |
| 37 | cron: cronExpressionSchema, |
| 38 | description: z.string().trim().max(500).optional(), |
| 39 | }); |
| 40 | export type AppSchedule = z.infer<typeof appScheduleSchema>; |
| 41 |
| 42 | export const appTriggersV2Schema = z |
| 43 | .strictObject({ |
| 44 | webhooks: z |
| 45 | .array(z.strictObject({ event: webhookEventSchema })) |
| 46 | .max(50) |
| 47 | .default([]), |
| 48 | schedules: z |
| 49 | .array(appScheduleSchema) |
| 50 | .max(20) |
| 51 | .default([]) |
| 52 | .refine( |
| 53 | (schedules) => new Set(schedules.map((schedule) => schedule.id)).size === schedules.length, |
| 54 | "Schedule ids must be unique.", |
| 55 | ), |
| 56 | }) |
| 57 | .default({ webhooks: [], schedules: [] }); |
| 58 | export type AppTriggersV2 = z.infer<typeof appTriggersV2Schema>; |
| 59 |