@nextlyhq/storage-s3 0.0.2-alpha.8 → 0.0.2-alpha.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,5 +1,4 @@
1
- import { S3ClientConfig, S3Client } from '@aws-sdk/client-s3';
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
- /** Original filename from user */
15
- filename: string;
16
- /** MIME type (e.g., 'image/png', 'video/mp4') */
17
- mimeType: string;
18
- /** Optional content type override */
19
- contentType?: string;
20
- /** Optional folder/prefix for organizing uploads */
21
- folder?: string;
22
- /** Collection slug this upload belongs to (for collection-specific storage) */
23
- collection?: string;
24
- /** Optional Content-Disposition header value (e.g., 'attachment' for SVG security) */
25
- contentDisposition?: "inline" | "attachment";
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
- /** Public URL to access the file */
29
- url: string;
30
- /** Storage path/key (for deletion and metadata retrieval) */
31
- path: string;
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
- /** Unique identifier (typically the storage path/key) */
41
- id: string;
42
- /** Storage filename (may differ from original) */
43
- filename: string;
44
- /** Original filename as uploaded by user */
45
- originalFilename: string;
46
- /** MIME type (e.g., 'image/jpeg', 'application/pdf') */
47
- mimeType: string;
48
- /** File size in bytes */
49
- size: number;
50
- /** Public URL to access the file */
51
- url: string;
52
- /** Thumbnail URL for images (if generated) */
53
- thumbnailUrl?: string;
54
- /** Image width in pixels (for images only) */
55
- width?: number;
56
- /** Image height in pixels (for images only) */
57
- height?: number;
58
- /** ISO timestamp when file was uploaded */
59
- createdAt: string;
60
- /** ISO timestamp when file was last modified */
61
- updatedAt?: string;
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.
@@ -72,29 +71,109 @@ type StorageType = "s3" | "vercel-blob" | "local" | "uploadthing";
72
71
  * Information about a storage adapter's capabilities.
73
72
  * Returned by adapter.getInfo() method.
74
73
  */
74
+ /**
75
+ * Bounds for a read that pulls an object into memory.
76
+ *
77
+ * Reading a stored object means BUFFERING it, so its size is the caller's
78
+ * problem whether or not the caller says so. Left unbounded, a large object
79
+ * consumes as much process memory as it happens to occupy, and a stalled
80
+ * backend holds the request until something further out gives up.
81
+ *
82
+ * OPTIONAL, with the defaults living in the fetch layer rather than being
83
+ * restated per adapter — a second set of numbers agrees today and drifts. What
84
+ * this type exists for is the caller that already knows its own limit: the
85
+ * email attachment path caps a read at the configured attachment size, so an
86
+ * oversized object fails as a size error rather than after it has been read.
87
+ */
88
+ interface StorageReadOptions {
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;
93
+ }
75
94
  interface StorageAdapterInfo {
76
- /** Storage type identifier */
77
- type: StorageType;
78
- /** Human-readable adapter name */
79
- name: string;
80
- /** Whether this adapter supports signed URLs for private access */
81
- supportsSignedUrls: boolean;
82
- /** Whether this adapter supports client-side (direct) uploads */
83
- supportsClientUploads: boolean;
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;
103
+ /**
104
+ * Whether files written through the private calls (`putPrivate`,
105
+ * `getPrivateUploadUrl`) can be reached only through Nextly: no public
106
+ * address serves them. An adapter says so only when it is configured that
107
+ * way, for example with no public URL in front of its bucket. Absent means
108
+ * no, so a collection of private files is never stored where it may be
109
+ * public.
110
+ *
111
+ * @experimental
112
+ */
113
+ supportsPrivateFiles?: boolean;
114
+ }
115
+ /**
116
+ * What a storage says about an object it holds, read without its bytes.
117
+ *
118
+ * @experimental
119
+ */
120
+ interface StoredObjectHead {
121
+ /** The object's size in bytes, as stored. */
122
+ size: number;
123
+ /** The type it was stored with, where the storage keeps one. */
124
+ contentType?: string;
125
+ /** When it was last written, where the storage says. */
126
+ lastModified?: Date;
127
+ }
128
+ /**
129
+ * Bounds for a read handed back as a stream.
130
+ *
131
+ * @experimental
132
+ */
133
+ interface StorageStreamOptions {
134
+ /**
135
+ * Give up when the storage has not started answering after this long. The
136
+ * transfer itself is not bounded: its reader decides how long it takes.
137
+ */
138
+ timeoutMs?: number;
139
+ }
140
+ /**
141
+ * A short-lived link to a private file, as the private download call takes it.
142
+ *
143
+ * @experimental
144
+ */
145
+ interface PrivateDownloadUrlOptions {
146
+ /** How long the link lasts, in seconds, within the adapter's own cap. */
147
+ expiresIn: number;
148
+ /** The Content-Disposition the storage answers the link with. */
149
+ contentDisposition: string;
150
+ /** The Content-Type the storage answers the link with. */
151
+ contentType?: string;
152
+ }
153
+ /**
154
+ * A direct upload of a private file, as the private upload call takes it.
155
+ *
156
+ * @experimental
157
+ */
158
+ interface PrivateUploadUrlOptions {
159
+ /** The file's exact size in bytes; storage refuses a body of another length. */
160
+ contentLength: number;
161
+ /** How long the URL lasts, in seconds, within the adapter's own cap. */
162
+ expiresIn: number;
84
163
  }
85
164
  /**
86
165
  * Per-collection storage configuration.
87
166
  * Allows customizing storage behavior for specific upload collections.
88
167
  */
89
168
  interface CollectionStorageConfig {
90
- /** Prefix/folder for this collection's uploads */
91
- prefix?: string;
92
- /** Enable client-side uploads (for serverless platforms with body size limits) */
93
- clientUploads?: boolean;
94
- /** Generate signed URLs for downloads (for private buckets) */
95
- signedDownloads?: boolean;
96
- /** Signed URL expiry time in seconds (default: 3600) */
97
- signedUrlExpiresIn?: number;
169
+ /** Prefix/folder for this collection's uploads */
170
+ prefix?: string;
171
+ /** Enable client-side uploads (for serverless platforms with body size limits) */
172
+ clientUploads?: boolean;
173
+ /** Generate signed URLs for downloads (for private buckets) */
174
+ signedDownloads?: boolean;
175
+ /** Signed URL expiry time in seconds (default: 3600) */
176
+ signedUrlExpiresIn?: number;
98
177
  }
99
178
  /**
100
179
  * Collection storage map - maps collection slugs to their config.
@@ -118,10 +197,10 @@ type CollectionStorageMap = Record<string, boolean | CollectionStorageConfig>;
118
197
  * Extended by specific adapter configs (S3StorageConfig, etc.)
119
198
  */
120
199
  interface StoragePluginConfig {
121
- /** Enable/disable the plugin (default: true) */
122
- enabled?: boolean;
123
- /** Collections to apply this storage adapter to */
124
- collections: CollectionStorageMap;
200
+ /** Enable/disable the plugin (default: true) */
201
+ enabled?: boolean;
202
+ /** Collections to apply this storage adapter to */
203
+ collections: CollectionStorageMap;
125
204
  }
126
205
  /**
127
206
  * Storage plugin returned by adapter plugin functions.
@@ -139,24 +218,34 @@ interface StoragePluginConfig {
139
218
  * ```
140
219
  */
