Add recoverable administrator room removal and restoration

Preserve room JSON, seats, credentials and messages while removed rooms deny ordinary reads and writes. Add deliberate room-scoped controls, removed-directory filters, persistent player notices and live-authorized atomic version/revision audit receipts. Retain uncertain room/seat requests and hidden recovery drafts through removal; restore the prior pause/join settings without reviving revoked credentials.

Fix AI readiness after a joining human or human faction change so real lobby starts remain legal.

Verified types, lint, 5314 offline tests, 52 HTTP tests and build. Fourteen authenticated HTTP groups and independent privacy/persistence review passed. Desktop/mobile browser QA confirmed a saved removal after a lost response and refresh, one audit on exact retry, persistent notices and recovery draft continuity. All 1,945 baseline rooms, 4,121 seats and related records preserved. Positive authenticated production admin acceptance remains pending authorized QA operator access; full admin and rules gates remain open.
This commit is contained in:
Quintine committed 2026-09-22 12:01:22 +10:00
1 parent c0cc4de9e1
commit 238de3860d
44 files changed
+4626 -90

No files matched your search

+25 -1
View File
@@ -10,14 +10,30 @@ export class ClientRequestError extends Error {
| 'http'
| 'invalid-response',
readonly status?: number,
readonly code?: string,
) {
super(message);
this.name = 'ClientRequestError';
}
}
export const isRoomRemoved = (error: unknown): error is ClientRequestError =>
error instanceof ClientRequestError && error.code === 'ROOM_REMOVED';
// Controllers subscribe to a public room identifier, never response bodies or
// credentials. A removal observed by discussion or seat controls also closes the
// table. Pending controllers can stay mounted to retain their private retry proof.
const removalListeners = new Set<(room: string) => void>();
export function subscribeRoomRemoval(listener: (room: string) => void) {
removalListeners.add(listener);
return () => { removalListeners.delete(listener); };
}
/** Gateways can report failure after the server has already committed a mutation. */
export function requestMayHaveCompleted(error: unknown): boolean {
// Creation/recovery can commit before their final private read loses to removal.
// A temporary removal is never proof that a preceding mutation did not commit.
if (isRoomRemoved(error)) return true;
if (!(error instanceof ClientRequestError) || error.kind !== 'http')
return true;
return (
@@ -92,7 +108,15 @@ export async function requestJson<T>(
typeof data.error === 'string'
? data.error
: `Request failed (${response.status}).`;
throw new ClientRequestError(message, 'http', response.status);
const code = data && typeof data === 'object' && 'code' in data &&
typeof data.code === 'string' && /^[A-Z_]{1,80}$/.test(data.code) ? data.code : undefined;
if (code === 'ROOM_REMOVED') {
const room = new URL(url, 'http://local.invalid').pathname.match(/^\/api\/rooms\/([A-Z2-9]{8})(?:\/|$)/)?.[1];
if (room) for (const listener of removalListeners) {
try { listener(room); } catch { /* A controller cannot change request semantics. */ }
}
}
throw new ClientRequestError(message, 'http', response.status, code);
}
return data as T;
};