@oxyhq/services 5.10.5 → 5.10.6

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.
Files changed (36) hide show
  1. package/lib/commonjs/core/OxyServices.js +1 -1
  2. package/lib/commonjs/core/OxyServices.js.map +1 -1
  3. package/lib/commonjs/index.js +31 -1
  4. package/lib/commonjs/index.js.map +1 -1
  5. package/lib/commonjs/utils/s3FileManager.js +243 -0
  6. package/lib/commonjs/utils/s3FileManager.js.map +1 -0
  7. package/lib/commonjs/utils/s3FileManagerExample.js +407 -0
  8. package/lib/commonjs/utils/s3FileManagerExample.js.map +1 -0
  9. package/lib/commonjs/utils/s3FileManagerRN.js +274 -0
  10. package/lib/commonjs/utils/s3FileManagerRN.js.map +1 -0
  11. package/lib/module/core/OxyServices.js +1 -1
  12. package/lib/module/core/OxyServices.js.map +1 -1
  13. package/lib/module/index.js +4 -0
  14. package/lib/module/index.js.map +1 -1
  15. package/lib/module/utils/s3FileManager.js +237 -0
  16. package/lib/module/utils/s3FileManager.js.map +1 -0
  17. package/lib/module/utils/s3FileManagerExample.js +400 -0
  18. package/lib/module/utils/s3FileManagerExample.js.map +1 -0
  19. package/lib/module/utils/s3FileManagerRN.js +268 -0
  20. package/lib/module/utils/s3FileManagerRN.js.map +1 -0
  21. package/lib/typescript/core/OxyServices.d.ts +2 -2
  22. package/lib/typescript/core/OxyServices.d.ts.map +1 -1
  23. package/lib/typescript/index.d.ts +4 -0
  24. package/lib/typescript/index.d.ts.map +1 -1
  25. package/lib/typescript/utils/s3FileManager.d.ts +81 -0
  26. package/lib/typescript/utils/s3FileManager.d.ts.map +1 -0
  27. package/lib/typescript/utils/s3FileManagerExample.d.ts +87 -0
  28. package/lib/typescript/utils/s3FileManagerExample.d.ts.map +1 -0
  29. package/lib/typescript/utils/s3FileManagerRN.d.ts +104 -0
  30. package/lib/typescript/utils/s3FileManagerRN.d.ts.map +1 -0
  31. package/package.json +3 -1
  32. package/src/core/OxyServices.ts +2 -2
  33. package/src/index.ts +17 -1
  34. package/src/utils/s3FileManager.ts +281 -0
  35. package/src/utils/s3FileManagerExample.ts +432 -0
  36. package/src/utils/s3FileManagerRN.ts +322 -0
