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 | return new Response(JSON.stringify(payload), { |
| 6 | status, |
| 7 | headers: { "Content-Type": "application/json" }, |
| 8 | }); |
| 9 | } |
| 10 |
| 11 | describe("ColineApiClient", () => { |
| 12 | it("installs a workspace app with explicit granted permissions", async () => { |
| 13 | const fetchMock = vi.fn().mockResolvedValue( |
| 14 | createJsonResponse({ |
| 15 | data: { |
| 16 | installId: "install_123", |
| 17 | appId: "app_123", |
| 18 | appKey: "com.coline.notes", |
| 19 | version: "0.1.0", |
| 20 | grantedPermissions: ["app.home.read"], |
| 21 | }, |
| 22 | }), |
| 23 | ); |
| 24 |
| 25 | const client = new ColineApiClient({ |
| 26 | baseUrl: "https://api.coline.app", |
| 27 | apiKey: "test-key", |
| 28 | fetch: fetchMock, |
| 29 | }); |
| 30 |
| 31 | const result = await client.installWorkspaceApp("acme", { |
| 32 | appId: "app_123", |
| 33 | grantedPermissions: ["app.home.read"], |
| 34 | }); |
| 35 |
| 36 | expect(result.installId).toBe("install_123"); |
| 37 | expect(fetchMock).toHaveBeenCalledWith( |
| 38 | "https://api.coline.app/api/workspaces/acme/apps", |
| 39 | expect.objectContaining({ |
| 40 | method: "POST", |
| 41 | headers: expect.any(Headers), |
| 42 | }), |
| 43 | ); |
| 44 |
| 45 | const headers = fetchMock.mock.calls[0]?.[1]?.headers as Headers; |
| 46 | expect(headers.get("Authorization")).toBe("Bearer test-key"); |
| 47 | }); |
| 48 |
| 49 | it("loads and updates workspace app permissions", async () => { |
| 50 | const fetchMock = vi |
| 51 | .fn() |
| 52 | .mockResolvedValueOnce( |
| 53 | createJsonResponse({ |
| 54 | data: { |
| 55 | install: { |
| 56 | installId: "install_123", |
| 57 | appId: "app_123", |
| 58 | appKey: "com.coline.notes", |
| 59 | name: "Notes", |
| 60 | description: null, |
| 61 | iconUrl: null, |
| 62 | status: "active", |
| 63 | installScope: "workspace", |
| 64 | scopeSubjectId: "workspace_123", |
| 65 | version: "0.1.0", |
| 66 | }, |
| 67 | availablePermissions: ["app.home.read", "files.write"], |
| 68 | grantedPermissions: ["app.home.read"], |
| 69 | permissions: { |
| 70 | canManageApps: true, |
| 71 | }, |
| 72 | }, |
| 73 | }), |
| 74 | ) |
| 75 | .mockResolvedValueOnce( |
| 76 | createJsonResponse({ |
| 77 | data: { |
| 78 | install: { |
| 79 | installId: "install_123", |
| 80 | appId: "app_123", |
| 81 | appKey: "com.coline.notes", |
| 82 | name: "Notes", |
| 83 | description: null, |
| 84 | iconUrl: null, |
| 85 | status: "active", |
| 86 | installScope: "workspace", |
| 87 | scopeSubjectId: "workspace_123", |
| 88 | version: "0.1.0", |
| 89 | }, |
| 90 | availablePermissions: ["app.home.read", "files.write"], |
| 91 | grantedPermissions: ["app.home.read", "files.write"], |
| 92 | permissions: { |
| 93 | canManageApps: true, |
| 94 | }, |
| 95 | }, |
| 96 | }), |
| 97 | ); |
| 98 |
| 99 | const client = new ColineApiClient({ |
| 100 | baseUrl: "https://api.coline.app", |
| 101 | fetch: fetchMock, |
| 102 | }); |
| 103 |
| 104 | const currentPermissions = await client.getWorkspaceAppPermissions( |
| 105 | "acme", |
| 106 | "com.coline.notes", |
| 107 | ); |
| 108 | expect(currentPermissions.grantedPermissions).toEqual(["app.home.read"]); |
| 109 |
| 110 | const updatedPermissions = await client.updateWorkspaceAppPermissions( |
| 111 | "acme", |
| 112 | "com.coline.notes", |
| 113 | { |
| 114 | grantedPermissions: ["app.home.read", "files.write"], |
| 115 | }, |
| 116 | ); |
| 117 |
| 118 | expect(updatedPermissions.grantedPermissions).toEqual([ |
| 119 | "app.home.read", |
| 120 | "files.write", |
| 121 | ]); |
| 122 | }); |
| 123 |
| 124 | it("loads app detail, app versions, installed app, and uninstalls it", async () => { |
| 125 | const fetchMock = vi |
| 126 | .fn() |
| 127 | .mockResolvedValueOnce( |
| 128 | createJsonResponse({ |
| 129 | data: { |
| 130 | app: { |
| 131 | appId: "app_123", |
| 132 | appKey: "com.coline.notes", |
| 133 | name: "Notes", |
| 134 | description: null, |
| 135 | iconUrl: null, |
| 136 | status: "active", |
| 137 | ownerUserId: "user_123", |
| 138 | latestPublishedVersion: "0.1.0", |
| 139 | latestPublishedVersionId: "ver_123", |
| 140 | }, |
| 141 | }, |
| 142 | }), |
| 143 | ) |
| 144 | .mockResolvedValueOnce( |
| 145 | createJsonResponse({ |
| 146 | data: { |
| 147 | versions: [ |
| 148 | { |
| 149 | versionId: "ver_123", |
| 150 | version: "0.1.0", |
| 151 | status: "published", |
| 152 | apiBaseUrl: "https://notes.example.com", |
| 153 | permissions: ["app.home.read"], |
| 154 | fileTypes: [], |
| 155 | createdAt: "2026-04-01T00:00:00.000Z", |
| 156 | updatedAt: "2026-04-01T00:00:00.000Z", |
| 157 | }, |
| 158 | ], |
| 159 | }, |
| 160 | }), |
| 161 | ) |
| 162 | .mockResolvedValueOnce( |
| 163 | createJsonResponse({ |
| 164 | data: { |
| 165 | install: { |
| 166 | installId: "install_123", |
| 167 | appId: "app_123", |
| 168 | appKey: "com.coline.notes", |
| 169 | name: "Notes", |
| 170 | description: null, |
| 171 | iconUrl: null, |
| 172 | status: "active", |
| 173 | installScope: "workspace", |
| 174 | scopeSubjectId: "workspace_123", |
| 175 | version: "0.1.0", |
| 176 | }, |
| 177 | permissions: { |
| 178 | canManageApps: true, |
| 179 | }, |
| 180 | }, |
| 181 | }), |
| 182 | ) |
| 183 | .mockResolvedValueOnce(createJsonResponse({ data: { ok: true } })); |
| 184 |
| 185 | const client = new ColineApiClient({ |
| 186 | baseUrl: "https://api.coline.app", |
| 187 | fetch: fetchMock, |
| 188 | }); |
| 189 |
| 190 | const app = await client.getApp("com.coline.notes"); |
| 191 | expect(app.app.appKey).toBe("com.coline.notes"); |
| 192 |
| 193 | const versions = await client.listAppVersions("com.coline.notes"); |
| 194 | expect(versions.versions[0]?.version).toBe("0.1.0"); |
| 195 |
| 196 | const installed = await client.getWorkspaceInstalledApp("acme", "com.coline.notes"); |
| 197 | expect(installed.install.installId).toBe("install_123"); |
| 198 |
| 199 | const uninstallResult = await client.uninstallWorkspaceApp( |
| 200 | "acme", |
| 201 | "com.coline.notes", |
| 202 | ); |
| 203 | expect(uninstallResult.ok).toBe(true); |
| 204 | }); |
| 205 | }); |
| 206 |