141
220
  interface StoragePlugin {
142
- /** Plugin name for identification */
143
- name: string;
144
- /** Storage type */
145
- type: StorageType;
146
- /** Collections this plugin handles */
147
- collections: CollectionStorageMap;
148
- /** The storage adapter instance */
149
- adapter: IStorageAdapter;
150
- /**
151
- * Handler for generating client-side upload URLs.
152
- * Called when clientUploads is enabled for a collection.
153
- */
154
- getClientUploadUrl?: (filename: string, mimeType: string, collection: string) => Promise<ClientUploadData>;
155
- /**
156
- * Handler for generating signed download URLs.
157
- * Called when signedDownloads is enabled for a collection.
158
- */
159
- getSignedDownloadUrl?: (path: string, expiresIn?: number) => Promise<string>;
221
+ /** Plugin name for identification */
222
+ name: string;
223
+ /** Storage type */
224
+ type: StorageType;
225
+ /** Collections this plugin handles */
226
+ collections: CollectionStorageMap;
227
+ /** The storage adapter instance */
228
+ adapter: IStorageAdapter;
229
+ /**
230
+ * Handler for generating client-side upload URLs.
231
+ * Called when clientUploads is enabled for a collection, for a file whose
232
+ * name, type and size the upload checks have already allowed. The URL must
233
+ * bind the type and `options.size`, so storage refuses a different file:
234
+ * its bytes never pass Nextly's checks.
235
+ */
236
+ getClientUploadUrl?: (filename: string, mimeType: string, collection: string, options: ClientUploadOptions) => Promise<ClientUploadData>;
237
+ /**
238
+ * Handler for generating signed download URLs.
239
+ * Called when signedDownloads is enabled for a collection.
240
+ */
241
+ getSignedDownloadUrl?: (path: string, expiresIn?: number) => Promise<string>;
242
+ }
243
+ /** What a signed client upload is bound to, besides its key and type. */
244
+ interface ClientUploadOptions {
245
+ /** The file's exact size in bytes; storage refuses a body of another length. */
246
+ size: number;
247
+ /** How long the URL lasts, in seconds, within the adapter's own cap. */
248
+ expiresIn?: number;
160
249
  }
161
250
  /**
162
251
  * Data returned for client-side (direct) uploads.
@@ -179,18 +268,18 @@ interface StoragePlugin {
179
268
  * ```
180
269
  */
181
270
  interface ClientUploadData {
182
- /** Pre-signed URL for direct upload */
183
- uploadUrl: string;
184
- /** Storage path/key that will be used */
185
- path: string;
186
- /** HTTP method to use (usually PUT for S3, POST for some services) */
187
- method: "PUT" | "POST";
188
- /** Headers to include in upload request */
189
- headers?: Record<string, string>;
190
- /** Form fields for multipart uploads (some services require this) */
191
- fields?: Record<string, string>;
192
- /** URL expiry timestamp */
193
- expiresAt: Date;
271
+ /** Pre-signed URL for direct upload */
272
+ uploadUrl: string;
273
+ /** Storage path/key that will be used */
274
+ path: string;
275
+ /** HTTP method to use (usually PUT for S3, POST for some services) */
276
+ method: "PUT" | "POST";
277
+ /** Headers to include in upload request */
278
+ headers?: Record<string, string>;
279
+ /** Form fields for multipart uploads (some services require this) */
280
+ fields?: Record<string, string>;
281
+ /** URL expiry timestamp */
282
+ expiresAt: Date;
194
283
  }
195
284
  /**
196
285
  * Base storage adapter interface.
@@ -209,47 +298,117 @@ interface ClientUploadData {
209
298
  * - getSignedUrl: Generate temporary signed URLs for private access
210
299
  * - getPresignedUploadUrl: Generate pre-signed URL for client uploads
211
300
  */
301
+ /** A file a storage holds, as {@link IStorageAdapter.list} names it. */
302
+ interface StoredFileEntry {
303
+ /** The stored path, as `upload` returned it and `delete` takes it. */
304
+ path: string;
305
+ /** When it was stored, where the storage says. */
306
+ lastModified?: Date;
307
+ /**
308
+ * The name it was uploaded under, where the storage keeps that apart from
309
+ * its path: UploadThing's keys carry no name. Elsewhere the name is the
310
+ * path's last segment.
311
+ */
312
+ name?: string;
313
+ }
212
314
  interface BulkDeleteResult {
213
- successful: string[];
214
- failed: Array<{
215
- filePath: string;
216
- error: string;
217
- }>;
315
+ successful: string[];
316
+ failed: Array<{
317
+ filePath: string;
318
+ error: string;
319
+ }>;
218
320
  }
