@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.
- package/CHANGELOG.md +6 -0
- package/README.md +54 -7
- package/dist/agent/directTools.d.ts +3 -3
- package/dist/cli/commands/config.d.ts +6 -6
- package/dist/image-gen/ImageGenService.d.ts +143 -0
- package/dist/image-gen/ImageGenService.js +345 -0
- package/dist/image-gen/imageGenTools.d.ts +126 -0
- package/dist/image-gen/imageGenTools.js +304 -0
- package/dist/image-gen/index.d.ts +46 -0
- package/dist/image-gen/index.js +48 -0
- package/dist/image-gen/types.d.ts +237 -0
- package/dist/image-gen/types.js +24 -0
- package/dist/lib/agent/directTools.d.ts +3 -3
- package/dist/lib/image-gen/ImageGenService.d.ts +143 -0
- package/dist/lib/image-gen/ImageGenService.js +346 -0
- package/dist/lib/image-gen/imageGenTools.d.ts +126 -0
- package/dist/lib/image-gen/imageGenTools.js +305 -0
- package/dist/lib/image-gen/index.d.ts +46 -0
- package/dist/lib/image-gen/index.js +49 -0
- package/dist/lib/image-gen/types.d.ts +237 -0
- package/dist/lib/image-gen/types.js +25 -0
- package/dist/lib/processors/base/BaseFileProcessor.d.ts +273 -0
- package/dist/lib/processors/base/BaseFileProcessor.js +614 -0
- package/dist/lib/processors/base/index.d.ts +14 -0
- package/dist/lib/processors/base/index.js +20 -0
- package/dist/lib/processors/base/types.d.ts +593 -0
- package/dist/lib/processors/base/types.js +77 -0
- package/dist/lib/processors/cli/fileProcessorCli.d.ts +163 -0
- package/dist/lib/processors/cli/fileProcessorCli.js +389 -0
- package/dist/lib/processors/cli/index.d.ts +37 -0
- package/dist/lib/processors/cli/index.js +50 -0
- package/dist/lib/processors/code/ConfigProcessor.d.ts +171 -0
- package/dist/lib/processors/code/ConfigProcessor.js +401 -0
- package/dist/lib/processors/code/SourceCodeProcessor.d.ts +174 -0
- package/dist/lib/processors/code/SourceCodeProcessor.js +305 -0
- package/dist/lib/processors/code/index.d.ts +44 -0
- package/dist/lib/processors/code/index.js +61 -0
- package/dist/lib/processors/config/fileTypes.d.ts +283 -0
- package/dist/lib/processors/config/fileTypes.js +521 -0
- package/dist/lib/processors/config/index.d.ts +32 -0
- package/dist/lib/processors/config/index.js +93 -0
- package/dist/lib/processors/config/languageMap.d.ts +66 -0
- package/dist/lib/processors/config/languageMap.js +411 -0
- package/dist/lib/processors/config/mimeTypes.d.ts +376 -0
- package/dist/lib/processors/config/mimeTypes.js +339 -0
- package/dist/lib/processors/config/sizeLimits.d.ts +194 -0
- package/dist/lib/processors/config/sizeLimits.js +247 -0
- package/dist/lib/processors/data/JsonProcessor.d.ts +122 -0
- package/dist/lib/processors/data/JsonProcessor.js +204 -0
- package/dist/lib/processors/data/XmlProcessor.d.ts +160 -0
- package/dist/lib/processors/data/XmlProcessor.js +284 -0
- package/dist/lib/processors/data/YamlProcessor.d.ts +163 -0
- package/dist/lib/processors/data/YamlProcessor.js +295 -0
- package/dist/lib/processors/data/index.d.ts +49 -0
- package/dist/lib/processors/data/index.js +77 -0
- package/dist/lib/processors/document/ExcelProcessor.d.ts +238 -0
- package/dist/lib/processors/document/ExcelProcessor.js +520 -0
- package/dist/lib/processors/document/OpenDocumentProcessor.d.ts +69 -0
- package/dist/lib/processors/document/OpenDocumentProcessor.js +211 -0
- package/dist/lib/processors/document/RtfProcessor.d.ts +152 -0
- package/dist/lib/processors/document/RtfProcessor.js +362 -0
- package/dist/lib/processors/document/WordProcessor.d.ts +168 -0
- package/dist/lib/processors/document/WordProcessor.js +354 -0
- package/dist/lib/processors/document/index.d.ts +54 -0
- package/dist/lib/processors/document/index.js +91 -0
- package/dist/lib/processors/errors/FileErrorCode.d.ts +98 -0
- package/dist/lib/processors/errors/FileErrorCode.js +256 -0
- package/dist/lib/processors/errors/errorHelpers.d.ts +151 -0
- package/dist/lib/processors/errors/errorHelpers.js +379 -0
- package/dist/lib/processors/errors/errorSerializer.d.ts +139 -0
- package/dist/lib/processors/errors/errorSerializer.js +508 -0
- package/dist/lib/processors/errors/index.d.ts +46 -0
- package/dist/lib/processors/errors/index.js +50 -0
- package/dist/lib/processors/index.d.ts +76 -0
- package/dist/lib/processors/index.js +113 -0
- package/dist/lib/processors/integration/FileProcessorIntegration.d.ts +244 -0
- package/dist/lib/processors/integration/FileProcessorIntegration.js +273 -0
- package/dist/lib/processors/integration/index.d.ts +42 -0
- package/dist/lib/processors/integration/index.js +45 -0
- package/dist/lib/processors/markup/HtmlProcessor.d.ts +169 -0
- package/dist/lib/processors/markup/HtmlProcessor.js +250 -0
- package/dist/lib/processors/markup/MarkdownProcessor.d.ts +165 -0
- package/dist/lib/processors/markup/MarkdownProcessor.js +245 -0
- package/dist/lib/processors/markup/SvgProcessor.d.ts +156 -0
- package/dist/lib/processors/markup/SvgProcessor.js +241 -0
- package/dist/lib/processors/markup/TextProcessor.d.ts +135 -0
- package/dist/lib/processors/markup/TextProcessor.js +189 -0
- package/dist/lib/processors/markup/index.d.ts +66 -0
- package/dist/lib/processors/markup/index.js +103 -0
- package/dist/lib/processors/registry/ProcessorRegistry.d.ts +334 -0
- package/dist/lib/processors/registry/ProcessorRegistry.js +609 -0
- package/dist/lib/processors/registry/index.d.ts +12 -0
- package/dist/lib/processors/registry/index.js +17 -0
- package/dist/lib/processors/registry/types.d.ts +53 -0
- package/dist/lib/processors/registry/types.js +11 -0
- package/dist/lib/providers/sagemaker/language-model.d.ts +2 -2
- package/dist/lib/server/utils/validation.d.ts +6 -6
- package/dist/lib/types/fileTypes.d.ts +1 -1
- package/dist/lib/types/index.d.ts +25 -24
- package/dist/lib/types/index.js +21 -20
- package/dist/lib/types/modelTypes.d.ts +18 -18
- package/dist/lib/types/pptTypes.d.ts +14 -2
- package/dist/lib/types/pptTypes.js +16 -0
- package/dist/lib/utils/async/delay.d.ts +40 -0
- package/dist/lib/utils/async/delay.js +43 -0
- package/dist/lib/utils/async/index.d.ts +23 -0
- package/dist/lib/utils/async/index.js +24 -0
- package/dist/lib/utils/async/retry.d.ts +141 -0
- package/dist/lib/utils/async/retry.js +172 -0
- package/dist/lib/utils/async/withTimeout.d.ts +73 -0
- package/dist/lib/utils/async/withTimeout.js +97 -0
- package/dist/lib/utils/fileDetector.d.ts +7 -1
- package/dist/lib/utils/fileDetector.js +91 -18
- package/dist/lib/utils/json/extract.d.ts +103 -0
- package/dist/lib/utils/json/extract.js +249 -0
- package/dist/lib/utils/json/index.d.ts +36 -0
- package/dist/lib/utils/json/index.js +37 -0
- package/dist/lib/utils/json/safeParse.d.ts +137 -0
- package/dist/lib/utils/json/safeParse.js +191 -0
- package/dist/lib/utils/messageBuilder.d.ts +2 -2
- package/dist/lib/utils/messageBuilder.js +15 -7
- package/dist/lib/utils/sanitizers/filename.d.ts +137 -0
- package/dist/lib/utils/sanitizers/filename.js +366 -0
- package/dist/lib/utils/sanitizers/html.d.ts +170 -0
- package/dist/lib/utils/sanitizers/html.js +326 -0
- package/dist/lib/utils/sanitizers/index.d.ts +26 -0
- package/dist/lib/utils/sanitizers/index.js +30 -0
- package/dist/lib/utils/sanitizers/svg.d.ts +81 -0
- package/dist/lib/utils/sanitizers/svg.js +483 -0
- package/dist/processors/base/BaseFileProcessor.d.ts +273 -0
- package/dist/processors/base/BaseFileProcessor.js +613 -0
- package/dist/processors/base/index.d.ts +14 -0
- package/dist/processors/base/index.js +19 -0
- package/dist/processors/base/types.d.ts +593 -0
- package/dist/processors/base/types.js +76 -0
- package/dist/processors/cli/fileProcessorCli.d.ts +163 -0
- package/dist/processors/cli/fileProcessorCli.js +388 -0
- package/dist/processors/cli/index.d.ts +37 -0
- package/dist/processors/cli/index.js +49 -0
- package/dist/processors/code/ConfigProcessor.d.ts +171 -0
- package/dist/processors/code/ConfigProcessor.js +400 -0
- package/dist/processors/code/SourceCodeProcessor.d.ts +174 -0
- package/dist/processors/code/SourceCodeProcessor.js +304 -0
- package/dist/processors/code/index.d.ts +44 -0
- package/dist/processors/code/index.js +60 -0
- package/dist/processors/config/fileTypes.d.ts +283 -0
- package/dist/processors/config/fileTypes.js +520 -0
- package/dist/processors/config/index.d.ts +32 -0
- package/dist/processors/config/index.js +92 -0
- package/dist/processors/config/languageMap.d.ts +66 -0
- package/dist/processors/config/languageMap.js +410 -0
- package/dist/processors/config/mimeTypes.d.ts +376 -0
- package/dist/processors/config/mimeTypes.js +338 -0
- package/dist/processors/config/sizeLimits.d.ts +194 -0
- package/dist/processors/config/sizeLimits.js +246 -0
- package/dist/processors/data/JsonProcessor.d.ts +122 -0
- package/dist/processors/data/JsonProcessor.js +203 -0
- package/dist/processors/data/XmlProcessor.d.ts +160 -0
- package/dist/processors/data/XmlProcessor.js +283 -0
- package/dist/processors/data/YamlProcessor.d.ts +163 -0
- package/dist/processors/data/YamlProcessor.js +294 -0
- package/dist/processors/data/index.d.ts +49 -0
- package/dist/processors/data/index.js +76 -0
- package/dist/processors/document/ExcelProcessor.d.ts +238 -0
- package/dist/processors/document/ExcelProcessor.js +519 -0
- package/dist/processors/document/OpenDocumentProcessor.d.ts +69 -0
- package/dist/processors/document/OpenDocumentProcessor.js +210 -0
- package/dist/processors/document/RtfProcessor.d.ts +152 -0
- package/dist/processors/document/RtfProcessor.js +361 -0
- package/dist/processors/document/WordProcessor.d.ts +168 -0
- package/dist/processors/document/WordProcessor.js +353 -0
- package/dist/processors/document/index.d.ts +54 -0
- package/dist/processors/document/index.js +90 -0
- package/dist/processors/errors/FileErrorCode.d.ts +98 -0
- package/dist/processors/errors/FileErrorCode.js +255 -0
- package/dist/processors/errors/errorHelpers.d.ts +151 -0
- package/dist/processors/errors/errorHelpers.js +378 -0
- package/dist/processors/errors/errorSerializer.d.ts +139 -0
- package/dist/processors/errors/errorSerializer.js +507 -0
- package/dist/processors/errors/index.d.ts +46 -0
- package/dist/processors/errors/index.js +49 -0
- package/dist/processors/index.d.ts +76 -0
- package/dist/processors/index.js +112 -0
- package/dist/processors/integration/FileProcessorIntegration.d.ts +244 -0
- package/dist/processors/integration/FileProcessorIntegration.js +272 -0
- package/dist/processors/integration/index.d.ts +42 -0
- package/dist/processors/integration/index.js +44 -0
- package/dist/processors/markup/HtmlProcessor.d.ts +169 -0
- package/dist/processors/markup/HtmlProcessor.js +249 -0
- package/dist/processors/markup/MarkdownProcessor.d.ts +165 -0
- package/dist/processors/markup/MarkdownProcessor.js +244 -0
- package/dist/processors/markup/SvgProcessor.d.ts +156 -0
- package/dist/processors/markup/SvgProcessor.js +240 -0
- package/dist/processors/markup/TextProcessor.d.ts +135 -0
- package/dist/processors/markup/TextProcessor.js +188 -0
- package/dist/processors/markup/index.d.ts +66 -0
- package/dist/processors/markup/index.js +102 -0
- package/dist/processors/registry/ProcessorRegistry.d.ts +334 -0
- package/dist/processors/registry/ProcessorRegistry.js +608 -0
- package/dist/processors/registry/index.d.ts +12 -0
- package/dist/processors/registry/index.js +16 -0
- package/dist/processors/registry/types.d.ts +53 -0
- package/dist/processors/registry/types.js +10 -0
- package/dist/server/utils/validation.d.ts +6 -6
- package/dist/types/fileTypes.d.ts +1 -1
- package/dist/types/index.d.ts +25 -24
- package/dist/types/index.js +21 -20
- package/dist/types/modelTypes.d.ts +10 -10
- package/dist/types/pptTypes.d.ts +14 -2
- package/dist/types/pptTypes.js +16 -0
- package/dist/utils/async/delay.d.ts +40 -0
- package/dist/utils/async/delay.js +42 -0
- package/dist/utils/async/index.d.ts +23 -0
- package/dist/utils/async/index.js +23 -0
- package/dist/utils/async/retry.d.ts +141 -0
- package/dist/utils/async/retry.js +171 -0
- package/dist/utils/async/withTimeout.d.ts +73 -0
- package/dist/utils/async/withTimeout.js +96 -0
- package/dist/utils/fileDetector.d.ts +7 -1
- package/dist/utils/fileDetector.js +91 -18
- package/dist/utils/json/extract.d.ts +103 -0
- package/dist/utils/json/extract.js +248 -0
- package/dist/utils/json/index.d.ts +36 -0
- package/dist/utils/json/index.js +36 -0
- package/dist/utils/json/safeParse.d.ts +137 -0
- package/dist/utils/json/safeParse.js +190 -0
- package/dist/utils/messageBuilder.d.ts +2 -2
- package/dist/utils/messageBuilder.js +15 -7
- package/dist/utils/sanitizers/filename.d.ts +137 -0
- package/dist/utils/sanitizers/filename.js +365 -0
- package/dist/utils/sanitizers/html.d.ts +170 -0
- package/dist/utils/sanitizers/html.js +325 -0
- package/dist/utils/sanitizers/index.d.ts +26 -0
- package/dist/utils/sanitizers/index.js +29 -0
- package/dist/utils/sanitizers/svg.d.ts +81 -0
- package/dist/utils/sanitizers/svg.js +482 -0
- package/package.json +2 -2
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base File Processor Abstract Class
|
|
3
|
+
*
|
|
4
|
+
* Provides common functionality for downloading, validating, and processing files
|
|
5
|
+
* from any source (URLs, buffers, cloud storage, etc.)
|
|
6
|
+
*
|
|
7
|
+
* This class uses the Template Method pattern to provide a consistent processing
|
|
8
|
+
* pipeline while allowing subclasses to customize specific steps.
|
|
9
|
+
*
|
|
10
|
+
* Key features:
|
|
11
|
+
* - Support for both URL downloads and direct buffer input
|
|
12
|
+
* - Configurable retry with exponential backoff
|
|
13
|
+
* - Gzip decompression support
|
|
14
|
+
* - Structured error handling with user-friendly messages
|
|
15
|
+
* - File type validation by MIME type and extension
|
|
16
|
+
* - Size limit enforcement
|
|
17
|
+
*
|
|
18
|
+
* @module processors/base/BaseFileProcessor
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* class ImageProcessor extends BaseFileProcessor<ProcessedImage> {
|
|
23
|
+
* constructor() {
|
|
24
|
+
* super({
|
|
25
|
+
* maxSizeMB: 10,
|
|
26
|
+
* timeoutMs: 30000,
|
|
27
|
+
* supportedMimeTypes: ['image/jpeg', 'image/png'],
|
|
28
|
+
* supportedExtensions: ['.jpg', '.jpeg', '.png'],
|
|
29
|
+
* fileTypeName: 'image',
|
|
30
|
+
* defaultFilename: 'image.jpg',
|
|
31
|
+
* });
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* protected buildProcessedResult(buffer: Buffer, fileInfo: FileInfo): ProcessedImage {
|
|
35
|
+
* return {
|
|
36
|
+
* buffer,
|
|
37
|
+
* mimetype: fileInfo.mimetype,
|
|
38
|
+
* size: buffer.length,
|
|
39
|
+
* filename: this.getFilename(fileInfo),
|
|
40
|
+
* // ... additional image-specific fields
|
|
41
|
+
* };
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
import { FileErrorCode } from "../errors/index.js";
|
|
47
|
+
import type { BatchProcessingSummary, FileInfo, FileProcessingError, FileProcessingResult, FileProcessorConfig, OperationResult, ProcessedFileBase, ProcessOptions } from "./types.js";
|
|
48
|
+
/**
|
|
49
|
+
* Abstract base class for file processors.
|
|
50
|
+
* Provides common download, validation, and error handling functionality.
|
|
51
|
+
*
|
|
52
|
+
* @typeParam T - The type of processed result, must extend ProcessedFileBase
|
|
53
|
+
*/
|
|
54
|
+
export declare abstract class BaseFileProcessor<T extends ProcessedFileBase> {
|
|
55
|
+
/** Processor configuration */
|
|
56
|
+
protected readonly config: FileProcessorConfig;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new file processor with the given configuration.
|
|
59
|
+
*
|
|
60
|
+
* @param config - Processor configuration
|
|
61
|
+
*/
|
|
62
|
+
constructor(config: FileProcessorConfig);
|
|
63
|
+
/**
|
|
64
|
+
* Get the processor configuration.
|
|
65
|
+
* Provides read-only access to processor config for external consumers
|
|
66
|
+
* (e.g., ProcessorRegistry, FileProcessorIntegration) without requiring
|
|
67
|
+
* unsafe casts to access the protected field.
|
|
68
|
+
*
|
|
69
|
+
* @returns Readonly processor configuration
|
|
70
|
+
*/
|
|
71
|
+
getConfig(): Readonly<FileProcessorConfig>;
|
|
72
|
+
/**
|
|
73
|
+
* Process a single file.
|
|
74
|
+
* Main entry point - implements the Template Method pattern.
|
|
75
|
+
*
|
|
76
|
+
* @param fileInfo - File information (can include URL or buffer)
|
|
77
|
+
* @param options - Optional processing options (auth headers, timeout, retry config)
|
|
78
|
+
* @returns Processing result with success flag and either data or error
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const result = await processor.processFile(fileInfo, {
|
|
83
|
+
* authHeaders: { 'Authorization': 'Bearer token' },
|
|
84
|
+
* timeout: 60000,
|
|
85
|
+
* });
|
|
86
|
+
*
|
|
87
|
+
* if (result.success) {
|
|
88
|
+
* console.log('Processed:', result.data.filename);
|
|
89
|
+
* } else {
|
|
90
|
+
* console.error('Failed:', result.error.userMessage);
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
processFile(fileInfo: FileInfo, options?: ProcessOptions): Promise<FileProcessingResult<T>>;
|
|
95
|
+
/**
|
|
96
|
+
* Process multiple files with detailed summary.
|
|
97
|
+
*
|
|
98
|
+
* @param fileIds - Array of file IDs to process
|
|
99
|
+
* @param getFileInfo - Function to retrieve file info by ID
|
|
100
|
+
* @param options - Optional processing options
|
|
101
|
+
* @returns Summary with processed, failed, and skipped files
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const summary = await processor.processFiles(
|
|
106
|
+
* ['file1', 'file2', 'file3'],
|
|
107
|
+
* async (id) => await fetchFileInfo(id),
|
|
108
|
+
* { authHeaders: { 'Authorization': 'Bearer token' } }
|
|
109
|
+
* );
|
|
110
|
+
*
|
|
111
|
+
* console.log(`Success: ${summary.processedFiles.length}`);
|
|
112
|
+
* console.log(`Failed: ${summary.failedFiles.length}`);
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
processFiles(fileIds: string[], getFileInfo: (id: string) => Promise<FileInfo | null>, options?: ProcessOptions): Promise<BatchProcessingSummary<T>>;
|
|
116
|
+
/**
|
|
117
|
+
* Check if a file is supported by this processor.
|
|
118
|
+
*
|
|
119
|
+
* @param mimetype - MIME type of the file
|
|
120
|
+
* @param filename - Filename (for extension-based detection)
|
|
121
|
+
* @returns true if the file type is supported
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* if (processor.isFileSupported('image/jpeg', 'photo.jpg')) {
|
|
126
|
+
* // Process the file
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
isFileSupported(mimetype: string, filename: string): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Build the processed result object.
|
|
133
|
+
* Subclasses must implement this to create their specific result type.
|
|
134
|
+
*
|
|
135
|
+
* @param buffer - Downloaded/provided file content
|
|
136
|
+
* @param fileInfo - Original file information
|
|
137
|
+
* @returns Processed result object
|
|
138
|
+
*/
|
|
139
|
+
protected abstract buildProcessedResult(buffer: Buffer, fileInfo: FileInfo): T | Promise<T>;
|
|
140
|
+
/**
|
|
141
|
+
* Validate downloaded file buffer.
|
|
142
|
+
* Override for custom post-download validation (e.g., magic bytes).
|
|
143
|
+
*
|
|
144
|
+
* @param _buffer - Downloaded file content
|
|
145
|
+
* @param _fileInfo - Original file information
|
|
146
|
+
* @returns null if valid, error message if invalid
|
|
147
|
+
*/
|
|
148
|
+
protected validateDownloadedFile(_buffer: Buffer, _fileInfo: FileInfo): Promise<string | null>;
|
|
149
|
+
/**
|
|
150
|
+
* Validate downloaded file buffer with structured error result.
|
|
151
|
+
* Override for custom post-download validation with detailed errors.
|
|
152
|
+
*
|
|
153
|
+
* @param buffer - Downloaded file content
|
|
154
|
+
* @param fileInfo - Original file information
|
|
155
|
+
* @returns Success result or error result
|
|
156
|
+
*/
|
|
157
|
+
protected validateDownloadedFileWithResult(buffer: Buffer, fileInfo: FileInfo): Promise<OperationResult<void>>;
|
|
158
|
+
/**
|
|
159
|
+
* Build processed result with structured error handling.
|
|
160
|
+
* Override for custom result building that can fail with errors.
|
|
161
|
+
*
|
|
162
|
+
* @param buffer - Downloaded file content
|
|
163
|
+
* @param fileInfo - Original file information
|
|
164
|
+
* @returns Success result with data or error result
|
|
165
|
+
*/
|
|
166
|
+
protected buildProcessedResultWithResult(buffer: Buffer, fileInfo: FileInfo): Promise<FileProcessingResult<T>>;
|
|
167
|
+
/**
|
|
168
|
+
* Get filename with default fallback.
|
|
169
|
+
*
|
|
170
|
+
* @param fileInfo - File information
|
|
171
|
+
* @returns Filename or default if not available
|
|
172
|
+
*/
|
|
173
|
+
protected getFilename(fileInfo: FileInfo): string;
|
|
174
|
+
/**
|
|
175
|
+
* Download file from URL with authentication.
|
|
176
|
+
*
|
|
177
|
+
* @param url - URL to download from
|
|
178
|
+
* @param authHeaders - Optional authentication headers
|
|
179
|
+
* @param timeout - Optional timeout override
|
|
180
|
+
* @returns Downloaded file content as Buffer
|
|
181
|
+
* @throws Error if download fails
|
|
182
|
+
*/
|
|
183
|
+
protected downloadFile(url: string, authHeaders?: Record<string, string>, timeout?: number): Promise<Buffer>;
|
|
184
|
+
/**
|
|
185
|
+
* Download file with retry logic for transient failures.
|
|
186
|
+
*
|
|
187
|
+
* @param fileInfo - File information with URL
|
|
188
|
+
* @param options - Processing options including auth headers and retry config
|
|
189
|
+
* @returns Success result with buffer or error result
|
|
190
|
+
*/
|
|
191
|
+
protected downloadFileWithRetry(fileInfo: FileInfo, options?: ProcessOptions): Promise<OperationResult<Buffer>>;
|
|
192
|
+
/**
|
|
193
|
+
* Validate file type and size with structured error result.
|
|
194
|
+
*
|
|
195
|
+
* @param fileInfo - File information to validate
|
|
196
|
+
* @returns Success result or error result
|
|
197
|
+
*/
|
|
198
|
+
protected validateFileWithResult(fileInfo: FileInfo): OperationResult<void>;
|
|
199
|
+
/**
|
|
200
|
+
* Validate file size against configured maximum.
|
|
201
|
+
*
|
|
202
|
+
* @param sizeBytes - File size in bytes
|
|
203
|
+
* @returns true if size is within limits
|
|
204
|
+
*/
|
|
205
|
+
protected validateFileSize(sizeBytes: number): boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Check if file matches supported MIME types.
|
|
208
|
+
*
|
|
209
|
+
* @param mimetype - MIME type to check
|
|
210
|
+
* @returns true if MIME type is supported
|
|
211
|
+
*/
|
|
212
|
+
protected isSupportedMimeType(mimetype: string): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Check if file matches supported extensions.
|
|
215
|
+
*
|
|
216
|
+
* @param filename - Filename to check
|
|
217
|
+
* @returns true if extension is supported
|
|
218
|
+
*/
|
|
219
|
+
protected isSupportedExtension(filename: string): boolean;
|
|
220
|
+
/**
|
|
221
|
+
* Format file size in MB with 2 decimal places.
|
|
222
|
+
*
|
|
223
|
+
* @param sizeBytes - Size in bytes
|
|
224
|
+
* @returns Formatted size string
|
|
225
|
+
*/
|
|
226
|
+
protected formatSizeMB(sizeBytes: number): string;
|
|
227
|
+
/**
|
|
228
|
+
* Create a structured file processing error.
|
|
229
|
+
*
|
|
230
|
+
* @param code - Error code
|
|
231
|
+
* @param details - Additional error details
|
|
232
|
+
* @param originalError - Original error that caused this
|
|
233
|
+
* @returns Structured error object
|
|
234
|
+
*/
|
|
235
|
+
protected createError(code: FileErrorCode, details?: Record<string, unknown>, originalError?: Error): FileProcessingError;
|
|
236
|
+
/**
|
|
237
|
+
* Classify a download error into appropriate error code.
|
|
238
|
+
*
|
|
239
|
+
* @param error - The error to classify
|
|
240
|
+
* @returns Structured file processing error
|
|
241
|
+
*/
|
|
242
|
+
protected classifyDownloadError(error: Error): FileProcessingError;
|
|
243
|
+
/**
|
|
244
|
+
* Sleep for specified milliseconds.
|
|
245
|
+
*
|
|
246
|
+
* @param ms - Milliseconds to sleep
|
|
247
|
+
*/
|
|
248
|
+
protected sleep(ms: number): Promise<void>;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Get the default text file download timeout.
|
|
252
|
+
*
|
|
253
|
+
* @returns Timeout in milliseconds
|
|
254
|
+
*/
|
|
255
|
+
export declare function getDefaultTextTimeout(): number;
|
|
256
|
+
/**
|
|
257
|
+
* Get the default image download timeout.
|
|
258
|
+
*
|
|
259
|
+
* @returns Timeout in milliseconds
|
|
260
|
+
*/
|
|
261
|
+
export declare function getDefaultImageTimeout(): number;
|
|
262
|
+
/**
|
|
263
|
+
* Get the default text file max size in MB.
|
|
264
|
+
*
|
|
265
|
+
* @returns Max size in megabytes
|
|
266
|
+
*/
|
|
267
|
+
export declare function getDefaultTextMaxSizeMB(): number;
|
|
268
|
+
/**
|
|
269
|
+
* Get the default image max size in MB.
|
|
270
|
+
*
|
|
271
|
+
* @returns Max size in megabytes
|
|
272
|
+
*/
|
|
273
|
+
export declare function getDefaultImageMaxSizeMB(): number;
|