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
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { load, FAILSAFE_SCHEMA } from 'js-yaml';
|
|
2
|
+
import { AllowedYamlPrimitive, YAMLParserConfig } from '../config';
|
|
3
|
+
import { YAMLParseError, YAMLSecurityError } from '../errors';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parser YAML seguro com FAILSAFE_SCHEMA e validações rigorosas
|
|
7
|
+
* Preloading de módulos críticos realizada no construtor
|
|
8
|
+
*/
|
|
9
|
+
export class SecureYamlParser {
|
|
10
|
+
private readonly config: YAMLParserConfig;
|
|
11
|
+
|
|
12
|
+
constructor(config: YAMLParserConfig = {}) {
|
|
13
|
+
this.config = this.validateAndMergeConfig(config);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Valida e merge configuração com padrões seguros
|
|
18
|
+
*/
|
|
19
|
+
private validateAndMergeConfig(userConfig: YAMLParserConfig): Required<YAMLParserConfig> {
|
|
20
|
+
const defaultConfig: Required<YAMLParserConfig> = {
|
|
21
|
+
schema: 'FAILSAFE_SCHEMA',
|
|
22
|
+
allowedTypes: ['null', 'boolean', 'integer', 'float', 'string'],
|
|
23
|
+
performanceTarget: 100,
|
|
24
|
+
maxDepth: 1000,
|
|
25
|
+
maxKeys: 10000,
|
|
26
|
+
maxStringLength: 1024 * 1024, // 1MB
|
|
27
|
+
maxValueSize: 10 * 1024 * 1024, // 10MB total
|
|
28
|
+
lazyLoading: true,
|
|
29
|
+
enableCaching: true,
|
|
30
|
+
validateUTF8: true,
|
|
31
|
+
strictMode: true,
|
|
32
|
+
filename: 'secure-parser'
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Merge com configurações do usuário, validando tipos
|
|
36
|
+
const merged = { ...defaultConfig, ...userConfig };
|
|
37
|
+
|
|
38
|
+
// Validar tipos permitidos contra FAILSAFE_SCHEMA
|
|
39
|
+
const invalidTypes = merged.allowedTypes.filter((type: AllowedYamlPrimitive) =>
|
|
40
|
+
!defaultConfig.allowedTypes.includes(type)
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
if (invalidTypes.length > 0) {
|
|
44
|
+
throw new YAMLSecurityError(
|
|
45
|
+
`Tipos não permitidos na FAILSAFE_SCHEMA: ${invalidTypes.join(', ')}`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return merged;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Parse YAML com segurança máxima usando FAILSAFE_SCHEMA
|
|
54
|
+
*/
|
|
55
|
+
parseSecure(yamlContent: string): any {
|
|
56
|
+
const startTime = performance.now();
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
// Validar entrada
|
|
60
|
+
this.validateInput(yamlContent);
|
|
61
|
+
|
|
62
|
+
// Configurar opções de segurança para FAILSAFE_SCHEMA
|
|
63
|
+
const parseOptions = this.buildSecureOptions();
|
|
64
|
+
|
|
65
|
+
// Fazer parsing com FAILSAFE_SCHEMA
|
|
66
|
+
const result = load(yamlContent, parseOptions);
|
|
67
|
+
|
|
68
|
+
// Validar resultado
|
|
69
|
+
this.validateResult(result);
|
|
70
|
+
|
|
71
|
+
const endTime = performance.now();
|
|
72
|
+
const parseTime = endTime - startTime;
|
|
73
|
+
|
|
74
|
+
// Log performance se exceder target
|
|
75
|
+
const target = this.config.performanceTarget || 100;
|
|
76
|
+
if (parseTime > target) {
|
|
77
|
+
console.warn(`[SecureYamlParser] Performance warning: ${parseTime}ms > ${target}ms target`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return result;
|
|
81
|
+
|
|
82
|
+
} catch (error) {
|
|
83
|
+
if (error instanceof Error && error.name === 'YAMLException') {
|
|
84
|
+
throw new YAMLParseError(`Erro ao fazer parse do YAML: ${error.message}`);
|
|
85
|
+
}
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Constrói opções de segurança para FAILSAFE_SCHEMA
|
|
92
|
+
*/
|
|
93
|
+
private buildSecureOptions(): any {
|
|
94
|
+
return {
|
|
95
|
+
schema: FAILSAFE_SCHEMA,
|
|
96
|
+
json: false, // Desabilitar JSON mode para maior segurança
|
|
97
|
+
onWarning: (warning: any) => {
|
|
98
|
+
console.warn(`[SecureYamlParser] WARN: ${warning}`);
|
|
99
|
+
},
|
|
100
|
+
maxDepth: this.config.maxDepth,
|
|
101
|
+
maxKeys: this.config.maxKeys,
|
|
102
|
+
strict: this.config.strictMode,
|
|
103
|
+
// Security hardening
|
|
104
|
+
filename: this.config.filename || 'secure-parser',
|
|
105
|
+
onError: (error: any) => {
|
|
106
|
+
throw new YAMLSecurityError(`Erro de segurança durante parsing: ${error.message}`);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Valida entrada antes do parsing
|
|
113
|
+
*/
|
|
114
|
+
private validateInput(input: string): void {
|
|
115
|
+
if (typeof input !== 'string') {
|
|
116
|
+
throw new YAMLParseError('Input deve ser uma string');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const maxStringLength = this.config.maxStringLength || 1048576; // Default 1MB
|
|
120
|
+
if (input.length > maxStringLength) {
|
|
121
|
+
throw new YAMLSecurityError(
|
|
122
|
+
`Tamanho do input (${input.length}) excede limite máximo (${maxStringLength})`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (input.trim().length === 0) {
|
|
127
|
+
throw new YAMLParseError('Input vazio não é permitido');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Validações UTF-8 básicas
|
|
131
|
+
if ((this.config.validateUTF8 ?? true) && !this.isValidUTF8(input)) {
|
|
132
|
+
throw new YAMLSecurityError('Input contém caracteres UTF-8 inválidos');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Valida resultado após parsing
|
|
138
|
+
*/
|
|
139
|
+
private validateResult(result: any): void {
|
|
140
|
+
// Validar profundidade máxima antes de serialização
|
|
141
|
+
const depth = this.getObjectDepth(result);
|
|
142
|
+
const maxDepth = this.config.maxDepth || 1000;
|
|
143
|
+
if (depth > maxDepth) {
|
|
144
|
+
throw new YAMLSecurityError(
|
|
145
|
+
`Profundidade do objeto (${depth}) excede limite máximo (${maxDepth})`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Validar tipos permitidos
|
|
150
|
+
if (!this.isAllowedType(result)) {
|
|
151
|
+
const allowedTypes = this.config.allowedTypes || ['null', 'boolean', 'integer', 'float', 'string'];
|
|
152
|
+
throw new YAMLSecurityError(
|
|
153
|
+
'O resultado contém tipos não permitidos. Tipos permitidos: ' +
|
|
154
|
+
allowedTypes.join(', ')
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Validar tamanho total aproximado
|
|
159
|
+
const size = this.estimateObjectSize(result);
|
|
160
|
+
const maxValueSize = this.config.maxValueSize || 10485760; // Default 10MB
|
|
161
|
+
if (size > maxValueSize) {
|
|
162
|
+
throw new YAMLSecurityError(
|
|
163
|
+
`Tamanho do objeto (${size} bytes) excede limite máximo (${maxValueSize} bytes)`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Verifica se é UTF-8 válido
|
|
170
|
+
*/
|
|
171
|
+
private isValidUTF8(str: string): boolean {
|
|
172
|
+
try {
|
|
173
|
+
encodeURIComponent(str);
|
|
174
|
+
return true;
|
|
175
|
+
} catch {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Calcula profundidade do objeto
|
|
182
|
+
*/
|
|
183
|
+
private getObjectDepth(obj: any, currentDepth = 0): number {
|
|
184
|
+
if (obj === null || typeof obj !== 'object') {
|
|
185
|
+
return currentDepth;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (Array.isArray(obj)) {
|
|
189
|
+
return obj.reduce((max, item) =>
|
|
190
|
+
Math.max(max as number, this.getObjectDepth(item, currentDepth + 1)), currentDepth + 1);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const values = Object.values(obj);
|
|
194
|
+
return values.reduce((max: number, value) =>
|
|
195
|
+
Math.max(max, this.getObjectDepth(value, currentDepth + 1)), currentDepth + 1);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Verifica se os tipos são permitidos
|
|
200
|
+
*/
|
|
201
|
+
private isAllowedType(obj: any): boolean {
|
|
202
|
+
const type = this.getType(obj);
|
|
203
|
+
|
|
204
|
+
// Verificar tipos básicos permitidos
|
|
205
|
+
const allowedTypes = this.config.allowedTypes || ['null', 'boolean', 'integer', 'float', 'string'];
|
|
206
|
+
if (!allowedTypes.includes(type as any)) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Recursivamente verificar objetos e arrays
|
|
211
|
+
if (typeof obj === 'object' && obj !== null) {
|
|
212
|
+
const values = Array.isArray(obj) ? obj : Object.values(obj);
|
|
213
|
+
return values.every(value => this.isAllowedType(value));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Estima tamanho do objeto em bytes
|
|
221
|
+
*/
|
|
222
|
+
private estimateObjectSize(obj: any): number {
|
|
223
|
+
return JSON.stringify(obj).length;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Obtém tipo completo do objeto
|
|
228
|
+
*/
|
|
229
|
+
private getType(obj: any): string {
|
|
230
|
+
if (obj === null) return 'null';
|
|
231
|
+
if (Array.isArray(obj)) return 'array';
|
|
232
|
+
if (typeof obj === 'object') return 'object';
|
|
233
|
+
if (typeof obj === 'number') {
|
|
234
|
+
return Number.isInteger(obj) ? 'integer' : 'float';
|
|
235
|
+
}
|
|
236
|
+
return typeof obj;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Parse assíncrono para lazy loading
|
|
241
|
+
*/
|
|
242
|
+
async parseSecureAsync(yamlContent: string): Promise<any> {
|
|
243
|
+
if (this.config.lazyLoading) {
|
|
244
|
+
// Lazy loading - criar Promise para carregar parser apenas quando necessário
|
|
245
|
+
return new Promise((resolve, reject) => {
|
|
246
|
+
setTimeout(() => {
|
|
247
|
+
try {
|
|
248
|
+
resolve(this.parseSecure(yamlContent));
|
|
249
|
+
} catch (error) {
|
|
250
|
+
reject(error);
|
|
251
|
+
}
|
|
252
|
+
}, 0);
|
|
253
|
+
});
|
|
254
|
+
} else {
|
|
255
|
+
return this.parseSecure(yamlContent);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Factory function para criar parser com configuração padrão segura
|
|
262
|
+
*/
|
|
263
|
+
export function createSecureYamlParser(config?: Partial<YAMLParserConfig>): SecureYamlParser {
|
|
264
|
+
return new SecureYamlParser(config);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Função utilitária para parse rápido com configuração padrão
|
|
269
|
+
*/
|
|
270
|
+
export function parseSecureYaml(yamlContent: string, config?: Partial<YAMLParserConfig>): any {
|
|
271
|
+
const parser = createSecureYamlParser(config);
|
|
272
|
+
return parser.parseSecure(yamlContent);
|
|
273
|
+
}
|