UNPKG

@mochabug/adapt-plugin-toolkit

Version:

The API toolkit to facilitate mochabug adapt plugin development

8 lines (7 loc) 5.22 kB
{ "version": 3, "sources": ["../../src/types.ts"], "sourcesContent": ["/**\n * Global type definitions for the Mochabug Adapt Plugin system.\n * These types define the runtime environment and APIs available to plugins.\n */\n\n/**\n * Execution context providing lifecycle management for asynchronous operations.\n */\nexport interface ExecutionContext {\n waitUntil(promise: Promise<any>): void;\n passThroughOnException(): void;\n abort(reason?: any): void;\n}\n\nexport interface SocketInfo {\n remoteAddress?: string;\n localAddress?: string;\n}\n\nexport interface Socket {\n get readable(): ReadableStream;\n get writable(): WritableStream;\n get closed(): Promise<void>;\n get opened(): Promise<SocketInfo>;\n get upgraded(): boolean;\n get secureTransport(): 'on' | 'off' | 'starttls';\n close(): Promise<void>;\n startTls(options?: TlsOptions): Socket;\n}\n\nexport interface TlsOptions {\n expectedServerHostname?: string;\n}\n\nexport interface SocketOptions {\n secureTransport?: 'on' | 'off' | 'starttls';\n allowHalfOpen: boolean;\n highWaterMark?: number | bigint;\n}\n\nexport interface SocketAddress {\n hostname: string;\n port: number;\n}\n\nexport interface Fetcher {\n fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;\n connect(address: SocketAddress | string, options?: SocketOptions): Socket;\n}\n\n/**\n * Environment represents an interface that holds\n * all the common runtime functionality between a plugin - configurator / executor\n *\n * @interface\n */\nexport interface Environment {\n /**\n * assets is a Fetcher that wraps the Web Platform API fetch function.\n * It provides access to files inside the assetsDir, as defined in the manifest.json file,\n * without requiring authentication.\n *\n * Note: This is a simple interface to the directory content and is not suitable for serving\n * a full-fledged website. For example, it does not attempt to guess the `Content-Type` header.\n * You may want to wrap this Fetcher in a plugin that fills in the metadata as required.\n *\n * A GET request targeting a directory (instead of a file) returns a basic JSON directory\n * listing, like:\n *\n * [\n * {\"name\":\"foo\",\"type\":\"file\"},\n * {\"name\":\"bar\",\"type\":\"directory\"}\n * ]\n *\n * For file requests, the `Content-Type` will be `application/octet-stream`, while for\n * directory listings, it will be `application/json`. Files will have a `Content-Length`\n * header, while directories will not.\n *\n * HEAD requests are optimized to perform a stat() without actually opening the file.\n *\n * Example Request for fetching an index.html file:\n * GET http://./index.html\n *\n * Example Response:\n * HTTP/1.1 200 OK\n * Content-Type: application/octet-stream\n * Content-Length: 12345\n *\n * <html>\n * ...\n * </html>\n *\n * @type {Fetcher}\n */\n assets: Fetcher;\n\n /**\n * HTTP Proxy fetcher for secure requests with TLS configuration and dynamic header injection.\n * Requests are proxied through the runtime which handles certificate validation, mTLS, and\n * template variable substitution.\n *\n * Service Types:\n * - \"plugin:name\" - System-level services (shared across all vertices)\n * - \"user:name\" - Vertex-level services (per-user configuration)\n *\n * Required Headers:\n * - X-Mochabug-Adapt-Plugin-HttpProxy-Token: Bearer token\n * - X-Mochabug-Adapt-Plugin-HttpProxy-Path: \"plugin:name\" or \"user:name\"\n * - Host: Target host (auto-set by helper methods)\n *\n * TLS Modes (from service definition):\n * - MODE_SERVER_ONLY: Validates server cert against CA bundle\n * - MODE_MTLS: Mutual auth requiring client cert + private key\n *\n * Header Injection:\n * - Template syntax: \"Bearer %ACCESS_TOKEN%\" (Envoy-style)\n * - Variables resolved from runtime configuration\n * - Injected headers override caller's headers\n *\n * Error Codes:\n * - 400: Invalid header format\n * - 401: Invalid token or no permission\n * - 412: Service not configured or unavailable\n *\n * Usage (prefer helper methods):\n * ```typescript\n * const fetch = api.userHttpProxy(\"stripe_api\");\n * const res = await fetch(\"https://api.stripe.com/v1/charges\");\n * ```\n *\n * @type {Fetcher}\n */\n httpproxy: Fetcher;\n\n /**\n * See the runtime.proto/PluginService for a complete reference\n */\n plugin: Fetcher;\n}\n\n/**\n * The environment available to a executor of a plugin vertex\n * See the runtime.proto/ExecutorService for a complete reference\n *\n * @interface ExecutorEnvironment\n */\nexport interface ExecutorEnvironment extends Environment {\n executor: Fetcher;\n}\n\n/**\n * The environment available to a configurator of a plugin vertex\n * See the runtime.proto/ConfiguratorService for a complete reference\n *\n * @interface ConfiguratorEnvironment\n * @property {Fetcher} configurator - the configurator API\n */\nexport interface ConfiguratorEnvironment extends Environment {\n configurator: Fetcher;\n}\n"], "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD", "names": ["types_exports", "__toCommonJS"] }