The code cited its plan instead of saying why: `E28 review J4`, `(R6 S3b)`, `S1 justified…`,
`deep-review round 5`. That plan lives in the private ops repo, so for every reader of this one the
citation was noise, and a sentence whose subject was the plan step ("round 2 showed…") hid its
lesson behind an id. Each one is gone and the "why" kept: a bare citation is deleted, a sentence
carrying a lesson is reworded around it ("a later attempt showed…").
Measured (`scripts/audit_metrics.py`, product code): 652 lines in 270 files carried an epic code by
the definition the next commit holds (507 / 241 by the old, two-digit-only one) -> 0. Across all
code, tests, scripts and configs: ~1100 epic-code lines plus ~320 sprint/round ids.
Behaviour unchanged, checked mechanically: every changed .py file has the same AST once docstrings
are blanked; css/sh/toml/yml/json files are identical once comments are stripped; the only
non-comment changes in TS/JS are test titles, one description string in a contract table, and five
ESLint messages, whose text is all the gates snapshot diff holds. Not touched: Markdown (docs and
the changelog keep their history), Alembic migrations, TV episode notation (`S2 · E5`), DESIGN.md
ids (`C1`, `B4`, `S3h`), tracker ids (`SEC-16`, `DX-17`).
One stale claim fixed on the way: test_hls_reaper's docstring said the player checkpoints "every
10 s whether or not it is playing", which plex/stream.py calls wrong; it now says what the code does.
89 lines
4.0 KiB
TypeScript
89 lines
4.0 KiB
TypeScript
// The signed-in account & session: the bootstrap `me` probe, multi-account switch/list, sign-out,
|
|
// app version, and preference save. Only touches core's req.
|
|
import { req } from "./core";
|
|
import type { DebugSession, DiagnosticsState } from "./diagnostics";
|
|
|
|
export interface Me {
|
|
id: number;
|
|
email: string;
|
|
display_name: string | null;
|
|
avatar_url: string | null;
|
|
role: string;
|
|
/** The latest sign-in on any device (ISO), or null when none is recorded. */
|
|
last_login_at: string | null;
|
|
has_google: boolean;
|
|
/** The address Google answers with, ONLY when it differs from `email` — the backend does that
|
|
* comparison, so a surface can render this whenever it is present. Someone who registered as
|
|
* `me+siftlode@gmail.com` keeps that address; this is the other one that also signs them in. */
|
|
google_email: string | null;
|
|
has_password: boolean;
|
|
google_enabled: boolean;
|
|
plex_enabled: boolean;
|
|
search_source: "scrape" | "api";
|
|
can_read: boolean;
|
|
can_write: boolean;
|
|
pending_invites: number;
|
|
/** Admin-only: sign-ups an admin still has to let in — approved BEFORE they registered, so nothing
|
|
* ever reached the Access-requests queue and its badge read zero (roadmap UX-25). Counted apart
|
|
* from pending_invites because they are different facts, and widening one number silently would
|
|
* change what an existing field means. */
|
|
pending_activations: number;
|
|
/** Admin-only: false when SMTP is incomplete, so every outbound message is silently skipped. */
|
|
email_configured: boolean;
|
|
preferences: Record<string, unknown>;
|
|
/** The consented diagnostics level in force and when it lapses. */
|
|
diagnostics: DiagnosticsState;
|
|
/** The debug session recording right now, if any — a reload resumes it. */
|
|
debug_session: DebugSession | null;
|
|
/** Where a bug report goes — the tracker's repository — or null: download only. */
|
|
issues: { repo: string } | null;
|
|
}
|
|
|
|
/** The `nav.role.*` key an account is shown under. */
|
|
export function roleKey(a: Pick<Me, "role">): "admin" | "user" {
|
|
return a.role === "admin" ? "admin" : "user";
|
|
}
|
|
|
|
/** What an account is called on screen: its display name, else the local part of its email. */
|
|
export function displayName(a: { display_name: string | null; email: string }): string {
|
|
return a.display_name ?? a.email.split("@")[0]!;
|
|
}
|
|
|
|
export interface Account {
|
|
id: number;
|
|
email: string;
|
|
display_name: string | null;
|
|
avatar_url: string | null;
|
|
active: boolean;
|
|
}
|
|
|
|
export interface VersionInfo {
|
|
app_version: string;
|
|
git_sha: string;
|
|
build_date: string | null;
|
|
db_revision: string | null;
|
|
}
|
|
|
|
export const accountApi = {
|
|
// Bootstrap probe: 200 always. Returns the user when signed in, or null when logged out
|
|
// (the endpoint answers `{authenticated:false}` rather than 401, so the public landing never
|
|
// logs a failed request to the console). React Query treats the null as data, not an error.
|
|
me: async (): Promise<Me | null> => {
|
|
// Always 200: `{ authenticated: false }` when logged out, else the full Me + `authenticated`.
|
|
const r = await req<{ authenticated: boolean } & Partial<Me>>("/api/me");
|
|
return r.authenticated ? (r as Me) : null;
|
|
},
|
|
accounts: (): Promise<Account[]> => req("/api/me/accounts"),
|
|
deleteAccount: (): Promise<{ deleted: boolean }> => req("/api/me/account", { method: "DELETE" }),
|
|
switchAccount: (userId: number): Promise<{ ok: boolean; user_id: number }> =>
|
|
req("/api/me/switch", { method: "POST", body: JSON.stringify({ user_id: userId }) }),
|
|
// Signs the current tab's active account out of the browser wallet (per-tab aware via the
|
|
// X-Siftlode-Account header that req() attaches).
|
|
logout: (): Promise<{ ok: boolean; switched: boolean }> =>
|
|
req("/auth/logout", { method: "POST" }),
|
|
version: (): Promise<VersionInfo> => req("/api/version"),
|
|
// Overwriting preferences is idempotent, so let it retry on a transient gateway blip.
|
|
savePrefs: (p: Record<string, unknown>) =>
|
|
req("/api/me/preferences", { method: "PUT", body: JSON.stringify(p) }, { idempotent: true }),
|
|
};
|