import { ResponseCookies } from '@edge-runtime/cookies';
export { RequestCookies, ResponseCookies } from '@edge-runtime/cookies';
import { SafeReturn } from 'p-safe';
import { a as ActionErrorPlain, A as ActionError } from './errors-BVGZMZdH.cjs';

type AnyFunc<This = void> = (this: This, ...args: readonly any[]) => unknown;
type ActionFunc<T> = T extends (...args: infer Args) => infer Return ? (this: any, ...args: Args) => Promise<SafeReturn<Awaited<Return>, ActionError>> : never;
interface ActionContext<Return> {
    resolve: (result: Return) => never;
    reject: (error: ActionErrorPlain | ActionError) => never;
}
declare class Action<Return> {
    #private;
    constructor(fn: AnyFunc<ActionContext<any>>);
    resolve(result: Return): never;
    reject(reason: ActionErrorPlain | ActionError): never;
    /** @internal */
    run(...arguments_: any[]): Promise<(object & Record<"data", unknown>) | {
        error: {
            code: unknown;
            message: unknown;
        };
    }>;
}

declare function createAction<T extends AnyFunc<ActionContext<any>>>(fn: T): ActionFunc<T>;
declare function actionError(code: string, message: string): never;
/**
 * Handles HTTP cookies for server-side components and actions.
 *
 * This function serves two primary purposes:
 * 1. Reading cookies from an incoming HTTP request when used in a Server Component.
 * 2. Writing cookies to an outgoing HTTP response when used in a Server Component, Server Action, or Route Handler.
 *
 * This function leverages a shared request storage mechanism to access or modify the cookies.
 *
 * @returns {ResponseCookies} An object representing the mutable cookies for the current HTTP request context.
 *
 * @throws {Error} Throws an error if the request storage is not available, indicating an internal consistency issue.
 *
 * @example
 * // Reading cookies in a Server Component
 * const requestCookies = cookies();
 * console.log(requestCookies.get('sessionId'));
 *
 * @example
 * // Writing cookies in a Server Action
 * export function myAction() {
 *   const responseCookies = cookies();
 *   responseCookies.set('sessionId', 'abc123', { httpOnly: true });
 * }
 *
 * @example
 * // Modifying cookies in a Route Handler
 * export default async function handler(req, res) {
 *   const responseCookies = cookies();
 *   responseCookies.delete('sessionId');
 *   res.end('Cookie deleted');
 * }
 */
declare function cookies(): ResponseCookies;
/**
 * Retrieves the client's IP address from request headers.
 *
 * The function checks various headers commonly used by different cloud providers and proxies to find the client's IP address.
 * It prioritizes the 'x-forwarded-for' header, which may contain multiple IP addresses, and extracts the first one.
 * If no valid IP is found, it throws an error.
 *
 * @returns {string|null} The client's IP address.
 */
declare function clientIP(): Promise<string | null>;

export { Action, actionError, clientIP, cookies, createAction };
