UNPKG

@vigilbase/cli

Version:

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

66 lines (65 loc) • 2.67 kB
import { z } from 'zod'; import { type Operation, type OperationCallInput, type OperationOutput } from '../core/operation.js'; /** * Problems as a client reads them: any `code` string, so a code added to the * contract later still reaches the caller. */ declare const ReceivedProblem: z.ZodObject<{ type: z.ZodString; title: z.ZodString; status: z.ZodNumber; detail: z.ZodString; code: z.ZodString; requestId: z.ZodOptional<z.ZodString>; docs: z.ZodOptional<z.ZodString>; errors: z.ZodOptional<z.ZodArray<z.ZodObject<{ pointer: z.ZodString; message: z.ZodString; }, z.core.$strip>>>; retryAfterSeconds: z.ZodOptional<z.ZodNumber>; }, z.core.$loose>; export type ReceivedProblem = z.infer<typeof ReceivedProblem>; /** A problem answer, or a response the contract does not declare. */ export declare class ApiCallError extends Error { readonly status: number; readonly problem: ReceivedProblem | null; readonly requestId: string | null; /** The parsed JSON body as sent, whatever its shape; null when it was not JSON. */ readonly body: unknown; constructor(status: number, problem: ReceivedProblem | null, requestId: string | null, message: string, /** The parsed JSON body as sent, whatever its shape; null when it was not JSON. */ body?: unknown); } export interface CallOptions { /** Default `https://api.vigilbase.com/{product}/{version}`. */ baseUrl?: string; fetch?: typeof fetch; /** Defaults to Bearer; DPoP tokens also require a per-request proof. */ token?: string; tokenType?: string; dpopProof?: (url: string, method: string) => Promise<string>; idempotencyKey?: string; headers?: Record<string, string>; signal?: AbortSignal; } type Optional<T> = { [K in keyof T as T[K] extends undefined ? never : K]: T[K]; } & { [K in keyof T as T[K] extends undefined ? K : never]?: T[K]; }; /** The URL an operation call goes to: the path template filled in, the query appended. */ export declare function operationUrl(op: Operation, input: { params?: unknown; query?: unknown; }, baseUrl?: string): string; /** * Calls a declared operation and returns its parsed, typed response. The input * is checked against the request schemas before anything is sent; the answer is * checked against the declared response for its status. Problems and * undeclared answers throw ApiCallError. */ export declare function callOperation<const O extends Operation>(op: O, input: Optional<OperationCallInput<O>>, options?: CallOptions): Promise<OperationOutput<O> & { requestId: string | null; headers: Headers; }>; export {};