@dataparade/cli 0.0.10 → 0.0.11

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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataparade/cli",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "dataPARADE CLI — scan codebases for privacy and security data flows",
5
5
  "publishConfig": {
6
6
  "access": "public",
package/dist/src/cli.js CHANGED
@@ -40,6 +40,7 @@ exports.run = run;
40
40
  require("./config/load-cli-env");
41
41
  const path_1 = __importDefault(require("path"));
42
42
  const commander_1 = require("commander");
43
+ const crypto_1 = require("crypto");
43
44
  const package_json_1 = __importDefault(require("../package.json"));
44
45
  const json_1 = require("./output/json");
45
46
  const upload_env_1 = require("./config/upload-env");
@@ -50,6 +51,7 @@ const resolve_1 = require("./config/resolve");
50
51
  const scan_env_1 = require("./config/scan-env");
51
52
  const validate_scan_ai_1 = require("./config/validate-scan-ai");
52
53
  const scan_sentry_1 = require("./observability/scan-sentry");
54
+ const telemetry_client_1 = require("./platform-api/telemetry-client");
53
55
  const scan_config_schema_1 = require("./core/schema/scan-config.schema");
54
56
  const file_system_1 = require("./ingest/file-system");
55
57
  function formatEvidence(detail) {
@@ -159,6 +161,15 @@ function createProgram() {
159
161
  const workspaceApiKey = options.workspaceApiKey?.trim() ||
160
162
  options.apiKey?.trim() ||
161
163
  (0, scan_env_1.resolveWorkspaceApiKey)(process.env);
164
+ const usageSessionId = (0, crypto_1.randomUUID)();
165
+ await (0, telemetry_client_1.reportCliUsageEvent)({
166
+ sessionId: usageSessionId,
167
+ event: "scan_started",
168
+ command: "scan",
169
+ hasApiKey: Boolean(workspaceApiKey),
170
+ apiKey: workspaceApiKey,
171
+ cliVersion: package_json_1.default.version,
172
+ });
162
173
  try {
163
174
  const rootPathArg = path || ".";
164
175
  // Load dataparade.config.json from the directory being scanned, not
@@ -438,6 +449,8 @@ function createProgram() {
438
449
  projectName: resolvedProjectName,
439
450
  scanJobId: cliQuotaJobId,
440
451
  logPrefix: "[scan]",
452
+ cliUsageSessionId: usageSessionId,
453
+ command: "scan",
441
454
  });
442
455
  }
443
456
  catch (uploadError) {
@@ -516,6 +529,17 @@ function createProgram() {
516
529
  process.exitCode = 1;
517
530
  }
518
531
  finally {
532
+ const scanFailed = (process.exitCode ?? 0) !== 0;
533
+ await (0, telemetry_client_1.reportCliUsageEvent)({
534
+ sessionId: usageSessionId,
535
+ event: scanFailed ? "scan_failed" : "scan_succeeded",
536
+ command: "scan",
537
+ hasApiKey: Boolean(workspaceApiKey),
538
+ apiKey: workspaceApiKey,
539
+ cliVersion: package_json_1.default.version,
540
+ errorCode: scanFailed ? "scan_failed" : undefined,
541
+ errorMessage: scanFailed ? fallbackFailureMessage : undefined,
542
+ });
519
543
  if (platformQuotaApiKey && cliQuotaJobId && !quotaCompletionReported) {
520
544
  try {
521
545
  const { cliScanComplete } = await Promise.resolve().then(() => __importStar(require("./platform-api/scan-quota-client")));
@@ -548,6 +572,7 @@ function createProgram() {
548
572
  const apiKey = options.workspaceApiKey?.trim() ||
549
573
  options.apiKey?.trim() ||
550
574
  (0, scan_env_1.resolveWorkspaceApiKey)(process.env);
575
+ const usageSessionId = (0, crypto_1.randomUUID)();
551
576
  const filePath = path_1.default.resolve(process.cwd(), file || "dataflow.json");
552
577
  let dataflow;
553
578
  try {
@@ -575,6 +600,8 @@ function createProgram() {
575
600
  apiKey,
576
601
  dataflow,
577
602
  projectName,
603
+ cliUsageSessionId: usageSessionId,
604
+ command: "upload",
578
605
  });
579
606
  }
580
607
  catch (err) {
@@ -0,0 +1,6 @@
1
+ import type { ReportCliUsageEventInput } from "./telemetry.types";
2
+ export declare function isCliTelemetryEnabled(env?: NodeJS.ProcessEnv): boolean;
3
+ /**
4
+ * Fire-and-forget CLI usage telemetry. Never throws.
5
+ */
6
+ export declare function reportCliUsageEvent(input: ReportCliUsageEventInput, env?: NodeJS.ProcessEnv): Promise<void>;
@@ -0,0 +1,65 @@
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.isCliTelemetryEnabled = isCliTelemetryEnabled;
7
+ exports.reportCliUsageEvent = reportCliUsageEvent;
8
+ const package_json_1 = __importDefault(require("../../package.json"));
9
+ const dataparade_api_base_url_1 = require("./dataparade-api-base-url");
10
+ const TELEMETRY_TIMEOUT_MS = 2000;
11
+ const FALSY = new Set(["0", "false", "no", "off"]);
12
+ const TRUTHY = new Set(["1", "true", "yes", "on"]);
13
+ function isCliTelemetryEnabled(env = process.env) {
14
+ const explicit = env.DATAPARADE_TELEMETRY?.trim().toLowerCase() ||
15
+ env.SCAN_TELEMETRY_ENABLED?.trim().toLowerCase();
16
+ if (explicit && FALSY.has(explicit))
17
+ return false;
18
+ if (explicit && TRUTHY.has(explicit))
19
+ return true;
20
+ if (env.NODE_ENV === "test")
21
+ return false;
22
+ return true;
23
+ }
24
+ /**
25
+ * Fire-and-forget CLI usage telemetry. Never throws.
26
+ */
27
+ async function reportCliUsageEvent(input, env = process.env) {
28
+ if (!isCliTelemetryEnabled(env))
29
+ return;
30
+ const controller = new AbortController();
31
+ const timer = setTimeout(() => controller.abort(), TELEMETRY_TIMEOUT_MS);
32
+ try {
33
+ const headers = {
34
+ "Content-Type": "application/json",
35
+ };
36
+ const apiKey = input.apiKey?.trim();
37
+ if (apiKey) {
38
+ headers.Authorization = `Bearer ${apiKey}`;
39
+ }
40
+ await fetch(`${(0, dataparade_api_base_url_1.getDataparadeApiBaseUrl)(env)}/api/scans/cli/telemetry`, {
41
+ method: "POST",
42
+ headers,
43
+ signal: controller.signal,
44
+ body: JSON.stringify({
45
+ sessionId: input.sessionId,
46
+ event: input.event,
47
+ command: input.command,
48
+ hasApiKey: Boolean(input.hasApiKey ?? apiKey),
49
+ cliVersion: input.cliVersion ?? package_json_1.default.version,
50
+ draftId: input.draftId,
51
+ errorCode: input.errorCode,
52
+ errorMessage: input.errorMessage
53
+ ? input.errorMessage.slice(0, 500)
54
+ : undefined,
55
+ source: input.source ?? "cli",
56
+ }),
57
+ });
58
+ }
59
+ catch {
60
+ // Telemetry must never change CLI behavior.
61
+ }
62
+ finally {
63
+ clearTimeout(timer);
64
+ }
65
+ }
@@ -0,0 +1,13 @@
1
+ export type CliUsageEventName = "scan_started" | "scan_succeeded" | "scan_failed" | "upload_succeeded" | "upload_failed" | "preview_opened";
2
+ export type ReportCliUsageEventInput = {
3
+ sessionId: string;
4
+ event: CliUsageEventName;
5
+ command?: "scan" | "upload";
6
+ hasApiKey?: boolean;
7
+ apiKey?: string;
8
+ cliVersion?: string;
9
+ draftId?: string;
10
+ errorCode?: string;
11
+ errorMessage?: string;
12
+ source?: "cli" | "web";
13
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -4,6 +4,8 @@ export declare function cliUploadAnonymousPreview(input: {
4
4
  dataflow: unknown;
5
5
  projectName?: string;
6
6
  scanJobId?: string;
7
+ cliUsageSessionId?: string;
8
+ command?: "scan" | "upload";
7
9
  }): Promise<CliAnonymousUploadPreviewResponse>;
8
10
  export declare function cliUploadPreview(input: CliUploadPreviewInput & {
9
11
  apiKey: string;
@@ -33,6 +33,8 @@ async function cliUploadAnonymousPreview(input) {
33
33
  dataflow: input.dataflow,
34
34
  projectName: input.projectName,
35
35
  scanJobId: input.scanJobId,
36
+ cliUsageSessionId: input.cliUsageSessionId,
37
+ command: input.command,
36
38
  }),
37
39
  });
38
40
  if (!res.ok) {
@@ -48,6 +50,8 @@ async function cliUploadPreview(input) {
48
50
  dataflow: input.dataflow,
49
51
  projectName: input.projectName,
50
52
  scanJobId: input.scanJobId,
53
+ cliUsageSessionId: input.cliUsageSessionId,
54
+ command: input.command,
51
55
  }),
52
56
  });
53
57
  if (!res.ok) {
@@ -12,4 +12,6 @@ export type CliUploadPreviewInput = {
12
12
  dataflow: unknown;
13
13
  projectName?: string;
14
14
  scanJobId?: string;
15
+ cliUsageSessionId?: string;
16
+ command?: "scan" | "upload";
15
17
  };
@@ -1,2 +1,2 @@
1
- export declare function buildImportPreviewUrl(draftId: string): string;
2
- export declare function buildAnonymousCliPreviewUrl(claimToken: string): string;
1
+ export declare function buildImportPreviewUrl(draftId: string, cliSessionId?: string): string;
2
+ export declare function buildAnonymousCliPreviewUrl(claimToken: string, cliSessionId?: string): string;
@@ -3,14 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildImportPreviewUrl = buildImportPreviewUrl;
4
4
  exports.buildAnonymousCliPreviewUrl = buildAnonymousCliPreviewUrl;
5
5
  const dataparade_app_base_url_1 = require("../platform-api/dataparade-app-base-url");
6
- function buildImportPreviewUrl(draftId) {
6
+ function buildImportPreviewUrl(draftId, cliSessionId) {
7
7
  const base = (0, dataparade_app_base_url_1.getDataparadeAppBaseUrl)();
8
8
  const url = new URL("/dashboard", `${base}/`);
9
9
  url.searchParams.set("importDraft", draftId);
10
+ if (cliSessionId?.trim()) {
11
+ url.searchParams.set("cliSession", cliSessionId.trim());
12
+ }
10
13
  return url.toString();
11
14
  }
12
- function buildAnonymousCliPreviewUrl(claimToken) {
15
+ function buildAnonymousCliPreviewUrl(claimToken, cliSessionId) {
13
16
  const base = (0, dataparade_app_base_url_1.getDataparadeAppBaseUrl)();
14
17
  const encoded = encodeURIComponent(claimToken);
15
- return `${base}/preview/cli/${encoded}`;
18
+ const url = new URL(`/preview/cli/${encoded}`, `${base}/`);
19
+ if (cliSessionId?.trim()) {
20
+ url.searchParams.set("cliSession", cliSessionId.trim());
21
+ }
22
+ return url.toString();
16
23
  }
@@ -2,33 +2,76 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runDataflowUpload = runDataflowUpload;
4
4
  const upload_client_1 = require("../platform-api/upload-client");
5
+ const telemetry_client_1 = require("../platform-api/telemetry-client");
5
6
  const build_preview_url_1 = require("./build-preview-url");
6
7
  async function runDataflowUpload(input) {
7
8
  const prefix = input.logPrefix ?? "[upload]";
8
- if (input.apiKey?.trim()) {
9
- const result = await (0, upload_client_1.cliUploadPreview)({
10
- apiKey: input.apiKey.trim(),
9
+ const command = input.command ?? "scan";
10
+ const sessionId = input.cliUsageSessionId?.trim();
11
+ const apiKey = input.apiKey?.trim();
12
+ try {
13
+ if (apiKey) {
14
+ const result = await (0, upload_client_1.cliUploadPreview)({
15
+ apiKey,
16
+ dataflow: input.dataflow,
17
+ projectName: input.projectName,
18
+ scanJobId: input.scanJobId,
19
+ cliUsageSessionId: sessionId,
20
+ command,
21
+ });
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}`);
25
+ if (sessionId) {
26
+ await (0, telemetry_client_1.reportCliUsageEvent)({
27
+ sessionId,
28
+ event: "upload_succeeded",
29
+ command,
30
+ hasApiKey: true,
31
+ apiKey,
32
+ draftId: result.draftId,
33
+ });
34
+ }
35
+ return { draftId: result.draftId, previewUrl };
36
+ }
37
+ const result = await (0, upload_client_1.cliUploadAnonymousPreview)({
11
38
  dataflow: input.dataflow,
12
39
  projectName: input.projectName,
13
40
  scanJobId: input.scanJobId,
41
+ cliUsageSessionId: sessionId,
42
+ command,
14
43
  });
15
- const previewUrl = (0, build_preview_url_1.buildImportPreviewUrl)(result.draftId);
44
+ const previewUrl = (0, build_preview_url_1.buildAnonymousCliPreviewUrl)(result.claimToken, sessionId);
16
45
  // eslint-disable-next-line no-console
17
46
  console.log(`${prefix} Preview ready: ${previewUrl}`);
18
- return { draftId: result.draftId, previewUrl };
47
+ // eslint-disable-next-line no-console
48
+ console.log(`${prefix} Claiming this preview after signup uses 1 scan slot` +
49
+ (input.scanJobId
50
+ ? " and any platform AI tokens used during the scan."
51
+ : "."));
52
+ if (sessionId) {
53
+ await (0, telemetry_client_1.reportCliUsageEvent)({
54
+ sessionId,
55
+ event: "upload_succeeded",
56
+ command,
57
+ hasApiKey: false,
58
+ });
59
+ }
60
+ return { previewUrl };
61
+ }
62
+ catch (error) {
63
+ if (sessionId) {
64
+ const message = error instanceof Error ? error.message : "Upload failed.";
65
+ await (0, telemetry_client_1.reportCliUsageEvent)({
66
+ sessionId,
67
+ event: "upload_failed",
68
+ command,
69
+ hasApiKey: Boolean(apiKey),
70
+ apiKey,
71
+ errorCode: "upload_failed",
72
+ errorMessage: message,
73
+ });
74
+ }
75
+ throw error;
19
76
  }
20
- const result = await (0, upload_client_1.cliUploadAnonymousPreview)({
21
- dataflow: input.dataflow,
22
- projectName: input.projectName,
23
- scanJobId: input.scanJobId,
24
- });
25
- const previewUrl = (0, build_preview_url_1.buildAnonymousCliPreviewUrl)(result.claimToken);
26
- // eslint-disable-next-line no-console
27
- console.log(`${prefix} Preview ready: ${previewUrl}`);
28
- // eslint-disable-next-line no-console
29
- console.log(`${prefix} Claiming this preview after signup uses 1 scan slot` +
30
- (input.scanJobId
31
- ? " and any platform AI tokens used during the scan."
32
- : "."));
33
- return { previewUrl };
34
77
  }
@@ -4,6 +4,8 @@ export type RunDataflowUploadInput = {
4
4
  projectName?: string;
5
5
  scanJobId?: string;
6
6
  logPrefix?: string;
7
+ cliUsageSessionId?: string;
8
+ command?: "scan" | "upload";
7
9
  };
8
10
  export type RunDataflowUploadResult = {
9
11
  draftId?: string;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const telemetry_client_1 = require("../../../src/platform-api/telemetry-client");
4
+ describe("isCliTelemetryEnabled", () => {
5
+ const originalNodeEnv = process.env.NODE_ENV;
6
+ afterEach(() => {
7
+ delete process.env.DATAPARADE_TELEMETRY;
8
+ delete process.env.SCAN_TELEMETRY_ENABLED;
9
+ process.env.NODE_ENV = originalNodeEnv;
10
+ });
11
+ it("is off in test unless explicitly enabled", () => {
12
+ process.env.NODE_ENV = "test";
13
+ delete process.env.DATAPARADE_TELEMETRY;
14
+ expect((0, telemetry_client_1.isCliTelemetryEnabled)({ NODE_ENV: "test" })).toBe(false);
15
+ });
16
+ it("honors DATAPARADE_TELEMETRY=false", () => {
17
+ expect((0, telemetry_client_1.isCliTelemetryEnabled)({ DATAPARADE_TELEMETRY: "false", NODE_ENV: "production" })).toBe(false);
18
+ });
19
+ it("honors SCAN_TELEMETRY_ENABLED=false", () => {
20
+ expect((0, telemetry_client_1.isCliTelemetryEnabled)({
21
+ SCAN_TELEMETRY_ENABLED: "false",
22
+ NODE_ENV: "production",
23
+ })).toBe(false);
24
+ });
25
+ });
26
+ describe("reportCliUsageEvent", () => {
27
+ const fetchMock = jest.fn();
28
+ beforeEach(() => {
29
+ fetchMock.mockReset();
30
+ global.fetch = fetchMock;
31
+ });
32
+ it("does not throw when the API returns 5xx", async () => {
33
+ fetchMock.mockResolvedValue({ ok: false, status: 500 });
34
+ await expect((0, telemetry_client_1.reportCliUsageEvent)({
35
+ sessionId: "11111111-1111-4111-8111-111111111111",
36
+ event: "scan_started",
37
+ command: "scan",
38
+ }, { DATAPARADE_TELEMETRY: "true", NODE_ENV: "test" })).resolves.toBeUndefined();
39
+ expect(fetchMock).toHaveBeenCalled();
40
+ });
41
+ it("is a no-op when telemetry is disabled", async () => {
42
+ await (0, telemetry_client_1.reportCliUsageEvent)({
43
+ sessionId: "11111111-1111-4111-8111-111111111111",
44
+ event: "scan_started",
45
+ }, { DATAPARADE_TELEMETRY: "false" });
46
+ expect(fetchMock).not.toHaveBeenCalled();
47
+ });
48
+ });
@@ -16,6 +16,11 @@ describe("buildImportPreviewUrl", () => {
16
16
  const url = (0, build_preview_url_1.buildImportPreviewUrl)("draft-abc");
17
17
  expect(url).toBe("http://localhost:3001/dashboard?importDraft=draft-abc");
18
18
  });
19
+ it("appends cliSession when provided", () => {
20
+ process.env.DATAPARADE_APP_URL = "http://localhost:3001";
21
+ const url = (0, build_preview_url_1.buildImportPreviewUrl)("draft-abc", "11111111-1111-4111-8111-111111111111");
22
+ expect(url).toContain("cliSession=11111111-1111-4111-8111-111111111111");
23
+ });
19
24
  });
20
25
  describe("buildAnonymousCliPreviewUrl", () => {
21
26
  const original = process.env.DATAPARADE_APP_URL;
@@ -32,4 +37,9 @@ describe("buildAnonymousCliPreviewUrl", () => {
32
37
  const url = (0, build_preview_url_1.buildAnonymousCliPreviewUrl)("claim-token-xyz");
33
38
  expect(url).toBe("http://localhost:3001/preview/cli/claim-token-xyz");
34
39
  });
40
+ it("appends cliSession when provided", () => {
41
+ process.env.DATAPARADE_APP_URL = "http://localhost:3001";
42
+ const url = (0, build_preview_url_1.buildAnonymousCliPreviewUrl)("claim-token-xyz", "11111111-1111-4111-8111-111111111111");
43
+ expect(url).toContain("cliSession=11111111-1111-4111-8111-111111111111");
44
+ });
35
45
  });
@@ -5,11 +5,15 @@ jest.mock("../../../src/platform-api/upload-client", () => ({
5
5
  cliUploadAnonymousPreview: jest.fn(),
6
6
  cliUploadPreview: jest.fn(),
7
7
  }));
8
+ jest.mock("../../../src/platform-api/telemetry-client", () => ({
9
+ reportCliUsageEvent: jest.fn().mockResolvedValue(undefined),
10
+ }));
8
11
  jest.mock("../../../src/upload/build-preview-url", () => ({
9
12
  buildAnonymousCliPreviewUrl: jest.fn((token) => `https://app.example/preview/cli/${token}`),
10
13
  buildImportPreviewUrl: jest.fn((draftId) => `https://app.example/dashboard?importDraft=${draftId}`),
11
14
  }));
12
15
  const upload_client_1 = require("../../../src/platform-api/upload-client");
16
+ const telemetry_client_1 = require("../../../src/platform-api/telemetry-client");
13
17
  describe("runDataflowUpload anonymous path", () => {
14
18
  const logSpy = jest.spyOn(console, "log").mockImplementation(() => undefined);
15
19
  afterEach(() => {
@@ -34,10 +38,24 @@ describe("runDataflowUpload anonymous path", () => {
34
38
  dataflow: { schemaVersion: "1.0" },
35
39
  projectName: "Proj",
36
40
  scanJobId: "job-anon-1",
41
+ cliUsageSessionId: undefined,
42
+ command: "scan",
37
43
  });
38
44
  expect(upload_client_1.cliUploadPreview).not.toHaveBeenCalled();
39
45
  expect(result.previewUrl).toContain("claim-1");
40
46
  expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("Claiming this preview after signup uses 1 scan slot"));
41
47
  expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("platform AI tokens"));
42
48
  });
49
+ it("reports upload_failed and rethrows", async () => {
50
+ upload_client_1.cliUploadAnonymousPreview.mockRejectedValue(new Error("network down"));
51
+ await expect((0, run_upload_1.runDataflowUpload)({
52
+ dataflow: { schemaVersion: "1.0" },
53
+ cliUsageSessionId: "11111111-1111-4111-8111-111111111111",
54
+ logPrefix: "[scan]",
55
+ })).rejects.toThrow("network down");
56
+ expect(telemetry_client_1.reportCliUsageEvent).toHaveBeenCalledWith(expect.objectContaining({
57
+ event: "upload_failed",
58
+ errorCode: "upload_failed",
59
+ }));
60
+ });
43
61
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataparade/cli",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "dataPARADE CLI — scan codebases for privacy and security data flows",
5
5
  "publishConfig": {
6
6
  "access": "public",