anon-identity
Version:
Decentralized identity framework with DIDs, Verifiable Credentials, and privacy-preserving selective disclosure
192 lines • 4.3 kB
TypeScript
/**
* Result Validator for MCP Functions
*
* Validates and sanitizes function execution results
*/
/**
* Validation rule types
*/
export type ValidationRuleType = 'type' | 'format' | 'length' | 'range' | 'pattern' | 'whitelist' | 'blacklist' | 'custom';
/**
* Validation rule
*/
export interface ValidationRule {
type: ValidationRuleType;
constraint: any;
message?: string;
severity: 'error' | 'warning' | 'info';
}
/**
* Validation schema
*/
export interface ValidationSchema {
type: 'string' | 'number' | 'boolean' | 'array' | 'object' | 'null' | 'any';
rules: ValidationRule[];
properties?: Record<string, ValidationSchema>;
items?: ValidationSchema;
required?: string[];
optional?: string[];
additionalProperties?: boolean;
}
/**
* Validation result
*/
export interface ValidationResult {
valid: boolean;
errors: ValidationError[];
warnings: ValidationWarning[];
sanitizedValue?: any;
metadata: {
validatedAt: Date;
validationTime: number;
rulesApplied: number;
transformationsApplied: string[];
};
}
/**
* Validation error
*/
export interface ValidationError {
path: string;
rule: ValidationRuleType;
message: string;
actualValue: any;
expectedConstraint: any;
}
/**
* Validation warning
*/
export interface ValidationWarning {
path: string;
rule: ValidationRuleType;
message: string;
suggestion?: string;
}
/**
* Sanitization options
*/
export interface SanitizationOptions {
removeUnknownProperties: boolean;
truncateStrings: boolean;
maxStringLength: number;
maxArrayLength: number;
maxObjectDepth: number;
convertTypes: boolean;
removeNullValues: boolean;
escapeSqlInjection: boolean;
escapeXssVectors: boolean;
removeScriptTags: boolean;
}
/**
* Built-in validation patterns
*/
export declare const VALIDATION_PATTERNS: {
EMAIL: RegExp;
URL: RegExp;
UUID: RegExp;
PHONE: RegExp;
IP_ADDRESS: RegExp;
DATE_ISO: RegExp;
ALPHANUMERIC: RegExp;
NO_SQL_INJECTION: RegExp;
NO_XSS: RegExp;
};
/**
* Result Validator
*/
export declare class ResultValidator {
private defaultSanitizationOptions;
private schemas;
private customRules;
constructor(defaultSanitizationOptions?: SanitizationOptions);
/**
* Register validation schema for a function
*/
registerSchema(functionName: string, schema: ValidationSchema): void;
/**
* Register custom validation rule
*/
registerCustomRule(ruleName: string, validator: (value: any) => boolean): void;
/**
* Validate function result
*/
validateResult(functionName: string, result: any, options?: Partial<SanitizationOptions>): Promise<ValidationResult>;
/**
* Validate value against schema
*/
private validateValue;
/**
* Validate type
*/
private validateType;
/**
* Attempt type conversion
*/
private attemptTypeConversion;
/**
* Apply validation rule
*/
private applyValidationRule;
/**
* Apply length rule
*/
private applyLengthRule;
/**
* Apply range rule
*/
private applyRangeRule;
/**
* Apply pattern rule
*/
private applyPatternRule;
/**
* Apply whitelist rule
*/
private applyWhitelistRule;
/**
* Apply blacklist rule
*/
private applyBlacklistRule;
/**
* Apply format rule
*/
private applyFormatRule;
/**
* Apply custom rule
*/
private applyCustomRule;
/**
* Validate string
*/
private validateString;
/**
* Validate array
*/
private validateArray;
/**
* Validate object
*/
private validateObject;
/**
* Basic validation for functions without schemas
*/
private basicValidation;
/**
* Count rules in schema
*/
private countRules;
/**
* Initialize built-in schemas
*/
private initializeBuiltinSchemas;
/**
* Get registered schemas
*/
getRegisteredSchemas(): string[];
/**
* Remove schema
*/
removeSchema(functionName: string): boolean;
}
export default ResultValidator;
//# sourceMappingURL=result-validator.d.ts.map