import { env } from "cloudflare:workers";
import { run } from "./db";
import { TERMS_VERSION } from "~/lib/legal";
import type { LegalInfo } from "~/lib/legal";
const SECURITY_TXT_PATH = "/.well-known/security.txt";
/** RFC 9116 asks for an Expires under a year; one day short also covers the cache lifetime. */
const SECURITY_TXT_LIFETIME_MS = 364 * 24 * 60 * 60 * 1000;
const SECURITY_TXT_CACHE_SECONDS = 60 * 60 * 24;
function value(raw: string | undefined): string | null {
const trimmed = raw?.trim();
return trimmed ? trimmed : null;
}
export function legalInfo(): LegalInfo {
const info = {
forgeName: value(env.FORGE_NAME) ?? "gitfor",
publicUrl: value(env.PUBLIC_URL) ?? "",
entity: value(env.LEGAL_ENTITY),
contactEmail: value(env.LEGAL_CONTACT_EMAIL),
address: value(env.LEGAL_ADDRESS),
jurisdiction: value(env.LEGAL_JURISDICTION),
dmcaEmail: value(env.DMCA_AGENT_EMAIL),
securityEmail: value(env.SECURITY_CONTACT_EMAIL),
supportEmail: value(env.SUPPORT_EMAIL),
};
const draft = [info.entity, info.contactEmail, info.jurisdiction, info.dmcaEmail].includes(null);
return { ...info, draft };
}
/** Signup (password or GitHub) is acceptance of the Terms and Privacy Policy shown next to the button. */
export async function recordTermsAcceptance(userId: string): Promise<void> {
await run(
"UPDATE users SET terms_version = ?, terms_accepted_at = ? WHERE account_id = ?",
TERMS_VERSION,
Date.now(),
userId,
);
}