@vigilbase/cli
Version:
Vigilbase CLI — security scanners, agent tools, and Vigilbase One from the terminal.
175 lines (174 loc) • 7.16 kB
TypeScript
import { z } from 'zod';
/** RFC 9457 §3: the media type of every error body on api.vigilbase.com. */
export declare const PROBLEM_CONTENT_TYPE = "application/problem+json";
/**
* Every `code` a problem body can carry, with its HTTP status. One shared list:
* Tools v1 keeps its existing codes (bad_request … service_unavailable, decision 3
* of the contract design), One's key denials keep theirs, and the rest come from
* OS's ERROR_CODES so OS can move across later.
*/
export declare const ERROR_STATUS: {
readonly bad_request: 400;
readonly validation_failed: 400;
readonly idempotency_key_invalid: 400;
readonly unauthorized: 401;
readonly invalid_api_key: 401;
readonly api_key_revoked: 401;
readonly api_key_expired: 401;
readonly forbidden: 403;
readonly step_up_required: 403;
readonly staff_only: 403;
readonly read_only_key: 403;
readonly not_for_api_keys: 403;
readonly insufficient_scope: 403;
readonly not_found: 404;
readonly method_not_allowed: 405;
readonly conflict: 409;
readonly idempotency_in_progress: 409;
readonly gone: 410;
readonly length_required: 411;
readonly precondition_failed: 412;
readonly payload_too_large: 413;
readonly unsupported_media_type: 415;
readonly unprocessable_entity: 422;
readonly idempotency_key_reused: 422;
readonly rate_limit_exceeded: 429;
readonly internal_error: 500;
readonly upstream_unavailable: 502;
readonly service_unavailable: 503;
};
export type ErrorCode = keyof typeof ERROR_STATUS;
export declare const ERROR_CODES: [ErrorCode, ...ErrorCode[]];
export declare const ErrorCodeSchema: z.ZodEnum<{
bad_request: "bad_request";
unauthorized: "unauthorized";
forbidden: "forbidden";
not_found: "not_found";
conflict: "conflict";
gone: "gone";
length_required: "length_required";
payload_too_large: "payload_too_large";
unsupported_media_type: "unsupported_media_type";
rate_limit_exceeded: "rate_limit_exceeded";
unprocessable_entity: "unprocessable_entity";
internal_error: "internal_error";
service_unavailable: "service_unavailable";
validation_failed: "validation_failed";
idempotency_key_invalid: "idempotency_key_invalid";
invalid_api_key: "invalid_api_key";
api_key_revoked: "api_key_revoked";
api_key_expired: "api_key_expired";
step_up_required: "step_up_required";
staff_only: "staff_only";
read_only_key: "read_only_key";
not_for_api_keys: "not_for_api_keys";
insufficient_scope: "insufficient_scope";
method_not_allowed: "method_not_allowed";
idempotency_in_progress: "idempotency_in_progress";
precondition_failed: "precondition_failed";
idempotency_key_reused: "idempotency_key_reused";
upstream_unavailable: "upstream_unavailable";
}>;
/** A field-level validation issue, from zod's issue list. */
export declare const ProblemFieldError: z.ZodObject<{
pointer: z.ZodString;
message: z.ZodString;
}, z.core.$strip>;
/**
* RFC 9457 problem details (§3.1 members, all present) with the extension
* members of the contract (§3.2): `code`, `requestId`, `docs`, field `errors`
* and `retryAfterSeconds` where they apply. Extra members are allowed so Tools
* v1 can keep its legacy `success`/`error` members.
*/
export declare const ProblemDetails: z.ZodObject<{
type: z.ZodString;
title: z.ZodString;
status: z.ZodNumber;
detail: z.ZodString;
instance: z.ZodOptional<z.ZodString>;
code: z.ZodEnum<{
bad_request: "bad_request";
unauthorized: "unauthorized";
forbidden: "forbidden";
not_found: "not_found";
conflict: "conflict";
gone: "gone";
length_required: "length_required";
payload_too_large: "payload_too_large";
unsupported_media_type: "unsupported_media_type";
rate_limit_exceeded: "rate_limit_exceeded";
unprocessable_entity: "unprocessable_entity";
internal_error: "internal_error";
service_unavailable: "service_unavailable";
validation_failed: "validation_failed";
idempotency_key_invalid: "idempotency_key_invalid";
invalid_api_key: "invalid_api_key";
api_key_revoked: "api_key_revoked";
api_key_expired: "api_key_expired";
step_up_required: "step_up_required";
staff_only: "staff_only";
read_only_key: "read_only_key";
not_for_api_keys: "not_for_api_keys";
insufficient_scope: "insufficient_scope";
method_not_allowed: "method_not_allowed";
idempotency_in_progress: "idempotency_in_progress";
precondition_failed: "precondition_failed";
idempotency_key_reused: "idempotency_key_reused";
upstream_unavailable: "upstream_unavailable";
}>;
requestId: 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 ProblemDetails = z.infer<typeof ProblemDetails>;
/** How a product names its problem types. */
export interface ProblemConfig {
/** `type` is `<typeBase>/<code-with-dashes>`; without one it is `about:blank` (RFC 9457 §4.2.1). */
typeBase?: string;
/** Where the product's error codes are documented; sent as `docs`. */
docs?: string;
}
export interface ProblemInput {
code: ErrorCode;
detail: string;
requestId: string;
instance?: string;
errors?: z.infer<typeof ProblemFieldError>[];
retryAfterSeconds?: number;
/** Extra members (Tools v1 legacy `success`/`error`). Never overrides a standard member. */
extensions?: Record<string, unknown>;
}
export declare function problemBody(input: ProblemInput, config?: ProblemConfig): ProblemDetails;
/** Zod issues as problem `errors`, prefixed with the request part that failed. */
export declare function fieldErrors(part: 'params' | 'query' | 'body' | 'headers', error: z.ZodError): z.infer<typeof ProblemFieldError>[];
/** Thrown by implementations to answer with a problem; the dispatcher renders it. */
export declare class ApiProblem extends Error {
readonly code: ErrorCode;
readonly options: {
errors?: z.infer<typeof ProblemFieldError>[];
retryAfterSeconds?: number;
headers?: Record<string, string>;
/**
* The operation changed nothing, so an Idempotency-Key claim may be
* released and the same key retried. Without it the problem is stored as
* the key's answer.
*/
noEffect?: boolean;
};
constructor(code: ErrorCode, detail: string, options?: {
errors?: z.infer<typeof ProblemFieldError>[];
retryAfterSeconds?: number;
headers?: Record<string, string>;
/**
* The operation changed nothing, so an Idempotency-Key claim may be
* released and the same key retried. Without it the problem is stored as
* the key's answer.
*/
noEffect?: boolean;
});
get status(): number;
}