import { Telemetry } from '@opvious/stl-telemetry'; import { MarkPresent } from '@opvious/stl-utils/objects'; import ProxyServer from 'http-proxy'; import Koa from 'koa'; import { OpenapiDocument, OpenapiOperation } from 'yasdk-openapi'; type ProxiedOperation = MarkPresent, 'operationId'>; /** * Creates a proxy for OpenAPI operations. Note that the returned middleware * returns immediately: it does not wait for the response to be proxied back. * Instead it disables Koa response handling by setting `ctx.respond` to false. */ export declare function createOperationsProxy>(args: { /** OpenAPI document. */ readonly document: D; /** Upstream server options. */ readonly upstreams: U; /** * Maps operations to upstream key. Unmapped operations are not proxied. * Operations without an ID or with `trace` method are always skipped. */ readonly dispatch: (op: ProxiedOperation, path: string) => (keyof U & string) | undefined; /** * Optional setup for newly created proxy serverss. Use this for example to * set up error handling. */ readonly setup?: (server: ProxyServer, key: keyof U & string) => void; /** * Optional hook called just before a request is proxied. This can be used for * example to throw an exception and abort handling. */ readonly prepare?: (ctx: Koa.Context, op: ProxiedOperation) => Promise; /** Telemetry provider. */ readonly telemetry?: Telemetry; /** * Proxy OPTIONS requests for all operations, even if one is not declared * explicitly. This can be useful to support CORS. An error will be thrown if * a single path is mapped to multiple upstreams. */ readonly proxyOptionsRequests?: boolean; }): Koa.Middleware; export {};