// REST implementation of the repository seam: maps each semantic operation to the // existing HTTP endpoint via `api/client`. This is the ONLY place that knows about // URL paths, query strings, and multipart bodies. Behaviour here must stay a // verbatim mirror of the calls the stores/views made before the seam existed — the // web app is unchanged; the offline `local.ts` source (M10.5) is the alternative. import { api } from "../api/client"; import type { Note, NoteRevision } from "../stores/notes"; import type { Label } from "../stores/labels"; import type { SavedFilter } from "../stores/savedFilters"; import type { Device } from "../stores/devices"; import type { TitleEntry } from "../stores/titles"; import type { User } from "../stores/session"; import type { PublicConfig } from "../stores/config"; import type { DeviceToken, ImportResult, NoteChanges, NoteCreateInput, NoteListQuery, ChecklistItemChanges, Repo, } from "./repo"; // Render a board query to the GET /api/notes query string. Mirrors the param // building that used to live in notes.store.load()/TimelineView (order-preserving; // query-param order is irrelevant to the server, but kept close for review). function notesQuery(q: NoteListQuery): string { const params = new URLSearchParams(); params.set("filter", q.view); if (q.labelId) params.append("label", q.labelId); for (const id of q.facets?.label ?? []) if (id) params.append("label", id); if (q.facets?.q) params.set("q", q.facets.q); if (q.facets?.color) params.set("color", q.facets.color); if (q.facets?.has_reminder) params.set("has_reminder", "true"); if (q.facets?.has_attachment) params.set("has_attachment", "true"); if (q.facets?.created_after) params.set("created_after", q.facets.created_after); if (q.facets?.created_before) params.set("created_before", q.facets.created_before); if (q.sort) params.set("sort", q.sort); return params.toString(); } function fileForm(file: File): FormData { const form = new FormData(); form.append("file", file); return form; } export const rest: Repo = { config: { get: () => api.get("/api/config"), }, auth: { me: () => api.get("/api/auth/me"), login: (email, password) => api.post("/api/auth/login", { email, password }), register: (email, password, displayName) => api.post("/api/auth/register", { email, password, display_name: displayName }), logout: () => api.post("/api/auth/logout"), }, devices: { list: async () => (await api.get<{ devices: Device[] }>("/api/auth/devices")).devices, create: (name) => api.post("/api/auth/devices", { name }), remove: (id) => api.del(`/api/auth/devices/${id}`), }, labels: { list: async () => (await api.get<{ labels: Label[] }>("/api/labels")).labels, create: (name) => api.post