340 lines · 13.7 KB
import { env } from "cloudflare:workers";
import { all, first, run } from "../db";
import { encryptSecret, randomId, randomToken } from "../crypto";
import { badRequest, conflict } from "../errors";
import { assertBelowCap } from "../limits";
import { hostKey, isForgeRelatedHost, isValidHostname, pagesDomain } from "../pages/config";
import type { PagesSiteRow } from "../pages/config";
import {
  createCustomHostname,
  customDomainsEnabled,
  deleteCustomHostname,
  domainStatus,
  getCustomHostname,
} from "../pages/domains";
import { customHostKey, metaKey, publishMeta, SITE_LIMITS, sitesDomain } from "./config";
import { assertLabelFree, loadSiteForRepo, unpublishSite } from "./deploy";
import { siteLabel } from "./naming";
import { hashSitePassword } from "./password";
import { assertPublicHttps } from "./oidc";
import type { SiteAccess, SiteRow } from "./config";
import type { RepoRow } from "~/lib/types";

const UNVERIFIED_CLAIM_MS = 72 * 60 * 60 * 1000;
const MIN_PASSWORD = 8;
const FOLDER = /^[A-Za-z0-9._\-/]*$/;
const ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;
const RESERVED_ENV = new Set(["ASSETS"]);

export type SiteSettings = {
  source: "branch" | "workflow";
  branch: string;
  folder: string;
  artifactName: string;
  spa: boolean;
  previews: boolean;
};

export type AccessSettings = {
  access: SiteAccess;
  audience: "readers" | "members";