http/surface.ts

App surface generation — JSON-serializable attack surface from route and middleware specs.

Pure schema helpers (is_null_schema, schema_to_surface, middleware_applies, middleware_spec_applies) live in http/schema_helpers.ts, and each route's error map (resolve_route_error_map) in http/route_errors.ts.

view source

Declarations
#

17 declarations

AppSurface
#

AppSurfaceDiagnostic
#

http/surface.ts view source

AppSurfaceDiagnostic import type {AppSurfaceDiagnostic} from '@fuzdev/fuz_app/http/surface.js';

Assembly-time diagnostic collected during surface generation or server assembly.

level

type "warning" | "info"

category

type string

message

type string

source?

type string

AppSurfaceEnv
#

http/surface.ts view source

AppSurfaceEnv import type {AppSurfaceEnv} from '@fuzdev/fuz_app/http/surface.js';

An env var in the generated attack surface (JSON-serializable).

name

type string

description

type string

sensitivity

Sensitivity level from meta(schema, {sensitivity}). null when not sensitive.

type Sensitivity | null

has_default

type boolean

optional

type boolean

AppSurfaceEvent
#

http/surface.ts view source

AppSurfaceEvent import type {AppSurfaceEvent} from '@fuzdev/fuz_app/http/surface.js';

An SSE event in the generated attack surface (JSON-serializable).

method

type string

description

type string

channel

type string | null

params_schema

type unknown

AppSurfaceMiddleware
#

http/surface.ts view source

AppSurfaceMiddleware import type {AppSurfaceMiddleware} from '@fuzdev/fuz_app/http/surface.js';

A middleware in the generated attack surface (JSON-serializable).

name

type string

path

type string

error_schemas

JSON Schema representations of error responses, keyed by HTTP status code. null when none.

type Record<string, unknown> | null

carve_outs?

Paths under path the layer does not run on, each with its reason. Absent when none.

type { path: string; reason: string; }[]

AppSurfaceRoute
#

http/surface.ts view source

AppSurfaceRoute import type {AppSurfaceRoute} from '@fuzdev/fuz_app/http/surface.js';

A route in the generated attack surface (JSON-serializable).

method

type string

path

type string

auth

type RouteAuth

applicable_middleware

type string[]

description

type string

is_mutation

Whether this route mutates state (POST, PUT, DELETE, PATCH).

type boolean

transaction

Whether this route's handler runs inside a database transaction.

type boolean

raw_body

Whether this route carries raw bytes / a streaming protocol rather than JSON (see RouteSpec.raw_body). When true, input_schema / output_schema being null means "raw bytes", not "no body".

type boolean

rate_limit_key

Rate limit key type declared on the route spec. null when not rate-limited.

type RateLimitKey | null

params_schema

JSON Schema representation of the URL path params schema. null when no params.

type unknown

query_schema

JSON Schema representation of the URL query params schema. null when no query schema.

type unknown

input_schema

JSON Schema representation of the request body schema. null for no-body routes.

type unknown

output_schema

JSON Schema representation of the success response schema.

type unknown

error_schemas

JSON Schema representations of error responses, keyed by HTTP status code. null when none.

type Record<string, unknown> | null

AppSurfaceRpcEndpoint
#

http/surface.ts view source

AppSurfaceRpcEndpoint import type {AppSurfaceRpcEndpoint} from '@fuzdev/fuz_app/http/surface.js';

An RPC endpoint in the generated attack surface (JSON-serializable).

path

type string

methods

type AppSurfaceRpcMethod[]

AppSurfaceRpcMethod
#

http/surface.ts view source

AppSurfaceRpcMethod import type {AppSurfaceRpcMethod} from '@fuzdev/fuz_app/http/surface.js';

A method within an RPC endpoint in the generated attack surface (JSON-serializable).

name

type string

auth

type RouteAuth

input_schema

JSON Schema representation of the input schema. null for null-input methods.

type unknown

output_schema

JSON Schema representation of the output schema.

type unknown

side_effects

type boolean

description

type string

rate_limit_key

Rate limit key declared on the action spec. null when not rate-limited.

type RateLimitKey | null

AppSurfaceSpec
#

http/surface.ts view source

AppSurfaceSpec import type {AppSurfaceSpec} from '@fuzdev/fuz_app/http/surface.js';

The surface bundled with the source specs that produced it.

AppSurface is JSON-serializable (snapshots, UI, startup logging) — it's the observability layer, written to disk by gro gen for human inspection + drift detection.

AppSurfaceSpec is runtime-only — tests, introspection, attack surface assertions. Both in-process and cross-process tests construct an AppSurfaceSpec in TS via create_test_app_surface_spec (or a consumer equivalent); the cross-process-ness lives in the transport + per-test fixture, not the schema source.

surface

type AppSurface

route_specs

type RouteSpec[]

middleware_specs

type MiddlewareSpec[]

route_error_maps

Each route's error map (resolve_route_error_map against middleware_specs), keyed METHOD path (format_route_key) — the one the surface writes, and the one the DEV error check and the test helpers read.

type ReadonlyMap<string, RouteErrorMap>

rpc_endpoints

type RpcEndpointSpec[]

