@pelatform/storage 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/s3.d.cts DELETED
@@ -1,108 +0,0 @@
1
- import { S as StorageInterface, v as S3Config, U as UploadOptions, a as UploadResult, D as DownloadOptions, b as DownloadResult, c as DeleteOptions, d as DeleteResult, B as BatchDeleteOptions, e as BatchDeleteResult, L as ListOptions, f as ListResult, E as ExistsResult, g as CopyOptions, h as CopyResult, M as MoveOptions, i as MoveResult, j as DuplicateOptions, k as DuplicateResult, P as PresignedUrlOptions, l as PresignedUrlResult, m as CreateFolderOptions, n as CreateFolderResult, o as DeleteFolderOptions, p as DeleteFolderResult, q as ListFoldersOptions, r as ListFoldersResult, F as FolderExistsResult, R as RenameFolderOptions, s as RenameFolderResult, t as CopyFolderOptions, u as CopyFolderResult } from './storage-interface-BKeDAlGP.cjs';
2
-
3
- /**
4
- * S3 storage service implementation
5
- * High-level service wrapper for S3-compatible storage operations with convenience methods
6
- */
7
-
8
- /**
9
- * S3 storage service
10
- * High-level service for S3-compatible storage operations with convenience methods
11
- * @public
12
- */
13
- declare class S3Service implements StorageInterface {
14
- private provider;
15
- private config;
16
- constructor();
17
- constructor(config: S3Config);
18
- private createProvider;
19
- getConfig(): S3Config;
20
- getBucket(): string;
21
- getRegion(): string;
22
- getProvider(): string;
23
- getPublicUrl(key: string): string;
24
- upload(options: UploadOptions): Promise<UploadResult>;
25
- download(options: DownloadOptions): Promise<DownloadResult>;
26
- delete(options: DeleteOptions): Promise<DeleteResult>;
27
- batchDelete(options: BatchDeleteOptions): Promise<BatchDeleteResult>;
28
- list(options?: ListOptions): Promise<ListResult>;
29
- exists(key: string): Promise<ExistsResult>;
30
- copy(options: CopyOptions): Promise<CopyResult>;
31
- move(options: MoveOptions): Promise<MoveResult>;
32
- duplicate(options: DuplicateOptions): Promise<DuplicateResult>;
33
- getPresignedUrl(options: PresignedUrlOptions): Promise<PresignedUrlResult>;
34
- createFolder(options: CreateFolderOptions): Promise<CreateFolderResult>;
35
- deleteFolder(options: DeleteFolderOptions): Promise<DeleteFolderResult>;
36
- listFolders(options?: ListFoldersOptions): Promise<ListFoldersResult>;
37
- folderExists(path: string): Promise<FolderExistsResult>;
38
- renameFolder(options: RenameFolderOptions): Promise<RenameFolderResult>;
39
- copyFolder(options: CopyFolderOptions): Promise<CopyFolderResult>;
40
- uploadFile(key: string, file: Buffer | Uint8Array | string, options?: Partial<UploadOptions>): Promise<UploadResult>;
41
- downloadFile(key: string): Promise<DownloadResult>;
42
- deleteFile(key: string): Promise<DeleteResult>;
43
- deleteFiles(keys: string[]): Promise<BatchDeleteResult>;
44
- fileExists(key: string): Promise<boolean>;
45
- copyFile(sourceKey: string, destinationKey: string, options?: Partial<CopyOptions>): Promise<CopyResult>;
46
- moveFile(sourceKey: string, destinationKey: string, options?: Partial<MoveOptions>): Promise<MoveResult>;
47
- duplicateFile(sourceKey: string, destinationKey: string, options?: Partial<DuplicateOptions>): Promise<DuplicateResult>;
48
- renameFile(sourceKey: string, newKey: string, options?: Partial<MoveOptions>): Promise<MoveResult>;
49
- getDownloadUrl(key: string, expiresIn?: number): Promise<PresignedUrlResult>;
50
- getUploadUrl(key: string, contentType?: string, expiresIn?: number): Promise<PresignedUrlResult>;
51
- createFolderPath(path: string): Promise<CreateFolderResult>;
52
- deleteFolderPath(path: string, recursive?: boolean): Promise<DeleteFolderResult>;
53
- folderPathExists(path: string): Promise<boolean>;
54
- renameFolderPath(oldPath: string, newPath: string): Promise<RenameFolderResult>;
55
- copyFolderPath(sourcePath: string, destinationPath: string, recursive?: boolean): Promise<CopyFolderResult>;
56
- }
57
-
58
- /**
59
- * Create S3 service using environment variables or manual configuration
60
- * @param config Optional S3 configuration. If not provided, loads from environment variables
61
- * @returns S3Service instance
62
- * @throws Error if configuration is invalid or environment variables are missing
63
- * @public
64
- *
65
- * @example
66
- * ```typescript
67
- * import { createS3 } from '@pelatform/storage/s3';
68
- *
69
- * // Using environment variables
70
- * // Set: PELATFORM_S3_PROVIDER=aws, PELATFORM_S3_REGION=us-east-1, etc.
71
- * const s3FromEnv = createS3();
72
- * await s3FromEnv.uploadFile('test.txt', 'Hello World');
73
- *
74
- * // Using manual configuration
75
- * const s3Manual = createS3({
76
- * provider: 'aws',
77
- * region: 'us-east-1',
78
- * bucket: 'my-bucket',
79
- * accessKeyId: 'AKIA...',
80
- * secretAccessKey: 'secret...'
81
- * });
82
- *
83
- * // Cloudflare R2
84
- * const r2 = createS3({
85
- * provider: 'cloudflare-r2',
86
- * region: 'auto',
87
- * bucket: 'my-r2-bucket',
88
- * accessKeyId: 'your-r2-key',
89
- * secretAccessKey: 'your-r2-secret',
90
- * endpoint: 'https://account-id.r2.cloudflarestorage.com'
91
- * });
92
- *
93
- * // MinIO
94
- * const minio = createS3({
95
- * provider: 'minio',
96
- * region: 'us-east-1',
97
- * bucket: 'my-minio-bucket',
98
- * accessKeyId: 'minioadmin',
99
- * secretAccessKey: 'minioadmin',
100
- * endpoint: 'http://localhost:9000',
101
- * forcePathStyle: true
102
- * });
103
- * ```
104
- */
105
- declare function createS3(): S3Service;
106
- declare function createS3(config: S3Config): S3Service;
107
-
108
- export { S3Service, createS3 };
@@ -1,316 +0,0 @@
1
- /**
2
- * Base storage types and configurations
3
- * Defines core types for storage providers, configurations, and file information
4
- */
5
- /**
6
- * S3-compatible provider types
7
- * @public
8
- */
9
- type S3ProviderType = 'aws' | 'cloudflare-r2' | 'minio' | 'digitalocean' | 'supabase' | 'custom';
10
- /**
11
- * All supported storage provider types
12
- * @public
13
- */
14
- type StorageProvider = S3ProviderType | 'cloudinary';
15
- /**
16
- * Union type for all storage configurations
17
- * @public
18
- */
19
- type StorageConfig = S3Config | CloudinaryConfig;
20
- /**
21
- * S3-compatible storage configuration
22
- * @public
23
- */
24
- interface S3Config {
25
- /** S3-compatible provider type */
26
- provider: S3ProviderType;
27
- /** AWS region or provider-specific region */
28
- region: string;
29
- /** Bucket name */
30
- bucket: string;
31
- /** Access key ID for authentication */
32
- accessKeyId: string;
33
- /** Secret access key for authentication */
34
- secretAccessKey: string;
35
- /** Custom endpoint for S3-compatible services (MinIO, R2, etc.) */
36
- endpoint?: string;
37
- /** Force path style for services like MinIO */
38
- forcePathStyle?: boolean;
39
- /** Base URL for public access (CDN, custom domain) */
40
- publicUrl?: string;
41
- }
42
- /**
43
- * Cloudinary storage configuration
44
- * @public
45
- */
46
- interface CloudinaryConfig {
47
- /** Provider type (always 'cloudinary') */
48
- provider: 'cloudinary';
49
- /** Cloudinary cloud name */
50
- cloudName: string;
51
- /** Cloudinary API key */
52
- apiKey: string;
53
- /** Cloudinary API secret */
54
- apiSecret: string;
55
- /** Use HTTPS for URLs (default: true) */
56
- secure?: boolean;
57
- /** Default upload folder */
58
- folder?: string;
59
- }
60
- /**
61
- * File information structure
62
- * @public
63
- */
64
- interface FileInfo {
65
- /** File key/path */
66
- key: string;
67
- /** File size in bytes */
68
- size: number;
69
- /** Last modified date */
70
- lastModified: Date;
71
- /** Entity tag for caching */
72
- etag: string;
73
- /** MIME content type */
74
- contentType?: string;
75
- /** Custom metadata */
76
- metadata?: Record<string, string>;
77
- }
78
- /**
79
- * Folder information structure
80
- * @public
81
- */
82
- interface FolderInfo {
83
- /** Folder name */
84
- name: string;
85
- /** Full folder path */
86
- path: string;
87
- /** Total size of all files in folder */
88
- size: number;
89
- /** Number of files in folder */
90
- fileCount: number;
91
- /** Last modified date */
92
- lastModified: Date;
93
- }
94
-
95
- /**
96
- * File operation types and interfaces
97
- * Defines types for file upload, download, delete, copy, move, and other file operations
98
- */
99
-
100
- interface UploadOptions {
101
- key: string;
102
- file: Buffer | Uint8Array | string;
103
- contentType?: string;
104
- metadata?: Record<string, string>;
105
- cacheControl?: string;
106
- contentDisposition?: string;
107
- acl?: 'private' | 'public-read' | 'public-read-write';
108
- expires?: Date;
109
- }
110
- interface UploadResult {
111
- success: boolean;
112
- key?: string;
113
- url?: string;
114
- publicUrl?: string;
115
- etag?: string;
116
- size?: number;
117
- error?: string;
118
- }
119
- interface DownloadOptions {
120
- key: string;
121
- range?: string;
122
- }
123
- interface DownloadResult {
124
- success: boolean;
125
- content?: Buffer;
126
- data?: Buffer;
127
- contentType?: string;
128
- contentLength?: number;
129
- lastModified?: Date;
130
- etag?: string;
131
- metadata?: Record<string, string>;
132
- error?: string;
133
- }
134
- interface DeleteOptions {
135
- key: string;
136
- }
137
- interface DeleteResult {
138
- success: boolean;
139
- error?: string;
140
- }
141
- interface BatchDeleteOptions {
142
- keys: string[];
143
- }
144
- interface BatchDeleteResult {
145
- success: boolean;
146
- deleted?: string[];
147
- errors?: Array<{
148
- key: string;
149
- error: string;
150
- }>;
151
- }
152
- interface CopyOptions {
153
- sourceKey: string;
154
- destinationKey: string;
155
- metadata?: Record<string, string>;
156
- metadataDirective?: 'COPY' | 'REPLACE';
157
- }
158
- interface CopyResult {
159
- success: boolean;
160
- etag?: string;
161
- error?: string;
162
- }
163
- interface MoveOptions {
164
- sourceKey: string;
165
- destinationKey: string;
166
- metadata?: Record<string, string>;
167
- metadataDirective?: 'COPY' | 'REPLACE';
168
- }
169
- interface MoveResult {
170
- success: boolean;
171
- etag?: string;
172
- error?: string;
173
- }
174
- type DuplicateOptions = CopyOptions;
175
- type DuplicateResult = CopyResult;
176
- interface ExistsResult {
177
- exists: boolean;
178
- fileInfo?: FileInfo;
179
- error?: string;
180
- }
181
- interface ListOptions {
182
- prefix?: string;
183
- delimiter?: string;
184
- maxKeys?: number;
185
- continuationToken?: string;
186
- }
187
- interface ListResult {
188
- success: boolean;
189
- files?: FileInfo[];
190
- isTruncated?: boolean;
191
- nextContinuationToken?: string;
192
- commonPrefixes?: string[];
193
- error?: string;
194
- }
195
- interface PresignedUrlOptions {
196
- key: string;
197
- operation: 'get' | 'put';
198
- expiresIn?: number;
199
- contentType?: string;
200
- }
201
- interface PresignedUrlResult {
202
- success: boolean;
203
- url?: string;
204
- expiresAt?: Date;
205
- error?: string;
206
- }
207
-
208
- /**
209
- * Folder operation types and interfaces
210
- * Defines types for folder creation, deletion, listing, and other folder operations
211
- */
212
-
213
- interface CreateFolderOptions {
214
- path: string;
215
- }
216
- interface CreateFolderResult {
217
- success: boolean;
218
- path?: string;
219
- error?: string;
220
- }
221
- interface DeleteFolderOptions {
222
- path: string;
223
- recursive?: boolean;
224
- }
225
- interface DeleteFolderResult {
226
- success: boolean;
227
- deletedFiles?: string[];
228
- error?: string;
229
- }
230
- interface ListFoldersOptions {
231
- prefix?: string;
232
- delimiter?: string;
233
- maxKeys?: number;
234
- continuationToken?: string;
235
- }
236
- interface ListFoldersResult {
237
- success: boolean;
238
- folders?: FolderInfo[];
239
- files?: FileInfo[];
240
- isTruncated?: boolean;
241
- nextContinuationToken?: string;
242
- error?: string;
243
- }
244
- interface FolderExistsResult {
245
- exists: boolean;
246
- folderInfo?: FolderInfo;
247
- error?: string;
248
- }
249
- interface RenameFolderOptions {
250
- oldPath: string;
251
- newPath: string;
252
- }
253
- interface RenameFolderResult {
254
- success: boolean;
255
- movedFiles?: string[];
256
- error?: string;
257
- }
258
- interface CopyFolderOptions {
259
- sourcePath: string;
260
- destinationPath: string;
261
- recursive?: boolean;
262
- }
263
- interface CopyFolderResult {
264
- success: boolean;
265
- copiedFiles?: string[];
266
- error?: string;
267
- }
268
-
269
- /**
270
- * Storage interface definition
271
- * Defines the unified interface that all storage providers must implement
272
- */
273
-
274
- /**
275
- * Main storage interface that all providers must implement
276
- * Provides unified API for file and folder operations across different storage providers
277
- * @public
278
- */
279
- interface StorageInterface {
280
- /** Upload a file to storage */
281
- upload(options: UploadOptions): Promise<UploadResult>;
282
- /** Download a file from storage */
283
- download(options: DownloadOptions): Promise<DownloadResult>;
284
- /** Delete a single file from storage */
285
- delete(options: DeleteOptions): Promise<DeleteResult>;
286
- /** Delete multiple files from storage */
287
- batchDelete(options: BatchDeleteOptions): Promise<BatchDeleteResult>;
288
- /** List files in storage */
289
- list(options?: ListOptions): Promise<ListResult>;
290
- /** Check if a file exists in storage */
291
- exists(key: string): Promise<ExistsResult>;
292
- /** Copy a file within storage */
293
- copy(options: CopyOptions): Promise<CopyResult>;
294
- /** Move a file within storage */
295
- move(options: MoveOptions): Promise<MoveResult>;
296
- /** Duplicate a file within storage */
297
- duplicate(options: DuplicateOptions): Promise<DuplicateResult>;
298
- /** Generate a presigned URL for file access */
299
- getPresignedUrl(options: PresignedUrlOptions): Promise<PresignedUrlResult>;
300
- /** Get public URL for a file */
301
- getPublicUrl(key: string): string;
302
- /** Create a folder in storage */
303
- createFolder(options: CreateFolderOptions): Promise<CreateFolderResult>;
304
- /** Delete a folder from storage */
305
- deleteFolder(options: DeleteFolderOptions): Promise<DeleteFolderResult>;
306
- /** List folders in storage */
307
- listFolders(options?: ListFoldersOptions): Promise<ListFoldersResult>;
308
- /** Check if a folder exists in storage */
309
- folderExists(path: string): Promise<FolderExistsResult>;
310
- /** Rename a folder in storage */
311
- renameFolder(options: RenameFolderOptions): Promise<RenameFolderResult>;
312
- /** Copy a folder within storage */
313
- copyFolder(options: CopyFolderOptions): Promise<CopyFolderResult>;
314
- }
315
-
316
- export type { FolderInfo as A, BatchDeleteOptions as B, CloudinaryConfig as C, DownloadOptions as D, ExistsResult as E, FolderExistsResult as F, ListOptions as L, MoveOptions as M, PresignedUrlOptions as P, RenameFolderOptions as R, StorageInterface as S, UploadOptions as U, UploadResult as a, DownloadResult as b, DeleteOptions as c, DeleteResult as d, BatchDeleteResult as e, ListResult as f, CopyOptions as g, CopyResult as h, MoveResult as i, DuplicateOptions as j, DuplicateResult as k, PresignedUrlResult as l, CreateFolderOptions as m, CreateFolderResult as n, DeleteFolderOptions as o, DeleteFolderResult as p, ListFoldersOptions as q, ListFoldersResult as r, RenameFolderResult as s, CopyFolderOptions as t, CopyFolderResult as u, S3Config as v, StorageConfig as w, S3ProviderType as x, StorageProvider as y, FileInfo as z };