locai 2.1.1 → 2.1.3

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 (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -897
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/commands/review.d.ts +109 -0
  5. package/dist/commands/translator.d.ts +23 -0
  6. package/dist/config/index.d.ts +145 -0
  7. package/dist/core/adapters/base-adapter.d.ts +20 -0
  8. package/dist/core/adapters/factory.d.ts +16 -0
  9. package/dist/core/adapters/json-adapter.d.ts +9 -0
  10. package/dist/core/adapters/po-adapter.d.ts +9 -0
  11. package/dist/core/adapters/properties-adapter.d.ts +9 -0
  12. package/dist/core/adapters/yaml-adapter.d.ts +9 -0
  13. package/dist/core/context-processor.d.ts +81 -0
  14. package/dist/core/detection/framework-detector.d.ts +9 -0
  15. package/dist/core/detection/structure-detector.d.ts +9 -0
  16. package/dist/core/fallback-provider.d.ts +54 -0
  17. package/dist/core/orchestrator.d.ts +101 -0
  18. package/dist/core/orchestrator.js +0 -1
  19. package/dist/core/pipeline/Pipeline.d.ts +23 -0
  20. package/dist/core/pipeline/PipelineStep.d.ts +18 -0
  21. package/dist/core/pipeline/context.d.ts +29 -0
  22. package/dist/core/pipeline/steps/CacheReadStep.d.ts +25 -0
  23. package/dist/core/pipeline/steps/CacheWriteStep.d.ts +11 -0
  24. package/dist/core/pipeline/steps/ConfidenceCheckStep.d.ts +10 -0
  25. package/dist/core/pipeline/steps/GlossaryPostStep.d.ts +9 -0
  26. package/dist/core/pipeline/steps/GlossaryPreStep.d.ts +9 -0
  27. package/dist/core/pipeline/steps/InputValidationStep.d.ts +8 -0
  28. package/dist/core/pipeline/steps/QualityCheckStep.d.ts +10 -0
  29. package/dist/core/pipeline/steps/ToneCheckStep.d.ts +13 -0
  30. package/dist/core/pipeline/steps/TranslationStep.d.ts +22 -0
  31. package/dist/core/pipeline/steps/VectorCacheReadStep.d.ts +17 -0
  32. package/dist/core/pipeline/steps/VectorCacheWriteStep.d.ts +11 -0
  33. package/dist/core/pipeline/steps/__tests__/ToneCheckStep.test.d.ts +1 -0
  34. package/dist/core/provider-factory.d.ts +41 -0
  35. package/dist/providers/base-provider.d.ts +66 -0
  36. package/dist/providers/dashscope.d.ts +24 -0
  37. package/dist/providers/deepseek.d.ts +22 -0
  38. package/dist/providers/gemini.d.ts +22 -0
  39. package/dist/providers/openai.d.ts +28 -0
  40. package/dist/providers/xai.d.ts +22 -0
  41. package/dist/services/embedding-provider.d.ts +26 -0
  42. package/dist/services/translation-service.d.ts +138 -0
  43. package/dist/services/translation-service.js +1 -1
  44. package/dist/services/vector-store.d.ts +26 -0
  45. package/dist/utils/ai-context-analyzer.d.ts +73 -0
  46. package/dist/utils/confidence-scorer.d.ts +77 -0
  47. package/dist/utils/error-helper.d.ts +87 -0
  48. package/dist/utils/file-manager.d.ts +129 -0
  49. package/dist/utils/glossary-manager.d.ts +69 -0
  50. package/dist/utils/graceful-shutdown.d.ts +22 -0
  51. package/dist/utils/input-validator.d.ts +227 -0
  52. package/dist/utils/logger.d.ts +134 -0
  53. package/dist/utils/object-transformer.d.ts +38 -0
  54. package/dist/utils/progress-tracker.d.ts +63 -0
  55. package/dist/utils/prompt-templates.d.ts +37 -0
  56. package/dist/utils/quality/__tests__/tone-verifier.test.d.ts +1 -0
  57. package/dist/utils/quality/base-checker.d.ts +79 -0
  58. package/dist/utils/quality/code-block-checker.d.ts +64 -0
  59. package/dist/utils/quality/html-tag-checker.d.ts +33 -0
  60. package/dist/utils/quality/index.d.ts +39 -0
  61. package/dist/utils/quality/length-checker.d.ts +70 -0
  62. package/dist/utils/quality/markdown-checker.d.ts +63 -0
  63. package/dist/utils/quality/placeholder-checker.d.ts +42 -0
  64. package/dist/utils/quality/punctuation-checker.d.ts +31 -0
  65. package/dist/utils/quality/quote-balance-checker.d.ts +37 -0
  66. package/dist/utils/quality/special-characters-checker.d.ts +66 -0
  67. package/dist/utils/quality/style-guide-checker.d.ts +71 -0
  68. package/dist/utils/quality/text-sanitizer.d.ts +51 -0
  69. package/dist/utils/quality/tone-verifier.d.ts +14 -0
  70. package/dist/utils/rate-limiter.d.ts +73 -0
  71. package/dist/utils/retry-helper.d.ts +49 -0
  72. package/dist/utils/state-manager.d.ts +62 -0
  73. package/dist/utils/statistics-manager.d.ts +47 -0
  74. package/dist/utils/ui-manager.d.ts +21 -0
  75. package/package.json +19 -4
@@ -0,0 +1,73 @@
1
+ export interface AnalysisResult {
2
+ category: string;
3
+ confidence: number;
4
+ keywords: string[];
5
+ explanation: string;
6
+ prompt: string;
7
+ method?: string;
8
+ }
9
+ export interface ContextConfig {
10
+ enabled?: boolean;
11
+ useAI?: boolean;
12
+ minTextLength?: number;
13
+ cacheSize?: number;
14
+ cacheTTL?: number;
15
+ categories?: Record<string, any>;
16
+ detection?: {
17
+ threshold?: number;
18
+ minConfidence?: number;
19
+ };
20
+ allowNewCategories?: boolean;
21
+ fallback?: {
22
+ category?: string;
23
+ prompt?: string;
24
+ };
25
+ analysisOptions?: {
26
+ maxTokens?: number;
27
+ timeout?: number;
28
+ retries?: number;
29
+ };
30
+ [key: string]: any;
31
+ }
32
+ export interface Stats {
33
+ totalAnalyzed: number;
34
+ aiCalls: number;
35
+ cacheHits: number;
36
+ keywordMatches: number;
37
+ newCategories: number;
38
+ errors: number;
39
+ }
40
+ declare class AIContextAnalyzer {
41
+ private config;
42
+ private cache;
43
+ private categoryKeywords;
44
+ private stats;
45
+ constructor(config: ContextConfig);
46
+ analyzeBatch(texts: (string | null)[], apiProvider?: string): Promise<(AnalysisResult | null)[]>;
47
+ analyzeContext(text: string, apiProvider?: string): Promise<AnalysisResult | null>;
48
+ _batchAIAnalysis(texts: string[], apiProvider: string): Promise<(AnalysisResult | null)[]>;
49
+ _createBatchAnalysisPrompt(texts: string[]): string;
50
+ _createAnalysisPrompt(text: string): string;
51
+ _createSimplifiedAnalysisPrompt(text: string): string;
52
+ _parseBatchAnalysisResult(result: string, expectedCount: number): (AnalysisResult | null)[];
53
+ _parseAnalysisResult(result: string): AnalysisResult | null;
54
+ _fastKeywordMatch(text: string): AnalysisResult | null;
55
+ _getDefaultContext(): AnalysisResult;
56
+ _findClosestCategory(suggestedCategory: string, keywords: string[]): string;
57
+ _saveNewCategory(category: string, keywords: string[]): void;
58
+ /**
59
+ * Generate a collision-resistant cache key for text
60
+ */
61
+ _getCacheKey(text: string): string;
62
+ getStats(): Stats & {
63
+ cacheSize: number;
64
+ cacheCapacity: number;
65
+ hitRate: number;
66
+ aiUsageRate: number;
67
+ keywordMatchRate: number;
68
+ errorRate: number;
69
+ };
70
+ resetStats(): void;
71
+ clearCache(): void;
72
+ }
73
+ export default AIContextAnalyzer;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Quality Confidence Scoring System
3
+ * Calculates confidence scores for translations based on AI response and quality checks
4
+ */
5
+ export interface ConfidenceIssue {
6
+ type: string;
7
+ severity: "critical" | "warning" | "error";
8
+ message: string;
9
+ }
10
+ export interface ConfidenceOptions {
11
+ aiConfidence?: number;
12
+ sourceText: string;
13
+ translation: string;
14
+ sourceLang: string;
15
+ targetLang: string;
16
+ provider: string;
17
+ category?: string;
18
+ }
19
+ export interface ConfidenceResult {
20
+ score: number;
21
+ level: "high" | "medium" | "low" | "very_low";
22
+ aiConfidence: number;
23
+ qualityScore: number;
24
+ details: {
25
+ categoryAdjustment: number;
26
+ languageFactor: number;
27
+ providerReliability: number;
28
+ };
29
+ issues: ConfidenceIssue[];
30
+ needsReview: boolean;
31
+ autoApprove: boolean;
32
+ }
33
+ declare class ConfidenceScorer {
34
+ /**
35
+ * Calculate final confidence score
36
+ * @param {ConfidenceOptions} options
37
+ * @returns {ConfidenceResult} { score, details, issues }
38
+ */
39
+ static calculateConfidence(options: ConfidenceOptions): ConfidenceResult;
40
+ /**
41
+ * Calculate quality score based on internal checks
42
+ */
43
+ private static _calculateQualityScore;
44
+ /**
45
+ * Get category-specific adjustment
46
+ */
47
+ private static _getCategoryAdjustment;
48
+ /**
49
+ * Get language pair complexity factor
50
+ */
51
+ private static _getLanguagePairFactor;
52
+ /**
53
+ * Get provider reliability for specific tasks
54
+ */
55
+ private static _getProviderReliability;
56
+ /**
57
+ * Determine confidence level from score
58
+ */
59
+ private static _getConfidenceLevel;
60
+ /**
61
+ * Detect specific issues with translation
62
+ */
63
+ private static _detectIssues;
64
+ /**
65
+ * Get confidence color for terminal display
66
+ */
67
+ static getConfidenceColor(score: number): string;
68
+ /**
69
+ * Format confidence for display
70
+ */
71
+ static formatConfidence(score: number): string;
72
+ /**
73
+ * Extract AI confidence from provider response
74
+ */
75
+ static extractAIConfidence(response: any, provider: string): number;
76
+ }
77
+ export default ConfidenceScorer;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Centralized Error Handling System
3
+ * Provides detailed, actionable error messages with context and solutions
4
+ */
5
+ export interface HelperError extends Error {
6
+ code?: string;
7
+ type?: string;
8
+ details?: Record<string, any>;
9
+ solutions?: string[];
10
+ context?: string[];
11
+ }
12
+ export interface ErrorDetails {
13
+ [key: string]: any;
14
+ }
15
+ declare class ErrorHelper {
16
+ static ErrorCodes: {
17
+ API_RATE_LIMIT: string;
18
+ API_AUTH_FAILED: string;
19
+ API_SERVER_ERROR: string;
20
+ API_NETWORK: string;
21
+ API_TIMEOUT: string;
22
+ API_INVALID_KEY: string;
23
+ API_QUOTA_EXCEEDED: string;
24
+ API_RESPONSE_ERROR: string;
25
+ CONFIG_NOT_FOUND: string;
26
+ CONFIG_INVALID: string;
27
+ CONFIG_VALIDATION: string;
28
+ CONFIG_MISSING_FIELD: string;
29
+ FILE_NOT_FOUND: string;
30
+ FILE_READ_ERROR: string;
31
+ FILE_WRITE_ERROR: string;
32
+ FILE_PERMISSION: string;
33
+ VALIDATION_LANGUAGE: string;
34
+ VALIDATION_TEXT: string;
35
+ VALIDATION_PROVIDER: string;
36
+ VALIDATION_CONCURRENCY: string;
37
+ TRANSLATION_FAILED: string;
38
+ TRANSLATION_QUALITY: string;
39
+ TRANSLATION_TIMEOUT: string;
40
+ };
41
+ /**
42
+ * Create a detailed error with context and solutions
43
+ */
44
+ static createError(type: string, details?: ErrorDetails): HelperError;
45
+ /**
46
+ * Format error for display
47
+ */
48
+ static formatError(error: HelperError, options?: {
49
+ showDebug?: boolean;
50
+ showSolutions?: boolean;
51
+ showContext?: boolean;
52
+ }): string;
53
+ /**
54
+ * Get error information based on type
55
+ */
56
+ private static _getErrorInfo;
57
+ /**
58
+ * Build rate limit message with details
59
+ */
60
+ private static _buildRateLimitMessage;
61
+ /**
62
+ * Get environment variable name for provider
63
+ */
64
+ private static _getEnvKeyName;
65
+ /**
66
+ * Get provider console URL
67
+ */
68
+ private static _getProviderConsoleUrl;
69
+ /**
70
+ * Suggest fallback provider
71
+ */
72
+ private static _suggestFallbackProvider;
73
+ /**
74
+ * Quick error creators for common cases
75
+ */
76
+ static rateLimitError(provider: string, details?: ErrorDetails): HelperError;
77
+ static authError(provider: string, statusCode?: number | string, apiMessage?: string): HelperError;
78
+ static serverError(provider: string, statusCode?: number | string, apiMessage?: string): HelperError;
79
+ static networkError(provider: string): HelperError;
80
+ static timeoutError(provider: string, timeout?: number): HelperError;
81
+ static configNotFoundError(): HelperError;
82
+ static configValidationError(validationErrors: string[]): HelperError;
83
+ static fileNotFoundError(filePath: string, expectedSource?: string): HelperError;
84
+ static translationError(key: string, language: string, reason?: string): HelperError;
85
+ static languageValidationError(langCode: string, field?: string): HelperError;
86
+ }
87
+ export default ErrorHelper;
@@ -0,0 +1,129 @@
1
+ export interface FileOptions {
2
+ atomic?: boolean;
3
+ createMissingDirs?: boolean;
4
+ backupFiles?: boolean;
5
+ backupDir?: string;
6
+ encoding?: BufferEncoding;
7
+ jsonIndent?: number;
8
+ compact?: boolean;
9
+ indent?: number;
10
+ format?: string;
11
+ }
12
+ export interface ValidationResult {
13
+ valid: boolean;
14
+ filePath?: string;
15
+ error?: string;
16
+ position?: {
17
+ position: number | null;
18
+ line: number | null;
19
+ } | null;
20
+ key?: string;
21
+ value?: any;
22
+ }
23
+ /**
24
+ * FileManager - Modern asynchronous file operations
25
+ * Handles multiple file formats via Adapter pattern.
26
+ */
27
+ declare class FileManager {
28
+ /**
29
+ * Default options for file operations
30
+ */
31
+ static defaultOptions: Required<Omit<FileOptions, "compact" | "indent" | "format">>;
32
+ private static options;
33
+ /**
34
+ * Configure global options for file operations
35
+ * @param options - File operation options
36
+ */
37
+ static configure(options: FileOptions): void;
38
+ /**
39
+ * Get current configuration
40
+ * @returns Current configuration
41
+ */
42
+ static getConfig(): FileOptions;
43
+ /**
44
+ * Find locale files in the specified directory
45
+ * @param localesDir - Directory containing locale files
46
+ * @param sourceLang - Source language code
47
+ * @returns Array of file paths
48
+ */
49
+ static findLocaleFiles(localesDir: string, sourceLang: string): Promise<string[]>;
50
+ /**
51
+ * Read structured data file asynchronously (JSON, YAML, etc.)
52
+ * @param filePath - Path to the file
53
+ * @param options - Options for reading
54
+ * @returns Parsed data
55
+ */
56
+ static readFile(filePath: string, options?: FileOptions): Promise<any>;
57
+ /**
58
+ * Write data to file asynchronously
59
+ * @param filePath - Path to write the file
60
+ * @param data - Data to write
61
+ * @param options - Options for writing
62
+ * @returns Success status
63
+ */
64
+ static writeFile(filePath: string, data: any, options?: FileOptions): Promise<boolean>;
65
+ static readJSON(filePath: string, options?: FileOptions): Promise<any>;
66
+ static writeJSON(filePath: string, data: any, options?: FileOptions): Promise<boolean>;
67
+ /**
68
+ * Generate a unique temporary file path
69
+ */
70
+ static _generateTempFilePath(filePath: string): string;
71
+ /**
72
+ * Ensure directory exists
73
+ */
74
+ static ensureDir(dir: string): Promise<void>;
75
+ /**
76
+ * Scan for locale files
77
+ */
78
+ static scanLocaleFiles(localesDir: string, pattern?: RegExp): Promise<string[]>;
79
+ /**
80
+ * Get file modification time
81
+ */
82
+ static getModifiedTime(filePath: string): Promise<Date>;
83
+ /**
84
+ * Check if file exists
85
+ */
86
+ static exists(filePath: string): Promise<boolean>;
87
+ /**
88
+ * Delete file
89
+ * @param filePath - Path to the file
90
+ * @param options - Options for deletion
91
+ * @returns Success status
92
+ */
93
+ static deleteFile(filePath: string, options?: FileOptions): Promise<boolean>;
94
+ /**
95
+ * Validate JSON file structure
96
+ * @param filePath - Path to the JSON file
97
+ * @returns Validation result
98
+ */
99
+ static validateJSONFile(filePath: string): Promise<ValidationResult>;
100
+ /**
101
+ * Extract error position from JSON parse error
102
+ * @param error - JSON parse error
103
+ * @returns Error position details
104
+ */
105
+ static _extractErrorPosition(error: any): {
106
+ position: number | null;
107
+ line: number | null;
108
+ } | null;
109
+ /**
110
+ * Validate translation value can be safely added to JSON
111
+ * @param key - Translation key
112
+ * @param value - Translation value
113
+ * @returns Validation result
114
+ */
115
+ static validateTranslationValue(key: string, value: any): ValidationResult;
116
+ /**
117
+ * List files in a directory
118
+ * @param dirPath - Directory path
119
+ * @returns Array of file paths
120
+ */
121
+ static listFiles(dirPath: string): Promise<string[]>;
122
+ /**
123
+ * Ensure directory exists, create if it doesn't
124
+ * @param dirPath - Directory path
125
+ * @returns True if directory exists or was created
126
+ */
127
+ static ensureDirectoryExists(dirPath: string): Promise<boolean>;
128
+ }
129
+ export { FileManager };
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Glossary Manager
3
+ * Manages brand terminology and ensures consistent translations
4
+ */
5
+ export interface GlossaryEntry {
6
+ term: string;
7
+ translation: string;
8
+ caseSensitive?: boolean;
9
+ languages?: string[];
10
+ }
11
+ export interface ProtectedTerm {
12
+ original: string;
13
+ translation: string;
14
+ term: string;
15
+ }
16
+ export interface GlossaryConfig {
17
+ glossary?: Record<string, string | Partial<GlossaryEntry> | Record<string, string>>;
18
+ enabled?: boolean;
19
+ caseSensitive?: boolean;
20
+ preserveFormatting?: boolean;
21
+ }
22
+ declare class GlossaryManager {
23
+ private glossary;
24
+ enabled: boolean;
25
+ private caseSensitive;
26
+ private preserveFormatting;
27
+ constructor(config?: GlossaryConfig);
28
+ /**
29
+ * Apply glossary terms to source text before translation
30
+ * Replaces terms with protected tokens to preserve them
31
+ */
32
+ protectTerms(text: string, sourceLang: string, targetLang: string): {
33
+ protectedText: string;
34
+ termMap: Map<string, ProtectedTerm>;
35
+ };
36
+ /**
37
+ * Restore protected terms in translated text
38
+ */
39
+ restoreTerms(translatedText: string, termMap: Map<string, ProtectedTerm>): string;
40
+ /**
41
+ * Get applicable glossary entries for language pair
42
+ */
43
+ getApplicableEntries(sourceLang: string, targetLang: string): GlossaryEntry[];
44
+ /**
45
+ * Match formatting (capitalization) from original to translation
46
+ */
47
+ matchFormatting(original: string, translation: string): string;
48
+ /**
49
+ * Escape special regex characters
50
+ */
51
+ escapeRegex(string: string): string;
52
+ /**
53
+ * Validate glossary configuration
54
+ */
55
+ validate(): {
56
+ valid: boolean;
57
+ errors: string[];
58
+ warnings: string[];
59
+ };
60
+ /**
61
+ * Get statistics about glossary
62
+ */
63
+ getStats(): any;
64
+ /**
65
+ * Load glossary from file
66
+ */
67
+ static loadFromFile(filePath: string): Promise<GlossaryManager>;
68
+ }
69
+ export default GlossaryManager;
@@ -0,0 +1,22 @@
1
+ export type ShutdownCallback = () => Promise<void> | void;
2
+ export interface ShutdownOptions {
3
+ shutdownTimeout?: number;
4
+ waitForPending?: boolean;
5
+ logger?: Console | any;
6
+ }
7
+ declare class GracefulShutdown {
8
+ private options;
9
+ private isShuttingDown;
10
+ private shutdownCallbacks;
11
+ private logger;
12
+ constructor(options?: ShutdownOptions);
13
+ registerCallback(callback: ShutdownCallback): void;
14
+ unregisterCallback(callback: ShutdownCallback): void;
15
+ init(): void;
16
+ handleSignal(signal: string): Promise<void>;
17
+ shutdown(exitCode?: number): Promise<void>;
18
+ performShutdown(): Promise<void>;
19
+ waitForPendingOperations(): Promise<void>;
20
+ }
21
+ declare const gracefulShutdown: GracefulShutdown;
22
+ export default gracefulShutdown;
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Input validation utility for security and data integrity.
3
+ * Defines regex patterns, limits, and validation methods.
4
+ */
5
+ export interface ApiProviderConfig {
6
+ temperature?: number;
7
+ maxTokens?: number;
8
+ [key: string]: any;
9
+ }
10
+ export interface RateLimiterProviderLimit {
11
+ rpm?: number;
12
+ concurrency?: number;
13
+ }
14
+ export interface RateLimiterConfig {
15
+ queueStrategy?: "fifo" | "priority";
16
+ queueTimeout?: number;
17
+ providerLimits?: Record<string, RateLimiterProviderLimit>;
18
+ }
19
+ export interface RetryOptions {
20
+ maxRetries?: number;
21
+ initialDelay?: number;
22
+ maxDelay?: number;
23
+ }
24
+ export interface ContextConfig {
25
+ aiProvider?: string;
26
+ minTextLength?: number;
27
+ detection?: {
28
+ threshold?: number;
29
+ minConfidence?: number;
30
+ };
31
+ categories?: Record<string, any>;
32
+ }
33
+ export interface QualityChecksConfig {
34
+ rules?: Record<string, any>;
35
+ enabled?: boolean;
36
+ autoFix?: boolean;
37
+ }
38
+ export interface LengthControlConfig {
39
+ mode?: "strict" | "flexible" | "exact" | "relaxed" | "smart";
40
+ rules?: Record<string, any>;
41
+ }
42
+ export interface AdvancedConfig {
43
+ timeoutMs?: number;
44
+ maxKeyLength?: number;
45
+ maxBatchSize?: number;
46
+ }
47
+ export interface AppConfig {
48
+ source: string;
49
+ targets: string[];
50
+ localesDir: string;
51
+ apiProvider?: string;
52
+ fallbackOrder?: string[];
53
+ concurrencyLimit?: number;
54
+ cacheSize?: number;
55
+ cacheTTL?: number;
56
+ apiConfig?: Record<string, ApiProviderConfig>;
57
+ rateLimiter?: RateLimiterConfig;
58
+ retryOptions?: RetryOptions;
59
+ context?: ContextConfig;
60
+ qualityChecks?: QualityChecksConfig;
61
+ lengthControl?: LengthControlConfig;
62
+ advanced?: AdvancedConfig;
63
+ fileOperations?: Record<string, any>;
64
+ debug?: boolean;
65
+ verbose?: boolean;
66
+ [key: string]: any;
67
+ }
68
+ declare class InputValidator {
69
+ static LANGUAGE_CODE_PATTERN: RegExp;
70
+ static VALID_PROVIDERS: string[];
71
+ static MAX_TEXT_LENGTH: number;
72
+ static MAX_KEY_LENGTH: number;
73
+ static MAX_PATH_LENGTH: number;
74
+ static MAX_CONFIG_DEPTH: number;
75
+ static DANGEROUS_PATTERNS: RegExp[];
76
+ private static _requestCounts?;
77
+ /**
78
+ * Validate and sanitize language code.
79
+ * @param {string} langCode - Language code to validate.
80
+ * @param {string} [paramName="language"] - Parameter name for error messages.
81
+ * @returns {string} - Sanitized language code.
82
+ * @throws {Error} If validation fails.
83
+ */
84
+ static validateLanguageCode(langCode: string, paramName?: string): string;
85
+ /**
86
+ * Validate array of language codes.
87
+ * @param {string[]} langCodes - Array of language codes.
88
+ * @param {string} [paramName="languages"] - Parameter name for errors.
89
+ * @returns {string[]} - Sanitized array of language codes.
90
+ * @throws {Error} If array is empty or contains invalid codes.
91
+ */
92
+ static validateLanguageCodes(langCodes: string[], paramName?: string): string[];
93
+ /**
94
+ * Validate and sanitize directory path.
95
+ * @param {string} dirPath - Directory path.
96
+ * @param {string} [paramName="directory"] - Parameter name for errors.
97
+ * @returns {string} - Resolved and validated absolute path.
98
+ * @throws {Error} If path is invalid or outside working directory.
99
+ */
100
+ static validateDirectoryPath(dirPath: string, paramName?: string): string;
101
+ /**
102
+ * Validate translation text.
103
+ * @param {string} text - Text to validate.
104
+ * @param {string} [paramName="text"] - Parameter name for errors.
105
+ * @returns {string} - Validated text.
106
+ * @throws {Error} If text is invalid or too long.
107
+ */
108
+ static validateText(text: string, paramName?: string): string;
109
+ /**
110
+ * Validate translation key.
111
+ * @param {string} key - Key to validate.
112
+ * @param {string} [paramName="key"] - Parameter name.
113
+ * @returns {string} - Validated key.
114
+ * @throws {Error} If key is invalid, too long, or contains traversal.
115
+ */
116
+ static validateKey(key: string, paramName?: string): string;
117
+ /**
118
+ * Validate API provider name.
119
+ * @param {string} provider - Provider name.
120
+ * @param {string} [fieldName="API provider"] - Parameter name.
121
+ * @returns {string} - Normalized provider name.
122
+ * @throws {Error} If provider is unknown.
123
+ */
124
+ static validateProvider(provider: string, fieldName?: string): string;
125
+ /**
126
+ * Sanitize filename to prevent path traversal.
127
+ * @param {string} filename - Filename to sanitize.
128
+ * @param {string|null} [extension=null] - Optional extension to enforce.
129
+ * @returns {string} - Sanitized filename.
130
+ * @throws {Error} If filename is invalid.
131
+ */
132
+ static sanitizeFilename(filename: string, extension?: string | null): string;
133
+ /**
134
+ * Create safe file path within a directory.
135
+ * @param {string} baseDir - Base directory.
136
+ * @param {string} filename - Filename.
137
+ * @returns {string} - Safe full path.
138
+ * @throws {Error} If path escapes base directory.
139
+ */
140
+ static createSafeFilePath(baseDir: string, filename: string): string;
141
+ /**
142
+ * Validate configuration object.
143
+ * @param {any} config - Configuration object to validate.
144
+ * @returns {AppConfig} - Validated configuration.
145
+ * @throws {Error} If configuration is invalid.
146
+ */
147
+ static validateConfig(config: any): AppConfig;
148
+ /**
149
+ * Validate API config for each provider.
150
+ * @param {Record<string, ApiProviderConfig>} apiConfig - API configuration object.
151
+ * @param {string[]} errors - Array to push errors to.
152
+ * @param {string[]} warnings - Array to push warnings to.
153
+ */
154
+ static validateApiConfig(apiConfig: Record<string, ApiProviderConfig>, errors: string[], warnings: string[]): void;
155
+ /**
156
+ * Validate rate limiter configuration.
157
+ * @param {RateLimiterConfig} rateLimiter - Rate limiter configuration.
158
+ * @param {string[]} errors - Array to push errors to.
159
+ * @param {string[]} warnings - Array to push warnings to.
160
+ */
161
+ static validateRateLimiterConfig(rateLimiter: RateLimiterConfig, errors: string[], _warnings: string[]): void;
162
+ /**
163
+ * Validate retry options.
164
+ * @param {RetryOptions} retryOptions - Retry options.
165
+ * @param {string[]} errors - Array to push errors to.
166
+ * @param {string[]} warnings - Array to push warnings to.
167
+ */
168
+ static validateRetryOptions(retryOptions: RetryOptions, errors: string[], _warnings: string[]): void;
169
+ /**
170
+ * Validate context configuration.
171
+ * @param {ContextConfig} context - Context configuration.
172
+ * @param {string[]} errors - Array to push errors to.
173
+ * @param {string[]} warnings - Array to push warnings to.
174
+ */
175
+ static validateContextConfig(context: ContextConfig, errors: string[], warnings: string[]): void;
176
+ /**
177
+ * Validate quality checks configuration.
178
+ * @param {QualityChecksConfig} qualityChecks - Quality checks configuration.
179
+ * @param {string[]} errors - Array to push errors to.
180
+ * @param {string[]} warnings - Array to push warnings to.
181
+ */
182
+ static validateQualityChecks(qualityChecks: QualityChecksConfig, errors: string[], warnings: string[]): void;
183
+ /**
184
+ * Validate length control configuration.
185
+ * @param {LengthControlConfig} lengthControl - Length control configuration.
186
+ * @param {string[]} errors - Array to push errors to.
187
+ */
188
+ static validateLengthControl(lengthControl: LengthControlConfig, errors: string[]): void;
189
+ /**
190
+ * Validate advanced configuration.
191
+ * @param {AdvancedConfig} advanced - Advanced configuration.
192
+ * @param {string[]} errors - Array to push errors to.
193
+ */
194
+ static validateAdvancedConfig(advanced: AdvancedConfig, errors: string[]): void;
195
+ /**
196
+ * Sanitize translation text for security.
197
+ * @param {string | null} text - Text to sanitize.
198
+ * @returns {string | null} - Sanitized text.
199
+ */
200
+ static sanitizeTranslationText(text: string | null): string | null;
201
+ /**
202
+ * Validate API key format.
203
+ * @param {string} apiKey - API key to validate.
204
+ * @param {string} providerName - Provider name.
205
+ * @returns {boolean} - True if valid.
206
+ * @throws {Error} If key is invalid.
207
+ */
208
+ static validateApiKeyFormat(apiKey: string, providerName: string): boolean;
209
+ /**
210
+ * Validate object depth to prevent circular references and deep nesting.
211
+ * @param {any} obj - Object to validate.
212
+ * @param {number} [maxDepth=10] - Maximum depth.
213
+ * @param {number} [currentDepth=0] - Current depth.
214
+ * @returns {boolean} - True if valid.
215
+ * @throws {Error} If depth exceeded.
216
+ */
217
+ static validateObjectDepth(obj: any, maxDepth?: number, currentDepth?: number): boolean;
218
+ /**
219
+ * Validate request rate for an identifier.
220
+ * @param {string} identifier - Identifier (e.g., user ID or IP).
221
+ * @param {number} [maxRequestsPerMinute=60] - Max requests per minute.
222
+ * @returns {boolean} - True if allowed.
223
+ * @throws {Error} If rate limit exceeded.
224
+ */
225
+ static validateRequestRate(identifier: string, maxRequestsPerMinute?: number): boolean;
226
+ }
227
+ export default InputValidator;