@dataparade/cli 0.0.20 → 0.0.21

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.
@@ -0,0 +1,386 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ScanProgressRenderer = void 0;
7
+ exports.formatPreviewLink = formatPreviewLink;
8
+ exports.formatAiStepResult = formatAiStepResult;
9
+ exports.formatOutputPath = formatOutputPath;
10
+ exports.formatProjectLabel = formatProjectLabel;
11
+ exports.createScanProgressRenderer = createScanProgressRenderer;
12
+ exports.stripAnsi = stripAnsi;
13
+ exports.hasAnsi = hasAnsi;
14
+ const node_path_1 = __importDefault(require("node:path"));
15
+ const node_util_1 = require("node:util");
16
+ const brand_1 = require("./brand");
17
+ const teaching_lines_1 = require("./teaching-lines");
18
+ async function loadClack() {
19
+ const importEsm = new Function('specifier', 'return import(specifier)');
20
+ const mod = await importEsm('@clack/prompts');
21
+ if (typeof mod.intro === 'function')
22
+ return mod;
23
+ if (mod.default && typeof mod.default.intro === 'function')
24
+ return mod.default;
25
+ return mod;
26
+ }
27
+ // ESC [ … m — built without a literal control char so eslint no-control-regex is happy.
28
+ const ANSI_PATTERN = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, 'g');
29
+ const STEP_LABELS = {
30
+ scanning_files: 'Reading your project files',
31
+ analyzing: 'Getting a feel for the codebase',
32
+ detecting_frameworks: 'Looking for APIs and routes',
33
+ mapping_data_stores: 'Looking for databases',
34
+ finding_outbound: 'Checking who you call outside',
35
+ ai_enrichment: 'Filling in details with AI',
36
+ };
37
+ function envNoColor(env = process.env) {
38
+ const value = env.NO_COLOR;
39
+ return typeof value === 'string' && value.length > 0;
40
+ }
41
+ function paint(enabled, style, text) {
42
+ if (!enabled)
43
+ return text;
44
+ return (0, node_util_1.styleText)(style, text);
45
+ }
46
+ /**
47
+ * Make the preview URL stand out in the next-step block.
48
+ * Uses explicit CSI sequences so our colorEnabled flag wins even when
49
+ * process.env.NO_COLOR would make util.styleText a no-op.
50
+ */
51
+ function formatPreviewLink(url, colorEnabled) {
52
+ if (!colorEnabled) {
53
+ return url;
54
+ }
55
+ const esc = String.fromCharCode(27);
56
+ // Color only: terminals already underline links on hover.
57
+ return `${esc}[36m${url}${esc}[39m`;
58
+ }
59
+ function formatAiStepResult(result) {
60
+ const applied = result.proposalsApplied;
61
+ if (applied <= 0)
62
+ return 'Nothing new to add from AI';
63
+ return applied === 1
64
+ ? 'Filled in 1 detail from your code'
65
+ : `Filled in ${applied} details from your code`;
66
+ }
67
+ /** Output path relative to cwd when it lives below it, otherwise the ~ form. */
68
+ function formatOutputPath(outputPath) {
69
+ const relative = node_path_1.default.relative(process.cwd(), outputPath);
70
+ if (relative && !relative.startsWith('..') && !node_path_1.default.isAbsolute(relative)) {
71
+ return `./${relative}`;
72
+ }
73
+ return formatProjectLabel(outputPath);
74
+ }
75
+ /** Prefer a short, human path in the header (home → ~). */
76
+ function formatProjectLabel(projectPath) {
77
+ const home = process.env.HOME?.trim();
78
+ if (home && projectPath.startsWith(`${home}/`)) {
79
+ return `~${projectPath.slice(home.length)}`;
80
+ }
81
+ return projectPath;
82
+ }
83
+ /**
84
+ * Staged scan progress for TTY (Clack) and plain logs for non-TTY / NO_COLOR.
85
+ */
86
+ class ScanProgressRenderer {
87
+ constructor(options, clack) {
88
+ this.started = false;
89
+ this.recognitionHandled = false;
90
+ this.activeStep = null;
91
+ this.spinner = null;
92
+ this.completedSteps = new Set();
93
+ this.teachingSummaryLines = [];
94
+ this.clack = clack;
95
+ this.isTTY = options.isTTY;
96
+ // Prefer explicit option over env (so tests can force color on/off).
97
+ this.noColor =
98
+ options.noColor !== undefined ? options.noColor : envNoColor();
99
+ this.projectLabel = options.projectLabel
100
+ ? formatProjectLabel(options.projectLabel)
101
+ : undefined;
102
+ this.version = options.version;
103
+ this.columns = options.columns;
104
+ this.colorDepth = options.colorDepth;
105
+ this.writeLine =
106
+ options.writeLine ??
107
+ ((line) => {
108
+ console.log(line);
109
+ });
110
+ // Clack for interactive TTY without NO_COLOR. Plain logs otherwise.
111
+ this.useClack = this.isTTY && !this.noColor;
112
+ this.colorEnabled = this.useClack;
113
+ }
114
+ /** Test helper: true when Clack chrome is active. */
115
+ get usesClackChrome() {
116
+ return this.useClack;
117
+ }
118
+ start() {
119
+ if (this.started)
120
+ return;
121
+ this.started = true;
122
+ const where = this.projectLabel
123
+ ? `Let's scan ${this.projectLabel}`
124
+ : "Let's scan your project";
125
+ // Figlet only on a real terminal; CI logs get a single header line.
126
+ const header = (0, brand_1.renderBrandHeader)({
127
+ version: this.version,
128
+ color: this.colorEnabled,
129
+ colorDepth: this.colorDepth,
130
+ columns: this.columns,
131
+ showLogo: this.isTTY,
132
+ });
133
+ if (this.useClack) {
134
+ this.writeLine('');
135
+ for (const line of header)
136
+ this.writeLine(line);
137
+ this.writeLine('');
138
+ this.prompts().intro(where);
139
+ }
140
+ else {
141
+ for (const line of header)
142
+ this.writePlain(line);
143
+ this.writePlain('────────────────');
144
+ this.writePlain(where);
145
+ }
146
+ }
147
+ onProgress(progress) {
148
+ this.start();
149
+ switch (progress.phase) {
150
+ case 'ingest':
151
+ this.transitionTo('scanning_files');
152
+ break;
153
+ case 'analyze':
154
+ this.transitionTo('analyzing');
155
+ break;
156
+ case 'classify':
157
+ if (!this.recognitionHandled) {
158
+ this.transitionTo('analyzing');
159
+ }
160
+ break;
161
+ case 'ai_enrichment':
162
+ this.transitionTo('ai_enrichment');
163
+ break;
164
+ case 'data_flow':
165
+ case 'output':
166
+ case 'idle':
167
+ default:
168
+ break;
169
+ }
170
+ }
171
+ onRecognition(payload) {
172
+ if (this.recognitionHandled)
173
+ return;
174
+ this.recognitionHandled = true;
175
+ this.start();
176
+ const groups = (0, teaching_lines_1.buildTeachingLineGroups)(payload.findings, payload.components);
177
+ this.teachingSummaryLines = (0, teaching_lines_1.flattenTeachingLines)(groups);
178
+ this.completeActiveStep();
179
+ this.runTeachingStep('detecting_frameworks', groups.routes.map((line) => line));
180
+ this.runTeachingStep('mapping_data_stores', groups.stores.map((line) => line));
181
+ this.runTeachingStep('finding_outbound', groups.outbound.map((line) => line));
182
+ if (this.teachingSummaryLines.length > 0) {
183
+ const body = this.teachingSummaryLines
184
+ .map((line) => `• ${line}`)
185
+ .join('\n');
186
+ if (this.useClack) {
187
+ this.prompts().note(body, "Here's what stood out");
188
+ }
189
+ else {
190
+ this.writePlain("Here's what stood out");
191
+ for (const line of this.teachingSummaryLines) {
192
+ this.writePlain(` • ${line}`);
193
+ }
194
+ }
195
+ }
196
+ }
197
+ /** Close the AI step with one plain-language result line. */
198
+ onAiResult(result) {
199
+ if (this.activeStep !== 'ai_enrichment')
200
+ return;
201
+ this.completeActiveStep();
202
+ const line = formatAiStepResult(result);
203
+ if (this.useClack) {
204
+ this.prompts().log.message(line);
205
+ }
206
+ else {
207
+ this.writePlain(` · ${line}`);
208
+ }
209
+ }
210
+ onWroteDataflow(outputPath) {
211
+ this.start();
212
+ this.completeActiveStep();
213
+ const label = 'Saved your data-flow map';
214
+ if (this.useClack) {
215
+ // The `[scan] dataflow.json written to` machine line is skipped in TTY,
216
+ // so the path lives here.
217
+ const where = outputPath
218
+ ? `\n${paint(this.colorEnabled, 'dim', formatOutputPath(outputPath))}`
219
+ : '';
220
+ this.prompts().log.success(`${label}${where}`);
221
+ }
222
+ else {
223
+ this.writePlain(`✓ ${label}`);
224
+ }
225
+ }
226
+ /** Store preview URL for the "What to do next" note. Machine line stays in upload. */
227
+ onPreviewUrl(previewUrl, notice) {
228
+ this.previewUrl = previewUrl;
229
+ this.previewNotice = notice;
230
+ }
231
+ /**
232
+ * Non-fatal scan warning. Clack renders it inside the guide rail; plain mode
233
+ * keeps the `[scan] …` stderr line scripts may grep for.
234
+ */
235
+ warn(message) {
236
+ if (this.useClack) {
237
+ this.prompts().log.warn(message);
238
+ }
239
+ else {
240
+ console.warn(`[scan] ${message}`);
241
+ }
242
+ }
243
+ /**
244
+ * Technical meters (`--ai-verbose`, quota). Plain mode prints the raw lines;
245
+ * Clack folds them into one dimmed note so they don't break the guide rail.
246
+ */
247
+ showTechnicalDetails(title, lines) {
248
+ if (lines.length === 0)
249
+ return;
250
+ if (this.useClack) {
251
+ const body = lines
252
+ .map((line) => line.replace(/^\[scan\] ?/, ''))
253
+ .map((line) => paint(this.colorEnabled, 'dim', line))
254
+ .join('\n');
255
+ this.prompts().note(body, title);
256
+ }
257
+ else {
258
+ for (const line of lines) {
259
+ this.writeLine(line);
260
+ }
261
+ }
262
+ }
263
+ finish() {
264
+ this.completeActiveStep();
265
+ const nextSteps = [];
266
+ if (this.previewUrl) {
267
+ nextSteps.push(`Open your diagram:\n${formatPreviewLink(this.previewUrl, this.colorEnabled)}`);
268
+ // Plain mode already got the notice from the upload's own log line.
269
+ if (this.useClack && this.previewNotice) {
270
+ nextSteps.push(this.previewNotice);
271
+ }
272
+ }
273
+ else {
274
+ nextSteps.push('Jump into DataParade to keep editing the diagram.');
275
+ }
276
+ if (this.useClack) {
277
+ // Not a note(): it hard-wraps to the terminal width, which splits long
278
+ // preview URLs and breaks click-to-open.
279
+ this.prompts().log.step('What to do next');
280
+ this.prompts().log.message(nextSteps.join('\n\n'));
281
+ this.prompts().outro('All done — nice work.');
282
+ }
283
+ else {
284
+ this.writePlain('What to do next');
285
+ for (const line of nextSteps) {
286
+ // Preserve ANSI on the link line when color is on; strip elsewhere.
287
+ if (this.colorEnabled && line.includes('http')) {
288
+ this.writeLine(` ${line}`);
289
+ }
290
+ else {
291
+ this.writePlain(` ${line}`);
292
+ }
293
+ }
294
+ this.writePlain('All done — nice work.');
295
+ }
296
+ }
297
+ transitionTo(step) {
298
+ if (this.activeStep === step || this.completedSteps.has(step)) {
299
+ return;
300
+ }
301
+ this.completeActiveStep();
302
+ this.activeStep = step;
303
+ const label = STEP_LABELS[step];
304
+ if (this.useClack) {
305
+ this.spinner = this.prompts().spinner({ withGuide: true });
306
+ this.spinner.start(label);
307
+ }
308
+ else {
309
+ this.writePlain(`… ${label}`);
310
+ }
311
+ }
312
+ completeActiveStep() {
313
+ if (!this.activeStep)
314
+ return;
315
+ const label = STEP_LABELS[this.activeStep];
316
+ if (this.useClack && this.spinner) {
317
+ this.spinner.stop(label);
318
+ this.spinner = null;
319
+ }
320
+ else if (!this.useClack) {
321
+ this.writePlain(`✓ ${label}`);
322
+ }
323
+ this.completedSteps.add(this.activeStep);
324
+ this.activeStep = null;
325
+ }
326
+ runTeachingStep(step, teachingLines) {
327
+ if (this.completedSteps.has(step))
328
+ return;
329
+ // Only show the step when there is something to teach, per AL-160.
330
+ if (teachingLines.length === 0)
331
+ return;
332
+ const label = STEP_LABELS[step];
333
+ if (this.useClack) {
334
+ const spin = this.prompts().spinner({ withGuide: true });
335
+ spin.start(label);
336
+ spin.stop(label);
337
+ for (const line of teachingLines) {
338
+ this.prompts().log.message(line);
339
+ }
340
+ }
341
+ else {
342
+ this.writePlain(`✓ ${label}`);
343
+ for (const line of teachingLines) {
344
+ this.writePlain(` · ${line}`);
345
+ }
346
+ }
347
+ this.completedSteps.add(step);
348
+ }
349
+ prompts() {
350
+ if (!this.clack) {
351
+ throw new Error('@clack/prompts is not loaded');
352
+ }
353
+ return this.clack;
354
+ }
355
+ writePlain(line) {
356
+ const text = this.noColor ? line.replace(ANSI_PATTERN, '') : line;
357
+ this.writeLine(text);
358
+ }
359
+ }
360
+ exports.ScanProgressRenderer = ScanProgressRenderer;
361
+ async function createScanProgressRenderer(options) {
362
+ const isTTY = options?.isTTY ?? Boolean(process.stdout.isTTY);
363
+ const noColor = options?.noColor !== undefined ? options.noColor : envNoColor();
364
+ const useClack = isTTY && !noColor;
365
+ const clack = useClack ? (options?.prompts ?? (await loadClack())) : null;
366
+ return new ScanProgressRenderer({
367
+ isTTY,
368
+ noColor,
369
+ writeLine: options?.writeLine,
370
+ projectLabel: options?.projectLabel,
371
+ version: options?.version,
372
+ columns: options?.columns ?? process.stdout.columns,
373
+ colorDepth: options?.colorDepth ??
374
+ (typeof process.stdout.getColorDepth === 'function'
375
+ ? process.stdout.getColorDepth()
376
+ : undefined),
377
+ }, clack);
378
+ }
379
+ /** Exported for tests. */
380
+ function stripAnsi(text) {
381
+ return text.replace(ANSI_PATTERN, '');
382
+ }
383
+ function hasAnsi(text) {
384
+ // Avoid RegExp.lastIndex surprises with the global flag.
385
+ return new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`).test(text);
386
+ }
@@ -0,0 +1,9 @@
1
+ import type { DetectedComponent, RawFinding } from '../core/types';
2
+ import type { TeachingLineGroups } from './types';
3
+ /**
4
+ * Build teaching lines from deterministic findings/components.
5
+ * Empty groups are omitted by the renderer.
6
+ */
7
+ export declare function buildTeachingLineGroups(findings: RawFinding[], components: DetectedComponent[]): TeachingLineGroups;
8
+ /** Flatten groups into display strings (without the leading bullet). */
9
+ export declare function flattenTeachingLines(groups: TeachingLineGroups): string[];
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildTeachingLineGroups = buildTeachingLineGroups;
4
+ exports.flattenTeachingLines = flattenTeachingLines;
5
+ function asString(value) {
6
+ if (typeof value !== 'string')
7
+ return undefined;
8
+ const trimmed = value.trim();
9
+ return trimmed.length > 0 ? trimmed : undefined;
10
+ }
11
+ function titleCaseToken(token) {
12
+ if (!token)
13
+ return token;
14
+ if (token === token.toUpperCase() && token.length <= 4)
15
+ return token;
16
+ return token.charAt(0).toUpperCase() + token.slice(1);
17
+ }
18
+ function prettyFramework(framework) {
19
+ const lower = framework.toLowerCase();
20
+ if (lower === 'express')
21
+ return 'Express';
22
+ if (lower === 'nest')
23
+ return 'Nest';
24
+ if (lower === 'next_or_react_route')
25
+ return 'Next.js';
26
+ if (lower === 'fastapi')
27
+ return 'FastAPI';
28
+ if (lower === 'flask')
29
+ return 'Flask';
30
+ if (lower === 'django')
31
+ return 'Django';
32
+ return titleCaseToken(framework.replace(/_/g, ' '));
33
+ }
34
+ function prettyClient(client) {
35
+ const lower = client.toLowerCase();
36
+ if (lower === 'typeorm')
37
+ return 'TypeORM';
38
+ if (lower === 'prisma')
39
+ return 'Prisma';
40
+ if (lower === 'mongoose')
41
+ return 'Mongoose';
42
+ if (lower === 'psycopg2' || lower === 'psycopg')
43
+ return 'psycopg';
44
+ if (lower === 'pg')
45
+ return 'pg';
46
+ if (lower === 'knex')
47
+ return 'Knex';
48
+ return titleCaseToken(client);
49
+ }
50
+ function prettyDatabaseType(databaseType) {
51
+ const lower = databaseType.toLowerCase();
52
+ if (lower === 'postgres' || lower === 'postgresql')
53
+ return 'Postgres';
54
+ if (lower === 'mysql')
55
+ return 'MySQL';
56
+ if (lower === 'mongodb' || lower === 'mongo')
57
+ return 'MongoDB';
58
+ if (lower === 'sqlite')
59
+ return 'SQLite';
60
+ if (lower === 'redis')
61
+ return 'Redis';
62
+ if (lower === 'sql')
63
+ return 'SQL';
64
+ return titleCaseToken(databaseType);
65
+ }
66
+ function prettyVendor(serviceName) {
67
+ const lower = serviceName.toLowerCase();
68
+ const known = {
69
+ stripe: 'Stripe',
70
+ sendgrid: 'Sendgrid',
71
+ sentry: 'Sentry',
72
+ openai: 'OpenAI',
73
+ aws: 'AWS',
74
+ auth0: 'Auth0',
75
+ };
76
+ if (known[lower])
77
+ return known[lower];
78
+ return titleCaseToken(serviceName);
79
+ }
80
+ /**
81
+ * Build teaching lines from deterministic findings/components.
82
+ * Empty groups are omitted by the renderer.
83
+ */
84
+ function buildTeachingLineGroups(findings, components) {
85
+ const routeCounts = new Map();
86
+ for (const finding of findings) {
87
+ if (finding.pattern !== 'express_route')
88
+ continue;
89
+ const framework = asString(finding.properties?.framework) ?? 'framework';
90
+ routeCounts.set(framework, (routeCounts.get(framework) ?? 0) + 1);
91
+ }
92
+ const routes = [...routeCounts.entries()]
93
+ .sort(([a], [b]) => a.localeCompare(b))
94
+ .map(([framework, count]) => {
95
+ const name = prettyFramework(framework);
96
+ return count === 1
97
+ ? `Found 1 ${name} route`
98
+ : `Found ${count} ${name} routes`;
99
+ });
100
+ const storeKeys = new Set();
101
+ const stores = [];
102
+ for (const finding of findings) {
103
+ if (finding.pattern !== 'database_connection')
104
+ continue;
105
+ const client = asString(finding.properties?.client) ?? 'database';
106
+ const databaseType = asString(finding.properties?.databaseType) ?? 'SQL';
107
+ const key = `${client}|${databaseType}`;
108
+ if (storeKeys.has(key))
109
+ continue;
110
+ storeKeys.add(key);
111
+ stores.push(`Talks to ${prettyDatabaseType(databaseType)} (${prettyClient(client)})`);
112
+ }
113
+ const vendorNames = new Set();
114
+ for (const component of components) {
115
+ if (component.type !== 'third_party')
116
+ continue;
117
+ const serviceName = asString(component.properties?.serviceName);
118
+ if (serviceName)
119
+ vendorNames.add(serviceName.toLowerCase());
120
+ }
121
+ for (const finding of findings) {
122
+ if (finding.pattern !== 'external_api_call')
123
+ continue;
124
+ const serviceName = asString(finding.properties?.serviceName);
125
+ if (serviceName)
126
+ vendorNames.add(serviceName.toLowerCase());
127
+ }
128
+ const outboundSorted = [...vendorNames].sort((a, b) => a.localeCompare(b));
129
+ const outboundLabels = outboundSorted.map(prettyVendor);
130
+ const outbound = outboundLabels.length === 0
131
+ ? []
132
+ : outboundLabels.length === 1
133
+ ? [`Calls out to ${outboundLabels[0]}`]
134
+ : outboundLabels.length === 2
135
+ ? [`Calls out to ${outboundLabels[0]} and ${outboundLabels[1]}`]
136
+ : [
137
+ `Calls out to ${outboundLabels.slice(0, -1).join(', ')}, and ${outboundLabels[outboundLabels.length - 1]}`,
138
+ ];
139
+ return { routes, stores, outbound };
140
+ }
141
+ /** Flatten groups into display strings (without the leading bullet). */
142
+ function flattenTeachingLines(groups) {
143
+ return [...groups.routes, ...groups.stores, ...groups.outbound];
144
+ }
@@ -0,0 +1,33 @@
1
+ import type { DetectedComponent, RawFinding } from '../core/types';
2
+ export type ScanUiStepId = 'scanning_files' | 'analyzing' | 'detecting_frameworks' | 'mapping_data_stores' | 'finding_outbound' | 'ai_enrichment';
3
+ /** What the AI step changed, for its one-line result. */
4
+ export interface ScanAiStepResult {
5
+ proposalsApplied: number;
6
+ }
7
+ export interface ScanRecognitionPayload {
8
+ findings: RawFinding[];
9
+ components: DetectedComponent[];
10
+ }
11
+ export interface ScanProgressRendererOptions {
12
+ /** When false, plain logs only (no Clack spinner / intro chrome). */
13
+ isTTY: boolean;
14
+ /** When true, never emit ANSI escape codes. */
15
+ noColor: boolean;
16
+ /** CLI version shown in the brand header. */
17
+ version?: string;
18
+ /** Terminal width (defaults to process.stdout.columns). */
19
+ columns?: number;
20
+ /** Terminal color depth in bits (defaults to process.stdout.getColorDepth()). */
21
+ colorDepth?: number;
22
+ /** Short path/name shown under the brand header. */
23
+ projectLabel?: string;
24
+ /** Override stdout writes (tests). Defaults to console.log. */
25
+ writeLine?: (line: string) => void;
26
+ /** Injected Clack module. Tests pass a mock; production loads the ESM package. */
27
+ prompts?: typeof import('@clack/prompts');
28
+ }
29
+ export interface TeachingLineGroups {
30
+ routes: string[];
31
+ stores: string[];
32
+ outbound: string[];
33
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,2 @@
1
- import type { RunDataflowUploadInput, RunDataflowUploadResult } from "./types";
1
+ import type { RunDataflowUploadInput, RunDataflowUploadResult } from './types';
2
2
  export declare function runDataflowUpload(input: RunDataflowUploadInput): Promise<RunDataflowUploadResult>;
@@ -5,8 +5,8 @@ const upload_client_1 = require("../platform-api/upload-client");
5
5
  const telemetry_client_1 = require("../platform-api/telemetry-client");
6
6
  const build_preview_url_1 = require("./build-preview-url");
7
7
  async function runDataflowUpload(input) {
8
- const prefix = input.logPrefix ?? "[upload]";
9
- const command = input.command ?? "scan";
8
+ const prefix = input.logPrefix ?? '[upload]';
9
+ const command = input.command ?? 'scan';
10
10
  const sessionId = input.cliUsageSessionId?.trim();
11
11
  const apiKey = input.apiKey?.trim();
12
12
  try {
@@ -20,12 +20,14 @@ async function runDataflowUpload(input) {
20
20
  command,
21
21
  });
22
22
  const previewUrl = (0, build_preview_url_1.buildImportPreviewUrl)(result.draftId, sessionId);
23
- // eslint-disable-next-line no-console
24
- console.log(`${prefix} Preview ready: ${previewUrl}`);
23
+ if (!input.quiet) {
24
+ // eslint-disable-next-line no-console
25
+ console.log(`${prefix} Preview ready: ${previewUrl}`);
26
+ }
25
27
  if (sessionId) {
26
28
  await (0, telemetry_client_1.reportCliUsageEvent)({
27
29
  sessionId,
28
- event: "upload_succeeded",
30
+ event: 'upload_succeeded',
29
31
  command,
30
32
  hasApiKey: true,
31
33
  apiKey,
@@ -42,33 +44,36 @@ async function runDataflowUpload(input) {
42
44
  command,
43
45
  });
44
46
  const previewUrl = (0, build_preview_url_1.buildAnonymousCliPreviewUrl)(result.claimToken, sessionId);
45
- // eslint-disable-next-line no-console
46
- console.log(`${prefix} Preview ready: ${previewUrl}`);
47
- // eslint-disable-next-line no-console
48
- console.log(`${prefix} Claiming this preview after signup uses 1 scan slot` +
47
+ const notice = 'You can view the diagram now. Claiming it to your account uses 1 scan slot' +
49
48
  (input.scanJobId
50
- ? " and any platform AI tokens used during the scan."
51
- : "."));
49
+ ? ' and any platform AI tokens used during the scan.'
50
+ : '.');
51
+ if (!input.quiet) {
52
+ // eslint-disable-next-line no-console
53
+ console.log(`${prefix} Preview ready: ${previewUrl}`);
54
+ // eslint-disable-next-line no-console
55
+ console.log(`${prefix} ${notice}`);
56
+ }
52
57
  if (sessionId) {
53
58
  await (0, telemetry_client_1.reportCliUsageEvent)({
54
59
  sessionId,
55
- event: "upload_succeeded",
60
+ event: 'upload_succeeded',
56
61
  command,
57
62
  hasApiKey: false,
58
63
  });
59
64
  }
60
- return { previewUrl };
65
+ return { previewUrl, notice };
61
66
  }
62
67
  catch (error) {
63
68
  if (sessionId) {
64
- const message = error instanceof Error ? error.message : "Upload failed.";
69
+ const message = error instanceof Error ? error.message : 'Upload failed.';
65
70
  await (0, telemetry_client_1.reportCliUsageEvent)({
66
71
  sessionId,
67
- event: "upload_failed",
72
+ event: 'upload_failed',
68
73
  command,
69
74
  hasApiKey: Boolean(apiKey),
70
75
  apiKey,
71
- errorCode: "upload_failed",
76
+ errorCode: 'upload_failed',
72
77
  errorMessage: message,
73
78
  });
74
79
  }
@@ -6,8 +6,12 @@ export type RunDataflowUploadInput = {
6
6
  logPrefix?: string;
7
7
  cliUsageSessionId?: string;
8
8
  command?: "scan" | "upload";
9
+ /** Skip the `[prefix] Preview ready` lines (TTY scan renders its own block). */
10
+ quiet?: boolean;
9
11
  };
10
12
  export type RunDataflowUploadResult = {
11
13
  draftId?: string;
12
14
  previewUrl: string;
15
+ /** Extra human hint shown with the preview (anonymous claim cost). */
16
+ notice?: string;
13
17
  };