@plyaz/types 1.30.0 → 1.31.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.
@@ -4,10 +4,10 @@
4
4
  */
5
5
  import type { LoggerInterface } from '../logger/types';
6
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, TEMPLATE_VARIABLE_TYPE, TEMPLATE_DOCUMENT_TYPE } from './enums';
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, TEMPLATE_VARIABLE_TYPE, TEMPLATE_DOCUMENT_TYPE, STORAGE_WEBHOOK_EVENT_TYPE } from './enums';
8
8
  import type { StorageSoftDeleteMetadata, StorageDeleteComplianceOptions, StorageComplianceConfig, StorageRetentionPolicy } from './compliance';
9
9
  import type { PluginRegistryConfig, StorageKnownPluginName, StoragePlugin } from './plugins';
10
- import type { StorageBaseWebhookAdapterConfig, StorageWebhookAdapter, StorageWebhookManagerConfig } from './webhooks';
10
+ import type { StorageBaseWebhookAdapterConfig, StorageWebhookAdapter, StorageWebhookManagerConfig, StorageWebhookPayload, StorageWebhookProcessingResult } from './webhooks';
11
11
  /**
12
12
  * Simplified API client configuration for storage adapters
13
13
  * Avoids direct dependency on full ApiConfig to prevent version conflicts
@@ -2575,3 +2575,110 @@ export type StorageTemplateInvoiceTotalArgs = [
2575
2575
  shippingCost?: number | unknown,
2576
2576
  calcType?: string | unknown
2577
2577
  ];
2578
+ /**
2579
+ * StorageServiceInstance - Main public API interface
2580
+ *
2581
+ * This interface defines the public contract for StorageService.
2582
+ * The StorageService class in @plyaz/storage implements this interface.
2583
+ *
2584
+ * Used by:
2585
+ * - Core's StorageService wrapper (Proxy-based method forwarding)
2586
+ * - Domain services that need storage operations
2587
+ * - Type-safe dependency injection
2588
+ */
2589
+ export interface StorageServiceInstance {
2590
+ /** Upload a file to storage (supports template-based generation) */
2591
+ uploadFile(params: UploadParams): Promise<UploadResult>;
2592
+ /** Upload multiple files with concurrency control */
2593
+ uploadMultipleFiles(files: UploadParams[], options?: {
2594
+ concurrency?: number;
2595
+ useQueue?: boolean;
2596
+ continueOnError?: boolean;
2597
+ }): Promise<UploadResult[]>;
2598
+ /** Download a file from storage */
2599
+ downloadFile(params: DownloadParams): Promise<DownloadResult>;
2600
+ /** Delete a file from storage */
2601
+ deleteFile(params: DeleteParams): Promise<FileDeleteResult>;
2602
+ /** Restore a soft-deleted file */
2603
+ restoreFile(fileId: string): Promise<FileMetadata>;
2604
+ /** Update an existing file */
2605
+ updateFile(params: UpdateFileParams): Promise<UploadResult>;
2606
+ /** Generate a document from template (returns Buffer, no upload) */
2607
+ generateFile(params: GenerateFileParams): Promise<globalThis.Buffer>;
2608
+ /** Generate a document and save to a file path */
2609
+ generateFileToPath(params: GenerateFileToPathParams): Promise<GenerateFileToPathResult>;
2610
+ /** Get a signed URL for temporary access */
2611
+ getSignedUrl(options: PresignedUrlOptions): Promise<PresignedUrlResult>;
2612
+ /** Create a signed URL for direct upload */
2613
+ createSignedUploadUrl(params: StorageSignedUploadUrlParams): Promise<StorageSignedUploadUrlResult>;
2614
+ /** Get public URL for a file */
2615
+ getPublicUrl(params: StoragePublicUrlParams): Promise<string>;
2616
+ /** Move a file within storage */
2617
+ moveFile(params: StorageMoveFileParams): Promise<FileMetadata>;
2618
+ /** Copy a file within storage */
2619
+ copyFile(params: StorageCopyFileParams): Promise<FileMetadata>;
2620
+ /** Replace a file in storage */
2621
+ replaceFile(params: StorageReplaceFileParams): Promise<FileMetadata>;
2622
+ /** List all buckets */
2623
+ listBuckets(adapterName?: string): Promise<StorageListBucketsResult>;
2624
+ /** Get bucket info */
2625
+ getBucket(bucketName: string, adapterName?: string): Promise<StorageBucketInfo>;
2626
+ /** Update bucket configuration */
2627
+ updateBucket(params: StorageUpdateBucketParams, adapterName?: string): Promise<void>;
2628
+ /** Delete multiple buckets */
2629
+ deleteBuckets(bucketNames: string[], adapterName?: string): Promise<{
2630
+ deleted: string[];
2631
+ failed: Array<{
2632
+ bucket: string;
2633
+ error: string;
2634
+ adapter?: string;
2635
+ }>;
2636
+ }>;
2637
+ /** List files in storage */
2638
+ listFiles(params: StorageListFilesParams): Promise<StorageListFilesResult>;
2639
+ /** Get health summary for all adapters */
2640
+ getHealthSummary(): unknown;
2641
+ /** Get event statistics */
2642
+ getEventStatistics(): unknown;
2643
+ /** Check health of all adapters */
2644
+ checkAllAdaptersHealth(): Promise<void>;
2645
+ /** Queue multiple files for bulk upload */
2646
+ queueBulkUpload(files: Array<UploadParams & {
2647
+ priority?: 'high' | 'normal' | 'low';
2648
+ }>): Promise<void>;
2649
+ /** Queue a document generation job */
2650
+ queueDocumentGeneration(options: {
2651
+ templateId: string;
2652
+ data: Record<string, unknown>;
2653
+ outputOptions: Omit<UploadParams, 'file' | 'templateId' | 'templateData'>;
2654
+ priority?: 'high' | 'normal' | 'low';
2655
+ }): Promise<void>;
2656
+ /** Start the queue processor */
2657
+ startQueue(): void;
2658
+ /** Stop the queue processor */
2659
+ stopQueue(): Promise<void>;
2660
+ /** Get queue statistics */
2661
+ getQueueStatistics(): StorageQueueStatistics;
2662
+ /** Get the template engine instance */
2663
+ getTemplateEngine(): unknown;
2664
+ /** Get the compliance manager instance */
2665
+ getComplianceManager(): unknown;
2666
+ /** Check if compliance is enabled */
2667
+ isComplianceEnabled(): boolean;
2668
+ /** Get the webhook manager instance */
2669
+ getWebhookManager(): unknown;
2670
+ /** Check if webhooks are enabled */
2671
+ isWebhooksEnabled(): boolean;
2672
+ /** Register a webhook adapter */
2673
+ registerWebhookAdapter(adapter: StorageWebhookAdapter): void;
2674
+ /** Handle incoming webhook */
2675
+ handleWebhook(providerName: string, eventType: STORAGE_WEBHOOK_EVENT_TYPE | string, payload: StorageWebhookPayload<unknown>): Promise<StorageWebhookProcessingResult>;
2676
+ /** Subscribe to storage events (alias for on) */
2677
+ onEvent(eventType: STORAGE_EVENT_TYPE, handler: (payload: StorageEventPayload) => void | Promise<void>): () => void;
2678
+ /** Subscribe to storage events */
2679
+ on(eventType: STORAGE_EVENT_TYPE, handler: (payload: StorageEventPayload) => void | Promise<void>): () => void;
2680
+ /** Unsubscribe from storage events */
2681
+ off(eventType: STORAGE_EVENT_TYPE, handler: (payload: StorageEventPayload) => void | Promise<void>): void;
2682
+ /** Cleanup and destroy the service */
2683
+ destroy(): Promise<void>;
2684
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Files Store Types
3
+ *
4
+ * Store types for files/media domain.
5
+ */
6
+ export type { FilesStoreItem, GeneratedFileItem, FilesFrontendStoreState, FilesFrontendStoreData, FilesFrontendStoreActions, FilesFrontendStoreSlice, FilesStoreSelectors, } from './types';
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Files Store Types
3
+ *
4
+ * Store state, actions, and slice types for files/media.
5
+ * Domain types are in @plyaz/types/core/domain/files.
6
+ * API types are in @plyaz/types/api/endpoints/files.
7
+ */
8
+ import type { CoreBaseFrontendStore } from '../../core/frontend';
9
+ import type { FilesEntity, FileType } from '../../core/domain/files';
10
+ /**
11
+ * Serializable store item for files
12
+ */
13
+ export interface FilesStoreItem {
14
+ id: string;
15
+ key: string;
16
+ filename: string;
17
+ mimeType: string;
18
+ size: number;
19
+ url?: string;
20
+ publicUrl?: string;
21
+ bucket: string;
22
+ entityType?: string;
23
+ entityId?: string;
24
+ category?: string;
25
+ uploadedAt: string;
26
+ type: FileType;
27
+ isImage: boolean;
28
+ isVideo: boolean;
29
+ isDocument: boolean;
30
+ isAudio: boolean;
31
+ }
32
+ /**
33
+ * Generated document item (not uploaded to storage)
34
+ */
35
+ export interface GeneratedFileItem {
36
+ id: string;
37
+ templateId: string;
38
+ buffer: string;
39
+ size: number;
40
+ mimeType: string;
41
+ filename: string;
42
+ generatedAt: string;
43
+ }
44
+ /**
45
+ * Files store state
46
+ */
47
+ export interface FilesFrontendStoreState {
48
+ filesList: FilesEntity[];
49
+ uploadsList: FilesEntity[];
50
+ generatedFilesList: GeneratedFileItem[];
51
+ lastUpload: FilesEntity | null;
52
+ lastGenerated: GeneratedFileItem | null;
53
+ filesCount: number;
54
+ uploadsCount: number;
55
+ isLoading: boolean;
56
+ isUploading: boolean;
57
+ isGenerating: boolean;
58
+ }
59
+ /**
60
+ * Files store data for setData()
61
+ */
62
+ export interface FilesFrontendStoreData {
63
+ filesList: FilesEntity[];
64
+ uploadsList?: FilesEntity[];
65
+ generatedFilesList?: GeneratedFileItem[];
66
+ lastUpload?: FilesEntity | null;
67
+ lastGenerated?: GeneratedFileItem | null;
68
+ }
69
+ /**
70
+ * Files store actions
71
+ *
72
+ * Note: No update action since there's no update endpoint in the API.
73
+ * Files are immutable once uploaded - only metadata changes via storage service.
74
+ */
75
+ export interface FilesFrontendStoreActions extends CoreBaseFrontendStore<FilesFrontendStoreData> {
76
+ addFile: (file: FilesEntity) => void;
77
+ removeFile: (id: string) => void;
78
+ clearFiles: () => void;
79
+ addUpload: (upload: FilesEntity) => void;
80
+ removeUpload: (id: string) => void;
81
+ clearUploads: () => void;
82
+ addGenerated: (file: GeneratedFileItem) => void;
83
+ removeGenerated: (id: string) => void;
84
+ clearGenerated: () => void;
85
+ setLoading: (isLoading: boolean) => void;
86
+ setUploading: (isUploading: boolean) => void;
87
+ setGenerating: (isGenerating: boolean) => void;
88
+ reset: () => void;
89
+ }
90
+ /**
91
+ * Complete files store slice
92
+ */
93
+ export interface FilesFrontendStoreSlice extends FilesFrontendStoreState, FilesFrontendStoreActions {
94
+ }
95
+ export interface FilesStoreSelectors {
96
+ selectFiles: (state: FilesFrontendStoreState) => FilesEntity[];
97
+ selectUploads: (state: FilesFrontendStoreState) => FilesEntity[];
98
+ selectGenerated: (state: FilesFrontendStoreState) => GeneratedFileItem[];
99
+ selectLastUpload: (state: FilesFrontendStoreState) => FilesEntity | null;
100
+ selectLastGenerated: (state: FilesFrontendStoreState) => GeneratedFileItem | null;
101
+ selectIsLoading: (state: FilesFrontendStoreState) => boolean;
102
+ selectIsUploading: (state: FilesFrontendStoreState) => boolean;
103
+ selectFilesCount: (state: FilesFrontendStoreState) => number;
104
+ selectUploadsCount: (state: FilesFrontendStoreState) => number;
105
+ selectFileById: (state: FilesFrontendStoreState, id: string) => FilesEntity | undefined;
106
+ selectFilesByType: (state: FilesFrontendStoreState, type: FileType) => FilesEntity[];
107
+ }
@@ -1,3 +1,4 @@
1
1
  export type * from './types';
2
2
  export { STORE_KEYS, ALL_STORE_KEYS } from './keys';
3
3
  export type { StoreKey } from './keys';
4
+ export type * from './files';
@@ -9,6 +9,7 @@
9
9
  import type { SerializedError, ErrorStoreActions, ErrorStoreSlice } from '../errors/store';
10
10
  import type { FeatureFlagStoreState, FeatureFlagStoreSlice } from '../features/feature-flag/store.types';
11
11
  import type { ExampleFrontendStoreSlice } from '../examples';
12
+ import type { FilesFrontendStoreSlice } from './files/types';
12
13
  /**
13
14
  * Configuration for creating an error store.
14
15
  */
@@ -85,6 +86,8 @@ export interface RootStoreSlice {
85
86
  featureFlags: FeatureFlagStoreSlice;
86
87
  /** Example domain slice */
87
88
  example: ExampleFrontendStoreSlice;
89
+ /** Files/media domain slice */
90
+ files: FilesFrontendStoreSlice;
88
91
  }
89
92
  /**
90
93
  * Type-safe store registry interface.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plyaz/types",
3
- "version": "1.30.0",
3
+ "version": "1.31.1",
4
4
  "author": "Redeemer Pace",
5
5
  "license": "ISC",
6
6
  "description": "Provides shared TypeScript types and schema utilities for validation and parsing in the @playz ecosystem.",