@kumix/storage 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.
- package/README.md +291 -0
- package/dist/cloudinary.d.ts +93 -0
- package/dist/cloudinary.d.ts.map +1 -0
- package/dist/cloudinary.js +516 -0
- package/dist/cloudinary.js.map +1 -0
- package/dist/config-J6AdDh_c.d.ts +594 -0
- package/dist/config-J6AdDh_c.d.ts.map +1 -0
- package/dist/config-t-NVJICl.js +410 -0
- package/dist/config-t-NVJICl.js.map +1 -0
- package/dist/helpers.d.ts +764 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +1042 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/s3.d.ts +109 -0
- package/dist/s3.d.ts.map +1 -0
- package/dist/s3.js +779 -0
- package/dist/s3.js.map +1 -0
- package/package.json +94 -0
|
@@ -0,0 +1,594 @@
|
|
|
1
|
+
//#region src/types/base.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Base storage types and configurations
|
|
4
|
+
* Defines core types for storage providers, configurations, and file information
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* S3-compatible provider types
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
type S3ProviderType = "aws" | "cloudflare-r2" | "minio" | "digitalocean" | "supabase" | "custom";
|
|
11
|
+
/**
|
|
12
|
+
* All supported storage provider types
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
type StorageProvider = S3ProviderType | "cloudinary";
|
|
16
|
+
/**
|
|
17
|
+
* Union type for all storage configurations
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
type StorageConfig = S3Config | CloudinaryConfig;
|
|
21
|
+
/**
|
|
22
|
+
* S3-compatible storage configuration
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
interface S3Config {
|
|
26
|
+
/** S3-compatible provider type */
|
|
27
|
+
provider: S3ProviderType;
|
|
28
|
+
/** AWS region or provider-specific region */
|
|
29
|
+
region: string;
|
|
30
|
+
/** Bucket name */
|
|
31
|
+
bucket: string;
|
|
32
|
+
/** Access key ID for authentication */
|
|
33
|
+
accessKeyId: string;
|
|
34
|
+
/** Secret access key for authentication */
|
|
35
|
+
secretAccessKey: string;
|
|
36
|
+
/** Custom endpoint for S3-compatible services (MinIO, R2, etc.) */
|
|
37
|
+
endpoint?: string;
|
|
38
|
+
/** Force path style for services like MinIO */
|
|
39
|
+
forcePathStyle?: boolean;
|
|
40
|
+
/** Base URL for public access (CDN, custom domain) */
|
|
41
|
+
publicUrl?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Cloudinary storage configuration
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
interface CloudinaryConfig {
|
|
48
|
+
/** Provider type (always 'cloudinary') */
|
|
49
|
+
provider: "cloudinary";
|
|
50
|
+
/** Cloudinary cloud name */
|
|
51
|
+
cloudName: string;
|
|
52
|
+
/** Cloudinary API key */
|
|
53
|
+
apiKey: string;
|
|
54
|
+
/** Cloudinary API secret */
|
|
55
|
+
apiSecret: string;
|
|
56
|
+
/** Use HTTPS for URLs (default: true) */
|
|
57
|
+
secure?: boolean;
|
|
58
|
+
/** Default upload folder */
|
|
59
|
+
folder?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* File information structure
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
interface FileInfo {
|
|
66
|
+
/** File key/path */
|
|
67
|
+
key: string;
|
|
68
|
+
/** File size in bytes */
|
|
69
|
+
size: number;
|
|
70
|
+
/** Last modified date */
|
|
71
|
+
lastModified: Date;
|
|
72
|
+
/** Entity tag for caching */
|
|
73
|
+
etag: string;
|
|
74
|
+
/** MIME content type */
|
|
75
|
+
contentType?: string;
|
|
76
|
+
/** Custom metadata */
|
|
77
|
+
metadata?: Record<string, string>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Folder information structure
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
interface FolderInfo {
|
|
84
|
+
/** Folder name */
|
|
85
|
+
name: string;
|
|
86
|
+
/** Full folder path */
|
|
87
|
+
path: string;
|
|
88
|
+
/** Total size of all files in folder */
|
|
89
|
+
size: number;
|
|
90
|
+
/** Number of files in folder */
|
|
91
|
+
fileCount: number;
|
|
92
|
+
/** Last modified date */
|
|
93
|
+
lastModified: Date;
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/types/file-operations.d.ts
|
|
97
|
+
interface UploadOptions {
|
|
98
|
+
key: string;
|
|
99
|
+
file: Buffer | Uint8Array | string;
|
|
100
|
+
contentType?: string;
|
|
101
|
+
metadata?: Record<string, string>;
|
|
102
|
+
cacheControl?: string;
|
|
103
|
+
contentDisposition?: string;
|
|
104
|
+
acl?: "private" | "public-read" | "public-read-write";
|
|
105
|
+
expires?: Date;
|
|
106
|
+
}
|
|
107
|
+
interface UploadResult {
|
|
108
|
+
success: boolean;
|
|
109
|
+
key?: string;
|
|
110
|
+
url?: string;
|
|
111
|
+
publicUrl?: string;
|
|
112
|
+
etag?: string;
|
|
113
|
+
size?: number;
|
|
114
|
+
error?: string;
|
|
115
|
+
}
|
|
116
|
+
interface DownloadOptions {
|
|
117
|
+
key: string;
|
|
118
|
+
range?: string;
|
|
119
|
+
}
|
|
120
|
+
interface DownloadResult {
|
|
121
|
+
success: boolean;
|
|
122
|
+
content?: Buffer;
|
|
123
|
+
data?: Buffer;
|
|
124
|
+
contentType?: string;
|
|
125
|
+
contentLength?: number;
|
|
126
|
+
lastModified?: Date;
|
|
127
|
+
etag?: string;
|
|
128
|
+
metadata?: Record<string, string>;
|
|
129
|
+
error?: string;
|
|
130
|
+
}
|
|
131
|
+
interface DeleteOptions {
|
|
132
|
+
key: string;
|
|
133
|
+
}
|
|
134
|
+
interface DeleteResult {
|
|
135
|
+
success: boolean;
|
|
136
|
+
error?: string;
|
|
137
|
+
}
|
|
138
|
+
interface BatchDeleteOptions {
|
|
139
|
+
keys: string[];
|
|
140
|
+
}
|
|
141
|
+
interface BatchDeleteResult {
|
|
142
|
+
success: boolean;
|
|
143
|
+
deleted?: string[];
|
|
144
|
+
errors?: Array<{
|
|
145
|
+
key: string;
|
|
146
|
+
error: string;
|
|
147
|
+
}>;
|
|
148
|
+
}
|
|
149
|
+
interface CopyOptions {
|
|
150
|
+
sourceKey: string;
|
|
151
|
+
destinationKey: string;
|
|
152
|
+
metadata?: Record<string, string>;
|
|
153
|
+
metadataDirective?: "COPY" | "REPLACE";
|
|
154
|
+
}
|
|
155
|
+
interface CopyResult {
|
|
156
|
+
success: boolean;
|
|
157
|
+
etag?: string;
|
|
158
|
+
error?: string;
|
|
159
|
+
}
|
|
160
|
+
interface MoveOptions {
|
|
161
|
+
sourceKey: string;
|
|
162
|
+
destinationKey: string;
|
|
163
|
+
metadata?: Record<string, string>;
|
|
164
|
+
metadataDirective?: "COPY" | "REPLACE";
|
|
165
|
+
}
|
|
166
|
+
interface MoveResult {
|
|
167
|
+
success: boolean;
|
|
168
|
+
etag?: string;
|
|
169
|
+
error?: string;
|
|
170
|
+
}
|
|
171
|
+
type DuplicateOptions = CopyOptions;
|
|
172
|
+
type DuplicateResult = CopyResult;
|
|
173
|
+
interface ExistsResult {
|
|
174
|
+
exists: boolean;
|
|
175
|
+
fileInfo?: FileInfo;
|
|
176
|
+
error?: string;
|
|
177
|
+
}
|
|
178
|
+
interface ListOptions {
|
|
179
|
+
prefix?: string;
|
|
180
|
+
delimiter?: string;
|
|
181
|
+
maxKeys?: number;
|
|
182
|
+
continuationToken?: string;
|
|
183
|
+
}
|
|
184
|
+
interface ListResult {
|
|
185
|
+
success: boolean;
|
|
186
|
+
files?: FileInfo[];
|
|
187
|
+
isTruncated?: boolean;
|
|
188
|
+
nextContinuationToken?: string;
|
|
189
|
+
commonPrefixes?: string[];
|
|
190
|
+
error?: string;
|
|
191
|
+
}
|
|
192
|
+
interface PresignedUrlOptions {
|
|
193
|
+
key: string;
|
|
194
|
+
operation: "get" | "put";
|
|
195
|
+
expiresIn?: number;
|
|
196
|
+
contentType?: string;
|
|
197
|
+
}
|
|
198
|
+
interface PresignedUrlResult {
|
|
199
|
+
success: boolean;
|
|
200
|
+
url?: string;
|
|
201
|
+
expiresAt?: Date;
|
|
202
|
+
error?: string;
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/types/folder-operations.d.ts
|
|
206
|
+
interface CreateFolderOptions {
|
|
207
|
+
path: string;
|
|
208
|
+
}
|
|
209
|
+
interface CreateFolderResult {
|
|
210
|
+
success: boolean;
|
|
211
|
+
path?: string;
|
|
212
|
+
error?: string;
|
|
213
|
+
}
|
|
214
|
+
interface DeleteFolderOptions {
|
|
215
|
+
path: string;
|
|
216
|
+
recursive?: boolean;
|
|
217
|
+
}
|
|
218
|
+
interface DeleteFolderResult {
|
|
219
|
+
success: boolean;
|
|
220
|
+
deletedFiles?: string[];
|
|
221
|
+
error?: string;
|
|
222
|
+
}
|
|
223
|
+
interface ListFoldersOptions {
|
|
224
|
+
prefix?: string;
|
|
225
|
+
delimiter?: string;
|
|
226
|
+
maxKeys?: number;
|
|
227
|
+
continuationToken?: string;
|
|
228
|
+
}
|
|
229
|
+
interface ListFoldersResult {
|
|
230
|
+
success: boolean;
|
|
231
|
+
folders?: FolderInfo[];
|
|
232
|
+
files?: FileInfo[];
|
|
233
|
+
isTruncated?: boolean;
|
|
234
|
+
nextContinuationToken?: string;
|
|
235
|
+
error?: string;
|
|
236
|
+
}
|
|
237
|
+
interface FolderExistsResult {
|
|
238
|
+
exists: boolean;
|
|
239
|
+
folderInfo?: FolderInfo;
|
|
240
|
+
error?: string;
|
|
241
|
+
}
|
|
242
|
+
interface RenameFolderOptions {
|
|
243
|
+
oldPath: string;
|
|
244
|
+
newPath: string;
|
|
245
|
+
}
|
|
246
|
+
interface RenameFolderResult {
|
|
247
|
+
success: boolean;
|
|
248
|
+
movedFiles?: string[];
|
|
249
|
+
error?: string;
|
|
250
|
+
}
|
|
251
|
+
interface CopyFolderOptions {
|
|
252
|
+
sourcePath: string;
|
|
253
|
+
destinationPath: string;
|
|
254
|
+
recursive?: boolean;
|
|
255
|
+
}
|
|
256
|
+
interface CopyFolderResult {
|
|
257
|
+
success: boolean;
|
|
258
|
+
copiedFiles?: string[];
|
|
259
|
+
error?: string;
|
|
260
|
+
}
|
|
261
|
+
//#endregion
|
|
262
|
+
//#region src/types/storage-interface.d.ts
|
|
263
|
+
/**
|
|
264
|
+
* Main storage interface that all providers must implement
|
|
265
|
+
* Provides unified API for file and folder operations across different storage providers
|
|
266
|
+
* @public
|
|
267
|
+
*/
|
|
268
|
+
interface StorageInterface {
|
|
269
|
+
/** Upload a file to storage */
|
|
270
|
+
upload(options: UploadOptions): Promise<UploadResult>;
|
|
271
|
+
/** Download a file from storage */
|
|
272
|
+
download(options: DownloadOptions): Promise<DownloadResult>;
|
|
273
|
+
/** Delete a single file from storage */
|
|
274
|
+
delete(options: DeleteOptions): Promise<DeleteResult>;
|
|
275
|
+
/** Delete multiple files from storage */
|
|
276
|
+
batchDelete(options: BatchDeleteOptions): Promise<BatchDeleteResult>;
|
|
277
|
+
/** List files in storage */
|
|
278
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
279
|
+
/** Check if a file exists in storage */
|
|
280
|
+
exists(key: string): Promise<ExistsResult>;
|
|
281
|
+
/** Copy a file within storage */
|
|
282
|
+
copy(options: CopyOptions): Promise<CopyResult>;
|
|
283
|
+
/** Move a file within storage */
|
|
284
|
+
move(options: MoveOptions): Promise<MoveResult>;
|
|
285
|
+
/** Duplicate a file within storage */
|
|
286
|
+
duplicate(options: DuplicateOptions): Promise<DuplicateResult>;
|
|
287
|
+
/** Generate a presigned URL for file access */
|
|
288
|
+
getPresignedUrl(options: PresignedUrlOptions): Promise<PresignedUrlResult>;
|
|
289
|
+
/** Get public URL for a file */
|
|
290
|
+
getPublicUrl(key: string): string;
|
|
291
|
+
/** Create a folder in storage */
|
|
292
|
+
createFolder(options: CreateFolderOptions): Promise<CreateFolderResult>;
|
|
293
|
+
/** Delete a folder from storage */
|
|
294
|
+
deleteFolder(options: DeleteFolderOptions): Promise<DeleteFolderResult>;
|
|
295
|
+
/** List folders in storage */
|
|
296
|
+
listFolders(options?: ListFoldersOptions): Promise<ListFoldersResult>;
|
|
297
|
+
/** Check if a folder exists in storage */
|
|
298
|
+
folderExists(path: string): Promise<FolderExistsResult>;
|
|
299
|
+
/** Rename a folder in storage */
|
|
300
|
+
renameFolder(options: RenameFolderOptions): Promise<RenameFolderResult>;
|
|
301
|
+
/** Copy a folder within storage */
|
|
302
|
+
copyFolder(options: CopyFolderOptions): Promise<CopyFolderResult>;
|
|
303
|
+
}
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region src/config.d.ts
|
|
306
|
+
/**
|
|
307
|
+
* Cross-runtime environment record.
|
|
308
|
+
* Pass `process.env` on Node.js, `ctx.env` on Cloudflare Workers,
|
|
309
|
+
* `Deno.env.toObject()` on Deno, or a plain object in the browser.
|
|
310
|
+
*/
|
|
311
|
+
type EnvRecord = Record<string, string | undefined>;
|
|
312
|
+
/**
|
|
313
|
+
* Environment variable names for storage configuration
|
|
314
|
+
* @public
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```typescript
|
|
318
|
+
* import { ENV_VARS } from '@kumix/storage';
|
|
319
|
+
*
|
|
320
|
+
* // Check if specific env vars are set
|
|
321
|
+
* console.log(process.env[ENV_VARS.KUMIX_S3_BUCKET]);
|
|
322
|
+
* console.log(process.env[ENV_VARS.KUMIX_CLOUDINARY_CLOUD_NAME]);
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
declare const ENV_VARS: {
|
|
326
|
+
readonly KUMIX_S3_PROVIDER: "KUMIX_S3_PROVIDER";
|
|
327
|
+
readonly KUMIX_S3_REGION: "KUMIX_S3_REGION";
|
|
328
|
+
readonly KUMIX_S3_BUCKET: "KUMIX_S3_BUCKET";
|
|
329
|
+
readonly KUMIX_S3_ACCESS_KEY_ID: "KUMIX_S3_ACCESS_KEY_ID";
|
|
330
|
+
readonly KUMIX_S3_SECRET_ACCESS_KEY: "KUMIX_S3_SECRET_ACCESS_KEY";
|
|
331
|
+
readonly KUMIX_S3_ENDPOINT: "KUMIX_S3_ENDPOINT";
|
|
332
|
+
readonly KUMIX_S3_FORCE_PATH_STYLE: "KUMIX_S3_FORCE_PATH_STYLE";
|
|
333
|
+
readonly KUMIX_S3_PUBLIC_URL: "KUMIX_S3_PUBLIC_URL";
|
|
334
|
+
readonly KUMIX_CLOUDINARY_CLOUD_NAME: "KUMIX_CLOUDINARY_CLOUD_NAME";
|
|
335
|
+
readonly KUMIX_CLOUDINARY_API_KEY: "KUMIX_CLOUDINARY_API_KEY";
|
|
336
|
+
readonly KUMIX_CLOUDINARY_API_SECRET: "KUMIX_CLOUDINARY_API_SECRET";
|
|
337
|
+
readonly KUMIX_CLOUDINARY_SECURE: "KUMIX_CLOUDINARY_SECURE";
|
|
338
|
+
readonly KUMIX_CLOUDINARY_FOLDER: "KUMIX_CLOUDINARY_FOLDER";
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
* Load S3 configuration from environment variables
|
|
342
|
+
* @param env - Optional environment record
|
|
343
|
+
* @returns S3 configuration object
|
|
344
|
+
* @throws Error if required environment variables are missing
|
|
345
|
+
* @public
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```typescript
|
|
349
|
+
* import { loadS3Config } from '@kumix/storage';
|
|
350
|
+
*
|
|
351
|
+
* // Set environment variables first:
|
|
352
|
+
* // KUMIX_S3_PROVIDER=aws
|
|
353
|
+
* // KUMIX_S3_REGION=us-east-1
|
|
354
|
+
* // KUMIX_S3_BUCKET=my-bucket
|
|
355
|
+
* // KUMIX_S3_ACCESS_KEY_ID=AKIA...
|
|
356
|
+
* // KUMIX_S3_SECRET_ACCESS_KEY=secret...
|
|
357
|
+
*
|
|
358
|
+
* try {
|
|
359
|
+
* const config = loadS3Config();
|
|
360
|
+
* console.log(config);
|
|
361
|
+
* // Returns: {
|
|
362
|
+
* // provider: 'aws',
|
|
363
|
+
* // region: 'us-east-1',
|
|
364
|
+
* // bucket: 'my-bucket',
|
|
365
|
+
* // accessKeyId: 'AKIA...',
|
|
366
|
+
* // secretAccessKey: 'secret...'
|
|
367
|
+
* // }
|
|
368
|
+
* } catch (error) {
|
|
369
|
+
* console.error('Missing S3 configuration:', error.message);
|
|
370
|
+
* }
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
declare function loadS3Config(env?: EnvRecord): S3Config;
|
|
374
|
+
/**
|
|
375
|
+
* Load Cloudinary configuration from environment variables
|
|
376
|
+
* @param env - Optional environment record
|
|
377
|
+
* @returns Cloudinary configuration object
|
|
378
|
+
* @throws Error if required environment variables are missing
|
|
379
|
+
* @public
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* ```typescript
|
|
383
|
+
* import { loadCloudinaryConfig } from '@kumix/storage';
|
|
384
|
+
*
|
|
385
|
+
* // Set environment variables first:
|
|
386
|
+
* // KUMIX_CLOUDINARY_CLOUD_NAME=my-cloud
|
|
387
|
+
* // KUMIX_CLOUDINARY_API_KEY=123456789
|
|
388
|
+
* // KUMIX_CLOUDINARY_API_SECRET=secret...
|
|
389
|
+
* // KUMIX_CLOUDINARY_SECURE=true (optional)
|
|
390
|
+
* // KUMIX_CLOUDINARY_FOLDER=uploads (optional)
|
|
391
|
+
*
|
|
392
|
+
* try {
|
|
393
|
+
* const config = loadCloudinaryConfig();
|
|
394
|
+
* console.log(config);
|
|
395
|
+
* // Returns: {
|
|
396
|
+
* // provider: 'cloudinary',
|
|
397
|
+
* // cloudName: 'my-cloud',
|
|
398
|
+
* // apiKey: '123456789',
|
|
399
|
+
* // apiSecret: 'secret...',
|
|
400
|
+
* // secure: true,
|
|
401
|
+
* // folder: 'uploads'
|
|
402
|
+
* // }
|
|
403
|
+
* } catch (error) {
|
|
404
|
+
* console.error('Missing Cloudinary configuration:', error.message);
|
|
405
|
+
* }
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
declare function loadCloudinaryConfig(env?: EnvRecord): CloudinaryConfig;
|
|
409
|
+
/**
|
|
410
|
+
* Auto-detect and load storage configuration from environment variables
|
|
411
|
+
* Determines the provider based on available environment variables
|
|
412
|
+
* @param env - Optional environment record
|
|
413
|
+
* @returns Storage configuration object (S3 or Cloudinary)
|
|
414
|
+
* @throws Error if no valid configuration is found
|
|
415
|
+
* @public
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```typescript
|
|
419
|
+
* import { loadStorageConfig } from '@kumix/storage';
|
|
420
|
+
*
|
|
421
|
+
* // Auto-detection based on available env vars
|
|
422
|
+
* try {
|
|
423
|
+
* const config = loadStorageConfig();
|
|
424
|
+
*
|
|
425
|
+
* if (config.provider === 'cloudinary') {
|
|
426
|
+
* console.log('Using Cloudinary:', config.cloudName);
|
|
427
|
+
* } else {
|
|
428
|
+
* console.log('Using S3:', config.provider, config.bucket);
|
|
429
|
+
* }
|
|
430
|
+
* } catch (error) {
|
|
431
|
+
* console.error('No storage configuration found:', error.message);
|
|
432
|
+
* }
|
|
433
|
+
*
|
|
434
|
+
* // Explicit provider (set KUMIX_S3_PROVIDER=cloudinary)
|
|
435
|
+
* // Will load Cloudinary config even if S3 vars are also present
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
declare function loadStorageConfig(env?: EnvRecord): StorageConfig;
|
|
439
|
+
/**
|
|
440
|
+
* Check if storage configuration is available in environment variables
|
|
441
|
+
* @param env - Optional environment record
|
|
442
|
+
* @returns True if valid storage configuration is found
|
|
443
|
+
* @public
|
|
444
|
+
*
|
|
445
|
+
* @example
|
|
446
|
+
* ```typescript
|
|
447
|
+
* import { hasStorageConfig, loadStorageConfig } from '@kumix/storage';
|
|
448
|
+
*
|
|
449
|
+
* if (hasStorageConfig()) {
|
|
450
|
+
* const config = loadStorageConfig();
|
|
451
|
+
* console.log('Storage configured:', config.provider);
|
|
452
|
+
* } else {
|
|
453
|
+
* console.log('Please set storage environment variables');
|
|
454
|
+
* }
|
|
455
|
+
*
|
|
456
|
+
* // Use in conditional initialization
|
|
457
|
+
* const storage = hasStorageConfig() ? createStorage() : null;
|
|
458
|
+
* ```
|
|
459
|
+
*/
|
|
460
|
+
declare function hasStorageConfig(env?: EnvRecord): boolean;
|
|
461
|
+
/**
|
|
462
|
+
* Check if storage configuration is available in environment variables
|
|
463
|
+
* @param env - Optional environment record
|
|
464
|
+
* @returns True if either S3 or Cloudinary configuration is available
|
|
465
|
+
* @public
|
|
466
|
+
*
|
|
467
|
+
* @example
|
|
468
|
+
* ```typescript
|
|
469
|
+
* import { isStorageConfigured, createS3, createCloudinary } from '@kumix/storage';
|
|
470
|
+
*
|
|
471
|
+
* if (isStorageConfigured()) {
|
|
472
|
+
* // Choose your preferred provider
|
|
473
|
+
* const s3 = createS3();
|
|
474
|
+
* // OR
|
|
475
|
+
* const cloudinary = createCloudinary();
|
|
476
|
+
*
|
|
477
|
+
* await s3.uploadFile('test.txt', 'Hello World');
|
|
478
|
+
* } else {
|
|
479
|
+
* console.log('Storage not configured. Please set environment variables.');
|
|
480
|
+
* }
|
|
481
|
+
*
|
|
482
|
+
* // Use in conditional initialization
|
|
483
|
+
* const storage = isStorageConfigured() ? createS3() : null;
|
|
484
|
+
* if (storage) {
|
|
485
|
+
* await storage.uploadFile('file.txt', content);
|
|
486
|
+
* }
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
489
|
+
declare function isStorageConfigured(env?: EnvRecord): boolean;
|
|
490
|
+
/**
|
|
491
|
+
* Get storage provider name from environment variables without loading full config
|
|
492
|
+
* @param env - Optional environment record
|
|
493
|
+
* @returns Provider name or undefined if not configured
|
|
494
|
+
* @public
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* ```typescript
|
|
498
|
+
* import { getStorageProvider } from '@kumix/storage';
|
|
499
|
+
*
|
|
500
|
+
* const provider = getStorageProvider();
|
|
501
|
+
*
|
|
502
|
+
* switch (provider) {
|
|
503
|
+
* case 'aws':
|
|
504
|
+
* console.log('Using AWS S3');
|
|
505
|
+
* break;
|
|
506
|
+
* case 'cloudinary':
|
|
507
|
+
* console.log('Using Cloudinary');
|
|
508
|
+
* break;
|
|
509
|
+
* case 'cloudflare-r2':
|
|
510
|
+
* console.log('Using Cloudflare R2');
|
|
511
|
+
* break;
|
|
512
|
+
* default:
|
|
513
|
+
* console.log('No storage provider configured');
|
|
514
|
+
* }
|
|
515
|
+
*
|
|
516
|
+
* // Quick check without throwing errors
|
|
517
|
+
* if (getStorageProvider()) {
|
|
518
|
+
* // Storage is configured
|
|
519
|
+
* }
|
|
520
|
+
* ```
|
|
521
|
+
*/
|
|
522
|
+
declare function getStorageProvider(env?: EnvRecord): string | undefined;
|
|
523
|
+
/**
|
|
524
|
+
* Validate if all required environment variables are set for S3
|
|
525
|
+
* @param env - Optional environment record
|
|
526
|
+
* @returns Validation result with missing variables
|
|
527
|
+
* @public
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
* ```typescript
|
|
531
|
+
* import { validateS3EnvVars } from '@kumix/storage';
|
|
532
|
+
*
|
|
533
|
+
* const validation = validateS3EnvVars();
|
|
534
|
+
*
|
|
535
|
+
* if (validation.valid) {
|
|
536
|
+
* console.log('S3 configuration is complete');
|
|
537
|
+
* } else {
|
|
538
|
+
* console.log('Missing S3 variables:', validation.missing);
|
|
539
|
+
* // Returns: ["KUMIX_S3_REGION", "KUMIX_S3_BUCKET"]
|
|
540
|
+
* }
|
|
541
|
+
* ```
|
|
542
|
+
*/
|
|
543
|
+
declare function validateS3EnvVars(env?: EnvRecord): {
|
|
544
|
+
valid: boolean;
|
|
545
|
+
missing: string[];
|
|
546
|
+
};
|
|
547
|
+
/**
|
|
548
|
+
* Validate if all required environment variables are set for Cloudinary
|
|
549
|
+
* @param env - Optional environment record
|
|
550
|
+
* @returns Validation result with missing variables
|
|
551
|
+
* @public
|
|
552
|
+
*
|
|
553
|
+
* @example
|
|
554
|
+
* ```typescript
|
|
555
|
+
* import { validateCloudinaryEnvVars } from '@kumix/storage';
|
|
556
|
+
*
|
|
557
|
+
* const validation = validateCloudinaryEnvVars();
|
|
558
|
+
*
|
|
559
|
+
* if (validation.valid) {
|
|
560
|
+
* console.log('Cloudinary configuration is complete');
|
|
561
|
+
* } else {
|
|
562
|
+
* console.log('Missing Cloudinary variables:', validation.missing);
|
|
563
|
+
* // Returns: ["KUMIX_CLOUDINARY_API_KEY"]
|
|
564
|
+
* }
|
|
565
|
+
* ```
|
|
566
|
+
*/
|
|
567
|
+
declare function validateCloudinaryEnvVars(env?: EnvRecord): {
|
|
568
|
+
valid: boolean;
|
|
569
|
+
missing: string[];
|
|
570
|
+
};
|
|
571
|
+
/**
|
|
572
|
+
* Get all available environment variables for debugging
|
|
573
|
+
* @param env - Optional environment record
|
|
574
|
+
* @returns Object containing all storage-related env vars
|
|
575
|
+
* @public
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* ```typescript
|
|
579
|
+
* import { getStorageEnvVars } from '@kumix/storage';
|
|
580
|
+
*
|
|
581
|
+
* const envVars = getStorageEnvVars();
|
|
582
|
+
* console.log('Storage environment variables:', envVars);
|
|
583
|
+
* // Returns: {
|
|
584
|
+
* // KUMIX_S3_PROVIDER: 'aws',
|
|
585
|
+
* // KUMIX_S3_REGION: 'us-east-1',
|
|
586
|
+
* // KUMIX_S3_BUCKET: 'my-bucket',
|
|
587
|
+
* // // ... other set variables (secrets are masked)
|
|
588
|
+
* // }
|
|
589
|
+
* ```
|
|
590
|
+
*/
|
|
591
|
+
declare function getStorageEnvVars(env?: EnvRecord): Record<string, string | undefined>;
|
|
592
|
+
//#endregion
|
|
593
|
+
export { DownloadOptions as A, PresignedUrlResult as B, RenameFolderResult as C, CopyResult as D, CopyOptions as E, ListOptions as F, FolderInfo as G, UploadResult as H, ListResult as I, StorageConfig as J, S3Config as K, MoveOptions as L, DuplicateOptions as M, DuplicateResult as N, DeleteOptions as O, ExistsResult as P, MoveResult as R, RenameFolderOptions as S, BatchDeleteResult as T, CloudinaryConfig as U, UploadOptions as V, FileInfo as W, StorageProvider as Y, DeleteFolderOptions as _, hasStorageConfig as a, ListFoldersOptions as b, loadS3Config as c, validateS3EnvVars as d, StorageInterface as f, CreateFolderResult as g, CreateFolderOptions as h, getStorageProvider as i, DownloadResult as j, DeleteResult as k, loadStorageConfig as l, CopyFolderResult as m, EnvRecord as n, isStorageConfigured as o, CopyFolderOptions as p, S3ProviderType as q, getStorageEnvVars as r, loadCloudinaryConfig as s, ENV_VARS as t, validateCloudinaryEnvVars as u, DeleteFolderResult as v, BatchDeleteOptions as w, ListFoldersResult as x, FolderExistsResult as y, PresignedUrlOptions as z };
|
|
594
|
+
//# sourceMappingURL=config-J6AdDh_c.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-J6AdDh_c.d.ts","names":[],"sources":["../src/types/base.ts","../src/types/file-operations.ts","../src/types/folder-operations.ts","../src/types/storage-interface.ts","../src/config.ts"],"mappings":";;AASA;;;;AAA0B;AAY1B;;KAZY,cAAA;;AAYgC;AAM5C;;KANY,eAAA,GAAkB,cAAc;;AAMW;AAMvD;;KANY,aAAA,GAAgB,QAAA,GAAW,gBAAgB;;;;;UAMtC,QAAA;EAQf;EANA,QAAA,EAAU,cAAc;EAUxB;EARA,MAAA;EAYA;EAVA,MAAA;EAUS;EART,WAAA;EAe+B;EAb/B,eAAA;EAa+B;EAX/B,QAAA;EAeA;EAbA,cAAA;EAiBA;EAfA,SAAA;AAAA;;AAmBM;AAOR;;UAnBiB,gBAAA;EA+BE;EA7BjB,QAAA;EAqBA;EAnBA,SAAA;EAqBc;EAnBd,MAAA;EAuBA;EArBA,SAAA;EAuBW;EArBX,MAAA;EAqBiB;EAnBjB,MAAA;AAAA;;;;;UAOe,QAAA;EA2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