219
321
  interface IStorageAdapter {
220
- /** Upload file buffer to storage */
221
- upload(buffer: Buffer, options: UploadOptions): Promise<UploadResult>;
222
- /** Delete file from storage */
223
- delete(filePath: string): Promise<void>;
224
- /** Bulk delete files from storage. Optional — adapters that support batch operations should implement this. */
225
- bulkDelete?(filePaths: string[]): Promise<BulkDeleteResult>;
226
- /** Check if file exists in storage */
227
- exists(filePath: string): Promise<boolean>;
228
- /** Get public URL for file */
229
- getPublicUrl(filePath: string): string;
230
- /** Get storage type identifier */
231
- getType(): string;
232
- /** Read file contents from storage (optional - not all adapters support this) */
233
- read?(filePath: string): Promise<Buffer | null>;
234
- /** Get adapter info including capabilities (optional but recommended) */
235
- getInfo?(): StorageAdapterInfo;
236
- /** Get file metadata (optional - not all adapters support this) */
237
- getMetadata?(filePath: string): Promise<FileMetadata | null>;
238
- /** Generate signed URL for temporary private access (optional) */
239
- getSignedUrl?(filePath: string, expiresIn?: number): Promise<string>;
240
- /** Generate pre-signed upload URL for client-side uploads (optional) */
241
- getPresignedUploadUrl?(key: string, mimeType: string, expiresIn?: number): Promise<ClientUploadData>;
322
+ /** Upload file buffer to storage */
323
+ upload(buffer: Buffer, options: UploadOptions): Promise<UploadResult>;
324
+ /**
325
+ * Store bytes at exactly `filePath`, replacing anything there (optional).
326
+ *
327
+ * Core calls it only with a key it derived from a file this storage already
328
+ * holds, to keep a file made from that one, such as a resized copy of an
329
+ * image, beside it. A storage without it cannot keep such files, and core
330
+ * serves the original instead. `upload` stays the way new files are
331
+ * stored, since it is the storage that chooses their keys.
332
+ *
333
+ * @experimental
334
+ */
335
+ uploadAt?(filePath: string, buffer: Buffer, options: {
336
+ mimeType: string;
337
+ }): Promise<UploadResult>;
338
+ /** Delete file from storage */
339
+ delete(filePath: string): Promise<void>;
340
+ /** Bulk delete files from storage. Optional — adapters that support batch operations should implement this. */
341
+ bulkDelete?(filePaths: string[]): Promise<BulkDeleteResult>;
342
+ /** Check if file exists in storage */
343
+ exists(filePath: string): Promise<boolean>;
344
+ /** Get public URL for file */
345
+ getPublicUrl(filePath: string): string;
346
+ /** Get storage type identifier */
347
+ getType(): string;
348
+ /** Read file contents from storage (optional - not all adapters support this) */
349
+ read?(filePath: string, options?: StorageReadOptions): Promise<Buffer | null>;
350
+ /** Get adapter info including capabilities (optional but recommended) */
351
+ getInfo?(): StorageAdapterInfo;
352
+ /** Get file metadata (optional - not all adapters support this) */
353
+ getMetadata?(filePath: string): Promise<FileMetadata | null>;
354
+ /** Generate signed URL for temporary private access (optional) */
355
+ getSignedUrl?(filePath: string, expiresIn?: number): Promise<string>;
356
+ /**
357
+ * Generate pre-signed upload URL for client-side uploads (optional). With
358
+ * `options.contentLength`, the signature binds the body's exact length.
359
+ */
360
+ getPresignedUploadUrl?(key: string, mimeType: string, expiresIn?: number, options?: {
361
+ contentLength?: number;
362
+ }): Promise<ClientUploadData>;
363
+ /**
364
+ * Every file the storage holds, a page at a time (optional). Used to find
365
+ * files no record refers to; a storage without it cannot be searched for
366
+ * them, which is said rather than taken as "none".
367
+ */
368
+ list?(): AsyncIterable<StoredFileEntry>;
369
+ /**
370
+ * What the storage holds at `filePath`, its size and type, without reading
371
+ * it (optional); `null` when nothing is there.
372
+ *
373
+ * @experimental
374
+ */
375
+ head?(filePath: string): Promise<StoredObjectHead | null>;
376
+ /**
377
+ * The file's bytes as a stream, for a response that should not hold the
378
+ * whole file in memory (optional); `null` when nothing is there.
379
+ *
380
+ * @experimental
381
+ */
382
+ readStream?(filePath: string, options?: StorageStreamOptions): Promise<ReadableStream<Uint8Array> | null>;
383
+ /**
384
+ * Store a private file at exactly `key` (optional). Unlike `upload`, the key
385
+ * is core's (it names no file and no person), no public address is formed,
386
+ * the original file name is kept nowhere in the storage, and the object is
387
+ * marked never to be cached. Required, with the two calls below, for a
388
+ * collection of private files.
389
+ *
390
+ * @experimental
391
+ */
392
+ putPrivate?(key: string, buffer: Buffer, options: {
393
+ mimeType: string;
394
+ }): Promise<void>;
395
+ /**
396
+ * A pre-signed URL a browser sends one private file to, at exactly `key`
397
+ * (optional). Like `getPresignedUploadUrl`, it binds the type and exact
398
+ * length; unlike it, the object it writes is private and never cached.
399
+ *
400
+ * @experimental
401
+ */
402
+ getPrivateUploadUrl?(key: string, mimeType: string, options: PrivateUploadUrlOptions): Promise<ClientUploadData>;
403
+ /**
404
+ * A link to a private file that lasts `options.expiresIn` seconds and is
405
+ * answered as an attachment that is never cached (optional). Only Nextly's
406
+ * checked download hands one out, after the caller's access was checked.
407
+ *
408
+ * @experimental
409
+ */
410
+ getPrivateDownloadUrl?(key: string, options: PrivateDownloadUrlOptions): Promise<string>;
242
411
  }
243
-
244
- /**
245
- * S3 Storage Types
246
- *
247
- * Type definitions for the @nextly/storage-s3 package.
248
- * Supports AWS S3 and S3-compatible services (Cloudflare R2, MinIO, DigitalOcean Spaces).
249
- *
250
- * @packageDocumentation
251
- */
252
-
253
412
  /**
254
413
  * S3 storage adapter configuration.
255
414
  *
@@ -296,147 +455,147 @@ interface IStorageAdapter {
296
455
  * ```
297
456
  */
