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 () => |
| 47 | ui.stack([ |
| 48 | ui.heading("Notes"), |
| 49 | ui.button("New note", { |
| 50 | action: { type: "create_note" }, |
| 51 | }), |
| 52 | ]), |
| 53 | ) |
| 54 | .onIndexSync(() => []); |
| 55 |
| 56 | const definition = app.getDefinition(); |
| 57 |
| 58 | expect(definition.fileTypes).toHaveLength(1); |
| 59 | expect(definition.notificationChannels).toHaveLength(1); |
| 60 | expect(definition.fileTypes[0]?.typeKey).toBe("com.coline.notes.note"); |
| 61 | expect(typeof definition.handlers.homeRender).toBe("function"); |
| 62 | expect(typeof definition.handlers.indexSync).toBe("function"); |
| 63 | }); |
| 64 |
| 65 | it("builds a typed registration payload for API submission", () => { |
| 66 | const app = new ColineApp({ |
| 67 | key: "com.coline.notes", |
| 68 | name: "Notes", |
| 69 | permissions: ["app.home.read"], |
| 70 | hosting: { |
| 71 | mode: "external", |
| 72 | baseUrl: "https://notes.example.com", |
| 73 | }, |
| 74 | }) |
| 75 | .defineFileType({ |
| 76 | typeKey: "com.coline.notes.note", |
| 77 | name: "Note", |
| 78 | storage: "coline_document", |
| 79 | }) |
| 80 | .defineNotificationChannel({ |
| 81 | key: "updates", |
| 82 | name: "Updates", |
| 83 | defaultDeliveries: ["in_app"], |
| 84 | }); |
| 85 |
| 86 | const payload = app.getRegistrationPayload("0.1.0"); |
| 87 |
| 88 | expect(payload.version).toBe("0.1.0"); |
| 89 | expect(payload.manifest.key).toBe("com.coline.notes"); |
| 90 | expect(payload.fileTypes[0]?.homeRenderMode).toBe("cached"); |
| 91 | expect(payload.manifest.notificationChannels[0]?.key).toBe("updates"); |
| 92 | }); |
| 93 |
| 94 | it("rejects invalid external hosting urls", () => { |
| 95 | expect(() => { |
| 96 | new ColineApp({ |
| 97 | key: "com.coline.invalid", |
| 98 | name: "Invalid", |
| 99 | permissions: [], |
| 100 | hosting: { |
| 101 | mode: "external", |
| 102 | baseUrl: "not-a-url", |
| 103 | }, |
| 104 | }); |
| 105 | }).toThrow(); |
| 106 | }); |
| 107 |
| 108 | it("builds typed notification payloads", () => { |
| 109 | const app = new ColineApp({ |
| 110 | key: "com.coline.notes", |
| 111 | name: "Notes", |
| 112 | permissions: ["notifications.write"], |
| 113 | hosting: { |
| 114 | mode: "external", |
| 115 | baseUrl: "https://notes.example.com", |
| 116 | }, |
| 117 | }).defineNotificationChannel({ |
| 118 | key: "updates", |
| 119 | name: "Updates", |
| 120 | defaultDeliveries: ["in_app", "desktop"], |
| 121 | }); |
| 122 |
| 123 | const payload = app.createNotification({ |
| 124 | channelKey: "updates", |
| 125 | typeKey: "note.shared", |
| 126 | recipients: [{ userId: "user_123" }], |
| 127 | title: "A note was shared", |
| 128 | metadata: { noteId: "note_123" }, |
| 129 | }); |
| 130 |
| 131 | expect(payload.priority).toBe("default"); |
| 132 | expect(payload.recipients[0]?.userId).toBe("user_123"); |
| 133 | }); |
| 134 |
| 135 | it("builds typed ambient event batches", () => { |
| 136 | const app = new ColineApp({ |
| 137 | key: "com.coline.notes", |
| 138 | name: "Notes", |
| 139 | permissions: ["ambient.events.write"], |
| 140 | hosting: { |
| 141 | mode: "external", |
| 142 | baseUrl: "https://notes.example.com", |
| 143 | }, |
| 144 | }); |
| 145 |
| 146 | const payload = app.createAmbientEvents({ |
| 147 | events: [ |
| 148 | { |
| 149 | action: "synced", |
| 150 | entityType: "app_document", |
| 151 | entityId: "note_123", |
| 152 | dedupeKey: "sync:note_123:v1", |
| 153 | payload: { title: "Roadmap" }, |
| 154 | }, |
| 155 | ], |
| 156 | }); |
| 157 |
| 158 | expect(payload.events[0]?.sourceKind).toBe("app_signal"); |
| 159 | expect(payload.events[0]?.payload).toEqual({ title: "Roadmap" }); |
| 160 | }); |
| 161 | }); |
| 162 |