@@ -0,0 +1,407 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.validateFile = exports.useS3FileManager = exports.uploadWithRetry = exports.WebFileManagerExample = exports.ReactNativeFileManagerExample = void 0;
7
+ var _s3FileManager = require("./s3FileManager");
8
+ var _s3FileManagerRN = require("./s3FileManagerRN");
9
+ /**
10
+ * S3 File Management Examples
11
+ *
12
+ * This file demonstrates how to use the S3 file management functionality
13
+ * in both web and React Native environments.
14
+ */
15
+
16
+ // Example configuration
17
+ const s3Config = {
18
+ region: 'us-east-1',
19
+ accessKeyId: 'your-access-key-id',
20
+ secretAccessKey: 'your-secret-access-key',
21
+ bucketName: 'your-bucket-name'
22
+ };
23
+
24
+ // ============================================================================
25
+ // WEB ENVIRONMENT EXAMPLES
26
+ // ============================================================================
27
+
28
+ class WebFileManagerExample {
29
+ constructor() {
30
+ this.s3Manager = (0, _s3FileManager.createS3FileManager)(s3Config);
31
+ }
32
+
33
+ /**
34
+ * Example: Upload a file from web form
35
+ */
36
+ async uploadFileFromForm(fileInput) {
37
+ const file = fileInput.files?.[0];
38
+ if (!file) {
39
+ throw new Error('No file selected');
40
+ }
41
+ const key = `uploads/${Date.now()}-${file.name}`;
42
+ const uploadOptions = {
43
+ contentType: file.type,
44
+ metadata: {
45
+ originalName: file.name,
46
+ uploadedBy: 'web-user',
47
+ uploadedAt: new Date().toISOString()
48
+ },
49
+ publicRead: false
50
+ };
51
+ try {
52
+ const url = await this.s3Manager.uploadFile(key, file, uploadOptions);
53
+ console.log('File uploaded successfully:', url);
54
+ return url;
55
+ } catch (error) {
56
+ console.error('Upload failed:', error);
57
+ throw error;
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Example: Upload multiple files
63
+ */
64
+ async uploadMultipleFiles(fileList) {
65
+ const files = Array.from(fileList).map(file => ({
66
+ key: `uploads/${Date.now()}-${file.name}`,
67
+ file,
68
+ options: {
69
+ contentType: file.type,
70
+ metadata: {
71
+ originalName: file.name,
72
+ uploadedBy: 'web-user',
73
+ uploadedAt: new Date().toISOString()
74
+ },
75
+ publicRead: false
76
+ }
77
+ }));
78
+ try {
79
+ const urls = await this.s3Manager.uploadMultipleFiles(files);
80
+ console.log('Files uploaded successfully:', urls);
81
+ return urls;
82
+ } catch (error) {
83
+ console.error('Upload failed:', error);
84
+ throw error;
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Example: Download a file
90
+ */
91
+ async downloadFile(key) {
92
+ try {
93
+ const buffer = await this.s3Manager.downloadFile(key);
94
+
95
+ // Create a blob and download link
96
+ const blob = new Blob([buffer]);
97
+ const url = URL.createObjectURL(blob);
98
+ const a = document.createElement('a');
99
+ a.href = url;
100
+ a.download = key.split('/').pop() || 'download';
101
+ document.body.appendChild(a);
102
+ a.click();
103
+ document.body.removeChild(a);
104
+ URL.revokeObjectURL(url);
105
+ console.log('File downloaded successfully');
106
+ } catch (error) {
107
+ console.error('Download failed:', error);
108
+ throw error;
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Example: Get presigned URLs
114
+ */
115
+ async getPresignedUrls(key) {
116
+ try {
117
+ const uploadUrl = await this.s3Manager.getPresignedUploadUrl(key, 'application/octet-stream');
118
+ const downloadUrl = await this.s3Manager.getPresignedDownloadUrl(key);
119
+ return {
120
+ upload: uploadUrl,
121
+ download: downloadUrl
122
+ };
123
+ } catch (error) {
124
+ console.error('Failed to get presigned URLs:', error);
125
+ throw error;
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Example: List files with pagination
131
+ */
132
+ async listFiles(prefix = '', maxKeys = 50) {
133
+ try {
134
+ const files = await this.s3Manager.listFiles(prefix, maxKeys);
135
+ console.log('Files found:', files);
136
+ files.forEach(file => {
137
+ console.log(`- ${file.key} (${file.size} bytes, modified: ${file.lastModified})`);
138
+ });
139
+ } catch (error) {
140
+ console.error('Failed to list files:', error);
141
+ throw error;
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Example: File operations (copy, move, delete)
147
+ */
148
+ async performFileOperations() {
149
+ const sourceKey = 'uploads/source-file.txt';
150
+ const destKey = 'uploads/destination-file.txt';
151
+ try {
152
+ // Copy file
153
+ await this.s3Manager.copyFile(sourceKey, destKey);
154
+ console.log('File copied successfully');
155
+
156
+ // Move file
157
+ await this.s3Manager.moveFile(destKey, 'uploads/moved-file.txt');
158
+ console.log('File moved successfully');
159
+
160
+ // Delete file
161
+ await this.s3Manager.deleteFile('uploads/moved-file.txt');
162
+ console.log('File deleted successfully');
163
+ } catch (error) {
164
+ console.error('File operation failed:', error);
165
+ throw error;
166
+ }
167
+ }
168
+ }
169
+
170
+ // ============================================================================
171
+ // REACT NATIVE ENVIRONMENT EXAMPLES
172
+ // ============================================================================
173
+ exports.WebFileManagerExample = WebFileManagerExample;
174
+ class ReactNativeFileManagerExample {
175
+ constructor() {
176
+ this.s3Manager = (0, _s3FileManagerRN.createS3FileManagerRN)(s3Config);
177
+ }
178
+
179
+ /**
180
+ * Example: Upload a file from React Native
181
+ */
182
+ async uploadFileFromRN(fileInfo) {
183
+ const key = `uploads/${Date.now()}-${fileInfo.name}`;
184
+ const uploadOptions = {
185
+ contentType: fileInfo.type || 'application/octet-stream',
186
+ metadata: {
187
+ originalName: fileInfo.name,
188
+ uploadedBy: 'rn-user',
189
+ uploadedAt: new Date().toISOString(),
190
+ fileSize: fileInfo.size?.toString() || '0'
191
+ },
192
+ publicRead: false
193
+ };
194
+ try {
195
+ const url = await this.s3Manager.uploadFile(key, fileInfo, uploadOptions);
196
+ console.log('File uploaded successfully:', url);
197
+ return url;
198
+ } catch (error) {
199
+ console.error('Upload failed:', error);
200
+ throw error;
201
+ }
202
+ }
203
+
204
+ /**
205
+ * Example: Upload image with size validation
206
+ */
207
+ async uploadImageWithValidation(fileInfo, maxSize = 5 * 1024 * 1024) {
208
+ // Get file size
209
+ const fileSize = await this.s3Manager.getFileSize(fileInfo);
210
+ if (fileSize > maxSize) {
211
+ throw new Error(`File size (${fileSize} bytes) exceeds maximum allowed size (${maxSize} bytes)`);
212
+ }
213
+ const key = `images/${Date.now()}-${fileInfo.name}`;
214
+ const uploadOptions = {
215
+ contentType: fileInfo.type || 'image/jpeg',
216
+ metadata: {
217
+ originalName: fileInfo.name,
218
+ uploadedBy: 'rn-user',
219
+ uploadedAt: new Date().toISOString(),
220
+ fileSize: fileSize.toString(),
221
+ category: 'image'
222
+ },
223
+ publicRead: true // Images are often public
224
+ };
225
+ try {
226
+ const url = await this.s3Manager.uploadImage(key, fileInfo, uploadOptions);
227
+ console.log('Image uploaded successfully:', url);
228
+ return url;
229
+ } catch (error) {
230
+ console.error('Image upload failed:', error);
231
+ throw error;
232
+ }
233
+ }
234
+
235
+ /**
236
+ * Example: Download file to React Native
237
+ */
238
+ async downloadFileToRN(key) {
239
+ try {
240
+ const buffer = await this.s3Manager.downloadFile(key);
241
+ console.log('File downloaded successfully, size:', buffer.length);
242
+ return buffer;
243
+ } catch (error) {
244
+ console.error('Download failed:', error);
245
+ throw error;
246
+ }
247
+ }
248
+
249
+ /**
250
+ * Example: Batch operations
251
+ */
252
+ async performBatchOperations(files) {
253
+ try {
254
+ // Upload multiple files
255
+ const uploadPromises = files.map((file, index) => {
256
+ const key = `batch-uploads/${Date.now()}-${index}-${file.name}`;
257
+ return this.s3Manager.uploadFile(key, file, {
258
+ metadata: {
259
+ batchId: Date.now().toString()
260
+ }
261
+ });
262
+ });
263
+ const uploadedUrls = await Promise.all(uploadPromises);
264
+ console.log('Batch upload completed:', uploadedUrls);
265
+
266
+ // Delete multiple files (example with keys)
267
+ const keysToDelete = uploadedUrls.map(url => {
268
+ const key = url.split('/').pop();
269
+ return `batch-uploads/${key}`;
270
+ });
271
+ await this.s3Manager.deleteMultipleFiles(keysToDelete);
272
+ console.log('Batch delete completed');
273
+ } catch (error) {
274
+ console.error('Batch operations failed:', error);
275
+ throw error;
276
+ }
277
+ }
278
+ }
279
+
280
+ // ============================================================================
281
+ // USAGE EXAMPLES
282
+ // ============================================================================
283
+
284
+ /**
285
+ * Example usage in a React component
286
+ */
287
+ exports.ReactNativeFileManagerExample = ReactNativeFileManagerExample;
288
+ const useS3FileManager = () => {
289
+ const webManager = new WebFileManagerExample();
290
+ const rnManager = new ReactNativeFileManagerExample();
291
+ const handleFileUpload = async file => {
292
+ try {
293
+ if ('uri' in file) {
294
+ // React Native file
295
+ return await rnManager.uploadFileFromRN(file);
296
+ } else {
297
+ // Web file
298
+ const mockInput = {
299
+ files: [file]
300
+ };
301
+ return await webManager.uploadFileFromForm(mockInput);
302
+ }
303
+ } catch (error) {
304
+ console.error('Upload failed:', error);
305
+ throw error;
306
+ }
307
+ };
308
+ const handleFileDownload = async key => {
309
+ try {
310
+ if (typeof window !== 'undefined') {
311
+ // Web environment
312
+ await webManager.downloadFile(key);
313
+ } else {
314
+ // React Native environment
315
+ const buffer = await rnManager.downloadFileToRN(key);
316
+ // Handle buffer in React Native (save to file system, etc.)
317
+ return buffer;
318
+ }
319
+ } catch (error) {
320
+ console.error('Download failed:', error);
321
+ throw error;
322
+ }
323
+ };
324
+ return {
325
+ uploadFile: handleFileUpload,
326
+ downloadFile: handleFileDownload,
327
+ listFiles: webManager.listFiles.bind(webManager),
328
+ getPresignedUrls: webManager.getPresignedUrls.bind(webManager)
329
+ };
330
+ };
331
+
332
+ /**
333
+ * Example: Error handling and retry logic
334
+ */
335
+ exports.useS3FileManager = useS3FileManager;
336
+ const uploadWithRetry = async (s3Manager, key, file, options = {}, maxRetries = 3) => {
337
+ // Type guard to determine which manager we're using
338
+ const isRNManager = manager => {
339
+ return 'getFileSize' in manager;
340
+ };
341
+ let lastError;
342
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
343
+ try {
344
+ if (isRNManager(s3Manager)) {
345
+ // For React Native manager, ensure file is RNFile
346
+ if ('uri' in file) {
347
+ return await s3Manager.uploadFile(key, file, options);
348
+ } else {
349
+ throw new Error('React Native manager requires RNFile with uri property');
350
+ }
351
+ } else {
352
+ // For web manager, ensure file is not RNFile
353
+ if ('uri' in file) {
354
+ throw new Error('Web manager does not support RNFile');
355
+ } else {
356
+ return await s3Manager.uploadFile(key, file, options);
357
+ }
358
+ }
359
+ } catch (error) {
360
+ lastError = error;
361
+ console.warn(`Upload attempt ${attempt} failed:`, error);
362
+ if (attempt < maxRetries) {
363
+ // Wait before retrying (exponential backoff)
364
+ const delay = Math.pow(2, attempt) * 1000;
365
+ await new Promise(resolve => setTimeout(resolve, delay));
366
+ }
367
+ }
368
+ }
369
+ throw new Error(`Upload failed after ${maxRetries} attempts. Last error: ${lastError?.message || 'Unknown error'}`);
370
+ };
371
+
372
+ /**
373
+ * Example: File validation utilities
374
+ */
375
+ exports.uploadWithRetry = uploadWithRetry;
376
+ const validateFile = (file, options = {}) => {
377
+ const errors = [];
378
+ const {
379
+ maxSize = 10 * 1024 * 1024,
380
+ allowedTypes = [],
381
+ allowedExtensions = []
382
+ } = options;
383
+
384
+ // Check file size
385
+ if ('size' in file && file.size && file.size > maxSize) {
386
+ errors.push(`File size (${file.size} bytes) exceeds maximum allowed size (${maxSize} bytes)`);
387
+ }
388
+
389
+ // Check file type
390
+ if ('type' in file && file.type && allowedTypes.length > 0 && !allowedTypes.includes(file.type)) {
391
+ errors.push(`File type (${file.type}) is not allowed`);
392
+ }
393
+
394
+ // Check file extension
395
+ if (allowedExtensions.length > 0) {
396
+ const extension = file.name.split('.').pop()?.toLowerCase();
397
+ if (!extension || !allowedExtensions.includes(`.${extension}`)) {
398
+ errors.push(`File extension (.${extension}) is not allowed`);
399
+ }
400
+ }
401
+ return {
402
+ isValid: errors.length === 0,
403
+ errors
404
+ };
405
+ };
406
+ exports.validateFile = validateFile;
407
+ //# sourceMappingURL=s3FileManagerExample.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_s3FileManager","require","_s3FileManagerRN","s3Config","region","accessKeyId","secretAccessKey","bucketName","WebFileManagerExample","constructor","s3Manager","createS3FileManager","uploadFileFromForm","fileInput","file","files","Error","key","Date","now","name","uploadOptions","contentType","type","metadata","originalName","uploadedBy","uploadedAt","toISOString","publicRead","url","uploadFile","console","log","error","uploadMultipleFiles","fileList","Array","from","map","options","urls","downloadFile","buffer","blob","Blob","URL","createObjectURL","a","document","createElement","href","download","split","pop","body","appendChild","click","removeChild","revokeObjectURL","getPresignedUrls","uploadUrl","getPresignedUploadUrl","downloadUrl","getPresignedDownloadUrl","upload","listFiles","prefix","maxKeys","forEach","size","lastModified","performFileOperations","sourceKey","destKey","copyFile","moveFile","deleteFile","exports","ReactNativeFileManagerExample","createS3FileManagerRN","uploadFileFromRN","fileInfo","fileSize","toString","uploadImageWithValidation","maxSize","getFileSize","category","uploadImage","downloadFileToRN","length","performBatchOperations","uploadPromises","index","batchId","uploadedUrls","Promise","all","keysToDelete","deleteMultipleFiles","useS3FileManager","webManager","rnManager","handleFileUpload","mockInput","handleFileDownload","window","bind","uploadWithRetry","maxRetries","isRNManager","manager","lastError","attempt","warn","delay","Math","pow","resolve","setTimeout","message","validateFile","errors","allowedTypes","allowedExtensions","push","includes","extension","toLowerCase","isValid"],"sourceRoot":"../../../src","sources":["utils/s3FileManagerExample.ts"],"mappings":";;;;;;AAOA,IAAAA,cAAA,GAAAC,OAAA;AAMA,IAAAC,gBAAA,GAAAD,OAAA;AAbA;AACA;AACA;AACA;AACA;AACA;;AAcA;AACA,MAAME,QAAkB,GAAG;EACzBC,MAAM,EAAE,WAAW;EACnBC,WAAW,EAAE,oBAAoB;EACjCC,eAAe,EAAE,wBAAwB;EACzCC,UAAU,EAAE;AACd,CAAC;;AAED;AACA;AACA;;AAEO,MAAMC,qBAAqB,CAAC;EAGjCC,WAAWA,CAAA,EAAG;IACZ,IAAI,CAACC,SAAS,GAAG,IAAAC,kCAAmB,EAACR,QAAQ,CAAC;EAChD;;EAEA;AACF;AACA;EACE,MAAMS,kBAAkBA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AIxE,IAAI,IAAIA,IAAI,CAACS,IAAI,IAAIqG,YAAY,CAACjC,MAAM,GAAG,CAAC,IAAI,CAACiC,YAAY,CAACG,QAAQ,CAACjH,IAAI,CAACS,IAAI,CAAC,EAAE;IAC/FoG,MAAM,CAACG,IAAI,CAAC,cAAchH,IAAI,CAACS,IAAI,kBAAkB,CAAC;EACxD;;EAEA;EACA,IAAIsG,iBAAiB,CAAClC,MAAM,GAAG,CAAC,EAAE;IAChC,MAAMqC,SAAS,GAAGlH,IAAI,CAACM,IAAI,CAACiC,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAAC,CAAC,EAAE2E,WAAW,CAAC,CAAC;IAC3D,IAAI,CAACD,SAAS,IAAI,CAACH,iBAAiB,CAACE,QAAQ,CAAC,IAAIC,SAAS,EAAE,CAAC,EAAE;MAC9DL,MAAM,CAACG,IAAI,CAAC,oBAAoBE,SAAS,kBAAkB,CAAC;IAC9D;EACF;EAEA,OAAO;IACLE,OAAO,EAAEP,MAAM,CAAChC,MAAM,KAAK,CAAC;IAC5BgC;EACF,CAAC;AACH,CAAC;AAAC7C,OAAA,CAAA4C,YAAA,GAAAA,YAAA","ignoreList":[]}
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.S3FileManagerRN = void 0;
7
+ exports.createS3FileManagerRN = createS3FileManagerRN;
8
+ var _clientS = require("@aws-sdk/client-s3");
9
+ var _s3RequestPresigner = require("@aws-sdk/s3-request-presigner");
10
+ class S3FileManagerRN {
11
+ constructor(config) {
12
+ this.s3Client = new _clientS.S3Client({
13
+ region: config.region,
14
+ credentials: {
15
+ accessKeyId: config.accessKeyId,
16
+ secretAccessKey: config.secretAccessKey
17
+ }
18
+ });
19
+ this.bucketName = config.bucketName;
20
+ }
21
+
22
+ /**
23
+ * Upload a file to S3 from React Native
24
+ */
25
+ async uploadFile(key, file, options = {}) {
26
+ let body;
27
+ let contentType = options.contentType;
28
+ if (this.isRNFile(file)) {
29
+ body = await this.rnFileToBuffer(file);
30
+ contentType = contentType || file.type || 'application/octet-stream';
31
+ } else if (typeof file === 'string') {
32
+ body = file;
33
+ contentType = contentType || 'text/plain';
34
+ } else {
35
+ body = file;
36
+ contentType = contentType || 'application/octet-stream';
37
+ }
38
+ const command = new _clientS.PutObjectCommand({
39
+ Bucket: this.bucketName,
40
+ Key: key,
41
+ Body: body,
42
+ ContentType: contentType,
43
+ Metadata: options.metadata,
44
+ ACL: options.publicRead ? 'public-read' : 'private'
45
+ });
46
+ await this.s3Client.send(command);
47
+ return `https://${this.bucketName}.s3.amazonaws.com/${key}`;
48
+ }
49
+
50
+ /**
51
+ * Download a file from S3 to React Native
52
+ */
53
+ async downloadFile(key) {
54
+ const command = new _clientS.GetObjectCommand({
55
+ Bucket: this.bucketName,
56
+ Key: key
57
+ });
58
+ const response = await this.s3Client.send(command);
59
+ if (!response.Body) {
60
+ throw new Error('File not found or empty');
61
+ }
62
+
63
+ // Convert stream to buffer
64
+ const chunks = [];
65
+ const reader = response.Body.transformToWebStream().getReader();
66
+ while (true) {
67
+ const {
68
+ done,
69
+ value
70
+ } = await reader.read();
71
+ if (done) break;
72
+ chunks.push(value);
73
+ }
74
+ return Buffer.concat(chunks);
75
+ }
76
+
77
+ /**
78
+ * Delete a file from S3
79
+ */
80
+ async deleteFile(key) {
81
+ const command = new _clientS.DeleteObjectCommand({
82
+ Bucket: this.bucketName,
83
+ Key: key
84
+ });
85
+ await this.s3Client.send(command);
86
+ }
87
+
88
+ /**
89
+ * Generate a presigned URL for file upload
90
+ */
91
+ async getPresignedUploadUrl(key, contentType, expiresIn = 3600) {
92
+ const command = new _clientS.PutObjectCommand({
93
+ Bucket: this.bucketName,
94
+ Key: key,
95
+ ContentType: contentType
96
+ });
97
+ return (0, _s3RequestPresigner.getSignedUrl)(this.s3Client, command, {
98
+ expiresIn
99
+ });
100
+ }
101
+
102
+ /**
103
+ * Generate a presigned URL for file download
104
+ */
105
+ async getPresignedDownloadUrl(key, expiresIn = 3600) {
106
+ const command = new _clientS.GetObjectCommand({
107
+ Bucket: this.bucketName,
108
+ Key: key
109
+ });
110
+ return (0, _s3RequestPresigner.getSignedUrl)(this.s3Client, command, {
111
+ expiresIn
112
+ });
113
+ }
114
+
115
+ /**
116
+ * List files in a directory
117
+ */
118
+ async listFiles(prefix = '', maxKeys = 1000) {
119
+ const command = new _clientS.ListObjectsV2Command({
120
+ Bucket: this.bucketName,
121
+ Prefix: prefix,
122
+ MaxKeys: maxKeys
123
+ });
124
+ const response = await this.s3Client.send(command);
125
+ if (!response.Contents) {
126
+ return [];
127
+ }
128
+ return response.Contents.map(item => ({
129
+ key: item.Key,
130
+ size: item.Size || 0,
131
+ lastModified: item.LastModified
132
+ }));
133
+ }
134
+
135
+ /**
136
+ * Check if a file exists
137
+ */
138
+ async fileExists(key) {
139
+ try {
140
+ const command = new _clientS.GetObjectCommand({
141
+ Bucket: this.bucketName,
142
+ Key: key
143
+ });
144
+ await this.s3Client.send(command);
145
+ return true;
146
+ } catch (error) {
147
+ if (error.name === 'NoSuchKey') {
148
+ return false;
149
+ }
150
+ throw error;
151
+ }
152
+ }
153
+
154
+ /**
155
+ * Get file metadata
156
+ */
157
+ async getFileMetadata(key) {
158
+ try {
159
+ const command = new _clientS.GetObjectCommand({
160
+ Bucket: this.bucketName,
161
+ Key: key
162
+ });
163
+ const response = await this.s3Client.send(command);
164
+ return {
165
+ key,
166
+ size: parseInt(response.ContentLength?.toString() || '0'),
167
+ lastModified: response.LastModified,
168
+ contentType: response.ContentType,
169
+ metadata: response.Metadata
170
+ };
171
+ } catch (error) {
172
+ if (error.name === 'NoSuchKey') {
173
+ return null;
174
+ }
175
+ throw error;
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Convert React Native file to Buffer
181
+ */
182
+ async rnFileToBuffer(file) {
183
+ try {
184
+ // For React Native, we need to fetch the file from the URI
185
+ const response = await fetch(file.uri);
186
+ const arrayBuffer = await response.arrayBuffer();
187
+ return Buffer.from(arrayBuffer);
188
+ } catch (error) {
189
+ throw new Error(`Failed to read React Native file: ${error}`);
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Type guard to check if object is RNFile
195
+ */
196
+ isRNFile(file) {
197
+ return file && typeof file === 'object' && 'uri' in file && 'name' in file;
198
+ }
199
+
200
+ /**
201
+ * Upload multiple files
202
+ */
203
+ async uploadMultipleFiles(files) {
204
+ const uploadPromises = files.map(({
205
+ key,
206
+ file,
207
+ options
208
+ }) => this.uploadFile(key, file, options));
209
+ return Promise.all(uploadPromises);
210
+ }
211
+
212
+ /**
213
+ * Delete multiple files
214
+ */
215
+ async deleteMultipleFiles(keys) {
216
+ const deletePromises = keys.map(key => this.deleteFile(key));
217
+ await Promise.all(deletePromises);
218
+ }
219
+
220
+ /**
221
+ * Copy file from one key to another
222
+ */
223
+ async copyFile(sourceKey, destinationKey) {
224
+ const command = new _clientS.PutObjectCommand({
225
+ Bucket: this.bucketName,
226
+ Key: destinationKey,
227
+ Body: await this.downloadFile(sourceKey)
228
+ });
229
+ await this.s3Client.send(command);
230
+ }
231
+
232
+ /**
233
+ * Move file (copy + delete)
234
+ */
235
+ async moveFile(sourceKey, destinationKey) {
236
+ await this.copyFile(sourceKey, destinationKey);
237
+ await this.deleteFile(sourceKey);
238
+ }
239
+
240
+ /**
241
+ * Upload image with automatic resizing (placeholder for future implementation)
242
+ */
243
+ async uploadImage(key, file, options = {}) {
244
+ // For now, just upload as regular file
245
+ // In the future, this could integrate with image processing libraries
246
+ return this.uploadFile(key, file, options);
247
+ }
248
+
249
+ /**
250
+ * Get file size from React Native file
251
+ */
252
+ async getFileSize(file) {
253
+ if (file.size) {
254
+ return file.size;
255
+ }
256
+ try {
257
+ const response = await fetch(file.uri, {
258
+ method: 'HEAD'
259
+ });
260
+ const contentLength = response.headers.get('content-length');
261
+ return contentLength ? parseInt(contentLength, 10) : 0;
262
+ } catch (error) {
263
+ console.warn('Could not determine file size:', error);
264
+ return 0;
265
+ }
266
+ }
267
+ }
268
+
269
+ // Export a factory function for easier configuration
270
+ exports.S3FileManagerRN = S3FileManagerRN;
271
+ function createS3FileManagerRN(config) {
272
+ return new S3FileManagerRN(config);
273
+ }
274
+ //# sourceMappingURL=s3FileManagerRN.js.map