import type { ApiEnvelope, AppState } from "../utils.js";
/**
 * A non-empty absolute filesystem path string.
 * Branding prevents accidental use of unvalidated strings as directory paths.
 */
export type AbsolutePath = string & {
    readonly __brand: "AbsolutePath";
};
/**
 * A validated Cloudflare Worker script name:
 * 1–64 chars, only [A-Za-z0-9_-].
 */
export type ScriptName = string & {
    readonly __brand: "ScriptName";
};
/** Supported project frameworks. */
export type FrameworkType = "vite" | "nextjs";
/** Deployment environment — controls the suffix appended to the script name. */
export type DeployEnvironment = "production" | "preview";
/** Parsed, validated body for POST /api/site/deploy and /api/site/redeploy. */
export interface DeployBody {
    /** Absolute path to the user's project directory on the local filesystem. */
    readonly projectDir: AbsolutePath;
    /** Validated Cloudflare Worker script name (identifier in dispatch namespace). */
    readonly scriptName: ScriptName;
    /**
     * Target deployment environment.
     * Determines the suffix appended to `scriptName`:
     *   - `"production"` → `<scriptName>_production` (default)
     *   - `"preview"`    → `<scriptName>_preview`
     */
    readonly environment: DeployEnvironment;
    /** Cloudflare credentials extracted from the request body `env` map. */
    readonly cloudflareEnv: CloudflareEnv;
    /**
     * Full caller-supplied `env` map from the request body.
     * Forwarded as-is into the wrangler child process environment so every
     * key the caller provides (beyond the three Cloudflare credentials) is
     * available to wrangler without the daemon hard-coding individual vars.
     */
    readonly callerEnv: Record<string, string>;
}
/** Parsed, validated body for POST /api/site/delete. */
export interface DeleteBody {
    /** Validated Cloudflare Worker script name to delete. */
    readonly scriptName: ScriptName;
    /** Cloudflare credentials extracted from the request body `env` map. */
    readonly cloudflareEnv: CloudflareEnv;
}
/** Success payload returned by POST /api/site/deploy and /api/site/redeploy. */
export interface DeployResult {
    readonly scriptName: ScriptName;
    readonly dispatchNamespace: string;
    readonly framework: FrameworkType;
    readonly environment: DeployEnvironment;
}
/** Success payload returned by POST /api/site/delete. */
export interface DeleteResult {
    readonly scriptName: ScriptName;
    readonly dispatchNamespace: string;
    readonly deleted: true;
}
/**
 * Resolved Cloudflare credentials.
 * Sourced from the request body `env` map — never from `process.env` directly.
 */
interface CloudflareEnv {
    readonly apiToken: string;
    readonly accountId: string;
    readonly dispatchNamespace: string;
}
/**
 * Validates a script name string and brands it as `ScriptName`.
 * Exported as `validateScriptName` for backward-compatibility with tests.
 * Throws AppError(400) on any violation.
 */
export declare function validateScriptName(raw: string): ScriptName;
/**
 * Extracts and validates the three required Cloudflare credentials from the
 * caller-supplied `env` map (sourced from the request body, not `process.env`).
 *
 * All three keys are checked up-front before any SDK call so a missing value
 * surfaces as a clear 400 rather than an opaque authentication failure.
 * Throws AppError(400) for any missing or empty key.
 */
export declare function validateEnv(env: Record<string, string>): CloudflareEnv;
/**
 * Parses and validates a deploy/redeploy request body.
 *
 * The router passes `params` as `Record<string, unknown>`, but this function
 * accepts raw `unknown` so it can be called directly in tests without casting.
 * Returns a strongly-typed `DeployBody` with branded field types on success.
 * Throws AppError(400) on any validation failure.
 *
 * Cloudflare credentials are read from the `env` field of the request body
 * (a `Record<string, string>`) — never from `process.env`.
 */
