@vertaaux/cli 0.4.0 → 0.5.1

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.
Files changed (248) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/MIGRATION.md +239 -0
  3. package/README.md +62 -17
  4. package/dist/app/interactive-app.d.ts +103 -0
  5. package/dist/app/interactive-app.d.ts.map +1 -0
  6. package/dist/app/interactive-app.js +328 -0
  7. package/dist/app/layout/canvas.d.ts +23 -0
  8. package/dist/app/layout/canvas.d.ts.map +1 -0
  9. package/dist/app/layout/canvas.js +36 -0
  10. package/dist/app/layout/footer.d.ts +31 -0
  11. package/dist/app/layout/footer.d.ts.map +1 -0
  12. package/dist/app/layout/footer.js +41 -0
  13. package/dist/app/layout/header.d.ts +20 -0
  14. package/dist/app/layout/header.d.ts.map +1 -0
  15. package/dist/app/layout/header.js +27 -0
  16. package/dist/app/menu/categories.d.ts +20 -0
  17. package/dist/app/menu/categories.d.ts.map +1 -0
  18. package/dist/app/menu/categories.js +166 -0
  19. package/dist/app/menu/filter.d.ts +17 -0
  20. package/dist/app/menu/filter.d.ts.map +1 -0
  21. package/dist/app/menu/filter.js +33 -0
  22. package/dist/app/menu/menu-view.d.ts +35 -0
  23. package/dist/app/menu/menu-view.d.ts.map +1 -0
  24. package/dist/app/menu/menu-view.js +230 -0
  25. package/dist/app/menu/recent.d.ts +24 -0
  26. package/dist/app/menu/recent.d.ts.map +1 -0
  27. package/dist/app/menu/recent.js +49 -0
  28. package/dist/app/types.d.ts +43 -0
  29. package/dist/app/types.d.ts.map +1 -0
  30. package/dist/app/types.js +7 -0
  31. package/dist/app/views/command-runner.d.ts +36 -0
  32. package/dist/app/views/command-runner.d.ts.map +1 -0
  33. package/dist/app/views/command-runner.js +415 -0
  34. package/dist/app/views/help-overlay.d.ts +21 -0
  35. package/dist/app/views/help-overlay.d.ts.map +1 -0
  36. package/dist/app/views/help-overlay.js +46 -0
  37. package/dist/auth/ci-token.d.ts +8 -2
  38. package/dist/auth/ci-token.d.ts.map +1 -1
  39. package/dist/auth/ci-token.js +15 -30
  40. package/dist/auth/device-flow.d.ts +2 -1
  41. package/dist/auth/device-flow.d.ts.map +1 -1
  42. package/dist/auth/device-flow.js +13 -10
  43. package/dist/auth/token-store.d.ts.map +1 -1
  44. package/dist/auth/token-store.js +12 -2
  45. package/dist/baseline/diff.d.ts +2 -2
  46. package/dist/baseline/diff.d.ts.map +1 -1
  47. package/dist/baseline/diff.js +15 -34
  48. package/dist/commands/a11y.d.ts +11 -0
  49. package/dist/commands/a11y.d.ts.map +1 -0
  50. package/dist/commands/a11y.js +149 -0
  51. package/dist/commands/audit/artifacts.d.ts +27 -0
  52. package/dist/commands/audit/artifacts.d.ts.map +1 -0
  53. package/dist/commands/audit/artifacts.js +158 -0
  54. package/dist/commands/audit/ci-detection.d.ts +18 -0
  55. package/dist/commands/audit/ci-detection.d.ts.map +1 -0
  56. package/dist/commands/audit/ci-detection.js +71 -0
  57. package/dist/commands/audit/explain.d.ts +11 -0
  58. package/dist/commands/audit/explain.d.ts.map +1 -0
  59. package/dist/commands/audit/explain.js +45 -0
  60. package/dist/commands/audit/filters.d.ts +17 -0
  61. package/dist/commands/audit/filters.d.ts.map +1 -0
  62. package/dist/commands/audit/filters.js +40 -0
  63. package/dist/commands/audit/index.d.ts +18 -0
  64. package/dist/commands/audit/index.d.ts.map +1 -0
  65. package/dist/commands/audit/index.js +589 -0
  66. package/dist/commands/audit/output.d.ts +32 -0
  67. package/dist/commands/audit/output.d.ts.map +1 -0
  68. package/dist/commands/audit/output.js +129 -0
  69. package/dist/commands/audit/policy.d.ts +27 -0
  70. package/dist/commands/audit/policy.d.ts.map +1 -0
  71. package/dist/commands/audit/policy.js +147 -0
  72. package/dist/commands/audit/scoring.d.ts +23 -0
  73. package/dist/commands/audit/scoring.d.ts.map +1 -0
  74. package/dist/commands/audit/scoring.js +70 -0
  75. package/dist/commands/audit/types.d.ts +89 -0
  76. package/dist/commands/audit/types.d.ts.map +1 -0
  77. package/dist/commands/audit/types.js +8 -0
  78. package/dist/commands/audit.d.ts +2 -60
  79. package/dist/commands/audit.d.ts.map +1 -1
  80. package/dist/commands/audit.js +2 -1097
  81. package/dist/commands/baseline.d.ts +2 -0
  82. package/dist/commands/baseline.d.ts.map +1 -1
  83. package/dist/commands/baseline.js +221 -123
  84. package/dist/commands/comment.d.ts +22 -0
  85. package/dist/commands/comment.d.ts.map +1 -1
  86. package/dist/commands/comment.js +127 -62
  87. package/dist/commands/compare.d.ts +17 -0
  88. package/dist/commands/compare.d.ts.map +1 -1
  89. package/dist/commands/compare.js +288 -181
  90. package/dist/commands/diff.d.ts +7 -0
  91. package/dist/commands/diff.d.ts.map +1 -1
  92. package/dist/commands/diff.js +181 -143
  93. package/dist/commands/doc.d.ts +10 -0
  94. package/dist/commands/doc.d.ts.map +1 -1
  95. package/dist/commands/doc.js +135 -77
  96. package/dist/commands/doctor.d.ts +2 -0
  97. package/dist/commands/doctor.d.ts.map +1 -1
  98. package/dist/commands/doctor.js +166 -19
  99. package/dist/commands/download.d.ts +10 -0
  100. package/dist/commands/download.d.ts.map +1 -1
  101. package/dist/commands/download.js +169 -112
  102. package/dist/commands/explain.d.ts +5 -0
  103. package/dist/commands/explain.d.ts.map +1 -1
  104. package/dist/commands/explain.js +242 -156
  105. package/dist/commands/fix-all.d.ts +25 -0
  106. package/dist/commands/fix-all.d.ts.map +1 -0
  107. package/dist/commands/fix-all.js +206 -0
  108. package/dist/commands/fix-plan.d.ts +9 -0
  109. package/dist/commands/fix-plan.d.ts.map +1 -1
  110. package/dist/commands/fix-plan.js +154 -90
  111. package/dist/commands/fix.d.ts +17 -0
  112. package/dist/commands/fix.d.ts.map +1 -0
  113. package/dist/commands/fix.js +111 -0
  114. package/dist/commands/init.d.ts +11 -0
  115. package/dist/commands/init.d.ts.map +1 -1
  116. package/dist/commands/init.js +94 -42
  117. package/dist/commands/login.d.ts +18 -0
  118. package/dist/commands/login.d.ts.map +1 -1
  119. package/dist/commands/login.js +263 -92
  120. package/dist/commands/patch-review.d.ts +11 -0
  121. package/dist/commands/patch-review.d.ts.map +1 -1
  122. package/dist/commands/patch-review.js +160 -98
  123. package/dist/commands/policy.d.ts +31 -0
  124. package/dist/commands/policy.d.ts.map +1 -1
  125. package/dist/commands/policy.js +270 -125
  126. package/dist/commands/release-notes.d.ts +10 -0
  127. package/dist/commands/release-notes.d.ts.map +1 -1
  128. package/dist/commands/release-notes.js +128 -74
  129. package/dist/commands/scan.d.ts +13 -0
  130. package/dist/commands/scan.d.ts.map +1 -0
  131. package/dist/commands/scan.js +133 -0
  132. package/dist/commands/status.d.ts +9 -0
  133. package/dist/commands/status.d.ts.map +1 -0
  134. package/dist/commands/status.js +81 -0
  135. package/dist/commands/suggest.d.ts +10 -0
  136. package/dist/commands/suggest.d.ts.map +1 -1
  137. package/dist/commands/suggest.js +180 -83
  138. package/dist/commands/triage.d.ts +35 -0
  139. package/dist/commands/triage.d.ts.map +1 -1
  140. package/dist/commands/triage.js +207 -82
  141. package/dist/commands/upload.d.ts +9 -0
  142. package/dist/commands/upload.d.ts.map +1 -1
  143. package/dist/commands/upload.js +140 -101
  144. package/dist/commands/verify.d.ts +13 -0
  145. package/dist/commands/verify.d.ts.map +1 -0
  146. package/dist/commands/verify.js +118 -0
  147. package/dist/config/schema.d.ts +4 -0
  148. package/dist/config/schema.d.ts.map +1 -1
  149. package/dist/index.d.ts +3 -2
  150. package/dist/index.d.ts.map +1 -1
  151. package/dist/index.js +127 -991
  152. package/dist/interactive/fix-wizard.d.ts +3 -0
  153. package/dist/interactive/fix-wizard.d.ts.map +1 -1
  154. package/dist/interactive/fix-wizard.js +130 -112
  155. package/dist/interactive/init-wizard.d.ts +3 -1
  156. package/dist/interactive/init-wizard.d.ts.map +1 -1
  157. package/dist/interactive/init-wizard.js +207 -138
  158. package/dist/interactive/prompts.d.ts +7 -3
  159. package/dist/interactive/prompts.d.ts.map +1 -1
  160. package/dist/interactive/prompts.js +44 -23
  161. package/dist/output/envelope.d.ts +9 -0
  162. package/dist/output/envelope.d.ts.map +1 -1
  163. package/dist/output/envelope.js +37 -3
  164. package/dist/output/factory.d.ts +2 -1
  165. package/dist/output/factory.d.ts.map +1 -1
  166. package/dist/output/html.d.ts +2 -1
  167. package/dist/output/html.d.ts.map +1 -1
  168. package/dist/output/html.js +3 -2
  169. package/dist/output/human.d.ts +2 -1
  170. package/dist/output/human.d.ts.map +1 -1
  171. package/dist/output/human.js +3 -2
  172. package/dist/output/json.d.ts +2 -1
  173. package/dist/output/json.d.ts.map +1 -1
  174. package/dist/output/junit.d.ts +2 -1
  175. package/dist/output/junit.d.ts.map +1 -1
  176. package/dist/output/sarif.d.ts +2 -1
  177. package/dist/output/sarif.d.ts.map +1 -1
  178. package/dist/policy/schema.d.ts +137 -0
  179. package/dist/policy/schema.d.ts.map +1 -1
  180. package/dist/policy/schema.js +107 -0
  181. package/dist/prompts/command-catalog.js +9 -9
  182. package/dist/types.d.ts +74 -0
  183. package/dist/types.d.ts.map +1 -0
  184. package/dist/types.js +5 -0
  185. package/dist/ui/banner.d.ts +34 -0
  186. package/dist/ui/banner.d.ts.map +1 -1
  187. package/dist/ui/banner.js +97 -5
  188. package/dist/ui/diagnostics.d.ts +9 -4
  189. package/dist/ui/diagnostics.d.ts.map +1 -1
  190. package/dist/ui/diagnostics.js +32 -82
  191. package/dist/ui/strings.d.ts +373 -0
  192. package/dist/ui/strings.d.ts.map +1 -0
  193. package/dist/ui/strings.js +499 -0
  194. package/dist/ui/table.d.ts +0 -2
  195. package/dist/ui/table.d.ts.map +1 -1
  196. package/dist/ui/table.js +3 -4
  197. package/dist/utils/api-client.d.ts +46 -0
  198. package/dist/utils/api-client.d.ts.map +1 -0
  199. package/dist/utils/api-client.js +170 -0
  200. package/dist/utils/client.d.ts +29 -18
  201. package/dist/utils/client.d.ts.map +1 -1
  202. package/dist/utils/client.js +104 -12
  203. package/dist/utils/formatters.d.ts +38 -0
  204. package/dist/utils/formatters.d.ts.map +1 -0
  205. package/dist/utils/formatters.js +277 -0
  206. package/dist/utils/root-args.d.ts +12 -0
  207. package/dist/utils/root-args.d.ts.map +1 -0
  208. package/dist/utils/root-args.js +44 -0
  209. package/dist/utils/stdin.d.ts +7 -0
  210. package/dist/utils/stdin.d.ts.map +1 -1
  211. package/dist/utils/stdin.js +32 -2
  212. package/dist/utils/url-classify.d.ts.map +1 -1
  213. package/dist/utils/url-classify.js +24 -3
  214. package/node_modules/@vertaaux/tui/dist/index.cjs +1216 -27
  215. package/node_modules/@vertaaux/tui/dist/index.cjs.map +1 -1
  216. package/node_modules/@vertaaux/tui/dist/index.d.cts +361 -4
  217. package/node_modules/@vertaaux/tui/dist/index.d.ts +361 -4
  218. package/node_modules/@vertaaux/tui/dist/index.js +1189 -27
  219. package/node_modules/@vertaaux/tui/dist/index.js.map +1 -1
  220. package/node_modules/@vertaaux/tui/package.json +2 -3
  221. package/node_modules/chalk/license +9 -0
  222. package/node_modules/chalk/package.json +83 -0
  223. package/node_modules/chalk/readme.md +297 -0
  224. package/node_modules/chalk/source/index.d.ts +325 -0
  225. package/node_modules/chalk/source/index.js +225 -0
  226. package/node_modules/chalk/source/utilities.js +33 -0
  227. package/node_modules/chalk/source/vendor/ansi-styles/index.d.ts +236 -0
  228. package/node_modules/chalk/source/vendor/ansi-styles/index.js +223 -0
  229. package/node_modules/chalk/source/vendor/supports-color/browser.d.ts +1 -0
  230. package/node_modules/chalk/source/vendor/supports-color/browser.js +34 -0
  231. package/node_modules/chalk/source/vendor/supports-color/index.d.ts +55 -0
  232. package/node_modules/chalk/source/vendor/supports-color/index.js +190 -0
  233. package/package.json +20 -5
  234. package/dist/commands/client.d.ts +0 -14
  235. package/dist/commands/client.d.ts.map +0 -1
  236. package/dist/commands/client.js +0 -362
  237. package/dist/commands/drift.d.ts +0 -15
  238. package/dist/commands/drift.d.ts.map +0 -1
  239. package/dist/commands/drift.js +0 -309
  240. package/dist/commands/protect.d.ts +0 -16
  241. package/dist/commands/protect.d.ts.map +0 -1
  242. package/dist/commands/protect.js +0 -323
  243. package/dist/commands/report.d.ts +0 -15
  244. package/dist/commands/report.d.ts.map +0 -1
  245. package/dist/commands/report.js +0 -214
  246. package/dist/policy/sync.d.ts +0 -67
  247. package/dist/policy/sync.d.ts.map +0 -1
  248. 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
