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.
- package/README.md +297 -0
- package/dist/agents/agentRegistry.d.ts +68 -0
- package/dist/agents/agentRegistry.d.ts.map +1 -0
- package/dist/agents/agentRegistry.js +222 -0
- package/dist/agents/agentRegistry.js.map +1 -0
- package/dist/agents/formatter-agent.d.ts +10 -0
- package/dist/agents/formatter-agent.d.ts.map +1 -0
- package/dist/agents/formatter-agent.js +49 -0
- package/dist/agents/formatter-agent.js.map +1 -0
- package/dist/agents/genkit-agent.d.ts +12 -0
- package/dist/agents/genkit-agent.d.ts.map +1 -0
- package/dist/agents/genkit-agent.js +119 -0
- package/dist/agents/genkit-agent.js.map +1 -0
- package/dist/agents/i18n-messages.d.ts +17 -0
- package/dist/agents/i18n-messages.d.ts.map +1 -0
- package/dist/agents/i18n-messages.js +92 -0
- package/dist/agents/i18n-messages.js.map +1 -0
- package/dist/agents/index.d.ts +10 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +26 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/pipeline.d.ts +15 -0
- package/dist/agents/pipeline.d.ts.map +1 -0
- package/dist/agents/pipeline.js +45 -0
- package/dist/agents/pipeline.js.map +1 -0
- package/dist/agents/schema-factory.d.ts +40 -0
- package/dist/agents/schema-factory.d.ts.map +1 -0
- package/dist/agents/schema-factory.js +121 -0
- package/dist/agents/schema-factory.js.map +1 -0
- package/dist/agents/translation-validators.d.ts +26 -0
- package/dist/agents/translation-validators.d.ts.map +1 -0
- package/dist/agents/translation-validators.js +77 -0
- package/dist/agents/translation-validators.js.map +1 -0
- package/dist/agents/translator-agents.d.ts +184 -0
- package/dist/agents/translator-agents.d.ts.map +1 -0
- package/dist/agents/translator-agents.js +613 -0
- package/dist/agents/translator-agents.js.map +1 -0
- package/dist/agents/types/translation.types.d.ts +100 -0
- package/dist/agents/types/translation.types.d.ts.map +1 -0
- package/dist/agents/types/translation.types.js +3 -0
- package/dist/agents/types/translation.types.js.map +1 -0
- package/dist/agents/validator-agent.d.ts +42 -0
- package/dist/agents/validator-agent.d.ts.map +1 -0
- package/dist/agents/validator-agent.js +122 -0
- package/dist/agents/validator-agent.js.map +1 -0
- package/dist/audit/auditTrail.d.ts +55 -0
- package/dist/audit/auditTrail.d.ts.map +1 -0
- package/dist/audit/auditTrail.js +93 -0
- package/dist/audit/auditTrail.js.map +1 -0
- package/dist/compliance/gdprEngine.d.ts +44 -0
- package/dist/compliance/gdprEngine.d.ts.map +1 -0
- package/dist/compliance/gdprEngine.js +178 -0
- package/dist/compliance/gdprEngine.js.map +1 -0
- package/dist/compliance/lgpdEngine.d.ts +51 -0
- package/dist/compliance/lgpdEngine.d.ts.map +1 -0
- package/dist/compliance/lgpdEngine.js +221 -0
- package/dist/compliance/lgpdEngine.js.map +1 -0
- package/dist/config.d.ts +78 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +77 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +17 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +40 -0
- package/dist/errors.js.map +1 -0
- package/dist/firebase/tenantManager.d.ts +84 -0
- package/dist/firebase/tenantManager.d.ts.map +1 -0
- package/dist/firebase/tenantManager.js +378 -0
- package/dist/firebase/tenantManager.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +118 -0
- package/dist/index.js.map +1 -0
- package/dist/integration/secure-yaml-runtime.d.ts +68 -0
- package/dist/integration/secure-yaml-runtime.d.ts.map +1 -0
- package/dist/integration/secure-yaml-runtime.js +245 -0
- package/dist/integration/secure-yaml-runtime.js.map +1 -0
- package/dist/parser/secure-yaml-parser.d.ts +62 -0
- package/dist/parser/secure-yaml-parser.d.ts.map +1 -0
- package/dist/parser/secure-yaml-parser.js +234 -0
- package/dist/parser/secure-yaml-parser.js.map +1 -0
- package/dist/performance/autoscaling.d.ts +100 -0
- package/dist/performance/autoscaling.d.ts.map +1 -0
- package/dist/performance/autoscaling.js +339 -0
- package/dist/performance/autoscaling.js.map +1 -0
- package/dist/performance/benchmark.d.ts +104 -0
- package/dist/performance/benchmark.d.ts.map +1 -0
- package/dist/performance/benchmark.js +514 -0
- package/dist/performance/benchmark.js.map +1 -0
- package/dist/performance/index.d.ts +14 -0
- package/dist/performance/index.d.ts.map +1 -0
- package/dist/performance/index.js +35 -0
- package/dist/performance/index.js.map +1 -0
- package/dist/performance/monitor.d.ts +126 -0
- package/dist/performance/monitor.d.ts.map +1 -0
- package/dist/performance/monitor.js +324 -0
- package/dist/performance/monitor.js.map +1 -0
- package/dist/performance/streaming.d.ts +82 -0
- package/dist/performance/streaming.d.ts.map +1 -0
- package/dist/performance/streaming.js +287 -0
- package/dist/performance/streaming.js.map +1 -0
- package/dist/runtime/audit.d.ts +240 -0
- package/dist/runtime/audit.d.ts.map +1 -0
- package/dist/runtime/audit.js +641 -0
- package/dist/runtime/audit.js.map +1 -0
- package/dist/runtime/declarativeAgentRuntime.d.ts +123 -0
- package/dist/runtime/declarativeAgentRuntime.d.ts.map +1 -0
- package/dist/runtime/declarativeAgentRuntime.js +576 -0
- package/dist/runtime/declarativeAgentRuntime.js.map +1 -0
- package/dist/runtime/isolatedRuntime.d.ts +119 -0
- package/dist/runtime/isolatedRuntime.d.ts.map +1 -0
- package/dist/runtime/isolatedRuntime.js +425 -0
- package/dist/runtime/isolatedRuntime.js.map +1 -0
- package/dist/runtime/schemaCompiler.d.ts +35 -0
- package/dist/runtime/schemaCompiler.d.ts.map +1 -0
- package/dist/runtime/schemaCompiler.js +151 -0
- package/dist/runtime/schemaCompiler.js.map +1 -0
- package/dist/runtime/simpleRuntime.d.ts +57 -0
- package/dist/runtime/simpleRuntime.d.ts.map +1 -0
- package/dist/runtime/simpleRuntime.js +187 -0
- package/dist/runtime/simpleRuntime.js.map +1 -0
- package/dist/security/dashboard.d.ts +89 -0
- package/dist/security/dashboard.d.ts.map +1 -0
- package/dist/security/dashboard.js +300 -0
- package/dist/security/dashboard.js.map +1 -0
- package/dist/security/hardening.d.ts +130 -0
- package/dist/security/hardening.d.ts.map +1 -0
- package/dist/security/hardening.js +414 -0
- package/dist/security/hardening.js.map +1 -0
- package/dist/security/index.d.ts +128 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +353 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/monitor.d.ts +88 -0
- package/dist/security/monitor.d.ts.map +1 -0
- package/dist/security/monitor.js +356 -0
- package/dist/security/monitor.js.map +1 -0
- package/dist/security/scanner.d.ts +104 -0
- package/dist/security/scanner.d.ts.map +1 -0
- package/dist/security/scanner.js +298 -0
- package/dist/security/scanner.js.map +1 -0
- package/dist/security/score.d.ts +150 -0
- package/dist/security/score.d.ts.map +1 -0
- package/dist/security/score.js +983 -0
- package/dist/security/score.js.map +1 -0
- package/dist/security/test-security.d.ts +22 -0
- package/dist/security/test-security.d.ts.map +1 -0
- package/dist/security/test-security.js +154 -0
- package/dist/security/test-security.js.map +1 -0
- package/dist/security/threatDetector.d.ts +39 -0
- package/dist/security/threatDetector.d.ts.map +1 -0
- package/dist/security/threatDetector.js +354 -0
- package/dist/security/threatDetector.js.map +1 -0
- package/dist/security/validation.d.ts +69 -0
- package/dist/security/validation.d.ts.map +1 -0
- package/dist/security/validation.js +286 -0
- package/dist/security/validation.js.map +1 -0
- package/dist/server/api/clientsRoute.d.ts +9 -0
- package/dist/server/api/clientsRoute.d.ts.map +1 -0
- package/dist/server/api/clientsRoute.js +71 -0
- package/dist/server/api/clientsRoute.js.map +1 -0
- package/dist/server/api/endpointsRoute.d.ts +8 -0
- package/dist/server/api/endpointsRoute.d.ts.map +1 -0
- package/dist/server/api/endpointsRoute.js +76 -0
- package/dist/server/api/endpointsRoute.js.map +1 -0
- package/dist/server/api/graphql.d.ts +9 -0
- package/dist/server/api/graphql.d.ts.map +1 -0
- package/dist/server/api/graphql.js +180 -0
- package/dist/server/api/graphql.js.map +1 -0
- package/dist/server/errors.d.ts +19 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/errors.js +42 -0
- package/dist/server/errors.js.map +1 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +24 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/kvStore.d.ts +27 -0
- package/dist/server/kvStore.d.ts.map +1 -0
- package/dist/server/kvStore.js +128 -0
- package/dist/server/kvStore.js.map +1 -0
- package/dist/server/runtimeSecurity.d.ts +28 -0
- package/dist/server/runtimeSecurity.d.ts.map +1 -0
- package/dist/server/runtimeSecurity.js +85 -0
- package/dist/server/runtimeSecurity.js.map +1 -0
- package/dist/server/types.d.ts +53 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server/types.js +8 -0
- package/dist/server/types.js.map +1 -0
- package/dist/types/executionContext.d.ts +16 -0
- package/dist/types/executionContext.d.ts.map +1 -0
- package/dist/types/executionContext.js +3 -0
- package/dist/types/executionContext.js.map +1 -0
- package/package.json +77 -0
- package/src/agents/agentRegistry.ts +272 -0
- package/src/agents/image-agent.yaml +86 -0
- package/src/agents/joker-agent.yaml +47 -0
- package/src/agents/translator-agent.yaml +80 -0
- package/src/audit/auditTrail.ts +134 -0
- package/src/compliance/gdprEngine.ts +209 -0
- package/src/compliance/lgpdEngine.ts +268 -0
- package/src/config.ts +179 -0
- package/src/errors.ts +35 -0
- package/src/firebase/tenantManager.ts +443 -0
- package/src/index.ts +125 -0
- package/src/integration/secure-yaml-runtime.ts +341 -0
- package/src/parser/secure-yaml-parser.ts +273 -0
- package/src/performance/autoscaling.ts +495 -0
- package/src/performance/benchmark.ts +644 -0
- package/src/performance/index.ts +34 -0
- package/src/performance/monitor.ts +469 -0
- package/src/performance/streaming.ts +317 -0
- package/src/runtime/audit.ts +907 -0
- package/src/runtime/declarativeAgentRuntime.ts +836 -0
- package/src/runtime/isolatedRuntime.ts +572 -0
- package/src/runtime/schemaCompiler.ts +228 -0
- package/src/runtime/simpleRuntime.ts +201 -0
- package/src/security/dashboard.ts +462 -0
- package/src/security/hardening.ts +560 -0
- package/src/security/index.ts +439 -0
- package/src/security/monitor.ts +490 -0
- package/src/security/scanner.ts +368 -0
- package/src/security/score.ts +1138 -0
- package/src/security/threatDetector.ts +481 -0
- package/src/security/validation.ts +365 -0
- package/src/server/api/clientsRoute.ts +92 -0
- package/src/server/api/endpointsRoute.ts +97 -0
- package/src/server/api/graphql.ts +249 -0
- package/src/server/errors.ts +38 -0
- package/src/server/index.ts +6 -0
- package/src/server/kvStore.ts +152 -0
- package/src/server/runtimeSecurity.ts +102 -0
- package/src/server/types.ts +60 -0
- package/src/types/executionContext.ts +16 -0
- package/tools/seed.ts +365 -0
- 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;
|