@pelatform/storage 1.0.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,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.cjs ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+ var _chunkI3ME6WAGcjs = require('./chunk-I3ME6WAG.cjs');
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+ exports.ENV_VARS = _chunkI3ME6WAGcjs.ENV_VARS; exports.getStorageEnvVars = _chunkI3ME6WAGcjs.getStorageEnvVars; exports.getStorageProvider = _chunkI3ME6WAGcjs.getStorageProvider; exports.hasStorageConfig = _chunkI3ME6WAGcjs.hasStorageConfig; exports.isStorageConfigured = _chunkI3ME6WAGcjs.isStorageConfigured; exports.loadCloudinaryConfig = _chunkI3ME6WAGcjs.loadCloudinaryConfig; exports.loadS3Config = _chunkI3ME6WAGcjs.loadS3Config; exports.loadStorageConfig = _chunkI3ME6WAGcjs.loadStorageConfig; exports.validateCloudinaryEnvVars = _chunkI3ME6WAGcjs.validateCloudinaryEnvVars; exports.validateS3EnvVars = _chunkI3ME6WAGcjs.validateS3EnvVars;
@@ -0,0 +1,281 @@
1
+ import { v as S3Config, C as CloudinaryConfig, w as StorageConfig } from './storage-interface-BKeDAlGP.cjs';
2
+ export { B as BatchDeleteOptions, e as BatchDeleteResult, t as CopyFolderOptions, u as CopyFolderResult, g as CopyOptions, h as CopyResult, m as CreateFolderOptions, n as CreateFolderResult, o as DeleteFolderOptions, p as DeleteFolderResult, c as DeleteOptions, d as DeleteResult, D as DownloadOptions, b as DownloadResult, j as DuplicateOptions, k as DuplicateResult, E as ExistsResult, z as FileInfo, F as FolderExistsResult, A as FolderInfo, q as ListFoldersOptions, r as ListFoldersResult, L as ListOptions, f as ListResult, M as MoveOptions, i as MoveResult, P as PresignedUrlOptions, l as PresignedUrlResult, R as RenameFolderOptions, s as RenameFolderResult, x as S3ProviderType, S as StorageInterface, y as StorageProvider, U as UploadOptions, a as UploadResult } from './storage-interface-BKeDAlGP.cjs';
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 };
@@ -0,0 +1,281 @@
1
+ import { v as S3Config, C as CloudinaryConfig, w as StorageConfig } from './storage-interface-BKeDAlGP.js';
2
+ export { B as BatchDeleteOptions, e as BatchDeleteResult, t as CopyFolderOptions, u as CopyFolderResult, g as CopyOptions, h as CopyResult, m as CreateFolderOptions, n as CreateFolderResult, o as DeleteFolderOptions, p as DeleteFolderResult, c as DeleteOptions, d as DeleteResult, D as DownloadOptions, b as DownloadResult, j as DuplicateOptions, k as DuplicateResult, E as ExistsResult, z as FileInfo, F as FolderExistsResult, A as FolderInfo, q as ListFoldersOptions, r as ListFoldersResult, L as ListOptions, f as ListResult, M as MoveOptions, i as MoveResult, P as PresignedUrlOptions, l as PresignedUrlResult, R as RenameFolderOptions, s as RenameFolderResult, x as S3ProviderType, S as StorageInterface, y as StorageProvider, U as UploadOptions, a as UploadResult } from './storage-interface-BKeDAlGP.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
+ };