exarch-rs 0.1.1 → 0.1.2

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/index.d.ts DELETED
@@ -1,657 +0,0 @@
1
- /* auto-generated by NAPI-RS */
2
- /* eslint-disable */
3
- /**
4
- * Configuration for archive creation operations.
5
- *
6
- * Controls how archives are created from filesystem sources, including
7
- * security options, compression settings, and file filtering.
8
- *
9
- * # Defaults
10
- *
11
- * | Setting | Default Value |
12
- * |---------|--------------|
13
- * | `compression_level` | 6 (balanced) |
14
- * | `preserve_permissions` | true |
15
- * | `follow_symlinks` | false (secure) |
16
- * | `include_hidden` | false |
17
- * | `max_file_size` | None (no limit) |
18
- * | `exclude_patterns` | `[".git", ".DS_Store", "*.tmp"]` |
19
- */
20
- export declare class CreationConfig {
21
- /** Creates a new `CreationConfig` with secure defaults. */
22
- constructor()
23
- /**
24
- * Creates a `CreationConfig` with secure defaults.
25
- *
26
- * This is equivalent to calling `new CreationConfig()`.
27
- */
28
- static default(): CreationConfig
29
- /**
30
- * Sets the compression level (1-9).
31
- *
32
- * Higher values provide better compression but slower speed.
33
- * Default: 6 (balanced).
34
- *
35
- * # Errors
36
- *
37
- * Returns error if level is not in range 1-9.
38
- */
39
- setCompressionLevel(level: number): this
40
- /**
41
- * Sets whether to preserve file permissions from source.
42
- *
43
- * Default: true.
44
- */
45
- setPreservePermissions(preserve?: boolean | undefined | null): this
46
- /**
47
- * Sets whether to follow symlinks when adding files.
48
- *
49
- * Default: false (store symlinks as symlinks).
50
- *
51
- * Security note: Following symlinks may include unintended files
52
- * from outside the source directory.
53
- */
54
- setFollowSymlinks(follow?: boolean | undefined | null): this
55
- /**
56
- * Sets whether to include hidden files (files starting with '.').
57
- *
58
- * Default: false.
59
- */
60
- setIncludeHidden(include?: boolean | undefined | null): this
61
- /**
62
- * Sets maximum size for a single file in bytes.
63
- *
64
- * Files larger than this limit will be skipped.
65
- *
66
- * # Errors
67
- *
68
- * Returns error if size is negative.
69
- */
70
- setMaxFileSize(size: number): this
71
- /**
72
- * Adds an exclude pattern.
73
- *
74
- * Files matching this pattern will be skipped.
75
- *
76
- * # Errors
77
- *
78
- * Returns error if pattern contains null bytes.
79
- */
80
- addExcludePattern(pattern: string): this
81
- /** Finalizes the configuration (for API consistency). */
82
- build(): this
83
- /** Compression level (1-9). */
84
- get compressionLevel(): number | null
85
- /** Whether to preserve permissions. */
86
- get preservePermissions(): boolean
87
- /** Whether to follow symlinks. */
88
- get followSymlinks(): boolean
89
- /** Whether to include hidden files. */
90
- get includeHidden(): boolean
91
- /** Maximum file size in bytes. */
92
- get maxFileSize(): number | null
93
- /** List of exclude patterns. */
94
- get excludePatterns(): Array<string>
95
- }
96
-
97
- /**
98
- * Security configuration for archive extraction.
99
- *
100
- * All security features default to deny (secure-by-default policy).
101
- *
102
- * # Defaults
103
- *
104
- * | Setting | Default Value |
105
- * |---------|--------------|
106
- * | `max_file_size` | 50 MB (52,428,800 bytes) |
107
- * | `max_total_size` | 500 MB (524,288,000 bytes) |
108
- * | `max_compression_ratio` | 100.0 |
109
- * | `max_file_count` | 10,000 |
110
- * | `max_path_depth` | 32 |
111
- * | `allow_symlinks` | false |
112
- * | `allow_hardlinks` | false |
113
- * | `allow_absolute_paths` | false |
114
- * | `allow_world_writable` | false |
115
- * | `preserve_permissions` | false |
116
- * | `allowed_extensions` | empty (all allowed) |
117
- * | `banned_path_components` | `.git`, `.ssh` |
118
- */
119
- export declare class SecurityConfig {
120
- /** Creates a new `SecurityConfig` with secure defaults. */
121
- constructor()
122
- /**
123
- * Creates a `SecurityConfig` with secure defaults.
124
- *
125
- * This is equivalent to calling `new SecurityConfig()`.
126
- */
127
- static default(): SecurityConfig
128
- /**
129
- * Creates a permissive configuration for trusted archives.
130
- *
131
- * Enables: symlinks, hardlinks, absolute paths, world-writable files.
132
- * Use only for archives from trusted sources.
133
- */
134
- static permissive(): SecurityConfig
135
- /**
136
- * Sets the maximum file size in bytes.
137
- *
138
- * # Errors
139
- *
140
- * Returns error if size is negative.
141
- */
142
- setMaxFileSize(size: number): this
143
- /**
144
- * Sets the maximum total size in bytes.
145
- *
146
- * # Errors
147
- *
148
- * Returns error if size is negative.
149
- */
150
- setMaxTotalSize(size: number): this
151
- /**
152
- * Sets the maximum compression ratio.
153
- *
154
- * # Errors
155
- *
156
- * Returns error if ratio is not a positive finite number.
157
- */
158
- setMaxCompressionRatio(ratio: number): this
159
- /** Sets the maximum file count. */
160
- setMaxFileCount(count: number): this
161
- /** Sets the maximum path depth. */
162
- setMaxPathDepth(depth: number): this
163
- /** Allows or denies symlinks. */
164
- setAllowSymlinks(allow?: boolean | undefined | null): this
165
- /** Allows or denies hardlinks. */
166
- setAllowHardlinks(allow?: boolean | undefined | null): this
167
- /** Allows or denies absolute paths. */
168
- setAllowAbsolutePaths(allow?: boolean | undefined | null): this
169
- /** Allows or denies world-writable files. */
170
- setAllowWorldWritable(allow?: boolean | undefined | null): this
171
- /** Sets whether to preserve permissions from archive. */
172
- setPreservePermissions(preserve?: boolean | undefined | null): this
173
- /**
174
- * Adds an allowed file extension.
175
- *
176
- * # Errors
177
- *
178
- * Returns error if extension exceeds maximum length or contains null
179
- * bytes.
180
- */
181
- addAllowedExtension(ext: string): this
182
- /**
183
- * Adds a banned path component.
184
- *
185
- * # Errors
186
- *
187
- * Returns error if component exceeds maximum length or contains null
188
- * bytes.
189
- */
190
- addBannedComponent(component: string): this
191
- /**
192
- * Finalizes the configuration (for API consistency).
193
- *
194
- * This method is provided for builder pattern consistency but is optional.
195
- * The configuration is always valid and can be used directly.
196
- */
197
- build(): this
198
- /** Checks if a path component is allowed. */
199
- isPathComponentAllowed(component: string): boolean
200
- /** Checks if a file extension is allowed. */
201
- isExtensionAllowed(extension: string): boolean
202
- /** Maximum file size in bytes. */
203
- get maxFileSize(): number
204
- /** Maximum total size in bytes. */
205
- get maxTotalSize(): number
206
- /** Maximum compression ratio. */
207
- get maxCompressionRatio(): number
208
- /** Maximum file count. */
209
- get maxFileCount(): number
210
- /** Maximum path depth. */
211
- get maxPathDepth(): number
212
- /** Whether to preserve permissions from archive. */
213
- get preservePermissions(): boolean
214
- /** Whether symlinks are allowed. */
215
- get allowSymlinks(): boolean
216
- /** Whether hardlinks are allowed. */
217
- get allowHardlinks(): boolean
218
- /** Whether absolute paths are allowed. */
219
- get allowAbsolutePaths(): boolean
220
- /** Whether world-writable files are allowed. */
221
- get allowWorldWritable(): boolean
222
- /**
223
- * List of allowed file extensions.
224
- *
225
- * Note: This getter clones the underlying data. For performance-critical
226
- * code that only needs to count or check membership, use
227
- * `getAllowedExtensionsCount()` or `hasAllowedExtension()` instead.
228
- */
229
- get allowedExtensions(): Array<string>
230
- /** Returns the number of allowed extensions. */
231
- getAllowedExtensionsCount(): number
232
- /** Checks if a specific extension is in the allowed list. */
233
- hasAllowedExtension(ext: string): boolean
234
- /**
235
- * List of banned path components.
236
- *
237
- * Note: This getter clones the underlying data. For performance-critical
238
- * code that only needs to count or check membership, use
239
- * `getBannedPathComponentsCount()` or `hasBannedPathComponent()` instead.
240
- */
241
- get bannedPathComponents(): Array<string>
242
- /** Returns the number of banned path components. */
243
- getBannedPathComponentsCount(): number
244
- /** Checks if a specific component is in the banned list. */
245
- hasBannedPathComponent(component: string): boolean
246
- }
247
-
248
- /**
249
- * Single entry in archive manifest.
250
- *
251
- * Contains metadata about a file, directory, symlink, or hardlink
252
- * without extracting it to disk.
253
- */
254
- export interface ArchiveEntry {
255
- /** Entry path (relative, as stored in archive). */
256
- path: string
257
- /** Entry type ("File", "Directory", "Symlink", "Hardlink"). */
258
- entryType: string
259
- /** Uncompressed size in bytes (0 for directories). */
260
- size: number
261
- /** Compressed size in bytes (if available, ZIP only). */
262
- compressedSize?: number
263
- /** File permissions (Unix mode). */
264
- mode?: number
265
- /** Modification time (milliseconds since Unix epoch). */
266
- modified?: number
267
- /** Symlink target (if `entry_type` is "Symlink"). */
268
- symlinkTarget?: string
269
- /** Hardlink target (if `entry_type` is "Hardlink"). */
270
- hardlinkTarget?: string
271
- }
272
-
273
- /**
274
- * Complete manifest of archive contents.
275
- *
276
- * Generated by `listArchive()`, contains metadata about all entries
277
- * without extracting them to disk.
278
- */
279
- export interface ArchiveManifest {
280
- /** All entries in the archive (files, dirs, symlinks, hardlinks). */
281
- entries: Array<ArchiveEntry>
282
- /** Total number of entries. */
283
- totalEntries: number
284
- /** Total uncompressed size in bytes. */
285
- totalSize: number
286
- /** Archive format (e.g., `TarGz`, `Zip`). */
287
- format: string
288
- }
289
-
290
- /**
291
- * Create an archive from source files and directories (async).
292
- *
293
- * # Arguments
294
- *
295
- * * `output_path` - Path to output archive file
296
- * * `sources` - Array of source files/directories to include
297
- * * `config` - Optional `CreationConfig` (uses defaults if omitted)
298
- *
299
- * # Returns
300
- *
301
- * Promise resolving to `CreationReport` with creation statistics
302
- *
303
- * # Errors
304
- *
305
- * Returns error if path validation fails, archive creation fails, or I/O
306
- * errors occur.
307
- *
308
- * # Examples
309
- *
310
- * ```javascript
311
- * // Use defaults
312
- * const report = await createArchive('output.tar.gz', ['source_dir/']);
313
- * console.log(`Created archive with ${report.filesAdded} files`);
314
- *
315
- * // Customize configuration
316
- * const config = new CreationConfig().compressionLevel(9);
317
- * const report = await createArchive('output.tar.gz', ['src/'], config);
318
- * ```
319
- */
320
- export declare function createArchive(outputPath: string, sources: Array<string>, config?: CreationConfig | undefined | null): Promise<CreationReport>
321
-
322
- /**
323
- * Create an archive from source files and directories (sync).
324
- *
325
- * Synchronous version of `createArchive`. Blocks the event loop until
326
- * creation completes. Prefer the async version for most use cases.
327
- *
328
- * # Arguments
329
- *
330
- * * `output_path` - Path to output archive file
331
- * * `sources` - Array of source files/directories to include
332
- * * `config` - Optional `CreationConfig` (uses defaults if omitted)
333
- *
334
- * # Returns
335
- *
336
- * `CreationReport` with creation statistics
337
- *
338
- * # Errors
339
- *
340
- * Returns error if path validation fails, archive creation fails, or I/O
341
- * errors occur.
342
- *
343
- * # Examples
344
- *
345
- * ```javascript
346
- * // Use defaults
347
- * const report = createArchiveSync('output.tar.gz', ['source_dir/']);
348
- * console.log(`Created archive with ${report.filesAdded} files`);
349
- * ```
350
- */
351
- export declare function createArchiveSync(outputPath: string, sources: Array<string>, config?: CreationConfig | undefined | null): CreationReport
352
-
353
- /**
354
- * Report of an archive creation operation.
355
- *
356
- * Contains statistics and metadata about the creation process.
357
- */
358
- export interface CreationReport {
359
- /** Number of files added to the archive. */
360
- filesAdded: number
361
- /** Number of directories added to the archive. */
362
- directoriesAdded: number
363
- /** Number of symlinks added to the archive. */
364
- symlinksAdded: number
365
- /** Total bytes written to the archive (uncompressed). */
366
- bytesWritten: number
367
- /** Total bytes in the final archive (compressed). */
368
- bytesCompressed: number
369
- /** Duration of the creation operation in milliseconds. */
370
- durationMs: number
371
- /** Number of files skipped (due to filters or errors). */
372
- filesSkipped: number
373
- /** Warnings generated during creation. */
374
- warnings: Array<string>
375
- }
376
-
377
- /**
378
- * Extract an archive to the specified directory (async).
379
- *
380
- * This function provides secure archive extraction with configurable
381
- * security policies. By default, it uses a restrictive security
382
- * configuration that blocks symlinks, hardlinks, absolute paths, and
383
- * enforces resource quotas.
384
- *
385
- * # Security Considerations
386
- *
387
- * ## Thread Safety and TOCTOU
388
- *
389
- * The extraction runs on a libuv thread pool worker thread. This creates
390
- * a Time-Of-Check-Time-Of-Use (TOCTOU) race condition where the archive
391
- * file could be modified between validation and extraction. This is an
392
- * accepted tradeoff for async performance. For untrusted archives, ensure
393
- * exclusive access to the archive file during extraction.
394
- *
395
- * ## Input Validation
396
- *
397
- * - Paths containing null bytes are rejected (security)
398
- * - Paths exceeding 4096 bytes are rejected (`DoS` prevention)
399
- * - All validation happens at the Node.js boundary before calling core library
400
- *
401
- * # Arguments
402
- *
403
- * * `archive_path` - Path to the archive file
404
- * * `output_dir` - Directory where files will be extracted
405
- * * `config` - Optional `SecurityConfig` (uses secure defaults if omitted)
406
- *
407
- * # Returns
408
- *
409
- * Promise resolving to `ExtractionReport` with extraction statistics
410
- *
411
- * # Errors
412
- *
413
- * Returns error for security violations or I/O errors. Error messages are
414
- * prefixed with error codes for discrimination in JavaScript:
415
- *
416
- * - `PATH_TRAVERSAL`: Path traversal attempt detected
417
- * - `SYMLINK_ESCAPE`: Symlink points outside extraction directory
418
- * - `HARDLINK_ESCAPE`: Hardlink target outside extraction directory
419
- * - `ZIP_BOMB`: Potential zip bomb detected
420
- * - `INVALID_PERMISSIONS`: File permissions are invalid or unsafe
421
- * - `QUOTA_EXCEEDED`: Resource quota exceeded
422
- * - `SECURITY_VIOLATION`: Security policy violation
423
- * - `UNSUPPORTED_FORMAT`: Archive format not supported
424
- * - `INVALID_ARCHIVE`: Archive is corrupted
425
- * - `IO_ERROR`: I/O operation failed
426
- *
427
- * # Examples
428
- *
429
- * ```javascript
430
- * // Use secure defaults
431
- * const report = await extractArchive('archive.tar.gz', '/tmp/output');
432
- * console.log(`Extracted ${report.filesExtracted} files`);
433
- *
434
- * // Customize security settings
435
- * const config = new SecurityConfig().maxFileSize(100 * 1024 * 1024);
436
- * const report = await extractArchive('archive.tar.gz', '/tmp/output', config);
437
- * ```
438
- */
439
- export declare function extractArchive(archivePath: string, outputDir: string, config?: SecurityConfig | undefined | null): Promise<ExtractionReport>
440
-
441
- /**
442
- * Extract an archive to the specified directory (sync).
443
- *
444
- * Synchronous version of `extractArchive`. Blocks the event loop until
445
- * extraction completes. Prefer the async version for most use cases.
446
- *
447
- * # Arguments
448
- *
449
- * * `archive_path` - Path to the archive file
450
- * * `output_dir` - Directory where files will be extracted
451
- * * `config` - Optional `SecurityConfig` (uses secure defaults if omitted)
452
- *
453
- * # Returns
454
- *
455
- * `ExtractionReport` with extraction statistics
456
- *
457
- * # Errors
458
- *
459
- * Returns error for security violations or I/O errors. See `extract_archive`
460
- * for error code documentation.
461
- *
462
- * # Examples
463
- *
464
- * ```javascript
465
- * // Use secure defaults
466
- * const report = extractArchiveSync('archive.tar.gz', '/tmp/output');
467
- * console.log(`Extracted ${report.filesExtracted} files`);
468
- *
469
- * // Customize security settings
470
- * const config = new SecurityConfig().maxFileSize(100 * 1024 * 1024);
471
- * const report = extractArchiveSync('archive.tar.gz', '/tmp/output', config);
472
- * ```
473
- */
474
- export declare function extractArchiveSync(archivePath: string, outputDir: string, config?: SecurityConfig | undefined | null): ExtractionReport
475
-
476
- /**
477
- * Report of an archive extraction operation.
478
- *
479
- * Contains statistics and metadata about the extraction process.
480
- */
481
- export interface ExtractionReport {
482
- /** Number of files successfully extracted. */
483
- filesExtracted: number
484
- /** Number of directories created. */
485
- directoriesCreated: number
486
- /** Number of symlinks created. */
487
- symlinksCreated: number
488
- /** Total bytes written to disk. */
489
- bytesWritten: number
490
- /** Extraction duration in milliseconds. */
491
- durationMs: number
492
- /** Number of files skipped due to security checks. */
493
- filesSkipped: number
494
- /** List of warning messages. */
495
- warnings: Array<string>
496
- }
497
-
498
- /**
499
- * List archive contents without extracting (async).
500
- *
501
- * # Arguments
502
- *
503
- * * `archive_path` - Path to archive file
504
- * * `config` - Optional `SecurityConfig` (uses secure defaults if omitted)
505
- *
506
- * # Returns
507
- *
508
- * Promise resolving to `ArchiveManifest` with entry metadata
509
- *
510
- * # Errors
511
- *
512
- * Returns error if path validation fails, archive is invalid, or I/O errors
513
- * occur.
514
- *
515
- * # Examples
516
- *
517
- * ```javascript
518
- * const manifest = await listArchive('archive.tar.gz');
519
- * for (const entry of manifest.entries) {
520
- * console.log(`${entry.path}: ${entry.size} bytes`);
521
- * }
522
- * ```
523
- */
524
- export declare function listArchive(archivePath: string, config?: SecurityConfig | undefined | null): Promise<ArchiveManifest>
525
-
526
- /**
527
- * List archive contents without extracting (sync).
528
- *
529
- * Synchronous version of `listArchive`. Blocks the event loop until
530
- * listing completes. Prefer the async version for most use cases.
531
- *
532
- * # Arguments
533
- *
534
- * * `archive_path` - Path to archive file
535
- * * `config` - Optional `SecurityConfig` (uses secure defaults if omitted)
536
- *
537
- * # Returns
538
- *
539
- * `ArchiveManifest` with entry metadata
540
- *
541
- * # Errors
542
- *
543
- * Returns error if path validation fails, archive is invalid, or I/O errors
544
- * occur.
545
- *
546
- * # Examples
547
- *
548
- * ```javascript
549
- * const manifest = listArchiveSync('archive.tar.gz');
550
- * for (const entry of manifest.entries) {
551
- * console.log(`${entry.path}: ${entry.size} bytes`);
552
- * }
553
- * ```
554
- */
555
- export declare function listArchiveSync(archivePath: string, config?: SecurityConfig | undefined | null): ArchiveManifest
556
-
557
- /** Single verification issue. */
558
- export interface VerificationIssue {
559
- /** Issue severity level ("Critical", "High", "Medium", "Low", "Info"). */
560
- severity: string
561
- /** Issue category (`PathTraversal`, `SymlinkEscape`, etc.). */
562
- category: string
563
- /** Entry path that triggered issue (if applicable). */
564
- entryPath?: string
565
- /** Human-readable description. */
566
- message: string
567
- /** Optional context (compression ratio, target path, etc.). */
568
- context?: string
569
- }
570
-
571
- /**
572
- * Result of archive verification.
573
- *
574
- * Generated by `verifyArchive()`, contains security and integrity checks
575
- * performed without extracting files to disk.
576
- */
577
- export interface VerificationReport {
578
- /** Overall verification status ("Pass", "Fail", "Warning"). */
579
- status: string
580
- /** Integrity check result ("Pass", "Fail", "Warning", "Skipped"). */
581
- integrityStatus: string
582
- /** Security check result ("Pass", "Fail", "Warning", "Skipped"). */
583
- securityStatus: string
584
- /** List of all issues found (sorted by severity). */
585
- issues: Array<VerificationIssue>
586
- /** Total entries scanned. */
587
- totalEntries: number
588
- /** Entries flagged as suspicious. */
589
- suspiciousEntries: number
590
- /** Total uncompressed size. */
591
- totalSize: number
592
- /** Archive format (e.g., `TarGz`, `Zip`). */
593
- format: string
594
- }
595
-
596
- /**
597
- * Verify archive integrity and security (async).
598
- *
599
- * # Arguments
600
- *
601
- * * `archive_path` - Path to archive file
602
- * * `config` - Optional `SecurityConfig` (uses secure defaults if omitted)
603
- *
604
- * # Returns
605
- *
606
- * Promise resolving to `VerificationReport` with validation results
607
- *
608
- * # Errors
609
- *
610
- * Returns error if path validation fails, archive is invalid, or I/O errors
611
- * occur.
612
- *
613
- * # Examples
614
- *
615
- * ```javascript
616
- * const report = await verifyArchive('archive.tar.gz');
617
- * if (report.status === 'PASS') {
618
- * console.log('Archive is safe to extract');
619
- * } else {
620
- * for (const issue of report.issues) {
621
- * console.log(`[${issue.severity}] ${issue.message}`);
622
- * }
623
- * }
624
- * ```
625
- */
626
- export declare function verifyArchive(archivePath: string, config?: SecurityConfig | undefined | null): Promise<VerificationReport>
627
-
628
- /**
629
- * Verify archive integrity and security (sync).
630
- *
631
- * Synchronous version of `verifyArchive`. Blocks the event loop until
632
- * verification completes. Prefer the async version for most use cases.
633
- *
634
- * # Arguments
635
- *
636
- * * `archive_path` - Path to archive file
637
- * * `config` - Optional `SecurityConfig` (uses secure defaults if omitted)
638
- *
639
- * # Returns
640
- *
641
- * `VerificationReport` with validation results
642
- *
643
- * # Errors
644
- *
645
- * Returns error if path validation fails, archive is invalid, or I/O errors
646
- * occur.
647
- *
648
- * # Examples
649
- *
650
- * ```javascript
651
- * const report = verifyArchiveSync('archive.tar.gz');
652
- * if (report.status === 'PASS') {
653
- * console.log('Archive is safe to extract');
654
- * }
655
- * ```
656
- */
657
- export declare function verifyArchiveSync(archivePath: string, config?: SecurityConfig | undefined | null): VerificationReport