UNPKG

@vigilbase/cli

Version:

Vigilbase CLI — security scanners, agent tools, and Vigilbase One from the terminal.

174 lines (173 loc) • 6.8 kB
import { z } from 'zod'; import { type ErrorCode } from './errors.js'; import type { Deprecation } from './headers.js'; export declare const API_ORIGIN = "https://api.vigilbase.com"; export declare const PRODUCTS: readonly ["tools", "one", "docs", "os"]; export type Product = (typeof PRODUCTS)[number]; export type ApiVersion = 'v1'; export declare const HTTP_METHODS: readonly ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"]; export type HttpMethod = (typeof HTTP_METHODS)[number]; export declare const SAFE_METHODS: ReadonlySet<HttpMethod>; /** `https://api.vigilbase.com/{product}/{version}`: every operation path is relative to it. */ export declare function serverUrl(product: Product, version?: ApiVersion): string; /** * What an operation accepts. The dispatcher tells them apart by the * credential's shape (see runtime/credentials.ts); the app supplies the * verifier. Cookies are never a scheme: they stay on the legacy hosts. */ export type AuthScheme = { kind: 'anonymous'; rateLimit: string; } /** `vb_dev_` developer key, as `Authorization: Bearer` or `X-Api-Key`. */ | { kind: 'developerKey'; scopes: readonly string[]; } /** Identity access token whose audience is the product's resource. */ | { kind: 'identityBearer'; resource: Product; scopes: readonly string[]; } /** `vb_one_` organisation API key. */ | { kind: 'orgApiKey'; access: 'read' | 'write'; } /** Identity token whose audience is an MCP resource. */ | { kind: 'mcpToken'; scope: string; }; export type AuthKind = AuthScheme['kind']; /** A response: a schema (JSON), or a schema with its media type and description. */ export type ResponseSpec = z.ZodType | { schema: z.ZodType; contentType?: string; description?: string; }; export interface OperationRequest { /** A z.object whose keys are exactly the `{names}` in the path. */ params?: z.ZodType; query?: z.ZodType; body?: z.ZodType; contentType?: 'application/json' | 'multipart/form-data'; } export interface Operation { /** Stable operation ID, `<product>.<resource>.<action>`, e.g. `one.customers.list`. */ id: string; product: Product; version: ApiVersion; method: HttpMethod; /** Relative to `/{product}/{version}`, e.g. `/customers/{customerId}`. */ path: `/${string}`; summary: string; description?: string; tags: readonly string[]; /** Only declared operations exist on api.vigilbase.com. */ stability: 'ga' | 'beta'; audience: 'public' | 'customer' | 'staff'; /** Empty means refused to everyone. */ auth: readonly AuthScheme[]; /** Product RBAC permissions; still enforced by the implementation. */ permissions?: readonly string[]; /** Needs a recent sign-in by a person: always refused to keys and tokens. */ stepUp?: boolean; idempotency?: 'required' | 'optional'; pagination?: 'cursor'; /** Named rate-limit policy, sent as RateLimit / RateLimit-Policy. */ rateLimit?: string; request: OperationRequest; /** Status → response. 204 takes `z.void()`. */ responses: { readonly [status: number]: ResponseSpec; }; /** Documented problem codes. */ errors: readonly ErrorCode[]; examples?: readonly { name?: string; request?: { params?: Record<string, string>; query?: Record<string, unknown>; body?: unknown; }; response?: { status: number; body: unknown; }; }[]; /** * Legacy paths that serve the same implementation through the existing route * files. Their responses carry Deprecation and a successor Link once the * product is in LEGACY_ALIAS_DEPRECATION (src/deprecation.ts). */ legacy?: readonly LegacyAlias[]; deprecated?: Deprecation; expose?: { mcp?: 'code-mode' | 'tool'; cli?: string; llms?: boolean; }; } export interface LegacyAlias { host: 'com' | 'one'; method?: HttpMethod; path: `/api/${string}`; /** Never sunset (Q5 of the hostname plan): shipped CLIs pin this path. */ permanent?: boolean; /** * Embedded in third-party pages (badge `<img>` URLs). Must be permanent, and * announces no deprecation at all: nothing that loads it reads Deprecation * or a successor Link, and the path never goes away. */ embedded?: boolean; /** An alias-specific deprecation that predates the product's, e.g. the unversioned `/api/agent/*` paths. */ deprecated?: { at: Date; sunset?: Date; }; } /** Keeps the literal types of an operation so implementations and clients are typed by it. */ export declare const defineOperation: <const O extends Operation>(operation: O) => O; type Out<S> = S extends z.ZodType ? z.output<S> : undefined; type In<S> = S extends z.ZodType ? z.input<S> : undefined; type SchemaOf<R> = R extends z.ZodType ? R : R extends { schema: infer S extends z.ZodType; } ? S : never; export type ResponseStatus<O extends Operation> = Extract<keyof O['responses'], number>; /** What an implementation receives, after validation. */ export interface OperationInput<O extends Operation> { params: Out<O['request']['params']>; query: Out<O['request']['query']>; body: Out<O['request']['body']>; } /** What a client sends, before validation. Uploads go as FormData. */ export interface OperationCallInput<O extends Operation> { params: In<O['request']['params']>; query: In<O['request']['query']>; body: O['request']['contentType'] extends 'multipart/form-data' ? FormData : In<O['request']['body']>; } /** One of the declared responses. */ export type OperationResult<O extends Operation> = { [S in ResponseStatus<O>]: { status: S; body: z.input<SchemaOf<O['responses'][S]>>; headers?: Record<string, string>; }; }[ResponseStatus<O>]; /** The parsed body of a declared response. */ export type OperationOutput<O extends Operation, S extends ResponseStatus<O> = ResponseStatus<O>> = { [K in S]: { status: K; body: z.output<SchemaOf<O['responses'][K]>>; }; }[S]; export declare function responseSchema(spec: ResponseSpec): z.ZodType; export declare function responseContentType(spec: ResponseSpec): string; export declare function pathParamNames(path: string): string[]; /** The problems with a product's operation list; empty when it is consistent. */ export declare function operationProblems(product: Product, operations: readonly Operation[]): string[]; /** A product's operations, checked once at module load: a bad declaration fails every test that imports it. */ export declare function defineOperations<const Ops extends readonly Operation[]>(product: Product, operations: Ops): Ops; export {};