Files
pbakaus_impeccable/functions/api/chosen.js
T
Paul BakausandClaude Fable 5 b5ec969c07 Add world roll API and seed telemetry client
/api/roll deals deterministic challenger rolls server-side (same salts and
sha256 ranking as the local seed, verified bit-for-bit); the request log is
the impression record. /api/chosen takes the anonymous choice ping. Events
land in Workers Analytics Engine.

concept-seed.mjs resolves data in order: local catalog dir, roll API,
degraded promotion-only seed. --chosen sends the choice ping; DO_NOT_TRACK
and IMPECCABLE_NO_TELEMETRY disable it. API-dealt seeds carry the telemetry
instruction inline.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-20 22:17:09 -07:00

31 lines
1.2 KiB
JavaScript

// POST /api/chosen { key, poolRevision, chosenId, scope?, mode? }
//
// Anonymous choice ping: records that a world dealt by /api/roll was selected
// as the direction. No project data, no user identity; senders honor
// DO_NOT_TRACK and IMPECCABLE_NO_TELEMETRY before calling. Always answers
// 204 so a failed record can never disturb a design flow.
import { logEvent, CORS_HEADERS } from './_worldroll.js';
export async function onRequestOptions() {
return new Response(null, { status: 204, headers: CORS_HEADERS });
}
export async function onRequestPost({ request, env }) {
try {
const body = await request.json();
const chosenId = typeof body.chosenId === 'string' ? body.chosenId.slice(0, 120) : '';
if (chosenId && /^[a-z0-9-]+$/.test(chosenId)) {
logEvent(env, 'chosen', {
scope: typeof body.scope === 'string' ? body.scope.slice(0, 16) : '',
mode: typeof body.mode === 'string' ? body.mode.slice(0, 16) : '',
poolRevision: typeof body.poolRevision === 'string' ? body.poolRevision.slice(0, 16) : '',
chosenId,
});
}
} catch {
// Malformed pings are dropped silently.
}
return new Response(null, { status: 204, headers: CORS_HEADERS });
}