vibecode-anything 0.0.0-stage → 0.4.0
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/LICENSE +21 -0
- package/README.md +407 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +2519 -0
- package/dist/core/adapters.d.ts +31 -0
- package/dist/core/adapters.js +478 -0
- package/dist/core/agent-adapter.d.ts +67 -0
- package/dist/core/agent-adapter.js +312 -0
- package/dist/core/anti-cheat.d.ts +6 -0
- package/dist/core/anti-cheat.js +372 -0
- package/dist/core/badge.d.ts +18 -0
- package/dist/core/badge.js +360 -0
- package/dist/core/cache.d.ts +47 -0
- package/dist/core/cache.js +403 -0
- package/dist/core/ci-export.d.ts +35 -0
- package/dist/core/ci-export.js +796 -0
- package/dist/core/ci-formats.d.ts +21 -0
- package/dist/core/ci-formats.js +388 -0
- package/dist/core/client-codegen.d.ts +36 -0
- package/dist/core/client-codegen.js +2538 -0
- package/dist/core/compose.d.ts +71 -0
- package/dist/core/compose.js +1088 -0
- package/dist/core/diff.d.ts +10 -0
- package/dist/core/diff.js +207 -0
- package/dist/core/docs-export.d.ts +37 -0
- package/dist/core/docs-export.js +2706 -0
- package/dist/core/doctor.d.ts +70 -0
- package/dist/core/doctor.js +525 -0
- package/dist/core/errors.d.ts +32 -0
- package/dist/core/errors.js +81 -0
- package/dist/core/exec.d.ts +38 -0
- package/dist/core/exec.js +336 -0
- package/dist/core/fixtures.d.ts +153 -0
- package/dist/core/fixtures.js +2245 -0
- package/dist/core/format.d.ts +77 -0
- package/dist/core/format.js +632 -0
- package/dist/core/fs-snapshot.d.ts +37 -0
- package/dist/core/fs-snapshot.js +216 -0
- package/dist/core/graphql-export.d.ts +34 -0
- package/dist/core/graphql-export.js +2482 -0
- package/dist/core/har-export.d.ts +29 -0
- package/dist/core/har-export.js +988 -0
- package/dist/core/html-report.d.ts +27 -0
- package/dist/core/html-report.js +1535 -0
- package/dist/core/http-export.d.ts +31 -0
- package/dist/core/http-export.js +726 -0
- package/dist/core/impact.d.ts +80 -0
- package/dist/core/impact.js +1412 -0
- package/dist/core/lint.d.ts +38 -0
- package/dist/core/lint.js +1111 -0
- package/dist/core/load-export.d.ts +37 -0
- package/dist/core/load-export.js +1813 -0
- package/dist/core/mcp-export.d.ts +35 -0
- package/dist/core/mcp-export.js +1736 -0
- package/dist/core/mock-server.d.ts +47 -0
- package/dist/core/mock-server.js +1722 -0
- package/dist/core/openapi-export.d.ts +44 -0
- package/dist/core/openapi-export.js +1074 -0
- package/dist/core/parity.d.ts +14 -0
- package/dist/core/parity.js +173 -0
- package/dist/core/playwright-exporter.d.ts +23 -0
- package/dist/core/playwright-exporter.js +1343 -0
- package/dist/core/png.d.ts +7 -0
- package/dist/core/png.js +339 -0
- package/dist/core/regression.d.ts +54 -0
- package/dist/core/regression.js +529 -0
- package/dist/core/responsive.d.ts +86 -0
- package/dist/core/responsive.js +606 -0
- package/dist/core/run.d.ts +74 -0
- package/dist/core/run.js +696 -0
- package/dist/core/scheduler.d.ts +24 -0
- package/dist/core/scheduler.js +162 -0
- package/dist/core/schema-export.d.ts +29 -0
- package/dist/core/schema-export.js +2215 -0
- package/dist/core/schema.d.ts +18 -0
- package/dist/core/schema.js +1057 -0
- package/dist/core/security.d.ts +233 -0
- package/dist/core/security.js +1839 -0
- package/dist/core/server-export.d.ts +38 -0
- package/dist/core/server-export.js +3198 -0
- package/dist/core/slices.d.ts +24 -0
- package/dist/core/slices.js +294 -0
- package/dist/core/spec-writer.d.ts +9 -0
- package/dist/core/spec-writer.js +1202 -0
- package/dist/core/store.d.ts +26 -0
- package/dist/core/store.js +217 -0
- package/dist/core/target-map.d.ts +34 -0
- package/dist/core/target-map.js +262 -0
- package/dist/core/test-exporter.d.ts +25 -0
- package/dist/core/test-exporter.js +1918 -0
- package/dist/core/types.d.ts +919 -0
- package/dist/core/types.js +4 -0
- package/dist/core/visual-semantic.d.ts +67 -0
- package/dist/core/visual-semantic.js +673 -0
- package/dist/core/visual.d.ts +34 -0
- package/dist/core/visual.js +508 -0
- package/dist/core/watch.d.ts +78 -0
- package/dist/core/watch.js +495 -0
- package/dist/core/yaml.d.ts +5 -0
- package/dist/core/yaml.js +1009 -0
- package/dist/diagnostics/diagnose.d.ts +53 -0
- package/dist/diagnostics/diagnose.js +1083 -0
- package/dist/diagnostics/flake.d.ts +71 -0
- package/dist/diagnostics/flake.js +608 -0
- package/dist/diagnostics/mutation-audit.d.ts +69 -0
- package/dist/diagnostics/mutation-audit.js +769 -0
- package/dist/diagnostics/spatial.d.ts +42 -0
- package/dist/diagnostics/spatial.js +346 -0
- package/dist/diagnostics/trends.d.ts +122 -0
- package/dist/diagnostics/trends.js +1190 -0
- package/dist/discovery/discover.d.ts +111 -0
- package/dist/discovery/discover.js +2017 -0
- package/dist/discovery/lock.d.ts +116 -0
- package/dist/discovery/lock.js +1505 -0
- package/dist/discovery/routes.d.ts +36 -0
- package/dist/discovery/routes.js +1494 -0
- package/dist/discovery/test-importer.d.ts +92 -0
- package/dist/discovery/test-importer.js +4952 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.js +99 -0
- package/dist/ingestors/api-collections.d.ts +28 -0
- package/dist/ingestors/api-collections.js +2335 -0
- package/dist/ingestors/api-repo.d.ts +6 -0
- package/dist/ingestors/api-repo.js +1120 -0
- package/dist/ingestors/asyncapi.d.ts +26 -0
- package/dist/ingestors/asyncapi.js +2105 -0
- package/dist/ingestors/bridges.d.ts +5 -0
- package/dist/ingestors/bridges.js +1264 -0
- package/dist/ingestors/cli.d.ts +10 -0
- package/dist/ingestors/cli.js +454 -0
- package/dist/ingestors/curl.d.ts +14 -0
- package/dist/ingestors/curl.js +1024 -0
- package/dist/ingestors/graphql.d.ts +56 -0
- package/dist/ingestors/graphql.js +1852 -0
- package/dist/ingestors/http-file.d.ts +20 -0
- package/dist/ingestors/http-file.js +923 -0
- package/dist/ingestors/image.d.ts +2 -0
- package/dist/ingestors/image.js +147 -0
- package/dist/ingestors/index.d.ts +5 -0
- package/dist/ingestors/index.js +577 -0
- package/dist/ingestors/openrpc.d.ts +29 -0
- package/dist/ingestors/openrpc.js +1807 -0
- package/dist/ingestors/proto.d.ts +47 -0
- package/dist/ingestors/proto.js +2690 -0
- package/dist/ingestors/trace.d.ts +10 -0
- package/dist/ingestors/trace.js +599 -0
- package/dist/ingestors/video.d.ts +50 -0
- package/dist/ingestors/video.js +655 -0
- package/dist/ingestors/web.d.ts +40 -0
- package/dist/ingestors/web.js +839 -0
- package/dist/mcp/server.d.ts +2 -0
- package/dist/mcp/server.js +3969 -0
- package/dist/oracles/api-repo.d.ts +2 -0
- package/dist/oracles/api-repo.js +286 -0
- package/dist/oracles/cli.d.ts +2 -0
- package/dist/oracles/cli.js +205 -0
- package/dist/oracles/http-workflow.d.ts +68 -0
- package/dist/oracles/http-workflow.js +828 -0
- package/dist/oracles/image.d.ts +2 -0
- package/dist/oracles/image.js +429 -0
- package/dist/oracles/index.d.ts +6 -0
- package/dist/oracles/index.js +320 -0
- package/dist/oracles/perf-budget.d.ts +90 -0
- package/dist/oracles/perf-budget.js +1329 -0
- package/dist/oracles/stream.d.ts +94 -0
- package/dist/oracles/stream.js +1268 -0
- package/dist/oracles/ui-states.d.ts +49 -0
- package/dist/oracles/ui-states.js +894 -0
- package/dist/oracles/video.d.ts +21 -0
- package/dist/oracles/video.js +627 -0
- package/dist/oracles/web.d.ts +2 -0
- package/dist/oracles/web.js +871 -0
- package/dist/plugins/builtins.d.ts +12 -0
- package/dist/plugins/builtins.js +1052 -0
- package/dist/plugins/registry.d.ts +86 -0
- package/dist/plugins/registry.js +554 -0
- package/dist/setup/index.d.ts +7 -0
- package/dist/setup/index.js +298 -0
- package/package.json +54 -4
- package/skills/vibecode-anything/SKILL.md +75 -0
|
@@ -0,0 +1,1264 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { VibecodeError, errorMessage } from "../core/errors.js";
|
|
4
|
+
import { validateContract } from "../core/schema.js";
|
|
5
|
+
import { isSensitiveHeader, isSensitiveQueryParam, redactHeaders } from "./trace.js";
|
|
6
|
+
function isObject(v) {
|
|
7
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
8
|
+
}
|
|
9
|
+
function asArray(v) {
|
|
10
|
+
return Array.isArray(v) ? v : [];
|
|
11
|
+
}
|
|
12
|
+
function str(v, fallback = "") {
|
|
13
|
+
return typeof v === "string" && v.trim() ? v : fallback;
|
|
14
|
+
}
|
|
15
|
+
function loadJson(filePath) {
|
|
16
|
+
let raw;
|
|
17
|
+
try {
|
|
18
|
+
raw = fs.readFileSync(filePath, "utf8");
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
throw new VibecodeError("TARGET_MISSING", `Bridge file not found: ${filePath}`, { details: errorMessage(err) });
|
|
22
|
+
}
|
|
23
|
+
if (raw.charCodeAt(0) === 0xfeff)
|
|
24
|
+
raw = raw.slice(1);
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(raw);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
throw new VibecodeError("BRIDGE_FORMAT_ERROR", `Invalid JSON in bridge file: ${errorMessage(err)}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function slugify(text, fallback = "item") {
|
|
33
|
+
const s = String(text || "")
|
|
34
|
+
.toLowerCase()
|
|
35
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
36
|
+
.replace(/^-+|-+$/g, "")
|
|
37
|
+
.slice(0, 64);
|
|
38
|
+
return s || fallback;
|
|
39
|
+
}
|
|
40
|
+
function uniqueId(base, used) {
|
|
41
|
+
let id = slugify(base, "inv");
|
|
42
|
+
if (!id.startsWith("inv-"))
|
|
43
|
+
id = `inv-${id}`;
|
|
44
|
+
if (!used.has(id)) {
|
|
45
|
+
used.add(id);
|
|
46
|
+
return id;
|
|
47
|
+
}
|
|
48
|
+
let n = 2;
|
|
49
|
+
while (used.has(`${id}-${n}`))
|
|
50
|
+
n++;
|
|
51
|
+
const out = `${id}-${n}`;
|
|
52
|
+
used.add(out);
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
function normalizeSeverity(v) {
|
|
56
|
+
return v === "soft" ? "soft" : "hard";
|
|
57
|
+
}
|
|
58
|
+
function normalizeTags(tags, extra = []) {
|
|
59
|
+
const out = [];
|
|
60
|
+
for (const t of [...extra, ...(Array.isArray(tags) ? tags : [])]) {
|
|
61
|
+
if (typeof t === "string" && t.trim() && !out.includes(t))
|
|
62
|
+
out.push(t.trim());
|
|
63
|
+
}
|
|
64
|
+
return out.length ? out : extra.length ? extra : ["bridge"];
|
|
65
|
+
}
|
|
66
|
+
function pushWarning(warnings, code, message, details) {
|
|
67
|
+
warnings.push({ code, message, ...(details !== undefined ? { details } : {}) });
|
|
68
|
+
}
|
|
69
|
+
function finalizeInvariant(raw, { kind, fallbackDomain, index, usedIds }) {
|
|
70
|
+
if (!isObject(raw)) {
|
|
71
|
+
throw new VibecodeError("BRIDGE_FORMAT_ERROR", `${kind} bridge invariant at index ${index} must be an object`);
|
|
72
|
+
}
|
|
73
|
+
const domain = str(raw.domain, fallbackDomain || "cli");
|
|
74
|
+
const type = str(raw.type, domain === "cli" ? "command" : domain === "api" ? "http" : domain === "web" ? "web_route" : "command");
|
|
75
|
+
const idBase = str(raw.id) || `inv-${kind}-${type}-${index + 1}`;
|
|
76
|
+
const inv = {
|
|
77
|
+
id: uniqueId(idBase, usedIds),
|
|
78
|
+
domain: domain,
|
|
79
|
+
type: type,
|
|
80
|
+
severity: normalizeSeverity(raw.severity),
|
|
81
|
+
description: str(raw.description, `Imported ${kind} ${type} invariant ${index + 1}`),
|
|
82
|
+
tags: normalizeTags(raw.tags, ["bridge", kind]),
|
|
83
|
+
sourceId: str(raw.sourceId, "src-1"),
|
|
84
|
+
input: isObject(raw.input) ? raw.input : {},
|
|
85
|
+
expected: isObject(raw.expected) ? raw.expected : {},
|
|
86
|
+
tolerance: isObject(raw.tolerance) ? raw.tolerance : {}
|
|
87
|
+
};
|
|
88
|
+
return inv;
|
|
89
|
+
}
|
|
90
|
+
function validateInvariantsOrThrow(invariants, kind) {
|
|
91
|
+
const contract = {
|
|
92
|
+
schemaVersion: "0.2.0",
|
|
93
|
+
target: { name: kind, domains: ["cli"], sources: [{ id: "src-1", kind, ref: kind }] },
|
|
94
|
+
artifacts: { root: ".vibecode/artifacts", files: {} },
|
|
95
|
+
thresholds: { hardBehavioralParity: 1, softPerceptualParity: 0.85, softGateMode: "warn", defaults: {} },
|
|
96
|
+
invariants
|
|
97
|
+
};
|
|
98
|
+
const res = validateContract(contract);
|
|
99
|
+
if (!res.ok) {
|
|
100
|
+
const err = res.errors[0];
|
|
101
|
+
throw new VibecodeError("BRIDGE_FORMAT_ERROR", `${kind} bridge produced invalid invariant: ${err.path} ${err.message}`, { details: res.errors });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function extractArtifactFiles(doc) {
|
|
105
|
+
const files = {};
|
|
106
|
+
if (isObject(doc.artifacts) && isObject(doc.artifacts.files)) {
|
|
107
|
+
for (const [k, v] of Object.entries(doc.artifacts.files)) {
|
|
108
|
+
if (typeof v === "string")
|
|
109
|
+
files[k] = v;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return files;
|
|
113
|
+
}
|
|
114
|
+
function normalizePassThroughContract(doc, kind, warnings) {
|
|
115
|
+
const contractDoc = isObject(doc.contract) ? doc.contract : doc;
|
|
116
|
+
const rawInvs = asArray(contractDoc.invariants);
|
|
117
|
+
if (rawInvs.length === 0) {
|
|
118
|
+
throw new VibecodeError("BRIDGE_FORMAT_ERROR", `${kind} bridge file contains no invariants`);
|
|
119
|
+
}
|
|
120
|
+
const usedIds = new Set();
|
|
121
|
+
const invariants = rawInvs.map((inv, i) => finalizeInvariant(inv, {
|
|
122
|
+
kind,
|
|
123
|
+
fallbackDomain: (isObject(inv) && typeof inv.domain === "string" ? inv.domain : "") || "cli",
|
|
124
|
+
index: i,
|
|
125
|
+
usedIds,
|
|
126
|
+
warnings
|
|
127
|
+
}));
|
|
128
|
+
validateInvariantsOrThrow(invariants, kind);
|
|
129
|
+
return {
|
|
130
|
+
domain: invariants[0]?.domain || "cli",
|
|
131
|
+
sources: [{ id: "src-1", kind, ref: "inline", meta: { bridge: kind } }],
|
|
132
|
+
artifacts: { root: ".vibecode/artifacts", files: extractArtifactFiles(contractDoc) },
|
|
133
|
+
invariants,
|
|
134
|
+
warnings
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function looksLikeContractDoc(doc) {
|
|
138
|
+
return isObject(doc) && (Array.isArray(doc.invariants) || isObject(doc.contract));
|
|
139
|
+
}
|
|
140
|
+
function firstObject(doc, keys) {
|
|
141
|
+
for (const k of keys) {
|
|
142
|
+
if (isObject(doc[k]))
|
|
143
|
+
return doc[k];
|
|
144
|
+
if (Array.isArray(doc[k]))
|
|
145
|
+
return { [k]: doc[k] };
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
function getReaPayload(doc) {
|
|
150
|
+
if (!isObject(doc))
|
|
151
|
+
return null;
|
|
152
|
+
const nested = firstObject(doc, ["analysis", "spec", "manifest", "report", "rea", "output"]);
|
|
153
|
+
const base = nested ? { ...nested, ...doc, ...nested } : doc;
|
|
154
|
+
return base;
|
|
155
|
+
}
|
|
156
|
+
function getCliAnythingPayload(doc) {
|
|
157
|
+
if (!isObject(doc))
|
|
158
|
+
return null;
|
|
159
|
+
const nested = firstObject(doc, ["cli_anything", "cliAnything", "harness", "spec", "manifest", "report", "analysis"]);
|
|
160
|
+
const base = nested ? { ...nested, ...doc, ...nested } : doc;
|
|
161
|
+
return base;
|
|
162
|
+
}
|
|
163
|
+
function coerceStringArray(v) {
|
|
164
|
+
if (Array.isArray(v))
|
|
165
|
+
return v.map((x) => String(x));
|
|
166
|
+
if (typeof v === "string" && v.trim())
|
|
167
|
+
return [v];
|
|
168
|
+
return [];
|
|
169
|
+
}
|
|
170
|
+
function convertReaRoutes(items, usedIds, warnings) {
|
|
171
|
+
const out = [];
|
|
172
|
+
items.forEach((item, i) => {
|
|
173
|
+
if (!isObject(item)) {
|
|
174
|
+
pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `rea.routes[${i}] is not an object; skipped`);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const p = str(item.path, str(item.url, str(item.route, "")));
|
|
178
|
+
if (!p) {
|
|
179
|
+
pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `rea.routes[${i}] missing path; skipped`);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const pathVal = p.startsWith("/") ? p : `/${p}`;
|
|
183
|
+
const expected = isObject(item.expected) ? { ...item.expected } : {};
|
|
184
|
+
if (item.status !== undefined && expected.status === undefined)
|
|
185
|
+
expected.status = item.status;
|
|
186
|
+
if (item.title !== undefined && expected.titleContains === undefined)
|
|
187
|
+
expected.titleContains = String(item.title);
|
|
188
|
+
if (item.titleContains !== undefined && expected.titleContains === undefined)
|
|
189
|
+
expected.titleContains = String(item.titleContains);
|
|
190
|
+
if (Array.isArray(item.landmarks) && expected.landmarks === undefined)
|
|
191
|
+
expected.landmarks = item.landmarks;
|
|
192
|
+
if (Array.isArray(item.boundingBoxes) && expected.boundingBoxes === undefined)
|
|
193
|
+
expected.boundingBoxes = item.boundingBoxes;
|
|
194
|
+
if (expected.status === undefined)
|
|
195
|
+
expected.status = 200;
|
|
196
|
+
const inv = {
|
|
197
|
+
id: uniqueId(str(item.id, `inv-rea-route-${slugify(pathVal)}`), usedIds),
|
|
198
|
+
domain: "web",
|
|
199
|
+
type: "web_route",
|
|
200
|
+
severity: normalizeSeverity(item.severity),
|
|
201
|
+
description: str(item.description, `REA route ${pathVal}`),
|
|
202
|
+
tags: normalizeTags(item.tags, ["bridge", "rea", "web", "route"]),
|
|
203
|
+
sourceId: str(item.sourceId, "src-1"),
|
|
204
|
+
input: { path: pathVal, ...(isObject(item.input) ? item.input : {}) },
|
|
205
|
+
expected,
|
|
206
|
+
tolerance: isObject(item.tolerance) ? item.tolerance : {}
|
|
207
|
+
};
|
|
208
|
+
out.push(inv);
|
|
209
|
+
});
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
212
|
+
function convertReaFlows(items, usedIds, warnings) {
|
|
213
|
+
const out = [];
|
|
214
|
+
items.forEach((item, i) => {
|
|
215
|
+
if (!isObject(item)) {
|
|
216
|
+
pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `rea.flows[${i}] is not an object; skipped`);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const startPath = str(item.startPath, str(item.start_path, str(item.path, "/")));
|
|
220
|
+
const steps = Array.isArray(item.steps) ? item.steps : [];
|
|
221
|
+
const expected = isObject(item.expected) ? { ...item.expected } : {};
|
|
222
|
+
if (Array.isArray(item.assertions) && expected.assertions === undefined)
|
|
223
|
+
expected.assertions = item.assertions;
|
|
224
|
+
if (Array.isArray(item.networkCalls) && expected.networkCalls === undefined)
|
|
225
|
+
expected.networkCalls = item.networkCalls;
|
|
226
|
+
if (Array.isArray(item.network_calls) && expected.networkCalls === undefined)
|
|
227
|
+
expected.networkCalls = item.network_calls;
|
|
228
|
+
const inv = {
|
|
229
|
+
id: uniqueId(str(item.id, `inv-rea-flow-${slugify(item.name || startPath)}`), usedIds),
|
|
230
|
+
domain: "web",
|
|
231
|
+
type: "web_flow",
|
|
232
|
+
severity: normalizeSeverity(item.severity),
|
|
233
|
+
description: str(item.description, `REA flow ${str(item.name, startPath)}`),
|
|
234
|
+
tags: normalizeTags(item.tags, ["bridge", "rea", "web", "flow"]),
|
|
235
|
+
sourceId: str(item.sourceId, "src-1"),
|
|
236
|
+
input: {
|
|
237
|
+
startPath: startPath.startsWith("/") ? startPath : `/${startPath}`,
|
|
238
|
+
steps,
|
|
239
|
+
...(isObject(item.input) ? item.input : {})
|
|
240
|
+
},
|
|
241
|
+
expected,
|
|
242
|
+
tolerance: isObject(item.tolerance) ? item.tolerance : {}
|
|
243
|
+
};
|
|
244
|
+
out.push(inv);
|
|
245
|
+
});
|
|
246
|
+
return out;
|
|
247
|
+
}
|
|
248
|
+
function convertReaEndpoints(items, usedIds, warnings) {
|
|
249
|
+
const out = [];
|
|
250
|
+
items.forEach((item, i) => {
|
|
251
|
+
if (!isObject(item)) {
|
|
252
|
+
pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `rea.endpoints[${i}] is not an object; skipped`);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const method = str(item.method, "GET").toUpperCase();
|
|
256
|
+
const p = str(item.path, str(item.url, ""));
|
|
257
|
+
if (!p) {
|
|
258
|
+
pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `rea.endpoints[${i}] missing path; skipped`);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const pathVal = p.startsWith("/") ? p : `/${p}`;
|
|
262
|
+
const expected = isObject(item.expected) ? { ...item.expected } : {};
|
|
263
|
+
if (item.status !== undefined && expected.status === undefined)
|
|
264
|
+
expected.status = item.status;
|
|
265
|
+
if (item.jsonSchema !== undefined && expected.jsonSchema === undefined)
|
|
266
|
+
expected.jsonSchema = item.jsonSchema;
|
|
267
|
+
if (item.jsonSubset !== undefined && expected.jsonSubset === undefined)
|
|
268
|
+
expected.jsonSubset = item.jsonSubset;
|
|
269
|
+
if (item.jsonPaths !== undefined && expected.jsonPaths === undefined)
|
|
270
|
+
expected.jsonPaths = item.jsonPaths;
|
|
271
|
+
if (expected.status === undefined)
|
|
272
|
+
expected.status = 200;
|
|
273
|
+
const inv = {
|
|
274
|
+
id: uniqueId(str(item.id, `inv-rea-http-${method.toLowerCase()}-${slugify(pathVal)}`), usedIds),
|
|
275
|
+
domain: "api",
|
|
276
|
+
type: "http",
|
|
277
|
+
severity: normalizeSeverity(item.severity),
|
|
278
|
+
description: str(item.description, `REA endpoint ${method} ${pathVal}`),
|
|
279
|
+
tags: normalizeTags(item.tags, ["bridge", "rea", "api", "http"]),
|
|
280
|
+
sourceId: str(item.sourceId, "src-1"),
|
|
281
|
+
input: {
|
|
282
|
+
method,
|
|
283
|
+
path: pathVal,
|
|
284
|
+
...(isObject(item.headers) ? { headers: item.headers } : {}),
|
|
285
|
+
...(isObject(item.query) ? { query: item.query } : {}),
|
|
286
|
+
...(item.body !== undefined ? { body: item.body } : {}),
|
|
287
|
+
...(isObject(item.input) ? item.input : {})
|
|
288
|
+
},
|
|
289
|
+
expected,
|
|
290
|
+
tolerance: isObject(item.tolerance) ? item.tolerance : {}
|
|
291
|
+
};
|
|
292
|
+
out.push(inv);
|
|
293
|
+
});
|
|
294
|
+
return out;
|
|
295
|
+
}
|
|
296
|
+
function copyExpectedAliases(source, expected, mapping) {
|
|
297
|
+
const target = expected;
|
|
298
|
+
for (const [from, to] of mapping) {
|
|
299
|
+
if (source[from] !== undefined && target[to] === undefined) {
|
|
300
|
+
target[to] = source[from];
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function convertReaCommands(items, usedIds, warnings) {
|
|
305
|
+
const out = [];
|
|
306
|
+
items.forEach((item, i) => {
|
|
307
|
+
if (!isObject(item)) {
|
|
308
|
+
pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `rea.commands[${i}] is not an object; skipped`);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const args = coerceStringArray(item.args ?? item.argv ?? item.command);
|
|
312
|
+
const expected = isObject(item.expected) ? { ...item.expected } : {};
|
|
313
|
+
copyExpectedAliases(item, expected, [
|
|
314
|
+
["exitCode", "exitCode"], ["exit_code", "exitCode"],
|
|
315
|
+
["stdoutContains", "stdoutContains"], ["stdout_contains", "stdoutContains"],
|
|
316
|
+
["stderrContains", "stderrContains"], ["stderr_contains", "stderrContains"],
|
|
317
|
+
["goldenStdout", "goldenStdout"], ["golden_stdout", "goldenStdout"],
|
|
318
|
+
["jsonSchema", "jsonSchema"], ["json_schema", "jsonSchema"],
|
|
319
|
+
["jsonPaths", "jsonPaths"], ["json_paths", "jsonPaths"]
|
|
320
|
+
]);
|
|
321
|
+
const inv = {
|
|
322
|
+
id: uniqueId(str(item.id, `inv-rea-cli-${slugify(args.join("-") || item.name || i + 1)}`), usedIds),
|
|
323
|
+
domain: "cli",
|
|
324
|
+
type: "command",
|
|
325
|
+
severity: normalizeSeverity(item.severity),
|
|
326
|
+
description: str(item.description, `REA command ${args.join(" ") || "(no args)"}`),
|
|
327
|
+
tags: normalizeTags(item.tags, ["bridge", "rea", "cli", "command"]),
|
|
328
|
+
sourceId: str(item.sourceId, "src-1"),
|
|
329
|
+
input: {
|
|
330
|
+
args,
|
|
331
|
+
...(item.stdin !== undefined ? { stdin: item.stdin } : {}),
|
|
332
|
+
...(isObject(item.env) ? { env: item.env } : {}),
|
|
333
|
+
...(isObject(item.input) ? item.input : {})
|
|
334
|
+
},
|
|
335
|
+
expected,
|
|
336
|
+
tolerance: isObject(item.tolerance) ? item.tolerance : {}
|
|
337
|
+
};
|
|
338
|
+
out.push(inv);
|
|
339
|
+
});
|
|
340
|
+
return out;
|
|
341
|
+
}
|
|
342
|
+
function convertReaScreens(items, usedIds, warnings) {
|
|
343
|
+
const out = [];
|
|
344
|
+
items.forEach((item, i) => {
|
|
345
|
+
if (!isObject(item)) {
|
|
346
|
+
pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `rea.screens[${i}] is not an object; skipped`);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
const ref = str(item.referenceArtifact, str(item.reference_artifact, str(item.reference, "")));
|
|
350
|
+
const dims = item.dimensions || item.size;
|
|
351
|
+
const hasDims = isObject(dims) && Number.isFinite(Number(dims.width)) && Number.isFinite(Number(dims.height));
|
|
352
|
+
if (!ref || !hasDims) {
|
|
353
|
+
pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `rea.screens[${i}] missing referenceArtifact/dimensions; skipped`, { id: item.id, referenceArtifact: ref || null });
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
const expected = isObject(item.expected) ? { ...item.expected } : {};
|
|
357
|
+
const inv = {
|
|
358
|
+
id: uniqueId(str(item.id, `inv-rea-screen-${slugify(item.name || i + 1)}`), usedIds),
|
|
359
|
+
domain: "image",
|
|
360
|
+
type: str(item.type, "image_layout"),
|
|
361
|
+
severity: normalizeSeverity(item.severity),
|
|
362
|
+
description: str(item.description, `REA screen ${str(item.name, String(i + 1))}`),
|
|
363
|
+
tags: normalizeTags(item.tags, ["bridge", "rea", "image"]),
|
|
364
|
+
sourceId: str(item.sourceId, "src-1"),
|
|
365
|
+
input: {
|
|
366
|
+
referenceArtifact: ref,
|
|
367
|
+
dimensions: { width: Number(dims.width), height: Number(dims.height) },
|
|
368
|
+
...(isObject(item.input) ? item.input : {})
|
|
369
|
+
},
|
|
370
|
+
expected,
|
|
371
|
+
tolerance: isObject(item.tolerance) ? item.tolerance : {}
|
|
372
|
+
};
|
|
373
|
+
out.push(inv);
|
|
374
|
+
});
|
|
375
|
+
return out;
|
|
376
|
+
}
|
|
377
|
+
function convertReaManifest(doc, kind, warnings) {
|
|
378
|
+
const payload = getReaPayload(doc) || doc;
|
|
379
|
+
const routes = asArray(payload.routes || payload.pages);
|
|
380
|
+
const flows = asArray(payload.flows || payload.interactions);
|
|
381
|
+
const endpoints = asArray(payload.endpoints || payload.api || payload.apis);
|
|
382
|
+
const commands = asArray(payload.commands || payload.cli || payload.cliCommands);
|
|
383
|
+
const screens = asArray(payload.screens || payload.images);
|
|
384
|
+
const usedIds = new Set();
|
|
385
|
+
const invariants = [
|
|
386
|
+
...convertReaRoutes(routes, usedIds, warnings),
|
|
387
|
+
...convertReaFlows(flows, usedIds, warnings),
|
|
388
|
+
...convertReaEndpoints(endpoints, usedIds, warnings),
|
|
389
|
+
...convertReaCommands(commands, usedIds, warnings),
|
|
390
|
+
...convertReaScreens(screens, usedIds, warnings)
|
|
391
|
+
];
|
|
392
|
+
if (invariants.length === 0) {
|
|
393
|
+
throw new VibecodeError("BRIDGE_FORMAT_ERROR", "rea bridge file contains no convertible invariants", {
|
|
394
|
+
details: { keys: isObject(payload) ? Object.keys(payload) : [] }
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
validateInvariantsOrThrow(invariants, kind);
|
|
398
|
+
return {
|
|
399
|
+
domain: invariants[0]?.domain || "cli",
|
|
400
|
+
sources: [{ id: "src-1", kind, ref: "inline", meta: { bridge: kind, format: "rea-manifest" } }],
|
|
401
|
+
artifacts: { root: ".vibecode/artifacts", files: extractArtifactFiles(payload) },
|
|
402
|
+
invariants,
|
|
403
|
+
warnings
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
function extractCliAnythingCommands(payload) {
|
|
407
|
+
if (Array.isArray(payload?.commands))
|
|
408
|
+
return payload.commands;
|
|
409
|
+
if (Array.isArray(payload?.subcommands))
|
|
410
|
+
return payload.subcommands;
|
|
411
|
+
if (isObject(payload?.cli) && Array.isArray(payload.cli.commands))
|
|
412
|
+
return payload.cli.commands;
|
|
413
|
+
if (isObject(payload?.cli) && Array.isArray(payload.cli.subcommands))
|
|
414
|
+
return payload.cli.subcommands;
|
|
415
|
+
if (Array.isArray(payload?.commandTree))
|
|
416
|
+
return payload.commandTree;
|
|
417
|
+
return [];
|
|
418
|
+
}
|
|
419
|
+
function convertCliAnythingTestCases(testCases, { baseArgs, usedIds, warnings, commandName }) {
|
|
420
|
+
const out = [];
|
|
421
|
+
testCases.forEach((tc, i) => {
|
|
422
|
+
if (!isObject(tc)) {
|
|
423
|
+
pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `cli-anything test case ${commandName}[${i}] not an object; skipped`);
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
const tcArgs = coerceStringArray(tc.args ?? tc.argv ?? tc.command);
|
|
427
|
+
const args = [...baseArgs, ...tcArgs];
|
|
428
|
+
const expected = isObject(tc.expected) ? { ...tc.expected } : {};
|
|
429
|
+
copyExpectedAliases(tc, expected, [
|
|
430
|
+
["exit_code", "exitCode"], ["exitCode", "exitCode"],
|
|
431
|
+
["stdout_contains", "stdoutContains"], ["stdoutContains", "stdoutContains"],
|
|
432
|
+
["stderr_contains", "stderrContains"], ["stderrContains", "stderrContains"],
|
|
433
|
+
["golden_stdout", "goldenStdout"], ["goldenStdout", "goldenStdout"],
|
|
434
|
+
["json_schema", "jsonSchema"], ["jsonSchema", "jsonSchema"],
|
|
435
|
+
["json_paths", "jsonPaths"], ["jsonPaths", "jsonPaths"],
|
|
436
|
+
["stdout_regex", "stdoutRegex"], ["stdoutRegex", "stdoutRegex"]
|
|
437
|
+
]);
|
|
438
|
+
const inv = {
|
|
439
|
+
id: uniqueId(str(tc.id, `inv-cli-anything-${slugify([...baseArgs, tc.name || i + 1].join("-"))}`), usedIds),
|
|
440
|
+
domain: "cli",
|
|
441
|
+
type: "command",
|
|
442
|
+
severity: normalizeSeverity(tc.severity),
|
|
443
|
+
description: str(tc.description, `CLI-Anything ${commandName} ${args.join(" ") || "(no args)"}`),
|
|
444
|
+
tags: normalizeTags(tc.tags, ["bridge", "cli-anything", "cli", "command"]),
|
|
445
|
+
sourceId: str(tc.sourceId, "src-1"),
|
|
446
|
+
input: {
|
|
447
|
+
args,
|
|
448
|
+
...(tc.stdin !== undefined ? { stdin: tc.stdin } : {}),
|
|
449
|
+
...(isObject(tc.env) ? { env: tc.env } : {}),
|
|
450
|
+
...(isObject(tc.input) ? { input: tc.input } : {})
|
|
451
|
+
},
|
|
452
|
+
expected,
|
|
453
|
+
tolerance: isObject(tc.tolerance) ? tc.tolerance : {}
|
|
454
|
+
};
|
|
455
|
+
out.push(inv);
|
|
456
|
+
});
|
|
457
|
+
return out;
|
|
458
|
+
}
|
|
459
|
+
function walkCliAnythingCommands(commands, prefixArgs, usedIds, warnings, out, parentName = "root") {
|
|
460
|
+
commands.forEach((cmd, i) => {
|
|
461
|
+
if (!isObject(cmd)) {
|
|
462
|
+
pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `cli-anything command ${parentName}[${i}] not an object; skipped`);
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
const name = str(cmd.name, str(cmd.command, ""));
|
|
466
|
+
const cmdArgs = coerceStringArray(cmd.args ?? cmd.argv);
|
|
467
|
+
const ownArgs = name ? [...prefixArgs, name, ...cmdArgs] : [...prefixArgs, ...cmdArgs];
|
|
468
|
+
const commandLabel = ownArgs.join(" ") || name || `command-${i + 1}`;
|
|
469
|
+
const tests = asArray(cmd.test_cases || cmd.tests || cmd.probes || cmd.examples || cmd.cases);
|
|
470
|
+
if (tests.length > 0) {
|
|
471
|
+
out.push(...convertCliAnythingTestCases(tests, { baseArgs: ownArgs, usedIds, warnings, commandName: commandLabel }));
|
|
472
|
+
}
|
|
473
|
+
else if (name || cmdArgs.length || cmd.expected || cmd.exit_code !== undefined || cmd.exitCode !== undefined) {
|
|
474
|
+
// Treat command itself as a probe if it carries expectation-ish fields
|
|
475
|
+
const hasExpectation = cmd.expected !== undefined || cmd.exit_code !== undefined || cmd.exitCode !== undefined || cmd.stdout_contains !== undefined || cmd.stdoutContains !== undefined;
|
|
476
|
+
if (hasExpectation) {
|
|
477
|
+
out.push(...convertCliAnythingTestCases([{ ...cmd, args: cmdArgs }], { baseArgs: prefixArgs.concat(name ? [name] : []), usedIds, warnings, commandName: commandLabel }));
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
const children = asArray(cmd.subcommands || cmd.commands || cmd.children);
|
|
481
|
+
if (children.length > 0)
|
|
482
|
+
walkCliAnythingCommands(children, ownArgs, usedIds, warnings, out, commandLabel);
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
function convertCliAnythingManifest(doc, kind, warnings) {
|
|
486
|
+
const payload = getCliAnythingPayload(doc) || doc;
|
|
487
|
+
const commands = extractCliAnythingCommands(payload);
|
|
488
|
+
const rootTests = asArray(payload.test_cases || payload.tests || payload.probes || payload.examples);
|
|
489
|
+
const usedIds = new Set();
|
|
490
|
+
const invariants = [];
|
|
491
|
+
// Root-level tests (apply to base command, no subcommand prefix beyond optional cli entrypoint)
|
|
492
|
+
const entryObj = isObject(payload.entrypoint) ? payload.entrypoint : undefined;
|
|
493
|
+
const cliObj = isObject(payload.cli) ? payload.cli : undefined;
|
|
494
|
+
const binaryObj = isObject(payload.binary) ? payload.binary : undefined;
|
|
495
|
+
const entryArgs = coerceStringArray(entryObj?.args || cliObj?.args || binaryObj?.args);
|
|
496
|
+
const baseName = str(entryObj?.name, str(cliObj?.name, str(binaryObj?.name, str(payload.name, ""))));
|
|
497
|
+
const basePrefix = baseName ? [baseName, ...entryArgs] : [...entryArgs];
|
|
498
|
+
if (rootTests.length > 0) {
|
|
499
|
+
invariants.push(...convertCliAnythingTestCases(rootTests, { baseArgs: basePrefix, usedIds, warnings, commandName: baseName || "root" }));
|
|
500
|
+
}
|
|
501
|
+
if (commands.length > 0) {
|
|
502
|
+
walkCliAnythingCommands(commands, basePrefix, usedIds, warnings, invariants, baseName || "root");
|
|
503
|
+
}
|
|
504
|
+
// Fallback: some formats put command-like objects at top-level "cases"
|
|
505
|
+
if (invariants.length === 0 && Array.isArray(payload.cases)) {
|
|
506
|
+
invariants.push(...convertCliAnythingTestCases(payload.cases, { baseArgs: basePrefix, usedIds, warnings, commandName: baseName || "root" }));
|
|
507
|
+
}
|
|
508
|
+
if (invariants.length === 0) {
|
|
509
|
+
throw new VibecodeError("BRIDGE_FORMAT_ERROR", "cli-anything bridge file contains no convertible invariants", {
|
|
510
|
+
details: { keys: isObject(payload) ? Object.keys(payload) : [] }
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
validateInvariantsOrThrow(invariants, kind);
|
|
514
|
+
return {
|
|
515
|
+
domain: "cli",
|
|
516
|
+
sources: [{ id: "src-1", kind, ref: "inline", meta: { bridge: kind, format: "cli-anything-manifest" } }],
|
|
517
|
+
artifacts: { root: ".vibecode/artifacts", files: extractArtifactFiles(payload) },
|
|
518
|
+
invariants,
|
|
519
|
+
warnings
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
async function importBridge(kind, filePath, options = {}) {
|
|
523
|
+
if (!filePath || typeof filePath !== "string") {
|
|
524
|
+
throw new VibecodeError("TARGET_MISSING", `${kind} bridge requires --source <file.json>`);
|
|
525
|
+
}
|
|
526
|
+
const abs = path.resolve(options.cwd || process.cwd(), filePath);
|
|
527
|
+
const doc = loadJson(abs);
|
|
528
|
+
if (!isObject(doc)) {
|
|
529
|
+
throw new VibecodeError("BRIDGE_FORMAT_ERROR", `${kind} bridge file must contain a JSON object`);
|
|
530
|
+
}
|
|
531
|
+
const warnings = [];
|
|
532
|
+
let result;
|
|
533
|
+
if (looksLikeContractDoc(doc) && !options.forceManifest) {
|
|
534
|
+
try {
|
|
535
|
+
result = normalizePassThroughContract(doc, kind, warnings);
|
|
536
|
+
}
|
|
537
|
+
catch (err) {
|
|
538
|
+
// If it's contract-shaped but invalid as pass-through, try manifest conversion for rea/cli-anything
|
|
539
|
+
if (kind === "rea")
|
|
540
|
+
result = convertReaManifest(doc, kind, warnings);
|
|
541
|
+
else if (kind === "cli-anything")
|
|
542
|
+
result = convertCliAnythingManifest(doc, kind, warnings);
|
|
543
|
+
else
|
|
544
|
+
throw err;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
else if (kind === "rea") {
|
|
548
|
+
result = convertReaManifest(doc, kind, warnings);
|
|
549
|
+
}
|
|
550
|
+
else if (kind === "cli-anything") {
|
|
551
|
+
result = convertCliAnythingManifest(doc, kind, warnings);
|
|
552
|
+
}
|
|
553
|
+
else {
|
|
554
|
+
throw new VibecodeError("BRIDGE_FORMAT_ERROR", `${kind} bridge file must contain invariants or contract.invariants`);
|
|
555
|
+
}
|
|
556
|
+
result.sources[0].ref = filePath;
|
|
557
|
+
result.warnings = warnings;
|
|
558
|
+
return result;
|
|
559
|
+
}
|
|
560
|
+
export async function importRea(filePath, options = {}) {
|
|
561
|
+
return importBridge("rea", filePath, options);
|
|
562
|
+
}
|
|
563
|
+
export async function importCliAnything(filePath, options = {}) {
|
|
564
|
+
return importBridge("cli-anything", filePath, options);
|
|
565
|
+
}
|
|
566
|
+
const POSTMAN_MAX_DEPTH = 16;
|
|
567
|
+
const POSTMAN_MAX_INVARIANTS = 50;
|
|
568
|
+
const POSTMAN_MAX_BODY_BYTES = 128 * 1024;
|
|
569
|
+
const POSTMAN_MAX_JSON_SCHEMA_DEPTH = 16;
|
|
570
|
+
const POSTMAN_MAX_JSON_SCHEMA_KEYS = 200;
|
|
571
|
+
const POSTMAN_SECRET_VAR_RE = /(?:token|secret|pass(?:word|wd)?|api[-_]?key|apikey|auth|jwt|cookie|session|credential|private[-_]?key)/i;
|
|
572
|
+
const POSTMAN_VAR_RE = /\{\{\s*([^{}\s][^{}]*?)\s*\}\}/g;
|
|
573
|
+
const POSTMAN_VAR_TEST_RE = /\{\{\s*([^{}\s][^{}]*?)\s*\}\}/;
|
|
574
|
+
const POSTMAN_SAFE_METHODS = new Set(["GET", "HEAD", "OPTIONS"]);
|
|
575
|
+
const POSTMAN_MUTATING_METHODS = new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
576
|
+
function isPostmanItemLike(entry, depth = 0) {
|
|
577
|
+
if (!isObject(entry) || depth > POSTMAN_MAX_DEPTH)
|
|
578
|
+
return false;
|
|
579
|
+
if (typeof entry.request === "string" || isObject(entry.request))
|
|
580
|
+
return true;
|
|
581
|
+
if (Array.isArray(entry.item)) {
|
|
582
|
+
return entry.item.length === 0 || entry.item.some((child) => isPostmanItemLike(child, depth + 1));
|
|
583
|
+
}
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
export function isPostmanCollectionDoc(doc) {
|
|
587
|
+
if (!isObject(doc))
|
|
588
|
+
return false;
|
|
589
|
+
// Reject OpenAPI/Swagger, HAR, and vibecode/rea/cli-anything documents cleanly
|
|
590
|
+
if (doc.openapi !== undefined || doc.swagger !== undefined || isObject(doc.paths))
|
|
591
|
+
return false;
|
|
592
|
+
if (isObject(doc.log) && Array.isArray(doc.log.entries))
|
|
593
|
+
return false;
|
|
594
|
+
if (Array.isArray(doc.invariants) || isObject(doc.contract))
|
|
595
|
+
return false;
|
|
596
|
+
if (doc.cli_anything !== undefined || doc.cliAnything !== undefined || doc.rea !== undefined)
|
|
597
|
+
return false;
|
|
598
|
+
if (!Array.isArray(doc.item))
|
|
599
|
+
return false;
|
|
600
|
+
if (!isObject(doc.info))
|
|
601
|
+
return false;
|
|
602
|
+
const info = doc.info;
|
|
603
|
+
if (typeof info.schema === "string") {
|
|
604
|
+
const schemaLower = info.schema.toLowerCase();
|
|
605
|
+
if (schemaLower.includes("schema.getpostman.com/json/collection") ||
|
|
606
|
+
schemaLower.includes("schema.postman.com/json/collection")) {
|
|
607
|
+
return true;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
if (typeof info._postman_id === "string" && info._postman_id.trim().length > 0) {
|
|
611
|
+
return true;
|
|
612
|
+
}
|
|
613
|
+
if (typeof info.name === "string" && info.name.trim().length > 0) {
|
|
614
|
+
return doc.item.length > 0 && doc.item.some((entry) => isPostmanItemLike(entry, 0));
|
|
615
|
+
}
|
|
616
|
+
return false;
|
|
617
|
+
}
|
|
618
|
+
function isSecretPostmanVarName(name, secretVarNames) {
|
|
619
|
+
const trimmed = name.trim();
|
|
620
|
+
if (!trimmed)
|
|
621
|
+
return false;
|
|
622
|
+
return secretVarNames.has(trimmed.toLowerCase()) || POSTMAN_SECRET_VAR_RE.test(trimmed);
|
|
623
|
+
}
|
|
624
|
+
function containsSecretVarPlaceholder(text, secretVarNames) {
|
|
625
|
+
POSTMAN_VAR_RE.lastIndex = 0;
|
|
626
|
+
let match;
|
|
627
|
+
while ((match = POSTMAN_VAR_RE.exec(text)) !== null) {
|
|
628
|
+
if (isSecretPostmanVarName(match[1], secretVarNames))
|
|
629
|
+
return true;
|
|
630
|
+
}
|
|
631
|
+
return false;
|
|
632
|
+
}
|
|
633
|
+
function buildSafePostmanVariables(doc) {
|
|
634
|
+
const safeVars = new Map();
|
|
635
|
+
const secretVarNames = new Set();
|
|
636
|
+
for (const entry of asArray(doc.variable)) {
|
|
637
|
+
if (!isObject(entry) || entry.disabled === true)
|
|
638
|
+
continue;
|
|
639
|
+
const key = typeof entry.key === "string" ? entry.key.trim() : "";
|
|
640
|
+
if (!key)
|
|
641
|
+
continue;
|
|
642
|
+
const isSecretType = typeof entry.type === "string" && entry.type.trim().toLowerCase() === "secret";
|
|
643
|
+
if (isSecretType || POSTMAN_SECRET_VAR_RE.test(key)) {
|
|
644
|
+
secretVarNames.add(key.toLowerCase());
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
if (entry.value !== undefined && entry.value !== null) {
|
|
648
|
+
safeVars.set(key, String(entry.value));
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
return { safeVars, secretVarNames };
|
|
652
|
+
}
|
|
653
|
+
function interpolateSafePostmanVars(text, vars) {
|
|
654
|
+
let out = text;
|
|
655
|
+
for (let pass = 0; pass < 2; pass++) {
|
|
656
|
+
let changed = false;
|
|
657
|
+
out = out.replace(POSTMAN_VAR_RE, (full, rawName) => {
|
|
658
|
+
const name = rawName.trim();
|
|
659
|
+
if (isSecretPostmanVarName(name, vars.secretVarNames))
|
|
660
|
+
return full;
|
|
661
|
+
const val = vars.safeVars.get(name);
|
|
662
|
+
if (val === undefined)
|
|
663
|
+
return full;
|
|
664
|
+
changed = true;
|
|
665
|
+
return val;
|
|
666
|
+
});
|
|
667
|
+
if (!changed)
|
|
668
|
+
break;
|
|
669
|
+
}
|
|
670
|
+
return out;
|
|
671
|
+
}
|
|
672
|
+
function synthesizePostmanJsonSchema(value, depth = 0) {
|
|
673
|
+
if (depth >= POSTMAN_MAX_JSON_SCHEMA_DEPTH)
|
|
674
|
+
return {};
|
|
675
|
+
if (value === null)
|
|
676
|
+
return { type: "null" };
|
|
677
|
+
if (Array.isArray(value)) {
|
|
678
|
+
return { type: "array", items: value.length ? synthesizePostmanJsonSchema(value[0], depth + 1) : {} };
|
|
679
|
+
}
|
|
680
|
+
if (isObject(value)) {
|
|
681
|
+
const entries = Object.entries(value).slice(0, POSTMAN_MAX_JSON_SCHEMA_KEYS);
|
|
682
|
+
const properties = {};
|
|
683
|
+
const required = [];
|
|
684
|
+
for (const [k, v] of entries) {
|
|
685
|
+
properties[k] = synthesizePostmanJsonSchema(v, depth + 1);
|
|
686
|
+
required.push(k);
|
|
687
|
+
}
|
|
688
|
+
return { type: "object", required, properties };
|
|
689
|
+
}
|
|
690
|
+
if (Number.isInteger(value))
|
|
691
|
+
return { type: "integer" };
|
|
692
|
+
return { type: typeof value };
|
|
693
|
+
}
|
|
694
|
+
function buildPostmanPathVariables(rawVariables, vars) {
|
|
695
|
+
const out = new Map();
|
|
696
|
+
for (const entry of asArray(rawVariables)) {
|
|
697
|
+
if (!isObject(entry) || entry.disabled === true)
|
|
698
|
+
continue;
|
|
699
|
+
const key = typeof entry.key === "string" ? entry.key.trim() : "";
|
|
700
|
+
if (!key || isSecretPostmanVarName(key, vars.secretVarNames))
|
|
701
|
+
continue;
|
|
702
|
+
if (entry.value === undefined || entry.value === null)
|
|
703
|
+
continue;
|
|
704
|
+
const rawVal = String(entry.value);
|
|
705
|
+
if (containsSecretVarPlaceholder(rawVal, vars.secretVarNames))
|
|
706
|
+
continue;
|
|
707
|
+
const resolved = interpolateSafePostmanVars(rawVal, vars).trim();
|
|
708
|
+
if (resolved && !POSTMAN_VAR_TEST_RE.test(resolved)) {
|
|
709
|
+
out.set(key, resolved);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
return out;
|
|
713
|
+
}
|
|
714
|
+
function normalizePostmanPathSegment(rawSegment, vars, pathVars) {
|
|
715
|
+
let seg = rawSegment;
|
|
716
|
+
try {
|
|
717
|
+
seg = decodeURIComponent(seg);
|
|
718
|
+
}
|
|
719
|
+
catch {
|
|
720
|
+
// keep raw segment if percent-encoding is malformed
|
|
721
|
+
}
|
|
722
|
+
const colonMatch = /^:([A-Za-z0-9_-]+)$/.exec(seg);
|
|
723
|
+
if (colonMatch) {
|
|
724
|
+
const paramName = colonMatch[1];
|
|
725
|
+
if (isSecretPostmanVarName(paramName, vars.secretVarNames))
|
|
726
|
+
return ["sample"];
|
|
727
|
+
return [encodeURIComponent(pathVars.get(paramName) ?? "sample")];
|
|
728
|
+
}
|
|
729
|
+
if (containsSecretVarPlaceholder(seg, vars.secretVarNames)) {
|
|
730
|
+
return ["sample"];
|
|
731
|
+
}
|
|
732
|
+
let interpolated = interpolateSafePostmanVars(seg, vars);
|
|
733
|
+
if (containsSecretVarPlaceholder(interpolated, vars.secretVarNames)) {
|
|
734
|
+
return ["sample"];
|
|
735
|
+
}
|
|
736
|
+
interpolated = interpolated.replace(POSTMAN_VAR_RE, "sample");
|
|
737
|
+
return interpolated
|
|
738
|
+
.split("/")
|
|
739
|
+
.filter((part) => part.length > 0)
|
|
740
|
+
.map((part) => encodeURIComponent(part));
|
|
741
|
+
}
|
|
742
|
+
function normalizePostmanPathname(rawPathname, vars, pathVars) {
|
|
743
|
+
const out = [];
|
|
744
|
+
for (const part of rawPathname.split("/").filter((s) => s.length > 0)) {
|
|
745
|
+
out.push(...normalizePostmanPathSegment(part, vars, pathVars));
|
|
746
|
+
}
|
|
747
|
+
return out.length === 0 ? "/" : `/${out.join("/")}`;
|
|
748
|
+
}
|
|
749
|
+
function sanitizePostmanQueryPairs(pairs, vars) {
|
|
750
|
+
const out = {};
|
|
751
|
+
for (const [rawKey, rawVal] of pairs) {
|
|
752
|
+
if (containsSecretVarPlaceholder(rawKey, vars.secretVarNames))
|
|
753
|
+
continue;
|
|
754
|
+
const key = interpolateSafePostmanVars(rawKey, vars).trim();
|
|
755
|
+
if (!key || containsSecretVarPlaceholder(key, vars.secretVarNames))
|
|
756
|
+
continue;
|
|
757
|
+
if (isSensitiveQueryParam(key) || POSTMAN_SECRET_VAR_RE.test(key))
|
|
758
|
+
continue;
|
|
759
|
+
if (containsSecretVarPlaceholder(rawVal, vars.secretVarNames))
|
|
760
|
+
continue;
|
|
761
|
+
const val = interpolateSafePostmanVars(rawVal, vars);
|
|
762
|
+
if (containsSecretVarPlaceholder(val, vars.secretVarNames))
|
|
763
|
+
continue;
|
|
764
|
+
out[key] = val;
|
|
765
|
+
}
|
|
766
|
+
return out;
|
|
767
|
+
}
|
|
768
|
+
function parseOriginAndBasePath(rawBase) {
|
|
769
|
+
if (!rawBase || !rawBase.trim())
|
|
770
|
+
return { origin: "", basePath: "" };
|
|
771
|
+
try {
|
|
772
|
+
const u = new URL(/^https?:\/\//i.test(rawBase.trim()) ? rawBase.trim() : `http://${rawBase.trim()}`);
|
|
773
|
+
if (u.protocol !== "http:" && u.protocol !== "https:")
|
|
774
|
+
return { origin: "", basePath: "" };
|
|
775
|
+
return { origin: u.origin, basePath: u.pathname.replace(/\/+$/, "") };
|
|
776
|
+
}
|
|
777
|
+
catch {
|
|
778
|
+
return { origin: "", basePath: "" };
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
function parsePostmanUrlString(rawUrl, vars, pathVars, fallbackBaseUrl) {
|
|
782
|
+
let candidate = interpolateSafePostmanVars(rawUrl.trim(), vars);
|
|
783
|
+
if (!candidate)
|
|
784
|
+
return null;
|
|
785
|
+
const fallback = parseOriginAndBasePath(fallbackBaseUrl);
|
|
786
|
+
const leadingVar = /^\{\{\s*([^{}\s][^{}]*?)\s*\}\}/.exec(candidate);
|
|
787
|
+
if (leadingVar) {
|
|
788
|
+
// Unresolved or secret leading origin placeholder: strip it and fall back to options.baseUrl or relative path
|
|
789
|
+
candidate = candidate.slice(leadingVar[0].length) || "/";
|
|
790
|
+
}
|
|
791
|
+
let origin = "";
|
|
792
|
+
let rawPathname = "/";
|
|
793
|
+
const rawQueryPairs = [];
|
|
794
|
+
const tryParseAbsolute = (input) => {
|
|
795
|
+
try {
|
|
796
|
+
const u = new URL(input);
|
|
797
|
+
if (u.protocol !== "http:" && u.protocol !== "https:")
|
|
798
|
+
return null;
|
|
799
|
+
return u;
|
|
800
|
+
}
|
|
801
|
+
catch {
|
|
802
|
+
return null;
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
let parsed = null;
|
|
806
|
+
let syntheticOrigin = false;
|
|
807
|
+
if (/^https?:\/\//i.test(candidate)) {
|
|
808
|
+
parsed = tryParseAbsolute(candidate);
|
|
809
|
+
if (!parsed) {
|
|
810
|
+
// Unresolved variable inside authority (e.g. https://{{host}}/items): salvage path+query
|
|
811
|
+
const authMatch = /^https?:\/\/[^/?#]*(.*)$/i.exec(candidate);
|
|
812
|
+
const rest = authMatch?.[1] || "/";
|
|
813
|
+
parsed = tryParseAbsolute(`${fallback.origin || "http://localhost"}${rest.startsWith("/") || rest.startsWith("?") ? rest : `/${rest}`}`);
|
|
814
|
+
syntheticOrigin = !fallback.origin;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
else if (candidate.startsWith("/") || candidate.startsWith("?")) {
|
|
818
|
+
const base = fallback.origin ? `${fallback.origin}${fallback.basePath}` : "http://localhost";
|
|
819
|
+
const joined = candidate.startsWith("?")
|
|
820
|
+
? `${base}/${candidate}`
|
|
821
|
+
: `${base}${candidate}`;
|
|
822
|
+
parsed = tryParseAbsolute(joined);
|
|
823
|
+
syntheticOrigin = !fallback.origin;
|
|
824
|
+
}
|
|
825
|
+
else {
|
|
826
|
+
// Schemeless host/path such as "api.example.com/v1/items"
|
|
827
|
+
parsed = tryParseAbsolute(`https://${candidate}`);
|
|
828
|
+
if (!parsed) {
|
|
829
|
+
const restMatch = /^[^/?#]*(.*)$/.exec(candidate);
|
|
830
|
+
const rest = restMatch?.[1] || "/";
|
|
831
|
+
parsed = tryParseAbsolute(`${fallback.origin || "http://localhost"}${rest.startsWith("/") ? rest : `/${rest}`}`);
|
|
832
|
+
syntheticOrigin = !fallback.origin;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
if (!parsed)
|
|
836
|
+
return null;
|
|
837
|
+
origin = syntheticOrigin ? "" : parsed.origin;
|
|
838
|
+
rawPathname = parsed.pathname || "/";
|
|
839
|
+
for (const [k, v] of parsed.searchParams.entries()) {
|
|
840
|
+
rawQueryPairs.push([k, v]);
|
|
841
|
+
}
|
|
842
|
+
return {
|
|
843
|
+
origin,
|
|
844
|
+
pathname: normalizePostmanPathname(rawPathname, vars, pathVars),
|
|
845
|
+
query: sanitizePostmanQueryPairs(rawQueryPairs, vars)
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
function parsePostmanUrl(rawUrl, vars, fallbackBaseUrl) {
|
|
849
|
+
if (typeof rawUrl === "string") {
|
|
850
|
+
return parsePostmanUrlString(rawUrl, vars, new Map(), fallbackBaseUrl);
|
|
851
|
+
}
|
|
852
|
+
if (!isObject(rawUrl))
|
|
853
|
+
return null;
|
|
854
|
+
const pathVars = buildPostmanPathVariables(rawUrl.variable, vars);
|
|
855
|
+
const hasHost = (Array.isArray(rawUrl.host) && rawUrl.host.length > 0) || (typeof rawUrl.host === "string" && rawUrl.host.trim().length > 0);
|
|
856
|
+
const hasPath = Array.isArray(rawUrl.path) || (typeof rawUrl.path === "string" && rawUrl.path.trim().length > 0);
|
|
857
|
+
const hasQuery = Array.isArray(rawUrl.query);
|
|
858
|
+
if (!hasHost && !hasPath) {
|
|
859
|
+
if (typeof rawUrl.raw === "string") {
|
|
860
|
+
const fromRaw = parsePostmanUrlString(rawUrl.raw, vars, pathVars, fallbackBaseUrl);
|
|
861
|
+
if (!fromRaw)
|
|
862
|
+
return null;
|
|
863
|
+
if (hasQuery) {
|
|
864
|
+
const pairs = collectPostmanQueryPairs(rawUrl.query);
|
|
865
|
+
fromRaw.query = sanitizePostmanQueryPairs(pairs, vars);
|
|
866
|
+
}
|
|
867
|
+
return fromRaw;
|
|
868
|
+
}
|
|
869
|
+
return null;
|
|
870
|
+
}
|
|
871
|
+
const fallback = parseOriginAndBasePath(fallbackBaseUrl);
|
|
872
|
+
let origin = "";
|
|
873
|
+
let hostBasePath = "";
|
|
874
|
+
if (hasHost) {
|
|
875
|
+
const rawHost = Array.isArray(rawUrl.host)
|
|
876
|
+
? rawUrl.host.filter((s) => typeof s === "string" && s.trim().length > 0).join(".")
|
|
877
|
+
: String(rawUrl.host).trim();
|
|
878
|
+
const interpHost = interpolateSafePostmanVars(rawHost, vars).trim();
|
|
879
|
+
if (interpHost && !POSTMAN_VAR_TEST_RE.test(interpHost)) {
|
|
880
|
+
if (/^https?:\/\//i.test(interpHost)) {
|
|
881
|
+
const parsedHost = parseOriginAndBasePath(interpHost);
|
|
882
|
+
origin = parsedHost.origin;
|
|
883
|
+
hostBasePath = parsedHost.basePath;
|
|
884
|
+
}
|
|
885
|
+
else {
|
|
886
|
+
const rawProto = typeof rawUrl.protocol === "string" && rawUrl.protocol.trim()
|
|
887
|
+
? interpolateSafePostmanVars(rawUrl.protocol.trim(), vars).replace(/:$/, "")
|
|
888
|
+
: "https";
|
|
889
|
+
const proto = rawProto === "http" || rawProto === "https" ? rawProto : "https";
|
|
890
|
+
const rawPort = typeof rawUrl.port === "string" || typeof rawUrl.port === "number"
|
|
891
|
+
? interpolateSafePostmanVars(String(rawUrl.port).trim(), vars)
|
|
892
|
+
: "";
|
|
893
|
+
const portPart = /^\d+$/.test(rawPort) ? `:${rawPort}` : "";
|
|
894
|
+
const parsedHost = parseOriginAndBasePath(`${proto}://${interpHost}${portPart}`);
|
|
895
|
+
origin = parsedHost.origin;
|
|
896
|
+
hostBasePath = parsedHost.basePath;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
else if (fallback.origin) {
|
|
900
|
+
origin = fallback.origin;
|
|
901
|
+
hostBasePath = fallback.basePath;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
else if (fallback.origin) {
|
|
905
|
+
origin = fallback.origin;
|
|
906
|
+
hostBasePath = fallback.basePath;
|
|
907
|
+
}
|
|
908
|
+
const segments = [];
|
|
909
|
+
if (hostBasePath) {
|
|
910
|
+
for (const seg of hostBasePath.split("/").filter((s) => s.length > 0)) {
|
|
911
|
+
segments.push(seg);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
if (Array.isArray(rawUrl.path)) {
|
|
915
|
+
for (const seg of rawUrl.path) {
|
|
916
|
+
if (typeof seg === "string" && seg.length > 0) {
|
|
917
|
+
segments.push(...normalizePostmanPathSegment(seg, vars, pathVars));
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
else if (typeof rawUrl.path === "string" && rawUrl.path.trim().length > 0) {
|
|
922
|
+
const cleanPath = rawUrl.path.split(/[?#]/)[0];
|
|
923
|
+
for (const seg of cleanPath.split("/").filter((s) => s.length > 0)) {
|
|
924
|
+
segments.push(...normalizePostmanPathSegment(seg, vars, pathVars));
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
else if (typeof rawUrl.raw === "string") {
|
|
928
|
+
const fromRaw = parsePostmanUrlString(rawUrl.raw, vars, pathVars, fallbackBaseUrl);
|
|
929
|
+
if (fromRaw) {
|
|
930
|
+
if (!origin && fromRaw.origin)
|
|
931
|
+
origin = fromRaw.origin;
|
|
932
|
+
const query = hasQuery
|
|
933
|
+
? sanitizePostmanQueryPairs(collectPostmanQueryPairs(rawUrl.query), vars)
|
|
934
|
+
: fromRaw.query;
|
|
935
|
+
return { origin, pathname: fromRaw.pathname, query };
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
let query = {};
|
|
939
|
+
if (hasQuery) {
|
|
940
|
+
query = sanitizePostmanQueryPairs(collectPostmanQueryPairs(rawUrl.query), vars);
|
|
941
|
+
}
|
|
942
|
+
else if (typeof rawUrl.raw === "string") {
|
|
943
|
+
const fromRaw = parsePostmanUrlString(rawUrl.raw, vars, pathVars, fallbackBaseUrl);
|
|
944
|
+
if (fromRaw)
|
|
945
|
+
query = fromRaw.query;
|
|
946
|
+
}
|
|
947
|
+
return {
|
|
948
|
+
origin,
|
|
949
|
+
pathname: segments.length > 0 ? `/${segments.join("/")}` : "/",
|
|
950
|
+
query
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
function collectPostmanQueryPairs(rawQuery) {
|
|
954
|
+
const pairs = [];
|
|
955
|
+
for (const entry of rawQuery) {
|
|
956
|
+
if (!isObject(entry) || entry.disabled === true)
|
|
957
|
+
continue;
|
|
958
|
+
const key = typeof entry.key === "string" ? entry.key.trim() : "";
|
|
959
|
+
if (!key)
|
|
960
|
+
continue;
|
|
961
|
+
const val = entry.value === undefined || entry.value === null ? "" : String(entry.value);
|
|
962
|
+
pairs.push([key, val]);
|
|
963
|
+
}
|
|
964
|
+
return pairs;
|
|
965
|
+
}
|
|
966
|
+
function collectPostmanHeaders(rawHeader, vars) {
|
|
967
|
+
const entries = [];
|
|
968
|
+
if (Array.isArray(rawHeader)) {
|
|
969
|
+
for (const item of rawHeader) {
|
|
970
|
+
if (!isObject(item) || item.disabled === true)
|
|
971
|
+
continue;
|
|
972
|
+
const key = str(item.key, str(item.name, "")).trim();
|
|
973
|
+
if (!key)
|
|
974
|
+
continue;
|
|
975
|
+
const val = item.value === undefined || item.value === null ? "" : String(item.value);
|
|
976
|
+
entries.push([key, val]);
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
else if (typeof rawHeader === "string") {
|
|
980
|
+
for (const line of rawHeader.split(/\r?\n/)) {
|
|
981
|
+
const idx = line.indexOf(":");
|
|
982
|
+
if (idx <= 0)
|
|
983
|
+
continue;
|
|
984
|
+
const key = line.slice(0, idx).trim();
|
|
985
|
+
const val = line.slice(idx + 1).trim();
|
|
986
|
+
if (key)
|
|
987
|
+
entries.push([key, val]);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
else if (isObject(rawHeader)) {
|
|
991
|
+
for (const [rawKey, rawVal] of Object.entries(rawHeader)) {
|
|
992
|
+
const key = rawKey.trim();
|
|
993
|
+
if (!key || rawVal === undefined || rawVal === null)
|
|
994
|
+
continue;
|
|
995
|
+
entries.push([key, String(rawVal)]);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
const candidate = {};
|
|
999
|
+
for (const [key, rawVal] of entries) {
|
|
1000
|
+
if (isSensitiveHeader(key) || POSTMAN_SECRET_VAR_RE.test(key))
|
|
1001
|
+
continue;
|
|
1002
|
+
if (containsSecretVarPlaceholder(rawVal, vars.secretVarNames))
|
|
1003
|
+
continue;
|
|
1004
|
+
const resolvedVal = interpolateSafePostmanVars(rawVal, vars);
|
|
1005
|
+
if (containsSecretVarPlaceholder(resolvedVal, vars.secretVarNames))
|
|
1006
|
+
continue;
|
|
1007
|
+
candidate[key] = resolvedVal;
|
|
1008
|
+
}
|
|
1009
|
+
return redactHeaders(candidate, "strip");
|
|
1010
|
+
}
|
|
1011
|
+
function extractPostmanRequestBody(rawBody, vars) {
|
|
1012
|
+
if (!isObject(rawBody) || rawBody.disabled === true)
|
|
1013
|
+
return { body: undefined, isJson: false };
|
|
1014
|
+
const mode = typeof rawBody.mode === "string" ? rawBody.mode.trim().toLowerCase() : "";
|
|
1015
|
+
if (mode === "raw" || (mode === "" && typeof rawBody.raw === "string")) {
|
|
1016
|
+
if (typeof rawBody.raw !== "string" || !rawBody.raw.trim())
|
|
1017
|
+
return { body: undefined, isJson: false };
|
|
1018
|
+
if (rawBody.raw.length > POSTMAN_MAX_BODY_BYTES)
|
|
1019
|
+
return { body: undefined, isJson: false };
|
|
1020
|
+
const safeRaw = interpolateSafePostmanVars(rawBody.raw, vars).replace(POSTMAN_VAR_RE, (full, rawName) => isSecretPostmanVarName(rawName, vars.secretVarNames) ? "[REDACTED]" : full);
|
|
1021
|
+
try {
|
|
1022
|
+
const parsed = JSON.parse(safeRaw);
|
|
1023
|
+
return { body: parsed, isJson: true };
|
|
1024
|
+
}
|
|
1025
|
+
catch {
|
|
1026
|
+
return { body: safeRaw, isJson: false };
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
if (mode === "urlencoded" && Array.isArray(rawBody.urlencoded)) {
|
|
1030
|
+
const params = new URLSearchParams();
|
|
1031
|
+
for (const entry of rawBody.urlencoded) {
|
|
1032
|
+
if (!isObject(entry) || entry.disabled === true)
|
|
1033
|
+
continue;
|
|
1034
|
+
const key = typeof entry.key === "string" ? entry.key.trim() : "";
|
|
1035
|
+
if (!key || isSensitiveQueryParam(key) || POSTMAN_SECRET_VAR_RE.test(key))
|
|
1036
|
+
continue;
|
|
1037
|
+
const rawVal = entry.value === undefined || entry.value === null ? "" : String(entry.value);
|
|
1038
|
+
if (containsSecretVarPlaceholder(rawVal, vars.secretVarNames))
|
|
1039
|
+
continue;
|
|
1040
|
+
params.append(key, interpolateSafePostmanVars(rawVal, vars));
|
|
1041
|
+
}
|
|
1042
|
+
const serialized = params.toString();
|
|
1043
|
+
return serialized ? { body: serialized, isJson: false } : { body: undefined, isJson: false };
|
|
1044
|
+
}
|
|
1045
|
+
return { body: undefined, isJson: false };
|
|
1046
|
+
}
|
|
1047
|
+
function extractPostmanResponseStatusCode(resp) {
|
|
1048
|
+
for (const field of [resp.code, resp.status]) {
|
|
1049
|
+
if (typeof field === "number" && Number.isInteger(field) && field >= 100 && field <= 599) {
|
|
1050
|
+
return field;
|
|
1051
|
+
}
|
|
1052
|
+
if (typeof field === "string" && /^\d{3}$/.test(field.trim())) {
|
|
1053
|
+
const num = Number(field.trim());
|
|
1054
|
+
if (num >= 100 && num <= 599)
|
|
1055
|
+
return num;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
return null;
|
|
1059
|
+
}
|
|
1060
|
+
function findPostmanResponseContentType(resp) {
|
|
1061
|
+
const rawHeaders = resp.header ?? resp.headers;
|
|
1062
|
+
if (Array.isArray(rawHeaders)) {
|
|
1063
|
+
for (const item of rawHeaders) {
|
|
1064
|
+
if (!isObject(item))
|
|
1065
|
+
continue;
|
|
1066
|
+
const key = str(item.key, str(item.name, "")).trim().toLowerCase();
|
|
1067
|
+
if (key === "content-type" && typeof item.value === "string" && item.value.trim()) {
|
|
1068
|
+
return item.value.trim();
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
else if (isObject(rawHeaders)) {
|
|
1073
|
+
for (const [k, v] of Object.entries(rawHeaders)) {
|
|
1074
|
+
if (k.trim().toLowerCase() === "content-type" && typeof v === "string" && v.trim()) {
|
|
1075
|
+
return v.trim();
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
return null;
|
|
1080
|
+
}
|
|
1081
|
+
function buildPostmanExpected(rawResponses) {
|
|
1082
|
+
const candidates = [];
|
|
1083
|
+
for (const entry of asArray(rawResponses)) {
|
|
1084
|
+
if (!isObject(entry))
|
|
1085
|
+
continue;
|
|
1086
|
+
const code = extractPostmanResponseStatusCode(entry);
|
|
1087
|
+
if (code !== null)
|
|
1088
|
+
candidates.push({ resp: entry, code });
|
|
1089
|
+
}
|
|
1090
|
+
const chosen = candidates.find((c) => c.code >= 200 && c.code < 300) ?? candidates[0];
|
|
1091
|
+
if (!chosen)
|
|
1092
|
+
return { status: 200 };
|
|
1093
|
+
const expected = { status: chosen.code };
|
|
1094
|
+
const rawBody = typeof chosen.resp.body === "string" ? chosen.resp.body : "";
|
|
1095
|
+
const trimmedBody = rawBody.trim();
|
|
1096
|
+
let parsedJsonOk = false;
|
|
1097
|
+
if (trimmedBody.length > 0 && rawBody.length <= POSTMAN_MAX_BODY_BYTES) {
|
|
1098
|
+
try {
|
|
1099
|
+
const parsed = JSON.parse(trimmedBody);
|
|
1100
|
+
parsedJsonOk = true;
|
|
1101
|
+
if (isObject(parsed) || Array.isArray(parsed)) {
|
|
1102
|
+
expected.jsonSchema = synthesizePostmanJsonSchema(parsed);
|
|
1103
|
+
}
|
|
1104
|
+
if (isObject(parsed)) {
|
|
1105
|
+
expected.jsonSubset = parsed;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
catch {
|
|
1109
|
+
// non-JSON example body; keep status assertion only
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
const rawContentType = findPostmanResponseContentType(chosen.resp);
|
|
1113
|
+
if (rawContentType && (parsedJsonOk || rawContentType.toLowerCase().includes("json"))) {
|
|
1114
|
+
const mediaType = rawContentType.split(";")[0].trim().toLowerCase();
|
|
1115
|
+
if (mediaType) {
|
|
1116
|
+
expected.headers = { "content-type": mediaType };
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
return expected;
|
|
1120
|
+
}
|
|
1121
|
+
export async function importPostmanCollection(sourcePath, options = {}) {
|
|
1122
|
+
if (!sourcePath || typeof sourcePath !== "string") {
|
|
1123
|
+
throw new VibecodeError("TARGET_MISSING", "postman bridge requires --source <collection.postman_collection.json>");
|
|
1124
|
+
}
|
|
1125
|
+
const abs = path.resolve(options.cwd || process.cwd(), sourcePath);
|
|
1126
|
+
const doc = loadJson(abs);
|
|
1127
|
+
if (!isPostmanCollectionDoc(doc)) {
|
|
1128
|
+
throw new VibecodeError("BRIDGE_FORMAT_ERROR", "File is not a valid Postman Collection v2.0/v2.1 JSON document");
|
|
1129
|
+
}
|
|
1130
|
+
const info = isObject(doc.info) ? doc.info : {};
|
|
1131
|
+
const collectionName = str(info.name, path.basename(sourcePath));
|
|
1132
|
+
const vars = buildSafePostmanVariables(doc);
|
|
1133
|
+
const includeMutating = options.includeMutating === true;
|
|
1134
|
+
const warnings = [];
|
|
1135
|
+
const invariants = [];
|
|
1136
|
+
const usedIds = new Set();
|
|
1137
|
+
let skippedMutatingCount = 0;
|
|
1138
|
+
let truncatedByCap = false;
|
|
1139
|
+
let truncatedByDepth = false;
|
|
1140
|
+
let firstOrigin = "";
|
|
1141
|
+
const walkItems = (items, folderTrail, depth) => {
|
|
1142
|
+
for (const entry of items) {
|
|
1143
|
+
if (!isObject(entry))
|
|
1144
|
+
continue;
|
|
1145
|
+
const entryName = str(entry.name, "");
|
|
1146
|
+
if (entry.request !== undefined && (typeof entry.request === "string" || isObject(entry.request))) {
|
|
1147
|
+
const req = entry.request;
|
|
1148
|
+
const method = typeof req === "string" ? "GET" : str(req.method, "GET").trim().toUpperCase();
|
|
1149
|
+
if (POSTMAN_MUTATING_METHODS.has(method)) {
|
|
1150
|
+
if (!includeMutating) {
|
|
1151
|
+
skippedMutatingCount += 1;
|
|
1152
|
+
}
|
|
1153
|
+
else {
|
|
1154
|
+
emitRequest(req, method, entryName, folderTrail, entry.response);
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
else if (POSTMAN_SAFE_METHODS.has(method)) {
|
|
1158
|
+
emitRequest(req, method, entryName, folderTrail, entry.response);
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
if (Array.isArray(entry.item)) {
|
|
1162
|
+
if (depth >= POSTMAN_MAX_DEPTH) {
|
|
1163
|
+
truncatedByDepth = true;
|
|
1164
|
+
continue;
|
|
1165
|
+
}
|
|
1166
|
+
const nextTrail = entryName ? [...folderTrail, entryName] : folderTrail;
|
|
1167
|
+
walkItems(entry.item, nextTrail, depth + 1);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
const emitRequest = (req, method, itemName, folderTrail, rawResponses) => {
|
|
1172
|
+
if (invariants.length >= POSTMAN_MAX_INVARIANTS) {
|
|
1173
|
+
truncatedByCap = true;
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
const rawUrl = typeof req === "string" ? req : req.url;
|
|
1177
|
+
const parsedUrl = parsePostmanUrl(rawUrl, vars, options.baseUrl);
|
|
1178
|
+
if (!parsedUrl) {
|
|
1179
|
+
pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `Skipped Postman request "${[...folderTrail, itemName || method].join(" / ")}" with missing or invalid URL.`);
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
if (!firstOrigin && parsedUrl.origin)
|
|
1183
|
+
firstOrigin = parsedUrl.origin;
|
|
1184
|
+
const headers = typeof req === "string" ? {} : collectPostmanHeaders(req.header ?? req.headers, vars);
|
|
1185
|
+
const { body, isJson } = typeof req === "string" ? { body: undefined, isJson: false } : extractPostmanRequestBody(req.body, vars);
|
|
1186
|
+
if (isJson && body !== undefined && !Object.keys(headers).some((k) => k.toLowerCase() === "content-type")) {
|
|
1187
|
+
headers["content-type"] = "application/json";
|
|
1188
|
+
}
|
|
1189
|
+
const expected = buildPostmanExpected(rawResponses);
|
|
1190
|
+
const breadcrumbParts = [...folderTrail, ...(itemName ? [itemName] : [])];
|
|
1191
|
+
const breadcrumb = breadcrumbParts.join(" / ");
|
|
1192
|
+
const description = breadcrumb
|
|
1193
|
+
? `Postman ${breadcrumb} (${method} ${parsedUrl.pathname})`
|
|
1194
|
+
: `Postman ${method} ${parsedUrl.pathname}`;
|
|
1195
|
+
const folderTags = folderTrail.map((f) => slugify(f)).filter(Boolean);
|
|
1196
|
+
const idSeed = breadcrumbParts.length > 0 ? `${method.toLowerCase()}-${breadcrumbParts.join("-")}` : `${method.toLowerCase()}-${parsedUrl.pathname}`;
|
|
1197
|
+
const input = {
|
|
1198
|
+
method,
|
|
1199
|
+
path: parsedUrl.pathname,
|
|
1200
|
+
...(Object.keys(parsedUrl.query).length > 0 ? { query: parsedUrl.query } : {}),
|
|
1201
|
+
...(Object.keys(headers).length > 0 ? { headers } : {}),
|
|
1202
|
+
...(body !== undefined ? { body } : {})
|
|
1203
|
+
};
|
|
1204
|
+
invariants.push({
|
|
1205
|
+
id: uniqueId(`inv-postman-${slugify(idSeed)}`, usedIds),
|
|
1206
|
+
domain: "api",
|
|
1207
|
+
type: "http",
|
|
1208
|
+
severity: "hard",
|
|
1209
|
+
description,
|
|
1210
|
+
tags: normalizeTags(folderTags, ["bridge", "postman", "api", "http"]),
|
|
1211
|
+
sourceId: "src-1",
|
|
1212
|
+
input,
|
|
1213
|
+
expected,
|
|
1214
|
+
tolerance: {}
|
|
1215
|
+
});
|
|
1216
|
+
};
|
|
1217
|
+
walkItems(asArray(doc.item), [], 0);
|
|
1218
|
+
if (skippedMutatingCount > 0) {
|
|
1219
|
+
pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `Skipped ${skippedMutatingCount} mutating Postman request(s) (POST/PUT/PATCH/DELETE); pass includeMutating: true to include them.`, { skippedMutatingCount });
|
|
1220
|
+
}
|
|
1221
|
+
if (truncatedByCap) {
|
|
1222
|
+
pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `Postman collection exceeded maximum of ${POSTMAN_MAX_INVARIANTS} emitted invariants; remaining requests were skipped.`);
|
|
1223
|
+
}
|
|
1224
|
+
if (truncatedByDepth) {
|
|
1225
|
+
pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `Postman collection folder nesting exceeded maximum depth of ${POSTMAN_MAX_DEPTH}; deeper folders were skipped.`);
|
|
1226
|
+
}
|
|
1227
|
+
validateInvariantsOrThrow(invariants, "postman");
|
|
1228
|
+
const rawResolvedBaseUrl = (typeof options.baseUrl === "string" && options.baseUrl.trim()) || firstOrigin || undefined;
|
|
1229
|
+
let resolvedBaseUrl;
|
|
1230
|
+
if (rawResolvedBaseUrl) {
|
|
1231
|
+
try {
|
|
1232
|
+
const u = new URL(rawResolvedBaseUrl);
|
|
1233
|
+
u.username = "";
|
|
1234
|
+
u.password = "";
|
|
1235
|
+
const safeParams = new URLSearchParams();
|
|
1236
|
+
for (const [k, v] of u.searchParams.entries()) {
|
|
1237
|
+
if (!isSensitiveQueryParam(k.trim()))
|
|
1238
|
+
safeParams.append(k, v);
|
|
1239
|
+
}
|
|
1240
|
+
u.search = safeParams.toString();
|
|
1241
|
+
resolvedBaseUrl = u.toString().replace(/\/$/, "") === u.origin ? u.origin : u.toString();
|
|
1242
|
+
}
|
|
1243
|
+
catch {
|
|
1244
|
+
resolvedBaseUrl = undefined;
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
return {
|
|
1248
|
+
domain: "api",
|
|
1249
|
+
sources: [
|
|
1250
|
+
{
|
|
1251
|
+
id: "src-1",
|
|
1252
|
+
kind: "postman",
|
|
1253
|
+
ref: sourcePath,
|
|
1254
|
+
meta: {
|
|
1255
|
+
collectionName,
|
|
1256
|
+
...(resolvedBaseUrl ? { baseUrl: resolvedBaseUrl } : {})
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
],
|
|
1260
|
+
artifacts: { root: ".vibecode/artifacts", files: {} },
|
|
1261
|
+
invariants,
|
|
1262
|
+
warnings
|
|
1263
|
+
};
|
|
1264
|
+
}
|