import { H as HandlerConfig, a as HandlerRequest, b as HandlerResponse, F as FactoryRegistry, S as SchemaInfo, c as FactoryDefinition } from './graph-Caum9aCC.js'; export { A as AuthContext, d as AuthCookie, e as AuthResult, D as DiscoverResponse, f as DownResponse, g as FKEdge, h as FactoryContext, i as FieldInfo, j as HookContext, M as ModelInfo, k as SchemaRelation, l as SdkInfo, U as UpResponse, m as findDeferrableEdge, t as topoSort } from './graph-Caum9aCC.js'; import { ZodTypeAny } from 'zod'; /** * Request routing for discover / up / down protocol actions. * * Factory-driven design: every model in `body.create` must have a * registered factory. The SDK uses each factory's `inputSchema` (Zod) * to validate inputs and to build the `discover` schema. Ordering for * `up` and `down` comes from the create payload's `_alias` / `_ref` * graph (see `payload-topo.ts`); there is no SQL introspection. */ /** * Substitute built-in tokens in field values: {{testRunId}}, {{index}}, * {{cycle(a,b,c)}}. Defense-in-depth: the test runner should substitute * recipe variables before calling /up, but if a literal {{…}} slips * through we fail loudly with UNRESOLVED_TOKEN rather than INSERT the * raw string. */ declare function resolveTokens(value: unknown, testRunId: string, index: number): unknown; declare const PROTOCOL_VERSION: string; declare function handleRequest(config: HandlerConfig, req: HandlerRequest): Promise; declare function signBody(body: string, secret: string): string; declare function verifySignature(body: string, signature: string, secret: string): boolean; interface RefsPayload { refs: Record[]>; testRunId: string; environment: string; /** * Captured at `up` time so `down` can topo-sort teardown without * re-parsing the create payload. Optional — older tokens omitted it * and `down` falls back to refs-key insertion order. */ aliasDependencies?: Record; aliasOwnerModel?: Record; } /** * Sign refs into a JWT-like token (header.payload.signature). * Uses HMAC-SHA256 — not a full JWT library to avoid dependencies. */ declare function signRefs(payload: RefsPayload, secret: string): string; /** * Verify and decode a refs token. Returns the payload or throws. */ declare function verifyRefs(token: string, secret: string): RefsPayload; /** * Compute a stable 16-char hex fingerprint of a scenario definition. * Uses sha256 of the JSON-serialized spec with sorted keys. */ declare function fingerprint(value: unknown): string; interface CreateOp { model: string; fields: Record; tempId: string; } interface ResolvedTree { ops: CreateOp[]; /** alias → temp id assigned to the entity declaring that alias. */ aliases: Record; /** alias → model name, used by teardown to pick the right factory. */ aliasOwnerModel: Record; /** alias → list of aliases the owner depends on (may include unknowns). */ aliasDependencies: Record; } /** * Topo-sort a create payload into an ordered list of `CreateOp`. * * `create` is the dashboard's nested map `{ model: [entity, ...] }`. * Each entity is an object; `_alias` (declared by dependency targets) * and `_ref` (declared by dependents, anywhere in the field tree) are * the only reserved keys. * * Throws INVALID_BODY if the payload references an alias that is never * declared, or if the alias graph contains a cycle. */ declare function resolvePayloadTree(create: Record): ResolvedTree; /** * Order models for teardown. * * With `aliasDependencies` available (newer refs tokens carry it), we * run the same Kahn's topo sort over models — derived from aggregating * each alias's dependencies — and return the *reverse* topo so children * are torn down before parents. * * Without it (older refs tokens), fall back to reversing the insertion * order of `refs` keys, which is what the SDK always did for factory * teardown. */ declare function computeTeardownOrder(refs: Record, aliasDependencies?: Record, aliasOwnerModel?: Record): string[]; /** * Build the SDK's wire-shape schema from registered factories. * * The dashboard's `discover` response carries a `schema` block listing * every model the host can create. With the old SDK that came from * `information_schema` queries; with this one it comes from each * factory's `inputSchema` (a Zod schema). * * The mapping from a Zod type to the dashboard's coarse type string is * intentionally lossy — the dashboard only branches on a handful of * categories (`string`, `integer`, `boolean`, `timestamp`, ...) and * treats everything else as opaque JSON. */ /** * Map a Zod schema to the SDK's coarse type string. * * Unknown schemas fall back to `string` — the conservative default the * dashboard renders as a free-form text input. */ declare function fieldTypeFromZod(schema: ZodTypeAny): string; /** * Build the SDK's discover-time schema from registered factories. * * `edges` and `relations` are emitted as empty arrays. They were * populated from FK introspection in the old design; here the create * payload's `_alias` / `_ref` graph carries equivalent information at * request time, so the static schema doesn't need them. */ declare function buildSchemaFromFactories(factories: FactoryRegistry, scopeField: string): SchemaInfo; /** * Serialise a `SchemaInfo` to the JSON shape the dashboard expects. * * Field names in the wire JSON are camelCase (`isRequired`, not * `is_required`); kept here so both halves of the discover response * live in one place. */ declare function schemaToWire(schema: SchemaInfo): Record; interface CheckResult { valid: boolean; phase: 'up' | 'down' | 'ok'; errors: CheckError[]; timing?: { upMs: number; downMs: number; }; } interface CheckError { phase: 'up' | 'down'; message: string; fix?: string; } interface CheckScenario { /** Flat map: model name → list of entity payloads (with `_alias` / `_ref`). */ create: Record[]>; } /** * Dry-run a scenario through the same handler the dashboard hits. Runs * `up` then `down` and returns structured errors if either fails. */ declare function checkScenario(factories: FactoryRegistry, scenario: CheckScenario, options?: { scopeField?: string; sharedSecret?: string; signingSecret?: string; auth?: HandlerConfig['auth']; }): Promise; declare function checkAllScenarios(factories: FactoryRegistry, scenarios: CheckScenario[], options?: Parameters[2]): Promise; /** * Define a factory for creating entities via user code. * * Every factory must declare an `inputSchema` (Zod) so the SDK can: * 1. validate the create payload before invoking `create`, and * 2. derive the `discover` schema from the Zod shape (no DB introspection). * * The generics are inferred from the schemas you pass in: `create`'s * `data` argument is typed as `z.infer`, and * `teardown`'s `record` argument is typed as `z.infer` * when one is set. No call-site `z.infer<...>` annotations needed. */ declare function defineFactory(definition: FactoryDefinition): FactoryDefinition; declare class AutonomaError extends Error { readonly code: string; readonly status: number; constructor(message: string, code: string, status: number); } declare const Errors: { readonly unknownAction: (action: string) => AutonomaError; readonly unknownEnvironment: (name: string) => AutonomaError; readonly invalidSignature: () => AutonomaError; readonly invalidRefsToken: (reason: string) => AutonomaError; /** @deprecated The SDK no longer gates on production; this is never thrown. */ readonly productionBlocked: (detail?: string) => AutonomaError; readonly invalidBody: (reason: string) => AutonomaError; }; export { AutonomaError, type CheckError, type CheckResult, type CheckScenario, type CreateOp, Errors, FactoryDefinition, FactoryRegistry, HandlerConfig, HandlerRequest, HandlerResponse, PROTOCOL_VERSION, type RefsPayload, type ResolvedTree, SchemaInfo, buildSchemaFromFactories, checkAllScenarios, checkScenario, computeTeardownOrder, defineFactory, fieldTypeFromZod, fingerprint, handleRequest, resolvePayloadTree, resolveTokens, schemaToWire, signBody, signRefs, verifyRefs, verifySignature };