PY1.0 acceptance (C8 delta check on main f919636; Wave E Y-0 to Y-5 merged):
1. Denylist .3 (gtm/policy, published by this package) adds portfolio-ott-drm
and portfolio-ott-comparison (DRM, Netflix-style, your own Netflix beyond
Menivor), addon-unlaunched (ADDON_LIVE), rally-capacity-purchase
(RALLY_CAPACITY_PURCHASE_LIVE) and at-cost (allowed only next to a live
price source). Re-vendored byte for byte; every new rule has failing
fixtures (policy/test/fixtures/denylist-3-new-phrases.json); .2 fixtures kept.
2. apps/console/app/api/v1/bridge/scribase/{orgs,claims,proof}: signed
(Standard Webhooks, RAILYARD_SCRIBASE_BRIDGE_SECRET), replay-proof calls from
Scribase control-api. The first call creates the Railyard org bound to the
Scribase org id (deterministic owner id, no second sign-up) and mirrors the
add-on into the entitlement (plan "addon"); a lapsed add-on pauses the org
and keeps its data. Keys go only to the Scribase CLI: a claim is a one-time,
pre-approved device code (120 s) exchanged at /api/v1/device/token; a grep
test keeps every bridge handler free of stdout, stderr and log writes.
3. proof answers {slot, state, live, proof:{kind,id,at}, next}; slots whose
package has not landed answer "arriving".
Contract: tests/contract/fixtures/scribase-bridge/contract.json, run by
tests/contract/scribase-bridge.test.ts; the Scribase carve-out tests the same file.
Migration: apps/console/db/migrations/0002_scribase_bridge.sql (idempotent;
applied twice to a scratch local cluster only by test/migration.test.ts).
Env: RAILYARD_SCRIBASE_BRIDGE_SECRET (secret; unset keeps the bridge off).
Tests: console npm test 48/48, tests/contract 2/2, policy 11/11, cli 9/9, mcp 9/9,
tsc --noEmit clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
55 lines
2.2 KiB
TypeScript
55 lines
2.2 KiB
TypeScript
// Apps: create one (plan limits enforced) and the install snippet it shows.
|
|
|
|
import { access } from "./ladder.ts";
|
|
import { randomToken } from "./crypto.ts";
|
|
import type { Repo } from "./repo.ts";
|
|
import type { App } from "./types.ts";
|
|
|
|
export const APP_NAME = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
|
|
export class AppError extends Error {
|
|
code: string;
|
|
constructor(code: string, message: string) {
|
|
super(message);
|
|
this.code = code;
|
|
}
|
|
}
|
|
|
|
export function normaliseAppName(raw: string): string {
|
|
return raw.trim().toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40);
|
|
}
|
|
|
|
/** The plain message for a paused org, or null when the org is not paused. */
|
|
export function pausedMessage(a: { state: string; via?: "addon" }): string | null {
|
|
if (a.state !== "paused") return null;
|
|
return a.via === "addon"
|
|
? "The Scribase add-on has ended, so this is paused. Your apps and data are kept; renew the add-on in Scribase billing to continue."
|
|
: "Railyard is paused. Resume it on the Billing screen.";
|
|
}
|
|
|
|
export async function addApp(repo: Repo, orgId: string, rawName: string, now: Date): Promise<App> {
|
|
const name = normaliseAppName(rawName);
|
|
if (!APP_NAME.test(name)) throw new AppError("invalid_name", "Use letters, numbers and dashes.");
|
|
const a = access(await repo.getEntitlement(orgId), now);
|
|
if (!a.canAddApps) {
|
|
throw new AppError("no_plan", pausedMessage(a) ?? "Add a card on the Billing screen first ($1, credited back).");
|
|
}
|
|
const apps = await repo.listApps(orgId);
|
|
if (apps.length >= a.appsLimit) throw new AppError("limit", `Your plan includes ${a.appsLimit} apps.`);
|
|
if (apps.some((x) => x.name === name)) throw new AppError("exists", `You already have an app called ${name}.`);
|
|
return repo.createApp({ orgId, name, siteKey: `ry_site_${randomToken(18)}` });
|
|
}
|
|
|
|
export interface Snippet {
|
|
script: string;
|
|
deploy: string;
|
|
}
|
|
|
|
/** What the user pastes: one script tag for Insights and one deploy command. The site key is public by design. */
|
|
export function installSnippet(app: Pick<App, "name" | "site_key">, insightsUrl: string): Snippet {
|
|
return {
|
|
script: `<script defer src="${insightsUrl}/s.js" data-site="${app.site_key}"></script>`,
|
|
deploy: `npx railyard deploy --app ${app.name}`,
|
|
};
|
|
}
|