vibecode-anything 0.3.0 → 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/README.md +239 -67
- package/dist/cli.js +2140 -73
- package/dist/core/adapters.d.ts +26 -3
- package/dist/core/adapters.js +411 -25
- 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/docs-export.d.ts +37 -0
- package/dist/core/docs-export.js +2706 -0
- package/dist/core/doctor.d.ts +21 -1
- package/dist/core/doctor.js +234 -21
- package/dist/core/exec.d.ts +26 -2
- package/dist/core/exec.js +235 -8
- 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 +6 -1
- package/dist/core/parity.js +36 -1
- package/dist/core/playwright-exporter.d.ts +23 -0
- package/dist/core/playwright-exporter.js +1343 -0
- package/dist/core/png.js +45 -9
- 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 +3 -2
- package/dist/core/schema.js +460 -17
- 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/spec-writer.d.ts +9 -0
- package/dist/core/spec-writer.js +1202 -0
- package/dist/core/store.d.ts +11 -2
- package/dist/core/store.js +128 -8
- 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 +182 -14
- package/dist/core/visual-semantic.d.ts +67 -0
- package/dist/core/visual-semantic.js +673 -0
- package/dist/core/visual.js +65 -16
- package/dist/core/watch.d.ts +28 -3
- package/dist/core/watch.js +222 -12
- 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 +2 -1
- package/dist/ingestors/api-repo.js +483 -85
- package/dist/ingestors/asyncapi.d.ts +26 -0
- package/dist/ingestors/asyncapi.js +2105 -0
- package/dist/ingestors/bridges.d.ts +2 -0
- package/dist/ingestors/bridges.js +702 -0
- package/dist/ingestors/cli.d.ts +2 -1
- package/dist/ingestors/cli.js +234 -46
- 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/index.js +486 -6
- 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 +4 -1
- package/dist/ingestors/video.js +86 -36
- package/dist/ingestors/web.d.ts +16 -1
- package/dist/ingestors/web.js +474 -32
- package/dist/mcp/server.js +3532 -67
- package/dist/oracles/api-repo.js +102 -30
- package/dist/oracles/cli.js +65 -17
- package/dist/oracles/http-workflow.d.ts +68 -0
- package/dist/oracles/http-workflow.js +828 -0
- package/dist/oracles/image.js +178 -28
- package/dist/oracles/index.d.ts +3 -1
- package/dist/oracles/index.js +243 -14
- 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 +1 -1
- package/dist/oracles/video.js +232 -16
- package/dist/oracles/web.js +464 -73
- 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.js +145 -33
- package/package.json +56 -47
- package/skills/vibecode-anything/SKILL.md +75 -52
|
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { VibecodeError, errorMessage } from "../core/errors.js";
|
|
4
4
|
import { validateContract } from "../core/schema.js";
|
|
5
|
+
import { isSensitiveHeader, isSensitiveQueryParam, redactHeaders } from "./trace.js";
|
|
5
6
|
function isObject(v) {
|
|
6
7
|
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
7
8
|
}
|
|
@@ -19,6 +20,8 @@ function loadJson(filePath) {
|
|
|
19
20
|
catch (err) {
|
|
20
21
|
throw new VibecodeError("TARGET_MISSING", `Bridge file not found: ${filePath}`, { details: errorMessage(err) });
|
|
21
22
|
}
|
|
23
|
+
if (raw.charCodeAt(0) === 0xfeff)
|
|
24
|
+
raw = raw.slice(1);
|
|
22
25
|
try {
|
|
23
26
|
return JSON.parse(raw);
|
|
24
27
|
}
|
|
@@ -560,3 +563,702 @@ export async function importRea(filePath, options = {}) {
|
|
|
560
563
|
export async function importCliAnything(filePath, options = {}) {
|
|
561
564
|
return importBridge("cli-anything", filePath, options);
|
|
562
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
|
+
}
|