UNPKG

@vigilbase/cli

Version:

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

58 lines (57 loc) • 3.25 kB
/** * One's v1 API (api.vigilbase.com/one/v1) from the CLI: the operations come from the vendored * `@vigilbase/api-contract` (src/vendor/api-contract), and `callOperation` checks every input against the * request schemas and every answer against the declared response schema. Problems become VigilbaseApiErrors * with One's code, detail and request ID. */ import { type callOperation } from '../vendor/api-contract/client/index.js'; import type { Operation, OperationOutput } from '../vendor/api-contract/core/operation.js'; import { ONE_V1_OPERATIONS } from '../vendor/api-contract/one/v1/index.js'; import type { VigilbaseOneClient } from './one-client.js'; export { ONE_V1_OPERATIONS }; export type { Operation }; export type V1Input<O extends Operation> = Parameters<typeof callOperation<O>>[1]; export type V1Body<O extends Operation> = OperationOutput<O>['body']; type ListOperation = Operation & { pagination: 'cursor'; }; export type V1Item<O extends ListOperation> = Extract<V1Body<O>, { items: unknown[]; }>['items'][number]; export type V1Page<O extends ListOperation> = { items: V1Item<O>[]; nextCursor?: string; }; /** The v1 operation the CLI names `id`, from the contract; a typo fails at module load in tests. */ export declare function v1Operation<const Id extends (typeof ONE_V1_OPERATIONS)[number]['id']>(id: Id): Extract<(typeof ONE_V1_OPERATIONS)[number], { id: Id; }>; /** * A v1 failure as the CLI reports it. Errors that aren't the client's own pass through unchanged. * `retryAfterHeader` is the answer's Retry-After, for a 429 whose problem body names none. */ export declare function v1Error(op: Operation, query: unknown, error: unknown, retryAfterHeader?: number): unknown; /** Following every page stops here; the answer then carries nextCursor so the caller can go on. */ export declare const MAX_FOLLOWED_ITEMS = 10000; export type PageSelection = { /** --limit: at most this many items, across pages. */ limit?: number; /** --cursor: one page from here. */ cursor?: string; /** Without --limit or --cursor: every item (`all`), or one page of the API's default size. */ defaultScope: 'all' | 'page'; }; /** * A v1 list, page by page. --cursor reads one page; --limit reads pages until it has that many items, asking * each page for only what is left so the returned nextCursor continues exactly where the items end; without * either, `all` follows nextCursor to the end and `page` reads the API's default page. */ export declare function listV1<const O extends ListOperation>(client: VigilbaseOneClient, op: O, input: V1Input<O>, selection: PageSelection): Promise<V1Page<O>>; /** * `More: vigilbase <args…> --cursor <next>` for a list with another page. One binds a cursor to the filters it * was issued with, so `args` must repeat every filter of the request (and --limit when one was given). Each word * is shell-quoted: filter values and the opaque cursor are pasted into a shell. */ export declare function moreCommand(args: readonly (string | undefined)[], nextCursor: string): string; /** `[flag, value]` when the value was given, for moreCommand. */ export declare function flagArgs(flag: string, value: string | number | undefined): string[];