caelum0x 1bbce8d338 fix(bridge): the signed message id names its route and a late orgs sync never flips an entitlement (P-Y1)
Contract scribase-bridge version 2:
- webhook-id is msg_<route>_<24 hex>; the id is inside the Standard Webhooks
  signed content, so a signature made for one route is refused on another
  (401, fixture wrong_route). ai and ai_usage cannot be confused.
- every orgs request carries addon.as_of (Scribase's epoch ms of the state).
  Railyard stores it (migration 0004, addon_as_of) and applies a sync only
  when no newer state is stored: one guarded PATCH through PostgREST. An older
  sync answers 200 with stale: true and changes nothing.
- RAILYARD_BRIDGE_ACCEPT_LEGACY=1 (default off) accepts the P1 sender for the
  minutes between the console and control-api deploys; it never lets an id
  that names another route through.

Tests: bridge 15/15 (3 new), contract 3/3 with the new cases, postgrest-repo
and migration 11/11 (0004 applied twice on a scratch cluster, guarded update
proven in SQL), console suite 66/66, bundle 3/3, tsc clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 23:33:47 +03:00

18 lines
809 B
TypeScript

import { deps } from "../../../../../../lib/deps.ts";
import { json } from "../../../../../../lib/http.ts";
import { handleBridge } from "../service.ts";
export const dynamic = "force-dynamic";
export async function POST(req: Request) {
const { cfg, repo, sites, insights } = deps();
if (!cfg.scribaseBridgeSecret) return json({ error: "bridge_not_configured" }, 503);
const r = await handleBridge(
{ repo, secret: cfg.scribaseBridgeSecret, consoleUrl: cfg.consoleUrl, now: () => new Date(), sites, insights, insightsUrl: cfg.insightsUrl, acceptLegacy: cfg.bridgeAcceptLegacy },
"deploys",
{ id: req.headers.get("webhook-id"), timestamp: req.headers.get("webhook-timestamp"), signature: req.headers.get("webhook-signature") },
await req.text(),
);
return json(r.body, r.status);
}