export declare function parseDeployBody(raw: unknown): DeployBody;
/**
 * Parses and validates a delete request body.
 * Returns a strongly-typed `DeleteBody` with a branded `scriptName` on success.
 * Throws AppError(400) on any validation failure.
 *
 * Cloudflare credentials are read from the `env` field of the request body
 * (a `Record<string, string>`) — never from `process.env`.
 */
export declare function parseDeleteBody(raw: unknown): DeleteBody;
/**
 * Detects the project framework by checking for well-known config files.
 * Vite is checked first — it wins if both Vite and Next.js configs are present.
 *
 * Throws AppError(400) if:
 * - The directory does not exist or is not accessible (treated identically).
 * - No supported framework config file is found.
 */
export declare function detectFramework(projectDir: AbsolutePath): Promise<FrameworkType>;
/**
 * Deploys a Vite project by delegating to `npx wrangler deploy`.
 *
 * Strategy:
 * 1. Confirm wrangler is available — throws AppError(500) with install instructions if not.
 * 2. Check for an existing wrangler config (`wrangler.jsonc` or `wrangler.json`).
 *    - If found: patch the `name` field with `scriptName`, deploy, then restore.
 *    - If not found: probe for the first built artifact (.output/worker.js or dist/worker.js)
 *      to use as `main`, generate a minimal `wrangler.json`, deploy, then delete it.
 *      If no artifact exists yet, throws AppError(400) with actionable build instructions.
 * 3. Run `npx wrangler deploy --dispatch-namespace` in both cases.
 *
 * Throws AppError(400) if no artifact is found and no wrangler config exists.
 * Throws AppError(500) if wrangler is not available or exits with a non-zero code.
 */
export declare function deployViteWithWrangler(scriptName: ScriptName, projectDir: AbsolutePath, env: CloudflareEnv, callerEnv: Record<string, string>): Promise<void>;
/**
 * Deploys a Next.js project by delegating entirely to `npx wrangler deploy`.
 *
 * Strategy:
 * 1. Locate the wrangler config file (`wrangler.jsonc` or `wrangler.json`).
 * 2. Parse it, overwrite the `name` field with `scriptName`, write it back.
 * 3. Spawn `npx wrangler deploy` in the project directory, forwarding
 *    `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID` from the environment.
 * 4. Restore the original config content regardless of success or failure.
 *
 * Using wrangler avoids the need to manually replicate its module bundling,
 * JSON-manifest uploads, asset handling, and compatibility-flag logic.
 *
 * Throws AppError(400) if no wrangler config file is found.
 * Throws AppError(500) if wrangler exits with a non-zero code.
 */
export declare function deployNextjsWithWrangler(scriptName: ScriptName, projectDir: AbsolutePath, env: CloudflareEnv, callerEnv: Record<string, string>): Promise<void>;
/**
 * Deletes a named worker from the dispatch namespace via `npx wrangler delete`.
 * Throws AppError(500) if wrangler exits with a non-zero code.
 */
export declare function deleteWorker(scriptName: ScriptName, env: CloudflareEnv, callerEnv: Record<string, string>): Promise<void>;
/**
 * Shared pipeline for deploy and redeploy:
 *   validateEnv → parseDeployBody → detectFramework → deploy via wrangler
 *
 * Both Next.js and Vite patch (or generate) a wrangler config with scriptName,
 * then run `npx wrangler deploy`. Any step failure throws an AppError.
 */
export declare function runDeployPipeline(raw: unknown): Promise<DeployResult>;
export declare function deploy(_state: AppState, body: Record<string, unknown>): Promise<ApiEnvelope<DeployResult>>;
export declare function redeploy(_state: AppState, body: Record<string, unknown>): Promise<ApiEnvelope<DeployResult>>;
export declare function deleteSite(_state: AppState, body: Record<string, unknown>): Promise<ApiEnvelope<DeleteResult>>;
export {};
//# sourceMappingURL=site.d.ts.map