ws_endpoints

type ResolvedWsEndpointSpec[]

AppSurfaceWsEndpoint
#

http/surface.ts view source

AppSurfaceWsEndpoint import type {AppSurfaceWsEndpoint} from '@fuzdev/fuz_app/http/surface.js';

A WebSocket endpoint in the generated attack surface (JSON-serializable).

path

type string

allowed_origins

Upgrade-time origin allowlist — the spec's own allowed_origins, or the server's when it declares none — one entry per regex, stringified via RegExp.prototype.toString() ('/<source>/<flags>'). An empty array refuses every request that carries an Origin. Reviewers read this as the exact pattern matched at the upgrade gate, not a wildcard approximation. Reconstruct via new RegExp(source, flags) if needed.

type readonly string[]

required_roles

Upgrade-time role gate — empty array when no required_roles was declared (any-authenticated). Documents the coarse gate; per-action auth on each method covers per-message authorization.

type readonly string[]

methods

type AppSurfaceWsMethod[]

AppSurfaceWsMethod
#

http/surface.ts view source

AppSurfaceWsMethod import type {AppSurfaceWsMethod} from '@fuzdev/fuz_app/http/surface.js';

A method within a WebSocket endpoint in the generated attack surface (JSON-serializable).

name

type string

kind

request_response (inbound dispatch) or remote_notification (server → client).

type ActionKind

auth

Per-action auth shape. null for remote_notification (server → client) — notifications have no inbound dispatch and therefore no auth axis. request_response always carries a RouteAuth.

type RouteAuth | null

input_schema

JSON Schema of the input schema. null for nullary inputs.

type unknown

output_schema

JSON Schema of the output schema.

type unknown

description

type string

side_effects

type boolean

rate_limit_key

Rate limit key declared on the action spec. null when not rate-limited.

type RateLimitKey | null

create_app_surface_spec
#

http/surface.ts view source

(options: GenerateAppSurfaceOptions): AppSurfaceSpec import {create_app_surface_spec} from '@fuzdev/fuz_app/http/surface.js';

Create an AppSurfaceSpec — the surface bundled with its source specs and each route's error map, built once and read by both.

options

returns

AppSurfaceSpec

env_schema_to_surface
#

http/surface.ts view source

(schema: AnySchema): AppSurfaceEnv[] import {env_schema_to_surface} from '@fuzdev/fuz_app/http/surface.js';

Convert a @fuzdev/fuz_schema env schema to surface entries, one per entry in order, reading each field's meta: the description from its layers (get_schema_fields), and the fail-safe find_schema_sensitivity for secrets. optional and has_default are what a parse of undefined does: accepted, and accepted with a value other than undefined.

schema

an object schema (under any wrappers) with meta on its fields

type AnySchema

returns

AppSurfaceEnv[]

throws

  • TypeError - if `schema` is not an object schema

events_to_surface
#

http/surface.ts view source

(event_specs: EventSpec[], diagnostics?: AppSurfaceDiagnostic[] | undefined): AppSurfaceEvent[] import {events_to_surface} from '@fuzdev/fuz_app/http/surface.js';

Convert SSE event specs to surface entries, each event's params written as the output side (schema_to_surface) — the server sends them.

event_specs

the events to describe

type EventSpec[]

diagnostics?

receives an info diagnostic per part of a schema with no JSON Schema form

optional

returns

AppSurfaceEvent[]

throws

  • Error - naming the event when its params schema can't be written

generate_app_surface
#

http/surface.ts view source

(options: GenerateAppSurfaceOptions): AppSurface import {generate_app_surface} from '@fuzdev/fuz_app/http/surface.js';

Generate a JSON-serializable attack surface from middleware, route specs, and optional env/event metadata.

options

returns

AppSurface

GenerateAppSurfaceOptions
#

http/surface.ts view source

GenerateAppSurfaceOptions import type {GenerateAppSurfaceOptions} from '@fuzdev/fuz_app/http/surface.js';

route_specs

type RouteSpec[]

middleware_specs

type MiddlewareSpec[]

env_schema?

A @fuzdev/fuz_schema object schema of the app's env vars, such as BaseServerEnv.

type AnySchema

event_specs?

type EventSpec[]

rpc_endpoints?

type RpcEndpointSpec[]

ws_endpoints?

Mounted WS endpoints (the same array create_app_server.ws_endpoints auto-mounts). Each entry's actions surface into AppSurface.ws_endpoints[i].methods for attack-surface tests + startup logging. Each carries its effective allowed_origins — resolve_ws_endpoints fills in the server's list where a spec omits it — so the surface records the exact patterns the upgrade gate matches.

type readonly ResolvedWsEndpointSpec[]

route_error_maps?

Each route's error map, keyed METHOD path, when the caller has built it (resolve_app_route_error_maps over the same routes and middleware); resolved here otherwise.

type ReadonlyMap<string, RouteErrorMap>

RpcEndpointSpec
#

http/surface.ts view source

RpcEndpointSpec import type {RpcEndpointSpec} from '@fuzdev/fuz_app/http/surface.js';

An RPC endpoint definition for surface generation.

path

type string

actions

type RpcAction[]

Depends on
#

Imported by
#