@plyaz/types 1.15.20 → 1.16.1

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 (41) hide show
  1. package/dist/api/aws/index.d.ts +5 -0
  2. package/dist/api/aws/signature.d.ts +42 -0
  3. package/dist/api/endpoints/cdn/endpoints.d.ts +57 -0
  4. package/dist/api/endpoints/cdn/index.d.ts +6 -0
  5. package/dist/api/endpoints/cdn/types.d.ts +151 -0
  6. package/dist/api/endpoints/index.d.ts +2 -0
  7. package/dist/api/endpoints/types.d.ts +3 -1
  8. package/dist/api/endpoints/virustotal/endpoints.d.ts +37 -0
  9. package/dist/api/endpoints/virustotal/index.d.ts +6 -0
  10. package/dist/api/endpoints/virustotal/types.d.ts +202 -0
  11. package/dist/api/index.cjs +1317 -1
  12. package/dist/api/index.cjs.map +1 -1
  13. package/dist/api/index.d.ts +3 -0
  14. package/dist/api/index.js +1317 -1
  15. package/dist/api/index.js.map +1 -1
  16. package/dist/core/idempotency.d.ts +48 -0
  17. package/dist/core/index.d.ts +1 -0
  18. package/dist/errors/codes.d.ts +296 -0
  19. package/dist/errors/enums.d.ts +10 -0
  20. package/dist/errors/index.cjs +1482 -1
  21. package/dist/errors/index.cjs.map +1 -1
  22. package/dist/errors/index.d.ts +1 -0
  23. package/dist/errors/index.js +1482 -2
  24. package/dist/errors/index.js.map +1 -1
  25. package/dist/errors/validation.d.ts +71 -0
  26. package/dist/index.cjs +2268 -132
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.ts +11 -0
  29. package/dist/index.js +2227 -133
  30. package/dist/index.js.map +1 -1
  31. package/dist/logger/enums.d.ts +10 -0
  32. package/dist/notifications/types.d.ts +1 -2
  33. package/dist/storage/compliance.d.ts +247 -0
  34. package/dist/storage/enums.d.ts +527 -0
  35. package/dist/storage/event-handler-mapping.d.ts +69 -0
  36. package/dist/storage/index.d.ts +13 -0
  37. package/dist/storage/interfaces.d.ts +2242 -0
  38. package/dist/storage/plugins.d.ts +1056 -0
  39. package/dist/storage/schemas.d.ts +224 -0
  40. package/dist/storage/webhooks.d.ts +340 -0
  41. package/package.json +6 -1
