UNPKG

@vigilbase/cli

Version:

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

95 lines (94 loc) • 4.47 kB
/** * The frozen allowlist of read-only cf command templates (spec §F4). * * argv only ever comes from these templates. Interpolated values are * re-validated (32-hex IDs, the 19 zone setting IDs, integer pages), every API * template carries `--quiet` and profile mode appends `--profile <p>`. No * template has a confirmation-skipping, local-mode or request-body flag; * `run-cf.ts` refuses such argv at spawn time as a second guard. `per_page` * values equal the scanner's, so page boundaries and API order match live runs. * * The offline preflight runs each template with `--dry-run` and placeholder * IDs. In cf beta.13 the dry-run object is a literal emitted by each generated * handler, so the preflight is a command-name → API-path mapping check only: * it detects renamed or remapped commands but does not prove the real request * target. Scrubbing base-URL variables from the child env is that control. */ import { type CollectableKind, type ZoneSettingId } from '../contract.js'; export declare const DEFAULT_PROFILE = "vigilbase-checkup"; /** Template IDs: every collectable kind plus account selection (`accounts list`). */ export type TemplateId = CollectableKind | 'account_selection'; export type Paging = { kind: 'single'; } /** `--page N` until an empty page; `maxPages` data pages. */ | { kind: 'pages'; perPage: number; maxPages: number; } /** Cursor-only list printed without its cursor: one call, `possibly_truncated` at the threshold. */ | { kind: 'one_call'; perPage: number; }; export type TemplateIds = { accountId?: string; zoneId?: string; rulesetId?: string; settingId?: ZoneSettingId; page?: number; }; type TemplateSpec = { /** Command words, then fixed arguments; `{Z}`, `{R}`, `{S}` and `{N}` are interpolated. */ args: readonly string[]; /** Expected dry-run path below `https://api.cloudflare.com/client/v4`; `{A}` is the account. */ path: string; /** Expected dry-run query; `{A}`/`{N}` are interpolated. Absent when cf prints none. */ query?: Readonly<Record<string, string | number | boolean>>; paging: Paging; output: 'array' | 'object'; scope: 'account' | 'zone' | 'setting' | 'ruleset'; }; export declare const TEMPLATES: Readonly<Record<TemplateId, TemplateSpec>>; export declare const TEMPLATE_IDS: TemplateId[]; export type ProfileArgs = { authMode: 'profile' | 'env' | 'default'; profile: string; }; export declare function validateProfileName(profile: string): string; /** The exact argv for one call. Throws (a programming error) on any invalid interpolation. */ export declare function buildArgv(id: TemplateId, ids: TemplateIds, auth: ProfileArgs, options?: { dryRun?: boolean; }): string[]; export type PreflightCheck = { id: TemplateId; settingId?: ZoneSettingId; argv: string[]; expectedPath: string; expectedQuery?: Record<string, unknown>; }; /** One dry-run per template (one per zone setting), with placeholder IDs. */ export declare function preflightChecks(auth: ProfileArgs, only?: readonly TemplateId[]): PreflightCheck[]; export declare const PREFLIGHT_ACCOUNT_ID: string; /** True when a dry-run object maps to `GET` and exactly the expected path and query. */ export declare function dryRunMatches(stdout: string, check: PreflightCheck): boolean; /** Kinds whose mismatch aborts collection with CF_ALLOWLIST_MISMATCH. */ export declare const CRITICAL_TEMPLATES: readonly TemplateId[]; /** Display form of every template, with placeholders, for `collect --dry-run`. */ export declare function templateDisplay(id: TemplateId, auth: ProfileArgs): string[]; /** The other cf argv the CLI uses: version, the serial whoami, and the login and logout commands. */ export declare function versionArgv(): string[]; export declare function whoamiArgv(auth: ProfileArgs): string[]; /** `cf auth create <p> [--no-browser] --scopes …` (re-authenticates an existing profile). */ export declare function loginArgv(profile: string, scopes: readonly string[], options: { noBrowser: boolean; }): string[]; /** * `cf auth delete <p>` (logout). In cf 1.0.0-beta.13 it takes only the name: * it refuses `--profile` and a shell API token, fails when the profile does * not exist, removes the profile's directory bindings, logs the profile out * and deletes its stored credentials. It has no confirmation prompt. */ export declare function logoutArgv(profile: string): string[]; export {};