@juspay/neurolink 9.1.1 → 9.2.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 (237) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +54 -7
  3. package/dist/agent/directTools.d.ts +3 -3
  4. package/dist/cli/commands/config.d.ts +6 -6
  5. package/dist/image-gen/ImageGenService.d.ts +143 -0
  6. package/dist/image-gen/ImageGenService.js +345 -0
  7. package/dist/image-gen/imageGenTools.d.ts +126 -0
  8. package/dist/image-gen/imageGenTools.js +304 -0
  9. package/dist/image-gen/index.d.ts +46 -0
  10. package/dist/image-gen/index.js +48 -0
  11. package/dist/image-gen/types.d.ts +237 -0
  12. package/dist/image-gen/types.js +24 -0
  13. package/dist/lib/agent/directTools.d.ts +3 -3
  14. package/dist/lib/image-gen/ImageGenService.d.ts +143 -0
  15. package/dist/lib/image-gen/ImageGenService.js +346 -0
  16. package/dist/lib/image-gen/imageGenTools.d.ts +126 -0
  17. package/dist/lib/image-gen/imageGenTools.js +305 -0
  18. package/dist/lib/image-gen/index.d.ts +46 -0
  19. package/dist/lib/image-gen/index.js +49 -0
  20. package/dist/lib/image-gen/types.d.ts +237 -0
  21. package/dist/lib/image-gen/types.js +25 -0
  22. package/dist/lib/processors/base/BaseFileProcessor.d.ts +273 -0
  23. package/dist/lib/processors/base/BaseFileProcessor.js +614 -0
  24. package/dist/lib/processors/base/index.d.ts +14 -0
  25. package/dist/lib/processors/base/index.js +20 -0
  26. package/dist/lib/processors/base/types.d.ts +593 -0
  27. package/dist/lib/processors/base/types.js +77 -0
  28. package/dist/lib/processors/cli/fileProcessorCli.d.ts +163 -0
  29. package/dist/lib/processors/cli/fileProcessorCli.js +389 -0
  30. package/dist/lib/processors/cli/index.d.ts +37 -0
  31. package/dist/lib/processors/cli/index.js +50 -0
  32. package/dist/lib/processors/code/ConfigProcessor.d.ts +171 -0
  33. package/dist/lib/processors/code/ConfigProcessor.js +401 -0
  34. package/dist/lib/processors/code/SourceCodeProcessor.d.ts +174 -0
  35. package/dist/lib/processors/code/SourceCodeProcessor.js +305 -0
  36. package/dist/lib/processors/code/index.d.ts +44 -0
  37. package/dist/lib/processors/code/index.js +61 -0
  38. package/dist/lib/processors/config/fileTypes.d.ts +283 -0
  39. package/dist/lib/processors/config/fileTypes.js +521 -0
  40. package/dist/lib/processors/config/index.d.ts +32 -0
  41. package/dist/lib/processors/config/index.js +93 -0
  42. package/dist/lib/processors/config/languageMap.d.ts +66 -0
  43. package/dist/lib/processors/config/languageMap.js +411 -0
  44. package/dist/lib/processors/config/mimeTypes.d.ts +376 -0
  45. package/dist/lib/processors/config/mimeTypes.js +339 -0
  46. package/dist/lib/processors/config/sizeLimits.d.ts +194 -0
  47. package/dist/lib/processors/config/sizeLimits.js +247 -0
  48. package/dist/lib/processors/data/JsonProcessor.d.ts +122 -0
  49. package/dist/lib/processors/data/JsonProcessor.js +204 -0
  50. package/dist/lib/processors/data/XmlProcessor.d.ts +160 -0
  51. package/dist/lib/processors/data/XmlProcessor.js +284 -0
  52. package/dist/lib/processors/data/YamlProcessor.d.ts +163 -0
  53. package/dist/lib/processors/data/YamlProcessor.js +295 -0
  54. package/dist/lib/processors/data/index.d.ts +49 -0
  55. package/dist/lib/processors/data/index.js +77 -0
  56. package/dist/lib/processors/document/ExcelProcessor.d.ts +238 -0
  57. package/dist/lib/processors/document/ExcelProcessor.js +520 -0
  58. package/dist/lib/processors/document/OpenDocumentProcessor.d.ts +69 -0
  59. package/dist/lib/processors/document/OpenDocumentProcessor.js +211 -0
  60. package/dist/lib/processors/document/RtfProcessor.d.ts +152 -0
  61. package/dist/lib/processors/document/RtfProcessor.js +362 -0
  62. package/dist/lib/processors/document/WordProcessor.d.ts +168 -0
  63. package/dist/lib/processors/document/WordProcessor.js +354 -0
  64. package/dist/lib/processors/document/index.d.ts +54 -0
  65. package/dist/lib/processors/document/index.js +91 -0
  66. package/dist/lib/processors/errors/FileErrorCode.d.ts +98 -0
  67. package/dist/lib/processors/errors/FileErrorCode.js +256 -0
  68. package/dist/lib/processors/errors/errorHelpers.d.ts +151 -0
  69. package/dist/lib/processors/errors/errorHelpers.js +379 -0
  70. package/dist/lib/processors/errors/errorSerializer.d.ts +139 -0
  71. package/dist/lib/processors/errors/errorSerializer.js +508 -0
  72. package/dist/lib/processors/errors/index.d.ts +46 -0
  73. package/dist/lib/processors/errors/index.js +50 -0
  74. package/dist/lib/processors/index.d.ts +76 -0
  75. package/dist/lib/processors/index.js +113 -0
  76. package/dist/lib/processors/integration/FileProcessorIntegration.d.ts +244 -0
  77. package/dist/lib/processors/integration/FileProcessorIntegration.js +273 -0
  78. package/dist/lib/processors/integration/index.d.ts +42 -0
  79. package/dist/lib/processors/integration/index.js +45 -0
  80. package/dist/lib/processors/markup/HtmlProcessor.d.ts +169 -0
  81. package/dist/lib/processors/markup/HtmlProcessor.js +250 -0
  82. package/dist/lib/processors/markup/MarkdownProcessor.d.ts +165 -0
  83. package/dist/lib/processors/markup/MarkdownProcessor.js +245 -0
  84. package/dist/lib/processors/markup/SvgProcessor.d.ts +156 -0
  85. package/dist/lib/processors/markup/SvgProcessor.js +241 -0
  86. package/dist/lib/processors/markup/TextProcessor.d.ts +135 -0
  87. package/dist/lib/processors/markup/TextProcessor.js +189 -0
  88. package/dist/lib/processors/markup/index.d.ts +66 -0
  89. package/dist/lib/processors/markup/index.js +103 -0
  90. package/dist/lib/processors/registry/ProcessorRegistry.d.ts +334 -0
  91. package/dist/lib/processors/registry/ProcessorRegistry.js +609 -0
  92. package/dist/lib/processors/registry/index.d.ts +12 -0
  93. package/dist/lib/processors/registry/index.js +17 -0
  94. package/dist/lib/processors/registry/types.d.ts +53 -0
  95. package/dist/lib/processors/registry/types.js +11 -0
  96. package/dist/lib/providers/sagemaker/language-model.d.ts +2 -2
  97. package/dist/lib/server/utils/validation.d.ts +6 -6
  98. package/dist/lib/types/fileTypes.d.ts +1 -1
  99. package/dist/lib/types/index.d.ts +25 -24
  100. package/dist/lib/types/index.js +21 -20
  101. package/dist/lib/types/modelTypes.d.ts +18 -18
  102. package/dist/lib/types/pptTypes.d.ts +14 -2
  103. package/dist/lib/types/pptTypes.js +16 -0
  104. package/dist/lib/utils/async/delay.d.ts +40 -0
  105. package/dist/lib/utils/async/delay.js +43 -0
  106. package/dist/lib/utils/async/index.d.ts +23 -0
  107. package/dist/lib/utils/async/index.js +24 -0
  108. package/dist/lib/utils/async/retry.d.ts +141 -0
  109. package/dist/lib/utils/async/retry.js +172 -0
  110. package/dist/lib/utils/async/withTimeout.d.ts +73 -0
  111. package/dist/lib/utils/async/withTimeout.js +97 -0
  112. package/dist/lib/utils/fileDetector.d.ts +7 -1
  113. package/dist/lib/utils/fileDetector.js +91 -18
  114. package/dist/lib/utils/json/extract.d.ts +103 -0
  115. package/dist/lib/utils/json/extract.js +249 -0
  116. package/dist/lib/utils/json/index.d.ts +36 -0
  117. package/dist/lib/utils/json/index.js +37 -0
  118. package/dist/lib/utils/json/safeParse.d.ts +137 -0
  119. package/dist/lib/utils/json/safeParse.js +191 -0
  120. package/dist/lib/utils/messageBuilder.d.ts +2 -2
  121. package/dist/lib/utils/messageBuilder.js +15 -7
  122. package/dist/lib/utils/sanitizers/filename.d.ts +137 -0
  123. package/dist/lib/utils/sanitizers/filename.js +366 -0
  124. package/dist/lib/utils/sanitizers/html.d.ts +170 -0
  125. package/dist/lib/utils/sanitizers/html.js +326 -0
  126. package/dist/lib/utils/sanitizers/index.d.ts +26 -0
  127. package/dist/lib/utils/sanitizers/index.js +30 -0
  128. package/dist/lib/utils/sanitizers/svg.d.ts +81 -0
  129. package/dist/lib/utils/sanitizers/svg.js +483 -0
  130. package/dist/processors/base/BaseFileProcessor.d.ts +273 -0
  131. package/dist/processors/base/BaseFileProcessor.js +613 -0
  132. package/dist/processors/base/index.d.ts +14 -0
  133. package/dist/processors/base/index.js +19 -0
  134. package/dist/processors/base/types.d.ts +593 -0
  135. package/dist/processors/base/types.js +76 -0
  136. package/dist/processors/cli/fileProcessorCli.d.ts +163 -0
  137. package/dist/processors/cli/fileProcessorCli.js +388 -0
  138. package/dist/processors/cli/index.d.ts +37 -0
  139. package/dist/processors/cli/index.js +49 -0
  140. package/dist/processors/code/ConfigProcessor.d.ts +171 -0
  141. package/dist/processors/code/ConfigProcessor.js +400 -0
  142. package/dist/processors/code/SourceCodeProcessor.d.ts +174 -0
  143. package/dist/processors/code/SourceCodeProcessor.js +304 -0
  144. package/dist/processors/code/index.d.ts +44 -0
  145. package/dist/processors/code/index.js +60 -0
  146. package/dist/processors/config/fileTypes.d.ts +283 -0
  147. package/dist/processors/config/fileTypes.js +520 -0
  148. package/dist/processors/config/index.d.ts +32 -0
  149. package/dist/processors/config/index.js +92 -0
  150. package/dist/processors/config/languageMap.d.ts +66 -0
  151. package/dist/processors/config/languageMap.js +410 -0
  152. package/dist/processors/config/mimeTypes.d.ts +376 -0
  153. package/dist/processors/config/mimeTypes.js +338 -0
  154. package/dist/processors/config/sizeLimits.d.ts +194 -0
  155. package/dist/processors/config/sizeLimits.js +246 -0
  156. package/dist/processors/data/JsonProcessor.d.ts +122 -0
  157. package/dist/processors/data/JsonProcessor.js +203 -0
  158. package/dist/processors/data/XmlProcessor.d.ts +160 -0
  159. package/dist/processors/data/XmlProcessor.js +283 -0
  160. package/dist/processors/data/YamlProcessor.d.ts +163 -0
  161. package/dist/processors/data/YamlProcessor.js +294 -0
  162. package/dist/processors/data/index.d.ts +49 -0
  163. package/dist/processors/data/index.js +76 -0
  164. package/dist/processors/document/ExcelProcessor.d.ts +238 -0
  165. package/dist/processors/document/ExcelProcessor.js +519 -0
  166. package/dist/processors/document/OpenDocumentProcessor.d.ts +69 -0
  167. package/dist/processors/document/OpenDocumentProcessor.js +210 -0
  168. package/dist/processors/document/RtfProcessor.d.ts +152 -0
  169. package/dist/processors/document/RtfProcessor.js +361 -0
  170. package/dist/processors/document/WordProcessor.d.ts +168 -0
  171. package/dist/processors/document/WordProcessor.js +353 -0
  172. package/dist/processors/document/index.d.ts +54 -0
  173. package/dist/processors/document/index.js +90 -0
  174. package/dist/processors/errors/FileErrorCode.d.ts +98 -0
  175. package/dist/processors/errors/FileErrorCode.js +255 -0
  176. package/dist/processors/errors/errorHelpers.d.ts +151 -0
  177. package/dist/processors/errors/errorHelpers.js +378 -0
  178. package/dist/processors/errors/errorSerializer.d.ts +139 -0
  179. package/dist/processors/errors/errorSerializer.js +507 -0
  180. package/dist/processors/errors/index.d.ts +46 -0
  181. package/dist/processors/errors/index.js +49 -0
  182. package/dist/processors/index.d.ts +76 -0
  183. package/dist/processors/index.js +112 -0
  184. package/dist/processors/integration/FileProcessorIntegration.d.ts +244 -0
  185. package/dist/processors/integration/FileProcessorIntegration.js +272 -0
  186. package/dist/processors/integration/index.d.ts +42 -0
  187. package/dist/processors/integration/index.js +44 -0
  188. package/dist/processors/markup/HtmlProcessor.d.ts +169 -0
  189. package/dist/processors/markup/HtmlProcessor.js +249 -0
  190. package/dist/processors/markup/MarkdownProcessor.d.ts +165 -0
  191. package/dist/processors/markup/MarkdownProcessor.js +244 -0
  192. package/dist/processors/markup/SvgProcessor.d.ts +156 -0
  193. package/dist/processors/markup/SvgProcessor.js +240 -0
  194. package/dist/processors/markup/TextProcessor.d.ts +135 -0
  195. package/dist/processors/markup/TextProcessor.js +188 -0
  196. package/dist/processors/markup/index.d.ts +66 -0
  197. package/dist/processors/markup/index.js +102 -0
  198. package/dist/processors/registry/ProcessorRegistry.d.ts +334 -0
  199. package/dist/processors/registry/ProcessorRegistry.js +608 -0
  200. package/dist/processors/registry/index.d.ts +12 -0
  201. package/dist/processors/registry/index.js +16 -0
  202. package/dist/processors/registry/types.d.ts +53 -0
  203. package/dist/processors/registry/types.js +10 -0
  204. package/dist/server/utils/validation.d.ts +6 -6
  205. package/dist/types/fileTypes.d.ts +1 -1
  206. package/dist/types/index.d.ts +25 -24
  207. package/dist/types/index.js +21 -20
  208. package/dist/types/modelTypes.d.ts +10 -10
  209. package/dist/types/pptTypes.d.ts +14 -2
  210. package/dist/types/pptTypes.js +16 -0
  211. package/dist/utils/async/delay.d.ts +40 -0
  212. package/dist/utils/async/delay.js +42 -0
  213. package/dist/utils/async/index.d.ts +23 -0
  214. package/dist/utils/async/index.js +23 -0
  215. package/dist/utils/async/retry.d.ts +141 -0
  216. package/dist/utils/async/retry.js +171 -0
  217. package/dist/utils/async/withTimeout.d.ts +73 -0
  218. package/dist/utils/async/withTimeout.js +96 -0
  219. package/dist/utils/fileDetector.d.ts +7 -1
  220. package/dist/utils/fileDetector.js +91 -18
  221. package/dist/utils/json/extract.d.ts +103 -0
  222. package/dist/utils/json/extract.js +248 -0
  223. package/dist/utils/json/index.d.ts +36 -0
  224. package/dist/utils/json/index.js +36 -0
  225. package/dist/utils/json/safeParse.d.ts +137 -0
  226. package/dist/utils/json/safeParse.js +190 -0
  227. package/dist/utils/messageBuilder.d.ts +2 -2
  228. package/dist/utils/messageBuilder.js +15 -7
  229. package/dist/utils/sanitizers/filename.d.ts +137 -0
  230. package/dist/utils/sanitizers/filename.js +365 -0
  231. package/dist/utils/sanitizers/html.d.ts +170 -0
  232. package/dist/utils/sanitizers/html.js +325 -0
  233. package/dist/utils/sanitizers/index.d.ts +26 -0
  234. package/dist/utils/sanitizers/index.js +29 -0
  235. package/dist/utils/sanitizers/svg.d.ts +81 -0
  236. package/dist/utils/sanitizers/svg.js +482 -0
  237. package/package.json +2 -2
