import { Server } from 'node:http'; import type { Http2SecureServer, Http2Server } from 'node:http2'; import type { Command, CommandErrorResponse, CommandSuccessResponse, CustomMessage, DefinitionEventBridgeConfig, EBMessage, EBMessageAddress, EventBridge, EventBridgeConfig, HttpExposedServiceMeta, Subscription } from '@purista/core'; import { EventBridgeBaseClass } from '@purista/core'; import { Hono } from 'hono'; import type { HttpEventBridgeClient } from './types/HttpEventBridgeClient.js'; import type { HttpEventBridgeConfig } from './types/HttpEventBridgeConfig.js'; /** * Generic HTTP-based event bridge for runtimes that deliver PURISTA messages over HTTP. * * In environments like Dapr or Knative, communication is commonly handled by * sidecar containers or platform routers. This bridge exposes internal POST * endpoints for commands and subscriptions, optionally exposes command REST * projections, and uses the configured {@link HttpEventBridgeClient} for calls * back to the sidecar or platform HTTP API. * * In these cases, it is expected, that the current instance is a HTTP server, which provides REST endpoints for commands and subscriptions. * The communication from the current instance to the sidecar is also done via REST endpoints. * * HTTP calls from the sidecar to the current instance might be done via CloudEvent schema, which wraps the payload into a defined structure. * The HttpEventBridge can be configured to respect this, and to extract the information from CloudEvents. * * To use the HttpEventBridge, you will need following peer-dependencies installed: * * - hono * - trouter */ /** * Stores the app value exposed by HttpEventBridge. * Start the bridge before registering services and stop it during graceful shutdown. * Expose only schemas and metadata that are safe for clients to inspect. * Treat this property as runtime state unless the concrete API documents a stronger guarantee. */ export declare class HttpEventBridge /** * Stores the isShuttingDown value exposed by HttpEventBridge. * Start the bridge before registering services and stop it during graceful shutdown. * Expose only schemas and metadata that are safe for clients to inspect. * Treat this property as runtime state unless the concrete API documents a stronger guarantee. */ extends EventBridgeBaseClass /** * Stores the isStarted value exposed by HttpEventBridge. * Start the bridge before registering services and stop it during graceful shutdown. * Expose only schemas and metadata that are safe for clients to inspect. * Treat this property as runtime state unless the concrete API documents a stronger guarantee. */ implements EventBridge { /** * Stores the client value exposed by HttpEventBridge. * Start the bridge before registering services and stop it during graceful shutdown. * Expose only schemas and metadata that are safe for clients to inspect. * Treat this property as runtime state unless the concrete API documents a stronger guarantee. */ /** * Runtime server returned by the configured Hono `serve` adapter. * * It is set during {@link start} and closed during {@link destroy}. */ server: Server | Http2Server | Http2SecureServer | undefined; /** * Hono application that hosts health, command, subscription and REST projection routes. */ app: Hono; /** * Indicates that shutdown has started and new HTTP requests should be rejected. */ isShuttingDown: boolean; /** * Indicates that the bridge has registered routes and started its HTTP server. */ isStarted: boolean; /** * HTTP client adapter used for outgoing command invocations, event publication and health checks. */ client: HttpEventBridgeClient; /** * Creates an HTTP event bridge around a sidecar/platform client. * * @param config - Event bridge and HTTP server configuration. * @param client - Client that knows the platform-specific URL layout. */ constructor(config: EventBridgeConfig, client: HttpEventBridgeClient); /** * Starts the Hono server and registers common middleware and the `/healthz` route. * * The bridge rejects new requests with `503` while {@link destroy} is draining * in-flight work. */ start(): Promise; /** * Publishes an event message through the configured HTTP client. * * Info messages are ignored locally. Other messages must carry an `eventName` * because this bridge maps events to the underlying transport's event topic. * * @param message - Event bridge message without generated id, timestamp and correlation id. * @returns The immutable message with generated transport metadata. */ emitMessage(message: Omit): Promise>; /** * Invokes a PURISTA command over HTTP and returns the command payload. * * This is direct request/response command transport. It does not turn the * command into durable queued work; queue behavior must be modelled with a * queue definition and exposed as an async endpoint by the owning service. * * @param input - Command envelope without generated id, message type, timestamp and correlation id. * @param ttl - Optional request timeout forwarded to the HTTP client. * @throws `HandledError` or `UnhandledError` when the remote command returns an error response. */ invoke(input: Omit, ttl?: number): Promise; /** * Registers the internal command endpoint, plus an optional REST projection. * * Internal command endpoints accept full PURISTA command messages. REST * projections are generated only when command metadata declares HTTP exposure * and `enableRestApiExpose` is enabled. * * @returns The internal command route path. */ registerCommand(address: EBMessageAddress, cb: (message: Command) => Promise> | Readonly>>, metadata: HttpExposedServiceMeta, eventBridgeConfig: DefinitionEventBridgeConfig): Promise; /** * Placeholder for transport-specific command unregistration. * * Hono route removal is not supported by this bridge after registration. */ unregisterCommand(address: EBMessageAddress): Promise; /** * Registers a subscription endpoint before the HTTP server starts. * * Subscriptions react to emitted events/facts. They are not queue workers and * should remain idempotent because HTTP/event transports may redeliver. * * @returns The internal subscription route path. */ registerSubscription(subscription: Subscription, cb: (message: EBMessage) => Promise | undefined>): Promise; /** * Placeholder for transport-specific subscription unregistration. * * Hono route removal is not supported by this bridge after registration. */ unregisterSubscription(address: EBMessageAddress): Promise; /** * Reports whether the bridge can accept new HTTP requests. */ isReady(): Promise; /** * Reports whether the bridge is started and its sidecar/platform client is reachable. */ isHealthy(): Promise; /** * Shut down event bridge as gracefully as possible */ destroy(): Promise; } //# sourceMappingURL=HttpEventBridge.impl.d.ts.map