Some checks failed
ci / cargo test (abacus) (push) Has been cancelled
ci / cargo test (agent-runtime) (push) Has been cancelled
ci / cargo test (context-passport) (push) Has been cancelled
ci / cargo test (game-economy) (push) Has been cancelled
ci / cargo test (ledgerline) (push) Has been cancelled
ci / cargo test (mint) (push) Has been cancelled
ci / cargo test (rago) (push) Has been cancelled
ci / cargo test (relay) (push) Has been cancelled
ci / node suites (push) Has been cancelled
ci / cargo test (toolgate) (push) Has been cancelled
ci / cargo test (turnstile) (push) Has been cancelled
ci / cargo test (vend) (push) Has been cancelled
apps/gitea -> apps/rithub-server; compose services/containers renamed (rithub-server-app/postgres/act-runner) with explicit project name and volume names pinned to the exact existing Docker volumes (no data loss); our own GITEA_* compose/env var names -> RIT_*; new rit-admin CLI wrapper on railyard-box; giteaSession.mjs/giteaOAuth.mjs/giteaInfo.mjs -> ritSession/ritOAuth/ritInfo across 6 apps; GiteaForgeAdapter -> RitForgeAdapter + giteaSyncService/importGiteaRepos/syncGiteaRepos -> rit* in ritgram (tsc clean); apps/console/lib/gitea.ts -> lib/ritProvision.ts; Go internal/giteaclient -> internal/ritclient in rithub-async-import (go build/test clean); new /auth/rit + /forges/rit/connect routes with /gitea back-compat aliases; locale/swagger/footer/captcha template text scrubbed of remaining "Gitea" strings. Deployed to railyard-box: old containers stopped/removed, /srv/railyard-gitea renamed to /srv/rithub-server with a symlink kept, docker compose up -d from the new path, act_runner network-alias fix for its persisted instance URL. Live-verified: docker compose config diff showed zero unintended value changes, DB row counts unchanged (19 users, 635 repos), full route regression 200/expected, 0 "gitea" in headers/bodies on every checked page, real git clone+push over HTTPS and SSH with a disposable account (deleted after). Deferred on purpose (documented in plans/railyard.md): the forge discriminator / DB column names / Postgres role+volume names (data migrations, not a naming change) and the upstream GITEA__ env-to-ini keys and X-Gitea-* wire headers (hardcoded in the vendored engine binary). See plans/railyard.md RIT-OPS/RIT-BRD entry for the full old->new map and live evidence. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
106 lines
4.8 KiB
TypeScript
106 lines
4.8 KiB
TypeScript
// Server wiring: config, repository and payment client for route handlers
|
|
// and server components. Server-only (never imported by a "use client" file).
|
|
|
|
import { readConfig, type Config } from "./config.ts";
|
|
import { Dodo } from "./dodo.ts";
|
|
import { mintClient, type MintClient } from "./mint.ts";
|
|
import { ritClient, type RitClient } from "./ritProvision.ts";
|
|
import { PostgrestRepo } from "./postgrest-repo.ts";
|
|
import type { Repo } from "./repo.ts";
|
|
import { insightsClient, type InsightsClient } from "./insights.ts";
|
|
import type { EventAnomalyDeps } from "./eventAnomaly.ts";
|
|
import { productAnalyticsFromEnv, type ProductAnalyticsClient } from "./product-analytics.ts";
|
|
import { kvSites, type SitesStore } from "./sites.ts";
|
|
import { PostgrestFlagsStore } from "./flags/store.ts";
|
|
import { TableFlagsBackend } from "./flags/table-backend.ts";
|
|
import { FlagsmithBackend } from "./flags/flagsmith-backend.ts";
|
|
import type { FlagsDeps } from "./flags/service.ts";
|
|
import { PostgrestWatchStore } from "./watch/store.ts";
|
|
import { noMailer, rallySend } from "./watch/mail.ts";
|
|
import type { WatchDeps } from "./watch/service.ts";
|
|
import { CloudflareOAuth, DEFAULT_SCOPES } from "./ship/cloudflare.ts";
|
|
import { GithubApp } from "./ship/github.ts";
|
|
import { githubOidcKeys } from "./ship/http.ts";
|
|
import type { ShipDeps } from "./ship/service.ts";
|
|
import { PostgrestShipStore } from "./ship/store.ts";
|
|
|
|
export interface Deps {
|
|
cfg: Config;
|
|
repo: Repo;
|
|
dodo: Dodo;
|
|
sites: SitesStore;
|
|
insights: InsightsClient | null;
|
|
/** Event-volume anomaly severity (lib/eventAnomaly.ts); null until EVREN_LLM_API_KEY is set. Fail-open and additive -- never required for the Usage page's real event count. */
|
|
eventAnomaly: EventAnomalyDeps | null;
|
|
/** Product analytics (QY1.2); null while the service is not connected. */
|
|
productAnalytics: ProductAnalyticsClient | null;
|
|
flags: FlagsDeps;
|
|
watch: WatchDeps;
|
|
/** Ship on push (PY3.1); null until its GitHub App and Cloudflare client are configured. */
|
|
ship: ShipDeps | null;
|
|
/** Mint self-serve account provisioning (backlog item 11); null until MINT_URL/MINT_API_KEY are set. */
|
|
mint: MintClient | null;
|
|
/** Rithub self-serve provisioning (backlog item 4); null until RIT_API_URL/RIT_ADMIN_TOKEN are set. */
|
|
rithub: RitClient | null;
|
|
}
|
|
|
|
function flagsDeps(cfg: Config): FlagsDeps {
|
|
const store = new PostgrestFlagsStore({ url: cfg.scribaseUrl, serviceRoleKey: cfg.scribaseServiceRoleKey });
|
|
const table = new TableFlagsBackend(store);
|
|
const flagsmith = cfg.flags ? new FlagsmithBackend({ apiUrl: cfg.flags.apiUrl, adminToken: cfg.flags.adminToken }) : null;
|
|
return { store, backend: flagsmith ?? table, backends: flagsmith ? { table, flagsmith } : { table } };
|
|
}
|
|
|
|
function shipDeps(cfg: Config, repo: Repo, sites: SitesStore): ShipDeps | null {
|
|
if (!cfg.ship) return null;
|
|
return {
|
|
store: new PostgrestShipStore({ url: cfg.scribaseUrl, serviceRoleKey: cfg.scribaseServiceRoleKey }),
|
|
repo,
|
|
github: new GithubApp(cfg.ship.github),
|
|
cloudflare: new CloudflareOAuth({
|
|
clientId: cfg.ship.cloudflare.clientId,
|
|
clientSecret: cfg.ship.cloudflare.clientSecret,
|
|
redirectUri: `${cfg.consoleUrl}/api/v1/github/cloudflare/callback`,
|
|
scopes: cfg.ship.cloudflare.scopes ?? DEFAULT_SCOPES,
|
|
}),
|
|
oidcKeys: githubOidcKeys(),
|
|
consoleUrl: cfg.consoleUrl,
|
|
credentialsKey: cfg.ship.credentialsKey,
|
|
sessionSecret: cfg.sessionSecret,
|
|
sites,
|
|
};
|
|
}
|
|
|
|
let cached: Deps | null = null;
|
|
|
|
export function deps(): Deps {
|
|
if (cached) return cached;
|
|
const cfg = readConfig();
|
|
const repo = new PostgrestRepo({ url: cfg.scribaseUrl, serviceRoleKey: cfg.scribaseServiceRoleKey });
|
|
const sites = kvSites();
|
|
cached = {
|
|
cfg,
|
|
repo,
|
|
dodo: new Dodo({ base: cfg.dodoBase, apiKey: cfg.dodoApiKey, allowLive: cfg.dodoAllowLive }),
|
|
sites,
|
|
insights: cfg.insightsApi ? insightsClient({ apiUrl: cfg.insightsApi.url, token: cfg.insightsApi.token }) : null,
|
|
eventAnomaly: cfg.eventAnomaly
|
|
? { baseUrl: cfg.eventAnomaly.baseUrl, apiKey: cfg.eventAnomaly.apiKey, fetch: globalThis.fetch.bind(globalThis), log: (event, detail) => console.error(`${event}${detail ? ` ${JSON.stringify(detail)}` : ""}`) }
|
|
: null,
|
|
productAnalytics: productAnalyticsFromEnv(),
|
|
flags: flagsDeps(cfg),
|
|
watch: {
|
|
store: new PostgrestWatchStore({ url: cfg.scribaseUrl, serviceRoleKey: cfg.scribaseServiceRoleKey }),
|
|
repo,
|
|
mailer: cfg.rallySend ? rallySend(cfg.rallySend) : noMailer,
|
|
consoleUrl: cfg.consoleUrl,
|
|
agentToken: cfg.watchAgentToken,
|
|
live: cfg.watchLive,
|
|
},
|
|
ship: shipDeps(cfg, repo, sites),
|
|
mint: cfg.mint ? mintClient({ url: cfg.mint.url, apiKey: cfg.mint.apiKey }) : null,
|
|
rithub: cfg.rithub ? ritClient({ apiUrl: cfg.rithub.apiUrl, adminToken: cfg.rithub.adminToken }) : null,
|
|
};
|
|
return cached;
|
|
}
|