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.
| 5 | it("validates manifest configuration", () => { |
| 6 | const manifest = colineAppManifestSchema.parse({ |
| 7 | key: "com.coline.notes", |
| 8 | name: "Notes", |
| 9 | permissions: ["app.home.read", "files.write", "index.write"], |
| 10 | hosting: { |
| 11 | mode: "external", |
| 12 | baseUrl: "https://notes.example.com", |
| 13 | }, |
| 14 | }); |
| 15 |
| 16 | expect(manifest.hosting.baseUrl).toBe("https://notes.example.com"); |
| 17 | }); |
| 18 |
| 19 | it("registers file types and handlers in the app definition", () => { |
| 20 | const app = new ColineApp({ |
| 21 | key: "com.coline.notes", |
| 22 | name: "Notes", |
| 23 | permissions: ["app.home.read", "files.read", "files.write"], |
| 24 | hosting: { |
| 25 | mode: "external", |
| 26 | baseUrl: "https://notes.example.com", |
| 27 | }, |
| 28 | }) |
| 29 | .defineFileType({ |
| 30 | typeKey: "com.coline.notes.note", |
| 31 | name: "Note", |
| 32 | storage: "coline_document", |
| 33 | }) |
| 34 | .onHomeRender(async () => ({ type: "Text", props: { value: "Notes" } })) |
| 35 | .onIndexSync(() => []); |
| 36 |
| 37 | const definition = app.getDefinition(); |
| 38 |
| 39 | expect(definition.fileTypes).toHaveLength(1); |
| 40 | expect(definition.fileTypes[0]?.typeKey).toBe("com.coline.notes.note"); |
| 41 | expect(typeof definition.handlers.homeRender).toBe("function"); |
| 42 | expect(typeof definition.handlers.indexSync).toBe("function"); |
| 43 | }); |
| 44 |
| 45 | it("builds a typed registration payload for API submission", () => { |
| 46 | const app = new ColineApp({ |
| 47 | key: "com.coline.notes", |
| 48 | name: "Notes", |
| 49 | permissions: ["app.home.read"], |
| 50 | hosting: { |
| 51 | mode: "external", |
| 52 | baseUrl: "https://notes.example.com", |
| 53 | }, |
| 54 | }).defineFileType({ |
| 55 | typeKey: "com.coline.notes.note", |
| 56 | name: "Note", |
| 57 | storage: "coline_document", |
| 58 | }); |
| 59 |
| 60 | const payload = app.getRegistrationPayload("0.1.0"); |
| 61 |
| 62 | expect(payload.version).toBe("0.1.0"); |
| 63 | expect(payload.manifest.key).toBe("com.coline.notes"); |
| 64 | expect(payload.fileTypes[0]?.homeRenderMode).toBe("cached"); |
| 65 | }); |
| 66 |
| 67 | it("rejects invalid external hosting urls", () => { |
| 68 | expect(() => { |
| 69 | new ColineApp({ |
| 70 | key: "com.coline.invalid", |
| 71 | name: "Invalid", |
| 72 | permissions: [], |
| 73 | hosting: { |
| 74 | mode: "external", |
| 75 | baseUrl: "not-a-url", |
| 76 | }, |
| 77 | }); |
| 78 | }).toThrow(); |
| 79 | }); |
| 80 | }); |
| 81 |