Repository Public
1// SP Notes Core2// File: Sources/SPNotesAPI/NotesAPI+Workspace.swift3// Description: The home dashboard and its layout, the settings and audit log, the page lists (trash included) and4// the purge of old trash.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import Foundation910extension NotesAPI {11 // MARK: - Page lists and trash1213 /// `GET /api/pages?view=&limit=` — a list of pages without their documents (≤ 100, server default 20).14 /// `.trash` is the listing of the trash (there is no `GET /api/trash`).15 public func pages(view: PageListView, limit: Int? = nil) async throws -> [PageListItem] {16 let query = [URLQueryItem(name: "view", value: view.queryValue)] + Self.item("limit", limit.map(String.init))17 return try await client.decode([PageListItem].self, .get("/api/pages", query: query))18 }1920 /// The trash: `GET /api/pages?view=trash` (≤ 100 pages, most recently deleted first). Restore with21 /// `restorePage(id:)`, delete for good with `purgePage(id:)` or `emptyTrash(olderThanDays:)`.22 public func trashedPages(limit: Int = 100) async throws -> [PageListItem] {23 try await pages(view: .trash, limit: limit)24 }2526 private struct PurgeOldBody: Encodable {27 var action = "purge-old"28 var days: Int?29 }3031 /// `POST /api/trash` `{ action: "purge-old", days? }` — permanently deletes what was trashed more than `days` ago32 /// (1…365, server default 30) and reports what is left. Needs a fresh passkey verification (`APIError.needsReauth`).33 @discardableResult34 public func purgeOldTrash(days: Int? = nil) async throws -> TrashPurgeResult {35 try await client.decode(TrashPurgeResult.self, .json(.post, "/api/trash", body: PurgeOldBody(days: days)))36 }3738 // MARK: - Dashboard3940 /// `GET /api/dashboard` — layout, recent / pinned / modified pages, projects, tasks due, research, graph and AI41 /// usage of the day, in one call. No provider is called.42 public func dashboard() async throws -> Dashboard {43 try await client.decode(Dashboard.self, .get("/api/dashboard"))44 }4546 private struct LayoutBody: Encodable {47 var widgets: [DashboardWidget]?48 var reset: Bool?49 }5051 /// `PUT /api/dashboard` `{ widgets }` (≤ 40) — saves the layout. `400` for an unknown widget type or size.52 @discardableResult53 public func saveDashboardLayout(_ widgets: [DashboardWidget], idempotencyKey: String? = nil) async throws -> DashboardLayout {54 try await client.decode(DashboardLayout.self, .json(.put, "/api/dashboard", body: LayoutBody(widgets: widgets), idempotencyKey: idempotencyKey))55 }5657 /// `PUT /api/dashboard` `{ reset: true }` — back to the default layout, which is returned.58 @discardableResult59 public func resetDashboardLayout(idempotencyKey: String? = nil) async throws -> DashboardLayout {60 try await client.decode(DashboardLayout.self, .json(.put, "/api/dashboard", body: LayoutBody(reset: true), idempotencyKey: idempotencyKey))61 }6263 /// `GET /api/dashboard/summary` — the stored weekly digest, `nil` when none was ever generated.64 public func dashboardSummary() async throws -> DashboardSummary? {65 try await client.decode(DashboardSummary?.self, .get("/api/dashboard/summary"))66 }6768 /// `POST /api/dashboard/summary` — writes the weekly digest from the pages edited in the last 7 days and the69 /// open tasks. **Calls a paid model.** `400` when there is nothing to summarise, `502` when the provider fails.70 public func generateDashboardSummary() async throws -> DashboardSummary {71 try await client.decode(DashboardSummary.self, HTTPRequest(method: .post, path: "/api/dashboard/summary"))72 }7374 // MARK: - Settings7576 /// `GET /api/settings`.77 public func settings() async throws -> UserSettings {78 try await client.decode(UserSettings.self, .get("/api/settings"))79 }8081 /// `PATCH /api/settings` — display name, e-mail, preferences (merged key by key).82 @discardableResult83 public func updateSettings(_ changes: SettingsChanges, idempotencyKey: String? = nil) async throws -> SettingsUpdateResult {84 try await client.decode(SettingsUpdateResult.self, .json(.patch, "/api/settings", body: changes, idempotencyKey: idempotencyKey))85 }8687 /// `GET /api/settings/audit[?limit=]` — the most recent audit entries of the account (1…200, default 50).88 public func auditLog(limit: Int? = nil) async throws -> [AuditEntry] {89 try await client.decode([AuditEntry].self, .get("/api/settings/audit", query: Self.item("limit", limit.map(String.init))))90 }91}92