@nextlyhq/storage-s3 0.0.2-alpha.68 → 0.0.2-alpha.69
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 +1 -1
- package/dist/index.cjs +1306 -1125
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +530 -690
- package/dist/index.d.ts +530 -690
- package/dist/index.mjs +1305 -1123
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -17
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { S3Client, S3ClientConfig } from "@aws-sdk/client-s3";
|
|
3
2
|
/**
|
|
4
3
|
* Media Storage Types
|
|
5
4
|
*
|
|
@@ -11,24 +10,24 @@ import { S3ClientConfig, S3Client } from '@aws-sdk/client-s3';
|
|
|
11
10
|
* - Vercel Blob (via @nextlyhq/storage-vercel-blob)
|
|
12
11
|
*/
|
|
13
12
|
interface UploadOptions {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
/** Original filename from user */
|
|
14
|
+
filename: string;
|
|
15
|
+
/** MIME type (e.g., 'image/png', 'video/mp4') */
|
|
16
|
+
mimeType: string;
|
|
17
|
+
/** Optional content type override */
|
|
18
|
+
contentType?: string;
|
|
19
|
+
/** Optional folder/prefix for organizing uploads */
|
|
20
|
+
folder?: string;
|
|
21
|
+
/** Collection slug this upload belongs to (for collection-specific storage) */
|
|
22
|
+
collection?: string;
|
|
23
|
+
/** Optional Content-Disposition header value (e.g., 'attachment' for SVG security) */
|
|
24
|
+
contentDisposition?: "inline" | "attachment";
|
|
26
25
|
}
|
|
27
26
|
interface UploadResult {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
/** Public URL to access the file */
|
|
28
|
+
url: string;
|
|
29
|
+
/** Storage path/key (for deletion and metadata retrieval) */
|
|
30
|
+
path: string;
|
|
32
31
|
}
|
|
33
32
|
/**
|
|
34
33
|
* Extended file metadata returned by getMetadata()
|
|
@@ -37,28 +36,28 @@ interface UploadResult {
|
|
|
37
36
|
* including dimensions for images and creation timestamps.
|
|
38
37
|
*/
|
|
39
38
|
interface FileMetadata {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
39
|
+
/** Unique identifier (typically the storage path/key) */
|
|
40
|
+
id: string;
|
|
41
|
+
/** Storage filename (may differ from original) */
|
|
42
|
+
filename: string;
|
|
43
|
+
/** Original filename as uploaded by user */
|
|
44
|
+
originalFilename: string;
|
|
45
|
+
/** MIME type (e.g., 'image/jpeg', 'application/pdf') */
|
|
46
|
+
mimeType: string;
|
|
47
|
+
/** File size in bytes */
|
|
48
|
+
size: number;
|
|
49
|
+
/** Public URL to access the file */
|
|
50
|
+
url: string;
|
|
51
|
+
/** Thumbnail URL for images (if generated) */
|
|
52
|
+
thumbnailUrl?: string;
|
|
53
|
+
/** Image width in pixels (for images only) */
|
|
54
|
+
width?: number;
|
|
55
|
+
/** Image height in pixels (for images only) */
|
|
56
|
+
height?: number;
|
|
57
|
+
/** ISO timestamp when file was uploaded */
|
|
58
|
+
createdAt: string;
|
|
59
|
+
/** ISO timestamp when file was last modified */
|
|
60
|
+
updatedAt?: string;
|
|
62
61
|
}
|
|
63
62
|
/**
|
|
64
63
|
* Storage type identifier.
|
|
@@ -87,34 +86,34 @@ type StorageType = "s3" | "vercel-blob" | "local" | "uploadthing";
|
|
|
87
86
|
* oversized object fails as a size error rather than after it has been read.
|
|
88
87
|
*/
|
|
89
88
|
interface StorageReadOptions {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
/** Refuse once this many bytes have arrived. Defaults to the fetch cap. */
|
|
90
|
+
maxBytes?: number;
|
|
91
|
+
/** Give up after this long. Defaults to the fetch deadline. */
|
|
92
|
+
timeoutMs?: number;
|
|
94
93
|
}
|
|
95
94
|
interface StorageAdapterInfo {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
95
|
+
/** Storage type identifier */
|
|
96
|
+
type: StorageType;
|
|
97
|
+
/** Human-readable adapter name */
|
|
98
|
+
name: string;
|
|
99
|
+
/** Whether this adapter supports signed URLs for private access */
|
|
100
|
+
supportsSignedUrls: boolean;
|
|
101
|
+
/** Whether this adapter supports client-side (direct) uploads */
|
|
102
|
+
supportsClientUploads: boolean;
|
|
104
103
|
}
|
|
105
104
|
/**
|
|
106
105
|
* Per-collection storage configuration.
|
|
107
106
|
* Allows customizing storage behavior for specific upload collections.
|
|
108
107
|
*/
|
|
109
108
|
interface CollectionStorageConfig {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
109
|
+
/** Prefix/folder for this collection's uploads */
|
|
110
|
+
prefix?: string;
|
|
111
|
+
/** Enable client-side uploads (for serverless platforms with body size limits) */
|
|
112
|
+
clientUploads?: boolean;
|
|
113
|
+
/** Generate signed URLs for downloads (for private buckets) */
|
|
114
|
+
signedDownloads?: boolean;
|
|
115
|
+
/** Signed URL expiry time in seconds (default: 3600) */
|
|
116
|
+
signedUrlExpiresIn?: number;
|
|
118
117
|
}
|
|
119
118
|
/**
|
|
120
119
|
* Collection storage map - maps collection slugs to their config.
|
|
@@ -138,10 +137,10 @@ type CollectionStorageMap = Record<string, boolean | CollectionStorageConfig>;
|
|
|
138
137
|
* Extended by specific adapter configs (S3StorageConfig, etc.)
|
|
139
138
|
*/
|
|
140
139
|
interface StoragePluginConfig {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
140
|
+
/** Enable/disable the plugin (default: true) */
|
|
141
|
+
enabled?: boolean;
|
|
142
|
+
/** Collections to apply this storage adapter to */
|
|
143
|
+
collections: CollectionStorageMap;
|
|
145
144
|
}
|
|
146
145
|
/**
|
|
147
146
|
* Storage plugin returned by adapter plugin functions.
|
|
@@ -159,24 +158,24 @@ interface StoragePluginConfig {
|
|
|
159
158
|
* ```
|
|
160
159
|
*/
|
|
161
160
|
interface StoragePlugin {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
161
|
+
/** Plugin name for identification */
|
|
162
|
+
name: string;
|
|
163
|
+
/** Storage type */
|
|
164
|
+
type: StorageType;
|
|
165
|
+
/** Collections this plugin handles */
|
|
166
|
+
collections: CollectionStorageMap;
|
|
167
|
+
/** The storage adapter instance */
|
|
168
|
+
adapter: IStorageAdapter;
|
|
169
|
+
/**
|
|
170
|
+
* Handler for generating client-side upload URLs.
|
|
171
|
+
* Called when clientUploads is enabled for a collection.
|
|
172
|
+
*/
|
|
173
|
+
getClientUploadUrl?: (filename: string, mimeType: string, collection: string) => Promise<ClientUploadData>;
|
|
174
|
+
/**
|
|
175
|
+
* Handler for generating signed download URLs.
|
|
176
|
+
* Called when signedDownloads is enabled for a collection.
|
|
177
|
+
*/
|
|
178
|
+
getSignedDownloadUrl?: (path: string, expiresIn?: number) => Promise<string>;
|
|
180
179
|
}
|
|
181
180
|
/**
|
|
182
181
|
* Data returned for client-side (direct) uploads.
|
|
@@ -199,18 +198,18 @@ interface StoragePlugin {
|
|
|
199
198
|
* ```
|
|
200
199
|
*/
|
|
201
200
|
interface ClientUploadData {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
201
|
+
/** Pre-signed URL for direct upload */
|
|
202
|
+
uploadUrl: string;
|
|
203
|
+
/** Storage path/key that will be used */
|
|
204
|
+
path: string;
|
|
205
|
+
/** HTTP method to use (usually PUT for S3, POST for some services) */
|
|
206
|
+
method: "PUT" | "POST";
|
|
207
|
+
/** Headers to include in upload request */
|
|
208
|
+
headers?: Record<string, string>;
|
|
209
|
+
/** Form fields for multipart uploads (some services require this) */
|
|
210
|
+
fields?: Record<string, string>;
|
|
211
|
+
/** URL expiry timestamp */
|
|
212
|
+
expiresAt: Date;
|
|
214
213
|
}
|
|
215
214
|
/**
|
|
216
215
|
* Base storage adapter interface.
|
|
@@ -229,47 +228,56 @@ interface ClientUploadData {
|
|
|
229
228
|
* - getSignedUrl: Generate temporary signed URLs for private access
|
|
230
229
|
* - getPresignedUploadUrl: Generate pre-signed URL for client uploads
|
|
231
230
|
*/
|
|
231
|
+
/** A file a storage holds, as {@link IStorageAdapter.list} names it. */
|
|
232
|
+
interface StoredFileEntry {
|
|
233
|
+
/** The stored path, as `upload` returned it and `delete` takes it. */
|
|
234
|
+
path: string;
|
|
235
|
+
/** When it was stored, where the storage says. */
|
|
236
|
+
lastModified?: Date;
|
|
237
|
+
/**
|
|
238
|
+
* The name it was uploaded under, where the storage keeps that apart from
|
|
239
|
+
* its path: UploadThing's keys carry no name. Elsewhere the name is the
|
|
240
|
+
* path's last segment.
|
|
241
|
+
*/
|
|
242
|
+
name?: string;
|
|
243
|
+
}
|
|
232
244
|
interface BulkDeleteResult {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
245
|
+
successful: string[];
|
|
246
|
+
failed: Array<{
|
|
247
|
+
filePath: string;
|
|
248
|
+
error: string;
|
|
249
|
+
}>;
|
|
238
250
|
}
|
|
239
251
|
interface IStorageAdapter {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
252
|
+
/** Upload file buffer to storage */
|
|
253
|
+
upload(buffer: Buffer, options: UploadOptions): Promise<UploadResult>;
|
|
254
|
+
/** Delete file from storage */
|
|
255
|
+
delete(filePath: string): Promise<void>;
|
|
256
|
+
/** Bulk delete files from storage. Optional — adapters that support batch operations should implement this. */
|
|
257
|
+
bulkDelete?(filePaths: string[]): Promise<BulkDeleteResult>;
|
|
258
|
+
/** Check if file exists in storage */
|
|
259
|
+
exists(filePath: string): Promise<boolean>;
|
|
260
|
+
/** Get public URL for file */
|
|
261
|
+
getPublicUrl(filePath: string): string;
|
|
262
|
+
/** Get storage type identifier */
|
|
263
|
+
getType(): string;
|
|
264
|
+
/** Read file contents from storage (optional - not all adapters support this) */
|
|
265
|
+
read?(filePath: string, options?: StorageReadOptions): Promise<Buffer | null>;
|
|
266
|
+
/** Get adapter info including capabilities (optional but recommended) */
|
|
267
|
+
getInfo?(): StorageAdapterInfo;
|
|
268
|
+
/** Get file metadata (optional - not all adapters support this) */
|
|
269
|
+
getMetadata?(filePath: string): Promise<FileMetadata | null>;
|
|
270
|
+
/** Generate signed URL for temporary private access (optional) */
|
|
271
|
+
getSignedUrl?(filePath: string, expiresIn?: number): Promise<string>;
|
|
272
|
+
/** Generate pre-signed upload URL for client-side uploads (optional) */
|
|
273
|
+
getPresignedUploadUrl?(key: string, mimeType: string, expiresIn?: number): Promise<ClientUploadData>;
|
|
274
|
+
/**
|
|
275
|
+
* Every file the storage holds, a page at a time (optional). Used to find
|
|
276
|
+
* files no record refers to; a storage without it cannot be searched for
|
|
277
|
+
* them, which is said rather than taken as "none".
|
|
278
|
+
*/
|
|
279
|
+
list?(): AsyncIterable<StoredFileEntry>;
|
|
262
280
|
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* S3 Storage Types
|
|
266
|
-
*
|
|
267
|
-
* Type definitions for the @nextly/storage-s3 package.
|
|
268
|
-
* Supports AWS S3 and S3-compatible services (Cloudflare R2, MinIO, DigitalOcean Spaces).
|
|
269
|
-
*
|
|
270
|
-
* @packageDocumentation
|
|
271
|
-
*/
|
|
272
|
-
|
|
273
281
|
/**
|
|
274
282
|
* S3 storage adapter configuration.
|
|
275
283
|
*
|
|
@@ -316,147 +324,147 @@ interface IStorageAdapter {
|
|
|
316
324
|
* ```
|
|
317
325
|
*/
|
|
318
326
|
interface S3StorageConfig extends StoragePluginConfig {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
327
|
+
/** Enable/disable this storage plugin (default: true). */
|
|
328
|
+
enabled?: boolean;
|
|
329
|
+
/** Collections this plugin handles. */
|
|
330
|
+
collections: Record<string, boolean | CollectionStorageConfig>;
|
|
331
|
+
/**
|
|
332
|
+
* S3 bucket name.
|
|
333
|
+
* Must be an existing bucket that the credentials have access to.
|
|
334
|
+
*/
|
|
335
|
+
bucket: string;
|
|
336
|
+
/**
|
|
337
|
+
* AWS region (e.g., 'us-east-1', 'eu-west-1').
|
|
338
|
+
* Use 'auto' for Cloudflare R2.
|
|
339
|
+
*/
|
|
340
|
+
region: string;
|
|
341
|
+
/**
|
|
342
|
+
* AWS SDK S3 client configuration.
|
|
343
|
+
* Use this for advanced configuration like custom retry strategies,
|
|
344
|
+
* request handlers, or middleware.
|
|
345
|
+
*
|
|
346
|
+
* Note: `region`, `endpoint`, `credentials`, and `forcePathStyle` can be
|
|
347
|
+
* specified either here or via the dedicated config properties. The dedicated
|
|
348
|
+
* properties take precedence if both are specified.
|
|
349
|
+
*/
|
|
350
|
+
config?: Omit<S3ClientConfig, "region">;
|
|
351
|
+
/**
|
|
352
|
+
* AWS Access Key ID.
|
|
353
|
+
* Can also be provided via `config.credentials` or environment variables
|
|
354
|
+
* (AWS_ACCESS_KEY_ID).
|
|
355
|
+
*/
|
|
356
|
+
accessKeyId?: string;
|
|
357
|
+
/**
|
|
358
|
+
* AWS Secret Access Key.
|
|
359
|
+
* Can also be provided via `config.credentials` or environment variables
|
|
360
|
+
* (AWS_SECRET_ACCESS_KEY).
|
|
361
|
+
*/
|
|
362
|
+
secretAccessKey?: string;
|
|
363
|
+
/**
|
|
364
|
+
* Custom endpoint for S3-compatible services.
|
|
365
|
+
* Required for Cloudflare R2, MinIO, DigitalOcean Spaces, etc.
|
|
366
|
+
*
|
|
367
|
+
* @example Cloudflare R2
|
|
368
|
+
* ```typescript
|
|
369
|
+
* endpoint: `https://${accountId}.r2.cloudflarestorage.com`
|
|
370
|
+
* ```
|
|
371
|
+
*
|
|
372
|
+
* @example MinIO
|
|
373
|
+
* ```typescript
|
|
374
|
+
* endpoint: 'http://localhost:9000'
|
|
375
|
+
* ```
|
|
376
|
+
*
|
|
377
|
+
* @example DigitalOcean Spaces
|
|
378
|
+
* ```typescript
|
|
379
|
+
* endpoint: 'https://nyc3.digitaloceanspaces.com'
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
endpoint?: string;
|
|
383
|
+
/**
|
|
384
|
+
* Force path-style URLs instead of virtual-hosted-style.
|
|
385
|
+
*
|
|
386
|
+
* When true: `https://endpoint/bucket/key`
|
|
387
|
+
* When false: `https://bucket.endpoint/key`
|
|
388
|
+
*
|
|
389
|
+
* Required for MinIO and some S3-compatible services.
|
|
390
|
+
*
|
|
391
|
+
* @default false
|
|
392
|
+
*/
|
|
393
|
+
forcePathStyle?: boolean;
|
|
394
|
+
/**
|
|
395
|
+
* Access Control List (ACL) for uploaded objects.
|
|
396
|
+
* Determines who can access the uploaded files.
|
|
397
|
+
*
|
|
398
|
+
* Common values:
|
|
399
|
+
* - `'private'` (default): Only authenticated users; serve via signed URLs.
|
|
400
|
+
* - `'public-read'`: Anyone can read (opt in only for buckets that
|
|
401
|
+
* genuinely host public media).
|
|
402
|
+
* - `'bucket-owner-full-control'`: Bucket owner has full control.
|
|
403
|
+
*
|
|
404
|
+
* Defaults to `'private'` so uploads are not world-readable unless
|
|
405
|
+
* explicitly opted in. Pair with `getSignedUrl()` for read access to
|
|
406
|
+
* private objects.
|
|
407
|
+
*
|
|
408
|
+
* Note: Cloudflare R2 ignores ACL settings. Configure public access
|
|
409
|
+
* in the R2 dashboard instead.
|
|
410
|
+
*
|
|
411
|
+
* @default 'private'
|
|
412
|
+
*/
|
|
413
|
+
acl?: S3ObjectACL;
|
|
414
|
+
/**
|
|
415
|
+
* Public URL override for accessing uploaded files.
|
|
416
|
+
* Use this when serving files through a CDN or custom domain.
|
|
417
|
+
*
|
|
418
|
+
* If not set, uses the standard S3 URL format:
|
|
419
|
+
* `https://{bucket}.s3.{region}.amazonaws.com/{key}`
|
|
420
|
+
*
|
|
421
|
+
* Required for Cloudflare R2 (which doesn't have default public URLs).
|
|
422
|
+
*
|
|
423
|
+
* @example CDN URL
|
|
424
|
+
* ```typescript
|
|
425
|
+
* publicUrl: 'https://cdn.example.com'
|
|
426
|
+
* ```
|
|
427
|
+
*
|
|
428
|
+
* @example R2 Public Bucket
|
|
429
|
+
* ```typescript
|
|
430
|
+
* publicUrl: 'https://pub-abc123.r2.dev'
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
publicUrl?: string;
|
|
434
|
+
/**
|
|
435
|
+
* Enable signed download URLs for private file access.
|
|
436
|
+
* When enabled, `getSignedUrl()` can generate temporary access URLs.
|
|
437
|
+
*
|
|
438
|
+
* Can be overridden per-collection in the collections map.
|
|
439
|
+
*
|
|
440
|
+
* @default false
|
|
441
|
+
*/
|
|
442
|
+
signedDownloads?: boolean;
|
|
443
|
+
/**
|
|
444
|
+
* Default expiry time for signed URLs in seconds.
|
|
445
|
+
* Applies to both download and upload URLs.
|
|
446
|
+
*
|
|
447
|
+
* Can be overridden per-collection in the collections map.
|
|
448
|
+
*
|
|
449
|
+
* @default 3600 (1 hour)
|
|
450
|
+
*/
|
|
451
|
+
signedUrlExpiresIn?: number;
|
|
452
|
+
/**
|
|
453
|
+
* Cache-Control header for uploaded files.
|
|
454
|
+
* Controls browser and CDN caching behavior.
|
|
455
|
+
*
|
|
456
|
+
* @default 'public, max-age=31536000' (1 year)
|
|
457
|
+
*/
|
|
458
|
+
cacheControl?: string;
|
|
459
|
+
/**
|
|
460
|
+
* Content-Disposition header mode for uploaded files.
|
|
461
|
+
* Controls how browsers handle file downloads.
|
|
462
|
+
*
|
|
463
|
+
* - `'inline'`: Display in browser if possible
|
|
464
|
+
* - `'attachment'`: Always prompt for download
|
|
465
|
+
* - `undefined`: Don't set header (use S3/browser defaults)
|
|
466
|
+
*/
|
|
467
|
+
contentDisposition?: "inline" | "attachment";
|
|
460
468
|
}
|
|
461
469
|
/**
|
|
462
470
|
* S3 Object Access Control List (ACL) values.
|
|
@@ -492,21 +500,21 @@ type S3ObjectACL = "private" | "public-read" | "public-read-write" | "authentica
|
|
|
492
500
|
* ```
|
|
493
501
|
*/
|
|
494
502
|
interface S3CollectionConfig extends CollectionStorageConfig {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
503
|
+
/**
|
|
504
|
+
* Override ACL for this collection.
|
|
505
|
+
* If not set, uses the adapter-level ACL setting.
|
|
506
|
+
*/
|
|
507
|
+
acl?: S3ObjectACL;
|
|
508
|
+
/**
|
|
509
|
+
* Override Cache-Control header for this collection.
|
|
510
|
+
* If not set, uses the adapter-level cacheControl setting.
|
|
511
|
+
*/
|
|
512
|
+
cacheControl?: string;
|
|
513
|
+
/**
|
|
514
|
+
* Override Content-Disposition for this collection.
|
|
515
|
+
* If not set, uses the adapter-level contentDisposition setting.
|
|
516
|
+
*/
|
|
517
|
+
contentDisposition?: "inline" | "attachment";
|
|
510
518
|
}
|
|
511
519
|
/**
|
|
512
520
|
* Type-safe collection storage map for S3.
|
|
@@ -520,79 +528,16 @@ type S3CollectionStorageMap = Record<string, boolean | S3CollectionConfig>;
|
|
|
520
528
|
* @internal
|
|
521
529
|
*/
|
|
522
530
|
interface ResolvedS3Config {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
531
|
+
bucket: string;
|
|
532
|
+
region: string;
|
|
533
|
+
endpoint?: string;
|
|
534
|
+
forcePathStyle: boolean;
|
|
535
|
+
acl: S3ObjectACL;
|
|
536
|
+
publicUrl?: string;
|
|
537
|
+
cacheControl: string;
|
|
538
|
+
contentDisposition?: "inline" | "attachment";
|
|
539
|
+
signedUrlExpiresIn: number;
|
|
532
540
|
}
|
|
533
|
-
|
|
534
|
-
/**
|
|
535
|
-
* S3 Storage Plugin
|
|
536
|
-
*
|
|
537
|
-
* Factory function that creates a storage plugin for AWS S3 and S3-compatible services.
|
|
538
|
-
* Returns a StoragePlugin that can be registered with MediaStorage.
|
|
539
|
-
*
|
|
540
|
-
* @example Basic usage with AWS S3
|
|
541
|
-
* ```typescript
|
|
542
|
-
* import { s3Storage } from '@nextly/storage-s3'
|
|
543
|
-
* import { defineConfig } from 'nextly/config'
|
|
544
|
-
*
|
|
545
|
-
* export default defineConfig({
|
|
546
|
-
* storage: [
|
|
547
|
-
* s3Storage({
|
|
548
|
-
* bucket: process.env.S3_BUCKET!,
|
|
549
|
-
* region: process.env.AWS_REGION!,
|
|
550
|
-
* accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
|
|
551
|
-
* secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
|
|
552
|
-
* collections: {
|
|
553
|
-
* media: true
|
|
554
|
-
* }
|
|
555
|
-
* })
|
|
556
|
-
* ]
|
|
557
|
-
* })
|
|
558
|
-
* ```
|
|
559
|
-
*
|
|
560
|
-
* @example With Cloudflare R2
|
|
561
|
-
* ```typescript
|
|
562
|
-
* s3Storage({
|
|
563
|
-
* bucket: process.env.R2_BUCKET!,
|
|
564
|
-
* region: 'auto',
|
|
565
|
-
* accessKeyId: process.env.R2_ACCESS_KEY_ID!,
|
|
566
|
-
* secretAccessKey: process.env.R2_SECRET_ACCESS_KEY!,
|
|
567
|
-
* endpoint: `https://${process.env.R2_ACCOUNT_ID}.r2.cloudflarestorage.com`,
|
|
568
|
-
* publicUrl: process.env.R2_PUBLIC_URL,
|
|
569
|
-
* collections: { media: true }
|
|
570
|
-
* })
|
|
571
|
-
* ```
|
|
572
|
-
*
|
|
573
|
-
* @example With collection-specific configuration
|
|
574
|
-
* ```typescript
|
|
575
|
-
* s3Storage({
|
|
576
|
-
* bucket: 'my-bucket',
|
|
577
|
-
* region: 'us-east-1',
|
|
578
|
-
* collections: {
|
|
579
|
-
* // Simple enable with defaults
|
|
580
|
-
* media: true,
|
|
581
|
-
*
|
|
582
|
-
* // Full configuration for private documents
|
|
583
|
-
* 'private-docs': {
|
|
584
|
-
* prefix: 'private/',
|
|
585
|
-
* clientUploads: true,
|
|
586
|
-
* signedDownloads: true,
|
|
587
|
-
* signedUrlExpiresIn: 3600
|
|
588
|
-
* }
|
|
589
|
-
* }
|
|
590
|
-
* })
|
|
591
|
-
* ```
|
|
592
|
-
*
|
|
593
|
-
* @packageDocumentation
|
|
594
|
-
*/
|
|
595
|
-
|
|
596
541
|
/**
|
|
597
542
|
* Create an S3 storage plugin for Nextly.
|
|
598
543
|
*
|
|
@@ -611,335 +556,230 @@ interface ResolvedS3Config {
|
|
|
611
556
|
* @throws Error if bucket is not provided (via adapter)
|
|
612
557
|
* @throws Error if region is not provided (via adapter)
|
|
613
558
|
*/
|
|
614
|
-
declare function s3Storage(config: S3StorageConfig): StoragePlugin;
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
*
|
|
837
|
-
* `ContentLength` is OPTIONAL in the SDK's response type, and this adapter
|
|
838
|
-
* explicitly supports MinIO, R2 and other compatible services — any of which
|
|
839
|
-
* may omit it or report it wrongly. A preflight check against metadata is
|
|
840
|
-
* therefore a courtesy that fails OPEN: trusting it alone leaves the cap
|
|
841
|
-
* unenforced exactly where an unusual backend is involved, which is where a
|
|
842
|
-
* caller most needs it.
|
|
843
|
-
*
|
|
844
|
-
* Counted while consuming, so an oversized body is abandoned partway rather
|
|
845
|
-
* than after it has all been buffered — the cap exists to bound memory, and
|
|
846
|
-
* one applied after `transformToByteArray` has already spent it.
|
|
847
|
-
*
|
|
848
|
-
* Falls back to buffering when the body is not async-iterable, which the SDK
|
|
849
|
-
* types permit. Stated rather than hidden: on that path the cap bounds what a
|
|
850
|
-
* caller RECEIVES rather than what the process allocates.
|
|
851
|
-
*/
|
|
852
|
-
private readCapped;
|
|
853
|
-
/**
|
|
854
|
-
* Refuse a read whose object is already known to exceed the caller's cap.
|
|
855
|
-
*
|
|
856
|
-
* Its own method rather than three conditions inside `read`, because the
|
|
857
|
-
* decision has nothing to do with the surrounding error handling and reads
|
|
858
|
-
* as noise there — and because `read`'s branching is the part a reviewer has
|
|
859
|
-
* to hold in their head to check the absent-versus-unavailable distinction.
|
|
860
|
-
*
|
|
861
|
-
* Both `undefined` cases mean "no opinion" and pass: a caller that named no
|
|
862
|
-
* cap has none, and a store that reported no length gives nothing to compare.
|
|
863
|
-
* The second is deliberately permissive — refusing an unmeasured object would
|
|
864
|
-
* reject valid reads whenever S3 omits the header.
|
|
865
|
-
*/
|
|
866
|
-
private refuseOverCap;
|
|
867
|
-
private isNotFoundError;
|
|
868
|
-
/**
|
|
869
|
-
* Get the S3 client instance.
|
|
870
|
-
* Useful for advanced operations not covered by the adapter interface.
|
|
871
|
-
*/
|
|
872
|
-
getClient(): S3Client;
|
|
873
|
-
/**
|
|
874
|
-
* Get the bucket name.
|
|
875
|
-
*/
|
|
876
|
-
getBucket(): string;
|
|
877
|
-
/**
|
|
878
|
-
* Get the AWS region.
|
|
879
|
-
*/
|
|
880
|
-
getRegion(): string;
|
|
881
|
-
/**
|
|
882
|
-
* Check if this adapter is configured for Cloudflare R2.
|
|
883
|
-
*/
|
|
884
|
-
isCloudflareR2(): boolean;
|
|
559
|
+
export declare function s3Storage(config: S3StorageConfig): StoragePlugin;
|
|
560
|
+
export declare class S3StorageAdapter implements IStorageAdapter {
|
|
561
|
+
private config;
|
|
562
|
+
private client;
|
|
563
|
+
private resolvedConfig;
|
|
564
|
+
private isR2;
|
|
565
|
+
/**
|
|
566
|
+
* Create a new S3 storage adapter.
|
|
567
|
+
*
|
|
568
|
+
* @param config - S3 storage configuration
|
|
569
|
+
* @throws Error if bucket or region is not provided
|
|
570
|
+
*/
|
|
571
|
+
constructor(config: S3StorageConfig);
|
|
572
|
+
/**
|
|
573
|
+
* Build AWS credentials from config.
|
|
574
|
+
* Supports explicit credentials or falls back to SDK default chain.
|
|
575
|
+
*/
|
|
576
|
+
private buildCredentials;
|
|
577
|
+
/**
|
|
578
|
+
* Upload file to S3.
|
|
579
|
+
*
|
|
580
|
+
* Uses AWS SDK v3's Upload class from @aws-sdk/lib-storage which:
|
|
581
|
+
* - Automatically handles multipart upload for large files (>5MB)
|
|
582
|
+
* - Provides progress tracking capability
|
|
583
|
+
* - Includes retry logic
|
|
584
|
+
* - Optimizes upload performance
|
|
585
|
+
*
|
|
586
|
+
* @param buffer - File content as Buffer
|
|
587
|
+
* @param options - Upload options (filename, mimeType, folder, collection)
|
|
588
|
+
* @returns Upload result with URL and storage path
|
|
589
|
+
*/
|
|
590
|
+
upload(buffer: Buffer, options: UploadOptions): Promise<UploadResult>;
|
|
591
|
+
/**
|
|
592
|
+
* Delete file from S3.
|
|
593
|
+
*
|
|
594
|
+
* @param filePath - Storage path/key to delete
|
|
595
|
+
*/
|
|
596
|
+
delete(filePath: string): Promise<void>;
|
|
597
|
+
/**
|
|
598
|
+
* Bulk delete files from S3 using a single API call per 1000 keys.
|
|
599
|
+
*
|
|
600
|
+
* Uses AWS SDK v3's DeleteObjectsCommand which supports up to 1000 keys per
|
|
601
|
+
* request. Automatically batches larger arrays and collects per-key results.
|
|
602
|
+
*
|
|
603
|
+
* @param filePaths - Storage paths/keys to delete
|
|
604
|
+
* @returns Object with arrays of successful and failed deletions
|
|
605
|
+
*/
|
|
606
|
+
bulkDelete(filePaths: string[]): Promise<BulkDeleteResult>;
|
|
607
|
+
/**
|
|
608
|
+
* Check if file exists in S3.
|
|
609
|
+
*
|
|
610
|
+
* Uses HeadObject command which is more efficient than GetObject
|
|
611
|
+
* for existence checks (doesn't download the file).
|
|
612
|
+
*
|
|
613
|
+
* @param filePath - Storage path/key to check
|
|
614
|
+
* @returns true if file exists, false otherwise
|
|
615
|
+
*/
|
|
616
|
+
exists(filePath: string): Promise<boolean>;
|
|
617
|
+
/**
|
|
618
|
+
* Get public URL for S3 file.
|
|
619
|
+
*
|
|
620
|
+
* Priority order:
|
|
621
|
+
* 1. Custom publicUrl (CDN or custom domain) if configured
|
|
622
|
+
* 2. Standard S3 URL based on region and bucket
|
|
623
|
+
*
|
|
624
|
+
* For R2: Requires publicUrl configuration (R2 has no default public URLs).
|
|
625
|
+
*
|
|
626
|
+
* @param filePath - Storage path/key
|
|
627
|
+
* @returns Public URL to access the file
|
|
628
|
+
* @throws Error if R2 is used without publicUrl configuration
|
|
629
|
+
*/
|
|
630
|
+
/**
|
|
631
|
+
* Every object in the bucket, by key, with when it was last written, a page
|
|
632
|
+
* of up to 1,000 at a time.
|
|
633
|
+
*/
|
|
634
|
+
list(): AsyncIterable<StoredFileEntry>;
|
|
635
|
+
getPublicUrl(filePath: string): string;
|
|
636
|
+
/**
|
|
637
|
+
* Get storage type identifier.
|
|
638
|
+
*
|
|
639
|
+
* Returns "s3" for all S3-compatible services (AWS S3, R2, MinIO, etc.)
|
|
640
|
+
* as they all use the S3 API.
|
|
641
|
+
*/
|
|
642
|
+
getType(): "s3";
|
|
643
|
+
/**
|
|
644
|
+
* Get adapter info including capabilities.
|
|
645
|
+
*
|
|
646
|
+
* @returns Adapter info with type, name, and capability flags
|
|
647
|
+
*/
|
|
648
|
+
getInfo(): StorageAdapterInfo;
|
|
649
|
+
/**
|
|
650
|
+
* Get file metadata from S3.
|
|
651
|
+
*
|
|
652
|
+
* Retrieves file information including size, content type, and timestamps
|
|
653
|
+
* using the HeadObject command.
|
|
654
|
+
*
|
|
655
|
+
* @param filePath - Storage path/key
|
|
656
|
+
* @returns File metadata or null if file not found
|
|
657
|
+
*/
|
|
658
|
+
getMetadata(filePath: string): Promise<FileMetadata | null>;
|
|
659
|
+
/**
|
|
660
|
+
* Read a stored object back as bytes, or `null` when it is not there.
|
|
661
|
+
*
|
|
662
|
+
* The contract declares this OPTIONAL and, until now, no adapter supplied
|
|
663
|
+
* it — so a caller reaching for `adapter.read` got `undefined` and fell
|
|
664
|
+
* through whatever branch followed. An optional member nothing implements is
|
|
665
|
+
* a contract that reads as a capability and behaves as an absence.
|
|
666
|
+
*
|
|
667
|
+
* BUFFERS rather than streams, because that is the declared return type and
|
|
668
|
+
* widening it here would make this adapter answer a different question from
|
|
669
|
+
* its siblings. That bounds what it should be used for: an asset the server
|
|
670
|
+
* must serve from its own origin — a font file, a small document — rather
|
|
671
|
+
* than arbitrarily large media, which belongs behind {@link getSignedUrl} or
|
|
672
|
+
* a public URL. A streaming variant is a separate contract member, not a
|
|
673
|
+
* quiet change to this one.
|
|
674
|
+
*
|
|
675
|
+
* `null` for a missing key rather than a throw, matching
|
|
676
|
+
* {@link getMetadata}: absence is an ordinary answer about the bucket, while
|
|
677
|
+
* a credential or network failure is not, so only the first is folded into
|
|
678
|
+
* the return value.
|
|
679
|
+
*
|
|
680
|
+
* @param filePath - Storage path/key
|
|
681
|
+
* @returns The object's bytes, or `null` when no such key exists
|
|
682
|
+
*/
|
|
683
|
+
read(filePath: string, options?: StorageReadOptions): Promise<Buffer | null>;
|
|
684
|
+
/**
|
|
685
|
+
* Generate signed URL for temporary private file access.
|
|
686
|
+
*
|
|
687
|
+
* Creates a pre-signed GetObject URL that grants temporary read access
|
|
688
|
+
* to private files. Useful for serving files from private buckets.
|
|
689
|
+
*
|
|
690
|
+
* @param filePath - Storage path/key
|
|
691
|
+
* @param expiresIn - URL validity duration in seconds (default: 3600)
|
|
692
|
+
* @returns Pre-signed URL for downloading the file
|
|
693
|
+
*/
|
|
694
|
+
getSignedUrl(filePath: string, expiresIn?: number): Promise<string>;
|
|
695
|
+
/**
|
|
696
|
+
* Generate pre-signed URL for client-side uploads.
|
|
697
|
+
*
|
|
698
|
+
* Creates a pre-signed PutObject URL that allows direct uploads from
|
|
699
|
+
* the browser to S3, bypassing server-side upload limits (e.g., Vercel's 4.5MB).
|
|
700
|
+
*
|
|
701
|
+
* @param key - Storage path/key for the upload
|
|
702
|
+
* @param mimeType - MIME type of the file being uploaded
|
|
703
|
+
* @param expiresIn - URL validity duration in seconds (default: 3600)
|
|
704
|
+
* @returns Client upload data with URL, method, and headers
|
|
705
|
+
*/
|
|
706
|
+
getPresignedUploadUrl(key: string, mimeType: string, expiresIn?: number): Promise<ClientUploadData>;
|
|
707
|
+
/**
|
|
708
|
+
* Generate a unique storage key with date-based prefix.
|
|
709
|
+
*
|
|
710
|
+
* Creates keys in format: {folder}/{year}/{month}/{uuid}-{sanitized-filename}
|
|
711
|
+
*
|
|
712
|
+
* @param filename - Original filename (will be sanitized)
|
|
713
|
+
* @param folder - Optional folder/prefix for organizing uploads
|
|
714
|
+
* @returns Generated storage key
|
|
715
|
+
*/
|
|
716
|
+
private generateKey;
|
|
717
|
+
/**
|
|
718
|
+
* Sanitize filename to prevent directory traversal and S3 key issues.
|
|
719
|
+
*
|
|
720
|
+
* @param filename - Original filename
|
|
721
|
+
* @returns Sanitized filename safe for S3 keys
|
|
722
|
+
*/
|
|
723
|
+
private sanitizeFilename;
|
|
724
|
+
/**
|
|
725
|
+
* Check if an error is a "not found" error from S3.
|
|
726
|
+
*
|
|
727
|
+
* @param error - Error to check
|
|
728
|
+
* @returns true if error indicates file not found
|
|
729
|
+
*/
|
|
730
|
+
/**
|
|
731
|
+
* The object's bytes, refusing once more than `cap` have actually arrived.
|
|
732
|
+
*
|
|
733
|
+
* `ContentLength` is OPTIONAL in the SDK's response type, and this adapter
|
|
734
|
+
* explicitly supports MinIO, R2 and other compatible services — any of which
|
|
735
|
+
* may omit it or report it wrongly. A preflight check against metadata is
|
|
736
|
+
* therefore a courtesy that fails OPEN: trusting it alone leaves the cap
|
|
737
|
+
* unenforced exactly where an unusual backend is involved, which is where a
|
|
738
|
+
* caller most needs it.
|
|
739
|
+
*
|
|
740
|
+
* Counted while consuming, so an oversized body is abandoned partway rather
|
|
741
|
+
* than after it has all been buffered — the cap exists to bound memory, and
|
|
742
|
+
* one applied after `transformToByteArray` has already spent it.
|
|
743
|
+
*
|
|
744
|
+
* Falls back to buffering when the body is not async-iterable, which the SDK
|
|
745
|
+
* types permit. Stated rather than hidden: on that path the cap bounds what a
|
|
746
|
+
* caller RECEIVES rather than what the process allocates.
|
|
747
|
+
*/
|
|
748
|
+
private readCapped;
|
|
749
|
+
/**
|
|
750
|
+
* Refuse a read whose object is already known to exceed the caller's cap.
|
|
751
|
+
*
|
|
752
|
+
* Its own method rather than three conditions inside `read`, because the
|
|
753
|
+
* decision has nothing to do with the surrounding error handling and reads
|
|
754
|
+
* as noise there — and because `read`'s branching is the part a reviewer has
|
|
755
|
+
* to hold in their head to check the absent-versus-unavailable distinction.
|
|
756
|
+
*
|
|
757
|
+
* Both `undefined` cases mean "no opinion" and pass: a caller that named no
|
|
758
|
+
* cap has none, and a store that reported no length gives nothing to compare.
|
|
759
|
+
* The second is deliberately permissive — refusing an unmeasured object would
|
|
760
|
+
* reject valid reads whenever S3 omits the header.
|
|
761
|
+
*/
|
|
762
|
+
private refuseOverCap;
|
|
763
|
+
private isNotFoundError;
|
|
764
|
+
/**
|
|
765
|
+
* Get the S3 client instance.
|
|
766
|
+
* Useful for advanced operations not covered by the adapter interface.
|
|
767
|
+
*/
|
|
768
|
+
getClient(): S3Client;
|
|
769
|
+
/**
|
|
770
|
+
* Get the bucket name.
|
|
771
|
+
*/
|
|
772
|
+
getBucket(): string;
|
|
773
|
+
/**
|
|
774
|
+
* Get the AWS region.
|
|
775
|
+
*/
|
|
776
|
+
getRegion(): string;
|
|
777
|
+
/**
|
|
778
|
+
* Check if this adapter is configured for Cloudflare R2.
|
|
779
|
+
*/
|
|
780
|
+
isCloudflareR2(): boolean;
|
|
885
781
|
}
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
* AWS S3 storage adapter for Nextly CMS.
|
|
891
|
-
* Also works with S3-compatible services like Cloudflare R2, MinIO, and DigitalOcean Spaces.
|
|
892
|
-
*
|
|
893
|
-
* @example Basic usage with AWS S3
|
|
894
|
-
* ```typescript
|
|
895
|
-
* import { s3Storage } from '@nextly/storage-s3'
|
|
896
|
-
* import { defineConfig } from 'nextly/config'
|
|
897
|
-
*
|
|
898
|
-
* export default defineConfig({
|
|
899
|
-
* storage: [
|
|
900
|
-
* s3Storage({
|
|
901
|
-
* bucket: process.env.S3_BUCKET!,
|
|
902
|
-
* region: process.env.AWS_REGION!,
|
|
903
|
-
* accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
|
|
904
|
-
* secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
|
|
905
|
-
* collections: {
|
|
906
|
-
* media: true
|
|
907
|
-
* }
|
|
908
|
-
* })
|
|
909
|
-
* ]
|
|
910
|
-
* })
|
|
911
|
-
* ```
|
|
912
|
-
*
|
|
913
|
-
* @example With Cloudflare R2
|
|
914
|
-
* ```typescript
|
|
915
|
-
* s3Storage({
|
|
916
|
-
* bucket: process.env.R2_BUCKET!,
|
|
917
|
-
* region: 'auto',
|
|
918
|
-
* accessKeyId: process.env.R2_ACCESS_KEY_ID!,
|
|
919
|
-
* secretAccessKey: process.env.R2_SECRET_ACCESS_KEY!,
|
|
920
|
-
* endpoint: `https://${process.env.R2_ACCOUNT_ID}.r2.cloudflarestorage.com`,
|
|
921
|
-
* publicUrl: process.env.R2_PUBLIC_URL,
|
|
922
|
-
* collections: { media: true }
|
|
923
|
-
* })
|
|
924
|
-
* ```
|
|
925
|
-
*
|
|
926
|
-
* @example With MinIO
|
|
927
|
-
* ```typescript
|
|
928
|
-
* s3Storage({
|
|
929
|
-
* bucket: 'my-bucket',
|
|
930
|
-
* region: 'us-east-1',
|
|
931
|
-
* accessKeyId: process.env.MINIO_ACCESS_KEY!,
|
|
932
|
-
* secretAccessKey: process.env.MINIO_SECRET_KEY!,
|
|
933
|
-
* endpoint: 'http://localhost:9000',
|
|
934
|
-
* forcePathStyle: true,
|
|
935
|
-
* collections: { media: true }
|
|
936
|
-
* })
|
|
937
|
-
* ```
|
|
938
|
-
*
|
|
939
|
-
* @packageDocumentation
|
|
940
|
-
*/
|
|
941
|
-
|
|
942
|
-
declare const PACKAGE_NAME = "@nextly/storage-s3";
|
|
943
|
-
declare const PACKAGE_VERSION = "0.1.0";
|
|
944
|
-
|
|
945
|
-
export { PACKAGE_NAME, PACKAGE_VERSION, type ResolvedS3Config, type S3CollectionConfig, type S3CollectionStorageMap, type S3ObjectACL, S3StorageAdapter, type S3StorageConfig, s3Storage };
|
|
782
|
+
export declare const PACKAGE_NAME = "@nextly/storage-s3";
|
|
783
|
+
export declare const PACKAGE_VERSION = "0.1.0";
|
|
784
|
+
export type { ResolvedS3Config, S3CollectionConfig, S3CollectionStorageMap, S3ObjectACL, S3StorageConfig };
|
|
785
|
+
//# sourceMappingURL=index.d.ts.map
|