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 | hostedActionResults, |
| 7 | parseSignedColineRequest, |
| 8 | ui, |
| 9 | } from "../index"; |
| 10 |
| 11 | const COLINE_DELIVERY_SECRET = |
| 12 | ( |
| 13 | globalThis as { |
| 14 | process?: { |
| 15 | env?: Record<string, string | undefined>; |
| 16 | }; |
| 17 | } |
| 18 | ).process?.env?.["COLINE_DELIVERY_SECRET"] ?? ""; |
| 19 |
| 20 | export async function handleRenderHome(request: Request) { |
| 21 | const { data } = await parseSignedColineRequest({ |
| 22 | request, |
| 23 | secret: COLINE_DELIVERY_SECRET, |
| 24 | schema: colineHostedRenderHomeRequestSchema, |
| 25 | }); |
| 26 |
| 27 | const tree = ui.stack( |
| 28 | [ |
| 29 | ui.heading("CRM"), |
| 30 | ui.text(`Workspace: ${data.workspace.name}`), |
| 31 | ui.button("New customer", { |
| 32 | action: actions.createFile({ |
| 33 | name: "New customer", |
| 34 | typeKey: "acme.customer", |
| 35 | document: { |
| 36 | status: "lead", |
| 37 | }, |
| 38 | }), |
| 39 | }), |
| 40 | ], |
| 41 | { gap: "md" }, |
| 42 | ); |
| 43 |
| 44 | return Response.json(tree); |
| 45 | } |
| 46 |
| 47 | export async function handleRenderFile(request: Request) { |
| 48 | const { data } = await parseSignedColineRequest({ |
| 49 | request, |
| 50 | secret: COLINE_DELIVERY_SECRET, |
| 51 | schema: colineHostedRenderFileRequestSchema, |
| 52 | }); |
| 53 |
| 54 | const status = |
| 55 | typeof data.document["status"] === "string" ? data.document["status"] : "unknown"; |
| 56 |
| 57 | return Response.json( |
| 58 | ui.stack( |
| 59 | [ |
| 60 | ui.heading(data.file.title ?? "Customer"), |
| 61 | ui.badge(status), |
| 62 | ui.button("Open in Coline", { |
| 63 | action: actions.openFile(data.file.id), |
| 64 | }), |
| 65 | ], |
| 66 | { gap: "md" }, |
| 67 | ), |
| 68 | ); |
| 69 | } |
| 70 |
| 71 | export async function handleAction(request: Request) { |
| 72 | const { data } = await parseSignedColineRequest({ |
| 73 | request, |
| 74 | secret: COLINE_DELIVERY_SECRET, |
| 75 | schema: colineHostedActionRequestSchema, |
| 76 | }); |
| 77 |
| 78 | if (data.action.type === "crm.sync") { |
| 79 | return Response.json(hostedActionResults.refresh()); |
| 80 | } |
| 81 |
| 82 | return Response.json(hostedActionResults.ok()); |
| 83 | } |
| 84 |