feat(cli): railyard deploy with branch previews, deploy records and rollback (RYP-D4, Y-3)
npx railyard (zero dependencies):
- login: device flow against the console; the org token is saved 0600
and never printed; no option takes a key or token.
- deploy: detects Next.js (OpenNext build for Workers), Vite, Astro
(static output) or plain static; anything else stops with one line
that says what to change (SvelteKit, Remix, Nuxt, server Astro...).
Uses wrangler's own OAuth login on the user's machine, names the
Worker <app> on main and <app>-<branch> elsewhere, and records URL,
commit, branch, framework, duration and status in the console.
- rollback: wrangler rollback to the previous successful version id of
the same branch, recorded with rollback_of.
- deploys: lists recent deploys.
Console: /api/v1/deploys (POST record, GET list) and /api/v1/deploys/:id
with org-scoped bearer tokens; the first deploy of a new app name creates
the app within the plan's limits; a paused or card-less org is refused
with 402. The Apps screen lists recent deploys.
Tests: the CLI runs against a mocked wrangler and the real console
device-flow and deploy code over local HTTP (login, main deploy, branch
preview, records, rollback, OpenNext path, failure, refusals, no token
in any output); deploy service tests cover org isolation and input
validation; README and CLI strings pass the copy lint. The run on a
real Cloudflare account is owner-run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 15:54:03 +03:00
|
|
|
// A local console for CLI tests: the real console device-flow, token and
|
|
|
|
|
// deploy-record code (apps/console) over HTTP, on an in-memory repository.
|
|
|
|
|
import { createServer } from "node:http";
|
|
|
|
|
|
|
|
|
|
import { MemoryRepo } from "../../../apps/console/lib/repo.ts";
|
|
|
|
|
import { applyLadder } from "../../../apps/console/lib/ladder.ts";
|
|
|
|
|
import { emptyEntitlement } from "../../../apps/console/lib/types.ts";
|
feat(ship): deploy from a Scribase project with its URL and anon key, link-scribase, and the deploy slot on the bridge (PY1.2)
Railyard side of PY1.2 (SC-E2, SP-F2). Acceptance:
1. packages/cli/src/scribase/env.mjs: in a Scribase project folder,
`railyard deploy` reads the public URL and anon key `scribase init` wrote
(.env, .env.local; NEXT_PUBLIC_/VITE_/EXPO_PUBLIC_/PUBLIC_ variants) into
the build env and onto the Worker (--var), prints their names only, and
leaves secrets out by name (service role key, SECRET/PASSWORD names, a
service-role JWT under any name). `railyard link-scribase` reads a one-time
claim from stdin (no flag takes it), exchanges it once and saves the token
0600; nothing is printed.
2. A git branch with Scribase branch settings (.scribase/branches/<branch>.env,
written by the PS2.0 hook) deploys its <app>-<branch> preview against that
branch (fixture test).
3. Bridge: deploy slot landed; proof is the latest successful deploy; new
route POST /api/v1/bridge/scribase/deploys lists the bound org's deploys for
the Scribase Deploy tab (org isolation test). Contract cases added.
4. Real Cloudflare end-to-end stays owner-run (tests use the fake wrangler).
Tests: packages/cli 13/13, console bridge + deploys 15/15, tests/contract 3/3,
tsc clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 20:42:19 +03:00
|
|
|
import { approveDevice, createApprovedDevice, orgForBearer, pollDevice, startDevice } from "../../../apps/console/lib/tokens.ts";
|
feat(cli): railyard deploy with branch previews, deploy records and rollback (RYP-D4, Y-3)
npx railyard (zero dependencies):
- login: device flow against the console; the org token is saved 0600
and never printed; no option takes a key or token.
- deploy: detects Next.js (OpenNext build for Workers), Vite, Astro
(static output) or plain static; anything else stops with one line
that says what to change (SvelteKit, Remix, Nuxt, server Astro...).
Uses wrangler's own OAuth login on the user's machine, names the
Worker <app> on main and <app>-<branch> elsewhere, and records URL,
commit, branch, framework, duration and status in the console.
- rollback: wrangler rollback to the previous successful version id of
the same branch, recorded with rollback_of.
- deploys: lists recent deploys.
Console: /api/v1/deploys (POST record, GET list) and /api/v1/deploys/:id
with org-scoped bearer tokens; the first deploy of a new app name creates
the app within the plan's limits; a paused or card-less org is refused
with 402. The Apps screen lists recent deploys.
Tests: the CLI runs against a mocked wrangler and the real console
device-flow and deploy code over local HTTP (login, main deploy, branch
preview, records, rollback, OpenNext path, failure, refusals, no token
in any output); deploy service tests cover org isolation and input
validation; README and CLI strings pass the copy lint. The run on a
real Cloudflare account is owner-run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 15:54:03 +03:00
|
|
|
import { listDeploys, parseDeployInput, recordDeploy } from "../../../apps/console/app/api/v1/deploys/service.ts";
|
feat(ship): custom domains for shipped apps on the customer's own Cloudflare account (QY1.5, I6)
- packages/cli/src/domains.mjs: a dependency-free client of Cloudflare's
public Workers Custom Domains API (zones lookup, PUT/GET/DELETE
/accounts/{id}/workers/domains, certificate pack state). Cloudflare
issues the TLS certificate; a domain reads active once it is. The token
goes in the Authorization header only and is scrubbed from every error.
Byte copy at apps/console/lib/ship/cf-domains.mjs (drift test).
- railyard domains [add|remove HOSTNAME] [--app]: the console attaches the
hostname to the app's production Worker with the org's Cloudflare grant
(the QY1.1 OAuth step; the access token is opened and used inside the
console only). Without a grant (409 no_cloudflare_grant) the CLI does the
same with the local login (CLOUDFLARE_API_TOKEN or the wrangler login
file after `wrangler whoami`) and the console records the outcome. Adding
an attached hostname keeps it; one on another Worker is refused; remove
is idempotent; a hostname outside the account's zones is refused plainly.
- Console: migration 0010 railyard.app_domains (one org per hostname,
lower case, cascade, RLS, no anon); GET/POST/DELETE /api/v1/domains and
POST /api/v1/domains/record (CLI bearer); states refreshed from
Cloudflare when the org has a grant. Cloudflare OAuth default scopes add
zone:read and ssl_certs:write (orgs linked before need to run
railyard link once more for console-side domains).
- Scribase bridge: new signed route domains {scribase_org_id, app?} ->
{available, domains:[{app, hostname, state, checked_at, created_at}],
next} for the Deploy tab; contract fixture v2 adds it (additive).
Tests: CLI 23/23 (new domains.test.mjs 5: grant path with the real console
handlers and a fake Cloudflare, local-login path, wrangler config file,
refusals, idempotent remove, no token printed or sent to the console);
console 147/147 (new lib/ship/domains.test.ts 4: drift, worker naming
equal to the CLI's, attach/detach and cross-org refusal, record and
refresh, bridge listing; 0010 migration on a scratch PG); contract 6/6;
console tsc clean.
Owner-only: one real-domain proof (railyard domains add on a domain in the
owner's Cloudflare account) is not run here; record it at the deploy gate.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 13:45:57 +03:00
|
|
|
import { addApp } from "../../../apps/console/lib/apps.ts";
|
|
|
|
|
import { seal } from "../../../apps/console/lib/ai/seal.ts";
|
|
|
|
|
import { CloudflareOAuth } from "../../../apps/console/lib/ship/cloudflare.ts";
|
|
|
|
|
import { domainsH, domainsRecordH } from "../../../apps/console/lib/ship/http.ts";
|
|
|
|
|
import { MemoryShipStore } from "../../../apps/console/lib/ship/store.ts";
|
feat(cli): railyard deploy with branch previews, deploy records and rollback (RYP-D4, Y-3)
npx railyard (zero dependencies):
- login: device flow against the console; the org token is saved 0600
and never printed; no option takes a key or token.
- deploy: detects Next.js (OpenNext build for Workers), Vite, Astro
(static output) or plain static; anything else stops with one line
that says what to change (SvelteKit, Remix, Nuxt, server Astro...).
Uses wrangler's own OAuth login on the user's machine, names the
Worker <app> on main and <app>-<branch> elsewhere, and records URL,
commit, branch, framework, duration and status in the console.
- rollback: wrangler rollback to the previous successful version id of
the same branch, recorded with rollback_of.
- deploys: lists recent deploys.
Console: /api/v1/deploys (POST record, GET list) and /api/v1/deploys/:id
with org-scoped bearer tokens; the first deploy of a new app name creates
the app within the plan's limits; a paused or card-less org is refused
with 402. The Apps screen lists recent deploys.
Tests: the CLI runs against a mocked wrangler and the real console
device-flow and deploy code over local HTTP (login, main deploy, branch
preview, records, rollback, OpenNext path, failure, refusals, no token
in any output); deploy service tests cover org isolation and input
validation; README and CLI strings pass the copy lint. The run on a
real Cloudflare account is owner-run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 15:54:03 +03:00
|
|
|
|
feat(ship): custom domains for shipped apps on the customer's own Cloudflare account (QY1.5, I6)
- packages/cli/src/domains.mjs: a dependency-free client of Cloudflare's
public Workers Custom Domains API (zones lookup, PUT/GET/DELETE
/accounts/{id}/workers/domains, certificate pack state). Cloudflare
issues the TLS certificate; a domain reads active once it is. The token
goes in the Authorization header only and is scrubbed from every error.
Byte copy at apps/console/lib/ship/cf-domains.mjs (drift test).
- railyard domains [add|remove HOSTNAME] [--app]: the console attaches the
hostname to the app's production Worker with the org's Cloudflare grant
(the QY1.1 OAuth step; the access token is opened and used inside the
console only). Without a grant (409 no_cloudflare_grant) the CLI does the
same with the local login (CLOUDFLARE_API_TOKEN or the wrangler login
file after `wrangler whoami`) and the console records the outcome. Adding
an attached hostname keeps it; one on another Worker is refused; remove
is idempotent; a hostname outside the account's zones is refused plainly.
- Console: migration 0010 railyard.app_domains (one org per hostname,
lower case, cascade, RLS, no anon); GET/POST/DELETE /api/v1/domains and
POST /api/v1/domains/record (CLI bearer); states refreshed from
Cloudflare when the org has a grant. Cloudflare OAuth default scopes add
zone:read and ssl_certs:write (orgs linked before need to run
railyard link once more for console-side domains).
- Scribase bridge: new signed route domains {scribase_org_id, app?} ->
{available, domains:[{app, hostname, state, checked_at, created_at}],
next} for the Deploy tab; contract fixture v2 adds it (additive).
Tests: CLI 23/23 (new domains.test.mjs 5: grant path with the real console
handlers and a fake Cloudflare, local-login path, wrangler config file,
refusals, idempotent remove, no token printed or sent to the console);
console 147/147 (new lib/ship/domains.test.ts 4: drift, worker naming
equal to the CLI's, attach/detach and cross-org refusal, record and
refresh, bridge listing; 0010 migration on a scratch PG); contract 6/6;
console tsc clean.
Owner-only: one real-domain proof (railyard domains add on a domain in the
owner's Cloudflare account) is not run here; record it at the deploy gate.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 13:45:57 +03:00
|
|
|
const CREDS_KEY = Buffer.alloc(32, 7).toString("base64");
|
|
|
|
|
|
|
|
|
|
/** The console's ship deps for custom domains (QY1.5) against a fake Cloudflare; `grant` seals one for the org. */
|
|
|
|
|
async function shipFor(repo, orgId, cloudflare) {
|
|
|
|
|
if (!cloudflare) return null;
|
|
|
|
|
const store = new MemoryShipStore();
|
|
|
|
|
const oauth = new CloudflareOAuth({ clientId: "cid", clientSecret: "cs", redirectUri: "http://x/cb", scopes: ["zone:read"], tokenUrl: `${cloudflare.base}/oauth2/token`, apiBase: cloudflare.api });
|
|
|
|
|
return { store, repo, cloudflare: oauth, github: null, oidcKeys: async () => [], consoleUrl: "http://console", credentialsKey: CREDS_KEY, sessionSecret: "s".repeat(32) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function grantCloudflare(ship, orgId, accountId) {
|
|
|
|
|
const r = await seal(CREDS_KEY, `railyard:cloudflare:refresh:${orgId}`, "cf-refresh-1");
|
|
|
|
|
await ship.store.saveCloudflare({ org_id: orgId, account_id: accountId, account_name: "Shop", refresh_nonce: r.nonce, refresh_ciphertext: r.ciphertext, access_nonce: null, access_ciphertext: null, access_expires_at: null, updated_at: new Date().toISOString() });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function startConsole({ cloudflare = null } = {}) {
|
feat(cli): railyard deploy with branch previews, deploy records and rollback (RYP-D4, Y-3)
npx railyard (zero dependencies):
- login: device flow against the console; the org token is saved 0600
and never printed; no option takes a key or token.
- deploy: detects Next.js (OpenNext build for Workers), Vite, Astro
(static output) or plain static; anything else stops with one line
that says what to change (SvelteKit, Remix, Nuxt, server Astro...).
Uses wrangler's own OAuth login on the user's machine, names the
Worker <app> on main and <app>-<branch> elsewhere, and records URL,
commit, branch, framework, duration and status in the console.
- rollback: wrangler rollback to the previous successful version id of
the same branch, recorded with rollback_of.
- deploys: lists recent deploys.
Console: /api/v1/deploys (POST record, GET list) and /api/v1/deploys/:id
with org-scoped bearer tokens; the first deploy of a new app name creates
the app within the plan's limits; a paused or card-less org is refused
with 402. The Apps screen lists recent deploys.
Tests: the CLI runs against a mocked wrangler and the real console
device-flow and deploy code over local HTTP (login, main deploy, branch
preview, records, rollback, OpenNext path, failure, refusals, no token
in any output); deploy service tests cover org isolation and input
validation; README and CLI strings pass the copy lint. The run on a
real Cloudflare account is owner-run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 15:54:03 +03:00
|
|
|
const repo = new MemoryRepo();
|
|
|
|
|
const org = await repo.createOrgForUser({ userId: "u1", email: "founder@example.com", name: "founder" });
|
|
|
|
|
const now = new Date();
|
|
|
|
|
await repo.saveEntitlement(applyLadder(emptyEntitlement(org.id, now), { kind: "card_check_paid", paymentId: "p1", customerId: null, at: now }).ent);
|
|
|
|
|
const seen = [];
|
feat(ship): custom domains for shipped apps on the customer's own Cloudflare account (QY1.5, I6)
- packages/cli/src/domains.mjs: a dependency-free client of Cloudflare's
public Workers Custom Domains API (zones lookup, PUT/GET/DELETE
/accounts/{id}/workers/domains, certificate pack state). Cloudflare
issues the TLS certificate; a domain reads active once it is. The token
goes in the Authorization header only and is scrubbed from every error.
Byte copy at apps/console/lib/ship/cf-domains.mjs (drift test).
- railyard domains [add|remove HOSTNAME] [--app]: the console attaches the
hostname to the app's production Worker with the org's Cloudflare grant
(the QY1.1 OAuth step; the access token is opened and used inside the
console only). Without a grant (409 no_cloudflare_grant) the CLI does the
same with the local login (CLOUDFLARE_API_TOKEN or the wrangler login
file after `wrangler whoami`) and the console records the outcome. Adding
an attached hostname keeps it; one on another Worker is refused; remove
is idempotent; a hostname outside the account's zones is refused plainly.
- Console: migration 0010 railyard.app_domains (one org per hostname,
lower case, cascade, RLS, no anon); GET/POST/DELETE /api/v1/domains and
POST /api/v1/domains/record (CLI bearer); states refreshed from
Cloudflare when the org has a grant. Cloudflare OAuth default scopes add
zone:read and ssl_certs:write (orgs linked before need to run
railyard link once more for console-side domains).
- Scribase bridge: new signed route domains {scribase_org_id, app?} ->
{available, domains:[{app, hostname, state, checked_at, created_at}],
next} for the Deploy tab; contract fixture v2 adds it (additive).
Tests: CLI 23/23 (new domains.test.mjs 5: grant path with the real console
handlers and a fake Cloudflare, local-login path, wrangler config file,
refusals, idempotent remove, no token printed or sent to the console);
console 147/147 (new lib/ship/domains.test.ts 4: drift, worker naming
equal to the CLI's, attach/detach and cross-org refusal, record and
refresh, bridge listing; 0010 migration on a scratch PG); contract 6/6;
console tsc clean.
Owner-only: one real-domain proof (railyard domains add on a domain in the
owner's Cloudflare account) is not run here; record it at the deploy gate.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 13:45:57 +03:00
|
|
|
if (cloudflare) await addApp(repo, org.id, "shop", now);
|
|
|
|
|
const ship = await shipFor(repo, org.id, cloudflare);
|
feat(cli): railyard deploy with branch previews, deploy records and rollback (RYP-D4, Y-3)
npx railyard (zero dependencies):
- login: device flow against the console; the org token is saved 0600
and never printed; no option takes a key or token.
- deploy: detects Next.js (OpenNext build for Workers), Vite, Astro
(static output) or plain static; anything else stops with one line
that says what to change (SvelteKit, Remix, Nuxt, server Astro...).
Uses wrangler's own OAuth login on the user's machine, names the
Worker <app> on main and <app>-<branch> elsewhere, and records URL,
commit, branch, framework, duration and status in the console.
- rollback: wrangler rollback to the previous successful version id of
the same branch, recorded with rollback_of.
- deploys: lists recent deploys.
Console: /api/v1/deploys (POST record, GET list) and /api/v1/deploys/:id
with org-scoped bearer tokens; the first deploy of a new app name creates
the app within the plan's limits; a paused or card-less org is refused
with 402. The Apps screen lists recent deploys.
Tests: the CLI runs against a mocked wrangler and the real console
device-flow and deploy code over local HTTP (login, main deploy, branch
preview, records, rollback, OpenNext path, failure, refusals, no token
in any output); deploy service tests cover org isolation and input
validation; README and CLI strings pass the copy lint. The run on a
real Cloudflare account is owner-run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 15:54:03 +03:00
|
|
|
const server = createServer(async (req, res) => {
|
|
|
|
|
let raw = "";
|
|
|
|
|
for await (const c of req) raw += c;
|
|
|
|
|
seen.push({ method: req.method, url: req.url, auth: req.headers.authorization ?? null, body: raw });
|
|
|
|
|
const send = (status, body) => {
|
|
|
|
|
res.writeHead(status, { "content-type": "application/json" });
|
|
|
|
|
res.end(JSON.stringify(body));
|
|
|
|
|
};
|
|
|
|
|
const url = new URL(req.url, "http://x");
|
|
|
|
|
const base = `http://127.0.0.1:${server.address().port}`;
|
|
|
|
|
if (req.method === "POST" && url.pathname === "/api/v1/device/code") {
|
|
|
|
|
const d = await startDevice(repo, base, new Date());
|
|
|
|
|
// The signed-in user approves the code in the browser.
|
|
|
|
|
setTimeout(() => approveDevice(repo, d.user_code, org.id, "u1", new Date()), 20);
|
|
|
|
|
return send(200, { ...d, interval: 0.01 });
|
|
|
|
|
}
|
|
|
|
|
if (req.method === "POST" && url.pathname === "/api/v1/device/token") {
|
|
|
|
|
const r = await pollDevice(repo, JSON.parse(raw).device_code, new Date());
|
|
|
|
|
return send(r.status, r.body);
|
|
|
|
|
}
|
feat(ship): custom domains for shipped apps on the customer's own Cloudflare account (QY1.5, I6)
- packages/cli/src/domains.mjs: a dependency-free client of Cloudflare's
public Workers Custom Domains API (zones lookup, PUT/GET/DELETE
/accounts/{id}/workers/domains, certificate pack state). Cloudflare
issues the TLS certificate; a domain reads active once it is. The token
goes in the Authorization header only and is scrubbed from every error.
Byte copy at apps/console/lib/ship/cf-domains.mjs (drift test).
- railyard domains [add|remove HOSTNAME] [--app]: the console attaches the
hostname to the app's production Worker with the org's Cloudflare grant
(the QY1.1 OAuth step; the access token is opened and used inside the
console only). Without a grant (409 no_cloudflare_grant) the CLI does the
same with the local login (CLOUDFLARE_API_TOKEN or the wrangler login
file after `wrangler whoami`) and the console records the outcome. Adding
an attached hostname keeps it; one on another Worker is refused; remove
is idempotent; a hostname outside the account's zones is refused plainly.
- Console: migration 0010 railyard.app_domains (one org per hostname,
lower case, cascade, RLS, no anon); GET/POST/DELETE /api/v1/domains and
POST /api/v1/domains/record (CLI bearer); states refreshed from
Cloudflare when the org has a grant. Cloudflare OAuth default scopes add
zone:read and ssl_certs:write (orgs linked before need to run
railyard link once more for console-side domains).
- Scribase bridge: new signed route domains {scribase_org_id, app?} ->
{available, domains:[{app, hostname, state, checked_at, created_at}],
next} for the Deploy tab; contract fixture v2 adds it (additive).
Tests: CLI 23/23 (new domains.test.mjs 5: grant path with the real console
handlers and a fake Cloudflare, local-login path, wrangler config file,
refusals, idempotent remove, no token printed or sent to the console);
console 147/147 (new lib/ship/domains.test.ts 4: drift, worker naming
equal to the CLI's, attach/detach and cross-org refusal, record and
refresh, bridge listing; 0010 migration on a scratch PG); contract 6/6;
console tsc clean.
Owner-only: one real-domain proof (railyard domains add on a domain in the
owner's Cloudflare account) is not run here; record it at the deploy gate.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 13:45:57 +03:00
|
|
|
if (url.pathname === "/api/v1/domains" || url.pathname === "/api/v1/domains/record") {
|
|
|
|
|
const request = new Request(`${base}${req.url}`, { method: req.method, headers: { authorization: req.headers.authorization ?? "", "content-type": "application/json" }, body: req.method === "GET" ? undefined : raw });
|
|
|
|
|
const r = await (url.pathname === "/api/v1/domains" ? domainsH : domainsRecordH)(ship, repo, request, new Date());
|
|
|
|
|
res.writeHead(r.status, { "content-type": "application/json" });
|
|
|
|
|
return res.end(await r.text());
|
|
|
|
|
}
|
feat(cli): railyard deploy with branch previews, deploy records and rollback (RYP-D4, Y-3)
npx railyard (zero dependencies):
- login: device flow against the console; the org token is saved 0600
and never printed; no option takes a key or token.
- deploy: detects Next.js (OpenNext build for Workers), Vite, Astro
(static output) or plain static; anything else stops with one line
that says what to change (SvelteKit, Remix, Nuxt, server Astro...).
Uses wrangler's own OAuth login on the user's machine, names the
Worker <app> on main and <app>-<branch> elsewhere, and records URL,
commit, branch, framework, duration and status in the console.
- rollback: wrangler rollback to the previous successful version id of
the same branch, recorded with rollback_of.
- deploys: lists recent deploys.
Console: /api/v1/deploys (POST record, GET list) and /api/v1/deploys/:id
with org-scoped bearer tokens; the first deploy of a new app name creates
the app within the plan's limits; a paused or card-less org is refused
with 402. The Apps screen lists recent deploys.
Tests: the CLI runs against a mocked wrangler and the real console
device-flow and deploy code over local HTTP (login, main deploy, branch
preview, records, rollback, OpenNext path, failure, refusals, no token
in any output); deploy service tests cover org isolation and input
validation; README and CLI strings pass the copy lint. The run on a
real Cloudflare account is owner-run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 15:54:03 +03:00
|
|
|
const who = await orgForBearer(repo, req.headers.authorization ?? null);
|
|
|
|
|
if (!who) return send(401, { error: "unauthorized" });
|
|
|
|
|
if (url.pathname === "/api/v1/deploys" && req.method === "POST") {
|
|
|
|
|
const input = parseDeployInput(JSON.parse(raw));
|
|
|
|
|
if (typeof input === "string") return send(400, { error: input });
|
|
|
|
|
const r = await recordDeploy(repo, who.orgId, input, new Date());
|
|
|
|
|
return send(r.status, r.body);
|
|
|
|
|
}
|
|
|
|
|
if (url.pathname === "/api/v1/deploys" && req.method === "GET") {
|
|
|
|
|
const r = await listDeploys(repo, who.orgId, url.searchParams.get("app"), url.searchParams.get("branch"));
|
|
|
|
|
return send(r.status, r.body);
|
|
|
|
|
}
|
|
|
|
|
send(404, { error: "not found" });
|
|
|
|
|
});
|
|
|
|
|
await new Promise((r) => server.listen(0, "127.0.0.1", r));
|
feat(ship): deploy from a Scribase project with its URL and anon key, link-scribase, and the deploy slot on the bridge (PY1.2)
Railyard side of PY1.2 (SC-E2, SP-F2). Acceptance:
1. packages/cli/src/scribase/env.mjs: in a Scribase project folder,
`railyard deploy` reads the public URL and anon key `scribase init` wrote
(.env, .env.local; NEXT_PUBLIC_/VITE_/EXPO_PUBLIC_/PUBLIC_ variants) into
the build env and onto the Worker (--var), prints their names only, and
leaves secrets out by name (service role key, SECRET/PASSWORD names, a
service-role JWT under any name). `railyard link-scribase` reads a one-time
claim from stdin (no flag takes it), exchanges it once and saves the token
0600; nothing is printed.
2. A git branch with Scribase branch settings (.scribase/branches/<branch>.env,
written by the PS2.0 hook) deploys its <app>-<branch> preview against that
branch (fixture test).
3. Bridge: deploy slot landed; proof is the latest successful deploy; new
route POST /api/v1/bridge/scribase/deploys lists the bound org's deploys for
the Scribase Deploy tab (org isolation test). Contract cases added.
4. Real Cloudflare end-to-end stays owner-run (tests use the fake wrangler).
Tests: packages/cli 13/13, console bridge + deploys 15/15, tests/contract 3/3,
tsc clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 20:42:19 +03:00
|
|
|
// A one-time claim, as the Scribase bridge issues it (PY1.0).
|
|
|
|
|
const claim = () => createApprovedDevice(repo, org.id, "u1", 120, new Date());
|
feat(ship): custom domains for shipped apps on the customer's own Cloudflare account (QY1.5, I6)
- packages/cli/src/domains.mjs: a dependency-free client of Cloudflare's
public Workers Custom Domains API (zones lookup, PUT/GET/DELETE
/accounts/{id}/workers/domains, certificate pack state). Cloudflare
issues the TLS certificate; a domain reads active once it is. The token
goes in the Authorization header only and is scrubbed from every error.
Byte copy at apps/console/lib/ship/cf-domains.mjs (drift test).
- railyard domains [add|remove HOSTNAME] [--app]: the console attaches the
hostname to the app's production Worker with the org's Cloudflare grant
(the QY1.1 OAuth step; the access token is opened and used inside the
console only). Without a grant (409 no_cloudflare_grant) the CLI does the
same with the local login (CLOUDFLARE_API_TOKEN or the wrangler login
file after `wrangler whoami`) and the console records the outcome. Adding
an attached hostname keeps it; one on another Worker is refused; remove
is idempotent; a hostname outside the account's zones is refused plainly.
- Console: migration 0010 railyard.app_domains (one org per hostname,
lower case, cascade, RLS, no anon); GET/POST/DELETE /api/v1/domains and
POST /api/v1/domains/record (CLI bearer); states refreshed from
Cloudflare when the org has a grant. Cloudflare OAuth default scopes add
zone:read and ssl_certs:write (orgs linked before need to run
railyard link once more for console-side domains).
- Scribase bridge: new signed route domains {scribase_org_id, app?} ->
{available, domains:[{app, hostname, state, checked_at, created_at}],
next} for the Deploy tab; contract fixture v2 adds it (additive).
Tests: CLI 23/23 (new domains.test.mjs 5: grant path with the real console
handlers and a fake Cloudflare, local-login path, wrangler config file,
refusals, idempotent remove, no token printed or sent to the console);
console 147/147 (new lib/ship/domains.test.ts 4: drift, worker naming
equal to the CLI's, attach/detach and cross-org refusal, record and
refresh, bridge listing; 0010 migration on a scratch PG); contract 6/6;
console tsc clean.
Owner-only: one real-domain proof (railyard domains add on a domain in the
owner's Cloudflare account) is not run here; record it at the deploy gate.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 13:45:57 +03:00
|
|
|
return { url: `http://127.0.0.1:${server.address().port}`, repo, org, seen, claim, ship, close: () => new Promise((r) => server.close(r)) };
|
feat(cli): railyard deploy with branch previews, deploy records and rollback (RYP-D4, Y-3)
npx railyard (zero dependencies):
- login: device flow against the console; the org token is saved 0600
and never printed; no option takes a key or token.
- deploy: detects Next.js (OpenNext build for Workers), Vite, Astro
(static output) or plain static; anything else stops with one line
that says what to change (SvelteKit, Remix, Nuxt, server Astro...).
Uses wrangler's own OAuth login on the user's machine, names the
Worker <app> on main and <app>-<branch> elsewhere, and records URL,
commit, branch, framework, duration and status in the console.
- rollback: wrangler rollback to the previous successful version id of
the same branch, recorded with rollback_of.
- deploys: lists recent deploys.
Console: /api/v1/deploys (POST record, GET list) and /api/v1/deploys/:id
with org-scoped bearer tokens; the first deploy of a new app name creates
the app within the plan's limits; a paused or card-less org is refused
with 402. The Apps screen lists recent deploys.
Tests: the CLI runs against a mocked wrangler and the real console
device-flow and deploy code over local HTTP (login, main deploy, branch
preview, records, rollback, OpenNext path, failure, refusals, no token
in any output); deploy service tests cover org isolation and input
validation; README and CLI strings pass the copy lint. The run on a
real Cloudflare account is owner-run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 15:54:03 +03:00
|
|
|
}
|