mirror of
https://github.com/bitbaum/causius.git
synced 2026-12-04 19:48:21 +01:00
- Helpers list themselves (AI service, legal assistant, licensed lawyer) under a name or pseudonym; the same account keeps matters of its own. Directory search and filters through searchkit and listkit, with the typo suite. - A lawyer's admission is submitted privately (evidence sealed per credential), checked by a staff reviewer, and published as an SD-JWT signed with Ed25519: the place in clear, the legal name only as a salted digest. Key at /.well-known/jwks.json; anyone can check at /verify. A lawyer is listed only where verified. - An owner asks a helper about a matter, with or without their personal details; the request is previewed exactly as it will be read. Accepted, the helper becomes a participant; anonymisation is applied in the store, so no route can forget it. A lawyer hands over the checked name with proof. Ending it removes access in the same transaction. - Reviewers are staff/admin accounts, granted by the Grant role workflow. - Who may do what is lib/professions.ts, the one domain file, so Diplodoctor reuses the engine by changing it. - Fixes: the account menu label template; one site URL instead of three, with a dev-only origin so local sign-in works. Claude-Session: https://claude.ai/code/session_018Lem7GyhyyjKhmwjG8G7Ud Co-authored-by: Claude <noreply@anthropic.com>
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { auth } from "@/lib/auth";
|
|
import { encryptionConfigured, masterKey } from "@/lib/crypto";
|
|
import { dbConfigured, getDb, type Db } from "@/lib/db";
|
|
import { Refused } from "../helpers/store";
|
|
import { NotAllowed } from "./store";
|
|
|
|
/**
|
|
* The two checks every matter route makes, in one place: is anyone signed in,
|
|
* and is this deployment able to keep a matter safely (database AND master
|
|
* key). The third check — does this person take part in THIS matter — is made
|
|
* by the store itself, on every call.
|
|
*/
|
|
export type Ctx = { db: Db; master: Buffer; sub: string; name: string | null };
|
|
|
|
export function json(body: unknown, status = 200, headers?: HeadersInit) {
|
|
return Response.json(body, { status, headers });
|
|
}
|
|
|
|
export async function context(): Promise<Ctx | Response> {
|
|
if (!dbConfigured() || !encryptionConfigured()) return json({ error: "not_configured" }, 503);
|
|
const session = await auth();
|
|
const sub = session?.actorId;
|
|
if (!sub) return json({ error: "sign_in" }, 401);
|
|
return { db: getDb(), master: masterKey(), sub, name: session.user?.name ?? null };
|
|
}
|
|
|
|
/** Turn the store's refusals into answers rather than 500s. */
|
|
export async function guarded(fn: () => Promise<Response>): Promise<Response> {
|
|
try {
|
|
return await fn();
|
|
} catch (error) {
|
|
if (error instanceof NotAllowed) return json({ error: "not_allowed" }, 403);
|
|
// A rule the request ran into (already asked, needs verification…): named, so the screen can say what to do next.
|
|
if (error instanceof Refused) return json({ error: error.code }, 409);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
export async function body(request: Request): Promise<unknown> {
|
|
try {
|
|
return await request.json();
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|