298
457
  interface S3StorageConfig extends StoragePluginConfig {
299
- /** Enable/disable this storage plugin (default: true). */
300
- enabled?: boolean;
301
- /** Collections this plugin handles. */
302
- collections: Record<string, boolean | CollectionStorageConfig>;
303
- /**
304
- * S3 bucket name.
305
- * Must be an existing bucket that the credentials have access to.
306
- */
307
- bucket: string;
308
- /**
309
- * AWS region (e.g., 'us-east-1', 'eu-west-1').
310
- * Use 'auto' for Cloudflare R2.
311
- */
312
- region: string;
313
- /**
314
- * AWS SDK S3 client configuration.
315
- * Use this for advanced configuration like custom retry strategies,
316
- * request handlers, or middleware.
317
- *
318
- * Note: `region`, `endpoint`, `credentials`, and `forcePathStyle` can be
319
- * specified either here or via the dedicated config properties. The dedicated
320
- * properties take precedence if both are specified.
321
- */
322
- config?: Omit<S3ClientConfig, "region">;
323
- /**
324
- * AWS Access Key ID.
325
- * Can also be provided via `config.credentials` or environment variables
326
- * (AWS_ACCESS_KEY_ID).
327
- */
328
- accessKeyId?: string;
329
- /**
330
- * AWS Secret Access Key.
331
- * Can also be provided via `config.credentials` or environment variables
332
- * (AWS_SECRET_ACCESS_KEY).
333
- */
334
- secretAccessKey?: string;
335
- /**
336
- * Custom endpoint for S3-compatible services.
337
- * Required for Cloudflare R2, MinIO, DigitalOcean Spaces, etc.
338
- *
339
- * @example Cloudflare R2
340
- * ```typescript
341
- * endpoint: `https://${accountId}.r2.cloudflarestorage.com`
342
- * ```
343
- *
344
- * @example MinIO
345
- * ```typescript
346
- * endpoint: 'http://localhost:9000'
347
- * ```
348
- *
349
- * @example DigitalOcean Spaces
350
- * ```typescript
351
- * endpoint: 'https://nyc3.digitaloceanspaces.com'
352
- * ```
353
- */
354
- endpoint?: string;
355
- /**
356
- * Force path-style URLs instead of virtual-hosted-style.
357
- *
358
- * When true: `https://endpoint/bucket/key`
359
- * When false: `https://bucket.endpoint/key`
360
- *
361
- * Required for MinIO and some S3-compatible services.
362
- *
363
- * @default false
364
- */
365
- forcePathStyle?: boolean;
366
- /**
367
- * Access Control List (ACL) for uploaded objects.
368
- * Determines who can access the uploaded files.
369
- *
370
- * Common values:
371
- * - `'private'` (default): Only authenticated users; serve via signed URLs.
372
- * - `'public-read'`: Anyone can read (opt in only for buckets that
373
- * genuinely host public media).
374
- * - `'bucket-owner-full-control'`: Bucket owner has full control.
375
- *
376
- * Defaults to `'private'` so uploads are not world-readable unless
377
- * explicitly opted in. Pair with `getSignedUrl()` for read access to
378
- * private objects.
379
- *
380
- * Note: Cloudflare R2 ignores ACL settings. Configure public access
381
- * in the R2 dashboard instead.
382
- *
383
- * @default 'private'
384
- */
385
- acl?: S3ObjectACL;
386
- /**
387
- * Public URL override for accessing uploaded files.
388
- * Use this when serving files through a CDN or custom domain.
389
- *
390
- * If not set, uses the standard S3 URL format:
391
- * `https://{bucket}.s3.{region}.amazonaws.com/{key}`
392
- *
393
- * Required for Cloudflare R2 (which doesn't have default public URLs).
394
- *
395
- * @example CDN URL
396
- * ```typescript
397
- * publicUrl: 'https://cdn.example.com'
398
- * ```
399
- *
400
- * @example R2 Public Bucket
401
- * ```typescript
402
- * publicUrl: 'https://pub-abc123.r2.dev'
403
- * ```
404
- */
405
- publicUrl?: string;
406
- /**
407
- * Enable signed download URLs for private file access.
408
- * When enabled, `getSignedUrl()` can generate temporary access URLs.
409
- *
410
- * Can be overridden per-collection in the collections map.
411
- *
412
- * @default false
413
- */
414
- signedDownloads?: boolean;
415
- /**
416
- * Default expiry time for signed URLs in seconds.
417
- * Applies to both download and upload URLs.
418
- *
419
- * Can be overridden per-collection in the collections map.
420
- *
421
- * @default 3600 (1 hour)
422
- */
423
- signedUrlExpiresIn?: number;
424
- /**
425
- * Cache-Control header for uploaded files.
426
- * Controls browser and CDN caching behavior.
427
- *
428
- * @default 'public, max-age=31536000' (1 year)
429
- */
430
- cacheControl?: string;
431
- /**
432
- * Content-Disposition header mode for uploaded files.
433
- * Controls how browsers handle file downloads.
434
- *
435
- * - `'inline'`: Display in browser if possible
436
- * - `'attachment'`: Always prompt for download
437
- * - `undefined`: Don't set header (use S3/browser defaults)
438
- */
439
- contentDisposition?: "inline" | "attachment";
458
+ /** Enable/disable this storage plugin (default: true). */
459
+ enabled?: boolean;
460
+ /** Collections this plugin handles. */
461
+ collections: Record<string, boolean | CollectionStorageConfig>;
462
+ /**
463
+ * S3 bucket name.
464
+ * Must be an existing bucket that the credentials have access to.
465
+ */
466
+ bucket: string;
467
+ /**
468
+ * AWS region (e.g., 'us-east-1', 'eu-west-1').
469
+ * Use 'auto' for Cloudflare R2.
470
+ */
471
+ region: string;
472
+ /**
473
+ * AWS SDK S3 client configuration.
474
+ * Use this for advanced configuration like custom retry strategies,
475
+ * request handlers, or middleware.
476
+ *
477
+ * Note: `region`, `endpoint`, `credentials`, and `forcePathStyle` can be
478
+ * specified either here or via the dedicated config properties. The dedicated
479
+ * properties take precedence if both are specified.
480
+ */
481
+ config?: Omit<S3ClientConfig, "region">;
482
+ /**
483
+ * AWS Access Key ID.
484
+ * Can also be provided via `config.credentials` or environment variables
485
+ * (AWS_ACCESS_KEY_ID).
486
+ */
487
+ accessKeyId?: string;
488
+ /**
489
+ * AWS Secret Access Key.
490
+ * Can also be provided via `config.credentials` or environment variables
491
+ * (AWS_SECRET_ACCESS_KEY).
492
+ */
493
+ secretAccessKey?: string;
494
+ /**
495
+ * Custom endpoint for S3-compatible services.
496
+ * Required for Cloudflare R2, MinIO, DigitalOcean Spaces, etc.
497
+ *
498
+ * @example Cloudflare R2
499
+ * ```typescript
500
+ * endpoint: `https://${accountId}.r2.cloudflarestorage.com`
501
+ * ```
502
+ *
503
+ * @example MinIO
504
+ * ```typescript
505
+ * endpoint: 'http://localhost:9000'
506
+ * ```
507
+ *
508
+ * @example DigitalOcean Spaces
509
+ * ```typescript
510
+ * endpoint: 'https://nyc3.digitaloceanspaces.com'
511
+ * ```
512
+ */
513
+ endpoint?: string;
514
+ /**
515
+ * Force path-style URLs instead of virtual-hosted-style.
516
+ *
517
+ * When true: `https://endpoint/bucket/key`
518
+ * When false: `https://bucket.endpoint/key`
519
+ *
520
+ * Required for MinIO and some S3-compatible services.
521
+ *
522
+ * @default false
523
+ */
524
+ forcePathStyle?: boolean;
525
+ /**
526
+ * Access Control List (ACL) for uploaded objects.
527
+ * Determines who can access the uploaded files.
528
+ *
529
+ * Common values:
530
+ * - `'private'` (default): Only authenticated users; serve via signed URLs.
531
+ * - `'public-read'`: Anyone can read (opt in only for buckets that
532
+ * genuinely host public media).
533
+ * - `'bucket-owner-full-control'`: Bucket owner has full control.
534
+ *
535
+ * Defaults to `'private'` so uploads are not world-readable unless
536
+ * explicitly opted in. Pair with `getSignedUrl()` for read access to
537
+ * private objects.
538
+ *
539
+ * Note: Cloudflare R2 ignores ACL settings. Configure public access
540
+ * in the R2 dashboard instead.
541
+ *
542
+ * @default 'private'
543
+ */
544
+ acl?: S3ObjectACL;
545
+ /**
546
+ * Public URL override for accessing uploaded files.
547
+ * Use this when serving files through a CDN or custom domain.
548
+ *
549
+ * If not set, uses the standard S3 URL format:
550
+ * `https://{bucket}.s3.{region}.amazonaws.com/{key}`
551
+ *
552
+ * Required for Cloudflare R2 (which doesn't have default public URLs).
553
+ *
554
+ * @example CDN URL
555
+ * ```typescript
556
+ * publicUrl: 'https://cdn.example.com'
557
+ * ```
558
+ *
559
+ * @example R2 Public Bucket
560
+ * ```typescript
561
+ * publicUrl: 'https://pub-abc123.r2.dev'
562
+ * ```
563
+ */
564
+ publicUrl?: string;
565
+ /**
566
+ * Enable signed download URLs for private file access.
567
+ * When enabled, `getSignedUrl()` can generate temporary access URLs.
568
+ *
569
+ * Can be overridden per-collection in the collections map.
570
+ *
571
+ * @default false
572
+ */
573
+ signedDownloads?: boolean;
574
+ /**
575
+ * Default expiry time for signed URLs in seconds.
576
+ * Applies to both download and upload URLs.
577
+ *
578
+ * Can be overridden per-collection in the collections map.
579
+ *
580
+ * @default 3600 (1 hour)
581
+ */
582
+ signedUrlExpiresIn?: number;
583
+ /**
584
+ * Cache-Control header for uploaded files.
585
+ * Controls browser and CDN caching behavior.
586
+ *
587
+ * @default 'public, max-age=31536000' (1 year)
588
+ */
589
+ cacheControl?: string;
590
+ /**
591
+ * Content-Disposition header mode for uploaded files.
592
+ * Controls how browsers handle file downloads.
593
+ *
594
+ * - `'inline'`: Display in browser if possible
595
+ * - `'attachment'`: Always prompt for download
596
+ * - `undefined`: Don't set header (use S3/browser defaults)
597
+ */
598
+ contentDisposition?: "inline" | "attachment";
440
599
  }
441
600
  /**
442
601
  * S3 Object Access Control List (ACL) values.
@@ -472,21 +631,21 @@ type S3ObjectACL = "private" | "public-read" | "public-read-write" | "authentica
472
631
  * ```
473
632
  */
