guardrail-compliance 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 (149) hide show
  1. package/dist/audit/emitter.d.ts +97 -0
  2. package/dist/audit/emitter.d.ts.map +1 -0
  3. package/dist/audit/emitter.js +197 -0
  4. package/dist/audit/events.d.ts +304 -0
  5. package/dist/audit/events.d.ts.map +1 -0
  6. package/dist/audit/events.js +267 -0
  7. package/dist/audit/index.d.ts +11 -0
  8. package/dist/audit/index.d.ts.map +1 -0
  9. package/dist/audit/index.js +51 -0
  10. package/dist/audit/storage.d.ts +93 -0
  11. package/dist/audit/storage.d.ts.map +1 -0
  12. package/dist/audit/storage.js +337 -0
  13. package/dist/automation/__tests__/compliance-scheduler.test.d.ts +2 -0
  14. package/dist/automation/__tests__/compliance-scheduler.test.d.ts.map +1 -0
  15. package/dist/automation/__tests__/compliance-scheduler.test.js +140 -0
  16. package/dist/automation/audit-logger.d.ts +129 -0
  17. package/dist/automation/audit-logger.d.ts.map +1 -0
  18. package/dist/automation/audit-logger.js +473 -0
  19. package/dist/automation/compliance-scheduler-fixed.d.ts +1 -0
  20. package/dist/automation/compliance-scheduler-fixed.d.ts.map +1 -0
  21. package/dist/automation/compliance-scheduler-fixed.js +1 -0
  22. package/dist/automation/compliance-scheduler.d.ts +83 -0
  23. package/dist/automation/compliance-scheduler.d.ts.map +1 -0
  24. package/dist/automation/compliance-scheduler.js +414 -0
  25. package/dist/automation/dashboard.d.ts +194 -0
  26. package/dist/automation/dashboard.d.ts.map +1 -0
  27. package/dist/automation/dashboard.js +768 -0
  28. package/dist/automation/email-service.d.ts +69 -0
  29. package/dist/automation/email-service.d.ts.map +1 -0
  30. package/dist/automation/email-service.js +218 -0
  31. package/dist/automation/evidence-collector.d.ts +140 -0
  32. package/dist/automation/evidence-collector.d.ts.map +1 -0
  33. package/dist/automation/evidence-collector.js +682 -0
  34. package/dist/automation/index.d.ts +8 -0
  35. package/dist/automation/index.d.ts.map +1 -0
  36. package/dist/automation/index.js +24 -0
  37. package/dist/automation/pdf-exporter.d.ts +90 -0
  38. package/dist/automation/pdf-exporter.d.ts.map +1 -0
  39. package/dist/automation/pdf-exporter.js +381 -0
  40. package/dist/automation/reporting-engine.d.ts +116 -0
  41. package/dist/automation/reporting-engine.d.ts.map +1 -0
  42. package/dist/automation/reporting-engine.js +329 -0
  43. package/dist/container/index.d.ts +4 -0
  44. package/dist/container/index.d.ts.map +1 -0
  45. package/dist/container/index.js +19 -0
  46. package/dist/container/kubernetes.d.ts +94 -0
  47. package/dist/container/kubernetes.d.ts.map +1 -0
  48. package/dist/container/kubernetes.js +268 -0
  49. package/dist/container/rules.d.ts +27 -0
  50. package/dist/container/rules.d.ts.map +1 -0
  51. package/dist/container/rules.js +216 -0
  52. package/dist/container/scanner.d.ts +50 -0
  53. package/dist/container/scanner.d.ts.map +1 -0
  54. package/dist/container/scanner.js +143 -0
  55. package/dist/frameworks/engine.d.ts +108 -0
  56. package/dist/frameworks/engine.d.ts.map +1 -0
  57. package/dist/frameworks/engine.js +206 -0
  58. package/dist/frameworks/gdpr.d.ts +6 -0
  59. package/dist/frameworks/gdpr.d.ts.map +1 -0
  60. package/dist/frameworks/gdpr.js +198 -0
  61. package/dist/frameworks/hipaa.d.ts +6 -0
  62. package/dist/frameworks/hipaa.d.ts.map +1 -0
  63. package/dist/frameworks/hipaa.js +183 -0
  64. package/dist/frameworks/index.d.ts +8 -0
  65. package/dist/frameworks/index.d.ts.map +1 -0
  66. package/dist/frameworks/index.js +30 -0
  67. package/dist/frameworks/iso27001.d.ts +63 -0
  68. package/dist/frameworks/iso27001.d.ts.map +1 -0
  69. package/dist/frameworks/iso27001.js +331 -0
  70. package/dist/frameworks/nist.d.ts +62 -0
  71. package/dist/frameworks/nist.d.ts.map +1 -0
  72. package/dist/frameworks/nist.js +424 -0
  73. package/dist/frameworks/pci.d.ts +6 -0
  74. package/dist/frameworks/pci.d.ts.map +1 -0
  75. package/dist/frameworks/pci.js +201 -0
  76. package/dist/frameworks/soc2.d.ts +7 -0
  77. package/dist/frameworks/soc2.d.ts.map +1 -0
  78. package/dist/frameworks/soc2.js +248 -0
  79. package/dist/iac/drift-detector.d.ts +64 -0
  80. package/dist/iac/drift-detector.d.ts.map +1 -0
  81. package/dist/iac/drift-detector.js +134 -0
  82. package/dist/iac/index.d.ts +4 -0
  83. package/dist/iac/index.d.ts.map +1 -0
  84. package/dist/iac/index.js +19 -0
  85. package/dist/iac/rules.d.ts +17 -0
  86. package/dist/iac/rules.d.ts.map +1 -0
  87. package/dist/iac/rules.js +385 -0
  88. package/dist/iac/scanner.d.ts +104 -0
  89. package/dist/iac/scanner.d.ts.map +1 -0
  90. package/dist/iac/scanner.js +343 -0
  91. package/dist/index.d.ts +7 -0
  92. package/dist/index.d.ts.map +1 -0
  93. package/dist/index.js +28 -0
  94. package/dist/pii/data-flow.d.ts +58 -0
  95. package/dist/pii/data-flow.d.ts.map +1 -0
  96. package/dist/pii/data-flow.js +154 -0
  97. package/dist/pii/detector.d.ts +60 -0
  98. package/dist/pii/detector.d.ts.map +1 -0
  99. package/dist/pii/detector.js +267 -0
  100. package/dist/pii/index.d.ts +4 -0
  101. package/dist/pii/index.d.ts.map +1 -0
  102. package/dist/pii/index.js +19 -0
  103. package/dist/pii/patterns.d.ts +36 -0
  104. package/dist/pii/patterns.d.ts.map +1 -0
  105. package/dist/pii/patterns.js +108 -0
  106. package/dist/policy/index.d.ts +5 -0
  107. package/dist/policy/index.d.ts.map +1 -0
  108. package/dist/policy/index.js +20 -0
  109. package/dist/policy/opa-engine.d.ts +121 -0
  110. package/dist/policy/opa-engine.d.ts.map +1 -0
  111. package/dist/policy/opa-engine.js +423 -0
  112. package/package.json +31 -0
  113. package/src/audit/emitter.ts +383 -0
  114. package/src/audit/events.ts +351 -0
  115. package/src/audit/index.ts +35 -0
  116. package/src/audit/storage.ts +394 -0
  117. package/src/automation/__tests__/compliance-scheduler.test.ts +183 -0
  118. package/src/automation/audit-logger.ts +629 -0
  119. package/src/automation/compliance-scheduler-fixed.ts +0 -0
  120. package/src/automation/compliance-scheduler.ts +516 -0
  121. package/src/automation/dashboard.ts +947 -0
  122. package/src/automation/email-service.ts +230 -0
  123. package/src/automation/evidence-collector.ts +866 -0
  124. package/src/automation/index.ts +8 -0
  125. package/src/automation/pdf-exporter.ts +434 -0
  126. package/src/automation/reporting-engine.ts +462 -0
  127. package/src/container/index.ts +3 -0
  128. package/src/container/kubernetes.ts +379 -0
  129. package/src/container/rules.ts +244 -0
  130. package/src/container/scanner.ts +202 -0
  131. package/src/frameworks/engine.ts +298 -0
  132. package/src/frameworks/gdpr.ts +204 -0
  133. package/src/frameworks/hipaa.ts +209 -0
  134. package/src/frameworks/index.ts +23 -0
  135. package/src/frameworks/iso27001.ts +398 -0
  136. package/src/frameworks/nist.ts +518 -0
  137. package/src/frameworks/pci.ts +226 -0
  138. package/src/frameworks/soc2.ts +281 -0
  139. package/src/iac/drift-detector.ts +197 -0
  140. package/src/iac/index.ts +3 -0
  141. package/src/iac/rules.ts +420 -0
  142. package/src/iac/scanner.ts +445 -0
  143. package/src/index.ts +17 -0
  144. package/src/pii/data-flow.ts +216 -0
  145. package/src/pii/detector.ts +327 -0
  146. package/src/pii/index.ts +3 -0
  147. package/src/pii/patterns.ts +128 -0
  148. package/src/policy/index.ts +5 -0
  149. package/src/policy/opa-engine.ts +504 -0