@@ -0,0 +1,2242 @@
1
+ /**
2
+ * Storage Package Interfaces
3
+ * @module @plyaz/types/storage
4
+ */
5
+ import type { LoggerInterface } from '../logger/types';
6
+ import type { StorageErrorCode } from '../errors/codes';
7
+ import type { ADAPTER_HEALTH_STATUS, ENTITY_TYPE, FILE_ACCESS_LEVEL, FILE_CATEGORY, OUTPUT_FORMAT, PATH_GENERATION_STRATEGY, RETRY_STRATEGY, STORAGE_ADAPTER_TYPE, STORAGE_DEVICE_TYPE, STORAGE_EVENT_TYPE, STORAGE_QUEUE_PRIORITY, STORAGE_RENDERER_TYPE, TEMPLATE_OUTPUT_FORMAT, UPLOAD_STATUS, DOCUMENT_TYPE, MEDIA_ENTITY, STORAGE_VISIBILITY, STORAGE_ENVIRONMENT, BUSINESS_MODEL, ORGANIZATION_TIER, BUCKET_PURPOSE, PATH_STRATEGY } from './enums';
8
+ import type { StorageSoftDeleteMetadata, StorageDeleteComplianceOptions, StorageComplianceConfig } from './compliance';
9
+ import type { PluginRegistryConfig, StorageKnownPluginName, StoragePlugin } from './plugins';
10
+ import type { StorageBaseWebhookAdapterConfig, StorageWebhookAdapter, StorageWebhookManagerConfig } from './webhooks';
11
+ /**
12
+ * Simplified API client configuration for storage adapters
13
+ * Avoids direct dependency on full ApiConfig to prevent version conflicts
14
+ */
15
+ export type StorageApiClientConfig = {
16
+ /** Base URL for the API (required) */
17
+ baseURL: string;
18
+ } & Partial<Record<string, unknown>>;
19
+ /**
20
+ * Generic Result type for storage operations
21
+ * Type-safe error handling without try-catch in happy path
22
+ */
23
+ export type StorageResult<T, E = Error> = {
24
+ success: true;
25
+ data: T;
26
+ } | {
27
+ success: false;
28
+ error: E;
29
+ };
30
+ /**
31
+ * Event callback type for storage events
32
+ */
33
+ export type StorageEventCallback = (payload: StorageEventPayload) => void | Promise<void>;
34
+ /**
35
+ * Hash algorithm type for path generation
36
+ * Note: MD5 is included ONLY for non-security uses (deduplication, checksums).
37
+ * For security/compliance, use SHA-256 or higher.
38
+ */
39
+ export type StoragePathHashAlgorithm = 'sha256' | 'sha384' | 'sha512' | 'md5';
40
+ /**
41
+ * Hash algorithm type for signed URL generation
42
+ * Note: MD5 is NOT included as it's cryptographically broken and not compliant
43
+ */
44
+ export type StorageHashAlgorithm = 'sha256' | 'sha384' | 'sha512';
45
+ /**
46
+ * Signed URL permission type
47
+ */
48
+ export type StorageSignedUrlPermission = 'read' | 'write' | 'delete';
49
+ /**
50
+ * Adapter capability interface
51
+ * Defines what purposes an adapter can handle
52
+ */
53
+ export interface StorageAdapterCapability {
54
+ /** Adapter name */
55
+ name: string;
56
+ /** Bucket purposes this adapter can handle */
57
+ supportedPurposes: BUCKET_PURPOSE[];
58
+ /** Priority for this adapter (higher = preferred) */
59
+ priority?: number;
60
+ }
61
+ /**
62
+ * File metadata interface
63
+ */
64
+ export interface FileMetadata {
65
+ /** Unique identifier for the file */
66
+ fileId: string;
67
+ /** Original filename */
68
+ filename: string;
69
+ /** MIME type of the file */
70
+ mimeType: string;
71
+ /** File size in bytes */
72
+ size: number;
73
+ /** File category */
74
+ category: FILE_CATEGORY;
75
+ /** Entity type that owns this file */
76
+ entityType: ENTITY_TYPE;
77
+ /** Entity ID that owns this file */
78
+ entityId: string;
79
+ /** Access level */
80
+ accessLevel: FILE_ACCESS_LEVEL;
81
+ /** Storage path */
82
+ path: string;
83
+ /** Public URL (if applicable) */
84
+ url?: string;
85
+ /** Upload status */
86
+ status: UPLOAD_STATUS;
87
+ /** File extension */
88
+ extension?: string;
89
+ /** File hash (for deduplication) */
90
+ hash?: string;
91
+ /** Custom metadata */
92
+ customMetadata?: Record<string, unknown>;
93
+ /** Extracted metadata (dimensions, duration, etc.) */
94
+ extractedMetadata?: {
95
+ width?: number;
96
+ height?: number;
97
+ duration?: number;
98
+ format?: string;
99
+ codec?: string;
100
+ bitrate?: number;
101
+ [key: string]: unknown;
102
+ };
103
+ /** Upload timestamp */
104
+ uploadedAt: Date;
105
+ /** Uploaded by user ID */
106
+ uploadedBy?: string;
107
+ /** Expiry timestamp (for temporary files) */
108
+ expiresAt?: Date;
109
+ /** Whether the file is immutable */
110
+ immutable?: boolean;
111
+ /** Retention policy ID */
112
+ retentionPolicyId?: string;
113
+ /** Tags for categorization */
114
+ tags?: string[];
115
+ /** Storage adapter name that stored this file */
116
+ adapter?: string;
117
+ /** Bucket name where file is stored */
118
+ bucket?: string;
119
+ /** Bucket purpose (for routing) */
120
+ bucketPurpose?: BUCKET_PURPOSE;
121
+ }
122
+ /**
123
+ * Upload parameters
124
+ */
125
+ export interface UploadParams {
126
+ /** File buffer or stream (optional if templateId is provided) */
127
+ file?: globalThis.Buffer | globalThis.NodeJS.ReadableStream;
128
+ /** Original filename */
129
+ filename?: string;
130
+ /** MIME type (optional if templateId is provided) */
131
+ mimeType?: string;
132
+ /** File category */
133
+ category: FILE_CATEGORY;
134
+ /** Entity type */
135
+ entityType: ENTITY_TYPE;
136
+ /** Entity ID */
137
+ entityId: string;
138
+ /** Access level */
139
+ accessLevel?: FILE_ACCESS_LEVEL;
140
+ /** Custom metadata */
141
+ customMetadata?: Record<string, unknown>;
142
+ /** Whether to extract metadata */
143
+ extractMetadata?: boolean;
144
+ /** Whether to scan for viruses */
145
+ virusScan?: boolean;
146
+ /** Whether to process media (resize, transcode, etc.) */
147
+ processMedia?: boolean;
148
+ /** Media processing options */
149
+ mediaOptions?: MediaProcessingOptions;
150
+ /** Skip specific plugins by name for this operation (e.g., ['virus-scanner', 'cdn-invalidator']) */
151
+ skipPlugins?: readonly StorageKnownPluginName[];
152
+ /** Only run these specific plugins for this operation (e.g., ['metadata-enricher']) */
153
+ onlyPlugins?: readonly StorageKnownPluginName[];
154
+ /** Custom path (overrides path generation) */
155
+ customPath?: string;
156
+ /** Tags */
157
+ tags?: string[];
158
+ /** TTL in seconds (for temporary files) */
159
+ ttl?: number;
160
+ /** Whether the file is immutable */
161
+ immutable?: boolean;
162
+ /** Retention policy ID */
163
+ retentionPolicyId?: string;
164
+ /** Tenant/organization slug (for multi-tenancy) */
165
+ tenant?: string;
166
+ /** Document type (for compliance documents in R2) */
167
+ documentType?: DOCUMENT_TYPE;
168
+ /** Document ID (for compliance documents) */
169
+ documentId?: string;
170
+ /** Document slug (for human-readable names) */
171
+ documentSlug?: string;
172
+ /** Media entity type (for media files in Supabase) */
173
+ mediaEntity?: MEDIA_ENTITY;
174
+ /** Visibility level (for Supabase media) */
175
+ visibility?: STORAGE_VISIBILITY;
176
+ /** Storage environment (prod/stg/dev) */
177
+ environment?: STORAGE_ENVIRONMENT;
178
+ /** Region code (e.g., 'weur', 'use1') */
179
+ region?: string;
180
+ /** Business model (B2B/B2C/B2B2C/Internal) */
181
+ businessModel?: BUSINESS_MODEL;
182
+ /** Organization tier (for dedicated resources) */
183
+ organizationTier?: ORGANIZATION_TIER;
184
+ /** Organization ID (for org-specific isolation) */
185
+ organizationId?: string;
186
+ /** Variant name (for media: original, thumb, sm, md, lg, etc.) */
187
+ variantName?: string;
188
+ /** Bucket selection override (use specific bucket) */
189
+ bucketOverride?: string;
190
+ /** Adapter selection override (use specific adapter) */
191
+ adapterOverride?: string;
192
+ /** Locale for document generation (overrides service default) */
193
+ locale?: string;
194
+ /** Template data for document generation */
195
+ templateData?: Record<string, unknown>;
196
+ /** Template ID for document generation (e.g., 'invoices/standard-invoice') */
197
+ templateId?: string;
198
+ /** Output format (pdf, excel, word, png, etc.) - defaults to pdf */
199
+ outputFormat?: string;
200
+ /** Specific renderer to use by name (optional, registry selects best if not specified) */
201
+ rendererName?: string;
202
+ /** PDF render options (when outputFormat === 'pdf') */
203
+ pdfOptions?: PDFRenderOptions;
204
+ /** Excel render options (when outputFormat === 'excel') */
205
+ excelOptions?: StorageExcelRenderOptions;
206
+ /** Word render options (when outputFormat === 'word') */
207
+ wordOptions?: StorageWordRenderOptions;
208
+ /** Use queue for this operation (requires queue to be enabled in service config) */
209
+ useQueue?: boolean;
210
+ /** Queue priority (only used if useQueue is true) */
211
+ queuePriority?: STORAGE_QUEUE_PRIORITY;
212
+ /** Queue operation metadata (only used if useQueue is true) */
213
+ queueMetadata?: Record<string, unknown>;
214
+ /** Custom variants to generate (e.g., ['thumbnail', 'mobile', 'desktop'] or full config objects) */
215
+ variants?: string[] | StorageVariantConfig[];
216
+ /** Preset name(s) to use (e.g., 'profile-picture' or ['profile-picture', 'social-share']) */
217
+ presets?: string | string[];
218
+ /** Target device type for optimization (auto-detected if not specified) */
219
+ device?: string;
220
+ /** Generate variants for all devices (ignores device parameter, generates all optimized variants) */
221
+ allDevices?: boolean;
222
+ /** Progress callback for chunked/multipart uploads */
223
+ onProgress?: (progress: UploadProgressEvent) => void;
224
+ /** AbortSignal to cancel the upload */
225
+ abortSignal?: AbortSignal;
226
+ }
227
+ /**
228
+ * Upload result
229
+ */
230
+ export interface UploadResult {
231
+ /** File metadata */
232
+ metadata: FileMetadata;
233
+ /** Public URL (if applicable) */
234
+ url?: string;
235
+ /** Signed URL (for private files) */
236
+ signedUrl?: string;
237
+ /** Generated variants (device-optimized, thumbnails, resized versions, etc.) */
238
+ variants?: Record<string, StorageResolvedVariant>;
239
+ /** Legacy variants array (deprecated, use variants object instead) */
240
+ variantsArray?: Array<{
241
+ type: string;
242
+ url: string;
243
+ metadata: Partial<FileMetadata>;
244
+ }>;
245
+ /** Warnings (e.g., virus scan skipped) */
246
+ warnings?: string[];
247
+ /** Applied presets */
248
+ appliedPresets?: string[];
249
+ /** Target device (if specified) */
250
+ targetDevice?: string;
251
+ }
252
+ /**
253
+ * Download parameters
254
+ */
255
+ export interface DownloadParams {
256
+ /** File ID or path */
257
+ fileId: string;
258
+ /** Whether to return a signed URL instead of the file */
259
+ signedUrl?: boolean;
260
+ /** Signed URL expiry in seconds */
261
+ signedUrlExpiry?: number;
262
+ /** Download filename (for Content-Disposition header) */
263
+ downloadFilename?: string;
264
+ /** Optional: Bucket name (if known, skips metadata lookup) */
265
+ bucket?: string;
266
+ /** Optional: Adapter name (if known, skips routing) */
267
+ adapter?: string;
268
+ /** Optional: Bucket purpose (for routing) */
269
+ bucketPurpose?: BUCKET_PURPOSE;
270
+ }
271
+ /**
272
+ * Download result
273
+ */
274
+ export interface DownloadResult {
275
+ /** File buffer (if signedUrl is false) */
276
+ file?: globalThis.Buffer;
277
+ /** Signed URL (if signedUrl is true) */
278
+ url?: string;
279
+ /** File metadata */
280
+ metadata: FileMetadata;
281
+ }
282
+ /**
283
+ * Delete parameters
284
+ */
285
+ export interface DeleteParams {
286
+ /** File ID or path */
287
+ fileId: string;
288
+ /** Whether to permanently delete (bypass soft delete) */
289
+ permanent?: boolean;
290
+ /** Delete reason (for audit logs) */
291
+ reason?: string;
292
+ /** Soft delete metadata (for tracking soft-deleted files) */
293
+ softDeleteMetadata?: StorageSoftDeleteMetadata;
294
+ /** Compliance options for this delete operation */
295
+ complianceOptions?: StorageDeleteComplianceOptions;
296
+ /** Optional: Bucket name (if known, skips metadata lookup) */
297
+ bucket?: string;
298
+ /** Optional: Adapter name (if known, skips routing) */
299
+ adapter?: string;
300
+ /** Optional: Bucket purpose (for routing) */
301
+ bucketPurpose?: BUCKET_PURPOSE;
302
+ /** Custom metadata for plugins and tracking */
303
+ customMetadata?: Record<string, unknown>;
304
+ /** Skip specific plugins by name for this operation */
305
+ skipPlugins?: readonly StorageKnownPluginName[];
306
+ /** Only run these specific plugins for this operation */
307
+ onlyPlugins?: readonly StorageKnownPluginName[];
308
+ }
309
+ /**
310
+ * File delete result
311
+ */
312
+ export interface FileDeleteResult {
313
+ /** Whether the delete was successful */
314
+ success: boolean;
315
+ /** File metadata */
316
+ metadata?: FileMetadata;
317
+ /** Deletion timestamp */
318
+ deletedAt: Date;
319
+ /** Soft delete metadata (if soft deleted) */
320
+ softDelete?: {
321
+ deletedBy: string;
322
+ deletedAt: Date;
323
+ reason?: string;
324
+ gracePeriodDays?: number;
325
+ gracePeriodUntil?: Date;
326
+ canRestore: boolean;
327
+ };
328
+ }
329
+ /**
330
+ * Media processing options
331
+ */
332
+ export interface MediaProcessingOptions {
333
+ /** Image resize options */
334
+ resize?: {
335
+ width?: number;
336
+ height?: number;
337
+ fit?: 'cover' | 'contain' | 'fill' | 'inside' | 'outside';
338
+ position?: 'center' | 'top' | 'bottom' | 'left' | 'right';
339
+ };
340
+ /** Image format conversion */
341
+ format?: 'jpeg' | 'png' | 'webp' | 'avif';
342
+ /** Image quality (1-100) */
343
+ quality?: number;
344
+ /** Video transcode options */
345
+ transcode?: {
346
+ codec?: string;
347
+ resolution?: string;
348
+ bitrate?: number;
349
+ };
350
+ /** Generate thumbnail */
351
+ thumbnail?: boolean;
352
+ /** Thumbnail size */
353
+ thumbnailSize?: {
354
+ width: number;
355
+ height: number;
356
+ };
357
+ /** Generate variants */
358
+ variants?: Array<{
359
+ name: string;
360
+ width?: number;
361
+ height?: number;
362
+ format?: string;
363
+ quality?: number;
364
+ }>;
365
+ }
366
+ /**
367
+ * Comprehensive variant configuration for images and videos
368
+ * Supports device-aware optimization and multiple formats
369
+ */
370
+ export interface StorageVariantConfig {
371
+ /** Variant identifier (use StorageVariantName enum values) */
372
+ name: string;
373
+ /** Target width in pixels */
374
+ width?: number;
375
+ /** Target height in pixels */
376
+ height?: number;
377
+ /** Output format (webp, jpeg, png, avif for images; mp4, webm for videos) */
378
+ format?: 'webp' | 'jpeg' | 'png' | 'avif' | 'mp4' | 'webm' | 'hls';
379
+ /** Quality (1-100, default: 85 for images) */
380
+ quality?: number;
381
+ /** Aspect ratio ('16:9', '1:1', '4:3', 'preserve') */
382
+ aspectRatio?: string | 'preserve';
383
+ /** Video codec (h264, h265, vp9, av1) */
384
+ codec?: string;
385
+ /** Video bitrate (e.g., '1000k', '2500k') */
386
+ bitrate?: string;
387
+ /** Target device types for this variant (use StorageDeviceType enum values) */
388
+ devices?: STORAGE_DEVICE_TYPE[];
389
+ /** Fit mode for resizing (cover, contain, fill, inside, outside) */
390
+ fit?: 'cover' | 'contain' | 'fill' | 'inside' | 'outside';
391
+ /** Position for cropping (center, top, bottom, left, right) */
392
+ position?: 'center' | 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
393
+ /** Enable progressive rendering (for JPEG) */
394
+ progressive?: boolean;
395
+ /** Optimization level (0-100, higher = more compression time but smaller files) */
396
+ optimizationLevel?: number;
397
+ /** Maximum file size in bytes (will adjust quality to meet target) */
398
+ maxFileSize?: number;
399
+ /** Custom metadata for this variant */
400
+ metadata?: Record<string, unknown>;
401
+ }
402
+ /**
403
+ * Preset configuration for reusable transformation sets
404
+ * Presets bundle multiple variants with common settings
405
+ */
406
+ export interface StoragePresetConfig {
407
+ /** Preset identifier (e.g., 'profile-picture', 'post-image', 'hero-banner') */
408
+ name: string;
409
+ /** Description of this preset */
410
+ description?: string;
411
+ /** Variants included in this preset (use StorageVariantName enum values or full config) */
412
+ variants: string[] | StorageVariantConfig[];
413
+ /** Default format for all variants (can be overridden per variant) */
414
+ format?: 'webp' | 'jpeg' | 'png' | 'avif' | 'mp4' | 'webm' | 'hls';
415
+ /** Default quality for all variants (can be overridden per variant) */
416
+ quality?: number;
417
+ /** Default aspect ratio for all variants */
418
+ aspectRatio?: string | 'preserve';
419
+ /** Default codec for video variants */
420
+ codec?: string;
421
+ /** File categories this preset applies to */
422
+ categories?: FILE_CATEGORY[];
423
+ /** Device types this preset optimizes for (use StorageDeviceType enum values) */
424
+ devices?: STORAGE_DEVICE_TYPE[];
425
+ /** Priority (lower = higher priority when multiple presets match) */
426
+ priority?: number;
427
+ /** Whether this preset is enabled (default: true) */
428
+ enabled?: boolean;
429
+ /** Custom metadata for this preset */
430
+ metadata?: Record<string, unknown>;
431
+ }
432
+ /**
433
+ * Device-aware variant selection result
434
+ * Contains the resolved variant URL and metadata
435
+ */
436
+ export interface StorageResolvedVariant {
437
+ /** Variant name (STORAGE_VARIANT_NAME enum value) */
438
+ name: string;
439
+ /** Variant URL */
440
+ url: string;
441
+ /** File ID */
442
+ fileId?: string;
443
+ /** Width in pixels */
444
+ width?: number;
445
+ /** Height in pixels */
446
+ height?: number;
447
+ /** File size in bytes */
448
+ size?: number;
449
+ /** Format */
450
+ format?: string;
451
+ /** Device types this variant is optimized for (STORAGE_DEVICE_TYPE enum values) */
452
+ devices?: STORAGE_DEVICE_TYPE[];
453
+ /** Custom metadata */
454
+ metadata?: Partial<FileMetadata>;
455
+ }
456
+ /**
457
+ * Variant resolution options for PresetManager
458
+ * Used to resolve variants from presets, custom variants, and device context
459
+ */
460
+ export interface StorageResolveVariantsOptions {
461
+ /** Preset names to apply */
462
+ presets?: string | string[];
463
+ /** Custom variants (overrides presets) */
464
+ variants?: string[] | StorageVariantConfig[];
465
+ /** Target device type */
466
+ device?: string;
467
+ /** File category for default variants */
468
+ category?: FILE_CATEGORY;
469
+ /** Generate for all devices (ignores device parameter) */
470
+ allDevices?: boolean;
471
+ }
472
+ /**
473
+ * Generate file parameters (to buffer, without uploading)
474
+ */
475
+ export interface GenerateFileParams {
476
+ /** Template ID */
477
+ templateId: string;
478
+ /** Template data */
479
+ templateData: Record<string, unknown>;
480
+ /** Output format (default: 'pdf') */
481
+ outputFormat?: OUTPUT_FORMAT | string;
482
+ /** Locale for generation */
483
+ locale?: string;
484
+ /** Specific renderer to use by name */
485
+ rendererName?: STORAGE_RENDERER_TYPE | string;
486
+ /** PDF render options */
487
+ pdfOptions?: PDFRenderOptions;
488
+ }
489
+ /**
490
+ * Generate file to path parameters
491
+ */
492
+ export interface GenerateFileToPathParams extends GenerateFileParams {
493
+ /** Output path (local file system) */
494
+ outputPath: string;
495
+ }
496
+ /**
497
+ * Generate file to path result
498
+ */
499
+ export interface GenerateFileToPathResult {
500
+ /** Output path */
501
+ path: string;
502
+ /** File size in bytes */
503
+ size: number;
504
+ /** Output format */
505
+ format: string;
506
+ /** Renderer used */
507
+ renderer: string;
508
+ }
509
+ /**
510
+ * Update file parameters
511
+ */
512
+ export interface UpdateFileParams {
513
+ /** Existing file ID to update */
514
+ fileId: string;
515
+ /** New file buffer (if replacing with buffer) */
516
+ file?: globalThis.Buffer;
517
+ /** Template ID (if regenerating from template) */
518
+ templateId?: string;
519
+ /** Template data (if regenerating from template) */
520
+ templateData?: Record<string, unknown>;
521
+ /** Output format (if regenerating) */
522
+ outputFormat?: string;
523
+ /** Locale (if regenerating) */
524
+ locale?: string;
525
+ /** Custom metadata to merge with existing */
526
+ customMetadata?: Record<string, unknown>;
527
+ /** Reason for update (audit trail) */
528
+ reason?: string;
529
+ /** Skip specific plugins by name for this operation */
530
+ skipPlugins?: readonly StorageKnownPluginName[];
531
+ /** Only run these specific plugins for this operation */
532
+ onlyPlugins?: readonly StorageKnownPluginName[];
533
+ }
534
+ /**
535
+ * Validation rule
536
+ */
537
+ export interface ValidationRule {
538
+ /** Allowed MIME types */
539
+ allowedMimeTypes?: string[];
540
+ /** Allowed file extensions */
541
+ allowedExtensions?: string[];
542
+ /** Maximum file size in bytes */
543
+ maxSize?: number;
544
+ /** Minimum file size in bytes */
545
+ minSize?: number;
546
+ /** Whether to allow executables */
547
+ allowExecutables?: boolean;
548
+ /** Custom validation function */
549
+ customValidation?: (file: globalThis.Buffer, metadata: Partial<FileMetadata>) => Promise<boolean>;
550
+ }
551
+ /**
552
+ * File validation result
553
+ */
554
+ export interface FileValidationResult {
555
+ /** Whether validation passed */
556
+ valid: boolean;
557
+ /** Error code (if validation failed) */
558
+ errorCode?: StorageErrorCode;
559
+ /** Error message */
560
+ errorMessage?: string;
561
+ /** Additional context */
562
+ context?: Record<string, unknown>;
563
+ }
564
+ /**
565
+ * Adapter health check result
566
+ */
567
+ export interface AdapterHealthCheck {
568
+ /** Health status */
569
+ status: ADAPTER_HEALTH_STATUS;
570
+ /** Response time in milliseconds */
571
+ responseTime?: number;
572
+ /** Error message (if unhealthy) */
573
+ error?: string;
574
+ /** Last check timestamp */
575
+ lastChecked: Date;
576
+ /** Additional details */
577
+ details?: Record<string, unknown>;
578
+ }
579
+ /**
580
+ * Storage event payload base
581
+ */
582
+ export interface StorageEventPayload {
583
+ /** Event type */
584
+ type: STORAGE_EVENT_TYPE;
585
+ /** Timestamp */
586
+ timestamp: Date;
587
+ /** File metadata */
588
+ metadata?: FileMetadata;
589
+ /** Additional data */
590
+ data?: Record<string, unknown>;
591
+ }
592
+ /**
593
+ * Storage retry configuration
594
+ */
595
+ export interface StorageRetryConfig {
596
+ /** Retry strategy */
597
+ strategy: RETRY_STRATEGY;
598
+ /** Maximum retry attempts */
599
+ maxAttempts: number;
600
+ /** Initial delay in milliseconds */
601
+ initialDelay: number;
602
+ /** Maximum delay in milliseconds */
603
+ maxDelay?: number;
604
+ /** Backoff multiplier */
605
+ backoffMultiplier?: number;
606
+ }
607
+ /**
608
+ * Path generation configuration
609
+ */
610
+ export interface PathGenerationConfig {
611
+ /** Path generation strategy */
612
+ strategy: PATH_GENERATION_STRATEGY;
613
+ /** Custom path template */
614
+ template?: string;
615
+ /** Whether to include file hash in path */
616
+ includeHash?: boolean;
617
+ /** Whether to include timestamp in path */
618
+ includeTimestamp?: boolean;
619
+ }
620
+ /**
621
+ * Bucket configuration (provider-agnostic)
622
+ * Describes what a bucket is used for, not how it's named
623
+ */
624
+ export interface BucketConfiguration {
625
+ /** Bucket purpose */
626
+ purpose: BUCKET_PURPOSE;
627
+ /** Business model context (optional) */
628
+ businessModel?: BUSINESS_MODEL;
629
+ /** Organization tier (optional) */
630
+ tier?: ORGANIZATION_TIER;
631
+ /** Organization ID (for dedicated buckets) */
632
+ organizationId?: string;
633
+ /** Environment context */
634
+ environment?: string;
635
+ /** Region context */
636
+ region?: string;
637
+ }
638
+ /**
639
+ * Storage category metadata
640
+ * Provider-agnostic bucket organization
641
+ */
642
+ export interface StorageCategory {
643
+ /** Unique category identifier */
644
+ purpose: BUCKET_PURPOSE;
645
+ /** Human-readable description */
646
+ description: string;
647
+ /** Typical use cases */
648
+ useCases: string[];
649
+ /** Recommended retention period (days) */
650
+ recommendedRetention?: number;
651
+ /** Whether this requires compliance logging */
652
+ requiresCompliance: boolean;
653
+ /** Whether this supports public access */
654
+ supportsPublicAccess: boolean;
655
+ /** Recommended access level */
656
+ defaultVisibility: STORAGE_VISIBILITY;
657
+ }
658
+ /**
659
+ * Routing decision result
660
+ */
661
+ export interface RoutingDecision {
662
+ /** Adapter name to use */
663
+ adapterName: string;
664
+ /** Bucket purpose (adapter translates to actual name) */
665
+ bucketPurpose: BUCKET_PURPOSE;
666
+ /** Bucket configuration */
667
+ bucketConfig: BucketConfiguration;
668
+ /** Generated path (if auto-generated) */
669
+ path?: string;
670
+ /** Path generation strategy used */
671
+ pathStrategy?: PATH_STRATEGY;
672
+ /** Reason for routing decision (for logging) */
673
+ reason: string;
674
+ }
675
+ /**
676
+ * Routing rule condition function
677
+ */
678
+ export type RoutingCondition = (params: UploadParams, purpose: BUCKET_PURPOSE) => boolean;
679
+ /**
680
+ * Routing rule definition
681
+ */
682
+ export interface RoutingRule {
683
+ /** Rule name (for debugging/logging) */
684
+ name: string;
685
+ /** Condition function */
686
+ condition: RoutingCondition;
687
+ /** Adapter name to route to */
688
+ adapterName: string;
689
+ /** Priority (higher = checked first) */
690
+ priority?: number;
691
+ /** Whether to auto-generate path */
692
+ generatePath?: boolean;
693
+ }
694
+ /**
695
+ * Bucket Router Configuration
696
+ */
697
+ export interface BucketRouterConfig {
698
+ /** Custom routing rules */
699
+ customRules?: RoutingRule[];
700
+ /** Enable default routing rules */
701
+ enableDefaultRules?: boolean;
702
+ /** Logger instance */
703
+ logger?: LoggerInterface;
704
+ /** User preferences: which adapter to use for each purpose */
705
+ adapterPreferences?: Partial<Record<BUCKET_PURPOSE, string>>;
706
+ /** Available adapters (passed from StorageService) */
707
+ availableAdapters?: string[];
708
+ }
709
+ /**
710
+ * Options for compliance document paths
711
+ * Works on ANY storage provider (R2, S3, Supabase, etc.)
712
+ */
713
+ export interface CompliancePathOptions {
714
+ /** Tenant/organization slug */
715
+ tenant: string;
716
+ /** Document type (invoice, receipt, tax, etc.) */
717
+ documentType: DOCUMENT_TYPE;
718
+ /** Document ID (UUID or system ID) */
719
+ documentId: string;
720
+ /** Human-readable slug (optional) */
721
+ slug?: string;
722
+ /** File extension (with dot, e.g., '.pdf') */
723
+ extension: string;
724
+ /** Date for path (defaults to now) */
725
+ date?: Date;
726
+ /** Business model for sub-tenant separation */
727
+ businessModel?: BUSINESS_MODEL;
728
+ /** Organization ID for multi-org */
729
+ organizationId?: string;
730
+ }
731
+ /**
732
+ * Options for media paths
733
+ * Works on ANY storage provider
734
+ */
735
+ export interface MediaPathOptions {
736
+ /** Visibility level (public/private) */
737
+ visibility: STORAGE_VISIBILITY;
738
+ /** Media entity type (team, club, athlete, etc.) */
739
+ entity: MEDIA_ENTITY;
740
+ /** Entity ID (UUID or system ID) */
741
+ entityId: string;
742
+ /** Variant name (original, thumb, sm, md, lg, etc.) */
743
+ variant: string;
744
+ /** Filename with extension */
745
+ filename: string;
746
+ /** Date for path (defaults to now) */
747
+ date?: Date;
748
+ /** Business model for routing */
749
+ businessModel?: BUSINESS_MODEL;
750
+ }
751
+ /**
752
+ * Options for general paths
753
+ * Works on ANY storage provider
754
+ */
755
+ export interface GeneralPathOptions {
756
+ /** File category */
757
+ category: string;
758
+ /** Entity type */
759
+ entityType: string;
760
+ /** Entity ID */
761
+ entityId: string;
762
+ /** Filename */
763
+ filename: string;
764
+ /** Date for path (defaults to now) */
765
+ date?: Date;
766
+ /** Include UUID in filename */
767
+ includeUuid?: boolean;
768
+ }
769
+ /**
770
+ * Storage service configuration
771
+ */
772
+ /**
773
+ * Storage template engine configuration
774
+ */
775
+ export interface StorageTemplateEngineConfig<TTemplateService = unknown, TTranslationService = unknown, TRendererRegistry = unknown, TLayoutEngine = unknown> {
776
+ /** Template service for loading templates (markdown files for PDFs) */
777
+ templateService?: TTemplateService;
778
+ /** Translation service for loading translation strings (JSON files for i18n) - optional */
779
+ translationService?: TTranslationService;
780
+ /** Renderer registry for converting HTML to PDF/PNG/etc. - optional */
781
+ rendererRegistry?: TRendererRegistry;
782
+ /** Layout engine for applying headers/footers/wrappers - optional */
783
+ layoutEngine?: TLayoutEngine;
784
+ /** Logger instance */
785
+ logger?: LoggerInterface;
786
+ /** Default locale (default: 'en') */
787
+ defaultLocale?: string;
788
+ /** Base path for templates (default: process.cwd() + '/templates') */
789
+ templateBasePath?: string;
790
+ /** Enable template caching (default: true) */
791
+ cacheEnabled?: boolean;
792
+ /** Cache TTL in milliseconds (default: 5 minutes) */
793
+ cacheTTL?: number;
794
+ /** Custom Handlebars helpers */
795
+ helpers?: Record<string, unknown>;
796
+ /** Renderer configuration */
797
+ renderer?: {
798
+ /** Renderer to use (e.g., 'pdfkit', 'puppeteer', 'playwright', 'exceljs', 'officegen') */
799
+ use?: string;
800
+ /** Default output format (default: 'pdf') */
801
+ defaultFormat?: string;
802
+ /** Custom renderer options passed to the renderer adapter */
803
+ options?: Record<string, unknown>;
804
+ };
805
+ }
806
+ /**
807
+ * Storage service configuration
808
+ */
809
+ /**
810
+ * Cleaner event handler interface with camelCase method names
811
+ * Provides intuitive naming instead of enum-based syntax
812
+ *
813
+ * @example
814
+ * ```typescript
815
+ * const handlers: StorageEventHandlers = {
816
+ * onFileUploaded: async (payload) => { ... },
817
+ * onFileDeleted: async (payload) => { ... },
818
+ * onQueueStarted: async (payload) => { ... },
819
+ * };
820
+ * ```
821
+ */
822
+ export interface StorageEventHandlers {
823
+ onFileUploaded?: (payload: StorageEventPayload) => void | Promise<void>;
824
+ onFileUploadFailed?: (payload: StorageEventPayload) => void | Promise<void>;
825
+ onUploadProgress?: (payload: StorageEventPayload) => void | Promise<void>;
826
+ onUploadAborted?: (payload: StorageEventPayload) => void | Promise<void>;
827
+ onFileDeleted?: (payload: StorageEventPayload) => void | Promise<void>;
828
+ onFileDeleteFailed?: (payload: StorageEventPayload) => void | Promise<void>;
829
+ onFileAccessed?: (payload: StorageEventPayload) => void | Promise<void>;
830
+ onSignedUrlGenerated?: (payload: StorageEventPayload) => void | Promise<void>;
831
+ onMetadataExtracted?: (payload: StorageEventPayload) => void | Promise<void>;
832
+ onMediaProcessingStarted?: (payload: StorageEventPayload) => void | Promise<void>;
833
+ onMediaProcessingCompleted?: (payload: StorageEventPayload) => void | Promise<void>;
834
+ onMediaProcessingFailed?: (payload: StorageEventPayload) => void | Promise<void>;
835
+ onVirusDetected?: (payload: StorageEventPayload) => void | Promise<void>;
836
+ onVirusScanCompleted?: (payload: StorageEventPayload) => void | Promise<void>;
837
+ onAdapterHealthCheck?: (payload: StorageEventPayload) => void | Promise<void>;
838
+ onAdapterFailed?: (payload: StorageEventPayload) => void | Promise<void>;
839
+ onRetentionPolicyApplied?: (payload: StorageEventPayload) => void | Promise<void>;
840
+ onFileMarkedForDeletion?: (payload: StorageEventPayload) => void | Promise<void>;
841
+ onImmutabilityEnforced?: (payload: StorageEventPayload) => void | Promise<void>;
842
+ onFileReplaced?: (payload: StorageEventPayload) => void | Promise<void>;
843
+ onFileReplaceFailed?: (payload: StorageEventPayload) => void | Promise<void>;
844
+ onFileMoved?: (payload: StorageEventPayload) => void | Promise<void>;
845
+ onFileMoveFailed?: (payload: StorageEventPayload) => void | Promise<void>;
846
+ onFileCopied?: (payload: StorageEventPayload) => void | Promise<void>;
847
+ onFileCopyFailed?: (payload: StorageEventPayload) => void | Promise<void>;
848
+ onAuditLogCreated?: (payload: StorageEventPayload) => void | Promise<void>;
849
+ onQueueStarted?: (payload: StorageEventPayload) => void | Promise<void>;
850
+ onQueueStopped?: (payload: StorageEventPayload) => void | Promise<void>;
851
+ onOperationProcessing?: (payload: StorageEventPayload) => void | Promise<void>;
852
+ onOperationCompleted?: (payload: StorageEventPayload) => void | Promise<void>;
853
+ onOperationRetry?: (payload: StorageEventPayload) => void | Promise<void>;
854
+ onOperationFailed?: (payload: StorageEventPayload) => void | Promise<void>;
855
+ onStorageError?: (payload: StorageEventPayload) => void | Promise<void>;
856
+ }
857
+ /**
858
+ * Preset manager configuration
859
+ * Manages variant presets and device-aware optimization
860
+ */
861
+ export interface StoragePresetManagerConfig {
862
+ /** Custom presets to register */
863
+ presets?: StoragePresetConfig[];
864
+ /** Default variants by file category */
865
+ defaultVariants?: Partial<Record<FILE_CATEGORY, string[]>>;
866
+ /** Enable built-in presets (profile-picture, post-image, hero-banner, video-streaming) */
867
+ enableBuiltInPresets?: boolean;
868
+ /** Default device type when not specified */
869
+ defaultDevice?: string;
870
+ /** Enable device detection from user agent */
871
+ enableDeviceDetection?: boolean;
872
+ /** Logger instance */
873
+ logger?: unknown;
874
+ }
875
+ /**
876
+ * Storage service configuration
877
+ */
878
+ export interface StorageServiceConfig<BaseStorageAdapter = unknown> {
879
+ /** Storage adapters to register */
880
+ adapters: BaseStorageAdapter[];
881
+ /** Logger instance */
882
+ logger?: LoggerInterface;
883
+ /** Event handlers (enum-based syntax) */
884
+ eventHandlers?: Partial<Record<STORAGE_EVENT_TYPE, (payload: StorageEventPayload) => void | Promise<void>>>;
885
+ /** Event handlers (cleaner camelCase syntax - recommended) */
886
+ handlers?: StorageEventHandlers;
887
+ /** Adapter registry configuration */
888
+ adapterRegistryConfig?: Omit<StorageAdapterRegistryConfig, 'logger'>;
889
+ /** Event manager configuration */
890
+ eventManagerConfig?: Omit<StorageEventManagerConfig, 'logger'>;
891
+ /** Maximum retry attempts for failover */
892
+ maxFailoverAttempts?: number;
893
+ /** Template engine configuration (for PDF generation) */
894
+ template?: StorageTemplateEngineConfig;
895
+ /** Custom template service (defaults to FileSystemTemplateService) */
896
+ templateService?: TemplateService;
897
+ /** Queue configuration (for background operations) */
898
+ queue?: StorageQueueConfig;
899
+ /** Compliance configuration (retention policies, immutability, etc.) */
900
+ compliance?: StorageComplianceConfig;
901
+ /** Plugins to register (extends storage functionality with lifecycle hooks) */
902
+ plugins?: StoragePlugin[];
903
+ /** Plugin registry configuration */
904
+ pluginRegistryConfig?: Omit<PluginRegistryConfig, 'logger'>;
905
+ /** Webhook configuration (for external service integrations) */
906
+ webhooks?: StorageWebhookManagerConfig;
907
+ /** Webhook adapters to register */
908
+ webhookAdapters?: StorageWebhookAdapter[];
909
+ /** Preset manager configuration (variant presets and device-aware optimization) */
910
+ presets?: StoragePresetManagerConfig;
911
+ /** Bucket router configuration (content-based routing to adapters) */
912
+ bucketRouterConfig?: Omit<BucketRouterConfig, 'logger' | 'availableAdapters'>;
913
+ }
914
+ /**
915
+ * File validation rules per bucket purpose
916
+ */
917
+ export interface BucketPurposeValidationRules {
918
+ /** Maximum file size in bytes */
919
+ maxFileSize?: number;
920
+ /** Minimum file size in bytes */
921
+ minFileSize?: number;
922
+ /** Allowed MIME types (supports wildcards like 'image/*') */
923
+ allowedMimeTypes?: string[];
924
+ /** Disallowed MIME types */
925
+ disallowedMimeTypes?: string[];
926
+ /** Allow executable files (default: false) */
927
+ allowExecutables?: boolean;
928
+ }
929
+ /**
930
+ * Storage validation configuration
931
+ * Defines file size limits and MIME type restrictions per bucket purpose
932
+ */
933
+ export interface StorageValidationConfig {
934
+ /** Validation rules per bucket purpose */
935
+ rules?: Partial<Record<BUCKET_PURPOSE, BucketPurposeValidationRules>>;
936
+ /** Default rules for buckets without specific rules */
937
+ defaultRules?: BucketPurposeValidationRules;
938
+ }
939
+ /**
940
+ * Base storage adapter configuration
941
+ */
942
+ export interface BaseStorageAdapterConfig {
943
+ /** Adapter name */
944
+ name: string;
945
+ /** Adapter type */
946
+ type: STORAGE_ADAPTER_TYPE;
947
+ /** Whether this adapter is enabled */
948
+ enabled?: boolean;
949
+ /** Adapter priority (higher = preferred) */
950
+ priority?: number;
951
+ /** Health check interval in milliseconds */
952
+ healthCheckInterval?: number;
953
+ /** Retry configuration */
954
+ retry?: StorageRetryConfig;
955
+ /** API client configuration (for custom adapters) */
956
+ apiClientConfig?: StorageApiClientConfig;
957
+ /** Auto-create buckets if they don't exist (default: true) */
958
+ autoCreateBuckets?: boolean;
959
+ /** Default environment for bucket naming (prod/stg/dev) */
960
+ defaultEnvironment?: STORAGE_ENVIRONMENT;
961
+ /** Default region for bucket naming */
962
+ defaultRegion?: string;
963
+ /** Validation configuration (file size limits, MIME types per bucket purpose) */
964
+ validation?: StorageValidationConfig;
965
+ /** Progress callback for all uploads through this adapter */
966
+ onProgress?: (progress: UploadProgressEvent) => void;
967
+ /** Global abort signal for this adapter (can be used to cancel all operations) */
968
+ abortSignal?: AbortSignal;
969
+ }
970
+ /**
971
+ * Cloudflare R2 adapter configuration
972
+ */
973
+ export interface CloudflareR2Config extends BaseStorageAdapterConfig {
974
+ type: STORAGE_ADAPTER_TYPE.CloudflareR2;
975
+ /** AWS S3-compatible credentials */
976
+ credentials: {
977
+ accountId: string;
978
+ accessKeyId: string;
979
+ secretAccessKey: string;
980
+ };
981
+ /** Bucket name (optional when autoCreateBuckets is enabled - will use dynamic buckets) */
982
+ bucket?: string;
983
+ /** Region */
984
+ region?: string;
985
+ /** Public URL domain (for public files) */
986
+ publicDomain?: string;
987
+ /** Endpoint URL */
988
+ endpoint?: string;
989
+ }
990
+ /**
991
+ * Supabase Storage adapter configuration
992
+ */
993
+ export interface SupabaseStorageConfig extends BaseStorageAdapterConfig {
994
+ type: STORAGE_ADAPTER_TYPE.SupabaseStorage;
995
+ /** Supabase URL */
996
+ supabaseUrl: string;
997
+ /** Supabase service role key */
998
+ serviceRoleKey: string;
999
+ /** Default bucket name (optional when autoCreateBuckets is enabled - will use dynamic buckets) */
1000
+ bucket?: string;
1001
+ /** Public URL (for public files) */
1002
+ publicUrl?: string;
1003
+ }
1004
+ /**
1005
+ * Custom adapter configuration
1006
+ */
1007
+ export interface CustomAdapterConfig extends BaseStorageAdapterConfig {
1008
+ type: STORAGE_ADAPTER_TYPE.CUSTOM;
1009
+ /** API client configuration */
1010
+ apiClientConfig: StorageApiClientConfig;
1011
+ /** Upload endpoint */
1012
+ uploadEndpoint: string;
1013
+ /** Download endpoint */
1014
+ downloadEndpoint: string;
1015
+ /** Delete endpoint */
1016
+ deleteEndpoint: string;
1017
+ /** Signed URL endpoint */
1018
+ signedUrlEndpoint?: string;
1019
+ /** Health check endpoint */
1020
+ healthCheckEndpoint?: string;
1021
+ }
1022
+ /**
1023
+ * Mock adapter configuration (for testing)
1024
+ */
1025
+ export interface MockAdapterConfig extends BaseStorageAdapterConfig {
1026
+ type: STORAGE_ADAPTER_TYPE.MOCK;
1027
+ /** Whether to simulate failures */
1028
+ simulateFailures?: boolean;
1029
+ /** Failure rate (0-1) */
1030
+ failureRate?: number;
1031
+ /** Simulated latency in milliseconds */
1032
+ latency?: number;
1033
+ }
1034
+ /**
1035
+ * Base storage plugin configuration
1036
+ */
1037
+ export interface BaseStoragePluginConfig {
1038
+ /** Plugin name */
1039
+ name: string;
1040
+ /** Whether the plugin is enabled */
1041
+ enabled?: boolean;
1042
+ /** Plugin priority (higher = runs first) */
1043
+ priority?: number;
1044
+ /** Plugin hooks */
1045
+ hooks?: {
1046
+ beforeUpload?: boolean;
1047
+ afterUpload?: boolean;
1048
+ afterDelete?: boolean;
1049
+ };
1050
+ }
1051
+ /**
1052
+ * Queue item
1053
+ */
1054
+ export interface QueueItem<T = unknown> {
1055
+ /** Item ID */
1056
+ id: string;
1057
+ /** Item data */
1058
+ data: T;
1059
+ /** Priority */
1060
+ priority: STORAGE_QUEUE_PRIORITY;
1061
+ /** Retry count */
1062
+ retryCount: number;
1063
+ /** Maximum retries */
1064
+ maxRetries: number;
1065
+ /** Created timestamp */
1066
+ createdAt: Date;
1067
+ /** Scheduled execution time */
1068
+ scheduledAt?: Date;
1069
+ }
1070
+ /**
1071
+ * Storage queue configuration
1072
+ */
1073
+ export interface StorageQueueConfig {
1074
+ /** Enable queue processing */
1075
+ enabled?: boolean;
1076
+ /** Maximum queue size */
1077
+ maxSize?: number;
1078
+ /** Maximum concurrent workers */
1079
+ concurrency?: number;
1080
+ /** Processing interval in milliseconds */
1081
+ interval?: number;
1082
+ /** Default priority */
1083
+ defaultPriority?: STORAGE_QUEUE_PRIORITY;
1084
+ /** Default max retries */
1085
+ maxRetries?: number;
1086
+ /** Retry delay in milliseconds */
1087
+ retryDelay?: number;
1088
+ /** Auto-start queue processor */
1089
+ autoStart?: boolean;
1090
+ }
1091
+ /**
1092
+ * Storage file operation type for queue
1093
+ */
1094
+ export type StorageFileOperationType = 'upload' | 'download' | 'delete' | 'render' | 'transform';
1095
+ /**
1096
+ * Queued storage file operation
1097
+ */
1098
+ export interface StorageQueuedOperation {
1099
+ /** Operation ID */
1100
+ id: string;
1101
+ /** Operation type */
1102
+ type: StorageFileOperationType;
1103
+ /** File ID (for download/delete operations) */
1104
+ fileId?: string;
1105
+ /** Upload parameters (for upload operations) */
1106
+ uploadParams?: UploadParams;
1107
+ /** Template ID (for render operations) */
1108
+ templateId?: string;
1109
+ /** Template data (for render operations) */
1110
+ templateData?: Record<string, unknown>;
1111
+ /** Priority */
1112
+ priority: STORAGE_QUEUE_PRIORITY;
1113
+ /** Retry count */
1114
+ retryCount: number;
1115
+ /** Maximum retries */
1116
+ maxRetries: number;
1117
+ /** Created timestamp */
1118
+ createdAt: Date;
1119
+ /** Scheduled execution time */
1120
+ scheduledAt?: Date;
1121
+ /** Custom metadata */
1122
+ metadata?: Record<string, unknown>;
1123
+ }
1124
+ /**
1125
+ * Process function for storage queue processor
1126
+ */
1127
+ export type StorageQueueProcessFunction = (operation: StorageQueuedOperation) => Promise<void>;
1128
+ /**
1129
+ * Storage queue statistics
1130
+ */
1131
+ export interface StorageQueueStatistics {
1132
+ /** Total operations queued */
1133
+ totalQueued: number;
1134
+ /** Operations currently in queue */
1135
+ currentSize: number;
1136
+ /** Operations processed successfully */
1137
+ processedCount: number;
1138
+ /** Operations that failed */
1139
+ failedCount: number;
1140
+ /** Queue is currently processing */
1141
+ isProcessing: boolean;
1142
+ }
1143
+ /**
1144
+ * Retention policy
1145
+ */
1146
+ export interface RetentionPolicy {
1147
+ /** Policy ID */
1148
+ id: string;
1149
+ /** Policy name */
1150
+ name: string;
1151
+ /** Retention duration in days */
1152
+ retentionDays: number;
1153
+ /** File categories this policy applies to */
1154
+ categories?: FILE_CATEGORY[];
1155
+ /** Entity types this policy applies to */
1156
+ entityTypes?: ENTITY_TYPE[];
1157
+ /** Whether files are immutable during retention */
1158
+ immutable?: boolean;
1159
+ /** Whether to auto-delete after retention expires */
1160
+ autoDelete?: boolean;
1161
+ }
1162
+ /**
1163
+ * Storage compliance rule
1164
+ */
1165
+ export interface StorageComplianceRule {
1166
+ /** Rule ID */
1167
+ id: string;
1168
+ /** Rule name */
1169
+ name: string;
1170
+ /** Rule type */
1171
+ type: 'retention' | 'immutability' | 'encryption' | 'access-control';
1172
+ /** Validation function */
1173
+ validate: (metadata: FileMetadata) => Promise<boolean>;
1174
+ /** Enforcement action */
1175
+ enforce?: (metadata: FileMetadata) => Promise<void>;
1176
+ }
1177
+ /**
1178
+ * Template configuration
1179
+ */
1180
+ export interface TemplateConfig {
1181
+ /** Template name */
1182
+ name: string;
1183
+ /** Template source (Handlebars) */
1184
+ source: string;
1185
+ /** Template type */
1186
+ type: 'html' | 'markdown';
1187
+ /** Output format */
1188
+ outputFormat: TEMPLATE_OUTPUT_FORMAT;
1189
+ /** Partials */
1190
+ partials?: Record<string, string>;
1191
+ /** Helpers */
1192
+ helpers?: Record<string, (...args: unknown[]) => string>;
1193
+ }
1194
+ /**
1195
+ * PDF render options (used by renderer adapters)
1196
+ */
1197
+ export interface PDFRenderOptions {
1198
+ /** Page format (alias for pageSize) */
1199
+ format?: 'A4' | 'Letter' | 'Legal';
1200
+ /** Page size (preferred over format) */
1201
+ pageSize?: 'A4' | 'Letter' | 'Legal';
1202
+ /** Page orientation */
1203
+ orientation?: 'portrait' | 'landscape';
1204
+ /** Margins (alias for margin) */
1205
+ margins?: {
1206
+ top?: string;
1207
+ right?: string;
1208
+ bottom?: string;
1209
+ left?: string;
1210
+ };
1211
+ /** Margin (deprecated, use margins) */
1212
+ margin?: {
1213
+ top?: string;
1214
+ right?: string;
1215
+ bottom?: string;
1216
+ left?: string;
1217
+ };
1218
+ /** Header template (HTML) */
1219
+ headerTemplate?: string;
1220
+ /** Footer template (HTML) */
1221
+ footerTemplate?: string;
1222
+ /** Display header/footer */
1223
+ displayHeaderFooter?: boolean;
1224
+ /** Print background colors/images */
1225
+ printBackground?: boolean;
1226
+ /** Scale/zoom level (0.1 to 2) */
1227
+ scale?: number;
1228
+ /** Use CSS page size instead of format */
1229
+ preferCSSPageSize?: boolean;
1230
+ /** PDF metadata */
1231
+ metadata?: {
1232
+ author?: string;
1233
+ subject?: string;
1234
+ keywords?: string;
1235
+ title?: string;
1236
+ };
1237
+ /** CSS styles to inject */
1238
+ css?: string;
1239
+ /** Watermark configuration */
1240
+ watermark?: {
1241
+ enabled: boolean;
1242
+ text?: string;
1243
+ opacity?: number;
1244
+ };
1245
+ }
1246
+ /**
1247
+ * Storage Excel render options (used by ExcelJS renderer)
1248
+ */
1249
+ export interface StorageExcelRenderOptions {
1250
+ /** Sheet name */
1251
+ sheetName?: string;
1252
+ /** Creator name */
1253
+ creator?: string;
1254
+ /** Last modified by */
1255
+ lastModifiedBy?: string;
1256
+ /** Whether to freeze the header row */
1257
+ freezeHeader?: boolean;
1258
+ /** Auto-filter columns */
1259
+ autoFilter?: boolean;
1260
+ /** Column widths (array of widths or 'auto') */
1261
+ columnWidths?: number[] | 'auto';
1262
+ /** Cell styles */
1263
+ styles?: {
1264
+ headerStyle?: Record<string, unknown>;
1265
+ dataStyle?: Record<string, unknown>;
1266
+ };
1267
+ /** Protect worksheet */
1268
+ protection?: {
1269
+ password?: string;
1270
+ options?: Record<string, unknown>;
1271
+ };
1272
+ }
1273
+ /**
1274
+ * Storage Word document render options (used by DocxTemplater renderer)
1275
+ */
1276
+ export interface StorageWordRenderOptions {
1277
+ /** Creator name */
1278
+ creator?: string;
1279
+ /** Title */
1280
+ title?: string;
1281
+ /** Subject */
1282
+ subject?: string;
1283
+ /** Page size */
1284
+ pageSize?: 'A4' | 'Letter' | 'Legal';
1285
+ /** Orientation */
1286
+ orientation?: 'portrait' | 'landscape';
1287
+ /** Margins (in inches) */
1288
+ margins?: {
1289
+ top?: number;
1290
+ right?: number;
1291
+ bottom?: number;
1292
+ left?: number;
1293
+ };
1294
+ /** Header text */
1295
+ header?: string;
1296
+ /** Footer text */
1297
+ footer?: string;
1298
+ /** Line spacing */
1299
+ lineSpacing?: number;
1300
+ /** Font family */
1301
+ fontFamily?: string;
1302
+ /** Font size */
1303
+ fontSize?: number;
1304
+ }
1305
+ /**
1306
+ * Template service interface (for loading templates)
1307
+ */
1308
+ export interface TemplateService {
1309
+ /** Get template content by path */
1310
+ getTemplate(path: string): Promise<string>;
1311
+ /** Check if template exists */
1312
+ hasTemplate(path: string): Promise<boolean>;
1313
+ }
1314
+ /**
1315
+ * Storage translation service interface (for loading translation strings)
1316
+ * Separate from TemplateService for Separation of Concerns:
1317
+ * - TemplateService: Loads markdown templates for PDFs (invoices, receipts)
1318
+ * - StorageTranslationService: Loads translation strings for UI/messages (i18n)
1319
+ */
1320
+ export interface StorageTranslationService {
1321
+ /** Get translation content by path (e.g., 'en/storage.json') */
1322
+ getTranslation(path: string): Promise<string>;
1323
+ /** Check if translation file exists */
1324
+ hasTranslation(path: string): Promise<boolean>;
1325
+ }
1326
+ /**
1327
+ * Storage template frontmatter (YAML metadata in markdown for PDFs)
1328
+ */
1329
+ export interface StorageTemplateFrontmatter {
1330
+ /** Template name (identifier) */
1331
+ name?: string;
1332
+ /** Display title */
1333
+ title?: string;
1334
+ /** Template description */
1335
+ description?: string;
1336
+ /** Template version */
1337
+ version?: string;
1338
+ /** Locale */
1339
+ locale?: string;
1340
+ /** Category (invoices, receipts, etc.) */
1341
+ category?: string;
1342
+ /** Layout to use (full wrapper template) */
1343
+ layout?: string;
1344
+ /** Header template to use */
1345
+ header?: string;
1346
+ /** Footer template to use */
1347
+ footer?: string;
1348
+ /** Wrapper template to use */
1349
+ wrapper?: string;
1350
+ /** PDF configuration */
1351
+ pageSize?: 'A4' | 'Letter' | 'Legal';
1352
+ orientation?: 'portrait' | 'landscape';
1353
+ margins?: {
1354
+ top?: string;
1355
+ right?: string;
1356
+ bottom?: string;
1357
+ left?: string;
1358
+ };
1359
+ /** PDF metadata */
1360
+ metadata?: {
1361
+ author?: string;
1362
+ subject?: string;
1363
+ keywords?: string;
1364
+ };
1365
+ /** Security & compliance */
1366
+ watermark?: {
1367
+ enabled: boolean;
1368
+ text?: string;
1369
+ };
1370
+ requiresSignature?: boolean;
1371
+ archival?: boolean;
1372
+ expiration?: {
1373
+ enabled: boolean;
1374
+ days?: number;
1375
+ };
1376
+ /** Custom CSS */
1377
+ css?: string;
1378
+ /** Additional custom fields */
1379
+ [key: string]: unknown;
1380
+ }
1381
+ /**
1382
+ * Storage template render result
1383
+ */
1384
+ export interface StorageTemplateRenderResult {
1385
+ /** Rendered HTML */
1386
+ html: string;
1387
+ /** Parsed frontmatter */
1388
+ frontmatter: StorageTemplateFrontmatter;
1389
+ /** CSS to inject */
1390
+ css?: string;
1391
+ }
1392
+ /**
1393
+ * Storage layout configuration
1394
+ */
1395
+ export interface StorageLayoutConfig {
1396
+ /** Layout name */
1397
+ name: string;
1398
+ /** Header template */
1399
+ header?: string;
1400
+ /** Footer template */
1401
+ footer?: string;
1402
+ /** Wrapper template */
1403
+ wrapper?: string;
1404
+ }
1405
+ /**
1406
+ * Storage template cache entry
1407
+ */
1408
+ export interface StorageTemplateCacheEntry {
1409
+ /** Raw template content */
1410
+ content: string;
1411
+ /** Parsed frontmatter */
1412
+ frontmatter: StorageTemplateFrontmatter;
1413
+ /** Template body (without frontmatter) */
1414
+ body: string;
1415
+ /** Cached timestamp */
1416
+ cachedAt: number;
1417
+ /** TTL in milliseconds */
1418
+ ttl: number;
1419
+ }
1420
+ /**
1421
+ * Storage renderer adapter configuration
1422
+ * Similar to BaseStorageAdapterConfig but for document rendering
1423
+ */
1424
+ export interface StorageRendererAdapterConfig {
1425
+ /** Renderer name (unique identifier) */
1426
+ name: string;
1427
+ /** Renderer type */
1428
+ type: STORAGE_RENDERER_TYPE;
1429
+ /** Whether this renderer is enabled */
1430
+ enabled?: boolean;
1431
+ /** Priority (higher = preferred, 0-1000) */
1432
+ priority?: number;
1433
+ /** Supported output formats */
1434
+ supportedFormats?: string[];
1435
+ /** Logger instance */
1436
+ logger?: unknown;
1437
+ /** Custom configuration per renderer */
1438
+ config?: Record<string, unknown>;
1439
+ }
1440
+ /**
1441
+ * Storage renderer health check result
1442
+ */
1443
+ export interface StorageRendererHealthCheck {
1444
+ /** Renderer name */
1445
+ name: string;
1446
+ /** Health status */
1447
+ status: string;
1448
+ /** Last check timestamp */
1449
+ lastCheck: Date;
1450
+ /** Response time in ms */
1451
+ responseTime?: number;
1452
+ /** Error message if unhealthy */
1453
+ error?: string;
1454
+ /** Additional metadata */
1455
+ metadata?: Record<string, unknown>;
1456
+ }
1457
+ /**
1458
+ * Storage render options (generic for all renderers)
1459
+ */
1460
+ export interface StorageRenderOptions {
1461
+ /** Output format */
1462
+ format: string;
1463
+ /** Template ID or path */
1464
+ templateId?: string;
1465
+ /** Template data/variables */
1466
+ data?: Record<string, unknown>;
1467
+ /** Locale for multi-language support */
1468
+ locale?: string;
1469
+ /** PDF-specific options (when format === 'pdf') */
1470
+ pdfOptions?: PDFRenderOptions;
1471
+ /** Excel-specific options (when format === 'excel') */
1472
+ excelOptions?: StorageExcelRenderOptions;
1473
+ /** Word-specific options (when format === 'word') */
1474
+ wordOptions?: StorageWordRenderOptions;
1475
+ /** Additional renderer-specific options */
1476
+ options?: Record<string, unknown>;
1477
+ }
1478
+ /**
1479
+ * Storage render result (generic)
1480
+ */
1481
+ export interface StorageRenderResult {
1482
+ /** Rendered content as Buffer */
1483
+ content: globalThis.Buffer;
1484
+ /** Output format */
1485
+ format: string;
1486
+ /** MIME type */
1487
+ mimeType: string;
1488
+ /** File size in bytes */
1489
+ size: number;
1490
+ /** Metadata */
1491
+ metadata?: Record<string, unknown>;
1492
+ }
1493
+ /**
1494
+ * Share link configuration
1495
+ */
1496
+ export interface ShareLinkConfig {
1497
+ /** Link ID */
1498
+ id: string;
1499
+ /** File ID */
1500
+ fileId: string;
1501
+ /** Password protection */
1502
+ password?: string;
1503
+ /** Expiry timestamp */
1504
+ expiresAt?: Date;
1505
+ /** Maximum download count */
1506
+ maxDownloads?: number;
1507
+ /** Current download count */
1508
+ downloadCount?: number;
1509
+ /** Created by user ID */
1510
+ createdBy: string;
1511
+ /** Created timestamp */
1512
+ createdAt: Date;
1513
+ }
1514
+ /**
1515
+ * Presigned URL options
1516
+ */
1517
+ export interface PresignedUrlOptions {
1518
+ /** Operation type */
1519
+ operation: 'upload' | 'download' | 'get';
1520
+ /** File ID or path */
1521
+ fileId?: string;
1522
+ /** Expiry in seconds */
1523
+ expiresIn: number;
1524
+ /** Content type (for upload) */
1525
+ contentType?: string;
1526
+ /** File size (for upload) */
1527
+ fileSize?: number;
1528
+ /** Metadata (for upload) */
1529
+ metadata?: Partial<FileMetadata>;
1530
+ /** Custom metadata for plugins and tracking */
1531
+ customMetadata?: Record<string, unknown>;
1532
+ /** Skip specific plugins by name for this operation */
1533
+ skipPlugins?: readonly StorageKnownPluginName[];
1534
+ /** Only run these specific plugins for this operation */
1535
+ onlyPlugins?: readonly StorageKnownPluginName[];
1536
+ /** Optional: Bucket name (if known, skips metadata lookup) */
1537
+ bucket?: string;
1538
+ /** Optional: Adapter name (if known, skips routing) */
1539
+ adapter?: string;
1540
+ /** Optional: Bucket purpose (for routing) */
1541
+ bucketPurpose?: BUCKET_PURPOSE;
1542
+ }
1543
+ /**
1544
+ * Presigned URL result
1545
+ */
1546
+ export interface PresignedUrlResult {
1547
+ /** Presigned URL */
1548
+ url: string;
1549
+ /** Upload/download ID */
1550
+ id: string;
1551
+ /** Expiry timestamp */
1552
+ expiresAt: Date;
1553
+ /** Additional fields required for upload */
1554
+ fields?: Record<string, string>;
1555
+ }
1556
+ /**
1557
+ * S3/R2 multipart upload part
1558
+ * Used for tracking uploaded parts in multipart upload
1559
+ */
1560
+ export interface MultipartUploadPart {
1561
+ /** Part number (1-indexed) */
1562
+ PartNumber: number;
1563
+ /** ETag returned by S3/R2 after part upload */
1564
+ ETag: string;
1565
+ }
1566
+ /**
1567
+ * Bucket deletion result
1568
+ */
1569
+ export interface BucketDeletionResult {
1570
+ /** Successfully deleted bucket names */
1571
+ deleted: string[];
1572
+ /** Failed deletions with error details */
1573
+ failed: Array<{
1574
+ bucket: string;
1575
+ error: string;
1576
+ }>;
1577
+ }
1578
+ /**
1579
+ * Upload progress event
1580
+ */
1581
+ export interface UploadProgressEvent {
1582
+ /** File ID */
1583
+ fileId: string;
1584
+ /** Filename */
1585
+ filename: string;
1586
+ /** Bytes uploaded */
1587
+ loaded: number;
1588
+ /** Total bytes */
1589
+ total: number;
1590
+ /** Progress percentage (0-100) */
1591
+ percentage: number;
1592
+ /** Upload speed in bytes/second */
1593
+ speed?: number;
1594
+ /** Estimated time remaining in seconds */
1595
+ estimatedTimeRemaining?: number;
1596
+ /** Current chunk/part number (for chunked uploads) */
1597
+ currentChunk?: number;
1598
+ /** Total number of chunks/parts (for chunked uploads) */
1599
+ totalChunks?: number;
1600
+ /** MIME type */
1601
+ mimeType?: string;
1602
+ /** Entity type */
1603
+ entityType?: ENTITY_TYPE;
1604
+ /** Entity ID */
1605
+ entityId?: string;
1606
+ /** Adapter name */
1607
+ adapter?: string;
1608
+ }
1609
+ /**
1610
+ * CORS configuration
1611
+ */
1612
+ export interface CorsConfig {
1613
+ /** Allowed origins */
1614
+ allowedOrigins: string[];
1615
+ /** Allowed methods */
1616
+ allowedMethods: string[];
1617
+ /** Allowed headers */
1618
+ allowedHeaders?: string[];
1619
+ /** Exposed headers */
1620
+ exposedHeaders?: string[];
1621
+ /** Max age in seconds */
1622
+ maxAge?: number;
1623
+ /** Allow credentials */
1624
+ allowCredentials?: boolean;
1625
+ }
1626
+ /**
1627
+ * Storage adapter registry configuration
1628
+ */
1629
+ export interface StorageAdapterRegistryConfig {
1630
+ /** Logger instance */
1631
+ logger?: LoggerInterface;
1632
+ /** Health check interval in milliseconds */
1633
+ healthCheckInterval?: number;
1634
+ /** Whether to enable automatic health checks */
1635
+ enableAutoHealthCheck?: boolean;
1636
+ }
1637
+ /**
1638
+ * Storage event manager configuration
1639
+ */
1640
+ export interface StorageEventManagerConfig {
1641
+ /** Logger instance */
1642
+ logger?: LoggerInterface;
1643
+ /** Whether to buffer events in bulk operations */
1644
+ enableBuffering?: boolean;
1645
+ /** Buffer flush interval in milliseconds */
1646
+ bufferFlushInterval?: number;
1647
+ }
1648
+ /**
1649
+ * Storage queue processor configuration
1650
+ */
1651
+ export interface StorageQueueProcessorConfig<TEventManager = unknown> {
1652
+ /** Number of concurrent workers (default: 1) */
1653
+ concurrency?: number;
1654
+ /** Poll interval in milliseconds (default: 100) */
1655
+ interval?: number;
1656
+ /** Maximum retry attempts (default: 3) */
1657
+ maxRetries?: number;
1658
+ /** Event manager for emitting operation events */
1659
+ eventManager?: TEventManager;
1660
+ /** Logger instance */
1661
+ logger?: LoggerInterface;
1662
+ }
1663
+ /**
1664
+ * Storage compliance manager configuration
1665
+ */
1666
+ export interface StorageComplianceManagerConfig {
1667
+ /** Compliance configuration */
1668
+ compliance: StorageComplianceConfig;
1669
+ /** Logger instance */
1670
+ logger?: LoggerInterface;
1671
+ }
1672
+ /**
1673
+ * Storage renderer registry configuration
1674
+ */
1675
+ export interface StorageRendererRegistryConfig {
1676
+ /** Logger instance */
1677
+ logger?: LoggerInterface;
1678
+ /** Auto health check interval (ms, 0 to disable) */
1679
+ healthCheckInterval?: number;
1680
+ }
1681
+ /**
1682
+ * Storage layout engine configuration
1683
+ */
1684
+ export interface StorageLayoutEngineConfig {
1685
+ /** Base path for layouts (default: ./templates/layouts) */
1686
+ basePath?: string;
1687
+ /** Default locale (default: 'en') */
1688
+ defaultLocale?: string;
1689
+ /** Enable layout caching (default: true) */
1690
+ cacheEnabled?: boolean;
1691
+ /** Cache TTL in milliseconds (default: 300000 = 5 minutes) */
1692
+ cacheTTL?: number;
1693
+ /** Logger instance */
1694
+ logger?: LoggerInterface;
1695
+ }
1696
+ /**
1697
+ * Storage applied layout result
1698
+ */
1699
+ export interface StorageAppliedLayout {
1700
+ /** Content with layout applied */
1701
+ html: string;
1702
+ /** Layout name used */
1703
+ layoutName: string;
1704
+ /** Locale used */
1705
+ locale: string;
1706
+ }
1707
+ /**
1708
+ * Storage translation service configuration
1709
+ */
1710
+ export interface StorageTranslationServiceConfig {
1711
+ /** Base path for translations (default: process.cwd() + '/translations') */
1712
+ basePath?: string;
1713
+ /** Logger instance */
1714
+ logger?: LoggerInterface;
1715
+ }
1716
+ /**
1717
+ * File system template service configuration
1718
+ */
1719
+ export interface FileSystemTemplateServiceConfig {
1720
+ /** Base directory for templates */
1721
+ baseDir: string;
1722
+ /** Whether to watch for file changes */
1723
+ watch?: boolean;
1724
+ /** Logger instance */
1725
+ logger?: LoggerInterface;
1726
+ }
1727
+ /**
1728
+ * Storage file system template service configuration
1729
+ */
1730
+ export interface StorageFileSystemTemplateServiceConfig {
1731
+ /** Base path for templates (default: process.cwd() + '/templates') */
1732
+ basePath?: string;
1733
+ /** Logger instance */
1734
+ logger?: LoggerInterface;
1735
+ }
1736
+ /**
1737
+ * Storage DocxTemplater renderer configuration
1738
+ */
1739
+ export interface StorageDocxTemplaterRendererConfig extends StorageRendererAdapterConfig {
1740
+ config?: {
1741
+ /** Base path for .docx templates */
1742
+ templateBasePath?: string;
1743
+ /** Default Word options */
1744
+ defaultOptions?: Record<string, unknown>;
1745
+ };
1746
+ }
1747
+ /**
1748
+ * Storage Word document data structure
1749
+ */
1750
+ export interface StorageWordDocumentData {
1751
+ /** Template path (relative to templateBasePath or absolute) */
1752
+ templatePath?: string;
1753
+ /** Template data (variables to replace) */
1754
+ data: Record<string, unknown>;
1755
+ /** Document metadata */
1756
+ metadata?: {
1757
+ creator?: string;
1758
+ title?: string;
1759
+ subject?: string;
1760
+ };
1761
+ }
1762
+ /**
1763
+ * Storage Playwright renderer configuration
1764
+ */
1765
+ export interface StoragePlaywrightRendererConfig extends StorageRendererAdapterConfig {
1766
+ config?: {
1767
+ /** Browser type to use */
1768
+ browserType?: 'chromium' | 'firefox' | 'webkit';
1769
+ /** Launch options */
1770
+ launchOptions?: Record<string, unknown>;
1771
+ /** Keep browser alive between renders */
1772
+ keepAlive?: boolean;
1773
+ /** Default timeout for page loads (ms) */
1774
+ timeout?: number;
1775
+ };
1776
+ }
1777
+ /**
1778
+ * Storage PDFKit renderer configuration
1779
+ */
1780
+ export interface StoragePDFKitRendererConfig extends StorageRendererAdapterConfig {
1781
+ config?: {
1782
+ /** Default PDF options */
1783
+ defaultOptions?: {
1784
+ size?: string | [number, number];
1785
+ margin?: number;
1786
+ bufferPages?: boolean;
1787
+ };
1788
+ };
1789
+ }
1790
+ /**
1791
+ * Storage PDFKit document data structure
1792
+ */
1793
+ export interface StoragePDFKitDocumentData {
1794
+ /** Document title */
1795
+ title?: string;
1796
+ /** Document content (array of sections) */
1797
+ content: Array<{
1798
+ type: 'text' | 'heading' | 'image' | 'line' | 'table';
1799
+ data: unknown;
1800
+ options?: Record<string, unknown>;
1801
+ }>;
1802
+ /** PDF metadata */
1803
+ metadata?: {
1804
+ author?: string;
1805
+ subject?: string;
1806
+ keywords?: string;
1807
+ };
1808
+ }
1809
+ /**
1810
+ * Storage ExcelJS renderer configuration
1811
+ */
1812
+ export interface StorageExcelJSRendererConfig extends StorageRendererAdapterConfig {
1813
+ config?: {
1814
+ /** Default Excel options */
1815
+ defaultOptions?: Record<string, unknown>;
1816
+ };
1817
+ }
1818
+ /**
1819
+ * Storage Excel data structure
1820
+ */
1821
+ export interface StorageExcelData {
1822
+ /** Worksheet data */
1823
+ sheets: Array<{
1824
+ /** Sheet name */
1825
+ name: string;
1826
+ /** Table data (array of rows) */
1827
+ data: Array<Record<string, unknown>>;
1828
+ /** Column configuration */
1829
+ columns?: Array<{
1830
+ header: string;
1831
+ key: string;
1832
+ width?: number;
1833
+ }>;
1834
+ }>;
1835
+ /** Workbook metadata */
1836
+ metadata?: {
1837
+ creator?: string;
1838
+ lastModifiedBy?: string;
1839
+ created?: Date;
1840
+ modified?: Date;
1841
+ };
1842
+ }
1843
+ /**
1844
+ * Storage Puppeteer renderer configuration
1845
+ */
1846
+ export interface StoragePuppeteerRendererConfig extends StorageRendererAdapterConfig {
1847
+ config?: {
1848
+ /** Puppeteer launch options */
1849
+ launchOptions?: Record<string, unknown>;
1850
+ /** Keep browser alive between renders (better performance) */
1851
+ keepAlive?: boolean;
1852
+ /** Default timeout for page loads (ms) */
1853
+ timeout?: number;
1854
+ };
1855
+ }
1856
+ /**
1857
+ * Storage media processing webhook configuration
1858
+ */
1859
+ export interface StorageMediaProcessingWebhookConfig extends StorageBaseWebhookAdapterConfig {
1860
+ /** Provider name (e.g., 'aws-mediaconvert', 'mux', 'cloudinary') */
1861
+ providerName?: string;
1862
+ /** Whether to enable strict validation */
1863
+ strictValidation?: boolean;
1864
+ }
1865
+ /**
1866
+ * Storage retry options for operations
1867
+ */
1868
+ export interface StorageRetryOptions {
1869
+ /** Maximum number of retry attempts */
1870
+ maxAttempts: number;
1871
+ /** Initial delay in milliseconds */
1872
+ initialDelay: number;
1873
+ /** Maximum delay in milliseconds */
1874
+ maxDelay?: number;
1875
+ /** Backoff multiplier */
1876
+ backoffMultiplier?: number;
1877
+ /** Callback function to call on retry */
1878
+ onRetry?: (attempt: number, error: Error) => void;
1879
+ }
1880
+ /**
1881
+ * Storage hash-based path generation options
1882
+ */
1883
+ export interface StorageHashPathOptions {
1884
+ /** Hash algorithm to use */
1885
+ algorithm?: 'md5' | 'sha1' | 'sha256';
1886
+ /** Number of directory levels */
1887
+ levels?: number;
1888
+ /** Characters per level */
1889
+ charsPerLevel?: number;
1890
+ /** File extension */
1891
+ extension?: string;
1892
+ /** Path prefix */
1893
+ prefix?: string;
1894
+ }
1895
+ /**
1896
+ * Storage entity-based path generation options
1897
+ */
1898
+ export interface StorageEntityPathOptions {
1899
+ /** Entity type */
1900
+ entityType: ENTITY_TYPE;
1901
+ /** Entity ID */
1902
+ entityId: string;
1903
+ /** File category */
1904
+ category: FILE_CATEGORY;
1905
+ /** Filename */
1906
+ filename: string;
1907
+ /** Whether to include timestamp */
1908
+ includeTimestamp?: boolean;
1909
+ /** Additional path segments */
1910
+ segments?: string[];
1911
+ }
1912
+ /**
1913
+ * Storage date-based path generation options
1914
+ */
1915
+ export interface StorageDatePathOptions {
1916
+ /** File category */
1917
+ category: FILE_CATEGORY;
1918
+ /** Filename */
1919
+ filename: string;
1920
+ /** Base directory */
1921
+ baseDir?: string;
1922
+ /** Whether to include UUID */
1923
+ includeUuid?: boolean;
1924
+ /** Date to use for path */
1925
+ date?: Date;
1926
+ /** Date format pattern */
1927
+ format?: string;
1928
+ }
1929
+ /**
1930
+ * Storage category-based path generation options
1931
+ */
1932
+ export interface StorageCategoryPathOptions {
1933
+ /** File category */
1934
+ category: FILE_CATEGORY;
1935
+ /** Filename */
1936
+ filename: string;
1937
+ /** Entity ID */
1938
+ entityId?: string;
1939
+ /** Additional path segments */
1940
+ segments?: string[];
1941
+ }
1942
+ /**
1943
+ * Storage flat path generation options
1944
+ */
1945
+ export interface StorageFlatPathOptions {
1946
+ /** Filename */
1947
+ filename: string;
1948
+ /** Base directory */
1949
+ baseDir?: string;
1950
+ /** Whether to include UUID */
1951
+ includeUuid?: boolean;
1952
+ /** Optional prefix */
1953
+ prefix?: string;
1954
+ }
1955
+ /**
1956
+ * Storage template variables for path generation
1957
+ */
1958
+ export interface StorageTemplateVariables {
1959
+ /** Variable values */
1960
+ [key: string]: string | number | undefined;
1961
+ }
1962
+ /**
1963
+ * Storage signed URL generation options
1964
+ */
1965
+ export interface StorageSignedUrlOptions {
1966
+ /** Expiration time in seconds */
1967
+ expiresIn: number;
1968
+ /** Optional IP address restriction */
1969
+ ipAddress?: string;
1970
+ /** Optional permissions (default: ['read']) */
1971
+ permissions?: Array<'read' | 'write' | 'delete'>;
1972
+ /** Hash algorithm for HMAC signature (default: 'sha256') */
1973
+ algorithm?: 'sha256' | 'sha384' | 'sha512';
1974
+ /** Content type */
1975
+ contentType?: string;
1976
+ /** Content disposition */
1977
+ contentDisposition?: string;
1978
+ /** Additional metadata */
1979
+ metadata?: Record<string, string>;
1980
+ }
1981
+ /**
1982
+ * Storage URL signature verification result
1983
+ */
1984
+ export interface StorageVerificationResult {
1985
+ /** Whether the signature is valid */
1986
+ valid: boolean;
1987
+ /** Error message if invalid */
1988
+ error?: string;
1989
+ /** Extracted permissions if valid */
1990
+ permissions?: Array<'read' | 'write' | 'delete'>;
1991
+ /** Expiration timestamp if valid */
1992
+ expiresAt?: number;
1993
+ }
1994
+ /**
1995
+ * Storage bucket information
1996
+ */
1997
+ export interface StorageBucketInfo {
1998
+ /** Bucket name */
1999
+ name: string;
2000
+ /** Bucket ID (if applicable) */
2001
+ id?: string;
2002
+ /** Whether bucket is public */
2003
+ public: boolean;
2004
+ /** Creation date */
2005
+ createdAt: Date;
2006
+ /** Last updated date */
2007
+ updatedAt?: Date;
2008
+ /** File size limit (bytes) */
2009
+ fileSizeLimit?: number;
2010
+ /** Allowed MIME types */
2011
+ allowedMimeTypes?: string[];
2012
+ /** Additional metadata */
2013
+ metadata?: Record<string, unknown>;
2014
+ }
2015
+ /**
2016
+ * Storage list buckets result
2017
+ */
2018
+ export interface StorageListBucketsResult {
2019
+ /** List of buckets */
2020
+ buckets: StorageBucketInfo[];
2021
+ /** Total count */
2022
+ count: number;
2023
+ }
2024
+ /**
2025
+ * Storage update bucket parameters
2026
+ */
2027
+ export interface StorageUpdateBucketParams {
2028
+ /** Bucket name */
2029
+ bucketName: string;
2030
+ /** Whether bucket is public */
2031
+ public?: boolean;
2032
+ /** File size limit (bytes) */
2033
+ fileSizeLimit?: number;
2034
+ /** Allowed MIME types */
2035
+ allowedMimeTypes?: string[];
2036
+ /** Additional metadata */
2037
+ metadata?: Record<string, unknown>;
2038
+ }
2039
+ /**
2040
+ * Storage list files parameters
2041
+ */
2042
+ export interface StorageListFilesParams {
2043
+ /** Bucket name */
2044
+ bucket: string;
2045
+ /** Path prefix to filter by */
2046
+ prefix?: string;
2047
+ /** Maximum number of files to return */
2048
+ limit?: number;
2049
+ /** Pagination offset */
2050
+ offset?: number;
2051
+ /** Sort field */
2052
+ sortBy?: 'name' | 'size' | 'createdAt' | 'updatedAt';
2053
+ /** Sort direction */
2054
+ sortOrder?: 'asc' | 'desc';
2055
+ /** Search query */
2056
+ search?: string;
2057
+ }
2058
+ /**
2059
+ * Storage file info for list results
2060
+ */
2061
+ export interface StorageFileInfo {
2062
+ /** File ID/path */
2063
+ id: string;
2064
+ /** File name */
2065
+ name: string;
2066
+ /** File size in bytes */
2067
+ size: number;
2068
+ /** MIME type */
2069
+ mimeType: string;
2070
+ /** Creation date */
2071
+ createdAt: Date;
2072
+ /** Last updated date */
2073
+ updatedAt?: Date;
2074
+ /** File metadata */
2075
+ metadata?: Record<string, unknown>;
2076
+ /** Public URL (if public) */
2077
+ publicUrl?: string;
2078
+ }
2079
+ /**
2080
+ * Storage list files result
2081
+ */
2082
+ export interface StorageListFilesResult {
2083
+ /** List of files */
2084
+ files: StorageFileInfo[];
2085
+ /** Total count */
2086
+ count: number;
2087
+ /** Has more files */
2088
+ hasMore: boolean;
2089
+ /** Next offset for pagination */
2090
+ nextOffset?: number;
2091
+ }
2092
+ /**
2093
+ * Storage move file parameters
2094
+ */
2095
+ export interface StorageMoveFileParams {
2096
+ /** Source bucket */
2097
+ sourceBucket: string;
2098
+ /** Source file path */
2099
+ sourcePath: string;
2100
+ /** Destination bucket */
2101
+ destinationBucket: string;
2102
+ /** Destination file path */
2103
+ destinationPath: string;
2104
+ /** Optional: Source adapter name */
2105
+ sourceAdapter?: string;
2106
+ /** Optional: Destination adapter name */
2107
+ destinationAdapter?: string;
2108
+ /** Skip specific plugins by name for this operation (e.g., ['virus-scanner', 'cdn-invalidator']) */
2109
+ skipPlugins?: readonly StorageKnownPluginName[];
2110
+ /** Only run these specific plugins for this operation (e.g., ['metadata-enricher']) */
2111
+ onlyPlugins?: readonly StorageKnownPluginName[];
2112
+ /** Custom metadata for plugins and tracking */
2113
+ customMetadata?: Record<string, unknown>;
2114
+ /** Bypass retention policy checks (requires admin privileges) */
2115
+ bypassRetention?: boolean;
2116
+ }
2117
+ /**
2118
+ * Storage copy file parameters
2119
+ */
2120
+ export interface StorageCopyFileParams {
2121
+ /** Source bucket */
2122
+ sourceBucket: string;
2123
+ /** Source file path */
2124
+ sourcePath: string;
2125
+ /** Destination bucket */
2126
+ destinationBucket: string;
2127
+ /** Destination file path */
2128
+ destinationPath: string;
2129
+ /** Optional: Source adapter name */
2130
+ sourceAdapter?: string;
2131
+ /** Optional: Destination adapter name */
2132
+ destinationAdapter?: string;
2133
+ /** Skip specific plugins by name for this operation (e.g., ['virus-scanner', 'cdn-invalidator']) */
2134
+ skipPlugins?: readonly StorageKnownPluginName[];
2135
+ /** Only run these specific plugins for this operation (e.g., ['metadata-enricher']) */
2136
+ onlyPlugins?: readonly StorageKnownPluginName[];
2137
+ /** Custom metadata for plugins and tracking */
2138
+ customMetadata?: Record<string, unknown>;
2139
+ }
2140
+ /**
2141
+ * Storage replace file parameters
2142
+ */
2143
+ export interface StorageReplaceFileParams {
2144
+ /** File ID or path to replace */
2145
+ fileId: string;
2146
+ /** New file buffer */
2147
+ file: globalThis.Buffer | globalThis.NodeJS.ReadableStream;
2148
+ /** Bucket name */
2149
+ bucket?: string;
2150
+ /** Adapter name */
2151
+ adapter?: string;
2152
+ /** Optional: New MIME type */
2153
+ mimeType?: string;
2154
+ /** Optional: Update metadata */
2155
+ metadata?: Record<string, unknown>;
2156
+ /** Skip specific plugins by name for this operation (e.g., ['virus-scanner', 'cdn-invalidator']) */
2157
+ skipPlugins?: readonly StorageKnownPluginName[];
2158
+ /** Only run these specific plugins for this operation (e.g., ['metadata-enricher']) */
2159
+ onlyPlugins?: readonly StorageKnownPluginName[];
2160
+ /** Custom metadata for plugins and tracking */
2161
+ customMetadata?: Record<string, unknown>;
2162
+ /** Bypass retention policy checks (requires admin privileges) */
2163
+ bypassRetention?: boolean;
2164
+ }
2165
+ /**
2166
+ * Storage signed upload URL parameters
2167
+ */
2168
+ export interface StorageSignedUploadUrlParams {
2169
+ /** Bucket name */
2170
+ bucket: string;
2171
+ /** File path */
2172
+ path: string;
2173
+ /** Expiry in seconds */
2174
+ expiresIn?: number;
2175
+ /** Content type */
2176
+ contentType?: string;
2177
+ /** File size limit */
2178
+ fileSizeLimit?: number;
2179
+ /** Optional: Adapter name */
2180
+ adapter?: string;
2181
+ /** Upsert (replace if exists) - WARNING: Bypasses immutability and retention checks */
2182
+ upsert?: boolean;
2183
+ /** User ID for audit trail (REQUIRED for compliance) */
2184
+ userId?: string;
2185
+ /** Additional metadata for compliance tracking */
2186
+ metadata?: Record<string, unknown>;
2187
+ /** Entity type (for compliance classification) */
2188
+ entityType?: string;
2189
+ /** Entity ID (for compliance classification) */
2190
+ entityId?: string;
2191
+ }
2192
+ /**
2193
+ * Storage signed upload URL result
2194
+ */
2195
+ export interface StorageSignedUploadUrlResult {
2196
+ /** Signed URL for upload */
2197
+ url: string;
2198
+ /** Upload token/ID */
2199
+ token: string;
2200
+ /** Expiry timestamp */
2201
+ expiresAt: Date;
2202
+ /** Additional fields for upload (e.g., form fields for S3) */
2203
+ fields?: Record<string, string>;
2204
+ }
2205
+ /**
2206
+ * Storage public URL parameters
2207
+ */
2208
+ export interface StoragePublicUrlParams {
2209
+ /** Bucket name */
2210
+ bucket: string;
2211
+ /** File path */
2212
+ path: string;
2213
+ /** Optional: Adapter name */
2214
+ adapter?: string;
2215
+ /** Optional: Download filename (for Content-Disposition) */
2216
+ download?: string;
2217
+ }
2218
+ /**
2219
+ * Storage bucket deletion result for batch operations
2220
+ */
2221
+ export interface StorageBucketDeletionResult {
2222
+ /** Whether the bucket has more objects to delete */
2223
+ hasMore: boolean;
2224
+ /** Continuation token for next batch */
2225
+ nextToken: string | undefined;
2226
+ }
2227
+ /**
2228
+ * Storage chunk extraction result
2229
+ */
2230
+ export interface StorageChunkExtractionResult {
2231
+ /** Extracted chunk buffer */
2232
+ chunk: globalThis.Buffer;
2233
+ /** End position in original buffer */
2234
+ end: number;
2235
+ }
2236
+ /**
2237
+ * Storage chunk upload part result
2238
+ */
2239
+ export interface StorageChunkUploadPartResult {
2240
+ /** ETag from upload */
2241
+ ETag: string;
2242
+ }