- 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>
36 lines
1.7 KiB
SQL
36 lines
1.7 KiB
SQL
-- Custom domains for shipped apps (Wave Q QY1.5, I6). One row per hostname
|
|
-- attached to an app's production Worker on the org's own Cloudflare account.
|
|
-- The console keeps what is attached and its certificate state for the
|
|
-- Scribase Deploy tab; no credential is stored here. Additive and
|
|
-- idempotent. Not applied by agents to any hosted database; the owner
|
|
-- applies it after 0009.
|
|
|
|
create table if not exists railyard.app_domains (
|
|
org_id uuid not null references railyard.orgs (id) on delete cascade,
|
|
app text not null check (app ~ '^[a-z0-9][a-z0-9-]{0,39}$'),
|
|
hostname text not null check (length(hostname) between 4 and 253 and hostname = lower(hostname)),
|
|
worker text not null check (length(worker) between 1 and 63),
|
|
cf_domain_id text check (cf_domain_id is null or length(cf_domain_id) <= 64),
|
|
zone_name text check (zone_name is null or length(zone_name) <= 253),
|
|
state text not null default 'pending' check (state in ('pending', 'active', 'error')),
|
|
checked_at timestamptz,
|
|
created_at timestamptz not null default now(),
|
|
primary key (org_id, hostname)
|
|
);
|
|
create index if not exists app_domains_app_idx on railyard.app_domains (org_id, app);
|
|
|
|
alter table railyard.app_domains enable row level security;
|
|
|
|
do $$
|
|
begin
|
|
if exists (select 1 from pg_roles where rolname = 'anon') then
|
|
execute 'revoke all on railyard.app_domains from anon';
|
|
end if;
|
|
if exists (select 1 from pg_roles where rolname = 'authenticated') then
|
|
execute 'revoke all on railyard.app_domains from authenticated';
|
|
end if;
|
|
if exists (select 1 from pg_roles where rolname = 'service_role') then
|
|
execute 'grant all on railyard.app_domains to service_role';
|
|
end if;
|
|
end $$;
|