import { EventEmitter } from 'node:events'; import type { HttpRequest, HttpResponse, RequestHandler, S3FetchResponse, S3ProxyConfig, StaticSiteOptions } from './types.js'; import { UserException } from './UserException.js'; export declare class S3Proxy extends EventEmitter { private readonly bucket; private readonly verifyOnInit; private readonly gateway; constructor(config: S3ProxyConfig); static version(): string; isInitialized(): void; init(): Promise; healthCheck(): Promise; /** * Pure fetch: returns the stream + status + headers without writing * to a response. Dispatches GET or HEAD based on `req.method` * (defaults to GET). Throws typed S3ProxyError on classified failures. */ fetch(req: HttpRequest): Promise; /** * Convenience adapter over `fetch()` for Web-standard runtimes: take a Web * `Request`, return a Web `Response` streaming the object from S3. The Web * analog of `pipe()` / `middleware()` (which serve to a Node * `ServerResponse`). Not framework-specific: it uses the WHATWG `Request` / * `Response` that are global on Bun, Deno, Cloudflare Workers and Node, and * works with any framework exposing the raw `Request` (Hono's `c.req.raw`, a * Workers/Bun/Deno handler's argument). Removes the `Request` -> * `HttpRequest` and `Readable` -> `ReadableStream` conversion consumers * otherwise hand-roll on every deployment. * * Unlike `pipe()`, it does not render errors: it throws the typed * `S3ProxyError` on classified failures (404/403/416) so the framework's own * error handler (Hono `app.onError`, a Workers `try/catch`) owns the * error-body format. Call `fetch()` directly if you need to build the * `Response` yourself. */ fetchWeb(request: Request): Promise; /** * Fetch a specific key, taking the method and Range header from `req` * but ignoring its path. Lets the static-site layer rewrite the key * (index/error documents) without re-parsing or re-encoding the URL. */ private fetchKey; /** * Convenience adapter over the pure `fetch()` primitive: fetch the * object and write it straight to an HTTP response. Recovers v3's * one-call ergonomics (`proxy.get(req, res)`) *without* v3's empty-200 * lie — a missing key or denied object renders the honest 404/403/416 * status instead of a silent success. * * The response body for a classified failure is a short plaintext line. * Callers who need a custom error page (XML, HTML, structured logging) * should use `fetch()` directly and render errors themselves. * * Resolves once the body has finished streaming (or the error response * has been written). Never rejects for classified S3 failures — it * renders them. It only rejects if `res.writeHead` itself throws. */ pipe(req: HttpRequest, res: HttpResponse): Promise; /** * Write status + headers and pipe the body, resolving when it finishes. * The single "write the response" path shared by `pipe()`, the static-site * happy path, and the error-document render. Once headers are sent a * mid-stream S3 failure can only be handled by terminating the response — * the status can't change. */ private writeBody; /** * Returns an Express/Connect-style request handler built on `pipe()`. * Drop-in replacement for hand-writing the try/catch + writeHead + pipe * boilerplate: * * app.get('/*splat', proxy.middleware()); * * If a `next` callback is supplied and an unexpected (non-classified) * error escapes, it is forwarded to the framework's error handler. */ middleware(): RequestHandler; /** * Shared handler-error policy: forward to the framework's `next` when * present, otherwise render the error ourselves. `renderError` already * no-ops (just ends the response) once headers are sent. */ private onHandlerError; private renderError; /** * Returns a request handler that replicates S3 static website hosting on * top of `fetch()`: index-document resolution (`/` → `index.html`) and, * when `errorDocument` is set, serving that key with the original 4xx * status for missing/forbidden objects. Everything else falls through to * `renderError` (or `next`). The pure `fetch()` primitive is unchanged — * this behavior lives entirely in the layer. * * app.use(proxy.staticSite({ indexDocument: 'index.html', errorDocument: '404.html' })); */ staticSite(options?: StaticSiteOptions): RequestHandler; private serveStatic; private serveErrorDocument; } export { InvalidRequest, S3Forbidden, S3InvalidRange, S3NotFound, S3ProxyError, } from './errors.js'; export { mapHeaderToParam, parseRequest, stripLeadingSlash } from './request-parser.js'; export type { HttpRequest, HttpResponse, ParsedRequest, RequestHandler, S3Error, S3FetchResponse, S3ProxyConfig, StaticSiteOptions, } from './types.js'; export { UserException }; export default S3Proxy; //# sourceMappingURL=index.d.ts.map