@@ -0,0 +1,230 @@
1
+ import * as nodemailer from "nodemailer";
2
+
3
+ export interface EmailConfig {
4
+ host: string;
5
+ port: number;
6
+ secure?: boolean;
7
+ auth: {
8
+ user: string;
9
+ pass: string;
10
+ };
11
+ from: string;
12
+ }
13
+
14
+ export interface EmailMessage {
15
+ to: string | string[];
16
+ subject: string;
17
+ text?: string;
18
+ html?: string;
19
+ }
20
+
21
+ export interface EmailResult {
22
+ success: boolean;
23
+ messageId?: string;
24
+ error?: string;
25
+ }
26
+
27
+ /**
28
+ * Email Service for Guardrail notifications
29
+ *
30
+ * Supports SMTP-based email delivery via nodemailer.
31
+ * Configure via environment variables:
32
+ * - EMAIL_FROM: sender email address
33
+ * - SMTP_HOST: SMTP server hostname
34
+ * - SMTP_PORT: SMTP server port (default: 587)
35
+ * - SMTP_USER: SMTP authentication username
36
+ * - SMTP_PASS: SMTP authentication password
37
+ * - SMTP_SECURE: Use TLS (default: false for port 587, true for port 465)
38
+ */
39
+ export class EmailService {
40
+ private transporter: nodemailer.Transporter | null = null;
41
+ private config: EmailConfig | null = null;
42
+
43
+ constructor() {
44
+ this.initializeFromEnv();
45
+ }
46
+
47
+ /**
48
+ * Initialize email configuration from environment variables
49
+ */
50
+ private initializeFromEnv(): void {
51
+ const host = process.env["SMTP_HOST"];
52
+ const port = parseInt(process.env["SMTP_PORT"] || "587", 10);
53
+ const user = process.env["SMTP_USER"];
54
+ const pass = process.env["SMTP_PASS"];
55
+ const from = process.env["EMAIL_FROM"];
56
+
57
+ if (host && user && pass && from) {
58
+ this.config = {
59
+ host,
60
+ port,
61
+ secure: process.env["SMTP_SECURE"] === "true" || port === 465,
62
+ auth: { user, pass },
63
+ from,
64
+ };
65
+ this.createTransporter();
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Create nodemailer transporter with current config
71
+ */
72
+ private createTransporter(): void {
73
+ if (!this.config) return;
74
+
75
+ this.transporter = nodemailer.createTransport({
76
+ host: this.config.host,
77
+ port: this.config.port,
78
+ secure: this.config.secure,
79
+ auth: this.config.auth,
80
+ });
81
+ }
82
+
83
+ /**
84
+ * Check if email service is configured and available
85
+ */
86
+ isConfigured(): boolean {
87
+ return this.transporter !== null && this.config !== null;
88
+ }
89
+
90
+ /**
91
+ * Verify SMTP connection
92
+ */
93
+ async verifyConnection(): Promise<boolean> {
94
+ if (!this.transporter) return false;
95
+
96
+ try {
97
+ await this.transporter.verify();
98
+ return true;
99
+ } catch (error) {
100
+ console.error("Email service verification failed:", error);
101
+ return false;
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Send an email
107
+ */
108
+ async send(message: EmailMessage): Promise<EmailResult> {
109
+ if (!this.transporter || !this.config) {
110
+ return {
111
+ success: false,
112
+ error: "Email service not configured. Set SMTP_HOST, SMTP_USER, SMTP_PASS, and EMAIL_FROM environment variables.",
113
+ };
114
+ }
115
+
116
+ try {
117
+ const recipients = Array.isArray(message.to)
118
+ ? message.to.join(", ")
119
+ : message.to;
120
+
121
+ const result = await this.transporter.sendMail({
122
+ from: this.config.from,
123
+ to: recipients,
124
+ subject: message.subject,
125
+ text: message.text,
126
+ html: message.html,
127
+ });
128
+
129
+ return {
130
+ success: true,
131
+ messageId: result.messageId,
132
+ };
133
+ } catch (error) {
134
+ const errorMessage = error instanceof Error ? error.message : String(error);
135
+ console.error("Failed to send email:", errorMessage);
136
+ return {
137
+ success: false,
138
+ error: errorMessage,
139
+ };
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Send compliance check notification email
145
+ */
146
+ async sendComplianceNotification(
147
+ recipients: string[],
148
+ projectId: string,
149
+ frameworkId: string,
150
+ result: {
151
+ status: "completed" | "failed";
152
+ score?: number;
153
+ summary?: string;
154
+ reportUrl?: string;
155
+ }
156
+ ): Promise<EmailResult> {
157
+ const statusEmoji = result.status === "completed" ? "✅" : "❌";
158
+ const statusText = result.status === "completed" ? "Completed" : "Failed";
159
+ const scoreText = result.score !== undefined ? `${result.score}%` : "N/A";
160
+
161
+ const subject = `[Guardrail] Compliance Check ${statusText}: ${frameworkId}`;
162
+
163
+ const html = `
164
+ <!DOCTYPE html>
165
+ <html>
166
+ <head>
167
+ <style>
168
+ body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; line-height: 1.6; color: #333; }
169
+ .container { max-width: 600px; margin: 0 auto; padding: 20px; }
170
+ .header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 20px; border-radius: 8px 8px 0 0; }
171
+ .content { background: #f9fafb; padding: 20px; border: 1px solid #e5e7eb; border-top: none; border-radius: 0 0 8px 8px; }
172
+ .status { font-size: 24px; margin-bottom: 10px; }
173
+ .metric { background: white; padding: 15px; border-radius: 8px; margin: 10px 0; border: 1px solid #e5e7eb; }
174
+ .metric-label { color: #6b7280; font-size: 12px; text-transform: uppercase; }
175
+ .metric-value { font-size: 20px; font-weight: 600; color: #111827; }
176
+ .button { display: inline-block; background: #667eea; color: white; padding: 12px 24px; border-radius: 6px; text-decoration: none; margin-top: 15px; }
177
+ .footer { text-align: center; color: #6b7280; font-size: 12px; margin-top: 20px; }
178
+ </style>
179
+ </head>
180
+ <body>
181
+ <div class="container">
182
+ <div class="header">
183
+ <div class="status">${statusEmoji} Compliance Check ${statusText}</div>
184
+ <div>Project: ${projectId}</div>
185
+ </div>
186
+ <div class="content">
187
+ <div class="metric">
188
+ <div class="metric-label">Framework</div>
189
+ <div class="metric-value">${frameworkId}</div>
190
+ </div>
191
+ <div class="metric">
192
+ <div class="metric-label">Compliance Score</div>
193
+ <div class="metric-value">${scoreText}</div>
194
+ </div>
195
+ ${result.summary ? `<p>${result.summary}</p>` : ""}
196
+ ${result.reportUrl ? `<a href="${result.reportUrl}" class="button">View Full Report</a>` : ""}
197
+ </div>
198
+ <div class="footer">
199
+ <p>Sent by Guardrail Compliance Automation</p>
200
+ <p>Context Enhanced by Guardrail AI</p>
201
+ </div>
202
+ </div>
203
+ </body>
204
+ </html>
205
+ `.trim();
206
+
207
+ const text = `
208
+ Compliance Check ${statusText}
209
+
210
+ Project: ${projectId}
211
+ Framework: ${frameworkId}
212
+ Score: ${scoreText}
213
+ ${result.summary ? `\nSummary: ${result.summary}` : ""}
214
+ ${result.reportUrl ? `\nView Report: ${result.reportUrl}` : ""}
215
+
216
+ --
217
+ Sent by Guardrail Compliance Automation
218
+ `.trim();
219
+
220
+ return this.send({
221
+ to: recipients,
222
+ subject,
223
+ text,
224
+ html,
225
+ });
226
+ }
227
+ }
228
+
229
+ // Singleton instance
230
+ export const emailService = new EmailService();