+ }
@@ -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., "/audit")
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
- * @param base - API base URL
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 apiKey - API key for authentication
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(base: string, jobId: string, timeoutMs: number, intervalMs: number, apiKey: string, onProgress?: (progress: number, status: string) => void): Promise<AuditResponse>;
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;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAI1D;;;;;;;;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,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;;;;;;;;;GASG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAChC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,C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D,OAAO,CAAC,KAAK,CAAC,CA0ChB"}
@@ -3,8 +3,42 @@
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
- const DEFAULT_API_BASE = "https://vertaaux.ai/v1";
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
+ const NO_API_KEY_MESSAGE = "No API key found. Run 'vertaa login' or set VERTAAUX_API_KEY environment variable.";
14
+ /**
15
+ * Read the stored API key from ~/.vertaaux/credentials.json (sync).
16
+ * Returns the accessToken if the file exists and is valid JSON, else undefined.
17
+ */
18
+ function readStoredApiKey() {
19
+ const credPath = join(homedir(), ".vertaaux", "credentials.json");
20
+ if (!existsSync(credPath))
21
+ return undefined;
22
+ // SECVAL-1: Refuse to read if credentials path is a symlink
23
+ if (lstatSync(credPath).isSymbolicLink()) {
24
+ return undefined;
25
+ }
26
+ // SECVAL-2: Warn if file permissions are too open (non-Windows only)
27
+ if (process.platform !== "win32") {
28
+ const mode = statSync(credPath).mode;
29
+ if ((mode & 0o077) !== 0) {
30
+ process.stderr.write(`Warning: ${credPath} has overly permissive permissions. ` +
31
+ `Run 'chmod 600 ${credPath}' to fix.\n`);
32
+ }
33
+ }
34
+ try {
35
+ const data = JSON.parse(readFileSync(credPath, "utf-8"));
36
+ return data.accessToken || undefined;
37
+ }
38
+ catch {
39
+ return undefined;
40
+ }
41
+ }
8
42
  /**
9
43
  * Resolve the API base URL from various sources.
10
44
  *
@@ -21,6 +55,16 @@ export function resolveApiBase(flagBase, configBase) {
21
55
  DEFAULT_API_BASE;
22
56
  return raw.replace(/\/$/, "");
23
57
  }
58
+ function requireNonEmptyApiKey(candidate) {
59
+ if (candidate === undefined) {
60
+ return undefined;
61
+ }
62
+ const trimmed = candidate.trim();
63
+ if (!trimmed) {
64
+ throw new Error(NO_API_KEY_MESSAGE);
65
+ }
66
+ return trimmed;
67
+ }
24
68
  /**
25
69
  * Get API key from environment or config.
26
70
  *
@@ -29,9 +73,17 @@ export function resolveApiBase(flagBase, configBase) {
29
73
  * @throws Error if no API key is available
30
74
  */
