@devinnn/docdrift 0.1.1 → 0.1.3

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.
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.detectFernSpecDrift = detectFernSpecDrift;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const fs_1 = require("../utils/fs");
10
+ const json_1 = require("../utils/json");
11
+ function readFernDefinitionDir(dirPath) {
12
+ const out = {};
13
+ if (!node_fs_1.default.existsSync(dirPath) || !node_fs_1.default.statSync(dirPath).isDirectory()) {
14
+ return out;
15
+ }
16
+ const entries = node_fs_1.default.readdirSync(dirPath, { withFileTypes: true });
17
+ for (const e of entries) {
18
+ const full = node_path_1.default.join(dirPath, e.name);
19
+ if (e.isDirectory()) {
20
+ Object.assign(out, readFernDefinitionDir(full));
21
+ }
22
+ else if (e.isFile() && (e.name.endsWith(".yml") || e.name.endsWith(".yaml"))) {
23
+ out[full] = node_fs_1.default.readFileSync(full, "utf8");
24
+ }
25
+ }
26
+ return out;
27
+ }
28
+ async function getCurrentContent(config) {
29
+ const current = config.current;
30
+ if (current.type !== "local") {
31
+ throw new Error("Fern provider only supports local definition folder");
32
+ }
33
+ return readFernDefinitionDir(current.path);
34
+ }
35
+ function contentSignature(files) {
36
+ const sorted = Object.keys(files).sort();
37
+ return (0, json_1.stableStringify)(sorted.map((k) => ({ path: k, content: files[k] })));
38
+ }
39
+ async function detectFernSpecDrift(config, evidenceDir) {
40
+ if (config.format !== "fern") {
41
+ return {
42
+ hasDrift: false,
43
+ summary: `Format ${config.format} is not fern`,
44
+ evidenceFiles: [],
45
+ impactedDocs: [],
46
+ };
47
+ }
48
+ (0, fs_1.ensureDir)(evidenceDir);
49
+ let currentFiles;
50
+ try {
51
+ currentFiles = await getCurrentContent(config);
52
+ }
53
+ catch (err) {
54
+ const msg = err instanceof Error ? err.message : String(err);
55
+ const logPath = node_path_1.default.join(evidenceDir, "fern-export.log");
56
+ node_fs_1.default.writeFileSync(logPath, msg, "utf8");
57
+ return {
58
+ hasDrift: true,
59
+ summary: `Fern definition read failed: ${msg}`,
60
+ evidenceFiles: [logPath],
61
+ impactedDocs: [config.published],
62
+ signal: {
63
+ kind: "weak_evidence",
64
+ tier: 2,
65
+ confidence: 0.35,
66
+ evidence: [logPath],
67
+ },
68
+ };
69
+ }
70
+ const publishedPath = config.published;
71
+ let publishedSignature;
72
+ if (node_fs_1.default.existsSync(publishedPath) && node_fs_1.default.statSync(publishedPath).isDirectory()) {
73
+ const publishedFiles = readFernDefinitionDir(publishedPath);
74
+ publishedSignature = contentSignature(publishedFiles);
75
+ }
76
+ else if (node_fs_1.default.existsSync(publishedPath)) {
77
+ publishedSignature = node_fs_1.default.readFileSync(publishedPath, "utf8");
78
+ }
79
+ else {
80
+ return {
81
+ hasDrift: true,
82
+ summary: "Fern published path missing",
83
+ evidenceFiles: [],
84
+ impactedDocs: [config.published],
85
+ signal: {
86
+ kind: "weak_evidence",
87
+ tier: 2,
88
+ confidence: 0.35,
89
+ evidence: [],
90
+ },
91
+ };
92
+ }
93
+ const currentSignature = contentSignature(currentFiles);
94
+ if (currentSignature === publishedSignature) {
95
+ return {
96
+ hasDrift: false,
97
+ summary: "No Fern definition drift detected",
98
+ evidenceFiles: [],
99
+ impactedDocs: [config.published],
100
+ };
101
+ }
102
+ const summary = "Fern definition YAML changed.";
103
+ const diffPath = node_path_1.default.join(evidenceDir, "fern.diff.txt");
104
+ node_fs_1.default.writeFileSync(diffPath, [
105
+ "# Fern Drift Summary",
106
+ summary,
107
+ "",
108
+ "# Current definition signature (file list + content hash)",
109
+ currentSignature.slice(0, 12000),
110
+ ].join("\n"), "utf8");
111
+ return {
112
+ hasDrift: true,
113
+ summary,
114
+ evidenceFiles: [diffPath],
115
+ impactedDocs: [config.published],
116
+ signal: {
117
+ kind: "fern_diff",
118
+ tier: 1,
119
+ confidence: 0.95,
120
+ evidence: [diffPath],
121
+ },
122
+ };
123
+ }
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.detectGraphQLSpecDrift = detectGraphQLSpecDrift;
40
+ const node_fs_1 = __importDefault(require("node:fs"));
41
+ const node_path_1 = __importDefault(require("node:path"));
42
+ const fs_1 = require("../utils/fs");
43
+ const fetch_1 = require("../utils/fetch");
44
+ const GRAPHQL_INTROSPECTION_QUERY = `
45
+ query IntrospectionQuery {
46
+ __schema {
47
+ types { name kind }
48
+ queryType { name }
49
+ mutationType { name }
50
+ }
51
+ }
52
+ `;
53
+ function normalizeGraphQLSchema(content) {
54
+ // Strip comments and normalize whitespace for comparison
55
+ return content
56
+ .replace(/#[^\n]*/g, "")
57
+ .replace(/\s+/g, " ")
58
+ .trim();
59
+ }
60
+ async function getCurrentContent(config) {
61
+ const current = config.current;
62
+ if (current.type === "url") {
63
+ const body = { query: GRAPHQL_INTROSPECTION_QUERY };
64
+ const res = await (0, fetch_1.fetchSpecPost)(current.url, body);
65
+ const json = JSON.parse(res);
66
+ const schema = json?.data?.__schema;
67
+ if (!schema) {
68
+ throw new Error("GraphQL introspection did not return __schema");
69
+ }
70
+ return JSON.stringify(schema, null, 2);
71
+ }
72
+ if (current.type === "local") {
73
+ if (!node_fs_1.default.existsSync(current.path)) {
74
+ throw new Error(`GraphQL local path not found: ${current.path}`);
75
+ }
76
+ return node_fs_1.default.readFileSync(current.path, "utf8");
77
+ }
78
+ const { execCommand } = await Promise.resolve().then(() => __importStar(require("../utils/exec")));
79
+ const result = await execCommand(current.command);
80
+ if (result.exitCode !== 0) {
81
+ throw new Error(`GraphQL export failed: ${result.stderr}`);
82
+ }
83
+ if (!node_fs_1.default.existsSync(current.outputPath)) {
84
+ throw new Error(`GraphQL export did not create: ${current.outputPath}`);
85
+ }
86
+ return node_fs_1.default.readFileSync(current.outputPath, "utf8");
87
+ }
88
+ async function detectGraphQLSpecDrift(config, evidenceDir) {
89
+ if (config.format !== "graphql") {
90
+ return {
91
+ hasDrift: false,
92
+ summary: `Format ${config.format} is not graphql`,
93
+ evidenceFiles: [],
94
+ impactedDocs: [],
95
+ };
96
+ }
97
+ (0, fs_1.ensureDir)(evidenceDir);
98
+ let currentContent;
99
+ try {
100
+ currentContent = await getCurrentContent(config);
101
+ }
102
+ catch (err) {
103
+ const msg = err instanceof Error ? err.message : String(err);
104
+ const logPath = node_path_1.default.join(evidenceDir, "graphql-export.log");
105
+ node_fs_1.default.writeFileSync(logPath, msg, "utf8");
106
+ return {
107
+ hasDrift: true,
108
+ summary: `GraphQL current spec failed: ${msg}`,
109
+ evidenceFiles: [logPath],
110
+ impactedDocs: [config.published],
111
+ signal: {
112
+ kind: "weak_evidence",
113
+ tier: 2,
114
+ confidence: 0.35,
115
+ evidence: [logPath],
116
+ },
117
+ };
118
+ }
119
+ if (!node_fs_1.default.existsSync(config.published)) {
120
+ return {
121
+ hasDrift: true,
122
+ summary: "GraphQL published file missing",
123
+ evidenceFiles: [],
124
+ impactedDocs: [config.published],
125
+ signal: {
126
+ kind: "weak_evidence",
127
+ tier: 2,
128
+ confidence: 0.35,
129
+ evidence: [],
130
+ },
131
+ };
132
+ }
133
+ const publishedContent = node_fs_1.default.readFileSync(config.published, "utf8");
134
+ const normalizedCurrent = normalizeGraphQLSchema(currentContent);
135
+ const normalizedPublished = normalizeGraphQLSchema(publishedContent);
136
+ if (normalizedCurrent === normalizedPublished) {
137
+ return {
138
+ hasDrift: false,
139
+ summary: "No GraphQL schema drift detected",
140
+ evidenceFiles: [],
141
+ impactedDocs: [config.published],
142
+ };
143
+ }
144
+ const summary = "GraphQL schema changed (types or fields differ).";
145
+ const diffPath = node_path_1.default.join(evidenceDir, "graphql.diff.txt");
146
+ node_fs_1.default.writeFileSync(diffPath, [
147
+ "# GraphQL Drift Summary",
148
+ summary,
149
+ "",
150
+ "# Published (excerpt)",
151
+ normalizedPublished.slice(0, 8000),
152
+ "",
153
+ "# Current (excerpt)",
154
+ normalizedCurrent.slice(0, 8000),
155
+ ].join("\n"), "utf8");
156
+ return {
157
+ hasDrift: true,
158
+ summary,
159
+ evidenceFiles: [diffPath],
160
+ impactedDocs: [config.published],
161
+ signal: {
162
+ kind: "graphql_diff",
163
+ tier: 1,
164
+ confidence: 0.95,
165
+ evidence: [diffPath],
166
+ },
167
+ };
168
+ }
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.detectOpenApiSpecDrift = detectOpenApiSpecDrift;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const exec_1 = require("../utils/exec");
10
+ const fs_1 = require("../utils/fs");
11
+ const json_1 = require("../utils/json");
12
+ const fetch_1 = require("../utils/fetch");
13
+ function responseFields(spec) {
14
+ const fields = new Set();
15
+ const paths = spec?.paths ?? {};
16
+ for (const [pathName, methods] of Object.entries(paths)) {
17
+ for (const [method, methodDef] of Object.entries(methods)) {
18
+ const schema = methodDef?.responses?.["200"]?.content?.["application/json"]?.schema;
19
+ const properties = schema?.properties ?? {};
20
+ for (const key of Object.keys(properties)) {
21
+ fields.add(`${String(method).toUpperCase()} ${pathName}: ${key}`);
22
+ }
23
+ }
24
+ }
25
+ return fields;
26
+ }
27
+ function summarizeSpecDelta(previousSpec, currentSpec) {
28
+ const previous = responseFields(previousSpec);
29
+ const current = responseFields(currentSpec);
30
+ const added = [...current].filter((item) => !previous.has(item)).sort();
31
+ const removed = [...previous].filter((item) => !current.has(item)).sort();
32
+ const lines = [];
33
+ if (added.length) {
34
+ lines.push(`Added response fields (${added.length}):`);
35
+ lines.push(...added.map((value) => `+ ${value}`));
36
+ }
37
+ if (removed.length) {
38
+ lines.push(`Removed response fields (${removed.length}):`);
39
+ lines.push(...removed.map((value) => `- ${value}`));
40
+ }
41
+ if (!lines.length) {
42
+ return "OpenAPI changed, but no top-level response field changes were detected in 200 responses.";
43
+ }
44
+ return lines.join("\n");
45
+ }
46
+ async function getCurrentSpecContent(current, evidenceDir, logPath) {
47
+ const evidenceFiles = [];
48
+ if (current.type === "url") {
49
+ const content = await (0, fetch_1.fetchSpec)(current.url);
50
+ return { content, evidenceFiles };
51
+ }
52
+ if (current.type === "local") {
53
+ if (!node_fs_1.default.existsSync(current.path)) {
54
+ throw new Error(`OpenAPI local path not found: ${current.path}`);
55
+ }
56
+ const content = node_fs_1.default.readFileSync(current.path, "utf8");
57
+ return { content, evidenceFiles };
58
+ }
59
+ // current.type === "export"
60
+ const exportResult = await (0, exec_1.execCommand)(current.command);
61
+ node_fs_1.default.writeFileSync(logPath, [
62
+ `$ ${current.command}`,
63
+ `exitCode: ${exportResult.exitCode}`,
64
+ "\n--- stdout ---",
65
+ exportResult.stdout,
66
+ "\n--- stderr ---",
67
+ exportResult.stderr,
68
+ ].join("\n"), "utf8");
69
+ evidenceFiles.push(logPath);
70
+ if (exportResult.exitCode !== 0) {
71
+ throw new Error(`OpenAPI export failed: ${exportResult.stderr}`);
72
+ }
73
+ if (!node_fs_1.default.existsSync(current.outputPath)) {
74
+ throw new Error(`OpenAPI export did not create: ${current.outputPath}`);
75
+ }
76
+ const content = node_fs_1.default.readFileSync(current.outputPath, "utf8");
77
+ return { content, evidenceFiles };
78
+ }
79
+ async function detectOpenApiSpecDrift(config, evidenceDir) {
80
+ if (config.format !== "openapi3") {
81
+ return {
82
+ hasDrift: false,
83
+ summary: `Format ${config.format} is not openapi3`,
84
+ evidenceFiles: [],
85
+ impactedDocs: [],
86
+ };
87
+ }
88
+ (0, fs_1.ensureDir)(evidenceDir);
89
+ const logPath = node_path_1.default.join(evidenceDir, "openapi3-export.log");
90
+ let currentContent;
91
+ let evidenceFiles;
92
+ try {
93
+ const result = await getCurrentSpecContent(config.current, evidenceDir, logPath);
94
+ currentContent = result.content;
95
+ evidenceFiles = result.evidenceFiles;
96
+ }
97
+ catch (err) {
98
+ const msg = err instanceof Error ? err.message : String(err);
99
+ return {
100
+ hasDrift: true,
101
+ summary: `OpenAPI current spec failed: ${msg}`,
102
+ evidenceFiles: [logPath],
103
+ impactedDocs: [config.published],
104
+ signal: {
105
+ kind: "weak_evidence",
106
+ tier: 2,
107
+ confidence: 0.35,
108
+ evidence: [logPath],
109
+ },
110
+ };
111
+ }
112
+ if (!node_fs_1.default.existsSync(config.published)) {
113
+ return {
114
+ hasDrift: true,
115
+ summary: "OpenAPI published file missing",
116
+ evidenceFiles,
117
+ impactedDocs: [config.published],
118
+ signal: {
119
+ kind: "weak_evidence",
120
+ tier: 2,
121
+ confidence: 0.35,
122
+ evidence: evidenceFiles,
123
+ },
124
+ };
125
+ }
126
+ const publishedRaw = node_fs_1.default.readFileSync(config.published, "utf8");
127
+ let currentJson;
128
+ let publishedJson;
129
+ try {
130
+ currentJson = JSON.parse(currentContent);
131
+ publishedJson = JSON.parse(publishedRaw);
132
+ }
133
+ catch {
134
+ return {
135
+ hasDrift: true,
136
+ summary: "OpenAPI invalid JSON",
137
+ evidenceFiles,
138
+ impactedDocs: [config.published],
139
+ signal: {
140
+ kind: "weak_evidence",
141
+ tier: 2,
142
+ confidence: 0.35,
143
+ evidence: evidenceFiles,
144
+ },
145
+ };
146
+ }
147
+ const normalizedCurrent = (0, json_1.stableStringify)(currentJson);
148
+ const normalizedPublished = (0, json_1.stableStringify)(publishedJson);
149
+ if (normalizedCurrent === normalizedPublished) {
150
+ return {
151
+ hasDrift: false,
152
+ summary: "No OpenAPI drift detected",
153
+ evidenceFiles,
154
+ impactedDocs: [config.published],
155
+ };
156
+ }
157
+ const summary = summarizeSpecDelta(publishedJson, currentJson);
158
+ const diffPath = node_path_1.default.join(evidenceDir, "openapi3.diff.txt");
159
+ node_fs_1.default.writeFileSync(diffPath, [
160
+ "# OpenAPI Drift Summary",
161
+ summary,
162
+ "",
163
+ "# Published (normalized)",
164
+ normalizedPublished,
165
+ "",
166
+ "# Current (normalized)",
167
+ normalizedCurrent,
168
+ ].join("\n"), "utf8");
169
+ return {
170
+ hasDrift: true,
171
+ summary,
172
+ evidenceFiles: [...evidenceFiles, diffPath],
173
+ impactedDocs: [config.published],
174
+ signal: {
175
+ kind: "openapi_diff",
176
+ tier: 1,
177
+ confidence: 0.95,
178
+ evidence: [diffPath],
179
+ },
180
+ };
181
+ }
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.detectPostmanSpecDrift = detectPostmanSpecDrift;
40
+ const node_fs_1 = __importDefault(require("node:fs"));
41
+ const node_path_1 = __importDefault(require("node:path"));
42
+ const fs_1 = require("../utils/fs");
43
+ const json_1 = require("../utils/json");
44
+ const fetch_1 = require("../utils/fetch");
45
+ function extractEndpoints(collection) {
46
+ const endpoints = new Set();
47
+ const info = collection?.info ?? collection?.information;
48
+ const items = collection?.item ?? [];
49
+ function walk(items, prefix = "") {
50
+ for (const item of items) {
51
+ if (!item)
52
+ continue;
53
+ const name = item.name ?? item.id ?? "";
54
+ if (item.request) {
55
+ const req = typeof item.request === "string" ? { url: item.request, method: "GET" } : item.request;
56
+ const url = req?.url?.raw ?? req?.url ?? "";
57
+ const method = (req?.method ?? "GET").toUpperCase();
58
+ if (url) {
59
+ endpoints.add(`${method} ${url}`);
60
+ }
61
+ }
62
+ else if (item.item) {
63
+ walk(item.item, `${prefix}/${name}`);
64
+ }
65
+ }
66
+ }
67
+ walk(Array.isArray(items) ? items : [items]);
68
+ return endpoints;
69
+ }
70
+ async function getCurrentContent(config) {
71
+ const current = config.current;
72
+ if (current.type === "url") {
73
+ return (0, fetch_1.fetchSpec)(current.url);
74
+ }
75
+ if (current.type === "local") {
76
+ if (!node_fs_1.default.existsSync(current.path)) {
77
+ throw new Error(`Postman collection path not found: ${current.path}`);
78
+ }
79
+ return node_fs_1.default.readFileSync(current.path, "utf8");
80
+ }
81
+ const { execCommand } = await Promise.resolve().then(() => __importStar(require("../utils/exec")));
82
+ const result = await execCommand(current.command);
83
+ if (result.exitCode !== 0) {
84
+ throw new Error(`Postman export failed: ${result.stderr}`);
85
+ }
86
+ if (!node_fs_1.default.existsSync(current.outputPath)) {
87
+ throw new Error(`Postman export did not create: ${current.outputPath}`);
88
+ }
89
+ return node_fs_1.default.readFileSync(current.outputPath, "utf8");
90
+ }
91
+ async function detectPostmanSpecDrift(config, evidenceDir) {
92
+ if (config.format !== "postman") {
93
+ return {
94
+ hasDrift: false,
95
+ summary: `Format ${config.format} is not postman`,
96
+ evidenceFiles: [],
97
+ impactedDocs: [],
98
+ };
99
+ }
100
+ (0, fs_1.ensureDir)(evidenceDir);
101
+ let currentContent;
102
+ try {
103
+ currentContent = await getCurrentContent(config);
104
+ }
105
+ catch (err) {
106
+ const msg = err instanceof Error ? err.message : String(err);
107
+ const logPath = node_path_1.default.join(evidenceDir, "postman-export.log");
108
+ node_fs_1.default.writeFileSync(logPath, msg, "utf8");
109
+ return {
110
+ hasDrift: true,
111
+ summary: `Postman current spec failed: ${msg}`,
112
+ evidenceFiles: [logPath],
113
+ impactedDocs: [config.published],
114
+ signal: {
115
+ kind: "weak_evidence",
116
+ tier: 2,
117
+ confidence: 0.35,
118
+ evidence: [logPath],
119
+ },
120
+ };
121
+ }
122
+ if (!node_fs_1.default.existsSync(config.published)) {
123
+ return {
124
+ hasDrift: true,
125
+ summary: "Postman published file missing",
126
+ evidenceFiles: [],
127
+ impactedDocs: [config.published],
128
+ signal: {
129
+ kind: "weak_evidence",
130
+ tier: 2,
131
+ confidence: 0.35,
132
+ evidence: [],
133
+ },
134
+ };
135
+ }
136
+ const publishedRaw = node_fs_1.default.readFileSync(config.published, "utf8");
137
+ let currentJson;
138
+ let publishedJson;
139
+ try {
140
+ currentJson = JSON.parse(currentContent);
141
+ publishedJson = JSON.parse(publishedRaw);
142
+ }
143
+ catch {
144
+ return {
145
+ hasDrift: true,
146
+ summary: "Postman collection invalid JSON",
147
+ evidenceFiles: [],
148
+ impactedDocs: [config.published],
149
+ signal: {
150
+ kind: "weak_evidence",
151
+ tier: 2,
152
+ confidence: 0.35,
153
+ evidence: [],
154
+ },
155
+ };
156
+ }
157
+ const currentEndpoints = extractEndpoints(currentJson);
158
+ const publishedEndpoints = extractEndpoints(publishedJson);
159
+ const added = [...currentEndpoints].filter((e) => !publishedEndpoints.has(e)).sort();
160
+ const removed = [...publishedEndpoints].filter((e) => !currentEndpoints.has(e)).sort();
161
+ if (added.length === 0 && removed.length === 0) {
162
+ return {
163
+ hasDrift: false,
164
+ summary: "No Postman collection drift detected",
165
+ evidenceFiles: [],
166
+ impactedDocs: [config.published],
167
+ };
168
+ }
169
+ const lines = [];
170
+ if (added.length) {
171
+ lines.push(`Added endpoints (${added.length}):`);
172
+ lines.push(...added.map((v) => `+ ${v}`));
173
+ }
174
+ if (removed.length) {
175
+ lines.push(`Removed endpoints (${removed.length}):`);
176
+ lines.push(...removed.map((v) => `- ${v}`));
177
+ }
178
+ const summary = lines.join("\n");
179
+ const diffPath = node_path_1.default.join(evidenceDir, "postman.diff.txt");
180
+ node_fs_1.default.writeFileSync(diffPath, ["# Postman Drift Summary", summary, "", "# Current endpoints", (0, json_1.stableStringify)([...currentEndpoints].sort()), "", "# Published endpoints", (0, json_1.stableStringify)([...publishedEndpoints].sort())].join("\n"), "utf8");
181
+ return {
182
+ hasDrift: true,
183
+ summary,
184
+ evidenceFiles: [diffPath],
185
+ impactedDocs: [config.published],
186
+ signal: {
187
+ kind: "postman_diff",
188
+ tier: 1,
189
+ confidence: 0.95,
190
+ evidence: [diffPath],
191
+ },
192
+ };
193
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSpecDetector = getSpecDetector;
4
+ exports.getSupportedFormats = getSupportedFormats;
5
+ const openapi_1 = require("./openapi");
6
+ const swagger2_1 = require("./swagger2");
7
+ const graphql_1 = require("./graphql");
8
+ const fern_1 = require("./fern");
9
+ const postman_1 = require("./postman");
10
+ const registry = {
11
+ openapi3: openapi_1.detectOpenApiSpecDrift,
12
+ swagger2: swagger2_1.detectSwagger2SpecDrift,
13
+ graphql: graphql_1.detectGraphQLSpecDrift,
14
+ fern: fern_1.detectFernSpecDrift,
15
+ postman: postman_1.detectPostmanSpecDrift,
16
+ };
17
+ function getSpecDetector(format) {
18
+ const detector = registry[format];
19
+ if (!detector) {
20
+ throw new Error(`Unknown spec format: ${format}`);
21
+ }
22
+ return detector;
23
+ }
24
+ function getSupportedFormats() {
25
+ return Object.keys(registry);
26
+ }