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 | notificationChannels: [ |
| 11 | { |
| 12 | key: "updates", |
| 13 | name: "Updates", |
| 14 | defaultDeliveries: ["in_app", "desktop"], |
| 15 | }, |
| 16 | ], |
| 17 | hosting: { |
| 18 | mode: "external", |
| 19 | baseUrl: "https://notes.example.com", |
| 20 | }, |
| 21 | }); |
| 22 |
| 23 | expect(manifest.hosting.baseUrl).toBe("https://notes.example.com"); |
| 24 | }); |
| 25 |
| 26 | it("registers file types and handlers in the app definition", () => { |
| 27 | const app = new ColineApp({ |
| 28 | key: "com.coline.notes", |
| 29 | name: "Notes", |
| 30 | permissions: ["app.home.read", "files.read", "files.write"], |
| 31 | hosting: { |
| 32 | mode: "external", |
| 33 | baseUrl: "https://notes.example.com", |
| 34 | }, |
| 35 | }) |
| 36 | .defineFileType({ |
| 37 | typeKey: "com.coline.notes.note", |
| 38 | name: "Note", |
| 39 | storage: "coline_document", |
| 40 | }) |
| 41 | .defineNotificationChannel({ |
| 42 | key: "updates", |
| 43 | name: "Updates", |
| 44 | defaultDeliveries: ["in_app", "desktop"], |
| 45 | }) |
| 46 | .onHomeRender(async () => ({ type: "Text", props: { value: "Notes" } })) |
| 47 | .onIndexSync(() => []); |
| 48 |
| 49 | const definition = app.getDefinition(); |
| 50 |
| 51 | expect(definition.fileTypes).toHaveLength(1); |
| 52 | expect(definition.notificationChannels).toHaveLength(1); |
| 53 | expect(definition.fileTypes[0]?.typeKey).toBe("com.coline.notes.note"); |
| 54 | expect(typeof definition.handlers.homeRender).toBe("function"); |
| 55 | expect(typeof definition.handlers.indexSync).toBe("function"); |
| 56 | }); |
| 57 |
| 58 | it("builds a typed registration payload for API submission", () => { |
| 59 | const app = new ColineApp({ |
| 60 | key: "com.coline.notes", |
| 61 | name: "Notes", |
| 62 | permissions: ["app.home.read"], |
| 63 | hosting: { |
| 64 | mode: "external", |
| 65 | baseUrl: "https://notes.example.com", |
| 66 | }, |
| 67 | }) |
| 68 | .defineFileType({ |
| 69 | typeKey: "com.coline.notes.note", |
| 70 | name: "Note", |
| 71 | storage: "coline_document", |
| 72 | }) |
| 73 | .defineNotificationChannel({ |
| 74 | key: "updates", |
| 75 | name: "Updates", |
| 76 | defaultDeliveries: ["in_app"], |
| 77 | }); |
| 78 |
| 79 | const payload = app.getRegistrationPayload("0.1.0"); |
| 80 |
| 81 | expect(payload.version).toBe("0.1.0"); |
| 82 | expect(payload.manifest.key).toBe("com.coline.notes"); |
| 83 | expect(payload.fileTypes[0]?.homeRenderMode).toBe("cached"); |
| 84 | expect(payload.manifest.notificationChannels[0]?.key).toBe("updates"); |
| 85 | }); |
| 86 |
| 87 | it("rejects invalid external hosting urls", () => { |
| 88 | expect(() => { |
| 89 | new ColineApp({ |
| 90 | key: "com.coline.invalid", |
| 91 | name: "Invalid", |
| 92 | permissions: [], |
| 93 | hosting: { |
| 94 | mode: "external", |
| 95 | baseUrl: "not-a-url", |
| 96 | }, |
| 97 | }); |
| 98 | }).toThrow(); |
| 99 | }); |
| 100 |
| 101 | it("builds typed notification payloads", () => { |
| 102 | const app = new ColineApp({ |
| 103 | key: "com.coline.notes", |
| 104 | name: "Notes", |
| 105 | permissions: ["notifications.write"], |
| 106 | hosting: { |
| 107 | mode: "external", |
| 108 | baseUrl: "https://notes.example.com", |
| 109 | }, |
| 110 | }).defineNotificationChannel({ |
| 111 | key: "updates", |
| 112 | name: "Updates", |
| 113 | defaultDeliveries: ["in_app", "desktop"], |
| 114 | }); |
| 115 |
| 116 | const payload = app.createNotification({ |
| 117 | channelKey: "updates", |
| 118 | typeKey: "note.shared", |
| 119 | recipients: [{ userId: "user_123" }], |
| 120 | title: "A note was shared", |
| 121 | metadata: { noteId: "note_123" }, |
| 122 | }); |
| 123 |
| 124 | expect(payload.priority).toBe("default"); |
| 125 | expect(payload.recipients[0]?.userId).toBe("user_123"); |
| 126 | }); |
| 127 | }); |
| 128 |