@@ -0,0 +1,171 @@
1
+ /**
2
+ * Config File Processor
3
+ *
4
+ * Processes configuration files (.env, .ini, .toml, .cfg, .conf, .properties).
5
+ * Automatically detects format based on extension and redacts sensitive values
6
+ * for security.
7
+ *
8
+ * Key features:
9
+ * - Format detection (env, ini, toml, properties)
10
+ * - Automatic secret redaction (passwords, tokens, API keys)
11
+ * - Key-value extraction for structured access
12
+ * - Security-first approach to config file handling
13
+ *
14
+ * Priority: 130 (lower priority - text-based config files)
15
+ *
16
+ * @module processors/code/ConfigProcessor
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { configProcessor, processConfig, isConfigFile } from "./code/index.js";
21
+ *
22
+ * // Check if a file is a config file
23
+ * if (isConfigFile("text/plain", ".env")) {
24
+ * const result = await processConfig({
25
+ * id: "file-123",
26
+ * name: ".env",
27
+ * mimetype: "text/plain",
28
+ * size: 512,
29
+ * buffer: envBuffer,
30
+ * });
31
+ *
32
+ * if (result.success) {
33
+ * console.log(`Format: ${result.data.format}`);
34
+ * console.log(`Redacted keys: ${result.data.redactedKeys.join(", ")}`);
35
+ * }
36
+ * }
37
+ * ```
38
+ */
39
+ import { BaseFileProcessor } from "../base/BaseFileProcessor.js";
40
+ import type { FileInfo, FileProcessingResult, ProcessOptions } from "../base/types.js";
41
+ export type { ProcessedConfig } from "../base/types.js";
42
+ import type { ProcessedConfig } from "../base/types.js";
43
+ /**
44
+ * Config Processor - handles configuration files with security redaction.
45
+ *
46
+ * Automatically detects the format based on file extension and extracts
47
+ * key-value pairs while redacting sensitive values for security.
48
+ *
49
+ * Priority: 130 (processed after binary/document formats)
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * const processor = new ConfigProcessor();
54
+ *
55
+ * const result = await processor.processFile({
56
+ * id: "file-123",
57
+ * name: ".env",
58
+ * mimetype: "text/plain",
59
+ * size: 512,
60
+ * buffer: envBuffer,
61
+ * });
62
+ *
63
+ * if (result.success) {
64
+ * console.log(`Detected format: ${result.data.format}`);
65
+ * console.log(`Redacted ${result.data.redactedKeys.length} sensitive keys`);
66
+ * }
67
+ * ```
68
+ */
69
+ export declare class ConfigProcessor extends BaseFileProcessor<ProcessedConfig> {
70
+ constructor();
71
+ /**
72
+ * Override to check for exact filename matches like ".env" files.
73
+ *
74
+ * @param mimetype - MIME type of the file
75
+ * @param filename - Filename for detection
76
+ * @returns true if the file is a supported config file
77
+ */
78
+ isFileSupported(mimetype: string, filename: string): boolean;
79
+ /**
80
+ * Build the processed config result.
81
+ * Detects format, extracts key-values, and redacts sensitive content.
82
+ *
83
+ * @param buffer - Raw file content
84
+ * @param fileInfo - Original file information
85
+ * @returns Processed config with redacted content and key-value pairs
86
+ */
87
+ protected buildProcessedResult(buffer: Buffer, fileInfo: FileInfo): ProcessedConfig;
88
+ /**
89
+ * Detect the configuration format based on extension and content.
90
+ *
91
+ * @param ext - File extension (with leading dot)
92
+ * @param content - File content for format heuristics
93
+ * @returns Detected format
94
+ */
95
+ private detectFormat;
96
+ /**
97
+ * Parse configuration content and redact sensitive values.
98
+ *
99
+ * @param content - Raw configuration content
100
+ * @param format - Detected format
101
+ * @returns Key-value pairs and list of redacted keys
102
+ */
103
+ private parseAndRedact;
104
+ /**
105
+ * Check if a key likely contains sensitive data.
106
+ *
107
+ * @param key - Key name to check
108
+ * @returns true if the key matches a sensitive pattern
109
+ */
110
+ private isSensitiveKey;
111
+ /**
112
+ * Redact sensitive values in the original content.
113
+ *
114
+ * @param content - Original configuration content
115
+ * @param redactedKeys - Keys to redact
116
+ * @returns Content with redacted values
117
+ */
118
+ private redactContent;
119
+ /**
120
+ * Extract file extension from filename.
121
+ *
122
+ * @param filename - Filename to extract extension from
123
+ * @returns Extension with leading dot or null
124
+ */
125
+ private getExtension;
126
+ }
127
+ /**
128
+ * Singleton instance of the ConfigProcessor.
129
+ * Use this for all configuration file processing to share configuration.
130
+ */
131
+ export declare const configProcessor: ConfigProcessor;
132
+ /**
133
+ * Check if a file is a configuration file.
134
+ *
135
+ * @param mimetype - MIME type of the file
136
+ * @param filename - Filename for detection
137
+ * @returns true if the file is a supported config file
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * if (isConfigFile("text/plain", ".env")) {
142
+ * console.log("This is a config file");
143
+ * }
144
+ * ```
145
+ */
146
+ export declare function isConfigFile(mimetype: string, filename: string): boolean;
147
+ /**
148
+ * Process a configuration file.
149
+ *
150
+ * @param fileInfo - File information (can include URL or buffer)
151
+ * @param options - Optional processing options
152
+ * @returns Processing result with success flag and either data or error
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * const result = await processConfig({
157
+ * id: "file-123",
158
+ * name: ".env.production",
159
+ * mimetype: "text/plain",
160
+ * size: 1024,
161
+ * buffer: configBuffer,
162
+ * });
163
+ *
164
+ * if (result.success) {
165
+ * console.log(`Format: ${result.data.format}`);
166
+ * console.log(`Keys: ${Object.keys(result.data.keyValues).length}`);
167
+ * console.log(`Redacted: ${result.data.redactedKeys.join(", ")}`);
168
+ * }
169
+ * ```
170
+ */
171
+ export declare function processConfig(fileInfo: FileInfo, options?: ProcessOptions): Promise<FileProcessingResult<ProcessedConfig>>;
@@ -0,0 +1,400 @@
1
+ /**
2
+ * Config File Processor
3
+ *
4
+ * Processes configuration files (.env, .ini, .toml, .cfg, .conf, .properties).
5
+ * Automatically detects format based on extension and redacts sensitive values
6
+ * for security.
7
+ *
8
+ * Key features:
9
+ * - Format detection (env, ini, toml, properties)
10
+ * - Automatic secret redaction (passwords, tokens, API keys)
11
+ * - Key-value extraction for structured access
12
+ * - Security-first approach to config file handling
13
+ *
14
+ * Priority: 130 (lower priority - text-based config files)
15
+ *
16
+ * @module processors/code/ConfigProcessor
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { configProcessor, processConfig, isConfigFile } from "./code/index.js";
21
+ *
22
+ * // Check if a file is a config file
23
+ * if (isConfigFile("text/plain", ".env")) {
24
+ * const result = await processConfig({
25
+ * id: "file-123",
26
+ * name: ".env",
27
+ * mimetype: "text/plain",
28
+ * size: 512,
29
+ * buffer: envBuffer,
30
+ * });
31
+ *
32
+ * if (result.success) {
33
+ * console.log(`Format: ${result.data.format}`);
34
+ * console.log(`Redacted keys: ${result.data.redactedKeys.join(", ")}`);
35
+ * }
36
+ * }
37
+ * ```
38
+ */
39
+ import { basename as pathBasename } from "node:path";
40
+ import { BaseFileProcessor } from "../base/BaseFileProcessor.js";
41
+ import { SIZE_LIMITS } from "../config/index.js";
42
+ // =============================================================================
43
+ // CONSTANTS
44
+ // =============================================================================
45
+ /**
46
+ * Regex patterns for identifying keys that likely contain secrets.
47
+ * These keys will have their values redacted in the output.
48
+ */
49
+ const SECRET_KEY_PATTERNS = [
50
+ /password/i,
51
+ /secret/i,
52
+ /token/i,
53
+ /key/i,
54
+ /api[_-]?key/i,
55
+ /auth/i,
56
+ /credential/i,
57
+ /private/i,
58
+ /access[_-]?token/i,
59
+ /bearer/i,
60
+ /jwt/i,
61
+ /session/i,
62
+ /cookie/i,
63
+ /encryption/i,
64
+ /salt/i,
65
+ /hash/i,
66
+ /cert/i,
67
+ /certificate/i,
68
+ /pem/i,
69
+ /rsa/i,
70
+ /ssh/i,
71
+ /aws[_-]?secret/i,
72
+ /azure[_-]?key/i,
73
+ /gcp[_-]?key/i,
74
+ ];
75
+ /**
76
+ * Supported MIME types for configuration files
77
+ */
78
+ const SUPPORTED_CONFIG_MIME_TYPES = [
79
+ "text/plain",
80
+ "application/x-env",
81
+ "text/x-ini",
82
+ "application/toml",
83
+ ];
84
+ /**
85
+ * Supported file extensions for configuration files
86
+ */
87
+ const SUPPORTED_CONFIG_EXTENSIONS = [
88
+ ".env",
89
+ ".ini",
90
+ ".toml",
91
+ ".cfg",
92
+ ".conf",
93
+ ".properties",
94
+ ];
95
+ /**
96
+ * Default timeout for config file processing (30 seconds)
97
+ */
98
+ const CONFIG_TIMEOUT_MS = 30000;
99
+ // =============================================================================
100
+ // CONFIG PROCESSOR CLASS
101
+ // =============================================================================
102
+ /**
103
+ * Config Processor - handles configuration files with security redaction.
104
+ *
105
+ * Automatically detects the format based on file extension and extracts
106
+ * key-value pairs while redacting sensitive values for security.
107
+ *
108
+ * Priority: 130 (processed after binary/document formats)
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const processor = new ConfigProcessor();
113
+ *
114
+ * const result = await processor.processFile({
115
+ * id: "file-123",
116
+ * name: ".env",
117
+ * mimetype: "text/plain",
118
+ * size: 512,
119
+ * buffer: envBuffer,
120
+ * });
121
+ *
122
+ * if (result.success) {
123
+ * console.log(`Detected format: ${result.data.format}`);
124
+ * console.log(`Redacted ${result.data.redactedKeys.length} sensitive keys`);
125
+ * }
126
+ * ```
127
+ */
128
+ export class ConfigProcessor extends BaseFileProcessor {
129
+ constructor() {
130
+ super({
131
+ maxSizeMB: SIZE_LIMITS.TEXT_MAX_MB,
132
+ timeoutMs: CONFIG_TIMEOUT_MS,
133
+ supportedMimeTypes: SUPPORTED_CONFIG_MIME_TYPES,
134
+ supportedExtensions: SUPPORTED_CONFIG_EXTENSIONS,
135
+ fileTypeName: "Config",
136
+ defaultFilename: "config.env",
137
+ });
138
+ }
139
+ /**
140
+ * Override to check for exact filename matches like ".env" files.
141
+ *
142
+ * @param mimetype - MIME type of the file
143
+ * @param filename - Filename for detection
144
+ * @returns true if the file is a supported config file
145
+ */
146
+ isFileSupported(mimetype, filename) {
147
+ if (!filename) {
148
+ return false;
149
+ }
150
+ // Check for exact filename matches (e.g., ".env", ".env.local")
151
+ const basename = pathBasename(filename);
152
+ // Special handling for dotenv files
153
+ if (basename.startsWith(".env")) {
154
+ return true;
155
+ }
156
+ // Check by extension
157
+ const ext = this.getExtension(filename);
158
+ if (ext && SUPPORTED_CONFIG_EXTENSIONS.includes(ext.toLowerCase())) {
159
+ return true;
160
+ }
161
+ // Fall back to MIME type check
162
+ return super.isFileSupported(mimetype, filename);
163
+ }
164
+ /**
165
+ * Build the processed config result.
166
+ * Detects format, extracts key-values, and redacts sensitive content.
167
+ *
168
+ * @param buffer - Raw file content
169
+ * @param fileInfo - Original file information
170
+ * @returns Processed config with redacted content and key-value pairs
171
+ */
172
+ buildProcessedResult(buffer, fileInfo) {
173
+ const content = buffer.toString("utf-8");
174
+ const ext = this.getExtension(fileInfo.name || "");
175
+ const format = this.detectFormat(ext, content);
176
+ const { keyValues, redactedKeys } = this.parseAndRedact(content, format);
177
+ return {
178
+ content: this.redactContent(content, redactedKeys),
179
+ format,
180
+ keyValues,
181
+ redactedKeys,
182
+ buffer,
183
+ mimetype: fileInfo.mimetype || "text/plain",
184
+ size: fileInfo.size,
185
+ filename: this.getFilename(fileInfo),
186
+ };
187
+ }
188
+ /**
189
+ * Detect the configuration format based on extension and content.
190
+ *
191
+ * @param ext - File extension (with leading dot)
192
+ * @param content - File content for format heuristics
193
+ * @returns Detected format
194
+ */
195
+ detectFormat(ext, content) {
196
+ // First check extension
197
+ if (ext) {
198
+ const lowerExt = ext.toLowerCase();
199
+ if (lowerExt === ".env") {
200
+ return "env";
201
+ }
202
+ if (lowerExt === ".ini" || lowerExt === ".cfg" || lowerExt === ".conf") {
203
+ return "ini";
204
+ }
205
+ if (lowerExt === ".toml") {
206
+ return "toml";
207
+ }
208
+ if (lowerExt === ".properties") {
209
+ return "properties";
210
+ }
211
+ }
212
+ // Try content-based heuristics
213
+ const lines = content
214
+ .split("\n")
215
+ .filter((l) => l.trim() && !l.trim().startsWith("#"));
216
+ // Check for TOML markers
217
+ if (content.includes("[") &&
218
+ content.includes("]") &&
219
+ lines.some((l) => l.includes("="))) {
220
+ // Could be INI or TOML - check for TOML-specific syntax
221
+ if (content.includes("[[") ||
222
+ content.includes('"""') ||
223
+ content.includes("'''")) {
224
+ return "toml";
225
+ }
226
+ return "ini";
227
+ }
228
+ // Check for properties-style (key: value or key = value with Java conventions)
229
+ if (lines.some((l) => l.includes(":") && !l.includes("="))) {
230
+ return "properties";
231
+ }
232
+ // Default to env format for simple KEY=VALUE files
233
+ if (lines.some((l) => /^[A-Z_][A-Z0-9_]*=/i.test(l.trim()))) {
234
+ return "env";
235
+ }
236
+ return "unknown";
237
+ }
238
+ /**
239
+ * Parse configuration content and redact sensitive values.
240
+ *
241
+ * @param content - Raw configuration content
242
+ * @param format - Detected format
243
+ * @returns Key-value pairs and list of redacted keys
244
+ */
245
+ parseAndRedact(content, format) {
246
+ const keyValues = {};
247
+ const redactedKeys = [];
248
+ const lines = content.split("\n");
249
+ for (const line of lines) {
250
+ const trimmedLine = line.trim();
251
+ // Skip comments and empty lines
252
+ if (!trimmedLine ||
253
+ trimmedLine.startsWith("#") ||
254
+ trimmedLine.startsWith(";")) {
255
+ continue;
256
+ }
257
+ // Skip section headers (INI/TOML style)
258
+ if (trimmedLine.startsWith("[")) {
259
+ continue;
260
+ }
261
+ // Try to extract key-value pair
262
+ let key = "";
263
+ let value = "";
264
+ // Handle different formats
265
+ if (format === "properties" &&
266
+ trimmedLine.includes(":") &&
267
+ !trimmedLine.includes("=")) {
268
+ // Properties format: key: value or key : value
269
+ const colonIndex = trimmedLine.indexOf(":");
270
+ key = trimmedLine.substring(0, colonIndex).trim();
271
+ value = trimmedLine.substring(colonIndex + 1).trim();
272
+ }
273
+ else if (trimmedLine.includes("=")) {
274
+ // Standard KEY=VALUE format
275
+ const equalIndex = trimmedLine.indexOf("=");
276
+ key = trimmedLine.substring(0, equalIndex).trim();
277
+ value = trimmedLine.substring(equalIndex + 1).trim();
278
+ // Remove quotes if present
279
+ if ((value.startsWith('"') && value.endsWith('"')) ||
280
+ (value.startsWith("'") && value.endsWith("'"))) {
281
+ value = value.slice(1, -1);
282
+ }
283
+ }
284
+ if (key) {
285
+ // Check if this key should be redacted
286
+ if (this.isSensitiveKey(key)) {
287
+ keyValues[key] = "[REDACTED]";
288
+ redactedKeys.push(key);
289
+ }
290
+ else {
291
+ keyValues[key] = value;
292
+ }
293
+ }
294
+ }
295
+ return { keyValues, redactedKeys };
296
+ }
297
+ /**
298
+ * Check if a key likely contains sensitive data.
299
+ *
300
+ * @param key - Key name to check
301
+ * @returns true if the key matches a sensitive pattern
302
+ */
303
+ isSensitiveKey(key) {
304
+ return SECRET_KEY_PATTERNS.some((pattern) => pattern.test(key));
305
+ }
306
+ /**
307
+ * Redact sensitive values in the original content.
308
+ *
309
+ * @param content - Original configuration content
310
+ * @param redactedKeys - Keys to redact
311
+ * @returns Content with redacted values
312
+ */
313
+ redactContent(content, redactedKeys) {
314
+ let result = content;
315
+ for (const key of redactedKeys) {
316
+ // Escape special regex characters in the key
317
+ const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
318
+ // Match key=value or key: value patterns
319
+ const patterns = [
320
+ // KEY=value (with optional quotes)
321
+ new RegExp(`(${escapedKey}\\s*=\\s*)(["']?)[^"'\\n]*(["']?)`, "gm"),
322
+ // KEY: value (properties style)
323
+ new RegExp(`(${escapedKey}\\s*:\\s*)(.*)$`, "gm"),
324
+ ];
325
+ for (const regex of patterns) {
326
+ result = result.replace(regex, "$1[REDACTED]");
327
+ }
328
+ }
329
+ return result;
330
+ }
331
+ /**
332
+ * Extract file extension from filename.
333
+ *
334
+ * @param filename - Filename to extract extension from
335
+ * @returns Extension with leading dot or null
336
+ */
337
+ getExtension(filename) {
338
+ // Handle .env files specially
339
+ if (filename.startsWith(".env")) {
340
+ return ".env";
341
+ }
342
+ const match = filename.toLowerCase().match(/\.[^.]+$/);
343
+ return match ? match[0] : null;
344
+ }
345
+ }
346
+ // =============================================================================
347
+ // SINGLETON INSTANCE
348
+ // =============================================================================
349
+ /**
350
+ * Singleton instance of the ConfigProcessor.
351
+ * Use this for all configuration file processing to share configuration.
352
+ */
353
+ export const configProcessor = new ConfigProcessor();
354
+ // =============================================================================
355
+ // HELPER FUNCTIONS
356
+ // =============================================================================
357
+ /**
358
+ * Check if a file is a configuration file.
359
+ *
360
+ * @param mimetype - MIME type of the file
361
+ * @param filename - Filename for detection
362
+ * @returns true if the file is a supported config file
363
+ *
364
+ * @example
365
+ * ```typescript
366
+ * if (isConfigFile("text/plain", ".env")) {
367
+ * console.log("This is a config file");
368
+ * }
369
+ * ```
370
+ */
371
+ export function isConfigFile(mimetype, filename) {
372
+ return configProcessor.isFileSupported(mimetype, filename);
373
+ }
374
+ /**
375
+ * Process a configuration file.
376
+ *
377
+ * @param fileInfo - File information (can include URL or buffer)
378
+ * @param options - Optional processing options
379
+ * @returns Processing result with success flag and either data or error
380
+ *
381
+ * @example
382
+ * ```typescript
383
+ * const result = await processConfig({
384
+ * id: "file-123",
385
+ * name: ".env.production",
386
+ * mimetype: "text/plain",
387
+ * size: 1024,
388
+ * buffer: configBuffer,
389
+ * });
390
+ *
391
+ * if (result.success) {
392
+ * console.log(`Format: ${result.data.format}`);
393
+ * console.log(`Keys: ${Object.keys(result.data.keyValues).length}`);
394
+ * console.log(`Redacted: ${result.data.redactedKeys.join(", ")}`);
395
+ * }
396
+ * ```
397
+ */
398
+ export async function processConfig(fileInfo, options) {
399
+ return configProcessor.processFile(fileInfo, options);
400
+ }