import { ReadableStream } from "web-streams-polyfill"; import { Headers } from "../http/headers"; import { Method, Request } from "../http/request"; import { Response } from "../http/response"; import { URL } from "../types/url"; /** Arguments to the replaceResponse callback. */ export interface ReplaceResponseArgs { /** The incoming request including the body. */ request: EventRequest; } /** An event context for an incoming HTTP request. */ export declare class RequestEvent { #private; /** Returns metadata of the request that triggered this invocation. */ get requestMeta(): RequestMeta; /** * Get the Identity information for the user from the request. */ get userContext(): UserContext | null; /** * Takes over the HTTP transaction and sends the given response to the client instead. * * @param produceResponse Either: * - A readily available HTTP response * - A callback returning an HTTP response or a promise resolving to an HTTP response. * * If the callback is given, its given access to the incoming HTTP request (body). */ replaceResponse(produceResponse: Response | ((args: ReplaceResponseArgs) => Response | Promise)): void; } /** * Metadata of the incoming request. */ export declare class RequestMeta { #private; /** Gets a readonly list of headers that are present on the incoming request. */ get headers(): Headers; /** The method of the incoming request. */ get method(): Method; /** Location data about this request */ get origin(): Location; /** * Map of captured path values from the request. * * Consider an edge handler mounted on `/posts/:postId`, that is run during a * request to `/posts/1337`. Then, `pathCaptures` will contain an entry `"postId"` * (without the initial colon) with the value `"1337"`. * * Wildcard parameter values from path rules like `/posts/*` are exposed under the * key `"splat"`. * * The returned object is frozen and cannot be modified. */ get pathCaptures(): Readonly>; /** The URL of the incoming request. */ get url(): URL; /** Zone where the Edge Handler is executed */ get zone(): string | undefined; } /** * A specialized request subclass for incoming edge handler requests. */ export declare class EventRequest extends Request { #private; /** * Obtains a readable stream to the request body. * * This can only be accessed once. Subsequent invocations will throw. */ get body(): ReadableStream | null; /** Returns whether accessing the `body` property will throw an error. */ get bodyUsed(): boolean; } /** * Provide Identity information for the user that triggered the request */ export declare class UserContext { #private; /** JSON object with the claims from the JWT information in the request */ get claims(): any; /** List of roles in the JWT metadata */ get roles(): Array; /** Checks whether a role is included in the JWT metadata. */ is(role: string): boolean; } /** * Provide common information for an area's location. */ export declare class LocationData { /** Name of the area */ readonly name: string; /** ISO code of the area */ readonly code: string | undefined; constructor(name: string, code?: string | undefined); } /** * Provide location information extracted from the request headers. */ export declare class Location { #private; /** * Constructs a new `Location` from the given list of headers. * * @param headers The request headers to extract location information from. */ constructor(headers: Headers); /** LocationData included in the request headers for the country of origin. */ get country(): LocationData | undefined; /** LocationData included in the request headers for the subdivision area of origin. */ get subdivision(): LocationData | undefined; /** * LocationData included in the request headers for the city. * The code for a city is always undefined. */ get city(): LocationData | undefined; }