@dataparade/cli 0.1.0 → 0.1.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.
@@ -12,6 +12,7 @@ const fs_1 = __importDefault(require("fs"));
12
12
  const apply_answers_1 = require("../facts/apply-answers");
13
13
  Object.defineProperty(exports, "SYSTEM_FACT_ID", { enumerable: true, get: function () { return apply_answers_1.SYSTEM_FACT_ID; } });
14
14
  const io_1 = require("../facts/io");
15
+ const data_category_catalog_generated_1 = require("./data-category-catalog.generated");
15
16
  const layout_1 = require("../facts/layout");
16
17
  function resolveKbPaths(kbDir) {
17
18
  return (0, layout_1.layoutForDir)(kbDir);
@@ -70,7 +71,9 @@ function appliedStateToDocument(applied) {
70
71
  }),
71
72
  dataFlows: applied.facts.dataFlows.map((f) => {
72
73
  const extra = f;
73
- const categories = asStringList(extra.data_categories);
74
+ const answeredCategories = asStringList(extra.data_categories);
75
+ const resolvedCategories = answeredCategories ? (0, data_category_catalog_generated_1.resolveDataCategoryValues)(answeredCategories) : [];
76
+ const categories = resolvedCategories.length > 0 ? resolvedCategories : undefined;
74
77
  const purpose = asString(extra.purpose);
75
78
  return {
76
79
  id: f.id,
@@ -10,6 +10,7 @@ const path_1 = __importDefault(require("path"));
10
10
  const load_ocsf_discoveries_1 = require("../discoveries/load-ocsf-discoveries");
11
11
  const scan_entity_uri_1 = require("../discoveries/scan-entity-uri");
12
12
  const io_1 = require("../facts/io");
13
+ const data_category_catalog_generated_1 = require("./data-category-catalog.generated");
13
14
  const kb_store_1 = require("./kb-store");
14
15
  /** Same record, same id, so running migrate twice adds nothing. */
15
16
  function migratedAnswerId(recordUid) {
@@ -19,8 +20,9 @@ function storedValue(slot, text) {
19
20
  if (slot === "data_categories") {
20
21
  try {
21
22
  const parsed = JSON.parse(text);
22
- if (Array.isArray(parsed))
23
- return parsed;
23
+ if (Array.isArray(parsed)) {
24
+ return parsed.map((token) => typeof token === "string" ? ((0, data_category_catalog_generated_1.resolveCatalogDataCategoryValue)(token) ?? token) : token);
25
+ }
24
26
  }
25
27
  catch {
26
28
  // Not a list; keep the text.
@@ -17,7 +17,8 @@ export declare class SlotValueError extends Error {
17
17
  }
18
18
  /**
19
19
  * The value as it is stored in `asserted_value`: an enum token, a JSON-encoded
20
- * list of DataCategory tokens, or approved scope text. Throws on anything that
21
- * isn't ontology-shaped, so a model can't land an invented category.
20
+ * list of DPV data category concepts (an older category name is mapped to its
21
+ * concept), or approved scope text. Throws on anything that isn't
22
+ * vocabulary-shaped, so a model can't land an invented category.
22
23
  */
23
24
  export declare function normalizeSlotValue(slot: InterviewSlot, raw: string): string;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SlotValueError = exports.SHAPE_FOR_SLOT = exports.SYSTEM_ASSERTS_URI = void 0;
4
4
  exports.isInterviewSlot = isInterviewSlot;
5
5
  exports.normalizeSlotValue = normalizeSlotValue;
6
+ const data_category_catalog_generated_1 = require("./data-category-catalog.generated");
6
7
  const taxonomy_1 = require("./taxonomy");
7
8
  /**
8
9
  * The interview answers that may land as Discoveries (write-back rules §3).
@@ -28,8 +29,9 @@ class SlotValueError extends Error {
28
29
  exports.SlotValueError = SlotValueError;
29
30
  /**
30
31
  * The value as it is stored in `asserted_value`: an enum token, a JSON-encoded
31
- * list of DataCategory tokens, or approved scope text. Throws on anything that
32
- * isn't ontology-shaped, so a model can't land an invented category.
32
+ * list of DPV data category concepts (an older category name is mapped to its
33
+ * concept), or approved scope text. Throws on anything that isn't
34
+ * vocabulary-shaped, so a model can't land an invented category.
33
35
  */
34
36
  function normalizeSlotValue(slot, raw) {
35
37
  const value = raw.trim();
@@ -54,21 +56,24 @@ function normalizeSlotValue(slot, raw) {
54
56
  case "data_categories": {
55
57
  const tokens = parseCategoryList(value);
56
58
  if (tokens.length === 0) {
57
- throw new SlotValueError("data_categories needs at least one category (use 'other' when none fits)");
59
+ throw new SlotValueError(`data_categories needs at least one category (use '${taxonomy_1.UNCATEGORISED_DATA_CATEGORY}' when none fits)`);
58
60
  }
61
+ const concepts = [];
59
62
  for (const token of tokens) {
60
63
  if (token === "unspecified") {
61
- throw new SlotValueError("data_categories has no 'unspecified'; use 'other' for a gap");
64
+ throw new SlotValueError(`data_categories has no 'unspecified'; use '${taxonomy_1.UNCATEGORISED_DATA_CATEGORY}' for a gap`);
62
65
  }
63
- if (!taxonomy_1.DATA_CATEGORIES.includes(token)) {
64
- throw new SlotValueError(`unknown data category '${token}'; use one of ${taxonomy_1.DATA_CATEGORIES.join(", ")}`);
66
+ const concept = (0, data_category_catalog_generated_1.resolveCatalogDataCategoryValue)(token);
67
+ if (!concept) {
68
+ throw new SlotValueError(`unknown data category '${token}'; use a W3C DPV, DPV-PD or dpx concept, one of ${taxonomy_1.DATA_CATEGORIES.join(", ")}`);
65
69
  }
70
+ concepts.push(concept);
66
71
  }
67
- return JSON.stringify(Array.from(new Set(tokens)).sort());
72
+ return JSON.stringify(Array.from(new Set(concepts)).sort());
68
73
  }
69
74
  }
70
75
  }
71
- /** Accepts a JSON array (`["contact"]`) or a comma-separated list (`contact, identifiers`). */
76
+ /** Accepts a JSON array (`["pd:EmailAddress"]`) or a comma-separated list (`pd:EmailAddress, pd:Name`). */
72
77
  function parseCategoryList(value) {
73
78
  if (value.startsWith("[")) {
74
79
  let parsed;
@@ -1,12 +1,18 @@
1
1
  /**
2
- * Ontology controlled vocabularies used by interview write-back.
3
- * Source: DataParade-io/ontology v0.3.0 (taxonomy/data_category.yaml,
4
- * purpose.yaml, actor_kind.yaml). Update together with PINNED_ONTOLOGY_*.
2
+ * Controlled vocabularies used by interview write-back.
3
+ *
4
+ * Data categories are W3C DPV, DPV-PD and dpx: concepts (DATAP-961), the same concepts the
5
+ * scanner puts on data flows, so interview answers and scan results use one vocabulary. The
6
+ * catalog is generated from the scanner taxonomy by scripts/data-categories/. Purposes and actor
7
+ * kinds come from DataParade-io/ontology (taxonomy/purpose.yaml, actor_kind.yaml); update them
8
+ * together with PINNED_ONTOLOGY_*.
5
9
  */
6
- export declare const DATA_CATEGORIES: readonly ["personal", "identifiers", "contact", "demographic", "credentials", "financial", "health", "location", "communications", "commercial", "other"];
7
- /** `unspecified` is a Purpose only; DataCategory uses `other` for a gap. */
10
+ export declare const DATA_CATEGORIES: readonly string[];
11
+ /** The value an interview answer uses when no more specific data category fits. */
12
+ export declare const UNCATEGORISED_DATA_CATEGORY = "dpv:UncategorisedData";
13
+ /** `unspecified` is a Purpose only; a data category gap is dpv:UncategorisedData. */
8
14
  export declare const PURPOSES: readonly ["service_provision", "analytics", "marketing", "security", "legal_obligation", "research", "debugging", "unspecified"];
9
15
  export declare const ACTOR_KINDS: readonly ["person", "role", "persona"];
10
- export type DataCategory = (typeof DATA_CATEGORIES)[number];
16
+ export type DataCategory = string;
11
17
  export type Purpose = (typeof PURPOSES)[number];
12
18
  export type ActorKind = (typeof ACTOR_KINDS)[number];
@@ -1,25 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ACTOR_KINDS = exports.PURPOSES = exports.DATA_CATEGORIES = void 0;
3
+ exports.ACTOR_KINDS = exports.PURPOSES = exports.UNCATEGORISED_DATA_CATEGORY = exports.DATA_CATEGORIES = void 0;
4
+ const data_category_catalog_generated_1 = require("./data-category-catalog.generated");
4
5
  /**
5
- * Ontology controlled vocabularies used by interview write-back.
6
- * Source: DataParade-io/ontology v0.3.0 (taxonomy/data_category.yaml,
7
- * purpose.yaml, actor_kind.yaml). Update together with PINNED_ONTOLOGY_*.
6
+ * Controlled vocabularies used by interview write-back.
7
+ *
8
+ * Data categories are W3C DPV, DPV-PD and dpx: concepts (DATAP-961), the same concepts the
9
+ * scanner puts on data flows, so interview answers and scan results use one vocabulary. The
10
+ * catalog is generated from the scanner taxonomy by scripts/data-categories/. Purposes and actor
11
+ * kinds come from DataParade-io/ontology (taxonomy/purpose.yaml, actor_kind.yaml); update them
12
+ * together with PINNED_ONTOLOGY_*.
8
13
  */
9
- exports.DATA_CATEGORIES = [
10
- "personal",
11
- "identifiers",
12
- "contact",
13
- "demographic",
14
- "credentials",
15
- "financial",
16
- "health",
17
- "location",
18
- "communications",
19
- "commercial",
20
- "other",
21
- ];
22
- /** `unspecified` is a Purpose only; DataCategory uses `other` for a gap. */
14
+ exports.DATA_CATEGORIES = data_category_catalog_generated_1.DATA_CATEGORY_CONCEPTS.map((concept) => concept.value);
15
+ /** The value an interview answer uses when no more specific data category fits. */
16
+ exports.UNCATEGORISED_DATA_CATEGORY = "dpv:UncategorisedData";
17
+ /** `unspecified` is a Purpose only; a data category gap is dpv:UncategorisedData. */
23
18
  exports.PURPOSES = [
24
19
  "service_provision",
25
20
  "analytics",
@@ -235,7 +235,7 @@ describe("strictParseAndNormalizeProposals / propertyEvidence", () => {
235
235
  });
236
236
  expect(out).toHaveLength(1);
237
237
  if (out[0]?.kind === "component_patch") {
238
- expect(out[0].setProperties.data_categories_received).toEqual(["other"]);
238
+ expect(out[0].setProperties.data_categories_received).toEqual(["dpv:UncategorisedData"]);
239
239
  expect(out[0].setProperties.processing_purpose).toEqual(["service_provision"]);
240
240
  expect(out[0].setProperties.cloud_provider).toBe("AWS");
241
241
  expect(out[0].propertyEvidence?.cloud_provider).toHaveLength(1);
@@ -245,6 +245,23 @@ describe("buildFacts", () => {
245
245
  });
246
246
  expect(schema_1.factsFileSchema.safeParse(facts).success).toBe(true);
247
247
  });
248
+ it("copies the flow relationship, protocol, transport and channel", () => {
249
+ const result = scanResult();
250
+ Object.assign(result.scanResult.dataFlows[0], {
251
+ relationship: "interacts",
252
+ protocol: "mcp",
253
+ transport: "http",
254
+ channel: "mcp",
255
+ });
256
+ const { facts } = (0, build_facts_1.buildFacts)({ result, graph: graph(), ...meta });
257
+ expect(facts.dataFlows[0]).toMatchObject({
258
+ relationship: "interacts",
259
+ protocol: "mcp",
260
+ transport: "http",
261
+ channel: "mcp",
262
+ });
263
+ expect(schema_1.factsFileSchema.safeParse(facts).success).toBe(true);
264
+ });
248
265
  it("leaves authentication out when the scanner did not check the flow", () => {
249
266
  const { facts } = (0, build_facts_1.buildFacts)({ result: scanResult(), graph: graph(), ...meta });
250
267
  expect(facts.dataFlows[0].authentication).toBeUndefined();
@@ -0,0 +1 @@
1
+ export {};
@@ -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
+ const fs_1 = __importDefault(require("fs"));
7
+ const path_1 = __importDefault(require("path"));
8
+ const yaml_1 = require("yaml");
9
+ const data_category_catalog_generated_1 = require("../../../src/kb/data-category-catalog.generated");
10
+ function readPinnedScannerTaxonomy() {
11
+ let scannerPackageDirectory = path_1.default.dirname(require.resolve("../../../vendor/scanner/dist/src/index.js"));
12
+ while (!fs_1.default.existsSync(path_1.default.join(scannerPackageDirectory, "patterns", "personal-data-taxonomy.yaml"))) {
13
+ const parentDirectory = path_1.default.dirname(scannerPackageDirectory);
14
+ if (parentDirectory === scannerPackageDirectory)
15
+ throw new Error("Scanner personal-data taxonomy not found");
16
+ scannerPackageDirectory = parentDirectory;
17
+ }
18
+ const taxonomyPath = path_1.default.join(scannerPackageDirectory, "patterns", "personal-data-taxonomy.yaml");
19
+ return (0, yaml_1.parse)(fs_1.default.readFileSync(taxonomyPath, "utf8"));
20
+ }
21
+ describe("data category catalog (DATAP-961)", () => {
22
+ const scannerTaxonomy = readPinnedScannerTaxonomy();
23
+ it("was generated from the pinned scanner's taxonomy", () => {
24
+ expect(data_category_catalog_generated_1.DATA_CATEGORY_SCANNER_TAXONOMY_VERSION).toBe(String(scannerTaxonomy.version));
25
+ });
26
+ it("lists every concept the pinned scanner can put on a data flow, under the same parent", () => {
27
+ for (const scannerConcept of scannerTaxonomy.concepts) {
28
+ const catalogConcept = (0, data_category_catalog_generated_1.findDataCategoryConcept)(scannerConcept.id);
29
+ expect(catalogConcept).toBeDefined();
30
+ expect(catalogConcept?.parent).toBe(scannerConcept.broader);
31
+ }
32
+ });
33
+ it("names every concept as a DPV, DPV-PD or dpx compact IRI with a label", () => {
34
+ for (const concept of data_category_catalog_generated_1.DATA_CATEGORY_CONCEPTS) {
35
+ expect(concept.value).toMatch(/^(dpv|pd|dpx):[A-Z][A-Za-z0-9]*$/);
36
+ expect(concept.label.length).toBeGreaterThan(0);
37
+ }
38
+ });
39
+ it("maps the ontology v0.3.0 interview categories to DPV concepts", () => {
40
+ const interviewCategories = [
41
+ "personal",
42
+ "identifiers",
43
+ "contact",
44
+ "demographic",
45
+ "credentials",
46
+ "financial",
47
+ "health",
48
+ "location",
49
+ "communications",
50
+ "commercial",
51
+ "other",
52
+ ];
53
+ for (const interviewCategory of interviewCategories) {
54
+ expect((0, data_category_catalog_generated_1.resolveCatalogDataCategoryValue)(interviewCategory)).toMatch(/^(dpv|pd):/);
55
+ }
56
+ expect((0, data_category_catalog_generated_1.resolveCatalogDataCategoryValue)("credentials")).toBe("pd:Authenticating");
57
+ });
58
+ it("marks authentication, health and financial data as sensitive", () => {
59
+ expect((0, data_category_catalog_generated_1.isSensitiveDataCategory)("pd:Password")).toBe(true);
60
+ expect((0, data_category_catalog_generated_1.isSensitiveDataCategory)("dpx:AccessToken")).toBe(true);
61
+ expect((0, data_category_catalog_generated_1.isSensitiveDataCategory)("pd:MedicalHealth")).toBe(true);
62
+ expect((0, data_category_catalog_generated_1.isSensitiveDataCategory)("pd:PaymentCardNumber")).toBe(true);
63
+ expect((0, data_category_catalog_generated_1.isSensitiveDataCategory)("pd:EmailAddress")).toBe(false);
64
+ });
65
+ });
@@ -62,7 +62,7 @@ describe("live interview loop: brief → land → project", () => {
62
62
  });
63
63
  it("lands confirmed answers and projects them onto the diagram", () => {
64
64
  const { sha } = (0, brief_1.writeKbBrief)(paths);
65
- land(sha, "flow_mail", "data_categories", "contact, identifiers");
65
+ land(sha, "flow_mail", "data_categories", "pd:EmailAddress, dpx:AccessToken");
66
66
  land(sha, "flow_mail", "purpose", "service_provision");
67
67
  land(sha, "cmp_user", "actor_kind", "persona");
68
68
  land(sha, "dp:a0/system", "in_scope", "The DataParade web app and its backend");
@@ -72,7 +72,7 @@ describe("live interview loop: brief → land → project", () => {
72
72
  const { wrapper } = (0, project_diagram_1.writeKbDiagram)(paths, { projectName: "DataParade" });
73
73
  const mail = wrapper.graph.edges.find((e) => e.id === "flow_mail");
74
74
  expect(mail.data.privacy).toMatchObject({
75
- dataCategories: ["contact", "identifiers"],
75
+ dataCategories: ["dpx:AccessToken", "pd:EmailAddress"],
76
76
  purpose: "service_provision",
77
77
  slotStatus: "known",
78
78
  openSlots: [],
@@ -97,6 +97,7 @@ describe("live interview loop: brief → land → project", () => {
97
97
  it.each([
98
98
  ["an invented category", "flow_mail", "data_categories", "emails", {}, /unknown data category/],
99
99
  ["unspecified as a category", "flow_mail", "data_categories", "unspecified", {}, /no 'unspecified'/],
100
+ ["a well-formed concept outside the catalog", "flow_mail", "data_categories", "pd:Invented", {}, /unknown data category/],
100
101
  ["a purpose outside the enum", "flow_mail", "purpose", "billing", {}, /purpose must be one of/],
101
102
  ["two actor kinds", "cmp_user", "actor_kind", "Customer (persona)", {}, /exactly one of/],
102
103
  ["a scan-owned slot", "cmp_mail", "name", "SendGrid Inc", {}, /can't land from an interview/],
@@ -135,7 +136,7 @@ describe("live interview loop: brief → land → project", () => {
135
136
  });
136
137
  it("stores the who, when and evidence of an interview answer, with a category list as a list", () => {
137
138
  const { sha } = (0, brief_1.writeKbBrief)(paths);
138
- const landed = land(sha, "flow_mail", "data_categories", "identifiers, contact", { now: new Date("2026-10-10T12:00:00.000Z") });
139
+ const landed = land(sha, "flow_mail", "data_categories", "identifiers, contact, pd:Password", { now: new Date("2026-10-10T12:00:00.000Z") });
139
140
  expect(landed.path).toBe(paths.answersPath);
140
141
  expect((0, io_1.readAnswers)(paths).answers).toEqual([
141
142
  {
@@ -143,7 +144,7 @@ describe("live interview loop: brief → land → project", () => {
143
144
  factId: "flow_mail",
144
145
  action: "set",
145
146
  property: "data_categories",
146
- value: ["contact", "identifiers"],
147
+ value: ["pd:Contact", "pd:Identifying", "pd:Password"],
147
148
  by: REVIEWER,
148
149
  at: "2026-10-10T12:00:00.000Z",
149
150
  source: "interview",
@@ -69,14 +69,14 @@ describe("kb migrate", () => {
69
69
  briefSha: SHA,
70
70
  skillSha: SHA,
71
71
  });
72
- expect(answers.find((a) => a.property === "data_categories")?.value).toEqual(["contact"]);
72
+ expect(answers.find((a) => a.property === "data_categories")?.value).toEqual(["pd:Contact"]);
73
73
  expect(JSON.stringify(answers)).not.toContain(SCAN_PATH);
74
74
  });
75
75
  it("makes the old answers show up in the applied state", () => {
76
76
  (0, migrate_1.migrateInterviewRecords)(paths);
77
77
  const flow = (0, kb_store_1.loadKbState)(paths).applied.facts.dataFlows.find((f) => f.id === "flow_mail");
78
78
  expect(flow.purpose).toBe("marketing");
79
- expect(flow.data_categories).toEqual(["contact"]);
79
+ expect(flow.data_categories).toEqual(["pd:Contact"]);
80
80
  });
81
81
  it("is safe to run twice", () => {
82
82
  (0, migrate_1.migrateInterviewRecords)(paths);
@@ -117,6 +117,11 @@ describe("buildThreatModel", () => {
117
117
  expect(informationDisclosureThreat?.ruleStatus).toBe("open");
118
118
  expect(informationDisclosureThreat?.statusRuleId).toBeDefined();
119
119
  });
120
+ it("gives a structural flow no threats and leaves it out of its components' threats", () => {
121
+ const threatModel = (0, build_threat_model_1.buildThreatModel)(factsWith([mailFlowWith({ relationship: "uses_in_process", controls: flowWithTlsAndTimeoutControls.controls })]));
122
+ expect(categoriesOfElement(threatModel, "flow_mail")).toBe("");
123
+ expect(findThreat(threatModel, "cmp_mail", "S")?.ruleStatus).toBe("unknown");
124
+ });
120
125
  it("names the element by id, kind, framework element kind and identity key", () => {
121
126
  const threatModel = (0, build_threat_model_1.buildThreatModel)(factsWith([mailFlowWith()]));
122
127
  expect(findThreat(threatModel, "cmp_api", "S")).toMatchObject({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataparade/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "dataPARADE CLI — scan codebases for privacy and security data flows",
5
5
  "publishConfig": {
6
6
  "access": "public",