474
633
  interface S3CollectionConfig extends CollectionStorageConfig {
475
- /**
476
- * Override ACL for this collection.
477
- * If not set, uses the adapter-level ACL setting.
478
- */
479
- acl?: S3ObjectACL;
480
- /**
481
- * Override Cache-Control header for this collection.
482
- * If not set, uses the adapter-level cacheControl setting.
483
- */
484
- cacheControl?: string;
485
- /**
486
- * Override Content-Disposition for this collection.
487
- * If not set, uses the adapter-level contentDisposition setting.
488
- */
489
- contentDisposition?: "inline" | "attachment";
634
+ /**
635
+ * Override ACL for this collection.
636
+ * If not set, uses the adapter-level ACL setting.
637
+ */
638
+ acl?: S3ObjectACL;
639
+ /**
640
+ * Override Cache-Control header for this collection.
641
+ * If not set, uses the adapter-level cacheControl setting.
642
+ */
643
+ cacheControl?: string;
644
+ /**
645
+ * Override Content-Disposition for this collection.
646
+ * If not set, uses the adapter-level contentDisposition setting.
647
+ */
648
+ contentDisposition?: "inline" | "attachment";
490
649
  }
491
650
  /**
492
651
  * Type-safe collection storage map for S3.
@@ -500,79 +659,16 @@ type S3CollectionStorageMap = Record<string, boolean | S3CollectionConfig>;
500
659
  * @internal
501
660
  */
502
661
  interface ResolvedS3Config {
503
- bucket: string;
504
- region: string;
505
- endpoint?: string;
506
- forcePathStyle: boolean;
507
- acl: S3ObjectACL;
508
- publicUrl?: string;
509
- cacheControl: string;
510
- contentDisposition?: "inline" | "attachment";
511
- signedUrlExpiresIn: number;
662
+ bucket: string;
663
+ region: string;
664
+ endpoint?: string;
665
+ forcePathStyle: boolean;
666
+ acl: S3ObjectACL;
667
+ publicUrl?: string;
668
+ cacheControl: string;
669
+ contentDisposition?: "inline" | "attachment";
670
+ signedUrlExpiresIn: number;
512
671
  }
513
-
514
- /**
515
- * S3 Storage Plugin
516
- *
517
- * Factory function that creates a storage plugin for AWS S3 and S3-compatible services.
518
- * Returns a StoragePlugin that can be registered with MediaStorage.
519
- *
520
- * @example Basic usage with AWS S3
521
- * ```typescript
522
- * import { s3Storage } from '@nextly/storage-s3'
523
- * import { defineConfig } from 'nextly/config'
524
- *
525
- * export default defineConfig({
526
- * storage: [
527
- * s3Storage({
528
- * bucket: process.env.S3_BUCKET!,
529
- * region: process.env.AWS_REGION!,
530
- * accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
531
- * secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
532
- * collections: {
533
- * media: true
534
- * }
535
- * })
536
- * ]
537
- * })
538
- * ```
539
- *
540
- * @example With Cloudflare R2
541
- * ```typescript
542
- * s3Storage({
543
- * bucket: process.env.R2_BUCKET!,
544
- * region: 'auto',
545
- * accessKeyId: process.env.R2_ACCESS_KEY_ID!,
546
- * secretAccessKey: process.env.R2_SECRET_ACCESS_KEY!,
547
- * endpoint: `https://${process.env.R2_ACCOUNT_ID}.r2.cloudflarestorage.com`,
548
- * publicUrl: process.env.R2_PUBLIC_URL,
549
- * collections: { media: true }
550
- * })
551
- * ```
552
- *
553
- * @example With collection-specific configuration
554
- * ```typescript
555
- * s3Storage({
556
- * bucket: 'my-bucket',
557
- * region: 'us-east-1',
558
- * collections: {
559
- * // Simple enable with defaults
560
- * media: true,
561
- *
562
- * // Full configuration for private documents
563
- * 'private-docs': {
564
- * prefix: 'private/',
565
- * clientUploads: true,
566
- * signedDownloads: true,
567
- * signedUrlExpiresIn: 3600
568
- * }
569
- * }
570
- * })
571
- * ```
572
- *
573
- * @packageDocumentation
574
- */
575
-
576
672
  /**
577
673
  * Create an S3 storage plugin for Nextly.
578
674
  *
@@ -588,286 +684,333 @@ interface ResolvedS3Config {
588
684
  * @param config - S3 storage configuration
589
685
  * @returns A StoragePlugin that MediaStorage can register
590
686
  *
591
- * @throws Error if bucket is not provided (via adapter)
592
- * @throws Error if region is not provided (via adapter)
687
+ * Constructing the plugin never requires the bucket or region: a missing
688
+ * one is refused when storage is first used, not while the config loads.
593
689
  */
