react-upload-pro 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,218 @@
1
+ /**
2
+ * Core type definitions for react-upload-pro.
3
+ * Public API types are stable; internal types prefixed with `Internal`.
4
+ */
5
+ type UploadStatus = 'idle' | 'queued' | 'uploading' | 'paused' | 'success' | 'error' | 'cancelled';
6
+ type UploadMode = 'manual' | 'instant' | 'auto' | 'queue';
7
+ type UploadStrategy = 'parallel' | 'sequential';
8
+ interface FileMetadata {
9
+ tags?: string[];
10
+ category?: string;
11
+ description?: string;
12
+ [key: string]: unknown;
13
+ }
14
+ /**
15
+ * Wrapper around the native File with upload-state tracking.
16
+ * `file` is the original File; everything else is library-managed.
17
+ */
18
+ interface UploadFile {
19
+ id: string;
20
+ file: File;
21
+ name: string;
22
+ size: number;
23
+ type: string;
24
+ /** Full webkitRelativePath when uploaded from a folder, otherwise empty. */
25
+ path: string;
26
+ status: UploadStatus;
27
+ /** 0..1 */
28
+ progress: number;
29
+ /** Bytes uploaded so far. */
30
+ bytesUploaded: number;
31
+ /** Upload speed in bytes/sec, averaged over a short window. */
32
+ speed: number;
33
+ /** ETA in seconds. Infinity until speed is known. */
34
+ eta: number;
35
+ error?: UploadError;
36
+ /** Server response after success. */
37
+ response?: unknown;
38
+ /** Object URL for preview, if generated. */
39
+ previewUrl?: string;
40
+ /** Time the file was added (ms). */
41
+ addedAt: number;
42
+ /** Time the upload started (ms). */
43
+ startedAt?: number;
44
+ /** Time the upload finished (ms). */
45
+ finishedAt?: number;
46
+ /** Number of retry attempts so far. */
47
+ attempts: number;
48
+ /** User-supplied metadata. */
49
+ metadata: FileMetadata;
50
+ /** AbortController for in-flight upload. */
51
+ controller?: AbortController;
52
+ /** For chunked uploads. */
53
+ chunks?: ChunkState[];
54
+ }
55
+ interface ChunkState {
56
+ index: number;
57
+ start: number;
58
+ end: number;
59
+ status: 'pending' | 'uploading' | 'success' | 'error';
60
+ attempts: number;
61
+ etag?: string;
62
+ }
63
+ type ValidationErrorCode = 'file-too-large' | 'file-too-small' | 'file-invalid-type' | 'too-many-files' | 'duplicate-file' | 'custom';
64
+ interface ValidationError {
65
+ code: ValidationErrorCode;
66
+ message: string;
67
+ file?: File;
68
+ }
69
+ interface UploadError {
70
+ code: string;
71
+ message: string;
72
+ cause?: unknown;
73
+ retryable: boolean;
74
+ }
75
+ type Accept = string | string[] | Record<string, string[]>;
76
+ interface ValidationConfig {
77
+ /** Accepted MIME types or extensions. `image/*`, `.pdf`, or { "image/*": [".png"] } */
78
+ accept?: Accept;
79
+ /** Min file size in bytes. */
80
+ minSize?: number;
81
+ /** Max file size in bytes. */
82
+ maxSize?: number;
83
+ /** Max number of files. */
84
+ maxFiles?: number;
85
+ /** If true, reject duplicate files (same name + size). */
86
+ rejectDuplicates?: boolean;
87
+ /** Custom validators run after built-ins. Return null for valid. */
88
+ validators?: Array<(file: File) => ValidationError | null | Promise<ValidationError | null>>;
89
+ }
90
+ interface UploaderConfig {
91
+ /** Endpoint to POST files to. Required unless `cloud` adapter is provided. */
92
+ endpoint?: string;
93
+ method?: 'POST' | 'PUT' | 'PATCH';
94
+ headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
95
+ /** FormData field name for the file. Default 'file'. */
96
+ fieldName?: string;
97
+ /** Extra form fields to include on each request. */
98
+ formData?: Record<string, string> | ((file: UploadFile) => Record<string, string>);
99
+ /** Send credentials (cookies) with the request. */
100
+ withCredentials?: boolean;
101
+ /** Max parallel uploads when strategy='parallel'. Default 3. */
102
+ concurrency?: number;
103
+ /** Sequential = one at a time. Parallel = up to `concurrency`. */
104
+ strategy?: UploadStrategy;
105
+ /** Upload mode. instant uploads as soon as added, manual waits for `start()`. */
106
+ mode?: UploadMode;
107
+ /** Number of retry attempts on retryable errors. */
108
+ retries?: number;
109
+ /** Backoff base in ms. Doubles each retry. */
110
+ retryBackoffMs?: number;
111
+ /** Chunk size in bytes. If > 0, files are chunked. */
112
+ chunkSize?: number;
113
+ /** Optional cloud adapter — overrides endpoint-based upload. */
114
+ cloud?: CloudAdapter;
115
+ /** Called to obtain an upload token / presigned URL per file. */
116
+ getUploadToken?: (file: UploadFile) => Promise<UploadTokenPayload>;
117
+ /** Hook to scan files for malware before upload. Throw or return error to reject. */
118
+ virusScan?: (file: UploadFile) => Promise<{
119
+ clean: boolean;
120
+ reason?: string;
121
+ }>;
122
+ }
123
+ interface UploadTokenPayload {
124
+ url: string;
125
+ method?: 'POST' | 'PUT' | 'PATCH';
126
+ headers?: Record<string, string>;
127
+ fields?: Record<string, string>;
128
+ }
129
+ /**
130
+ * A cloud adapter encapsulates direct-to-cloud upload logic.
131
+ * The adapter is responsible for the full request lifecycle including
132
+ * progress reporting via `onProgress`.
133
+ */
134
+ interface CloudAdapter {
135
+ name: string;
136
+ upload(file: UploadFile, callbacks: {
137
+ onProgress: (loaded: number, total: number) => void;
138
+ signal: AbortSignal;
139
+ }): Promise<CloudUploadResult>;
140
+ }
141
+ interface CloudUploadResult {
142
+ url: string;
143
+ key?: string;
144
+ etag?: string;
145
+ metadata?: Record<string, unknown>;
146
+ }
147
+ type DropzoneState = 'idle' | 'dragging' | 'drag-accept' | 'drag-reject';
148
+ interface DropzoneCallbacks {
149
+ /** Called whenever files are accepted (after validation). */
150
+ onDrop?: (accepted: UploadFile[], rejected: ValidationError[]) => void;
151
+ onDropAccepted?: (accepted: UploadFile[]) => void;
152
+ onDropRejected?: (rejected: ValidationError[]) => void;
153
+ onUploadStart?: (file: UploadFile) => void;
154
+ onUploadProgress?: (file: UploadFile) => void;
155
+ onUploadSuccess?: (file: UploadFile) => void;
156
+ onUploadError?: (file: UploadFile, error: UploadError) => void;
157
+ onRetry?: (file: UploadFile) => void;
158
+ onPause?: (file: UploadFile) => void;
159
+ onResume?: (file: UploadFile) => void;
160
+ onRemove?: (file: UploadFile) => void;
161
+ onAllComplete?: (files: UploadFile[]) => void;
162
+ }
163
+ interface DropzoneOptions extends ValidationConfig, UploaderConfig, DropzoneCallbacks {
164
+ /** Allow multiple files. Default true. */
165
+ multiple?: boolean;
166
+ /** Allow directory upload via webkitdirectory. Default false. */
167
+ directory?: boolean;
168
+ /** Disable interaction. */
169
+ disabled?: boolean;
170
+ /** Allow paste from clipboard. Default true. */
171
+ clipboard?: boolean;
172
+ /** Prevent drag-drop events from bubbling. Default true. */
173
+ noBubble?: boolean;
174
+ /** Auto-revoke object URLs on remove. Default true. */
175
+ autoRevoke?: boolean;
176
+ }
177
+ type Locale = 'en' | 'hi' | 'gu' | 'fr' | 'de' | 'ar' | 'zh' | 'es' | 'pt' | 'ru' | 'ja' | 'ko' | 'it' | 'tr' | 'id' | 'bn' | 'ur' | 'nl' | 'pl' | 'vi' | 'th' | 'he' | 'fa';
178
+ interface Translations {
179
+ dropHere: string;
180
+ dragOrClick: string;
181
+ browse: string;
182
+ uploading: string;
183
+ paused: string;
184
+ success: string;
185
+ error: string;
186
+ retry: string;
187
+ pause: string;
188
+ resume: string;
189
+ cancel: string;
190
+ remove: string;
191
+ removeAll: string;
192
+ preview: string;
193
+ download: string;
194
+ edit: string;
195
+ save: string;
196
+ fullscreen: string;
197
+ rename: string;
198
+ tags: string;
199
+ description: string;
200
+ category: string;
201
+ addTag: string;
202
+ fileTooLarge: string;
203
+ fileTooSmall: string;
204
+ invalidType: string;
205
+ tooManyFiles: string;
206
+ duplicateFile: string;
207
+ speed: string;
208
+ eta: string;
209
+ ofText: string;
210
+ filesText: string;
211
+ bytes: string;
212
+ kb: string;
213
+ mb: string;
214
+ gb: string;
215
+ }
216
+ type Theme = 'light' | 'dark' | 'auto';
217
+
218
+ export type { Accept as A, ChunkState as C, DropzoneCallbacks as D, FileMetadata as F, Locale as L, Theme as T, UploadError as U, ValidationConfig as V, CloudAdapter as a, CloudUploadResult as b, DropzoneOptions as c, DropzoneState as d, Translations as e, UploadFile as f, UploadMode as g, UploadStatus as h, UploadStrategy as i, UploadTokenPayload as j, UploaderConfig as k, ValidationError as l, ValidationErrorCode as m };
@@ -0,0 +1,218 @@
1
+ /**
2
+ * Core type definitions for react-upload-pro.
3
+ * Public API types are stable; internal types prefixed with `Internal`.
4
+ */
5
+ type UploadStatus = 'idle' | 'queued' | 'uploading' | 'paused' | 'success' | 'error' | 'cancelled';
6
+ type UploadMode = 'manual' | 'instant' | 'auto' | 'queue';
7
+ type UploadStrategy = 'parallel' | 'sequential';
8
+ interface FileMetadata {
9
+ tags?: string[];
10
+ category?: string;
11
+ description?: string;
12
+ [key: string]: unknown;
13
+ }
14
+ /**
15
+ * Wrapper around the native File with upload-state tracking.
16
+ * `file` is the original File; everything else is library-managed.
17
+ */
18
+ interface UploadFile {
19
+ id: string;
20
+ file: File;
21
+ name: string;
22
+ size: number;
23
+ type: string;
24
+ /** Full webkitRelativePath when uploaded from a folder, otherwise empty. */
25
+ path: string;
26
+ status: UploadStatus;
27
+ /** 0..1 */
28
+ progress: number;
29
+ /** Bytes uploaded so far. */
30
+ bytesUploaded: number;
31
+ /** Upload speed in bytes/sec, averaged over a short window. */
32
+ speed: number;
33
+ /** ETA in seconds. Infinity until speed is known. */
34
+ eta: number;
35
+ error?: UploadError;
36
+ /** Server response after success. */
37
+ response?: unknown;
38
+ /** Object URL for preview, if generated. */
39
+ previewUrl?: string;
40
+ /** Time the file was added (ms). */
41
+ addedAt: number;
42
+ /** Time the upload started (ms). */
43
+ startedAt?: number;
44
+ /** Time the upload finished (ms). */
45
+ finishedAt?: number;
46
+ /** Number of retry attempts so far. */
47
+ attempts: number;
48
+ /** User-supplied metadata. */
49
+ metadata: FileMetadata;
50
+ /** AbortController for in-flight upload. */
51
+ controller?: AbortController;
52
+ /** For chunked uploads. */
53
+ chunks?: ChunkState[];
54
+ }
55
+ interface ChunkState {
56
+ index: number;
57
+ start: number;
58
+ end: number;
59
+ status: 'pending' | 'uploading' | 'success' | 'error';
60
+ attempts: number;
61
+ etag?: string;
62
+ }
63
+ type ValidationErrorCode = 'file-too-large' | 'file-too-small' | 'file-invalid-type' | 'too-many-files' | 'duplicate-file' | 'custom';
64
+ interface ValidationError {
65
+ code: ValidationErrorCode;
66
+ message: string;
67
+ file?: File;
68
+ }
69
+ interface UploadError {
70
+ code: string;
71
+ message: string;
72
+ cause?: unknown;
73
+ retryable: boolean;
74
+ }
75
+ type Accept = string | string[] | Record<string, string[]>;
76
+ interface ValidationConfig {
77
+ /** Accepted MIME types or extensions. `image/*`, `.pdf`, or { "image/*": [".png"] } */
78
+ accept?: Accept;
79
+ /** Min file size in bytes. */
80
+ minSize?: number;
81
+ /** Max file size in bytes. */
82
+ maxSize?: number;
83
+ /** Max number of files. */
84
+ maxFiles?: number;
85
+ /** If true, reject duplicate files (same name + size). */
86
+ rejectDuplicates?: boolean;
87
+ /** Custom validators run after built-ins. Return null for valid. */
88
+ validators?: Array<(file: File) => ValidationError | null | Promise<ValidationError | null>>;
89
+ }
90
+ interface UploaderConfig {
91
+ /** Endpoint to POST files to. Required unless `cloud` adapter is provided. */
92
+ endpoint?: string;
93
+ method?: 'POST' | 'PUT' | 'PATCH';
94
+ headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
95
+ /** FormData field name for the file. Default 'file'. */
96
+ fieldName?: string;
97
+ /** Extra form fields to include on each request. */
98
+ formData?: Record<string, string> | ((file: UploadFile) => Record<string, string>);
99
+ /** Send credentials (cookies) with the request. */
100
+ withCredentials?: boolean;
101
+ /** Max parallel uploads when strategy='parallel'. Default 3. */
102
+ concurrency?: number;
103
+ /** Sequential = one at a time. Parallel = up to `concurrency`. */
104
+ strategy?: UploadStrategy;
105
+ /** Upload mode. instant uploads as soon as added, manual waits for `start()`. */
106
+ mode?: UploadMode;
107
+ /** Number of retry attempts on retryable errors. */
108
+ retries?: number;
109
+ /** Backoff base in ms. Doubles each retry. */
110
+ retryBackoffMs?: number;
111
+ /** Chunk size in bytes. If > 0, files are chunked. */
112
+ chunkSize?: number;
113
+ /** Optional cloud adapter — overrides endpoint-based upload. */
114
+ cloud?: CloudAdapter;
115
+ /** Called to obtain an upload token / presigned URL per file. */
116
+ getUploadToken?: (file: UploadFile) => Promise<UploadTokenPayload>;
117
+ /** Hook to scan files for malware before upload. Throw or return error to reject. */
118
+ virusScan?: (file: UploadFile) => Promise<{
119
+ clean: boolean;
120
+ reason?: string;
121
+ }>;
122
+ }
123
+ interface UploadTokenPayload {
124
+ url: string;
125
+ method?: 'POST' | 'PUT' | 'PATCH';
126
+ headers?: Record<string, string>;
127
+ fields?: Record<string, string>;
128
+ }
129
+ /**
130
+ * A cloud adapter encapsulates direct-to-cloud upload logic.
131
+ * The adapter is responsible for the full request lifecycle including
132
+ * progress reporting via `onProgress`.
133
+ */
134
+ interface CloudAdapter {
135
+ name: string;
136
+ upload(file: UploadFile, callbacks: {
137
+ onProgress: (loaded: number, total: number) => void;
138
+ signal: AbortSignal;
139
+ }): Promise<CloudUploadResult>;
140
+ }
141
+ interface CloudUploadResult {
142
+ url: string;
143
+ key?: string;
144
+ etag?: string;
145
+ metadata?: Record<string, unknown>;
146
+ }
147
+ type DropzoneState = 'idle' | 'dragging' | 'drag-accept' | 'drag-reject';
148
+ interface DropzoneCallbacks {
149
+ /** Called whenever files are accepted (after validation). */
150
+ onDrop?: (accepted: UploadFile[], rejected: ValidationError[]) => void;
151
+ onDropAccepted?: (accepted: UploadFile[]) => void;
152
+ onDropRejected?: (rejected: ValidationError[]) => void;
153
+ onUploadStart?: (file: UploadFile) => void;
154
+ onUploadProgress?: (file: UploadFile) => void;
155
+ onUploadSuccess?: (file: UploadFile) => void;
156
+ onUploadError?: (file: UploadFile, error: UploadError) => void;
157
+ onRetry?: (file: UploadFile) => void;
158
+ onPause?: (file: UploadFile) => void;
159
+ onResume?: (file: UploadFile) => void;
160
+ onRemove?: (file: UploadFile) => void;
161
+ onAllComplete?: (files: UploadFile[]) => void;
162
+ }
163
+ interface DropzoneOptions extends ValidationConfig, UploaderConfig, DropzoneCallbacks {
164
+ /** Allow multiple files. Default true. */
165
+ multiple?: boolean;
166
+ /** Allow directory upload via webkitdirectory. Default false. */
167
+ directory?: boolean;
168
+ /** Disable interaction. */
169
+ disabled?: boolean;
170
+ /** Allow paste from clipboard. Default true. */
171
+ clipboard?: boolean;
172
+ /** Prevent drag-drop events from bubbling. Default true. */
173
+ noBubble?: boolean;
174
+ /** Auto-revoke object URLs on remove. Default true. */
175
+ autoRevoke?: boolean;
176
+ }
177
+ type Locale = 'en' | 'hi' | 'gu' | 'fr' | 'de' | 'ar' | 'zh' | 'es' | 'pt' | 'ru' | 'ja' | 'ko' | 'it' | 'tr' | 'id' | 'bn' | 'ur' | 'nl' | 'pl' | 'vi' | 'th' | 'he' | 'fa';
178
+ interface Translations {
179
+ dropHere: string;
180
+ dragOrClick: string;
181
+ browse: string;
182
+ uploading: string;
183
+ paused: string;
184
+ success: string;
185
+ error: string;
186
+ retry: string;
187
+ pause: string;
188
+ resume: string;
189
+ cancel: string;
190
+ remove: string;
191
+ removeAll: string;
192
+ preview: string;
193
+ download: string;
194
+ edit: string;
195
+ save: string;
196
+ fullscreen: string;
197
+ rename: string;
198
+ tags: string;
199
+ description: string;
200
+ category: string;
201
+ addTag: string;
202
+ fileTooLarge: string;
203
+ fileTooSmall: string;
204
+ invalidType: string;
205
+ tooManyFiles: string;
206
+ duplicateFile: string;
207
+ speed: string;
208
+ eta: string;
209
+ ofText: string;
210
+ filesText: string;
211
+ bytes: string;
212
+ kb: string;
213
+ mb: string;
214
+ gb: string;
215
+ }
216
+ type Theme = 'light' | 'dark' | 'auto';
217
+
218
+ export type { Accept as A, ChunkState as C, DropzoneCallbacks as D, FileMetadata as F, Locale as L, Theme as T, UploadError as U, ValidationConfig as V, CloudAdapter as a, CloudUploadResult as b, DropzoneOptions as c, DropzoneState as d, Translations as e, UploadFile as f, UploadMode as g, UploadStatus as h, UploadStrategy as i, UploadTokenPayload as j, UploaderConfig as k, ValidationError as l, ValidationErrorCode as m };