Milestone 5: canvas for access

The hub now serves a React canvas (web/, embedded at build time):
grant by dragging a vault onto a person, revoke by pulling a ribbon
until it snaps with an 8 s Undo the hub honours before anything reaches
devices, invites (including vaults dropped on invitees), device rename
and removal, Float/Dock, and panels with a button for every gesture.

Sign-in without passwords (SPEC §8): `lunesync open` one-time link or
a pairing code typed on the hub; 30-day HttpOnly session cookie plus an
X-Lune header on every canvas request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 07:56:41 +07:00
parent 4025726083
commit 193cb06f85
27 changed files with 3574 additions and 39 deletions

81
web/src/api.ts Normal file
View File

@@ -0,0 +1,81 @@
// Talking to the hub. The session cookie signs requests; X-Lune marks them as coming from the canvas.
export type Role = 'read' | 'edit' | 'manage';
export interface Vault {
id: string;
name: string;
can_manage: boolean;
delete_from_devices: boolean;
}
export interface Device {
id: string;
label: string;
}
export interface Person {
id: string;
name: string;
owner: boolean;
/** Invited but not joined yet. */
invited: boolean;
devices: Device[];
}
export interface Member {
vault: string;
person: string;
role: Role;
}
export interface CanvasData {
me: { id: string; person: string; owner: boolean };
vaults: Vault[];
people: Person[];
members: Member[];
/** Removals waiting out their Undo window. */
pending: { id: number; vault: string; person: string }[];
}
export interface LogEntry {
at: number;
actor: string;
action: string;
detail: string;
}
export class SignedOut extends Error {}
async function call<T>(method: string, path: string, body?: unknown): Promise<T> {
const res = await fetch(path, {
method,
credentials: 'same-origin',
headers: { 'X-Lune': '1', ...(body ? { 'Content-Type': 'application/json' } : {}) },
body: body ? JSON.stringify(body) : undefined,
});
const data = await res.json().catch(() => ({}));
if (res.status === 401) throw new SignedOut(data.error ?? 'please sign in');
if (!res.ok) throw new Error(data.error ?? 'something went wrong on the hub');
return data as T;
}
export const api = {
canvas: () => call<CanvasData>('GET', '/api/canvas'),
log: (count = 8) => call<LogEntry[]>('GET', `/api/log?count=${count}`),
signin: (code: string) => call<object>('POST', '/api/web/signin', { code }),
signout: () => call<object>('POST', '/api/web/signout'),
grant: (person: string, vault: string, role: Role) => call<object>('POST', '/api/grants', { person, vault, role }),
inviteGrant: (person: string, vault: string, role: Role | null, remove = false) =>
call<object>('POST', '/api/invites/grant', { person, vault, role, remove }),
remove: (person: string, vault: string, delaySeconds: number) =>
call<{ pending?: number }>('POST', '/api/remove', { person, vault, delay_seconds: delaySeconds }),
undoRemove: (pending: number) => call<object>('POST', '/api/remove/undo', { pending }),
invite: (person: string, grants: { vault: string; role: Role }[]) =>
call<{ link: string }>('POST', '/api/invites', { person, grants }),
createVault: (name: string) => call<object>('POST', '/api/vaults', { name }),
vaultSetting: (vault: string, deleteFromDevices: boolean) =>
call<object>('POST', '/api/vaults/settings', { vault, delete_from_devices: deleteFromDevices }),
renameDevice: (deviceId: string, label: string) => call<object>('POST', '/api/devices/rename', { device_id: deviceId, label }),
removeDevice: (deviceId: string) => call<object>('POST', '/api/device/remove', { device_id: deviceId }),
};