@pelatform/storage 1.0.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.
- package/LICENSE +21 -0
- package/README.md +10 -0
- package/dist/chunk-KJMGBTTL.js +413 -0
- package/dist/chunk-ZTZZCC52.js +169 -0
- package/dist/cloudinary.d.ts +93 -0
- package/dist/cloudinary.js +496 -0
- package/dist/helpers.d.ts +762 -0
- package/dist/helpers.js +68 -0
- package/dist/index.d.ts +281 -0
- package/dist/index.js +24 -0
- package/dist/s3.d.ts +108 -0
- package/dist/s3.js +799 -0
- package/dist/storage-interface-UizTndyU.d.ts +316 -0
- package/package.json +78 -0
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
base64ToBuffer,
|
|
3
|
+
bufferToBase64,
|
|
4
|
+
buildPublicUrl,
|
|
5
|
+
detectFileTypeFromContent,
|
|
6
|
+
extractS3Info,
|
|
7
|
+
fileToBuffer,
|
|
8
|
+
formatFileSize,
|
|
9
|
+
generateBatchKeys,
|
|
10
|
+
generateCacheControl,
|
|
11
|
+
generateFileHash,
|
|
12
|
+
generateFileKey,
|
|
13
|
+
generateUniqueKey,
|
|
14
|
+
getContentDisposition,
|
|
15
|
+
getFileExtension,
|
|
16
|
+
getFileInfo,
|
|
17
|
+
getFileName,
|
|
18
|
+
getMimeType,
|
|
19
|
+
getParentPath,
|
|
20
|
+
isAudioFile,
|
|
21
|
+
isDocumentFile,
|
|
22
|
+
isImageFile,
|
|
23
|
+
isVideoFile,
|
|
24
|
+
joinPath,
|
|
25
|
+
normalizePath,
|
|
26
|
+
parseS3Url,
|
|
27
|
+
sanitizeFileName,
|
|
28
|
+
validateBatchFiles,
|
|
29
|
+
validateBucketName,
|
|
30
|
+
validateFileSize,
|
|
31
|
+
validateFileType,
|
|
32
|
+
validateS3Config,
|
|
33
|
+
validateS3Key
|
|
34
|
+
} from "./chunk-KJMGBTTL.js";
|
|
35
|
+
export {
|
|
36
|
+
base64ToBuffer,
|
|
37
|
+
bufferToBase64,
|
|
38
|
+
buildPublicUrl,
|
|
39
|
+
detectFileTypeFromContent,
|
|
40
|
+
extractS3Info,
|
|
41
|
+
fileToBuffer,
|
|
42
|
+
formatFileSize,
|
|
43
|
+
generateBatchKeys,
|
|
44
|
+
generateCacheControl,
|
|
45
|
+
generateFileHash,
|
|
46
|
+
generateFileKey,
|
|
47
|
+
generateUniqueKey,
|
|
48
|
+
getContentDisposition,
|
|
49
|
+
getFileExtension,
|
|
50
|
+
getFileInfo,
|
|
51
|
+
getFileName,
|
|
52
|
+
getMimeType,
|
|
53
|
+
getParentPath,
|
|
54
|
+
isAudioFile,
|
|
55
|
+
isDocumentFile,
|
|
56
|
+
isImageFile,
|
|
57
|
+
isVideoFile,
|
|
58
|
+
joinPath,
|
|
59
|
+
normalizePath,
|
|
60
|
+
parseS3Url,
|
|
61
|
+
sanitizeFileName,
|
|
62
|
+
validateBatchFiles,
|
|
63
|
+
validateBucketName,
|
|
64
|
+
validateFileSize,
|
|
65
|
+
validateFileType,
|
|
66
|
+
validateS3Config,
|
|
67
|
+
validateS3Key
|
|
68
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { S as S3Config, C as CloudinaryConfig, a as StorageConfig } from './storage-interface-UizTndyU.js';
|
|
2
|
+
export { B as BatchDeleteOptions, i as BatchDeleteResult, y as CopyFolderOptions, z as CopyFolderResult, j as CopyOptions, k as CopyResult, q as CreateFolderOptions, r as CreateFolderResult, s as DeleteFolderOptions, t as DeleteFolderResult, g as DeleteOptions, h as DeleteResult, D as DownloadOptions, f as DownloadResult, m as DuplicateOptions, n as DuplicateResult, E as ExistsResult, F as FileInfo, w as FolderExistsResult, d as FolderInfo, u as ListFoldersOptions, v as ListFoldersResult, L as ListOptions, o as ListResult, M as MoveOptions, l as MoveResult, P as PresignedUrlOptions, p as PresignedUrlResult, R as RenameFolderOptions, x as RenameFolderResult, b as S3ProviderType, A as StorageInterface, c as StorageProvider, U as UploadOptions, e as UploadResult } from './storage-interface-UizTndyU.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Storage configuration from environment variables
|
|
6
|
+
* Provides automatic configuration loading from environment variables
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Environment variable names for storage configuration
|
|
11
|
+
* @public
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { ENV_VARS } from '@pelatform/storage';
|
|
16
|
+
*
|
|
17
|
+
* // Check if specific env vars are set
|
|
18
|
+
* console.log(process.env[ENV_VARS.PELATFORM_S3_BUCKET]);
|
|
19
|
+
* console.log(process.env[ENV_VARS.PELATFORM_CLOUDINARY_CLOUD_NAME]);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
declare const ENV_VARS: {
|
|
23
|
+
readonly PELATFORM_S3_PROVIDER: "PELATFORM_S3_PROVIDER";
|
|
24
|
+
readonly PELATFORM_S3_REGION: "PELATFORM_S3_REGION";
|
|
25
|
+
readonly PELATFORM_S3_BUCKET: "PELATFORM_S3_BUCKET";
|
|
26
|
+
readonly PELATFORM_S3_ACCESS_KEY_ID: "PELATFORM_S3_ACCESS_KEY_ID";
|
|
27
|
+
readonly PELATFORM_S3_SECRET_ACCESS_KEY: "PELATFORM_S3_SECRET_ACCESS_KEY";
|
|
28
|
+
readonly PELATFORM_S3_ENDPOINT: "PELATFORM_S3_ENDPOINT";
|
|
29
|
+
readonly PELATFORM_S3_FORCE_PATH_STYLE: "PELATFORM_S3_FORCE_PATH_STYLE";
|
|
30
|
+
readonly PELATFORM_S3_PUBLIC_URL: "PELATFORM_S3_PUBLIC_URL";
|
|
31
|
+
readonly PELATFORM_CLOUDINARY_CLOUD_NAME: "PELATFORM_CLOUDINARY_CLOUD_NAME";
|
|
32
|
+
readonly PELATFORM_CLOUDINARY_API_KEY: "PELATFORM_CLOUDINARY_API_KEY";
|
|
33
|
+
readonly PELATFORM_CLOUDINARY_API_SECRET: "PELATFORM_CLOUDINARY_API_SECRET";
|
|
34
|
+
readonly PELATFORM_CLOUDINARY_SECURE: "PELATFORM_CLOUDINARY_SECURE";
|
|
35
|
+
readonly PELATFORM_CLOUDINARY_FOLDER: "PELATFORM_CLOUDINARY_FOLDER";
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Load S3 configuration from environment variables
|
|
39
|
+
* @returns S3 configuration object
|
|
40
|
+
* @throws Error if required environment variables are missing
|
|
41
|
+
* @public
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { loadS3Config } from '@pelatform/storage';
|
|
46
|
+
*
|
|
47
|
+
* // Set environment variables first:
|
|
48
|
+
* // PELATFORM_S3_PROVIDER=aws
|
|
49
|
+
* // PELATFORM_S3_REGION=us-east-1
|
|
50
|
+
* // PELATFORM_S3_BUCKET=my-bucket
|
|
51
|
+
* // PELATFORM_S3_ACCESS_KEY_ID=AKIA...
|
|
52
|
+
* // PELATFORM_S3_SECRET_ACCESS_KEY=secret...
|
|
53
|
+
*
|
|
54
|
+
* try {
|
|
55
|
+
* const config = loadS3Config();
|
|
56
|
+
* console.log(config);
|
|
57
|
+
* // Returns: {
|
|
58
|
+
* // provider: 'aws',
|
|
59
|
+
* // region: 'us-east-1',
|
|
60
|
+
* // bucket: 'my-bucket',
|
|
61
|
+
* // accessKeyId: 'AKIA...',
|
|
62
|
+
* // secretAccessKey: 'secret...'
|
|
63
|
+
* // }
|
|
64
|
+
* } catch (error) {
|
|
65
|
+
* console.error('Missing S3 configuration:', error.message);
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare function loadS3Config(): S3Config;
|
|
70
|
+
/**
|
|
71
|
+
* Load Cloudinary configuration from environment variables
|
|
72
|
+
* @returns Cloudinary configuration object
|
|
73
|
+
* @throws Error if required environment variables are missing
|
|
74
|
+
* @public
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* import { loadCloudinaryConfig } from '@pelatform/storage';
|
|
79
|
+
*
|
|
80
|
+
* // Set environment variables first:
|
|
81
|
+
* // PELATFORM_CLOUDINARY_CLOUD_NAME=my-cloud
|
|
82
|
+
* // PELATFORM_CLOUDINARY_API_KEY=123456789
|
|
83
|
+
* // PELATFORM_CLOUDINARY_API_SECRET=secret...
|
|
84
|
+
* // PELATFORM_CLOUDINARY_SECURE=true (optional)
|
|
85
|
+
* // PELATFORM_CLOUDINARY_FOLDER=uploads (optional)
|
|
86
|
+
*
|
|
87
|
+
* try {
|
|
88
|
+
* const config = loadCloudinaryConfig();
|
|
89
|
+
* console.log(config);
|
|
90
|
+
* // Returns: {
|
|
91
|
+
* // provider: 'cloudinary',
|
|
92
|
+
* // cloudName: 'my-cloud',
|
|
93
|
+
* // apiKey: '123456789',
|
|
94
|
+
* // apiSecret: 'secret...',
|
|
95
|
+
* // secure: true,
|
|
96
|
+
* // folder: 'uploads'
|
|
97
|
+
* // }
|
|
98
|
+
* } catch (error) {
|
|
99
|
+
* console.error('Missing Cloudinary configuration:', error.message);
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
declare function loadCloudinaryConfig(): CloudinaryConfig;
|
|
104
|
+
/**
|
|
105
|
+
* Auto-detect and load storage configuration from environment variables
|
|
106
|
+
* Determines the provider based on available environment variables
|
|
107
|
+
* @returns Storage configuration object (S3 or Cloudinary)
|
|
108
|
+
* @throws Error if no valid configuration is found
|
|
109
|
+
* @public
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* import { loadStorageConfig } from '@pelatform/storage';
|
|
114
|
+
*
|
|
115
|
+
* // Auto-detection based on available env vars
|
|
116
|
+
* try {
|
|
117
|
+
* const config = loadStorageConfig();
|
|
118
|
+
*
|
|
119
|
+
* if (config.provider === 'cloudinary') {
|
|
120
|
+
* console.log('Using Cloudinary:', config.cloudName);
|
|
121
|
+
* } else {
|
|
122
|
+
* console.log('Using S3:', config.provider, config.bucket);
|
|
123
|
+
* }
|
|
124
|
+
* } catch (error) {
|
|
125
|
+
* console.error('No storage configuration found:', error.message);
|
|
126
|
+
* }
|
|
127
|
+
*
|
|
128
|
+
* // Explicit provider (set PELATFORM_S3_PROVIDER=cloudinary)
|
|
129
|
+
* // Will load Cloudinary config even if S3 vars are also present
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
declare function loadStorageConfig(): StorageConfig;
|
|
133
|
+
/**
|
|
134
|
+
* Check if storage configuration is available in environment variables
|
|
135
|
+
* @returns True if valid storage configuration is found
|
|
136
|
+
* @public
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* import { hasStorageConfig, loadStorageConfig } from '@pelatform/storage';
|
|
141
|
+
*
|
|
142
|
+
* if (hasStorageConfig()) {
|
|
143
|
+
* const config = loadStorageConfig();
|
|
144
|
+
* console.log('Storage configured:', config.provider);
|
|
145
|
+
* } else {
|
|
146
|
+
* console.log('Please set storage environment variables');
|
|
147
|
+
* }
|
|
148
|
+
*
|
|
149
|
+
* // Use in conditional initialization
|
|
150
|
+
* const storage = hasStorageConfig() ? createStorage() : null;
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
declare function hasStorageConfig(): boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Check if storage configuration is available in environment variables
|
|
156
|
+
* @returns True if either S3 or Cloudinary configuration is available
|
|
157
|
+
* @public
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* import { isStorageConfigured, createS3, createCloudinary } from '@pelatform/storage';
|
|
162
|
+
*
|
|
163
|
+
* if (isStorageConfigured()) {
|
|
164
|
+
* // Choose your preferred provider
|
|
165
|
+
* const s3 = createS3();
|
|
166
|
+
* // OR
|
|
167
|
+
* const cloudinary = createCloudinary();
|
|
168
|
+
*
|
|
169
|
+
* await s3.uploadFile('test.txt', 'Hello World');
|
|
170
|
+
* } else {
|
|
171
|
+
* console.log('Storage not configured. Please set environment variables.');
|
|
172
|
+
* }
|
|
173
|
+
*
|
|
174
|
+
* // Use in conditional initialization
|
|
175
|
+
* const storage = isStorageConfigured() ? createS3() : null;
|
|
176
|
+
* if (storage) {
|
|
177
|
+
* await storage.uploadFile('file.txt', content);
|
|
178
|
+
* }
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
declare function isStorageConfigured(): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Get storage provider name from environment variables without loading full config
|
|
184
|
+
* @returns Provider name or undefined if not configured
|
|
185
|
+
* @public
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* import { getStorageProvider } from '@pelatform/storage';
|
|
190
|
+
*
|
|
191
|
+
* const provider = getStorageProvider();
|
|
192
|
+
*
|
|
193
|
+
* switch (provider) {
|
|
194
|
+
* case 'aws':
|
|
195
|
+
* console.log('Using AWS S3');
|
|
196
|
+
* break;
|
|
197
|
+
* case 'cloudinary':
|
|
198
|
+
* console.log('Using Cloudinary');
|
|
199
|
+
* break;
|
|
200
|
+
* case 'cloudflare-r2':
|
|
201
|
+
* console.log('Using Cloudflare R2');
|
|
202
|
+
* break;
|
|
203
|
+
* default:
|
|
204
|
+
* console.log('No storage provider configured');
|
|
205
|
+
* }
|
|
206
|
+
*
|
|
207
|
+
* // Quick check without throwing errors
|
|
208
|
+
* if (getStorageProvider()) {
|
|
209
|
+
* // Storage is configured
|
|
210
|
+
* }
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
declare function getStorageProvider(): string | undefined;
|
|
214
|
+
/**
|
|
215
|
+
* Validate if all required environment variables are set for S3
|
|
216
|
+
* @returns Validation result with missing variables
|
|
217
|
+
* @public
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* import { validateS3EnvVars } from '@pelatform/storage';
|
|
222
|
+
*
|
|
223
|
+
* const validation = validateS3EnvVars();
|
|
224
|
+
*
|
|
225
|
+
* if (validation.valid) {
|
|
226
|
+
* console.log('S3 configuration is complete');
|
|
227
|
+
* } else {
|
|
228
|
+
* console.log('Missing S3 variables:', validation.missing);
|
|
229
|
+
* // Returns: ["PELATFORM_S3_REGION", "PELATFORM_S3_BUCKET"]
|
|
230
|
+
* }
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
declare function validateS3EnvVars(): {
|
|
234
|
+
valid: boolean;
|
|
235
|
+
missing: string[];
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* Validate if all required environment variables are set for Cloudinary
|
|
239
|
+
* @returns Validation result with missing variables
|
|
240
|
+
* @public
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* import { validateCloudinaryEnvVars } from '@pelatform/storage';
|
|
245
|
+
*
|
|
246
|
+
* const validation = validateCloudinaryEnvVars();
|
|
247
|
+
*
|
|
248
|
+
* if (validation.valid) {
|
|
249
|
+
* console.log('Cloudinary configuration is complete');
|
|
250
|
+
* } else {
|
|
251
|
+
* console.log('Missing Cloudinary variables:', validation.missing);
|
|
252
|
+
* // Returns: ["PELATFORM_CLOUDINARY_API_KEY"]
|
|
253
|
+
* }
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
declare function validateCloudinaryEnvVars(): {
|
|
257
|
+
valid: boolean;
|
|
258
|
+
missing: string[];
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Get all available environment variables for debugging
|
|
262
|
+
* @returns Object containing all storage-related env vars
|
|
263
|
+
* @public
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```typescript
|
|
267
|
+
* import { getStorageEnvVars } from '@pelatform/storage';
|
|
268
|
+
*
|
|
269
|
+
* const envVars = getStorageEnvVars();
|
|
270
|
+
* console.log('Storage environment variables:', envVars);
|
|
271
|
+
* // Returns: {
|
|
272
|
+
* // PELATFORM_S3_PROVIDER: 'aws',
|
|
273
|
+
* // PELATFORM_S3_REGION: 'us-east-1',
|
|
274
|
+
* // PELATFORM_S3_BUCKET: 'my-bucket',
|
|
275
|
+
* // // ... other set variables (secrets are masked)
|
|
276
|
+
* // }
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
declare function getStorageEnvVars(): Record<string, string | undefined>;
|
|
280
|
+
|
|
281
|
+
export { CloudinaryConfig, ENV_VARS, S3Config, StorageConfig, getStorageEnvVars, getStorageProvider, hasStorageConfig, isStorageConfigured, loadCloudinaryConfig, loadS3Config, loadStorageConfig, validateCloudinaryEnvVars, validateS3EnvVars };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ENV_VARS,
|
|
3
|
+
getStorageEnvVars,
|
|
4
|
+
getStorageProvider,
|
|
5
|
+
hasStorageConfig,
|
|
6
|
+
isStorageConfigured,
|
|
7
|
+
loadCloudinaryConfig,
|
|
8
|
+
loadS3Config,
|
|
9
|
+
loadStorageConfig,
|
|
10
|
+
validateCloudinaryEnvVars,
|
|
11
|
+
validateS3EnvVars
|
|
12
|
+
} from "./chunk-ZTZZCC52.js";
|
|
13
|
+
export {
|
|
14
|
+
ENV_VARS,
|
|
15
|
+
getStorageEnvVars,
|
|
16
|
+
getStorageProvider,
|
|
17
|
+
hasStorageConfig,
|
|
18
|
+
isStorageConfigured,
|
|
19
|
+
loadCloudinaryConfig,
|
|
20
|
+
loadS3Config,
|
|
21
|
+
loadStorageConfig,
|
|
22
|
+
validateCloudinaryEnvVars,
|
|
23
|
+
validateS3EnvVars
|
|
24
|
+
};
|
package/dist/s3.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { A as StorageInterface, S as S3Config, U as UploadOptions, e as UploadResult, D as DownloadOptions, f as DownloadResult, g as DeleteOptions, h as DeleteResult, B as BatchDeleteOptions, i as BatchDeleteResult, L as ListOptions, o as ListResult, E as ExistsResult, j as CopyOptions, k as CopyResult, M as MoveOptions, l as MoveResult, m as DuplicateOptions, n as DuplicateResult, P as PresignedUrlOptions, p as PresignedUrlResult, q as CreateFolderOptions, r as CreateFolderResult, s as DeleteFolderOptions, t as DeleteFolderResult, u as ListFoldersOptions, v as ListFoldersResult, w as FolderExistsResult, R as RenameFolderOptions, x as RenameFolderResult, y as CopyFolderOptions, z as CopyFolderResult } from './storage-interface-UizTndyU.js';
|
|
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 };
|