@vertaaux/cli 0.3.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +97 -0
- package/MIGRATION.md +239 -0
- package/README.md +34 -16
- package/dist/app/interactive-app.d.ts +101 -0
- package/dist/app/interactive-app.d.ts.map +1 -0
- package/dist/app/interactive-app.js +309 -0
- package/dist/app/layout/canvas.d.ts +23 -0
- package/dist/app/layout/canvas.d.ts.map +1 -0
- package/dist/app/layout/canvas.js +36 -0
- package/dist/app/layout/footer.d.ts +31 -0
- package/dist/app/layout/footer.d.ts.map +1 -0
- package/dist/app/layout/footer.js +41 -0
- package/dist/app/layout/header.d.ts +20 -0
- package/dist/app/layout/header.d.ts.map +1 -0
- package/dist/app/layout/header.js +27 -0
- package/dist/app/menu/categories.d.ts +20 -0
- package/dist/app/menu/categories.d.ts.map +1 -0
- package/dist/app/menu/categories.js +181 -0
- package/dist/app/menu/filter.d.ts +17 -0
- package/dist/app/menu/filter.d.ts.map +1 -0
- package/dist/app/menu/filter.js +33 -0
- package/dist/app/menu/menu-view.d.ts +35 -0
- package/dist/app/menu/menu-view.d.ts.map +1 -0
- package/dist/app/menu/menu-view.js +230 -0
- package/dist/app/menu/recent.d.ts +24 -0
- package/dist/app/menu/recent.d.ts.map +1 -0
- package/dist/app/menu/recent.js +49 -0
- package/dist/app/types.d.ts +43 -0
- package/dist/app/types.d.ts.map +1 -0
- package/dist/app/types.js +7 -0
- package/dist/app/views/command-runner.d.ts +36 -0
- package/dist/app/views/command-runner.d.ts.map +1 -0
- package/dist/app/views/command-runner.js +372 -0
- package/dist/app/views/help-overlay.d.ts +21 -0
- package/dist/app/views/help-overlay.d.ts.map +1 -0
- package/dist/app/views/help-overlay.js +45 -0
- package/dist/auth/ci-token.d.ts +14 -2
- package/dist/auth/ci-token.d.ts.map +1 -1
- package/dist/auth/ci-token.js +15 -30
- package/dist/auth/device-flow.d.ts +2 -1
- package/dist/auth/device-flow.d.ts.map +1 -1
- package/dist/auth/device-flow.js +13 -10
- package/dist/auth/token-store.d.ts.map +1 -1
- package/dist/auth/token-store.js +12 -2
- package/dist/baseline/diff.d.ts +2 -2
- package/dist/baseline/diff.d.ts.map +1 -1
- package/dist/baseline/diff.js +15 -34
- package/dist/commands/a11y.d.ts +9 -0
- package/dist/commands/a11y.d.ts.map +1 -0
- package/dist/commands/a11y.js +76 -0
- package/dist/commands/audit/artifacts.d.ts +27 -0
- package/dist/commands/audit/artifacts.d.ts.map +1 -0
- package/dist/commands/audit/artifacts.js +158 -0
- package/dist/commands/audit/ci-detection.d.ts +18 -0
- package/dist/commands/audit/ci-detection.d.ts.map +1 -0
- package/dist/commands/audit/ci-detection.js +71 -0
- package/dist/commands/audit/explain.d.ts +11 -0
- package/dist/commands/audit/explain.d.ts.map +1 -0
- package/dist/commands/audit/explain.js +45 -0
- package/dist/commands/audit/filters.d.ts +17 -0
- package/dist/commands/audit/filters.d.ts.map +1 -0
- package/dist/commands/audit/filters.js +40 -0
- package/dist/commands/audit/index.d.ts +18 -0
- package/dist/commands/audit/index.d.ts.map +1 -0
- package/dist/commands/audit/index.js +564 -0
- package/dist/commands/audit/output.d.ts +32 -0
- package/dist/commands/audit/output.d.ts.map +1 -0
- package/dist/commands/audit/output.js +130 -0
- package/dist/commands/audit/policy.d.ts +19 -0
- package/dist/commands/audit/policy.d.ts.map +1 -0
- package/dist/commands/audit/policy.js +102 -0
- package/dist/commands/audit/scoring.d.ts +23 -0
- package/dist/commands/audit/scoring.d.ts.map +1 -0
- package/dist/commands/audit/scoring.js +70 -0
- package/dist/commands/audit/types.d.ts +88 -0
- package/dist/commands/audit/types.d.ts.map +1 -0
- package/dist/commands/audit/types.js +8 -0
- package/dist/commands/audit.d.ts +2 -60
- package/dist/commands/audit.d.ts.map +1 -1
- package/dist/commands/audit.js +2 -1038
- package/dist/commands/baseline.d.ts +1 -0
- package/dist/commands/baseline.d.ts.map +1 -1
- package/dist/commands/baseline.js +205 -121
- package/dist/commands/comment.d.ts +22 -0
- package/dist/commands/comment.d.ts.map +1 -1
- package/dist/commands/comment.js +122 -58
- package/dist/commands/compare.d.ts +17 -0
- package/dist/commands/compare.d.ts.map +1 -1
- package/dist/commands/compare.js +287 -180
- package/dist/commands/diff.d.ts +5 -0
- package/dist/commands/diff.d.ts.map +1 -1
- package/dist/commands/diff.js +168 -141
- package/dist/commands/doc.d.ts +10 -0
- package/dist/commands/doc.d.ts.map +1 -1
- package/dist/commands/doc.js +134 -76
- package/dist/commands/doctor.d.ts +2 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +164 -17
- package/dist/commands/download.d.ts +10 -0
- package/dist/commands/download.d.ts.map +1 -1
- package/dist/commands/download.js +169 -112
- package/dist/commands/explain.d.ts +5 -0
- package/dist/commands/explain.d.ts.map +1 -1
- package/dist/commands/explain.js +241 -155
- package/dist/commands/fix-all.d.ts +25 -0
- package/dist/commands/fix-all.d.ts.map +1 -0
- package/dist/commands/fix-all.js +206 -0
- package/dist/commands/fix-plan.d.ts +9 -0
- package/dist/commands/fix-plan.d.ts.map +1 -1
- package/dist/commands/fix-plan.js +152 -89
- package/dist/commands/fix.d.ts +17 -0
- package/dist/commands/fix.d.ts.map +1 -0
- package/dist/commands/fix.js +111 -0
- package/dist/commands/init.d.ts +11 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +94 -42
- package/dist/commands/login.d.ts +18 -0
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +268 -95
- package/dist/commands/patch-review.d.ts +11 -0
- package/dist/commands/patch-review.d.ts.map +1 -1
- package/dist/commands/patch-review.js +159 -97
- package/dist/commands/policy.d.ts +31 -0
- package/dist/commands/policy.d.ts.map +1 -1
- package/dist/commands/policy.js +269 -124
- package/dist/commands/release-notes.d.ts +10 -0
- package/dist/commands/release-notes.d.ts.map +1 -1
- package/dist/commands/release-notes.js +127 -73
- package/dist/commands/scan.d.ts +13 -0
- package/dist/commands/scan.d.ts.map +1 -0
- package/dist/commands/scan.js +133 -0
- package/dist/commands/status.d.ts +9 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +81 -0
- package/dist/commands/suggest.d.ts +10 -0
- package/dist/commands/suggest.d.ts.map +1 -1
- package/dist/commands/suggest.js +153 -82
- package/dist/commands/triage.d.ts +35 -0
- package/dist/commands/triage.d.ts.map +1 -1
- package/dist/commands/triage.js +206 -81
- package/dist/commands/upload.d.ts +9 -0
- package/dist/commands/upload.d.ts.map +1 -1
- package/dist/commands/upload.js +140 -101
- package/dist/commands/verify.d.ts +13 -0
- package/dist/commands/verify.d.ts.map +1 -0
- package/dist/commands/verify.js +118 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +125 -990
- package/dist/interactive/fix-wizard.d.ts +3 -0
- package/dist/interactive/fix-wizard.d.ts.map +1 -1
- package/dist/interactive/fix-wizard.js +130 -112
- package/dist/interactive/init-wizard.d.ts +3 -1
- package/dist/interactive/init-wizard.d.ts.map +1 -1
- package/dist/interactive/init-wizard.js +207 -138
- package/dist/interactive/prompts.d.ts +7 -3
- package/dist/interactive/prompts.d.ts.map +1 -1
- package/dist/interactive/prompts.js +44 -23
- package/dist/output/envelope.d.ts +2 -0
- package/dist/output/envelope.d.ts.map +1 -1
- package/dist/output/envelope.js +18 -2
- package/dist/output/factory.d.ts +9 -1
- package/dist/output/factory.d.ts.map +1 -1
- package/dist/output/html.d.ts +2 -1
- package/dist/output/html.d.ts.map +1 -1
- package/dist/output/html.js +3 -2
- package/dist/output/human.d.ts +9 -1
- package/dist/output/human.d.ts.map +1 -1
- package/dist/output/human.js +17 -2
- package/dist/output/json.d.ts +2 -1
- package/dist/output/json.d.ts.map +1 -1
- package/dist/output/junit.d.ts +2 -1
- package/dist/output/junit.d.ts.map +1 -1
- package/dist/output/sarif.d.ts +2 -1
- package/dist/output/sarif.d.ts.map +1 -1
- package/dist/types.d.ts +74 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/ui/banner.d.ts +34 -0
- package/dist/ui/banner.d.ts.map +1 -1
- package/dist/ui/banner.js +97 -5
- package/dist/ui/diagnostics.d.ts +9 -4
- package/dist/ui/diagnostics.d.ts.map +1 -1
- package/dist/ui/diagnostics.js +32 -82
- package/dist/ui/strings.d.ts +373 -0
- package/dist/ui/strings.d.ts.map +1 -0
- package/dist/ui/strings.js +499 -0
- package/dist/ui/table.d.ts +0 -2
- package/dist/ui/table.d.ts.map +1 -1
- package/dist/ui/table.js +3 -4
- package/dist/utils/api-client.d.ts +46 -0
- package/dist/utils/api-client.d.ts.map +1 -0
- package/dist/utils/api-client.js +170 -0
- package/dist/utils/client.d.ts +29 -18
- package/dist/utils/client.d.ts.map +1 -1
- package/dist/utils/client.js +102 -12
- package/dist/utils/formatters.d.ts +38 -0
- package/dist/utils/formatters.d.ts.map +1 -0
- package/dist/utils/formatters.js +277 -0
- package/dist/utils/local-capture.d.ts +25 -0
- package/dist/utils/local-capture.d.ts.map +1 -0
- package/dist/utils/local-capture.js +57 -0
- package/dist/utils/url-classify.d.ts +18 -0
- package/dist/utils/url-classify.d.ts.map +1 -0
- package/dist/utils/url-classify.js +106 -0
- package/node_modules/@vertaaux/tui/dist/index.cjs +713 -20
- package/node_modules/@vertaaux/tui/dist/index.cjs.map +1 -1
- package/node_modules/@vertaaux/tui/dist/index.d.cts +361 -4
- package/node_modules/@vertaaux/tui/dist/index.d.ts +361 -4
- package/node_modules/@vertaaux/tui/dist/index.js +689 -21
- package/node_modules/@vertaaux/tui/dist/index.js.map +1 -1
- package/package.json +13 -5
- package/dist/commands/client.d.ts +0 -14
- package/dist/commands/client.d.ts.map +0 -1
- package/dist/commands/client.js +0 -362
- package/dist/commands/drift.d.ts +0 -15
- package/dist/commands/drift.d.ts.map +0 -1
- package/dist/commands/drift.js +0 -309
- package/dist/commands/protect.d.ts +0 -16
- package/dist/commands/protect.d.ts.map +0 -1
- package/dist/commands/protect.js +0 -323
- package/dist/commands/report.d.ts +0 -15
- package/dist/commands/report.d.ts.map +0 -1
- package/dist/commands/report.js +0 -214
- package/dist/policy/sync.d.ts +0 -67
- package/dist/policy/sync.d.ts.map +0 -1
- package/dist/policy/sync.js +0 -147
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API client utilities for the VertaaUX CLI legacy commands.
|
|
3
|
+
* Provides argument parsing helpers, API request function, and polling utilities.
|
|
4
|
+
*
|
|
5
|
+
* NOTE: resolveApiBase, getApiKey, sleep, apiRequest, and waitForAudit are
|
|
6
|
+
* now imported from ./client to avoid duplication. The legacy DEFAULT_API_BASE
|
|
7
|
+
* (which had a wrong path) is replaced by the corrected value in client.ts.
|
|
8
|
+
*/
|
|
9
|
+
import { resolveApiBase as _resolveApiBase, getApiKey as _getApiKey, sleep, apiRequest as _apiRequest, waitForAudit as _waitForAudit, createClient, } from "./client.js";
|
|
10
|
+
// Re-export utilities that legacy commands import from this module
|
|
11
|
+
export { sleep, createClient };
|
|
12
|
+
/**
|
|
13
|
+
* Legacy 3-arg apiRequest wrapper for legacy commands that don't pass apiKey
|
|
14
|
+
* explicitly (they rely on VERTAAUX_API_KEY from environment).
|
|
15
|
+
* Delegates to client.ts apiRequest with the key resolved internally.
|
|
16
|
+
*/
|
|
17
|
+
export async function apiRequest(base, reqPath, options) {
|
|
18
|
+
const apiKey = _getApiKey();
|
|
19
|
+
return _apiRequest(base, reqPath, options, apiKey);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Legacy waitForAudit wrapper that accepts base/jobId/timeout/interval (no apiKey param).
|
|
23
|
+
* Delegates to client.ts waitForAudit with key resolved internally.
|
|
24
|
+
*/
|
|
25
|
+
export async function waitForAudit(base, jobId, timeoutMs, intervalMs) {
|
|
26
|
+
const apiKey = _getApiKey();
|
|
27
|
+
return _waitForAudit(base, jobId, timeoutMs, intervalMs, apiKey);
|
|
28
|
+
}
|
|
29
|
+
// ============================================================================
|
|
30
|
+
// Argument parsing helpers
|
|
31
|
+
// ============================================================================
|
|
32
|
+
export function parseArgs(args) {
|
|
33
|
+
const positional = [];
|
|
34
|
+
const flags = {};
|
|
35
|
+
for (let i = 0; i < args.length; i++) {
|
|
36
|
+
const arg = args[i];
|
|
37
|
+
if (arg === "--") {
|
|
38
|
+
positional.push(...args.slice(i + 1));
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
if (arg.startsWith("--")) {
|
|
42
|
+
const [rawKey, rawValue] = arg.slice(2).split("=", 2);
|
|
43
|
+
if (rawValue !== undefined) {
|
|
44
|
+
flags[rawKey] = rawValue;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const next = args[i + 1];
|
|
48
|
+
if (next && !next.startsWith("-")) {
|
|
49
|
+
flags[rawKey] = next;
|
|
50
|
+
i += 1;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
flags[rawKey] = true;
|
|
54
|
+
}
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (arg.startsWith("-") && arg.length > 1) {
|
|
58
|
+
const key = arg.slice(1);
|
|
59
|
+
if (key === "u") {
|
|
60
|
+
const next = args[i + 1];
|
|
61
|
+
if (next && !next.startsWith("-")) {
|
|
62
|
+
flags.url = next;
|
|
63
|
+
i += 1;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
flags.url = true;
|
|
67
|
+
}
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (key === "b") {
|
|
71
|
+
const next = args[i + 1];
|
|
72
|
+
if (next && !next.startsWith("-")) {
|
|
73
|
+
flags.base = next;
|
|
74
|
+
i += 1;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
flags.base = true;
|
|
78
|
+
}
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (key === "f") {
|
|
82
|
+
const next = args[i + 1];
|
|
83
|
+
if (next && !next.startsWith("-")) {
|
|
84
|
+
flags.format = next;
|
|
85
|
+
i += 1;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
flags.format = true;
|
|
89
|
+
}
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (key === "h") {
|
|
93
|
+
flags.help = true;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (key === "q") {
|
|
97
|
+
flags.quiet = true;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const next = args[i + 1];
|
|
101
|
+
if (next && !next.startsWith("-")) {
|
|
102
|
+
flags[key] = next;
|
|
103
|
+
i += 1;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
flags[key] = true;
|
|
107
|
+
}
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
positional.push(arg);
|
|
111
|
+
}
|
|
112
|
+
return { positional, flags };
|
|
113
|
+
}
|
|
114
|
+
export function getString(flags, key) {
|
|
115
|
+
const value = flags[key];
|
|
116
|
+
if (typeof value === "string")
|
|
117
|
+
return value;
|
|
118
|
+
// Fallback: try camelCase version (Commander.js converts --multi-word to multiWord)
|
|
119
|
+
const camelKey = key.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
120
|
+
if (camelKey !== key) {
|
|
121
|
+
const camelValue = flags[camelKey];
|
|
122
|
+
if (typeof camelValue === "string")
|
|
123
|
+
return camelValue;
|
|
124
|
+
}
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
export function getBool(flags, key) {
|
|
128
|
+
if (flags[key] === true)
|
|
129
|
+
return true;
|
|
130
|
+
// Fallback: try camelCase version (Commander.js converts --multi-word to multiWord)
|
|
131
|
+
const camelKey = key.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
132
|
+
if (camelKey !== key)
|
|
133
|
+
return flags[camelKey] === true;
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
export function getNumber(flags, key) {
|
|
137
|
+
const raw = getString(flags, key);
|
|
138
|
+
if (raw === undefined)
|
|
139
|
+
return undefined;
|
|
140
|
+
const parsed = Number(raw);
|
|
141
|
+
if (Number.isNaN(parsed)) {
|
|
142
|
+
throw new Error(`Invalid --${key} value: ${raw}`);
|
|
143
|
+
}
|
|
144
|
+
return parsed;
|
|
145
|
+
}
|
|
146
|
+
export function resolveFormat(flags) {
|
|
147
|
+
if (getBool(flags, "json"))
|
|
148
|
+
return "json";
|
|
149
|
+
if (getBool(flags, "md") || getBool(flags, "markdown"))
|
|
150
|
+
return "md";
|
|
151
|
+
const raw = getString(flags, "format") || "json";
|
|
152
|
+
if (raw === "md" || raw === "markdown")
|
|
153
|
+
return "md";
|
|
154
|
+
return "json";
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Resolve API base URL for legacy commands that pass Flags objects.
|
|
158
|
+
* Delegates to client.ts resolveApiBase with the corrected default base URL.
|
|
159
|
+
*/
|
|
160
|
+
export function resolveApiBase(flags) {
|
|
161
|
+
const flagBase = getString(flags, "base");
|
|
162
|
+
return _resolveApiBase(flagBase);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get API key for legacy commands.
|
|
166
|
+
* Delegates to client.ts getApiKey.
|
|
167
|
+
*/
|
|
168
|
+
export function getApiKey() {
|
|
169
|
+
return _getApiKey();
|
|
170
|
+
}
|
package/dist/utils/client.d.ts
CHANGED
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Provides helper functions for making authenticated API requests.
|
|
5
5
|
* Handles API key resolution and error formatting.
|
|
6
|
+
* Uses @vertaaux/sdk for typed resource access (audits, patches, verification).
|
|
6
7
|
*/
|
|
8
|
+
import { VertaaUX } from "@vertaaux/sdk";
|
|
9
|
+
import type { Audit } from "@vertaaux/sdk";
|
|
7
10
|
import type { VertaauxConfig } from "../config/schema.js";
|
|
11
|
+
export type { Audit as AuditResponse };
|
|
8
12
|
/**
|
|
9
13
|
* Resolve the API base URL from various sources.
|
|
10
14
|
*
|
|
@@ -30,6 +34,20 @@ export declare function getApiKey(configApiKey?: string): string;
|
|
|
30
34
|
* @returns true if API key is available
|
|
31
35
|
*/
|
|
32
36
|
export declare function hasApiKey(config?: VertaauxConfig): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Create a VertaaUX SDK client instance.
|
|
39
|
+
*
|
|
40
|
+
* Provides typed access to SDK resources: audits, patches, verification,
|
|
41
|
+
* quota, engines, webhooks, schedules.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Optional override for base URL and API key
|
|
44
|
+
* @returns Configured VertaaUX client instance
|
|
45
|
+
* @throws Error if no API key is available
|
|
46
|
+
*/
|
|
47
|
+
export declare function createClient(options?: {
|
|
48
|
+
base?: string;
|
|
49
|
+
apiKey?: string;
|
|
50
|
+
}): VertaaUX;
|
|
33
51
|
export interface ApiRequestOptions {
|
|
34
52
|
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
35
53
|
body?: unknown;
|
|
@@ -38,8 +56,11 @@ export interface ApiRequestOptions {
|
|
|
38
56
|
/**
|
|
39
57
|
* Make an authenticated API request.
|
|
40
58
|
*
|
|
59
|
+
* Used for endpoints not covered by typed SDK resources
|
|
60
|
+
* (e.g. /analyze, /cli/ai/*, /sync/*).
|
|
61
|
+
*
|
|
41
62
|
* @param base - API base URL
|
|
42
|
-
* @param path - Request path (e.g., "/
|
|
63
|
+
* @param path - Request path (e.g., "/audits")
|
|
43
64
|
* @param options - Request options (method, body, headers)
|
|
44
65
|
* @param apiKey - API key for authentication
|
|
45
66
|
* @returns Parsed JSON response
|
|
@@ -53,30 +74,20 @@ export declare function apiRequest<T>(base: string, path: string, options: ApiRe
|
|
|
53
74
|
* @returns Promise that resolves after the duration
|
|
54
75
|
*/
|
|
55
76
|
export declare function sleep(ms: number): Promise<void>;
|
|
56
|
-
export interface AuditResponse {
|
|
57
|
-
job_id?: string;
|
|
58
|
-
status?: string;
|
|
59
|
-
url?: string;
|
|
60
|
-
mode?: string;
|
|
61
|
-
progress?: number;
|
|
62
|
-
created_at?: string;
|
|
63
|
-
started_at?: string;
|
|
64
|
-
completed_at?: string;
|
|
65
|
-
scores?: Record<string, unknown>;
|
|
66
|
-
issues?: unknown;
|
|
67
|
-
error?: string;
|
|
68
|
-
}
|
|
69
77
|
/**
|
|
70
78
|
* Wait for an audit to complete, polling at intervals.
|
|
71
79
|
*
|
|
72
|
-
*
|
|
80
|
+
* Accepts either a VertaaUX SDK client (preferred) or the legacy
|
|
81
|
+
* base/apiKey parameters for backward compatibility.
|
|
82
|
+
*
|
|
83
|
+
* @param clientOrBase - VertaaUX SDK client instance OR legacy API base URL
|
|
73
84
|
* @param jobId - Audit job ID
|
|
74
85
|
* @param timeoutMs - Maximum time to wait
|
|
75
86
|
* @param intervalMs - Poll interval
|
|
76
|
-
* @param
|
|
77
|
-
* @param onProgress - Optional callback for progress updates
|
|
87
|
+
* @param apiKeyOrCallback - API key (legacy) OR onProgress callback
|
|
88
|
+
* @param onProgress - Optional callback for progress updates (legacy positional)
|
|
78
89
|
* @returns Completed audit response
|
|
79
90
|
* @throws Error on timeout or failure
|
|
80
91
|
*/
|
|
81
|
-
export declare function waitForAudit(
|
|
92
|
+
export declare function waitForAudit(clientOrBase: VertaaUX | string, jobId: string, timeoutMs: number, intervalMs: number, apiKeyOrCallback?: string | ((progress: number, status: string) => void), onProgress?: (progress: number, status: string) => void): Promise<Audit>;
|
|
82
93
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/utils/client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/utils/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAI3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAG1D,YAAY,EAAE,KAAK,IAAI,aAAa,EAAE,CAAC;AAoCvC;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,CAAC,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM,CAOR;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAQvD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,OAAO,CAE1D;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,QAAQ,CA4BX;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAChC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,CAAC,CAAC,CA+BZ;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,YAAY,CAChC,YAAY,EAAE,QAAQ,GAAG,MAAM,EAC/B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,gBAAgB,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC,EACxE,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,GACtD,OAAO,CAAC,KAAK,CAAC,CA0ChB"}
|
package/dist/utils/client.js
CHANGED
|
@@ -3,8 +3,41 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Provides helper functions for making authenticated API requests.
|
|
5
5
|
* Handles API key resolution and error formatting.
|
|
6
|
+
* Uses @vertaaux/sdk for typed resource access (audits, patches, verification).
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
import { VertaaUX } from "@vertaaux/sdk";
|
|
9
|
+
import { readFileSync, existsSync, lstatSync, statSync } from "fs";
|
|
10
|
+
import { homedir } from "os";
|
|
11
|
+
import { join } from "path";
|
|
12
|
+
const DEFAULT_API_BASE = "https://vertaaux.ai/api/v1";
|
|
13
|
+
/**
|
|
14
|
+
* Read the stored API key from ~/.vertaaux/credentials.json (sync).
|
|
15
|
+
* Returns the accessToken if the file exists and is valid JSON, else undefined.
|
|
16
|
+
*/
|
|
17
|
+
function readStoredApiKey() {
|
|
18
|
+
const credPath = join(homedir(), ".vertaaux", "credentials.json");
|
|
19
|
+
if (!existsSync(credPath))
|
|
20
|
+
return undefined;
|
|
21
|
+
// SECVAL-1: Refuse to read if credentials path is a symlink
|
|
22
|
+
if (lstatSync(credPath).isSymbolicLink()) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
// SECVAL-2: Warn if file permissions are too open (non-Windows only)
|
|
26
|
+
if (process.platform !== "win32") {
|
|
27
|
+
const mode = statSync(credPath).mode;
|
|
28
|
+
if ((mode & 0o077) !== 0) {
|
|
29
|
+
process.stderr.write(`Warning: ${credPath} has overly permissive permissions. ` +
|
|
30
|
+
`Run 'chmod 600 ${credPath}' to fix.\n`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const data = JSON.parse(readFileSync(credPath, "utf-8"));
|
|
35
|
+
return data.accessToken || undefined;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
8
41
|
/**
|
|
9
42
|
* Resolve the API base URL from various sources.
|
|
10
43
|
*
|
|
@@ -29,9 +62,9 @@ export function resolveApiBase(flagBase, configBase) {
|
|
|
29
62
|
* @throws Error if no API key is available
|
|
30
63
|
*/
|
|
31
64
|
export function getApiKey(configApiKey) {
|
|
32
|
-
const key = process.env.VERTAAUX_API_KEY || configApiKey;
|
|
65
|
+
const key = process.env.VERTAAUX_API_KEY || configApiKey || readStoredApiKey();
|
|
33
66
|
if (!key) {
|
|
34
|
-
throw new Error("
|
|
67
|
+
throw new Error("No API key found. Run 'vertaa login' or set VERTAAUX_API_KEY environment variable.");
|
|
35
68
|
}
|
|
36
69
|
return key;
|
|
37
70
|
}
|
|
@@ -42,13 +75,54 @@ export function getApiKey(configApiKey) {
|
|
|
42
75
|
* @returns true if API key is available
|
|
43
76
|
*/
|
|
44
77
|
export function hasApiKey(config) {
|
|
45
|
-
return Boolean(process.env.VERTAAUX_API_KEY || config?.apiKey);
|
|
78
|
+
return Boolean(process.env.VERTAAUX_API_KEY || config?.apiKey || readStoredApiKey());
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a VertaaUX SDK client instance.
|
|
82
|
+
*
|
|
83
|
+
* Provides typed access to SDK resources: audits, patches, verification,
|
|
84
|
+
* quota, engines, webhooks, schedules.
|
|
85
|
+
*
|
|
86
|
+
* @param options - Optional override for base URL and API key
|
|
87
|
+
* @returns Configured VertaaUX client instance
|
|
88
|
+
* @throws Error if no API key is available
|
|
89
|
+
*/
|
|
90
|
+
export function createClient(options) {
|
|
91
|
+
const baseUrl = resolveApiBase(options?.base);
|
|
92
|
+
const apiKey = options?.apiKey ?? getApiKey();
|
|
93
|
+
// The SDK uses `new URL(path, baseUrl)` in buildUrl(), but SDK paths have
|
|
94
|
+
// leading slashes (e.g. "/audit"), which makes new URL treat them as absolute
|
|
95
|
+
// and strips the base path. Work around this by providing a custom fetch that
|
|
96
|
+
// intercepts URLs and reconstructs them with string concatenation.
|
|
97
|
+
const baseFetch = globalThis.fetch;
|
|
98
|
+
const patchedFetch = (input, init) => {
|
|
99
|
+
if (typeof input === "string") {
|
|
100
|
+
// If the URL lost its path prefix, reconstruct it.
|
|
101
|
+
// e.g. "https://vertaaux.ai/audit" → "https://vertaaux.ai/api/v1/audit"
|
|
102
|
+
try {
|
|
103
|
+
const parsed = new URL(input);
|
|
104
|
+
const baseOrigin = new URL(baseUrl).origin;
|
|
105
|
+
if (parsed.origin === baseOrigin && !input.startsWith(baseUrl)) {
|
|
106
|
+
const fixedUrl = baseUrl.replace(/\/$/, "") + parsed.pathname + parsed.search;
|
|
107
|
+
return baseFetch(fixedUrl, init);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// Not a valid URL, pass through
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return baseFetch(input, init);
|
|
115
|
+
};
|
|
116
|
+
return new VertaaUX({ apiKey, baseUrl, fetch: patchedFetch });
|
|
46
117
|
}
|
|
47
118
|
/**
|
|
48
119
|
* Make an authenticated API request.
|
|
49
120
|
*
|
|
121
|
+
* Used for endpoints not covered by typed SDK resources
|
|
122
|
+
* (e.g. /analyze, /cli/ai/*, /sync/*).
|
|
123
|
+
*
|
|
50
124
|
* @param base - API base URL
|
|
51
|
-
* @param path - Request path (e.g., "/
|
|
125
|
+
* @param path - Request path (e.g., "/audits")
|
|
52
126
|
* @param options - Request options (method, body, headers)
|
|
53
127
|
* @param apiKey - API key for authentication
|
|
54
128
|
* @returns Parsed JSON response
|
|
@@ -98,22 +172,38 @@ export function sleep(ms) {
|
|
|
98
172
|
/**
|
|
99
173
|
* Wait for an audit to complete, polling at intervals.
|
|
100
174
|
*
|
|
101
|
-
*
|
|
175
|
+
* Accepts either a VertaaUX SDK client (preferred) or the legacy
|
|
176
|
+
* base/apiKey parameters for backward compatibility.
|
|
177
|
+
*
|
|
178
|
+
* @param clientOrBase - VertaaUX SDK client instance OR legacy API base URL
|
|
102
179
|
* @param jobId - Audit job ID
|
|
103
180
|
* @param timeoutMs - Maximum time to wait
|
|
104
181
|
* @param intervalMs - Poll interval
|
|
105
|
-
* @param
|
|
106
|
-
* @param onProgress - Optional callback for progress updates
|
|
182
|
+
* @param apiKeyOrCallback - API key (legacy) OR onProgress callback
|
|
183
|
+
* @param onProgress - Optional callback for progress updates (legacy positional)
|
|
107
184
|
* @returns Completed audit response
|
|
108
185
|
* @throws Error on timeout or failure
|
|
109
186
|
*/
|
|
110
|
-
export async function waitForAudit(
|
|
187
|
+
export async function waitForAudit(clientOrBase, jobId, timeoutMs, intervalMs, apiKeyOrCallback, onProgress) {
|
|
111
188
|
const start = Date.now();
|
|
189
|
+
// Determine calling convention
|
|
190
|
+
const usingClient = clientOrBase instanceof VertaaUX;
|
|
191
|
+
const progressCallback = usingClient
|
|
192
|
+
? (typeof apiKeyOrCallback === "function" ? apiKeyOrCallback : onProgress)
|
|
193
|
+
: (typeof apiKeyOrCallback === "function" ? apiKeyOrCallback : onProgress);
|
|
112
194
|
while (true) {
|
|
113
|
-
|
|
195
|
+
let status;
|
|
196
|
+
if (usingClient) {
|
|
197
|
+
status = await clientOrBase.audits.retrieve(jobId);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
const base = clientOrBase;
|
|
201
|
+
const apiKey = typeof apiKeyOrCallback === "string" ? apiKeyOrCallback : "";
|
|
202
|
+
status = await apiRequest(base, `/audits/${jobId}`, { method: "GET" }, apiKey);
|
|
203
|
+
}
|
|
114
204
|
// Call progress callback if provided
|
|
115
|
-
if (
|
|
116
|
-
|
|
205
|
+
if (progressCallback && typeof status.progress === "number") {
|
|
206
|
+
progressCallback(status.progress, status.status || "unknown");
|
|
117
207
|
}
|
|
118
208
|
if (status.status === "completed")
|
|
119
209
|
return status;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output formatting utilities for the VertaaUX CLI legacy commands.
|
|
3
|
+
* Provides markdown and JSON formatting functions for audit/fix/verify results.
|
|
4
|
+
*/
|
|
5
|
+
import type { IssueLike, AuditResponse, PatchResponse, BatchPatchResult, VerifyResponse } from "../types.js";
|
|
6
|
+
import type { AuditScores } from "@vertaaux/sdk";
|
|
7
|
+
export type ScoresLike = AuditScores | Record<string, unknown> | undefined;
|
|
8
|
+
export declare function normalizeIssues(issues: unknown): IssueLike[];
|
|
9
|
+
export declare function toNumber(value: unknown): number | null;
|
|
10
|
+
export declare function getOverallScore(scores?: ScoresLike): number | null;
|
|
11
|
+
export declare function getCategoryScore(scores: ScoresLike, key: string): number | null;
|
|
12
|
+
export declare function formatScoresTable(scores: ScoresLike): string;
|
|
13
|
+
export declare function formatIssuesList(issues: IssueLike[], limit?: number): string;
|
|
14
|
+
export declare function formatAuditMarkdown(result: AuditResponse): string;
|
|
15
|
+
export declare function formatA11yMarkdown(result: AuditResponse): string;
|
|
16
|
+
export declare function formatCompareMarkdown(compare: {
|
|
17
|
+
urlA: string;
|
|
18
|
+
urlB: string;
|
|
19
|
+
jobA: string;
|
|
20
|
+
jobB: string;
|
|
21
|
+
overallA: number | null;
|
|
22
|
+
overallB: number | null;
|
|
23
|
+
delta: number | null;
|
|
24
|
+
categoryDeltas: Record<string, {
|
|
25
|
+
a: number | null;
|
|
26
|
+
b: number | null;
|
|
27
|
+
delta: number | null;
|
|
28
|
+
}>;
|
|
29
|
+
issuesA: number;
|
|
30
|
+
issuesB: number;
|
|
31
|
+
}): string;
|
|
32
|
+
export declare function formatExplainMarkdown(issue: IssueLike): string;
|
|
33
|
+
export declare function formatPatchMarkdown(patch: PatchResponse["patch"]): string;
|
|
34
|
+
export declare function formatVerifyMarkdown(result: VerifyResponse): string;
|
|
35
|
+
export declare function isAutoFixable(issueType: string): boolean;
|
|
36
|
+
export declare function formatBatchMarkdown(results: BatchPatchResult): string;
|
|
37
|
+
export declare function printOutput(format: "json" | "md", data: unknown, markdown?: string): void;
|
|
38
|
+
//# sourceMappingURL=formatters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../src/utils/formatters.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,cAAc,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAKjD,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;AAM3E,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,EAAE,CAO5D;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAGtD;AAED,wBAAgB,eAAe,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAWlE;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,MAAM,GACV,MAAM,GAAG,IAAI,CAGf;AAMD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAW5D;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,KAAK,SAAI,GAAG,MAAM,CAWvE;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAsBjE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAuBhE;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IAC7F,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG,MAAM,CA8BT;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAoB9D;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,MAAM,CAuBzE;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CA8BnE;AAwBD,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAGxD;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CA6BrE;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,QAOlF"}
|