import { env } from "cloudflare:workers";
import { all, first, run } from "./db";
import { repoDb } from "./scoped-db";
import type { ScopedDb } from "./scoped-db";
import { locate } from "./scoped-db/locators";
import type { LocatorKind } from "./scoped-db/locators";
import { captureServerEvent } from "./analytics";
import { hmacSha256Hex, randomId } from "./crypto";
import { badRequest, notFoundError } from "./errors";
import { cookieSecret, publishMeta, SCRATCH_LIMITS } from "./sites/config";
import { loadSiteById } from "./sites/deploy";
import { resolveAbuseTarget } from "./abuse-targets";
import type { AbuseTarget } from "./abuse-targets";
import { recordAdminAction } from "./admin-audit";
import { isHideable, setModerationHidden } from "./moderation";
import { notifyAdmins } from "./account-disable-actions";
import { ABUSE_TARGET_LABELS } from "~/lib/abuse";
import type { AbuseAction, AbuseCategory, AbuseStatus, AbuseTargetKind } from "~/lib/abuse";
export { siteIdForUrl } from "./abuse-targets";
export type AbuseSource = "web" | "email" | "site";
/**
* How much one reporter counts toward auto-pause. Signed-in users and mail whose sender domain passed DMARC are
* accountable; an IP is cheap to rotate; unauthenticated mail can forge any sender, so it never pauses anything.
*/
export type ReporterKind = "user" | "ip" | "email-verified" | "email-unverified";
const REPORTER_WEIGHT: Record<ReporterKind, number> = {
user: 2,
"email-verified": 2,
ip: 1,
"email-unverified": 0,
};
/** Phishing and malware hurt visitors immediately, so fewer distinct reporters are enough to hold the site. */
const SEVERE: ReadonlySet<AbuseCategory> = new Set(["phishing", "malware"]);
/**
* Weighted reporter totals that pause a site (an IP weighs 1, an accountable reporter 2). Scratch sites are
* anonymous and short-lived, so a few reports hold them. Owned sites count accountable reporters only and need