31
75
  export function getApiKey(configApiKey) {
32
- const key = process.env.VERTAAUX_API_KEY || configApiKey;
76
+ if (Object.prototype.hasOwnProperty.call(process.env, "VERTAAUX_API_KEY")) {
77
+ const envKey = requireNonEmptyApiKey(process.env.VERTAAUX_API_KEY);
78
+ if (envKey) {
79
+ return envKey;
80
+ }
81
+ throw new Error(NO_API_KEY_MESSAGE);
82
+ }
83
+ const configKey = requireNonEmptyApiKey(configApiKey);
84
+ const key = configKey || readStoredApiKey();
33
85
  if (!key) {
34
- throw new Error("VERTAAUX_API_KEY is required. Set it via environment variable or config file.");
86
+ throw new Error(NO_API_KEY_MESSAGE);
35
87
  }
36
88
  return key;
37
89
  }
@@ -42,13 +94,37 @@ export function getApiKey(configApiKey) {
42
94
  * @returns true if API key is available
43
95
  */
44
96
  export function hasApiKey(config) {
45
- return Boolean(process.env.VERTAAUX_API_KEY || config?.apiKey);
97
+ if (Object.prototype.hasOwnProperty.call(process.env, "VERTAAUX_API_KEY")) {
98
+ return Boolean(process.env.VERTAAUX_API_KEY?.trim());
99
+ }
100
+ if (config?.apiKey !== undefined) {
101
+ return Boolean(config.apiKey.trim());
102
+ }
103
+ return Boolean(readStoredApiKey());
104
+ }
105
+ /**
106
+ * Create a VertaaUX SDK client instance.
107
+ *
108
+ * Provides typed access to SDK resources: audits, patches, verification,
109
+ * quota, engines, webhooks, schedules.
110
+ *
111
+ * @param options - Optional override for base URL and API key
112
+ * @returns Configured VertaaUX client instance
113
+ * @throws Error if no API key is available
114
+ */
115
+ export function createClient(options) {
116
+ const baseUrl = resolveApiBase(options?.base);
117
+ const apiKey = requireNonEmptyApiKey(options?.apiKey) ?? getApiKey();
118
+ return new VertaaUX({ apiKey, baseUrl });
46
119
  }
47
120
  /**
48
121
  * Make an authenticated API request.
49
122
  *
123
+ * Used for endpoints not covered by typed SDK resources
124
+ * (e.g. /analyze, /cli/ai/*, /sync/*).
125
+ *
50
126
  * @param base - API base URL
51
- * @param path - Request path (e.g., "/audit")
127
+ * @param path - Request path (e.g., "/audits")
52
128
  * @param options - Request options (method, body, headers)
53
129
  * @param apiKey - API key for authentication
54
130
  * @returns Parsed JSON response
@@ -98,22 +174,38 @@ export function sleep(ms) {
98
174
  /**
99
175
  * Wait for an audit to complete, polling at intervals.
100
176
  *
101
- * @param base - API base URL
177
+ * Accepts either a VertaaUX SDK client (preferred) or the legacy
178
+ * base/apiKey parameters for backward compatibility.
179
+ *
180
+ * @param clientOrBase - VertaaUX SDK client instance OR legacy API base URL
102
181
  * @param jobId - Audit job ID
103
182
  * @param timeoutMs - Maximum time to wait
104
183
  * @param intervalMs - Poll interval
105
- * @param apiKey - API key for authentication
106
- * @param onProgress - Optional callback for progress updates
184
+ * @param apiKeyOrCallback - API key (legacy) OR onProgress callback
185
+ * @param onProgress - Optional callback for progress updates (legacy positional)
107
186
  * @returns Completed audit response
108
187
  * @throws Error on timeout or failure
109
188
  */
110
- export async function waitForAudit(base, jobId, timeoutMs, intervalMs, apiKey, onProgress) {
189
+ export async function waitForAudit(clientOrBase, jobId, timeoutMs, intervalMs, apiKeyOrCallback, onProgress) {
111
190
  const start = Date.now();
191
+ // Determine calling convention
192
+ const usingClient = clientOrBase instanceof VertaaUX;
193
+ const progressCallback = usingClient
194
+ ? (typeof apiKeyOrCallback === "function" ? apiKeyOrCallback : onProgress)
195
+ : (typeof apiKeyOrCallback === "function" ? apiKeyOrCallback : onProgress);
112
196
  while (true) {
113
- const status = await apiRequest(base, `/audit/${jobId}`, { method: "GET" }, apiKey);
197
+ let status;
198
+ if (usingClient) {
199
+ status = await clientOrBase.audits.retrieve(jobId);
200
+ }
201
+ else {
202
+ const base = clientOrBase;
203
+ const apiKey = typeof apiKeyOrCallback === "string" ? apiKeyOrCallback : "";
204
+ status = await apiRequest(base, `/audits/${jobId}`, { method: "GET" }, apiKey);
205
+ }
114
206
  // Call progress callback if provided
115
- if (onProgress && typeof status.progress === "number") {
116
- onProgress(status.progress, status.status || "unknown");
207
+ if (progressCallback && typeof status.progress === "number") {
208
+ progressCallback(status.progress, status.status || "unknown");
117
209
  }
118
210
  if (status.status === "completed")
119
211
  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,CAA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