d68f003000
CI / Change detection (push) Has been cancelled
CI / Version drift (push) Has been cancelled
CI / Lint (push) Has been cancelled
CI / Workflow RLM cache (push) Has been cancelled
CI / Test (macos-latest) (push) Has been cancelled
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / npm wrapper smoke (push) Has been cancelled
CI / Mobile runtime smoke (push) Has been cancelled
CI / Workflow lint (push) Has been cancelled
CI / Documentation (push) Has been cancelled
Web Frontend / Lint & Type Check (push) Failing after 1s
Auto-close harvested PRs / close (push) Failing after 1s
cargo-deny / cargo-deny (bans licenses sources) (push) Failing after 1s
Security audit / cargo-audit (push) Failing after 1s
Sync to CNB / sync (push) Failing after 1s
cargo-deny / cargo-deny (advisories) (push) Failing after 3s
Web Frontend / Deploy to Cloudflare (push) Has been cancelled
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { FACTS as BUILD_TIME_FACTS, type RepoFacts, type ProviderFact } from "./facts.generated";
|
|
|
|
const KV_KEY = "facts:current";
|
|
|
|
export type { RepoFacts, ProviderFact };
|
|
export const BUILD_FACTS = BUILD_TIME_FACTS;
|
|
|
|
interface KVNamespace {
|
|
get(key: string): Promise<string | null>;
|
|
put(key: string, value: string, opts?: { expirationTtl?: number }): Promise<void>;
|
|
}
|
|
|
|
async function getKv(): Promise<KVNamespace | undefined> {
|
|
if (process.env.NEXT_PHASE === "phase-production-build") {
|
|
return undefined;
|
|
}
|
|
|
|
try {
|
|
const mod = await import("@opennextjs/cloudflare");
|
|
const ctx = await mod.getCloudflareContext({ async: true });
|
|
return (ctx.env as { CURATED_KV?: KVNamespace }).CURATED_KV;
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Resolved facts for the current request. Prefers a KV override (written by
|
|
* the content-drift cron when it detects new repo state) over the build-time
|
|
* snapshot. Always returns a valid RepoFacts — falls back to BUILD_FACTS on
|
|
* any error.
|
|
*/
|
|
export async function getFacts(): Promise<RepoFacts> {
|
|
try {
|
|
const kv = await getKv();
|
|
if (!kv) return BUILD_FACTS;
|
|
const raw = await kv.get(KV_KEY);
|
|
if (!raw) return BUILD_FACTS;
|
|
const parsed = JSON.parse(raw) as RepoFacts;
|
|
if (!parsed.version || !Array.isArray(parsed.providers)) return BUILD_FACTS;
|
|
return parsed;
|
|
} catch {
|
|
return BUILD_FACTS;
|
|
}
|
|
}
|