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 | workspace: "none" | "read" | "write"; |
| 6 | readers: string[]; |
| 7 | writers: string[]; |
| 8 | } |
| 9 | export const DEFAULT_RECORD_ACCESS: ColineRecordAccess = { |
| 10 | workspace: "write", |
| 11 | readers: [], |
| 12 | writers: [], |
| 13 | }; |
| 14 | export function canAccessRecord( |
| 15 | access: ColineRecordAccess, |
| 16 | creator: ColineActorRef, |
| 17 | userId: string | null, |
| 18 | action: "read" | "write" | "manage", |
| 19 | ): boolean { |
| 20 | const owner = creator.kind === "user" ? creator.userId === userId : userId === null; |
| 21 | if (owner) return true; |
| 22 | if (action === "manage") return false; |
| 23 | if (access.workspace === "write") return true; |
| 24 | if (!userId) return false; |
| 25 | if (access.writers.includes(userId)) return true; |
| 26 | return action === "read" && (access.workspace === "read" || access.readers.includes(userId)); |
| 27 | } |
| 28 | export interface ColineRecordWriteOptions { |
| 29 | expectedVersion?: number; |
| 30 | } |
| 31 | export interface ColineRecordInsertOptions { |
| 32 | id?: string; |
| 33 | access?: ColineRecordAccess; |
| 34 | } |
| 35 |