594
- declare function s3Storage(config: S3StorageConfig): StoragePlugin;
595
-
596
- /**
597
- * S3 Storage Adapter
598
- *
599
- * Stores files on AWS S3 or S3-compatible services (Cloudflare R2, MinIO, DigitalOcean Spaces).
600
- * Uses AWS SDK v3 with automatic multipart upload for large files (>5MB).
601
- *
602
- * Features:
603
- * - Automatic multipart upload via @aws-sdk/lib-storage
604
- * - Pre-signed URL generation for client-side uploads
605
- * - Signed URL generation for private file access
606
- * - Cloudflare R2 support (S3-compatible API)
607
- * - Custom endpoint support (MinIO, DigitalOcean Spaces)
608
- * - CDN URL override support
609
- * - File metadata retrieval
610
- *
611
- * @example AWS S3
612
- * ```typescript
613
- * const adapter = new S3StorageAdapter({
614
- * bucket: 'my-media-bucket',
615
- * region: 'us-east-1',
616
- * accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
617
- * secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
618
- * collections: { media: true }
619
- * });
620
- * ```
621
- *
622
- * @example Cloudflare R2
623
- * ```typescript
624
- * const adapter = new S3StorageAdapter({
625
- * bucket: 'my-media',
626
- * region: 'auto',
627
- * accessKeyId: process.env.R2_ACCESS_KEY_ID!,
628
- * secretAccessKey: process.env.R2_SECRET_ACCESS_KEY!,
629
- * endpoint: `https://${accountId}.r2.cloudflarestorage.com`,
630
- * publicUrl: 'https://pub-abc.r2.dev',
631
- * collections: { media: true }
632
- * });
633
- * ```
634
- *
635
- * @example MinIO (self-hosted)
636
- * ```typescript
637
- * const adapter = new S3StorageAdapter({
638
- * bucket: 'my-bucket',
639
- * region: 'us-east-1',
640
- * accessKeyId: process.env.MINIO_ACCESS_KEY!,
641
- * secretAccessKey: process.env.MINIO_SECRET_KEY!,
642
- * endpoint: 'http://localhost:9000',
643
- * forcePathStyle: true,
644
- * collections: { media: true }
645
- * });
646
- * ```
647
- */
648
-
649
- /**
650
- * S3 Storage Adapter
651
- *
652
- * Implements the IStorageAdapter interface for AWS S3 and S3-compatible services.
653
- * Provides full support for uploads, downloads, signed URLs, and client-side uploads.
654
- */
655
- declare class S3StorageAdapter implements IStorageAdapter {
656
- private config;
657
- private client;
658
- private resolvedConfig;
659
- private isR2;
660
- /**
661
- * Create a new S3 storage adapter.
662
- *
663
- * @param config - S3 storage configuration
664
- * @throws Error if bucket or region is not provided
665
- */
666
- constructor(config: S3StorageConfig);
667
- /**
668
- * Build AWS credentials from config.
669
- * Supports explicit credentials or falls back to SDK default chain.
670
- */
671
- private buildCredentials;
672
- /**
673
- * Upload file to S3.
674
- *
675
- * Uses AWS SDK v3's Upload class from @aws-sdk/lib-storage which:
676
- * - Automatically handles multipart upload for large files (>5MB)
677
- * - Provides progress tracking capability
678
- * - Includes retry logic
679
- * - Optimizes upload performance
680
- *
681
- * @param buffer - File content as Buffer
682
- * @param options - Upload options (filename, mimeType, folder, collection)
683
- * @returns Upload result with URL and storage path
684
- */
685
- upload(buffer: Buffer, options: UploadOptions): Promise<UploadResult>;
686
- /**
687
- * Delete file from S3.
688
- *
689
- * @param filePath - Storage path/key to delete
690
- */
691
- delete(filePath: string): Promise<void>;
692
- /**
693
- * Bulk delete files from S3 using a single API call per 1000 keys.
694
- *
695
- * Uses AWS SDK v3's DeleteObjectsCommand which supports up to 1000 keys per
696
- * request. Automatically batches larger arrays and collects per-key results.
697
- *
698
- * @param filePaths - Storage paths/keys to delete
699
- * @returns Object with arrays of successful and failed deletions
700
- */
701
- bulkDelete(filePaths: string[]): Promise<BulkDeleteResult>;
702
- /**
703
- * Check if file exists in S3.
704
- *
705
- * Uses HeadObject command which is more efficient than GetObject
706
- * for existence checks (doesn't download the file).
707
- *
708
- * @param filePath - Storage path/key to check
709
- * @returns true if file exists, false otherwise
710
- */
711
- exists(filePath: string): Promise<boolean>;
712
- /**
713
- * Get public URL for S3 file.
714
- *
715
- * Priority order:
716
- * 1. Custom publicUrl (CDN or custom domain) if configured
717
- * 2. Standard S3 URL based on region and bucket
718
- *
719
- * For R2: Requires publicUrl configuration (R2 has no default public URLs).
720
- *
721
- * @param filePath - Storage path/key
722
- * @returns Public URL to access the file
723
- * @throws Error if R2 is used without publicUrl configuration
724
- */
725
- getPublicUrl(filePath: string): string;
726
- /**
727
- * Get storage type identifier.
728
- *
729
- * Returns "s3" for all S3-compatible services (AWS S3, R2, MinIO, etc.)
730
- * as they all use the S3 API.
731
- */
732
- getType(): "s3";
733
- /**
734
- * Get adapter info including capabilities.
735
- *
736
- * @returns Adapter info with type, name, and capability flags
737
- */
738
- getInfo(): StorageAdapterInfo;
739
- /**
740
- * Get file metadata from S3.
741
- *
742
- * Retrieves file information including size, content type, and timestamps
743
- * using the HeadObject command.
744
- *
745
- * @param filePath - Storage path/key
746
- * @returns File metadata or null if file not found
747
- */
748
- getMetadata(filePath: string): Promise<FileMetadata | null>;
749
- /**
750
- * Generate signed URL for temporary private file access.
751
- *
752
- * Creates a pre-signed GetObject URL that grants temporary read access
753
- * to private files. Useful for serving files from private buckets.
754
- *
755
- * @param filePath - Storage path/key
756
- * @param expiresIn - URL validity duration in seconds (default: 3600)
757
- * @returns Pre-signed URL for downloading the file
758
- */
759
- getSignedUrl(filePath: string, expiresIn?: number): Promise<string>;
760
- /**
761
- * Generate pre-signed URL for client-side uploads.
762
- *
763
- * Creates a pre-signed PutObject URL that allows direct uploads from
764
- * the browser to S3, bypassing server-side upload limits (e.g., Vercel's 4.5MB).
765
- *
766
- * @param key - Storage path/key for the upload
767
- * @param mimeType - MIME type of the file being uploaded
768
- * @param expiresIn - URL validity duration in seconds (default: 3600)
769
- * @returns Client upload data with URL, method, and headers
770
- */
771
- getPresignedUploadUrl(key: string, mimeType: string, expiresIn?: number): Promise<ClientUploadData>;
772
- /**
773
- * Generate a unique storage key with date-based prefix.
774
- *
775
- * Creates keys in format: {folder}/{year}/{month}/{uuid}-{sanitized-filename}
776
- *
777
- * @param filename - Original filename (will be sanitized)
778
- * @param folder - Optional folder/prefix for organizing uploads
779
- * @returns Generated storage key
780
- */
781
- private generateKey;
782
- /**
783
- * Sanitize filename to prevent directory traversal and S3 key issues.
784
- *
785
- * @param filename - Original filename
786
- * @returns Sanitized filename safe for S3 keys
787
- */
788
- private sanitizeFilename;
789
- /**
790
- * Check if an error is a "not found" error from S3.
791
- *
792
- * @param error - Error to check
793
- * @returns true if error indicates file not found
794
- */
795
- private isNotFoundError;
796
- /**
797
- * Get the S3 client instance.
798
- * Useful for advanced operations not covered by the adapter interface.
799
- */
800
- getClient(): S3Client;
801
- /**
802
- * Get the bucket name.
803
- */
804
- getBucket(): string;
805
- /**
806
- * Get the AWS region.
807
- */
808
- getRegion(): string;
809
- /**
810
- * Check if this adapter is configured for Cloudflare R2.
811
- */
812
- isCloudflareR2(): boolean;
690
+ export declare function s3Storage(config: S3StorageConfig): StoragePlugin;
691
+ export declare class S3StorageAdapter implements IStorageAdapter {
692
+ private config;
693
+ private client;
694
+ private resolvedConfig;
695
+ private isR2;
696
+ /**
697
+ * Create a new S3 storage adapter.
698
+ *
699
+ * The bucket and region are deliberately NOT checked here, and the SDK
700
+ * client is deliberately not built. This constructor runs while the host's
701
+ * config file is evaluated, so a throw would stop every command —
702
+ * including the schema-only ones that never touch storage. Both the checks
703
+ * and the client construction move to the first storage operation
704
+ * ({@link ensureClient} and {@link ensureConfigured}), which refuse with
705
+ * the same messages a missing bucket or region has always produced.
706
+ *
707
+ * @param config - S3 storage configuration
708
+ */
709
+ constructor(config: S3StorageConfig);
710
+ /**
711
+ * Validate that bucket and region are present.
712
+ *
713
+ * @throws Error if bucket is not provided
714
+ * @throws Error if region is not provided
715
+ */
716
+ private ensureConfigured;
717
+ /**
718
+ * Validate the stored configuration and build the SDK client, at the
719
+ * first use that needs them.
720
+ *
721
+ * The refusals are the ones the constructor used to throw, in the same
722
+ * order, so an operator with a genuinely misconfigured deployment sees
723
+ * the message they have always seen — at the moment the value was
724
+ * actually needed rather than at config load. The client is built once
725
+ * and reused.
726
+ *
727
+ * @throws Error if bucket is not provided
728
+ * @throws Error if region is not provided
729
+ */
730
+ private ensureClient;
731
+ /**
732
+ * Build AWS credentials from config.
733
+ * Supports explicit credentials or falls back to SDK default chain.
734
+ */
735
+ private buildCredentials;
736
+ /**
737
+ * Upload file to S3.
738
+ *
739
+ * Uses AWS SDK v3's Upload class from @aws-sdk/lib-storage which:
740
+ * - Automatically handles multipart upload for large files (>5MB)
741
+ * - Provides progress tracking capability
742
+ * - Includes retry logic
743
+ * - Optimizes upload performance
744
+ *
745
+ * @param buffer - File content as Buffer
746
+ * @param options - Upload options (filename, mimeType, folder, collection)
747
+ * @returns Upload result with URL and storage path
748
+ */
749
+ upload(buffer: Buffer, options: UploadOptions): Promise<UploadResult>;
750
+ /**
751
+ * Write bytes at exactly `filePath`, beside a file already in the bucket.
752
+ *
753
+ * Core uses it to keep a file made from a stored one, such as a resized
754
+ * copy of an image, under a key derived from the original's. One request,
755
+ * since such a file is small, with the same cache setting and access as an
756
+ * upload, so it is served the way its original is.
757
+ *
758
+ * @experimental
759
+ */
760
+ uploadAt(filePath: string, buffer: Buffer, options: {
761
+ mimeType: string;
762
+ }): Promise<UploadResult>;
763
+ /**
764
+ * Store a private file at exactly `key`, the key core made for it.
765
+ *
766
+ * Unlike {@link upload}: no public address is formed (so an R2 bucket needs
767
+ * no `publicUrl`), the original file name goes into neither the key nor the
768
+ * object's metadata, the object is stored never to be cached, and its ACL is
769
+ * `private` whatever the adapter's own `acl` says (R2 has no ACLs, and keeps
770
+ * a bucket private unless public access is turned on for it).
771
+ *
772
+ * @experimental
773
+ */
774
+ putPrivate(key: string, buffer: Buffer, options: {
775
+ mimeType: string;
776
+ }): Promise<void>;
777
+ /**
778
+ * A pre-signed URL a browser sends one private file to, at exactly `key`.
779
+ * Binds the type and exact length as {@link getPresignedUploadUrl} does,
780
+ * and writes the object private and never cached.
781
+ *
782
+ * @experimental
783
+ */
784
+ getPrivateUploadUrl(key: string, mimeType: string, options: PrivateUploadUrlOptions): Promise<ClientUploadData>;
785
+ /**
786
+ * A link to a private file that lasts `options.expiresIn` seconds (at most
787
+ * the configured `signedUrlExpiresIn`). The bucket answers it with the
788
+ * given Content-Disposition and type, and with a Cache-Control that lets no
789
+ * cache keep it, whatever the object itself was stored with.
790
+ *
791
+ * @experimental
792
+ */
793
+ getPrivateDownloadUrl(key: string, options: PrivateDownloadUrlOptions): Promise<string>;
794
+ /**
795
+ * Delete file from S3.
796
+ *
797
+ * @param filePath - Storage path/key to delete
798
+ */
799
+ delete(filePath: string): Promise<void>;
800
+ /**
801
+ * Bulk delete files from S3 using a single API call per 1000 keys.
802
+ *
803
+ * Uses AWS SDK v3's DeleteObjectsCommand which supports up to 1000 keys per
804
+ * request. Automatically batches larger arrays and collects per-key results.
805
+ *
806
+ * @param filePaths - Storage paths/keys to delete
807
+ * @returns Object with arrays of successful and failed deletions
808
+ */
809
+ bulkDelete(filePaths: string[]): Promise<BulkDeleteResult>;
810
+ /**
811
+ * Check if file exists in S3.
812
+ *
813
+ * Uses HeadObject command which is more efficient than GetObject
814
+ * for existence checks (doesn't download the file).
815
+ *
816
+ * @param filePath - Storage path/key to check
817
+ * @returns true if file exists, false otherwise
818
+ */
819
+ exists(filePath: string): Promise<boolean>;
820
+ /**
821
+ * Get public URL for S3 file.
822
+ *
823
+ * Priority order:
824
+ * 1. Custom publicUrl (CDN or custom domain) if configured
825
+ * 2. Standard S3 URL based on region and bucket
826
+ *
827
+ * For R2: Requires publicUrl configuration (R2 has no default public URLs).
828
+ *
829
+ * @param filePath - Storage path/key
830
+ * @returns Public URL to access the file
831
+ * @throws Error if R2 is used without publicUrl configuration
832
+ */
833
+ /**
834
+ * Every object in the bucket, by key, with when it was last written, a page
835
+ * of up to 1,000 at a time.
836
+ */
837
+ list(): AsyncIterable<StoredFileEntry>;
838
+ getPublicUrl(filePath: string): string;
839
+ /**
840
+ * Get storage type identifier.
841
+ *
842
+ * Returns "s3" for all S3-compatible services (AWS S3, R2, MinIO, etc.)
843
+ * as they all use the S3 API.
844
+ */
845
+ getType(): "s3";
846
+ /**
847
+ * Get adapter info including capabilities.
848
+ *
849
+ * @returns Adapter info with type, name, and capability flags
850
+ */
851
+ getInfo(): StorageAdapterInfo;
852
+ /**
853
+ * Get file metadata from S3.
854
+ *
855
+ * Retrieves file information including size, content type, and timestamps
856
+ * using the HeadObject command.
857
+ *
858
+ * @param filePath - Storage path/key
859
+ * @returns File metadata or null if file not found
860
+ */
861
+ getMetadata(filePath: string): Promise<FileMetadata | null>;
862
+ /**
863
+ * Read a stored object back as bytes, or `null` when it is not there.
864
+ *
865
+ * The contract declares this OPTIONAL and, until now, no adapter supplied
866
+ * it — so a caller reaching for `adapter.read` got `undefined` and fell
867
+ * through whatever branch followed. An optional member nothing implements is
868
+ * a contract that reads as a capability and behaves as an absence.
869
+ *
870
+ * BUFFERS rather than streams, because that is the declared return type and
871
+ * widening it here would make this adapter answer a different question from
872
+ * its siblings. That bounds what it should be used for: an asset the server
873
+ * must serve from its own origin — a font file, a small document — rather
874
+ * than arbitrarily large media, which belongs behind {@link getSignedUrl} or
875
+ * a public URL. A streaming variant is a separate contract member, not a
876
+ * quiet change to this one.
877
+ *
878
+ * `null` for a missing key rather than a throw, matching
879
+ * {@link getMetadata}: absence is an ordinary answer about the bucket, while
880
+ * a credential or network failure is not, so only the first is folded into
881
+ * the return value.
882
+ *
883
+ * @param filePath - Storage path/key
884
+ * @returns The object's bytes, or `null` when no such key exists
885
+ */
886
+ read(filePath: string, options?: StorageReadOptions): Promise<Buffer | null>;
887
+ /**
888
+ * The stored object's size and type, without reading it, or `null` when the
889
+ * key is not in the bucket. A missing bucket throws rather than reading as a
890
+ * missing key, as for {@link read}.
891
+ *
892
+ * @experimental
893
+ */
894
+ head(filePath: string): Promise<StoredObjectHead | null>;
895
+ /**
896
+ * The stored object as a stream, or `null` when the key is not in the
897
+ * bucket, for a response that should not buffer a whole file.
898
+ *
899
+ * The deadline covers the bucket's answer only, then is cleared: the body
900
+ * flows as fast as its reader takes it, and a deadline on the whole
901
+ * transfer would cut off a slow but healthy download.
902
+ *
903
+ * @experimental
904
+ */
905
+ readStream(filePath: string, options?: StorageStreamOptions): Promise<ReadableStream<Uint8Array> | null>;
906
+ /**
907
+ * Generate signed URL for temporary private file access.
908
+ *
909
+ * Creates a pre-signed GetObject URL that grants temporary read access
910
+ * to private files. Useful for serving files from private buckets.
911
+ *
912
+ * @param filePath - Storage path/key
913
+ * @param expiresIn - URL validity duration in seconds (default: 3600)
914
+ * @returns Pre-signed URL for downloading the file
915
+ */
916
+ getSignedUrl(filePath: string, expiresIn?: number): Promise<string>;
917
+ /**
918
+ * Generate pre-signed URL for client-side uploads.
919
+ *
920
+ * Creates a pre-signed PutObject URL that allows direct uploads from
921
+ * the browser to S3, bypassing server-side upload limits (e.g., Vercel's 4.5MB).
922
+ *
923
+ * The signature covers the `Content-Type` and, given `options.contentLength`,
924
+ * the `Content-Length`: the bytes never pass Nextly's upload checks, so S3
925
+ * itself refuses a body of another type or length. The browser sets the
926
+ * length from the body; it is not a header the client sends.
927
+ *
928
+ * It covers the configured `Cache-Control` too, which is returned in
929
+ * `headers`: S3 stores an object's Cache-Control only from the upload
930
+ * request's own header, so a browser upload is served with the same caching
931
+ * as a server one only when the client sends it. The client must send every
932
+ * header in `headers`, as it is; one left out fails the signature.
933
+ *
934
+ * @param key - Storage path/key for the upload
935
+ * @param mimeType - MIME type of the file being uploaded
936
+ * @param expiresIn - URL validity in seconds, at most the configured
937
+ * `signedUrlExpiresIn` (its default)
938
+ * @param options - `contentLength`: the exact size the upload may have
939
+ * @returns Client upload data with URL, method, and headers
940
+ */
941
+ getPresignedUploadUrl(key: string, mimeType: string, expiresIn?: number, options?: {
942
+ contentLength?: number;
943
+ }): Promise<ClientUploadData>;
944
+ /**
945
+ * Sign one direct upload at exactly `key`: the type, the length when given,
946
+ * and the Cache-Control are signed, so S3 refuses a body that differs. The
947
+ * one signer for public and private uploads alike, which differ only in the
948
+ * caching and access they write.
949
+ */
950
+ private presignPut;
951
+ /**
952
+ * Check if an error is a "not found" error from S3.
953
+ *
954
+ * @param error - Error to check
955
+ * @returns true if error indicates file not found
956
+ */
957
+ /**
958
+ * The object's bytes, refusing once more than `cap` have actually arrived.
959
+ *
960
+ * `ContentLength` is OPTIONAL in the SDK's response type, and this adapter
961
+ * explicitly supports MinIO, R2 and other compatible services — any of which
962
+ * may omit it or report it wrongly. A preflight check against metadata is
963
+ * therefore a courtesy that fails OPEN: trusting it alone leaves the cap
964
+ * unenforced exactly where an unusual backend is involved, which is where a
965
+ * caller most needs it.
966
+ *
967
+ * Counted while consuming, so an oversized body is abandoned partway rather
968
+ * than after it has all been buffered — the cap exists to bound memory, and
969
+ * one applied after `transformToByteArray` has already spent it.
970
+ *
971
+ * Falls back to buffering when the body is not async-iterable, which the SDK
972
+ * types permit. Stated rather than hidden: on that path the cap bounds what a
973
+ * caller RECEIVES rather than what the process allocates.
974
+ */
975
+ private readCapped;
976
+ /**
977
+ * Refuse a read whose object is already known to exceed the caller's cap.
978
+ *
979
+ * Its own method rather than three conditions inside `read`, because the
980
+ * decision has nothing to do with the surrounding error handling and reads
981
+ * as noise there — and because `read`'s branching is the part a reviewer has
982
+ * to hold in their head to check the absent-versus-unavailable distinction.
983
+ *
984
+ * Both `undefined` cases mean "no opinion" and pass: a caller that named no
985
+ * cap has none, and a store that reported no length gives nothing to compare.
986
+ * The second is deliberately permissive — refusing an unmeasured object would
987
+ * reject valid reads whenever S3 omits the header.
988
+ */
989
+ private refuseOverCap;
990
+ private isNotFoundError;
991
+ /**
992
+ * Get the S3 client instance.
993
+ * Useful for advanced operations not covered by the adapter interface.
994
+ *
995
+ * Handing out the client is itself a use of the adapter, so a caller
996
+ * without the configuration a client needs is refused here like any
997
+ * other operation.
998
+ */
999
+ getClient(): S3Client;
1000
+ /**
1001
+ * Get the bucket name.
1002
+ */
1003
+ getBucket(): string;
1004
+ /**
1005
+ * Get the AWS region.
1006
+ */
1007
+ getRegion(): string;
1008
+ /**
1009
+ * Check if this adapter is configured for Cloudflare R2.
1010
+ */
1011
+ isCloudflareR2(): boolean;
813
1012
  }
814
-
815
- /**
816
- * @nextly/storage-s3
817
- *
818
- * AWS S3 storage adapter for Nextly CMS.
819
- * Also works with S3-compatible services like Cloudflare R2, MinIO, and DigitalOcean Spaces.
820
- *
821
- * @example Basic usage with AWS S3
822
- * ```typescript
823
- * import { s3Storage } from '@nextly/storage-s3'
824
- * import { defineConfig } from 'nextly/config'
825
- *
826
- * export default defineConfig({
827
- * storage: [
828
- * s3Storage({
829
- * bucket: process.env.S3_BUCKET!,
830
- * region: process.env.AWS_REGION!,
831
- * accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
832
- * secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
833
- * collections: {
834
- * media: true
835
- * }
836
- * })
837
- * ]
838
- * })
839
- * ```
840
- *
841
- * @example With Cloudflare R2
842
- * ```typescript
843
- * s3Storage({
844
- * bucket: process.env.R2_BUCKET!,
845
- * region: 'auto',
846
- * accessKeyId: process.env.R2_ACCESS_KEY_ID!,
847
- * secretAccessKey: process.env.R2_SECRET_ACCESS_KEY!,
848
- * endpoint: `https://${process.env.R2_ACCOUNT_ID}.r2.cloudflarestorage.com`,
849
- * publicUrl: process.env.R2_PUBLIC_URL,
850
- * collections: { media: true }
851
- * })
852
- * ```
853
- *
854
- * @example With MinIO
855
- * ```typescript
856
- * s3Storage({
857
- * bucket: 'my-bucket',
858
- * region: 'us-east-1',
859
- * accessKeyId: process.env.MINIO_ACCESS_KEY!,
860
- * secretAccessKey: process.env.MINIO_SECRET_KEY!,
861
- * endpoint: 'http://localhost:9000',
862
- * forcePathStyle: true,
863
- * collections: { media: true }
864
- * })
865
- * ```
866
- *
867
- * @packageDocumentation
868
- */
869
-
870
- declare const PACKAGE_NAME = "@nextly/storage-s3";
871
- declare const PACKAGE_VERSION = "0.1.0";
872
-
873
- export { PACKAGE_NAME, PACKAGE_VERSION, type ResolvedS3Config, type S3CollectionConfig, type S3CollectionStorageMap, type S3ObjectACL, S3StorageAdapter, type S3StorageConfig, s3Storage };
1013
+ export declare const PACKAGE_NAME = "@nextly/storage-s3";
1014
+ export declare const PACKAGE_VERSION = "0.1.0";
1015
+ export type { ResolvedS3Config, S3CollectionConfig, S3CollectionStorageMap, S3ObjectACL, S3StorageConfig };
1016
+ //# sourceMappingURL=index.d.cts.map