guardrail-core 1.0.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.
Files changed (189) hide show
  1. package/dist/__tests__/autopilot.test.d.ts +7 -0
  2. package/dist/__tests__/autopilot.test.d.ts.map +1 -0
  3. package/dist/__tests__/autopilot.test.js +156 -0
  4. package/dist/__tests__/tier-config.test.d.ts +9 -0
  5. package/dist/__tests__/tier-config.test.d.ts.map +1 -0
  6. package/dist/__tests__/tier-config.test.js +230 -0
  7. package/dist/__tests__/utils/hash-inline.test.d.ts +2 -0
  8. package/dist/__tests__/utils/hash-inline.test.d.ts.map +1 -0
  9. package/dist/__tests__/utils/hash-inline.test.js +62 -0
  10. package/dist/__tests__/utils/hash.test.d.ts +3 -0
  11. package/dist/__tests__/utils/hash.test.d.ts.map +1 -0
  12. package/dist/__tests__/utils/hash.test.js +95 -0
  13. package/dist/__tests__/utils/simple.test.d.ts +1 -0
  14. package/dist/__tests__/utils/simple.test.d.ts.map +1 -0
  15. package/dist/__tests__/utils/simple.test.js +10 -0
  16. package/dist/__tests__/utils/utils-simple.test.d.ts +1 -0
  17. package/dist/__tests__/utils/utils-simple.test.d.ts.map +1 -0
  18. package/dist/__tests__/utils/utils-simple.test.js +6 -0
  19. package/dist/__tests__/utils/utils.test.d.ts +15 -0
  20. package/dist/__tests__/utils/utils.test.d.ts.map +1 -0
  21. package/dist/__tests__/utils/utils.test.js +172 -0
  22. package/dist/autopilot/autopilot-runner.d.ts +33 -0
  23. package/dist/autopilot/autopilot-runner.d.ts.map +1 -0
  24. package/dist/autopilot/autopilot-runner.js +479 -0
  25. package/dist/autopilot/index.d.ts +6 -0
  26. package/dist/autopilot/index.d.ts.map +1 -0
  27. package/dist/autopilot/index.js +25 -0
  28. package/dist/autopilot/types.d.ts +102 -0
  29. package/dist/autopilot/types.d.ts.map +1 -0
  30. package/dist/autopilot/types.js +18 -0
  31. package/dist/cache/index.d.ts +7 -0
  32. package/dist/cache/index.d.ts.map +1 -0
  33. package/dist/cache/index.js +22 -0
  34. package/dist/cache/redis-cache.d.ts +145 -0
  35. package/dist/cache/redis-cache.d.ts.map +1 -0
  36. package/dist/cache/redis-cache.js +459 -0
  37. package/dist/ci/github-actions.d.ts +77 -0
  38. package/dist/ci/github-actions.d.ts.map +1 -0
  39. package/dist/ci/github-actions.js +277 -0
  40. package/dist/ci/index.d.ts +12 -0
  41. package/dist/ci/index.d.ts.map +1 -0
  42. package/dist/ci/index.js +27 -0
  43. package/dist/ci/pre-commit.d.ts +65 -0
  44. package/dist/ci/pre-commit.d.ts.map +1 -0
  45. package/dist/ci/pre-commit.js +286 -0
  46. package/dist/entitlements.d.ts +149 -0
  47. package/dist/entitlements.d.ts.map +1 -0
  48. package/dist/entitlements.js +464 -0
  49. package/dist/env.d.ts +113 -0
  50. package/dist/env.d.ts.map +1 -0
  51. package/dist/env.js +204 -0
  52. package/dist/fix-packs/__tests__/generate-fix-packs.test.d.ts +7 -0
  53. package/dist/fix-packs/__tests__/generate-fix-packs.test.d.ts.map +1 -0
  54. package/dist/fix-packs/__tests__/generate-fix-packs.test.js +250 -0
  55. package/dist/fix-packs/generate-fix-packs.d.ts +15 -0
  56. package/dist/fix-packs/generate-fix-packs.d.ts.map +1 -0
  57. package/dist/fix-packs/generate-fix-packs.js +505 -0
  58. package/dist/fix-packs/index.d.ts +8 -0
  59. package/dist/fix-packs/index.d.ts.map +1 -0
  60. package/dist/fix-packs/index.js +23 -0
  61. package/dist/fix-packs/types.d.ts +113 -0
  62. package/dist/fix-packs/types.d.ts.map +1 -0
  63. package/dist/fix-packs/types.js +71 -0
  64. package/dist/index.d.ts +13 -0
  65. package/dist/index.d.ts.map +1 -0
  66. package/dist/index.js +28 -0
  67. package/dist/metrics/prometheus.d.ts +99 -0
  68. package/dist/metrics/prometheus.d.ts.map +1 -0
  69. package/dist/metrics/prometheus.js +306 -0
  70. package/dist/quota-ledger.d.ts +119 -0
  71. package/dist/quota-ledger.d.ts.map +1 -0
  72. package/dist/quota-ledger.js +462 -0
  73. package/dist/rbac/__tests__/permissions.test.d.ts +8 -0
  74. package/dist/rbac/__tests__/permissions.test.d.ts.map +1 -0
  75. package/dist/rbac/__tests__/permissions.test.js +350 -0
  76. package/dist/rbac/index.d.ts +9 -0
  77. package/dist/rbac/index.d.ts.map +1 -0
  78. package/dist/rbac/index.js +32 -0
  79. package/dist/rbac/permissions.d.ts +71 -0
  80. package/dist/rbac/permissions.d.ts.map +1 -0
  81. package/dist/rbac/permissions.js +247 -0
  82. package/dist/rbac/types.d.ts +69 -0
  83. package/dist/rbac/types.d.ts.map +1 -0
  84. package/dist/rbac/types.js +213 -0
  85. package/dist/tier-config.d.ts +203 -0
  86. package/dist/tier-config.d.ts.map +1 -0
  87. package/dist/tier-config.js +675 -0
  88. package/dist/types.d.ts +365 -0
  89. package/dist/types.d.ts.map +1 -0
  90. package/dist/types.js +5 -0
  91. package/dist/utils.d.ts +36 -0
  92. package/dist/utils.d.ts.map +1 -0
  93. package/dist/utils.js +127 -0
  94. package/dist/verified-autofix/__tests__/format-validator.test.d.ts +11 -0
  95. package/dist/verified-autofix/__tests__/format-validator.test.d.ts.map +1 -0
  96. package/dist/verified-autofix/__tests__/format-validator.test.js +285 -0
  97. package/dist/verified-autofix/__tests__/pipeline.test.d.ts +11 -0
  98. package/dist/verified-autofix/__tests__/pipeline.test.d.ts.map +1 -0
  99. package/dist/verified-autofix/__tests__/pipeline.test.js +389 -0
  100. package/dist/verified-autofix/__tests__/repo-fingerprint.test.d.ts +11 -0
  101. package/dist/verified-autofix/__tests__/repo-fingerprint.test.d.ts.map +1 -0
  102. package/dist/verified-autofix/__tests__/repo-fingerprint.test.js +236 -0
  103. package/dist/verified-autofix/__tests__/workspace.test.d.ts +11 -0
  104. package/dist/verified-autofix/__tests__/workspace.test.d.ts.map +1 -0
  105. package/dist/verified-autofix/__tests__/workspace.test.js +314 -0
  106. package/dist/verified-autofix/format-validator.d.ts +101 -0
  107. package/dist/verified-autofix/format-validator.d.ts.map +1 -0
  108. package/dist/verified-autofix/format-validator.js +446 -0
  109. package/dist/verified-autofix/index.d.ts +14 -0
  110. package/dist/verified-autofix/index.d.ts.map +1 -0
  111. package/dist/verified-autofix/index.js +39 -0
  112. package/dist/verified-autofix/pipeline.d.ts +68 -0
  113. package/dist/verified-autofix/pipeline.d.ts.map +1 -0
  114. package/dist/verified-autofix/pipeline.js +330 -0
  115. package/dist/verified-autofix/repo-fingerprint.d.ts +56 -0
  116. package/dist/verified-autofix/repo-fingerprint.d.ts.map +1 -0
  117. package/dist/verified-autofix/repo-fingerprint.js +396 -0
  118. package/dist/verified-autofix/workspace.d.ts +83 -0
  119. package/dist/verified-autofix/workspace.d.ts.map +1 -0
  120. package/dist/verified-autofix/workspace.js +454 -0
  121. package/dist/verified-autofix.d.ts +182 -0
  122. package/dist/verified-autofix.d.ts.map +1 -0
  123. package/dist/verified-autofix.js +1021 -0
  124. package/dist/visualization/dependency-graph.d.ts +79 -0
  125. package/dist/visualization/dependency-graph.d.ts.map +1 -0
  126. package/dist/visualization/dependency-graph.js +399 -0
  127. package/dist/visualization/index.d.ts +5 -0
  128. package/dist/visualization/index.d.ts.map +1 -0
  129. package/dist/visualization/index.js +20 -0
  130. package/package.json +29 -0
  131. package/src/__tests__/autopilot.test.ts +196 -0
  132. package/src/__tests__/tier-config.test.ts +289 -0
  133. package/src/__tests__/utils/hash-inline.test.ts +76 -0
  134. package/src/__tests__/utils/hash.test.ts +119 -0
  135. package/src/__tests__/utils/simple.test.ts +10 -0
  136. package/src/__tests__/utils/utils-simple.test.ts +5 -0
  137. package/src/__tests__/utils/utils.test.ts +203 -0
  138. package/src/autopilot/autopilot-runner.ts +503 -0
  139. package/src/autopilot/index.ts +6 -0
  140. package/src/autopilot/types.ts +119 -0
  141. package/src/cache/index.ts +7 -0
  142. package/src/cache/redis-cache.d.ts +155 -0
  143. package/src/cache/redis-cache.d.ts.map +1 -0
  144. package/src/cache/redis-cache.ts +517 -0
  145. package/src/ci/github-actions.ts +335 -0
  146. package/src/ci/index.ts +12 -0
  147. package/src/ci/pre-commit.ts +338 -0
  148. package/src/db/usage-schema.prisma +114 -0
  149. package/src/entitlements.ts +570 -0
  150. package/src/env.d.ts +68 -0
  151. package/src/env.d.ts.map +1 -0
  152. package/src/env.ts +247 -0
  153. package/src/fix-packs/__tests__/generate-fix-packs.test.ts +317 -0
  154. package/src/fix-packs/generate-fix-packs.ts +577 -0
  155. package/src/fix-packs/index.ts +8 -0
  156. package/src/fix-packs/types.ts +206 -0
  157. package/src/index.d.ts +7 -0
  158. package/src/index.d.ts.map +1 -0
  159. package/src/index.ts +12 -0
  160. package/src/metrics/prometheus.d.ts +104 -0
  161. package/src/metrics/prometheus.d.ts.map +1 -0
  162. package/src/metrics/prometheus.ts +446 -0
  163. package/src/quota-ledger.ts +548 -0
  164. package/src/rbac/__tests__/permissions.test.ts +446 -0
  165. package/src/rbac/index.ts +46 -0
  166. package/src/rbac/permissions.ts +301 -0
  167. package/src/rbac/types.ts +298 -0
  168. package/src/tier-config.json +157 -0
  169. package/src/tier-config.ts +815 -0
  170. package/src/types.d.ts +365 -0
  171. package/src/types.d.ts.map +1 -0
  172. package/src/types.ts +441 -0
  173. package/src/utils.d.ts +36 -0
  174. package/src/utils.d.ts.map +1 -0
  175. package/src/utils.ts +140 -0
  176. package/src/verified-autofix/__tests__/format-validator.test.ts +335 -0
  177. package/src/verified-autofix/__tests__/pipeline.test.ts +419 -0
  178. package/src/verified-autofix/__tests__/repo-fingerprint.test.ts +241 -0
  179. package/src/verified-autofix/__tests__/workspace.test.ts +373 -0
  180. package/src/verified-autofix/format-validator.ts +517 -0
  181. package/src/verified-autofix/index.ts +63 -0
  182. package/src/verified-autofix/pipeline.ts +403 -0
  183. package/src/verified-autofix/repo-fingerprint.ts +459 -0
  184. package/src/verified-autofix/workspace.ts +531 -0
  185. package/src/verified-autofix.ts +1187 -0
  186. package/src/visualization/dependency-graph.d.ts +85 -0
  187. package/src/visualization/dependency-graph.d.ts.map +1 -0
  188. package/src/visualization/dependency-graph.ts +495 -0
  189. package/src/visualization/index.ts +5 -0
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Visual Dependency Graph Generator
3
+ *
4
+ * Generates interactive dependency graphs showing:
5
+ * - Package dependencies and their relationships
6
+ * - Vulnerability status of each package
7
+ * - License compatibility
8
+ * - Security risk levels
9
+ */
10
+ export interface DependencyNode {
11
+ id: string;
12
+ name: string;
13
+ version: string;
14
+ type: "root" | "direct" | "transitive";
15
+ vulnerabilities: VulnerabilityInfo[];
16
+ license: string;
17
+ riskLevel: "none" | "low" | "medium" | "high" | "critical";
18
+ depth: number;
19
+ size?: number;
20
+ }
21
+ export interface DependencyEdge {
22
+ source: string;
23
+ target: string;
24
+ type: "dependency" | "devDependency" | "peerDependency";
25
+ }
26
+ export interface VulnerabilityInfo {
27
+ id: string;
28
+ severity: "low" | "medium" | "high" | "critical";
29
+ title: string;
30
+ }
31
+ export interface DependencyGraph {
32
+ nodes: DependencyNode[];
33
+ edges: DependencyEdge[];
34
+ metadata: {
35
+ projectName: string;
36
+ totalPackages: number;
37
+ vulnerablePackages: number;
38
+ riskDistribution: Record<string, number>;
39
+ generatedAt: string;
40
+ };
41
+ }
42
+ export interface GraphRenderOptions {
43
+ format: "svg" | "html" | "json" | "d3" | "mermaid";
44
+ width?: number;
45
+ height?: number;
46
+ showVulnerabilities?: boolean;
47
+ showLicenses?: boolean;
48
+ highlightVulnerable?: boolean;
49
+ maxDepth?: number;
50
+ colorScheme?: "default" | "colorblind" | "dark";
51
+ }
52
+ export declare class DependencyGraphGenerator {
53
+ /**
54
+ * Generate dependency graph from package.json
55
+ */
56
+ generateFromPackageJson(packageJsonPath: string, options?: Partial<GraphRenderOptions>): Promise<DependencyGraph>;
57
+ /**
58
+ * Create a dependency node
59
+ */
60
+ private createNode;
61
+ /**
62
+ * Get transitive dependencies
63
+ */
64
+ private getTransitiveDeps;
65
+ /**
66
+ * Render graph to Mermaid format
67
+ */
68
+ renderToMermaid(graph: DependencyGraph): string;
69
+ /**
70
+ * Render graph to D3.js compatible JSON
71
+ */
72
+ renderToD3(graph: DependencyGraph): string;
73
+ /**
74
+ * Render graph to HTML with embedded visualization
75
+ */
76
+ renderToHTML(graph: DependencyGraph, options?: Partial<GraphRenderOptions>): string;
77
+ }
78
+ export declare const dependencyGraphGenerator: DependencyGraphGenerator;
79
+ //# sourceMappingURL=dependency-graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency-graph.d.ts","sourceRoot":"","sources":["../../src/visualization/dependency-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,YAAY,CAAC;IACvC,eAAe,EAAE,iBAAiB,EAAE,CAAC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;IAC3D,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,YAAY,GAAG,eAAe,GAAG,gBAAgB,CAAC;CACzD;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;IACjD,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,QAAQ,EAAE;QACR,WAAW,EAAE,MAAM,CAAC;QACpB,aAAa,EAAE,MAAM,CAAC;QACtB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACzC,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACH;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,SAAS,GAAG,YAAY,GAAG,MAAM,CAAC;CACjD;AAED,qBAAa,wBAAwB;IACnC;;OAEG;IACG,uBAAuB,CAC3B,eAAe,EAAE,MAAM,EACvB,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAM,GACxC,OAAO,CAAC,eAAe,CAAC;IA6G3B;;OAEG;YACW,UAAU;IAoDxB;;OAEG;YACW,iBAAiB;IAiE/B;;OAEG;IACH,eAAe,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM;IAsC/C;;OAEG;IACH,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM;IAqB1C;;OAEG;IACH,YAAY,CACV,KAAK,EAAE,eAAe,EACtB,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAM,GACxC,MAAM;CA4HV;AAGD,eAAO,MAAM,wBAAwB,0BAAiC,CAAC"}
@@ -0,0 +1,399 @@
1
+ "use strict";
2
+ /**
3
+ * Visual Dependency Graph Generator
4
+ *
5
+ * Generates interactive dependency graphs showing:
6
+ * - Package dependencies and their relationships
7
+ * - Vulnerability status of each package
8
+ * - License compatibility
9
+ * - Security risk levels
10
+ */
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
+ desc = { enumerable: true, get: function() { return m[k]; } };
16
+ }
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
24
+ }) : function(o, v) {
25
+ o["default"] = v;
26
+ });
27
+ var __importStar = (this && this.__importStar) || (function () {
28
+ var ownKeys = function(o) {
29
+ ownKeys = Object.getOwnPropertyNames || function (o) {
30
+ var ar = [];
31
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
32
+ return ar;
33
+ };
34
+ return ownKeys(o);
35
+ };
36
+ return function (mod) {
37
+ if (mod && mod.__esModule) return mod;
38
+ var result = {};
39
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
40
+ __setModuleDefault(result, mod);
41
+ return result;
42
+ };
43
+ })();
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.dependencyGraphGenerator = exports.DependencyGraphGenerator = void 0;
46
+ class DependencyGraphGenerator {
47
+ /**
48
+ * Generate dependency graph from package.json
49
+ */
50
+ async generateFromPackageJson(packageJsonPath, options = {}) {
51
+ const { readFileSync } = await Promise.resolve().then(() => __importStar(require("fs")));
52
+ const { dirname } = await Promise.resolve().then(() => __importStar(require("path")));
53
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
54
+ const projectDir = dirname(packageJsonPath);
55
+ const nodes = [];
56
+ const edges = [];
57
+ const visited = new Set();
58
+ // Add root node
59
+ const rootId = `${packageJson.name}@${packageJson.version}`;
60
+ nodes.push({
61
+ id: rootId,
62
+ name: packageJson.name || "root",
63
+ version: packageJson.version || "0.0.0",
64
+ type: "root",
65
+ vulnerabilities: [],
66
+ license: packageJson.license || "UNKNOWN",
67
+ riskLevel: "none",
68
+ depth: 0,
69
+ });
70
+ // Process direct dependencies
71
+ const deps = packageJson.dependencies || {};
72
+ const devDeps = packageJson.devDependencies || {};
73
+ for (const [name, version] of Object.entries(deps)) {
74
+ const nodeId = `${name}@${version}`;
75
+ if (!visited.has(nodeId)) {
76
+ visited.add(nodeId);
77
+ const node = await this.createNode(name, String(version), "direct", 1, projectDir);
78
+ nodes.push(node);
79
+ edges.push({ source: rootId, target: nodeId, type: "dependency" });
80
+ // Check for transitive dependencies
81
+ if (options.maxDepth !== 1) {
82
+ const transitives = await this.getTransitiveDeps(name, projectDir, visited, 2, options.maxDepth || 3);
83
+ for (const trans of transitives.nodes) {
84
+ nodes.push(trans);
85
+ }
86
+ for (const edge of transitives.edges) {
87
+ edges.push(edge);
88
+ }
89
+ }
90
+ }
91
+ }
92
+ for (const [name, version] of Object.entries(devDeps)) {
93
+ const nodeId = `${name}@${version}`;
94
+ if (!visited.has(nodeId)) {
95
+ visited.add(nodeId);
96
+ const node = await this.createNode(name, String(version), "direct", 1, projectDir);
97
+ nodes.push(node);
98
+ edges.push({ source: rootId, target: nodeId, type: "devDependency" });
99
+ }
100
+ }
101
+ // Calculate risk distribution
102
+ const riskDistribution = {
103
+ none: 0,
104
+ low: 0,
105
+ medium: 0,
106
+ high: 0,
107
+ critical: 0,
108
+ };
109
+ for (const node of nodes) {
110
+ const level = node.riskLevel;
111
+ if (typeof riskDistribution[level] === "number") {
112
+ riskDistribution[level]++;
113
+ }
114
+ }
115
+ const vulnerablePackages = nodes.filter((n) => n.vulnerabilities.length > 0).length;
116
+ return {
117
+ nodes,
118
+ edges,
119
+ metadata: {
120
+ projectName: packageJson.name || "unknown",
121
+ totalPackages: nodes.length,
122
+ vulnerablePackages,
123
+ riskDistribution,
124
+ generatedAt: new Date().toISOString(),
125
+ },
126
+ };
127
+ }
128
+ /**
129
+ * Create a dependency node
130
+ */
131
+ async createNode(name, version, type, depth, projectDir) {
132
+ const { existsSync, readFileSync } = await Promise.resolve().then(() => __importStar(require("fs")));
133
+ const { join } = await Promise.resolve().then(() => __importStar(require("path")));
134
+ const versionStr = String(version).replace(/^[\^~]/, "");
135
+ const nodeId = `${name}@${version}`;
136
+ // Try to get license from node_modules
137
+ let license = "UNKNOWN";
138
+ const pkgPath = join(projectDir, "node_modules", name, "package.json");
139
+ if (existsSync(pkgPath)) {
140
+ try {
141
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
142
+ license = pkg.license || "UNKNOWN";
143
+ }
144
+ catch {
145
+ // Skip
146
+ }
147
+ }
148
+ // Placeholder for vulnerability check - would integrate with vulnerability DB
149
+ const vulnerabilities = [];
150
+ // Calculate risk level based on vulnerabilities
151
+ let riskLevel = "none";
152
+ if (vulnerabilities.some((v) => v.severity === "critical")) {
153
+ riskLevel = "critical";
154
+ }
155
+ else if (vulnerabilities.some((v) => v.severity === "high")) {
156
+ riskLevel = "high";
157
+ }
158
+ else if (vulnerabilities.some((v) => v.severity === "medium")) {
159
+ riskLevel = "medium";
160
+ }
161
+ else if (vulnerabilities.length > 0) {
162
+ riskLevel = "low";
163
+ }
164
+ return {
165
+ id: nodeId,
166
+ name,
167
+ version: versionStr,
168
+ type,
169
+ vulnerabilities,
170
+ license,
171
+ riskLevel,
172
+ depth,
173
+ };
174
+ }
175
+ /**
176
+ * Get transitive dependencies
177
+ */
178
+ async getTransitiveDeps(packageName, projectDir, visited, currentDepth, maxDepth) {
179
+ const { existsSync, readFileSync } = await Promise.resolve().then(() => __importStar(require("fs")));
180
+ const { join } = await Promise.resolve().then(() => __importStar(require("path")));
181
+ const nodes = [];
182
+ const edges = [];
183
+ if (currentDepth > maxDepth) {
184
+ return { nodes, edges };
185
+ }
186
+ const pkgPath = join(projectDir, "node_modules", packageName, "package.json");
187
+ if (!existsSync(pkgPath)) {
188
+ return { nodes, edges };
189
+ }
190
+ try {
191
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
192
+ const deps = pkg.dependencies || {};
193
+ const parentId = `${packageName}@${pkg.version}`;
194
+ for (const [name, version] of Object.entries(deps)) {
195
+ const nodeId = `${name}@${version}`;
196
+ if (!visited.has(nodeId)) {
197
+ visited.add(nodeId);
198
+ const node = await this.createNode(name, String(version), "transitive", currentDepth, projectDir);
199
+ nodes.push(node);
200
+ edges.push({ source: parentId, target: nodeId, type: "dependency" });
201
+ // Recurse for deeper transitive deps
202
+ const deeper = await this.getTransitiveDeps(name, projectDir, visited, currentDepth + 1, maxDepth);
203
+ nodes.push(...deeper.nodes);
204
+ edges.push(...deeper.edges);
205
+ }
206
+ }
207
+ }
208
+ catch {
209
+ // Skip packages we can't read
210
+ }
211
+ return { nodes, edges };
212
+ }
213
+ /**
214
+ * Render graph to Mermaid format
215
+ */
216
+ renderToMermaid(graph) {
217
+ const lines = ["graph TD"];
218
+ // Define node styles based on risk level
219
+ const riskStyles = {
220
+ none: "fill:#90EE90",
221
+ low: "fill:#FFFF99",
222
+ medium: "fill:#FFB347",
223
+ high: "fill:#FF6B6B",
224
+ critical: "fill:#FF0000,color:#fff",
225
+ };
226
+ // Add nodes
227
+ for (const node of graph.nodes) {
228
+ const label = `${node.name}@${node.version}`;
229
+ const safeId = node.id.replace(/[@./]/g, "_");
230
+ lines.push(` ${safeId}["${label}"]`);
231
+ }
232
+ // Add edges
233
+ for (const edge of graph.edges) {
234
+ const sourceId = edge.source.replace(/[@./]/g, "_");
235
+ const targetId = edge.target.replace(/[@./]/g, "_");
236
+ const edgeStyle = edge.type === "devDependency" ? "-->" : "-->";
237
+ lines.push(` ${sourceId} ${edgeStyle} ${targetId}`);
238
+ }
239
+ // Add styles
240
+ lines.push("");
241
+ for (const node of graph.nodes) {
242
+ const safeId = node.id.replace(/[@./]/g, "_");
243
+ const style = riskStyles[node.riskLevel];
244
+ lines.push(` style ${safeId} ${style}`);
245
+ }
246
+ return lines.join("\n");
247
+ }
248
+ /**
249
+ * Render graph to D3.js compatible JSON
250
+ */
251
+ renderToD3(graph) {
252
+ const d3Data = {
253
+ nodes: graph.nodes.map((node) => ({
254
+ id: node.id,
255
+ name: node.name,
256
+ version: node.version,
257
+ group: node.type === "root" ? 1 : node.type === "direct" ? 2 : 3,
258
+ riskLevel: node.riskLevel,
259
+ vulnerabilities: node.vulnerabilities.length,
260
+ license: node.license,
261
+ })),
262
+ links: graph.edges.map((edge) => ({
263
+ source: edge.source,
264
+ target: edge.target,
265
+ type: edge.type,
266
+ })),
267
+ };
268
+ return JSON.stringify(d3Data, null, 2);
269
+ }
270
+ /**
271
+ * Render graph to HTML with embedded visualization
272
+ */
273
+ renderToHTML(graph, options = {}) {
274
+ const width = options.width || 1200;
275
+ const height = options.height || 800;
276
+ const d3Data = this.renderToD3(graph);
277
+ return `<!DOCTYPE html>
278
+ <html lang="en">
279
+ <head>
280
+ <meta charset="UTF-8">
281
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
282
+ <title>Dependency Graph - ${graph.metadata.projectName}</title>
283
+ <script src="https://d3js.org/d3.v7.min.js"></script>
284
+ <style>
285
+ body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; margin: 0; padding: 20px; background: #f5f5f5; }
286
+ .container { background: white; border-radius: 8px; padding: 20px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
287
+ h1 { margin: 0 0 10px 0; color: #333; }
288
+ .stats { display: flex; gap: 20px; margin-bottom: 20px; }
289
+ .stat { background: #f0f0f0; padding: 10px 15px; border-radius: 4px; }
290
+ .stat-label { font-size: 12px; color: #666; }
291
+ .stat-value { font-size: 24px; font-weight: bold; }
292
+ .critical { color: #ff0000; }
293
+ .high { color: #ff6b6b; }
294
+ .medium { color: #ffb347; }
295
+ .low { color: #ffd700; }
296
+ svg { display: block; margin: 0 auto; }
297
+ .node circle { stroke: #fff; stroke-width: 2px; }
298
+ .node text { font-size: 10px; pointer-events: none; }
299
+ .link { stroke: #999; stroke-opacity: 0.6; }
300
+ .tooltip { position: absolute; background: #333; color: white; padding: 8px 12px; border-radius: 4px; font-size: 12px; pointer-events: none; }
301
+ </style>
302
+ </head>
303
+ <body>
304
+ <div class="container">
305
+ <h1>Dependency Graph: ${graph.metadata.projectName}</h1>
306
+ <div class="stats">
307
+ <div class="stat">
308
+ <div class="stat-label">Total Packages</div>
309
+ <div class="stat-value">${graph.metadata.totalPackages}</div>
310
+ </div>
311
+ <div class="stat">
312
+ <div class="stat-label">Vulnerable</div>
313
+ <div class="stat-value critical">${graph.metadata.vulnerablePackages}</div>
314
+ </div>
315
+ <div class="stat">
316
+ <div class="stat-label">Critical</div>
317
+ <div class="stat-value critical">${graph.metadata.riskDistribution["critical"]}</div>
318
+ </div>
319
+ <div class="stat">
320
+ <div class="stat-label">High</div>
321
+ <div class="stat-value high">${graph.metadata.riskDistribution["high"]}</div>
322
+ </div>
323
+ </div>
324
+ <svg width="${width}" height="${height}"></svg>
325
+ </div>
326
+ <script>
327
+ const data = ${d3Data};
328
+ const width = ${width};
329
+ const height = ${height};
330
+
331
+ const color = d3.scaleOrdinal()
332
+ .domain(['none', 'low', 'medium', 'high', 'critical'])
333
+ .range(['#90EE90', '#FFFF99', '#FFB347', '#FF6B6B', '#FF0000']);
334
+
335
+ const simulation = d3.forceSimulation(data.nodes)
336
+ .force('link', d3.forceLink(data.links).id(d => d.id).distance(100))
337
+ .force('charge', d3.forceManyBody().strength(-200))
338
+ .force('center', d3.forceCenter(width / 2, height / 2));
339
+
340
+ const svg = d3.select('svg');
341
+
342
+ const link = svg.append('g')
343
+ .selectAll('line')
344
+ .data(data.links)
345
+ .join('line')
346
+ .attr('class', 'link');
347
+
348
+ const node = svg.append('g')
349
+ .selectAll('g')
350
+ .data(data.nodes)
351
+ .join('g')
352
+ .attr('class', 'node')
353
+ .call(d3.drag()
354
+ .on('start', dragstarted)
355
+ .on('drag', dragged)
356
+ .on('end', dragended));
357
+
358
+ node.append('circle')
359
+ .attr('r', d => d.group === 1 ? 20 : d.group === 2 ? 12 : 8)
360
+ .attr('fill', d => color(d.riskLevel));
361
+
362
+ node.append('text')
363
+ .attr('dx', 15)
364
+ .attr('dy', 4)
365
+ .text(d => d.name);
366
+
367
+ simulation.on('tick', () => {
368
+ link
369
+ .attr('x1', d => d.source.x)
370
+ .attr('y1', d => d.source.y)
371
+ .attr('x2', d => d.target.x)
372
+ .attr('y2', d => d.target.y);
373
+ node.attr('transform', d => \`translate(\${d.x},\${d.y})\`);
374
+ });
375
+
376
+ function dragstarted(event) {
377
+ if (!event.active) simulation.alphaTarget(0.3).restart();
378
+ event.subject.fx = event.subject.x;
379
+ event.subject.fy = event.subject.y;
380
+ }
381
+
382
+ function dragged(event) {
383
+ event.subject.fx = event.x;
384
+ event.subject.fy = event.y;
385
+ }
386
+
387
+ function dragended(event) {
388
+ if (!event.active) simulation.alphaTarget(0);
389
+ event.subject.fx = null;
390
+ event.subject.fy = null;
391
+ }
392
+ </script>
393
+ </body>
394
+ </html>`;
395
+ }
396
+ }
397
+ exports.DependencyGraphGenerator = DependencyGraphGenerator;
398
+ // Export singleton
399
+ exports.dependencyGraphGenerator = new DependencyGraphGenerator();
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Visualization Module
3
+ */
4
+ export * from './dependency-graph';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/visualization/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /**
3
+ * Visualization Module
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ __exportStar(require("./dependency-graph"), exports);
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "guardrail-core",
3
+ "version": "1.0.0",
4
+ "main": "./dist/index.js",
5
+ "files": ["dist/**/*", "src/**/*"],
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./rbac": {
13
+ "types": "./dist/rbac/index.d.ts",
14
+ "default": "./dist/rbac/index.js"
15
+ }
16
+ },
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "dev": "tsc --watch",
20
+ "clean": "node -e \"require('fs').rmSync('dist', {recursive: true, force: true})\""
21
+ },
22
+ "dependencies": {
23
+ "zod": "^3.22.4"
24
+ },
25
+ "devDependencies": {
26
+ "typescript": "^5.3.3",
27
+ "@types/node": "^20.10.0"
28
+ }
29
+ }