beddel 0.1.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 (236) hide show
  1. package/README.md +297 -0
  2. package/dist/agents/agentRegistry.d.ts +68 -0
  3. package/dist/agents/agentRegistry.d.ts.map +1 -0
  4. package/dist/agents/agentRegistry.js +222 -0
  5. package/dist/agents/agentRegistry.js.map +1 -0
  6. package/dist/agents/formatter-agent.d.ts +10 -0
  7. package/dist/agents/formatter-agent.d.ts.map +1 -0
  8. package/dist/agents/formatter-agent.js +49 -0
  9. package/dist/agents/formatter-agent.js.map +1 -0
  10. package/dist/agents/genkit-agent.d.ts +12 -0
  11. package/dist/agents/genkit-agent.d.ts.map +1 -0
  12. package/dist/agents/genkit-agent.js +119 -0
  13. package/dist/agents/genkit-agent.js.map +1 -0
  14. package/dist/agents/i18n-messages.d.ts +17 -0
  15. package/dist/agents/i18n-messages.d.ts.map +1 -0
  16. package/dist/agents/i18n-messages.js +92 -0
  17. package/dist/agents/i18n-messages.js.map +1 -0
  18. package/dist/agents/index.d.ts +10 -0
  19. package/dist/agents/index.d.ts.map +1 -0
  20. package/dist/agents/index.js +26 -0
  21. package/dist/agents/index.js.map +1 -0
  22. package/dist/agents/pipeline.d.ts +15 -0
  23. package/dist/agents/pipeline.d.ts.map +1 -0
  24. package/dist/agents/pipeline.js +45 -0
  25. package/dist/agents/pipeline.js.map +1 -0
  26. package/dist/agents/schema-factory.d.ts +40 -0
  27. package/dist/agents/schema-factory.d.ts.map +1 -0
  28. package/dist/agents/schema-factory.js +121 -0
  29. package/dist/agents/schema-factory.js.map +1 -0
  30. package/dist/agents/translation-validators.d.ts +26 -0
  31. package/dist/agents/translation-validators.d.ts.map +1 -0
  32. package/dist/agents/translation-validators.js +77 -0
  33. package/dist/agents/translation-validators.js.map +1 -0
  34. package/dist/agents/translator-agents.d.ts +184 -0
  35. package/dist/agents/translator-agents.d.ts.map +1 -0
  36. package/dist/agents/translator-agents.js +613 -0
  37. package/dist/agents/translator-agents.js.map +1 -0
  38. package/dist/agents/types/translation.types.d.ts +100 -0
  39. package/dist/agents/types/translation.types.d.ts.map +1 -0
  40. package/dist/agents/types/translation.types.js +3 -0
  41. package/dist/agents/types/translation.types.js.map +1 -0
  42. package/dist/agents/validator-agent.d.ts +42 -0
  43. package/dist/agents/validator-agent.d.ts.map +1 -0
  44. package/dist/agents/validator-agent.js +122 -0
  45. package/dist/agents/validator-agent.js.map +1 -0
  46. package/dist/audit/auditTrail.d.ts +55 -0
  47. package/dist/audit/auditTrail.d.ts.map +1 -0
  48. package/dist/audit/auditTrail.js +93 -0
  49. package/dist/audit/auditTrail.js.map +1 -0
  50. package/dist/compliance/gdprEngine.d.ts +44 -0
  51. package/dist/compliance/gdprEngine.d.ts.map +1 -0
  52. package/dist/compliance/gdprEngine.js +178 -0
  53. package/dist/compliance/gdprEngine.js.map +1 -0
  54. package/dist/compliance/lgpdEngine.d.ts +51 -0
  55. package/dist/compliance/lgpdEngine.d.ts.map +1 -0
  56. package/dist/compliance/lgpdEngine.js +221 -0
  57. package/dist/compliance/lgpdEngine.js.map +1 -0
  58. package/dist/config.d.ts +78 -0
  59. package/dist/config.d.ts.map +1 -0
  60. package/dist/config.js +77 -0
  61. package/dist/config.js.map +1 -0
  62. package/dist/errors.d.ts +17 -0
  63. package/dist/errors.d.ts.map +1 -0
  64. package/dist/errors.js +40 -0
  65. package/dist/errors.js.map +1 -0
  66. package/dist/firebase/tenantManager.d.ts +84 -0
  67. package/dist/firebase/tenantManager.d.ts.map +1 -0
  68. package/dist/firebase/tenantManager.js +378 -0
  69. package/dist/firebase/tenantManager.js.map +1 -0
  70. package/dist/index.d.ts +36 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +118 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/integration/secure-yaml-runtime.d.ts +68 -0
  75. package/dist/integration/secure-yaml-runtime.d.ts.map +1 -0
  76. package/dist/integration/secure-yaml-runtime.js +245 -0
  77. package/dist/integration/secure-yaml-runtime.js.map +1 -0
  78. package/dist/parser/secure-yaml-parser.d.ts +62 -0
  79. package/dist/parser/secure-yaml-parser.d.ts.map +1 -0
  80. package/dist/parser/secure-yaml-parser.js +234 -0
  81. package/dist/parser/secure-yaml-parser.js.map +1 -0
  82. package/dist/performance/autoscaling.d.ts +100 -0
  83. package/dist/performance/autoscaling.d.ts.map +1 -0
  84. package/dist/performance/autoscaling.js +339 -0
  85. package/dist/performance/autoscaling.js.map +1 -0
  86. package/dist/performance/benchmark.d.ts +104 -0
  87. package/dist/performance/benchmark.d.ts.map +1 -0
  88. package/dist/performance/benchmark.js +514 -0
  89. package/dist/performance/benchmark.js.map +1 -0
  90. package/dist/performance/index.d.ts +14 -0
  91. package/dist/performance/index.d.ts.map +1 -0
  92. package/dist/performance/index.js +35 -0
  93. package/dist/performance/index.js.map +1 -0
  94. package/dist/performance/monitor.d.ts +126 -0
  95. package/dist/performance/monitor.d.ts.map +1 -0
  96. package/dist/performance/monitor.js +324 -0
  97. package/dist/performance/monitor.js.map +1 -0
  98. package/dist/performance/streaming.d.ts +82 -0
  99. package/dist/performance/streaming.d.ts.map +1 -0
  100. package/dist/performance/streaming.js +287 -0
  101. package/dist/performance/streaming.js.map +1 -0
  102. package/dist/runtime/audit.d.ts +240 -0
  103. package/dist/runtime/audit.d.ts.map +1 -0
  104. package/dist/runtime/audit.js +641 -0
  105. package/dist/runtime/audit.js.map +1 -0
  106. package/dist/runtime/declarativeAgentRuntime.d.ts +123 -0
  107. package/dist/runtime/declarativeAgentRuntime.d.ts.map +1 -0
  108. package/dist/runtime/declarativeAgentRuntime.js +576 -0
  109. package/dist/runtime/declarativeAgentRuntime.js.map +1 -0
  110. package/dist/runtime/isolatedRuntime.d.ts +119 -0
  111. package/dist/runtime/isolatedRuntime.d.ts.map +1 -0
  112. package/dist/runtime/isolatedRuntime.js +425 -0
  113. package/dist/runtime/isolatedRuntime.js.map +1 -0
  114. package/dist/runtime/schemaCompiler.d.ts +35 -0
  115. package/dist/runtime/schemaCompiler.d.ts.map +1 -0
  116. package/dist/runtime/schemaCompiler.js +151 -0
  117. package/dist/runtime/schemaCompiler.js.map +1 -0
  118. package/dist/runtime/simpleRuntime.d.ts +57 -0
  119. package/dist/runtime/simpleRuntime.d.ts.map +1 -0
  120. package/dist/runtime/simpleRuntime.js +187 -0
  121. package/dist/runtime/simpleRuntime.js.map +1 -0
  122. package/dist/security/dashboard.d.ts +89 -0
  123. package/dist/security/dashboard.d.ts.map +1 -0
  124. package/dist/security/dashboard.js +300 -0
  125. package/dist/security/dashboard.js.map +1 -0
  126. package/dist/security/hardening.d.ts +130 -0
  127. package/dist/security/hardening.d.ts.map +1 -0
  128. package/dist/security/hardening.js +414 -0
  129. package/dist/security/hardening.js.map +1 -0
  130. package/dist/security/index.d.ts +128 -0
  131. package/dist/security/index.d.ts.map +1 -0
  132. package/dist/security/index.js +353 -0
  133. package/dist/security/index.js.map +1 -0
  134. package/dist/security/monitor.d.ts +88 -0
  135. package/dist/security/monitor.d.ts.map +1 -0
  136. package/dist/security/monitor.js +356 -0
  137. package/dist/security/monitor.js.map +1 -0
  138. package/dist/security/scanner.d.ts +104 -0
  139. package/dist/security/scanner.d.ts.map +1 -0
  140. package/dist/security/scanner.js +298 -0
  141. package/dist/security/scanner.js.map +1 -0
  142. package/dist/security/score.d.ts +150 -0
  143. package/dist/security/score.d.ts.map +1 -0
  144. package/dist/security/score.js +983 -0
  145. package/dist/security/score.js.map +1 -0
  146. package/dist/security/test-security.d.ts +22 -0
  147. package/dist/security/test-security.d.ts.map +1 -0
  148. package/dist/security/test-security.js +154 -0
  149. package/dist/security/test-security.js.map +1 -0
  150. package/dist/security/threatDetector.d.ts +39 -0
  151. package/dist/security/threatDetector.d.ts.map +1 -0
  152. package/dist/security/threatDetector.js +354 -0
  153. package/dist/security/threatDetector.js.map +1 -0
  154. package/dist/security/validation.d.ts +69 -0
  155. package/dist/security/validation.d.ts.map +1 -0
  156. package/dist/security/validation.js +286 -0
  157. package/dist/security/validation.js.map +1 -0
  158. package/dist/server/api/clientsRoute.d.ts +9 -0
  159. package/dist/server/api/clientsRoute.d.ts.map +1 -0
  160. package/dist/server/api/clientsRoute.js +71 -0
  161. package/dist/server/api/clientsRoute.js.map +1 -0
  162. package/dist/server/api/endpointsRoute.d.ts +8 -0
  163. package/dist/server/api/endpointsRoute.d.ts.map +1 -0
  164. package/dist/server/api/endpointsRoute.js +76 -0
  165. package/dist/server/api/endpointsRoute.js.map +1 -0
  166. package/dist/server/api/graphql.d.ts +9 -0
  167. package/dist/server/api/graphql.d.ts.map +1 -0
  168. package/dist/server/api/graphql.js +180 -0
  169. package/dist/server/api/graphql.js.map +1 -0
  170. package/dist/server/errors.d.ts +19 -0
  171. package/dist/server/errors.d.ts.map +1 -0
  172. package/dist/server/errors.js +42 -0
  173. package/dist/server/errors.js.map +1 -0
  174. package/dist/server/index.d.ts +7 -0
  175. package/dist/server/index.d.ts.map +1 -0
  176. package/dist/server/index.js +24 -0
  177. package/dist/server/index.js.map +1 -0
  178. package/dist/server/kvStore.d.ts +27 -0
  179. package/dist/server/kvStore.d.ts.map +1 -0
  180. package/dist/server/kvStore.js +128 -0
  181. package/dist/server/kvStore.js.map +1 -0
  182. package/dist/server/runtimeSecurity.d.ts +28 -0
  183. package/dist/server/runtimeSecurity.d.ts.map +1 -0
  184. package/dist/server/runtimeSecurity.js +85 -0
  185. package/dist/server/runtimeSecurity.js.map +1 -0
  186. package/dist/server/types.d.ts +53 -0
  187. package/dist/server/types.d.ts.map +1 -0
  188. package/dist/server/types.js +8 -0
  189. package/dist/server/types.js.map +1 -0
  190. package/dist/types/executionContext.d.ts +16 -0
  191. package/dist/types/executionContext.d.ts.map +1 -0
  192. package/dist/types/executionContext.js +3 -0
  193. package/dist/types/executionContext.js.map +1 -0
  194. package/package.json +77 -0
  195. package/src/agents/agentRegistry.ts +272 -0
  196. package/src/agents/image-agent.yaml +86 -0
  197. package/src/agents/joker-agent.yaml +47 -0
  198. package/src/agents/translator-agent.yaml +80 -0
  199. package/src/audit/auditTrail.ts +134 -0
  200. package/src/compliance/gdprEngine.ts +209 -0
  201. package/src/compliance/lgpdEngine.ts +268 -0
  202. package/src/config.ts +179 -0
  203. package/src/errors.ts +35 -0
  204. package/src/firebase/tenantManager.ts +443 -0
  205. package/src/index.ts +125 -0
  206. package/src/integration/secure-yaml-runtime.ts +341 -0
  207. package/src/parser/secure-yaml-parser.ts +273 -0
  208. package/src/performance/autoscaling.ts +495 -0
  209. package/src/performance/benchmark.ts +644 -0
  210. package/src/performance/index.ts +34 -0
  211. package/src/performance/monitor.ts +469 -0
  212. package/src/performance/streaming.ts +317 -0
  213. package/src/runtime/audit.ts +907 -0
  214. package/src/runtime/declarativeAgentRuntime.ts +836 -0
  215. package/src/runtime/isolatedRuntime.ts +572 -0
  216. package/src/runtime/schemaCompiler.ts +228 -0
  217. package/src/runtime/simpleRuntime.ts +201 -0
  218. package/src/security/dashboard.ts +462 -0
  219. package/src/security/hardening.ts +560 -0
  220. package/src/security/index.ts +439 -0
  221. package/src/security/monitor.ts +490 -0
  222. package/src/security/scanner.ts +368 -0
  223. package/src/security/score.ts +1138 -0
  224. package/src/security/threatDetector.ts +481 -0
  225. package/src/security/validation.ts +365 -0
  226. package/src/server/api/clientsRoute.ts +92 -0
  227. package/src/server/api/endpointsRoute.ts +97 -0
  228. package/src/server/api/graphql.ts +249 -0
  229. package/src/server/errors.ts +38 -0
  230. package/src/server/index.ts +6 -0
  231. package/src/server/kvStore.ts +152 -0
  232. package/src/server/runtimeSecurity.ts +102 -0
  233. package/src/server/types.ts +60 -0
  234. package/src/types/executionContext.ts +16 -0
  235. package/tools/seed.ts +365 -0
  236. package/tools/test-endpoints.ts +174 -0
