@dataparade/cli 0.0.31 → 0.0.33
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/README.md +56 -1
- package/dist/package.json +4 -3
- package/dist/src/ai-enrichment/fallbacks.js +12 -1
- package/dist/src/cli.js +50 -4
- package/dist/src/core/pipeline/omit-internal-implementation.js +13 -6
- package/dist/src/diff/register-diff-command.d.ts +4 -0
- package/dist/src/diff/register-diff-command.js +79 -0
- package/dist/src/diff/run-diff.d.ts +80 -0
- package/dist/src/diff/run-diff.js +206 -0
- package/dist/src/diff/upload-diff.d.ts +26 -0
- package/dist/src/diff/upload-diff.js +69 -0
- package/dist/src/facts/apply-answers.js +1 -1
- package/dist/src/facts/build-facts.d.ts +3 -1
- package/dist/src/facts/build-facts.js +10 -1
- package/dist/src/facts/identity.d.ts +27 -0
- package/dist/src/facts/identity.js +203 -0
- package/dist/src/facts/io.d.ts +2 -0
- package/dist/src/facts/io.js +7 -0
- package/dist/src/facts/scan-stamps.d.ts +55 -0
- package/dist/src/facts/scan-stamps.js +165 -0
- package/dist/src/facts/schema.d.ts +243 -7
- package/dist/src/facts/schema.js +71 -1
- package/dist/src/kb/answer-fingerprint.d.ts +44 -0
- package/dist/src/kb/answer-fingerprint.js +173 -0
- package/dist/src/kb/brief.d.ts +8 -1
- package/dist/src/kb/brief.js +18 -2
- package/dist/src/kb/land.js +3 -0
- package/dist/src/kb/register-kb-commands.js +7 -1
- package/dist/src/output/git-context.d.ts +25 -0
- package/dist/src/output/git-context.js +122 -0
- package/dist/src/output/scan-output-excludes.js +5 -1
- package/dist/src/output/write-scan-knowledge.d.ts +2 -0
- package/dist/src/output/write-scan-knowledge.js +1 -0
- package/dist/src/platform-api/dataparade-app-base-url.d.ts +8 -4
- package/dist/src/platform-api/dataparade-app-base-url.js +10 -5
- package/dist/src/platform-api/upload-client.d.ts +1 -1
- package/dist/src/platform-api/upload-client.js +32 -1
- package/dist/src/platform-api/upload.types.d.ts +55 -0
- package/dist/src/sensitive-scan/process.d.ts +5 -0
- package/dist/src/sensitive-scan/process.js +48 -0
- package/dist/src/sensitive-scan/project.d.ts +12 -0
- package/dist/src/sensitive-scan/project.js +177 -0
- package/dist/src/sensitive-scan/report.d.ts +50 -0
- package/dist/src/sensitive-scan/report.js +32 -0
- package/dist/src/sensitive-scan/sessions.d.ts +2 -0
- package/dist/src/sensitive-scan/sessions.js +120 -0
- package/dist/src/ui/scan-progress-renderer.d.ts +1 -0
- package/dist/src/ui/scan-progress-renderer.js +8 -0
- package/dist/src/upload/build-preview-url.d.ts +2 -2
- package/dist/src/upload/build-preview-url.js +4 -4
- package/dist/src/upload/run-upload.js +6 -2
- package/dist/src/upload/types.d.ts +2 -0
- package/dist/tests/unit/ai-enrichment/fallbacks.spec.js +30 -0
- package/dist/tests/unit/core/omit-internal-implementation.spec.js +21 -0
- package/dist/tests/unit/diff/run-diff.spec.d.ts +1 -0
- package/dist/tests/unit/diff/run-diff.spec.js +189 -0
- package/dist/tests/unit/diff/upload-diff.spec.d.ts +1 -0
- package/dist/tests/unit/diff/upload-diff.spec.js +81 -0
- package/dist/tests/unit/facts/apply-answers.spec.js +1 -1
- package/dist/tests/unit/facts/build-facts.spec.js +67 -1
- package/dist/tests/unit/facts/identity.spec.d.ts +1 -0
- package/dist/tests/unit/facts/identity.spec.js +148 -0
- package/dist/tests/unit/facts/scan-stamps.spec.d.ts +1 -0
- package/dist/tests/unit/facts/scan-stamps.spec.js +95 -0
- package/dist/tests/unit/kb/answer-fingerprint.spec.d.ts +1 -0
- package/dist/tests/unit/kb/answer-fingerprint.spec.js +157 -0
- package/dist/tests/unit/kb/kb-interview-loop.spec.js +16 -0
- package/dist/tests/unit/output/git-context.spec.d.ts +1 -0
- package/dist/tests/unit/output/git-context.spec.js +98 -0
- package/dist/tests/unit/platform-api/dataparade-app-base-url.spec.js +9 -0
- package/dist/tests/unit/platform-api/upload-client.spec.js +101 -1
- package/dist/tests/unit/sensitive-scan/project.spec.d.ts +1 -0
- package/dist/tests/unit/sensitive-scan/project.spec.js +98 -0
- package/dist/tests/unit/upload/build-preview-url.spec.js +4 -0
- package/dist/tests/unit/upload/collect-scan-sidecars.spec.js +1 -0
- package/dist/tests/unit/upload/run-upload.spec.js +32 -0
- package/dist/vendor/kb-compare/dist/src/canonical.d.ts +80 -0
- package/dist/vendor/kb-compare/dist/src/canonical.js +119 -0
- package/dist/vendor/kb-compare/dist/src/change-set.d.ts +144 -0
- package/dist/vendor/kb-compare/dist/src/change-set.js +80 -0
- package/dist/vendor/kb-compare/dist/src/comparable.d.ts +23 -0
- package/dist/vendor/kb-compare/dist/src/comparable.js +48 -0
- package/dist/vendor/kb-compare/dist/src/compare.d.ts +52 -0
- package/dist/vendor/kb-compare/dist/src/compare.js +370 -0
- package/dist/vendor/kb-compare/dist/src/fingerprint.d.ts +40 -0
- package/dist/vendor/kb-compare/dist/src/fingerprint.js +88 -0
- package/dist/vendor/kb-compare/dist/src/index.d.ts +15 -0
- package/dist/vendor/kb-compare/dist/src/index.js +34 -0
- package/dist/vendor/kb-compare/dist/src/input.d.ts +128 -0
- package/dist/vendor/kb-compare/dist/src/input.js +75 -0
- package/dist/vendor/kb-compare/dist/src/slot-rules.d.ts +69 -0
- package/dist/vendor/kb-compare/dist/src/slot-rules.js +203 -0
- package/dist/vendor/kb-compare/dist/src/summary.d.ts +3 -0
- package/dist/vendor/kb-compare/dist/src/summary.js +47 -0
- package/dist/vendor/kb-compare/package.json +6 -0
- package/dist/vendor/scanner/dist/src/analyzers/python/python-detection-config.d.ts +11 -0
- package/dist/vendor/scanner/dist/src/analyzers/python/python-detection-config.js +2 -0
- package/dist/vendor/scanner/dist/src/analyzers/registry.d.ts +2 -0
- package/dist/vendor/scanner/dist/src/analyzers/registry.js +3 -2
- package/dist/vendor/scanner/dist/src/analyzers/typescript/typescript-detection-config.d.ts +17 -0
- package/dist/vendor/scanner/dist/src/analyzers/typescript/typescript-detection-config.js +11 -0
- package/dist/vendor/scanner/dist/src/classifier/application-injection.js +5 -0
- package/dist/vendor/scanner/dist/src/classifier/component-factory.js +33 -3
- package/dist/vendor/scanner/dist/src/classifier/enhance.js +14 -0
- package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.d.ts +8 -0
- package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.js +43 -2
- package/dist/vendor/scanner/dist/src/classifier/postprocessing.js +4 -1
- package/dist/vendor/scanner/dist/src/config/third-party-detection-config.d.ts +41 -0
- package/dist/vendor/scanner/dist/src/config/third-party-detection-config.js +65 -1
- package/dist/vendor/scanner/dist/src/core/pipeline/stable-component-ids.d.ts +8 -0
- package/dist/vendor/scanner/dist/src/core/pipeline/stable-component-ids.js +11 -1
- package/dist/vendor/scanner/dist/src/core/pipeline/structural-scan.js +2 -0
- package/dist/vendor/scanner/dist/src/eval/canonical/scanner/components.d.ts +5 -0
- package/dist/vendor/scanner/dist/src/eval/canonical/scanner/components.js +10 -2
- package/dist/vendor/scanner/dist/src/eval/canonical/scanner/data-flows.js +4 -4
- package/dist/vendor/scanner/dist/src/index.d.ts +1 -1
- package/dist/vendor/scanner/dist/src/index.js +4 -2
- package/dist/vendor/scanner/dist/src/patterns/config.js +7 -1
- package/dist/vendor/scanner/dist/src/patterns/detectors/git-remote-owner.d.ts +14 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/git-remote-owner.js +108 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python-outbound-http.d.ts +93 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python-outbound-http.js +1206 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python-source.d.ts +180 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python-source.js +1022 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python.d.ts +6 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python.js +49 -1
- package/dist/vendor/scanner/dist/src/patterns/detectors/repo-declared-domains.d.ts +2 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/repo-declared-domains.js +80 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/source-module-index.d.ts +23 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/source-module-index.js +145 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/typescript-outbound-http.d.ts +30 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/typescript-outbound-http.js +575 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/typescript.js +12 -0
- package/dist/vendor/scanner/dist/src/patterns/engine.js +6 -1
- package/dist/vendor/scanner/package.json +3 -1
- package/dist/vendor/scanner/patterns/classifier/third-party.classifier.yaml +198 -0
- package/dist/vendor/scanner/patterns/component-taxonomy.yaml +1 -1
- package/dist/vendor/scanner/patterns/python.patterns.yaml +10 -0
- package/dist/vendor/scanner/patterns/third-party.patterns.yaml +271 -0
- package/dist/vendor/scanner/patterns/typescript.patterns.yaml +21 -0
- package/package.json +4 -3
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Fingerprint } from "../../vendor/kb-compare/dist/src/index.js";
|
|
2
|
+
import type { Answer, FactsFile } from "../facts/schema";
|
|
3
|
+
import { type KbPaths } from "./kb-store";
|
|
4
|
+
/**
|
|
5
|
+
* Identity keys and evidence fingerprints on answers (DATAP-873).
|
|
6
|
+
*
|
|
7
|
+
* Each answer records the identity key of its element and the element's fingerprint at the
|
|
8
|
+
* time of the answer, so the slot rules (DATAP-874) can find the element in a later scan and
|
|
9
|
+
* decide whether the answer still holds. Answers about the whole system (`dp:a0/system`) keep
|
|
10
|
+
* that URI as their key and have no fingerprint: no element change can make them stale.
|
|
11
|
+
*/
|
|
12
|
+
export type AnswerSubject = Fingerprint["subject"];
|
|
13
|
+
export interface AnswerElement {
|
|
14
|
+
subject: AnswerSubject;
|
|
15
|
+
key: string;
|
|
16
|
+
}
|
|
17
|
+
/** The element a Fact id names in a scan, by its identity. Null when the scan has no such Fact or it has no identity. */
|
|
18
|
+
export declare function elementOfFact(facts: FactsFile, factId: string): AnswerElement | null;
|
|
19
|
+
/** Identity key and fingerprint fields for an answer about `factId`, from the scan it was given against. */
|
|
20
|
+
export declare function fingerprintFields(facts: FactsFile, factId: string): Pick<Answer, "identityKey" | "fingerprint" | "fingerprintSource">;
|
|
21
|
+
export type MigrationOutcome = "brief" | "scan" | "root" | "system" | "unresolved";
|
|
22
|
+
export interface MigrateFingerprintsResult {
|
|
23
|
+
/** Answers given an identity key (and a fingerprint where the element is in the current scan). */
|
|
24
|
+
migrated: number;
|
|
25
|
+
/** Answers that already had an identity key. */
|
|
26
|
+
alreadyKeyed: number;
|
|
27
|
+
/** How each migrated or unresolved answer found its element, by answer id. */
|
|
28
|
+
outcomes: Record<string, MigrationOutcome>;
|
|
29
|
+
/** Answers with a key whose element is not in the current scan: they keep the key and have no fingerprint. */
|
|
30
|
+
withoutFingerprint: string[];
|
|
31
|
+
/** Answers no brief or scan could key. */
|
|
32
|
+
unresolved: string[];
|
|
33
|
+
dryRun: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Give each answer without an identity key its key and a fingerprint (`fingerprintSource:
|
|
37
|
+
* migrated`). The key comes from the brief the answer cites; failing that, from the Fact with
|
|
38
|
+
* the same id in the current scan; failing that, for the root Application whose id changed
|
|
39
|
+
* once (DATAP-858), from the project-name token. The fingerprint is computed from the current
|
|
40
|
+
* scan. Answers on occurrences stay unkeyed: they are outside the carry rules (DATAP-862).
|
|
41
|
+
*/
|
|
42
|
+
export declare function migrateAnswerFingerprints(paths: KbPaths, options?: {
|
|
43
|
+
dryRun?: boolean;
|
|
44
|
+
}): MigrateFingerprintsResult;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.elementOfFact = elementOfFact;
|
|
4
|
+
exports.fingerprintFields = fingerprintFields;
|
|
5
|
+
exports.migrateAnswerFingerprints = migrateAnswerFingerprints;
|
|
6
|
+
const kb_compare_1 = require("../../vendor/kb-compare/dist/src/index.js");
|
|
7
|
+
const scanner_1 = require("../../vendor/scanner/dist/src/index.js");
|
|
8
|
+
const io_1 = require("../facts/io");
|
|
9
|
+
const brief_1 = require("./brief");
|
|
10
|
+
const kb_store_1 = require("./kb-store");
|
|
11
|
+
const slot_shapes_1 = require("./slot-shapes");
|
|
12
|
+
/** The element a Fact id names in a scan, by its identity. Null when the scan has no such Fact or it has no identity. */
|
|
13
|
+
function elementOfFact(facts, factId) {
|
|
14
|
+
for (const c of facts.components) {
|
|
15
|
+
if (c.id === factId && c.identity)
|
|
16
|
+
return { subject: "component", key: c.identity.key };
|
|
17
|
+
}
|
|
18
|
+
for (const f of facts.dataFlows) {
|
|
19
|
+
if (f.id === factId && f.identity)
|
|
20
|
+
return { subject: "dataFlow", key: f.identity.key };
|
|
21
|
+
}
|
|
22
|
+
for (const item of facts.dataItems) {
|
|
23
|
+
if (item.id === factId && item.identity)
|
|
24
|
+
return { subject: "dataItem", key: item.identity.key };
|
|
25
|
+
for (const g of item.groups) {
|
|
26
|
+
if (g.id === factId && g.identity)
|
|
27
|
+
return { subject: "group", key: g.identity.key };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
/** Identity key and fingerprint fields for an answer about `factId`, from the scan it was given against. */
|
|
33
|
+
function fingerprintFields(facts, factId) {
|
|
34
|
+
if (factId === slot_shapes_1.SYSTEM_ASSERTS_URI) {
|
|
35
|
+
return { identityKey: slot_shapes_1.SYSTEM_ASSERTS_URI, fingerprintSource: "landed" };
|
|
36
|
+
}
|
|
37
|
+
const element = elementOfFact(facts, factId);
|
|
38
|
+
if (!element)
|
|
39
|
+
return {};
|
|
40
|
+
const fingerprint = (0, kb_compare_1.fingerprintOf)(facts, element.subject, element.key);
|
|
41
|
+
return {
|
|
42
|
+
identityKey: element.key,
|
|
43
|
+
...(fingerprint ? { fingerprint } : {}),
|
|
44
|
+
fingerprintSource: "landed",
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** The element the brief recorded for a Fact id: a component (actor, external system, flow endpoint) or a flow. */
|
|
48
|
+
function elementFromBrief(brief, factId) {
|
|
49
|
+
for (const flow of brief.flows) {
|
|
50
|
+
if ((flow.id === factId || flow.asserts === factId) && flow.identity) {
|
|
51
|
+
return { subject: "dataFlow", key: flow.identity.key };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const entities = [
|
|
55
|
+
...brief.actors,
|
|
56
|
+
...brief.external_systems,
|
|
57
|
+
...brief.flows.flatMap((flow) => [flow.source, flow.target]),
|
|
58
|
+
];
|
|
59
|
+
for (const entity of entities) {
|
|
60
|
+
if ((entity.id === factId || entity.asserts === factId) && entity.identity) {
|
|
61
|
+
return { subject: "component", key: entity.identity.key };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
/** The root Application of a scan: the component keyed by the project-name token (DATAP-858). */
|
|
67
|
+
function rootApplicationKey(facts) {
|
|
68
|
+
const roots = facts.components.filter((c) => c.identity?.key.endsWith(`|${scanner_1.PROJECT_NAME_KEY_TOKEN}`));
|
|
69
|
+
return roots.length === 1 ? roots[0].identity.key : null;
|
|
70
|
+
}
|
|
71
|
+
/** An `app:` key with its name segment swapped for the project-name token. */
|
|
72
|
+
function withProjectNameToken(key) {
|
|
73
|
+
if (!key.startsWith("app:"))
|
|
74
|
+
return null;
|
|
75
|
+
const at = key.lastIndexOf("|");
|
|
76
|
+
return at === -1 ? null : `${key.slice(0, at)}|${scanner_1.PROJECT_NAME_KEY_TOKEN}`;
|
|
77
|
+
}
|
|
78
|
+
/** The brief's entity name for a Fact id, when the brief names it. */
|
|
79
|
+
function briefEntityName(brief, factId) {
|
|
80
|
+
const entities = [...brief.actors, ...brief.external_systems, ...brief.flows.flatMap((f) => [f.source, f.target])];
|
|
81
|
+
return entities.find((e) => e.id === factId || e.asserts === factId)?.name ?? null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Give each answer without an identity key its key and a fingerprint (`fingerprintSource:
|
|
85
|
+
* migrated`). The key comes from the brief the answer cites; failing that, from the Fact with
|
|
86
|
+
* the same id in the current scan; failing that, for the root Application whose id changed
|
|
87
|
+
* once (DATAP-858), from the project-name token. The fingerprint is computed from the current
|
|
88
|
+
* scan. Answers on occurrences stay unkeyed: they are outside the carry rules (DATAP-862).
|
|
89
|
+
*/
|
|
90
|
+
function migrateAnswerFingerprints(paths, options = {}) {
|
|
91
|
+
const state = (0, kb_store_1.loadKbState)(paths);
|
|
92
|
+
const file = (0, io_1.readAnswers)(paths);
|
|
93
|
+
const facts = state.facts;
|
|
94
|
+
const root = rootApplicationKey(facts);
|
|
95
|
+
const briefs = new Map();
|
|
96
|
+
const briefFor = (sha) => {
|
|
97
|
+
if (!sha)
|
|
98
|
+
return null;
|
|
99
|
+
if (!briefs.has(sha)) {
|
|
100
|
+
try {
|
|
101
|
+
briefs.set(sha, (0, brief_1.readKbBrief)(paths, sha));
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (!(error instanceof kb_store_1.KbError))
|
|
105
|
+
throw error;
|
|
106
|
+
briefs.set(sha, null);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return briefs.get(sha) ?? null;
|
|
110
|
+
};
|
|
111
|
+
const result = {
|
|
112
|
+
migrated: 0,
|
|
113
|
+
alreadyKeyed: 0,
|
|
114
|
+
outcomes: {},
|
|
115
|
+
withoutFingerprint: [],
|
|
116
|
+
unresolved: [],
|
|
117
|
+
dryRun: Boolean(options.dryRun),
|
|
118
|
+
};
|
|
119
|
+
const next = file.answers.map((answer) => {
|
|
120
|
+
if (answer.identityKey) {
|
|
121
|
+
result.alreadyKeyed += 1;
|
|
122
|
+
return answer;
|
|
123
|
+
}
|
|
124
|
+
if (answer.factId === slot_shapes_1.SYSTEM_ASSERTS_URI) {
|
|
125
|
+
result.migrated += 1;
|
|
126
|
+
result.outcomes[answer.id] = "system";
|
|
127
|
+
return { ...answer, identityKey: slot_shapes_1.SYSTEM_ASSERTS_URI, fingerprintSource: "migrated" };
|
|
128
|
+
}
|
|
129
|
+
const brief = briefFor(answer.briefSha);
|
|
130
|
+
let element = brief ? elementFromBrief(brief, answer.factId) : null;
|
|
131
|
+
let outcome = element ? "brief" : "unresolved";
|
|
132
|
+
if (!element) {
|
|
133
|
+
element = elementOfFact(facts, answer.factId);
|
|
134
|
+
if (element)
|
|
135
|
+
outcome = "scan";
|
|
136
|
+
}
|
|
137
|
+
if (element?.subject === "component" && root && !(0, kb_compare_1.fingerprintOf)(facts, "component", element.key)) {
|
|
138
|
+
// A brief key from before DATAP-858 names the root by its folder; the scan now uses the token.
|
|
139
|
+
if (withProjectNameToken(element.key) === root) {
|
|
140
|
+
element = { subject: "component", key: root };
|
|
141
|
+
outcome = "root";
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (!element && brief && root) {
|
|
145
|
+
// A brief without identities (CLI 0.0.32 and earlier) that names the root Application.
|
|
146
|
+
const rootFact = facts.components.find((c) => c.identity?.key === root);
|
|
147
|
+
if (rootFact && briefEntityName(brief, answer.factId) === rootFact.name) {
|
|
148
|
+
element = { subject: "component", key: root };
|
|
149
|
+
outcome = "root";
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (!element) {
|
|
153
|
+
result.unresolved.push(answer.id);
|
|
154
|
+
result.outcomes[answer.id] = "unresolved";
|
|
155
|
+
return answer;
|
|
156
|
+
}
|
|
157
|
+
result.migrated += 1;
|
|
158
|
+
result.outcomes[answer.id] = outcome;
|
|
159
|
+
const fingerprint = (0, kb_compare_1.fingerprintOf)(facts, element.subject, element.key);
|
|
160
|
+
if (!fingerprint)
|
|
161
|
+
result.withoutFingerprint.push(answer.id);
|
|
162
|
+
return {
|
|
163
|
+
...answer,
|
|
164
|
+
identityKey: element.key,
|
|
165
|
+
...(fingerprint ? { fingerprint } : {}),
|
|
166
|
+
fingerprintSource: "migrated",
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
if (!options.dryRun && result.migrated > 0) {
|
|
170
|
+
(0, io_1.writeAnswers)(paths, { ...file, answers: next });
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
}
|
package/dist/src/kb/brief.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { A0DiscoveriesDocument } from "../discoveries/contract/discoveries-document.schema";
|
|
2
|
+
import type { FactsFile, Identity } from "../facts/schema";
|
|
2
3
|
import { type KbPaths } from "./kb-store";
|
|
3
4
|
import { type EligibleShape, type InterviewSlot } from "./slot-shapes";
|
|
4
5
|
/**
|
|
@@ -13,6 +14,8 @@ export interface KbBriefEntity {
|
|
|
13
14
|
asserts: string;
|
|
14
15
|
name: string;
|
|
15
16
|
type: string;
|
|
17
|
+
/** The Fact's identity (DATAP-842), so an answer can be matched in a later scan. Absent for KBs from CLI 0.0.32 and earlier. */
|
|
18
|
+
identity?: Identity;
|
|
16
19
|
}
|
|
17
20
|
export type FlowCrossing = "outbound_third_party" | "from_actor" | "internal";
|
|
18
21
|
export interface KbBriefFlow {
|
|
@@ -24,6 +27,8 @@ export interface KbBriefFlow {
|
|
|
24
27
|
target: KbBriefEntity;
|
|
25
28
|
data_categories: string[] | null;
|
|
26
29
|
purpose: string | null;
|
|
30
|
+
/** The flow's identity (DATAP-842). Absent for KBs from CLI 0.0.32 and earlier. */
|
|
31
|
+
identity?: Identity;
|
|
27
32
|
}
|
|
28
33
|
export interface KbBriefQuestion {
|
|
29
34
|
asserts: string;
|
|
@@ -48,7 +53,9 @@ export interface KbBrief {
|
|
|
48
53
|
/** Interview order: scope, outbound third-party flows, then people (no internal or from-actor flow slots). */
|
|
49
54
|
questions: KbBriefQuestion[];
|
|
50
55
|
}
|
|
51
|
-
|
|
56
|
+
/** Identities of the scan's components and flows, by Fact id. */
|
|
57
|
+
export declare function factIdentities(facts: FactsFile): Map<string, Identity>;
|
|
58
|
+
export declare function buildKbBrief(document: A0DiscoveriesDocument, identities?: ReadonlyMap<string, Identity>): KbBrief;
|
|
52
59
|
/** 40-hex SHA-1 of the canonical brief: the form the ontology requires for `brief_sha`. */
|
|
53
60
|
export declare function kbBriefSha(brief: KbBrief): string;
|
|
54
61
|
export interface WrittenKbBrief {
|
package/dist/src/kb/brief.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.factIdentities = factIdentities;
|
|
6
7
|
exports.buildKbBrief = buildKbBrief;
|
|
7
8
|
exports.kbBriefSha = kbBriefSha;
|
|
8
9
|
exports.writeKbBrief = writeKbBrief;
|
|
@@ -22,13 +23,27 @@ function rawEntityId(projectedId) {
|
|
|
22
23
|
function entityAsserts(entity) {
|
|
23
24
|
return rawEntityId(entity.id);
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
+
/** Identities of the scan's components and flows, by Fact id. */
|
|
27
|
+
function factIdentities(facts) {
|
|
28
|
+
const result = new Map();
|
|
29
|
+
for (const fact of [...facts.components, ...facts.dataFlows]) {
|
|
30
|
+
if (fact.identity)
|
|
31
|
+
result.set(fact.id, fact.identity);
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
function buildKbBrief(document, identities = new Map()) {
|
|
26
36
|
const components = new Map(document.components.map((c) => [c.id, c]));
|
|
37
|
+
const withIdentity = (id) => {
|
|
38
|
+
const identity = identities.get(id);
|
|
39
|
+
return identity ? { identity } : {};
|
|
40
|
+
};
|
|
27
41
|
const brief = (c) => ({
|
|
28
42
|
id: rawEntityId(c.id),
|
|
29
43
|
asserts: entityAsserts(c),
|
|
30
44
|
name: c.name,
|
|
31
45
|
type: c.type,
|
|
46
|
+
...withIdentity(rawEntityId(c.id)),
|
|
32
47
|
});
|
|
33
48
|
const actors = document.components
|
|
34
49
|
.filter((c) => c.type === "actor")
|
|
@@ -54,6 +69,7 @@ function buildKbBrief(document) {
|
|
|
54
69
|
target: brief(target),
|
|
55
70
|
data_categories: flow.data_categories ?? null,
|
|
56
71
|
purpose: flow.purpose ?? null,
|
|
72
|
+
...withIdentity(rawEntityId(flow.id)),
|
|
57
73
|
});
|
|
58
74
|
}
|
|
59
75
|
const question = (asserts, slot, known, about) => ({
|
|
@@ -105,7 +121,7 @@ function kbBriefSha(brief) {
|
|
|
105
121
|
/** Snapshot the current KB as a brief and store it at `<kb>/briefs/<sha>.json`. */
|
|
106
122
|
function writeKbBrief(paths) {
|
|
107
123
|
const state = (0, kb_store_1.loadKbState)(paths);
|
|
108
|
-
const brief = buildKbBrief(state.document);
|
|
124
|
+
const brief = buildKbBrief(state.document, factIdentities(state.facts));
|
|
109
125
|
const sha = kbBriefSha(brief);
|
|
110
126
|
(0, kb_store_1.ensureDir)(paths.briefsDir);
|
|
111
127
|
const briefPath = path_1.default.join(paths.briefsDir, `${sha}.json`);
|
package/dist/src/kb/land.js
CHANGED
|
@@ -10,6 +10,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
11
|
const apply_answers_1 = require("../facts/apply-answers");
|
|
12
12
|
const io_1 = require("../facts/io");
|
|
13
|
+
const answer_fingerprint_1 = require("./answer-fingerprint");
|
|
13
14
|
const brief_1 = require("./brief");
|
|
14
15
|
const kb_store_1 = require("./kb-store");
|
|
15
16
|
const slot_shapes_1 = require("./slot-shapes");
|
|
@@ -88,6 +89,7 @@ function landInterviewAnswer(paths, input) {
|
|
|
88
89
|
evidence: evidenceRef,
|
|
89
90
|
briefSha: input.briefSha,
|
|
90
91
|
skillSha: input.skillSha,
|
|
92
|
+
...(0, answer_fingerprint_1.fingerprintFields)(state.facts, factId),
|
|
91
93
|
};
|
|
92
94
|
return store(paths, answer, previousAnswerId(state.answers, factId, slot), input.dryRun);
|
|
93
95
|
}
|
|
@@ -126,6 +128,7 @@ function landReviewAnswer(paths, input) {
|
|
|
126
128
|
at: now.toISOString(),
|
|
127
129
|
source: "review",
|
|
128
130
|
...(input.evidence ? { evidence: input.evidence } : {}),
|
|
131
|
+
...(0, answer_fingerprint_1.fingerprintFields)(state.facts, input.target),
|
|
129
132
|
};
|
|
130
133
|
const trial = (0, apply_answers_1.applyAnswers)(state.facts, state.dataItemFiles, [answer]);
|
|
131
134
|
if (trial.orphans.length > 0) {
|
|
@@ -4,6 +4,7 @@ exports.registerKbCommands = registerKbCommands;
|
|
|
4
4
|
const layout_1 = require("../facts/layout");
|
|
5
5
|
const brief_1 = require("./brief");
|
|
6
6
|
const kb_store_1 = require("./kb-store");
|
|
7
|
+
const answer_fingerprint_1 = require("./answer-fingerprint");
|
|
7
8
|
const migrate_1 = require("./migrate");
|
|
8
9
|
const land_1 = require("./land");
|
|
9
10
|
const project_diagram_1 = require("./project-diagram");
|
|
@@ -111,12 +112,17 @@ function registerKbCommands(program) {
|
|
|
111
112
|
}
|
|
112
113
|
});
|
|
113
114
|
kb.command("migrate")
|
|
114
|
-
.description("Convert interview records from an old ocsf-discoveries/ folder (CLI 0.0.26 and earlier) into answers.json")
|
|
115
|
+
.description("Convert interview records from an old ocsf-discoveries/ folder (CLI 0.0.26 and earlier) into answers.json, or with --fingerprints give old answers an identity key and fingerprint")
|
|
115
116
|
.option("--kb <dir>", "Knowledge base directory", DEFAULT_KB_DIR)
|
|
116
117
|
.option("--from <dir>", "Old OCSF folder (default: <kb>/ocsf-discoveries)")
|
|
118
|
+
.option("--fingerprints", "Add identity keys and fingerprints to answers that have none (from the cited brief and the current scan)")
|
|
117
119
|
.option("--dry-run", "Count what would be migrated without writing")
|
|
118
120
|
.action((options) => {
|
|
119
121
|
try {
|
|
122
|
+
if (options.fingerprints) {
|
|
123
|
+
print({ ok: true, ...(0, answer_fingerprint_1.migrateAnswerFingerprints)((0, kb_store_1.resolveKbPaths)(options.kb), { dryRun: options.dryRun }) });
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
120
126
|
print({ ok: true, ...(0, migrate_1.migrateInterviewRecords)((0, kb_store_1.resolveKbPaths)(options.kb), { from: options.from, dryRun: options.dryRun }) });
|
|
121
127
|
}
|
|
122
128
|
catch (error) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type GitContextSchema } from '../core/schema/dataflow-wrapper.schema';
|
|
2
|
+
type ParsedRemote = {
|
|
3
|
+
host: string;
|
|
4
|
+
repository: string;
|
|
5
|
+
protocol: string;
|
|
6
|
+
};
|
|
7
|
+
/** Accepts `git@host:owner/repo.git`, `ssh://git@host[:port]/owner/repo` and http(s) remotes. */
|
|
8
|
+
export declare function parseGitRemote(remote: string): ParsedRemote | null;
|
|
9
|
+
/**
|
|
10
|
+
* The remote as `https://host/owner/repo`: SCP-style and ssh remotes become https,
|
|
11
|
+
* the host is lowercased, and credentials, port and `.git` are dropped. The backend
|
|
12
|
+
* matches a repository by this URL when its root commit is unknown (DATAP-883).
|
|
13
|
+
*/
|
|
14
|
+
export declare function normalizeGitRemoteUrl(remote: string): string | null;
|
|
15
|
+
/** Maps a remote to the dataflow git context; null for hosts other than GitHub and GitLab. */
|
|
16
|
+
export declare function gitContextFromRemote(remote: string, commitSha: string): GitContextSchema | null;
|
|
17
|
+
/**
|
|
18
|
+
* Reads the origin remote and HEAD of the repository containing `dir`, so
|
|
19
|
+
* uploads can be matched to their repository. Never throws: no git, no repo
|
|
20
|
+
* or no origin all return null.
|
|
21
|
+
*/
|
|
22
|
+
export declare function detectGitContext(dir: string): GitContextSchema | null;
|
|
23
|
+
/** The normalized origin remote of the repository containing `dir`, or null. Never throws. */
|
|
24
|
+
export declare function readOriginRemoteUrl(dir: string): string | null;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseGitRemote = parseGitRemote;
|
|
4
|
+
exports.normalizeGitRemoteUrl = normalizeGitRemoteUrl;
|
|
5
|
+
exports.gitContextFromRemote = gitContextFromRemote;
|
|
6
|
+
exports.detectGitContext = detectGitContext;
|
|
7
|
+
exports.readOriginRemoteUrl = readOriginRemoteUrl;
|
|
8
|
+
const node_child_process_1 = require("node:child_process");
|
|
9
|
+
const dataflow_wrapper_schema_1 = require("../core/schema/dataflow-wrapper.schema");
|
|
10
|
+
const GIT_TIMEOUT_MS = 5000;
|
|
11
|
+
/** Accepts `git@host:owner/repo.git`, `ssh://git@host[:port]/owner/repo` and http(s) remotes. */
|
|
12
|
+
function parseGitRemote(remote) {
|
|
13
|
+
const trimmed = remote.trim();
|
|
14
|
+
const scp = /^[^@/\s]+@([^:/\s]+):(.+)$/.exec(trimmed);
|
|
15
|
+
let host;
|
|
16
|
+
let path;
|
|
17
|
+
let protocol = 'https:';
|
|
18
|
+
if (scp && !trimmed.includes('://')) {
|
|
19
|
+
host = scp[1];
|
|
20
|
+
path = scp[2];
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
let url;
|
|
24
|
+
try {
|
|
25
|
+
url = new URL(trimmed);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if (!['http:', 'https:', 'ssh:', 'git:'].includes(url.protocol)) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
host = url.hostname;
|
|
34
|
+
path = url.pathname;
|
|
35
|
+
if (url.protocol === 'http:')
|
|
36
|
+
protocol = 'http:';
|
|
37
|
+
}
|
|
38
|
+
const repository = path
|
|
39
|
+
.replace(/^\/+/, '')
|
|
40
|
+
.replace(/\/+$/, '')
|
|
41
|
+
.replace(/\.git$/, '');
|
|
42
|
+
if (!host || !repository.includes('/'))
|
|
43
|
+
return null;
|
|
44
|
+
return { host: host.toLowerCase(), repository, protocol };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The remote as `https://host/owner/repo`: SCP-style and ssh remotes become https,
|
|
48
|
+
* the host is lowercased, and credentials, port and `.git` are dropped. The backend
|
|
49
|
+
* matches a repository by this URL when its root commit is unknown (DATAP-883).
|
|
50
|
+
*/
|
|
51
|
+
function normalizeGitRemoteUrl(remote) {
|
|
52
|
+
const parsed = parseGitRemote(remote);
|
|
53
|
+
if (!parsed)
|
|
54
|
+
return null;
|
|
55
|
+
return `${parsed.protocol}//${parsed.host}/${parsed.repository}`;
|
|
56
|
+
}
|
|
57
|
+
/** Maps a remote to the dataflow git context; null for hosts other than GitHub and GitLab. */
|
|
58
|
+
function gitContextFromRemote(remote, commitSha) {
|
|
59
|
+
const parsed = parseGitRemote(remote);
|
|
60
|
+
if (!parsed)
|
|
61
|
+
return null;
|
|
62
|
+
let candidate;
|
|
63
|
+
if (parsed.host === 'github.com') {
|
|
64
|
+
candidate = {
|
|
65
|
+
provider: 'github',
|
|
66
|
+
repository: parsed.repository,
|
|
67
|
+
commitSha,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
else if (parsed.host === 'gitlab.com') {
|
|
71
|
+
candidate = {
|
|
72
|
+
provider: 'gitlab',
|
|
73
|
+
repository: parsed.repository,
|
|
74
|
+
commitSha,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
else if (parsed.host.includes('gitlab')) {
|
|
78
|
+
candidate = {
|
|
79
|
+
provider: 'gitlab',
|
|
80
|
+
repository: parsed.repository,
|
|
81
|
+
commitSha,
|
|
82
|
+
baseUrl: `${parsed.protocol}//${parsed.host}`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const validated = dataflow_wrapper_schema_1.gitContextSchema.safeParse(candidate);
|
|
89
|
+
return validated.success ? validated.data : null;
|
|
90
|
+
}
|
|
91
|
+
function git(cwd, args) {
|
|
92
|
+
try {
|
|
93
|
+
return (0, node_child_process_1.execFileSync)('git', args, {
|
|
94
|
+
cwd,
|
|
95
|
+
encoding: 'utf8',
|
|
96
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
97
|
+
timeout: GIT_TIMEOUT_MS,
|
|
98
|
+
}).trim();
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Reads the origin remote and HEAD of the repository containing `dir`, so
|
|
106
|
+
* uploads can be matched to their repository. Never throws: no git, no repo
|
|
107
|
+
* or no origin all return null.
|
|
108
|
+
*/
|
|
109
|
+
function detectGitContext(dir) {
|
|
110
|
+
const remote = git(dir, ['remote', 'get-url', 'origin']);
|
|
111
|
+
if (!remote)
|
|
112
|
+
return null;
|
|
113
|
+
const commitSha = git(dir, ['rev-parse', 'HEAD']);
|
|
114
|
+
if (!commitSha)
|
|
115
|
+
return null;
|
|
116
|
+
return gitContextFromRemote(remote, commitSha);
|
|
117
|
+
}
|
|
118
|
+
/** The normalized origin remote of the repository containing `dir`, or null. Never throws. */
|
|
119
|
+
function readOriginRemoteUrl(dir) {
|
|
120
|
+
const remote = git(dir, ['remote', 'get-url', 'origin']);
|
|
121
|
+
return remote ? normalizeGitRemoteUrl(remote) : null;
|
|
122
|
+
}
|
|
@@ -13,6 +13,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
13
13
|
const SCAN_OUTPUT_ENTRIES = [
|
|
14
14
|
"dataflow.json",
|
|
15
15
|
"facts.json",
|
|
16
|
+
"sensitive-findings.json",
|
|
16
17
|
"data-items/**",
|
|
17
18
|
"graphify.json",
|
|
18
19
|
"answers.json",
|
|
@@ -40,5 +41,8 @@ function scanOutputExcludes(scanRoot, dataflowOutputPath) {
|
|
|
40
41
|
return [];
|
|
41
42
|
}
|
|
42
43
|
const prefix = relative ? `${relative.split(path_1.default.sep).join("/")}/` : "";
|
|
43
|
-
return prefix ? [`${prefix}**`] :
|
|
44
|
+
return prefix ? [`${prefix}**`] : [...new Set([
|
|
45
|
+
...SCAN_OUTPUT_ENTRIES,
|
|
46
|
+
path_1.default.basename(dataflowOutputPath),
|
|
47
|
+
])];
|
|
44
48
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type DataParadeGraph, type OrchestratorScanResult } from '../../vendor/scanner/dist/src/index.js';
|
|
2
2
|
import type { OutputLayout } from '../facts/layout';
|
|
3
3
|
import { type DataflowHierarchy } from './c4-hierarchy';
|
|
4
|
+
import type { ScanStamps } from "../facts/schema";
|
|
4
5
|
/**
|
|
5
6
|
* Where Graphify keeps its working files and cache between scans, outside the output
|
|
6
7
|
* folder: `~/.cache/dataparade/graphify/<hash of the scan root>`.
|
|
@@ -28,6 +29,7 @@ export interface WriteScanFactsOptions {
|
|
|
28
29
|
cliVersion: string;
|
|
29
30
|
scannerVersion: string;
|
|
30
31
|
scannedAt?: string;
|
|
32
|
+
stamps?: ScanStamps;
|
|
31
33
|
}
|
|
32
34
|
/** Write facts.json and data-items/. answers.json is not touched. */
|
|
33
35
|
export declare function writeScanFacts(layout: OutputLayout, options: WriteScanFactsOptions): import("../facts/build-facts").BuiltFacts;
|
|
@@ -109,6 +109,7 @@ function writeScanFacts(layout, options) {
|
|
|
109
109
|
cliVersion: options.cliVersion,
|
|
110
110
|
scannerVersion: options.scannerVersion,
|
|
111
111
|
scannedAt: options.scannedAt,
|
|
112
|
+
stamps: options.stamps,
|
|
112
113
|
});
|
|
113
114
|
(0, io_1.writeFactsOutput)(layout, built.facts, built.dataItemFiles);
|
|
114
115
|
return built;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Default DataParade web app
|
|
3
|
-
*
|
|
2
|
+
* Default DataParade web app. Used when the CLI prints dashboard preview links and
|
|
3
|
+
* neither DATAPARADE_APP_URL nor the API's upload response names the app.
|
|
4
4
|
*/
|
|
5
5
|
export declare const DEFAULT_DATAPARADE_APP_URL = "https://app.dataparade.io";
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Resolve web app origin (no trailing slash): DATAPARADE_APP_URL, else the app the API
|
|
8
|
+
* named in its upload response (so an upload to the dev API links to the dev app), else
|
|
9
|
+
* the default.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getDataparadeAppBaseUrl(env?: NodeJS.ProcessEnv, fromApi?: string): string;
|
|
@@ -3,12 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DEFAULT_DATAPARADE_APP_URL = void 0;
|
|
4
4
|
exports.getDataparadeAppBaseUrl = getDataparadeAppBaseUrl;
|
|
5
5
|
/**
|
|
6
|
-
* Default DataParade web app
|
|
7
|
-
*
|
|
6
|
+
* Default DataParade web app. Used when the CLI prints dashboard preview links and
|
|
7
|
+
* neither DATAPARADE_APP_URL nor the API's upload response names the app.
|
|
8
8
|
*/
|
|
9
9
|
exports.DEFAULT_DATAPARADE_APP_URL = "https://app.dataparade.io";
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Resolve web app origin (no trailing slash): DATAPARADE_APP_URL, else the app the API
|
|
12
|
+
* named in its upload response (so an upload to the dev API links to the dev app), else
|
|
13
|
+
* the default.
|
|
14
|
+
*/
|
|
15
|
+
function getDataparadeAppBaseUrl(env = process.env, fromApi) {
|
|
16
|
+
const api = fromApi?.trim();
|
|
17
|
+
const base = env.DATAPARADE_APP_URL?.trim() || (api && /^https?:\/\//.test(api) ? api : "") || exports.DEFAULT_DATAPARADE_APP_URL;
|
|
13
18
|
return base.replace(/\/$/, "");
|
|
14
19
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ScanUploadFile } from '../upload/collect-scan-sidecars';
|
|
2
2
|
import type { CliAnonymousUploadPreviewResponse, CliUploadPreviewInput, CliUploadPreviewResponse } from './upload.types';
|
|
3
|
-
export type { CliAnonymousUploadPreviewResponse, CliUploadPreviewInput, CliUploadPreviewResponse, } from './upload.types';
|
|
3
|
+
export type { CliAnonymousUploadPreviewResponse, CliUploadComparison, CliUploadCompareRequest, CliUploadCompleteResponse, CliUploadPreviewInput, CliUploadPreviewResponse, } from './upload.types';
|
|
4
4
|
/** Upload rejected by the API; `status` is the HTTP status (429 = rate limit). */
|
|
5
5
|
export declare class CliUploadError extends Error {
|
|
6
6
|
readonly status: number;
|
|
@@ -94,7 +94,38 @@ async function cliUploadPreview(input) {
|
|
|
94
94
|
}
|
|
95
95
|
const created = (await res.json());
|
|
96
96
|
if (input.files && input.files.length > 0) {
|
|
97
|
-
|
|
97
|
+
const draftUrl = `${(0, dataparade_api_base_url_1.getDataparadeApiBaseUrl)()}/api/scans/cli/upload/${encodeURIComponent(created.draftId)}`;
|
|
98
|
+
await postScanFiles(`${draftUrl}/files`, buildAuthHeaders(input.apiKey), input.files);
|
|
99
|
+
const complete = await completeScanUpload(draftUrl, input.apiKey, input.remoteUrl ?? null, input.compare);
|
|
100
|
+
return { ...created, complete };
|
|
98
101
|
}
|
|
99
102
|
return created;
|
|
100
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Tells the backend the scan files are all uploaded, so it stores the scan in the
|
|
106
|
+
* knowledge base (DATAP-883). With `compare` (`diff --upload` head, DATAP-890) the
|
|
107
|
+
* backend also stores the rename map and compares the head with the base. The
|
|
108
|
+
* preview works without it, so a failure only warns and gives null.
|
|
109
|
+
*/
|
|
110
|
+
async function completeScanUpload(draftUrl, apiKey, remoteUrl, compare) {
|
|
111
|
+
try {
|
|
112
|
+
const res = await fetch(`${draftUrl}/complete`, {
|
|
113
|
+
method: 'POST',
|
|
114
|
+
headers: buildAuthHeaders(apiKey),
|
|
115
|
+
body: JSON.stringify({
|
|
116
|
+
...(remoteUrl ? { remoteUrl } : {}),
|
|
117
|
+
...(compare ? { compare } : {}),
|
|
118
|
+
}),
|
|
119
|
+
});
|
|
120
|
+
if (!res.ok) {
|
|
121
|
+
console.warn(`[upload] warning: the scan was uploaded but not stored for comparison (${res.status}).`);
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return (await res.json());
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
128
|
+
console.warn(`[upload] warning: the scan was uploaded but not stored for comparison: ${message}`);
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}
|