package/src/index.ts ADDED
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Beddel - Parser YAML seguro com FAILSAFE_SCHEMA e Runtime Isolado
3
+ *
4
+ * Open source package para parsing YAML com foco máximo em segurança
5
+ * Implementa FAILSAFE_SCHEMA, validações rigorosas, runtime isolado e multi-tenant isolation
6
+ */
7
+
8
+ // YAML Parser exports
9
+ export {
10
+ SecureYamlParser,
11
+ createSecureYamlParser,
12
+ parseSecureYaml,
13
+ } from "./parser/secure-yaml-parser";
14
+
15
+ // Runtime Isolado exports
16
+ export {
17
+ IsolatedRuntimeManager,
18
+ runtimeManager,
19
+ } from "./runtime/isolatedRuntime";
20
+ export type {
21
+ ExecutionOptions,
22
+ ExecutionResult,
23
+ RuntimeContext,
24
+ } from "./runtime/isolatedRuntime";
25
+
26
+ // Simple Runtime exports
27
+ export {
28
+ SimpleIsolatedRuntimeManager,
29
+ runtimeManager as simpleRuntimeManager,
30
+ IsolatedRuntimeError as SimpleRuntimeError,
31
+ } from "./runtime/simpleRuntime";
32
+ export type {
33
+ ExecutionOptions as SimpleExecutionOptions,
34
+ ExecutionResult as SimpleExecutionResult,
35
+ } from "./runtime/simpleRuntime";
36
+
37
+ // Declarative runtime exports
38
+ export {
39
+ DeclarativeAgentInterpreter,
40
+ declarativeInterpreter,
41
+ } from "./runtime/declarativeAgentRuntime";
42
+ export type {
43
+ YamlAgentDefinition,
44
+ YamlAgentInterpreterOptions,
45
+ YamlExecutionResult,
46
+ } from "./runtime/declarativeAgentRuntime";
47
+ export {
48
+ DeclarativeSchemaCompiler,
49
+ DeclarativeSchemaValidationError,
50
+ SchemaCompilationError,
51
+ } from "./runtime/schemaCompiler";
52
+
53
+ // Agent registry exports
54
+ export { AgentRegistry, agentRegistry } from "./agents/agentRegistry";
55
+ export type { AgentRegistration } from "./agents/agentRegistry";
56
+
57
+ // Configuration exports
58
+ export {
59
+ runtimeConfig,
60
+ securityProfiles,
61
+ performanceTargets,
62
+ auditConfig,
63
+ } from "./config";
64
+ export type {
65
+ RuntimeConfig,
66
+ SecurityProfile,
67
+ PerformanceTarget,
68
+ AuditConfig,
69
+ } from "./config";
70
+
71
+ // Error exports
72
+ export {
73
+ YAMLBaseError,
74
+ YAMLParseError,
75
+ YAMLSecurityError,
76
+ YAMLPerformanceError,
77
+ } from "./errors";
78
+
79
+ // Security exports
80
+ export { SecurityScanner } from "./security/scanner";
81
+ export { SecurityScore } from "./security/score";
82
+ export {
83
+ SecurityManager,
84
+ SecurityMonitor,
85
+ securityMonitor,
86
+ SecurityDashboard,
87
+ securityDashboard,
88
+ ThreatDetectionEngine,
89
+ AnomalyDetector,
90
+ ThreatMLModel,
91
+ } from "./security";
92
+ export type {
93
+ AlertLevel,
94
+ SecurityEvent,
95
+ ThreatAnalysis,
96
+ DashboardConfig,
97
+ SecurityMetric,
98
+ } from "./security";
99
+ export { AuditService } from "./runtime/audit";
100
+
101
+ // Performance exports
102
+ export { PerformanceMonitor } from "./performance/monitor";
103
+ export { default as AutoScaler } from "./performance/autoscaling";
104
+
105
+ // Multi-Tenant Firebase exports
106
+ export { MultiTenantFirebaseManager } from "./firebase/tenantManager";
107
+ export type {
108
+ TenantConfig,
109
+ TenantIsolationResult,
110
+ } from "./firebase/tenantManager";
111
+
112
+ // Compliance exports
113
+ export { GDPRCompliance } from "./compliance/gdprEngine";
114
+ export { LGPDCompliance } from "./compliance/lgpdEngine";
115
+ export type { GDPRConfig, GDPRComplianceResult } from "./compliance/gdprEngine";
116
+ export type { LGPDConfig, LGPDComplianceResult } from "./compliance/lgpdEngine";
117
+
118
+ // Integration: Secure YAML Parser with Isolated Runtime
119
+ export { SecureYamlRuntime } from "./integration/secure-yaml-runtime";
120
+
121
+ // Shared types
122
+ export type { ExecutionContext } from "./types/executionContext";
123
+
124
+ // Server/runtime exports
125
+ export * as Server from "./server";
@@ -0,0 +1,341 @@
1
+ /**
2
+ * Secure YAML Runtime Integration
3
+ * Integrates SecureYamlParser with IsolatedRuntimeManager for ultra-secure YAML processing
4
+ */
5
+ import { SecureYamlParser } from "../parser/secure-yaml-parser";
6
+ import { IsolatedRuntimeManager } from "../runtime/isolatedRuntime";
7
+ import { SecurityScanner } from "../security/scanner";
8
+ import { performanceTargets, securityProfiles } from "../config";
9
+
10
+ export interface RuntimeYAMLConfig {
11
+ securityProfile?: string;
12
+ tenantId?: string;
13
+ timeout?: number;
14
+ memoryLimit?: number;
15
+ validateSecurity?: boolean;
16
+ auditEnabled?: boolean;
17
+ }
18
+
19
+ export interface RuntimeYAMLResult {
20
+ success: boolean;
21
+ result?: any;
22
+ error?: Error;
23
+ executionTime: number;
24
+ memoryUsed: number;
25
+ securityScore?: number;
26
+ auditHash?: string;
27
+ tenantId?: string;
28
+ }
29
+
30
+ export class SecureYamlRuntime {
31
+ private readonly runtimeManager: IsolatedRuntimeManager;
32
+ private readonly securityScanner: SecurityScanner;
33
+
34
+ constructor(private runtimeManagerInstance: IsolatedRuntimeManager) {
35
+ this.runtimeManager = runtimeManagerInstance;
36
+ this.securityScanner = new SecurityScanner();
37
+ }
38
+
39
+ /**
40
+ * Parse YAML in isolated runtime environment
41
+ */
42
+ public async parseYamlSecureRuntime(
43
+ yamlContent: string,
44
+ config: RuntimeYAMLConfig = {}
45
+ ): Promise<RuntimeYAMLResult> {
46
+ const startTime = performance.now();
47
+
48
+ try {
49
+ // Validate input
50
+ this.validateInput(yamlContent);
51
+
52
+ // Security scan if enabled
53
+ if (config.validateSecurity !== false) {
54
+ const scanResult = await this.securityScanner.scan({
55
+ code: yamlContent,
56
+ executionId: `yaml-parse-${Date.now()}`,
57
+ });
58
+
59
+ if (!scanResult.secure) {
60
+ throw new Error(
61
+ `Security scan failed: ${scanResult.warnings.join(", ")}`
62
+ );
63
+ }
64
+ }
65
+
66
+ // Prepare execution code
67
+ const executionCode = this.buildYamlExecutionCode(yamlContent);
68
+
69
+ // Execute in isolated runtime
70
+ const executionResult = await this.runtimeManager.execute({
71
+ code: executionCode,
72
+ securityProfile: config.securityProfile || "ultra-secure",
73
+ timeout: config.timeout || 5000,
74
+ memoryLimit: config.memoryLimit || 2,
75
+ tenantId: config.tenantId,
76
+ scanForSecurity: config.validateSecurity,
77
+ });
78
+
79
+ const endTime = performance.now();
80
+ const totalTime = endTime - startTime;
81
+
82
+ // Validate performance targets
83
+ this.validatePerformanceTargets(totalTime, executionResult.memoryUsed);
84
+
85
+ const auditHash = this.generateAuditHash(
86
+ yamlContent,
87
+ executionResult,
88
+ config
89
+ );
90
+
91
+ return {
92
+ success: executionResult.success,
93
+ result: executionResult.result,
94
+ error: executionResult.error,
95
+ executionTime: totalTime,
96
+ memoryUsed: executionResult.memoryUsed,
97
+ securityScore: this.calculateSecurityScore(executionResult, config),
98
+ auditHash,
99
+ tenantId: config.tenantId,
100
+ };
101
+ } catch (error) {
102
+ const endTime = performance.now();
103
+ const totalTime = endTime - startTime;
104
+
105
+ return {
106
+ success: false,
107
+ error: error instanceof Error ? error : new Error(String(error)),
108
+ executionTime: totalTime,
109
+ memoryUsed: 0,
110
+ tenantId: config.tenantId,
111
+ };
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Multi-tenant YAML processing with isolation
117
+ */
118
+ public async parseYamlMultiTenant(
119
+ yamlContent: string,
120
+ tenantId: string,
121
+ config: RuntimeYAMLConfig = {}
122
+ ): Promise<RuntimeYAMLResult> {
123
+ const tenantConfig = {
124
+ ...config,
125
+ tenantId,
126
+ securityProfile: config.securityProfile || "tenant-isolated",
127
+ validateSecurity: config.validateSecurity !== false,
128
+ auditEnabled: config.auditEnabled !== false,
129
+ };
130
+
131
+ return this.parseYamlSecureRuntime(yamlContent, tenantConfig);
132
+ }
133
+
134
+ /**
135
+ * Batch process YAML for multiple tenants
136
+ */
137
+ public async parseYamlBatch(
138
+ yamlContents: Array<{ content: string; tenantId: string }>,
139
+ config: RuntimeYAMLConfig = {}
140
+ ): Promise<Map<string, RuntimeYAMLResult>> {
141
+ const results = new Map<string, RuntimeYAMLResult>();
142
+
143
+ // Process each tenant's YAML in isolated runtime
144
+ for (const { content, tenantId } of yamlContents) {
145
+ const result = await this.parseYamlMultiTenant(content, tenantId, config);
146
+ results.set(tenantId, result);
147
+ }
148
+
149
+ return results;
150
+ }
151
+
152
+ /**
153
+ * Test multi-tenant isolation
154
+ */
155
+ public async testTenantIsolation(
156
+ tenantIds: string[]
157
+ ): Promise<{ [tenantId: string]: boolean }> {
158
+ const results: { [tenantId: string]: boolean } = {};
159
+
160
+ for (const tenantId of tenantIds) {
161
+ try {
162
+ // Execute code that should trigger isolation violations if not properly isolated
163
+ const testCode = `
164
+ const memoryLeak = [];
165
+ for (let i = 0; i < 1000; i++) {
166
+ memoryLeak.push(new Array(10000).fill('${tenantId}'));
167
+ }
168
+ global.tenantData = '${tenantId}';
169
+ return global.tenantData;
170
+ `;
171
+
172
+ const executionResult = await this.runtimeManager.execute({
173
+ code: testCode,
174
+ tenantId,
175
+ securityProfile: "tenant-isolated",
176
+ timeout: 2000,
177
+ memoryLimit: 1,
178
+ });
179
+
180
+ results[tenantId] =
181
+ executionResult.success && executionResult.result === tenantId;
182
+ } catch (error) {
183
+ results[tenantId] = false;
184
+ }
185
+ }
186
+
187
+ return results;
188
+ }
189
+
190
+ /**
191
+ * Validate performance targets
192
+ */
193
+ private validatePerformanceTargets(
194
+ executionTime: number,
195
+ memoryUsed: number
196
+ ): void {
197
+ const timeTarget = performanceTargets.find(
198
+ (t) => t.metric === "executionTime"
199
+ );
200
+ const memoryTarget = performanceTargets.find(
201
+ (t) => t.metric === "memoryUsage"
202
+ );
203
+
204
+ if (timeTarget && executionTime > timeTarget.target) {
205
+ console.warn(
206
+ `[SecureYamlRuntime] Performance warning: execution time ${executionTime}ms exceeds target ${timeTarget.target}ms`
207
+ );
208
+ }
209
+
210
+ if (memoryTarget && memoryUsed > memoryTarget.target) {
211
+ console.warn(
212
+ `[SecureYamlRuntime] Performance warning: memory usage ${memoryUsed}MB exceeds target ${memoryTarget.target}MB`
213
+ );
214
+ }
215
+ }
216
+
217
+ /**
218
+ * Calculate security score
219
+ */
220
+ private calculateSecurityScore(
221
+ executionResult: any,
222
+ config: RuntimeYAMLConfig
223
+ ): number {
224
+ const profile = securityProfiles[config.securityProfile || "ultra-secure"];
225
+
226
+ let score = 9.5; // Base score
227
+
228
+ if (!executionResult.success) {
229
+ score -= 1.0;
230
+ }
231
+
232
+ if (config.tenantId) {
233
+ score += 0.5;
234
+ }
235
+
236
+ if (config.validateSecurity === false) {
237
+ score -= 1.5;
238
+ }
239
+
240
+ return Math.max(0, Math.min(10, score));
241
+ }
242
+
243
+ /**
244
+ * Validate input
245
+ */
246
+ private validateInput(yamlContent: string): void {
247
+ if (typeof yamlContent !== "string") {
248
+ throw new Error("YAML content must be a string");
249
+ }
250
+
251
+ if (yamlContent.length === 0) {
252
+ throw new Error("YAML content cannot be empty");
253
+ }
254
+
255
+ if (yamlContent.length > 1024 * 1024) {
256
+ // 1MB max
257
+ throw new Error("YAML content exceeds maximum size limit (1MB)");
258
+ }
259
+ }
260
+
261
+ /**
262
+ * Build execution code for YAML parsing
263
+ */
264
+ private buildYamlExecutionCode(yamlContent: string): string {
265
+ // Escape the YAML content to avoid injection attacks
266
+ const escapedYaml = JSON.stringify(yamlContent);
267
+
268
+ return `
269
+ // Secure YAML Parser implementation
270
+ class SecureYamlRuntime {
271
+ constructor() {
272
+ this.schema = 'FAILSAFE_SCHEMA';
273
+ this.allowedTypes = ['null', 'boolean', 'integer', 'float', 'string'];
274
+ }
275
+
276
+ parseSecure(yamlContent) {
277
+ // Simulate basic YAML parsing logic
278
+ const lines = yamlContent.split('\\n');
279
+ const result = {};
280
+
281
+ for (const line of lines) {
282
+ const trimmedLine = line.trim();
283
+ if (trimmedLine && !trimmedLine.startsWith('#')) {
284
+ const colonIndex = trimmedLine.indexOf(':');
285
+ if (colonIndex !== -1) {
286
+ const key = trimmedLine.substring(0, colonIndex).trim();
287
+ const value = trimmedLine.substring(colonIndex + 1).trim();
288
+
289
+ // Basic type conversion
290
+ if (value === 'null') {
291
+ result[key] = null;
292
+ } else if (value === 'true') {
293
+ result[key] = true;
294
+ } else if (value === 'false') {
295
+ result[key] = false;
296
+ } else if (!isNaN(parseFloat(value))) {
297
+ result[key] = parseFloat(value);
298
+ } else {
299
+ result[key] = value;
300
+ }
301
+ }
302
+ }
303
+ }
304
+
305
+ return result;
306
+ }
307
+ }
308
+
309
+ const runtime = new SecureYamlRuntime();
310
+ const yamlContent = ${escapedYaml};
311
+ return runtime.parseSecure(yamlContent);
312
+ `;
313
+ }
314
+
315
+ /**
316
+ * Generate audit hash
317
+ */
318
+ private generateAuditHash(
319
+ yamlContent: string,
320
+ executionResult: any,
321
+ config: RuntimeYAMLConfig
322
+ ): string {
323
+ const crypto = require("node:crypto");
324
+ const auditData = {
325
+ yamlHash: crypto.createHash("sha256").update(yamlContent).digest("hex"),
326
+ executionResult: executionResult.success,
327
+ securityProfile: config.securityProfile || "ultra-secure",
328
+ tenantId: config.tenantId,
329
+ timestamp: Date.now(),
330
+ executionTime: executionResult.executionTime,
331
+ memoryUsed: executionResult.memoryUsed,
332
+ };
333
+
334
+ return crypto
335
+ .createHash("sha256")
336
+ .update(JSON.stringify(auditData))
337
+ .digest("hex");
338
+ }
339
+ }
340
+
341
+ export default SecureYamlRuntime;