@nextlyhq/storage-s3 0.0.2-alpha.8 → 0.0.2-alpha.80
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 +9 -7
- package/dist/index.cjs +1723 -463
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +620 -636
- package/dist/index.d.ts +620 -636
- package/dist/index.mjs +1722 -461
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -20
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.
|
|
@@ -72,29 +71,49 @@ 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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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;
|
|
84
103
|
}
|
|
85
104
|
/**
|
|
86
105
|
* Per-collection storage configuration.
|
|
87
106
|
* Allows customizing storage behavior for specific upload collections.
|
|
88
107
|
*/
|
|
89
108
|
interface CollectionStorageConfig {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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;
|
|
98
117
|
}
|
|
99
118
|
/**
|
|
100
119
|
* Collection storage map - maps collection slugs to their config.
|
|
@@ -118,10 +137,10 @@ type CollectionStorageMap = Record<string, boolean | CollectionStorageConfig>;
|
|
|
118
137
|
* Extended by specific adapter configs (S3StorageConfig, etc.)
|
|
119
138
|
*/
|
|
120
139
|
interface StoragePluginConfig {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
140
|
+
/** Enable/disable the plugin (default: true) */
|
|
141
|
+
enabled?: boolean;
|
|
142
|
+
/** Collections to apply this storage adapter to */
|
|
143
|
+
collections: CollectionStorageMap;
|
|
125
144
|
}
|
|
126
145
|
/**
|
|
127
146
|
* Storage plugin returned by adapter plugin functions.
|
|
@@ -139,24 +158,34 @@ interface StoragePluginConfig {
|
|
|
139
158
|
* ```
|
|
140
159
|
*/
|
|
141
160
|
interface StoragePlugin {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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, for a file whose
|
|
172
|
+
* name, type and size the upload checks have already allowed. The URL must
|
|
173
|
+
* bind the type and `options.size`, so storage refuses a different file:
|
|
174
|
+
* its bytes never pass Nextly's checks.
|
|
175
|
+
*/
|
|
176
|
+
getClientUploadUrl?: (filename: string, mimeType: string, collection: string, options: ClientUploadOptions) => Promise<ClientUploadData>;
|
|
177
|
+
/**
|
|
178
|
+
* Handler for generating signed download URLs.
|
|
179
|
+
* Called when signedDownloads is enabled for a collection.
|
|
180
|
+
*/
|
|
181
|
+
getSignedDownloadUrl?: (path: string, expiresIn?: number) => Promise<string>;
|
|
182
|
+
}
|
|
183
|
+
/** What a signed client upload is bound to, besides its key and type. */
|
|
184
|
+
interface ClientUploadOptions {
|
|
185
|
+
/** The file's exact size in bytes; storage refuses a body of another length. */
|
|
186
|
+
size: number;
|
|
187
|
+
/** How long the URL lasts, in seconds, within the adapter's own cap. */
|
|
188
|
+
expiresIn?: number;
|
|
160
189
|
}
|
|
161
190
|
/**
|
|
162
191
|
* Data returned for client-side (direct) uploads.
|
|
@@ -179,18 +208,18 @@ interface StoragePlugin {
|
|
|
179
208
|
* ```
|
|
180
209
|
*/
|
|
181
210
|
interface ClientUploadData {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
211
|
+
/** Pre-signed URL for direct upload */
|
|
212
|
+
uploadUrl: string;
|
|
213
|
+
/** Storage path/key that will be used */
|
|
214
|
+
path: string;
|
|
215
|
+
/** HTTP method to use (usually PUT for S3, POST for some services) */
|
|
216
|
+
method: "PUT" | "POST";
|
|
217
|
+
/** Headers to include in upload request */
|
|
218
|
+
headers?: Record<string, string>;
|
|
219
|
+
/** Form fields for multipart uploads (some services require this) */
|
|
220
|
+
fields?: Record<string, string>;
|
|
221
|
+
/** URL expiry timestamp */
|
|
222
|
+
expiresAt: Date;
|
|
194
223
|
}
|
|
195
224
|
/**
|
|
196
225
|
* Base storage adapter interface.
|
|
@@ -209,47 +238,75 @@ interface ClientUploadData {
|
|
|
209
238
|
* - getSignedUrl: Generate temporary signed URLs for private access
|
|
210
239
|
* - getPresignedUploadUrl: Generate pre-signed URL for client uploads
|
|
211
240
|
*/
|
|
241
|
+
/** A file a storage holds, as {@link IStorageAdapter.list} names it. */
|
|
242
|
+
interface StoredFileEntry {
|
|
243
|
+
/** The stored path, as `upload` returned it and `delete` takes it. */
|
|
244
|
+
path: string;
|
|
245
|
+
/** When it was stored, where the storage says. */
|
|
246
|
+
lastModified?: Date;
|
|
247
|
+
/**
|
|
248
|
+
* The name it was uploaded under, where the storage keeps that apart from
|
|
249
|
+
* its path: UploadThing's keys carry no name. Elsewhere the name is the
|
|
250
|
+
* path's last segment.
|
|
251
|
+
*/
|
|
252
|
+
name?: string;
|
|
253
|
+
}
|
|
212
254
|
interface BulkDeleteResult {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
255
|
+
successful: string[];
|
|
256
|
+
failed: Array<{
|
|
257
|
+
filePath: string;
|
|
258
|
+
error: string;
|
|
259
|
+
}>;
|
|
218
260
|
}
|
|
219
261
|
interface IStorageAdapter {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
262
|
+
/** Upload file buffer to storage */
|
|
263
|
+
upload(buffer: Buffer, options: UploadOptions): Promise<UploadResult>;
|
|
264
|
+
/**
|
|
265
|
+
* Store bytes at exactly `filePath`, replacing anything there (optional).
|
|
266
|
+
*
|
|
267
|
+
* Core calls it only with a key it derived from a file this storage already
|
|
268
|
+
* holds, to keep a file made from that one, such as a resized copy of an
|
|
269
|
+
* image, beside it. A storage without it cannot keep such files, and core
|
|
270
|
+
* serves the original instead. `upload` stays the way new files are
|
|
271
|
+
* stored, since it is the storage that chooses their keys.
|
|
272
|
+
*
|
|
273
|
+
* @experimental
|
|
274
|
+
*/
|
|
275
|
+
uploadAt?(filePath: string, buffer: Buffer, options: {
|
|
276
|
+
mimeType: string;
|
|
277
|
+
}): Promise<UploadResult>;
|
|
278
|
+
/** Delete file from storage */
|
|
279
|
+
delete(filePath: string): Promise<void>;
|
|
280
|
+
/** Bulk delete files from storage. Optional — adapters that support batch operations should implement this. */
|
|
281
|
+
bulkDelete?(filePaths: string[]): Promise<BulkDeleteResult>;
|
|
282
|
+
/** Check if file exists in storage */
|
|
283
|
+
exists(filePath: string): Promise<boolean>;
|
|
284
|
+
/** Get public URL for file */
|
|
285
|
+
getPublicUrl(filePath: string): string;
|
|
286
|
+
/** Get storage type identifier */
|
|
287
|
+
getType(): string;
|
|
288
|
+
/** Read file contents from storage (optional - not all adapters support this) */
|
|
289
|
+
read?(filePath: string, options?: StorageReadOptions): Promise<Buffer | null>;
|
|
290
|
+
/** Get adapter info including capabilities (optional but recommended) */
|
|
291
|
+
getInfo?(): StorageAdapterInfo;
|
|
292
|
+
/** Get file metadata (optional - not all adapters support this) */
|
|
293
|
+
getMetadata?(filePath: string): Promise<FileMetadata | null>;
|
|
294
|
+
/** Generate signed URL for temporary private access (optional) */
|
|
295
|
+
getSignedUrl?(filePath: string, expiresIn?: number): Promise<string>;
|
|
296
|
+
/**
|
|
297
|
+
* Generate pre-signed upload URL for client-side uploads (optional). With
|
|
298
|
+
* `options.contentLength`, the signature binds the body's exact length.
|
|
299
|
+
*/
|
|
300
|
+
getPresignedUploadUrl?(key: string, mimeType: string, expiresIn?: number, options?: {
|
|
301
|
+
contentLength?: number;
|
|
302
|
+
}): Promise<ClientUploadData>;
|
|
303
|
+
/**
|
|
304
|
+
* Every file the storage holds, a page at a time (optional). Used to find
|
|
305
|
+
* files no record refers to; a storage without it cannot be searched for
|
|
306
|
+
* them, which is said rather than taken as "none".
|
|
307
|
+
*/
|
|
308
|
+
list?(): AsyncIterable<StoredFileEntry>;
|
|
242
309
|
}
|
|
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
310
|
/**
|
|
254
311
|
* S3 storage adapter configuration.
|
|
255
312
|
*
|
|
@@ -296,147 +353,147 @@ interface IStorageAdapter {
|
|
|
296
353
|
* ```
|
|
297
354
|
*/
|
|
298
355
|
interface S3StorageConfig extends StoragePluginConfig {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
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
|
-
|
|
356
|
+
/** Enable/disable this storage plugin (default: true). */
|
|
357
|
+
enabled?: boolean;
|
|
358
|
+
/** Collections this plugin handles. */
|
|
359
|
+
collections: Record<string, boolean | CollectionStorageConfig>;
|
|
360
|
+
/**
|
|
361
|
+
* S3 bucket name.
|
|
362
|
+
* Must be an existing bucket that the credentials have access to.
|
|
363
|
+
*/
|
|
364
|
+
bucket: string;
|
|
365
|
+
/**
|
|
366
|
+
* AWS region (e.g., 'us-east-1', 'eu-west-1').
|
|
367
|
+
* Use 'auto' for Cloudflare R2.
|
|
368
|
+
*/
|
|
369
|
+
region: string;
|
|
370
|
+
/**
|
|
371
|
+
* AWS SDK S3 client configuration.
|
|
372
|
+
* Use this for advanced configuration like custom retry strategies,
|
|
373
|
+
* request handlers, or middleware.
|
|
374
|
+
*
|
|
375
|
+
* Note: `region`, `endpoint`, `credentials`, and `forcePathStyle` can be
|
|
376
|
+
* specified either here or via the dedicated config properties. The dedicated
|
|
377
|
+
* properties take precedence if both are specified.
|
|
378
|
+
*/
|
|
379
|
+
config?: Omit<S3ClientConfig, "region">;
|
|
380
|
+
/**
|
|
381
|
+
* AWS Access Key ID.
|
|
382
|
+
* Can also be provided via `config.credentials` or environment variables
|
|
383
|
+
* (AWS_ACCESS_KEY_ID).
|
|
384
|
+
*/
|
|
385
|
+
accessKeyId?: string;
|
|
386
|
+
/**
|
|
387
|
+
* AWS Secret Access Key.
|
|
388
|
+
* Can also be provided via `config.credentials` or environment variables
|
|
389
|
+
* (AWS_SECRET_ACCESS_KEY).
|
|
390
|
+
*/
|
|
391
|
+
secretAccessKey?: string;
|
|
392
|
+
/**
|
|
393
|
+
* Custom endpoint for S3-compatible services.
|
|
394
|
+
* Required for Cloudflare R2, MinIO, DigitalOcean Spaces, etc.
|
|
395
|
+
*
|
|
396
|
+
* @example Cloudflare R2
|
|
397
|
+
* ```typescript
|
|
398
|
+
* endpoint: `https://${accountId}.r2.cloudflarestorage.com`
|
|
399
|
+
* ```
|
|
400
|
+
*
|
|
401
|
+
* @example MinIO
|
|
402
|
+
* ```typescript
|
|
403
|
+
* endpoint: 'http://localhost:9000'
|
|
404
|
+
* ```
|
|
405
|
+
*
|
|
406
|
+
* @example DigitalOcean Spaces
|
|
407
|
+
* ```typescript
|
|
408
|
+
* endpoint: 'https://nyc3.digitaloceanspaces.com'
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
endpoint?: string;
|
|
412
|
+
/**
|
|
413
|
+
* Force path-style URLs instead of virtual-hosted-style.
|
|
414
|
+
*
|
|
415
|
+
* When true: `https://endpoint/bucket/key`
|
|
416
|
+
* When false: `https://bucket.endpoint/key`
|
|
417
|
+
*
|
|
418
|
+
* Required for MinIO and some S3-compatible services.
|
|
419
|
+
*
|
|
420
|
+
* @default false
|
|
421
|
+
*/
|
|
422
|
+
forcePathStyle?: boolean;
|
|
423
|
+
/**
|
|
424
|
+
* Access Control List (ACL) for uploaded objects.
|
|
425
|
+
* Determines who can access the uploaded files.
|
|
426
|
+
*
|
|
427
|
+
* Common values:
|
|
428
|
+
* - `'private'` (default): Only authenticated users; serve via signed URLs.
|
|
429
|
+
* - `'public-read'`: Anyone can read (opt in only for buckets that
|
|
430
|
+
* genuinely host public media).
|
|
431
|
+
* - `'bucket-owner-full-control'`: Bucket owner has full control.
|
|
432
|
+
*
|
|
433
|
+
* Defaults to `'private'` so uploads are not world-readable unless
|
|
434
|
+
* explicitly opted in. Pair with `getSignedUrl()` for read access to
|
|
435
|
+
* private objects.
|
|
436
|
+
*
|
|
437
|
+
* Note: Cloudflare R2 ignores ACL settings. Configure public access
|
|
438
|
+
* in the R2 dashboard instead.
|
|
439
|
+
*
|
|
440
|
+
* @default 'private'
|
|
441
|
+
*/
|
|
442
|
+
acl?: S3ObjectACL;
|
|
443
|
+
/**
|
|
444
|
+
* Public URL override for accessing uploaded files.
|
|
445
|
+
* Use this when serving files through a CDN or custom domain.
|
|
446
|
+
*
|
|
447
|
+
* If not set, uses the standard S3 URL format:
|
|
448
|
+
* `https://{bucket}.s3.{region}.amazonaws.com/{key}`
|
|
449
|
+
*
|
|
450
|
+
* Required for Cloudflare R2 (which doesn't have default public URLs).
|
|
451
|
+
*
|
|
452
|
+
* @example CDN URL
|
|
453
|
+
* ```typescript
|
|
454
|
+
* publicUrl: 'https://cdn.example.com'
|
|
455
|
+
* ```
|
|
456
|
+
*
|
|
457
|
+
* @example R2 Public Bucket
|
|
458
|
+
* ```typescript
|
|
459
|
+
* publicUrl: 'https://pub-abc123.r2.dev'
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
publicUrl?: string;
|
|
463
|
+
/**
|
|
464
|
+
* Enable signed download URLs for private file access.
|
|
465
|
+
* When enabled, `getSignedUrl()` can generate temporary access URLs.
|
|
466
|
+
*
|
|
467
|
+
* Can be overridden per-collection in the collections map.
|
|
468
|
+
*
|
|
469
|
+
* @default false
|
|
470
|
+
*/
|
|
471
|
+
signedDownloads?: boolean;
|
|
472
|
+
/**
|
|
473
|
+
* Default expiry time for signed URLs in seconds.
|
|
474
|
+
* Applies to both download and upload URLs.
|
|
475
|
+
*
|
|
476
|
+
* Can be overridden per-collection in the collections map.
|
|
477
|
+
*
|
|
478
|
+
* @default 3600 (1 hour)
|
|
479
|
+
*/
|
|
480
|
+
signedUrlExpiresIn?: number;
|
|
481
|
+
/**
|
|
482
|
+
* Cache-Control header for uploaded files.
|
|
483
|
+
* Controls browser and CDN caching behavior.
|
|
484
|
+
*
|
|
485
|
+
* @default 'public, max-age=31536000' (1 year)
|
|
486
|
+
*/
|
|
487
|
+
cacheControl?: string;
|
|
488
|
+
/**
|
|
489
|
+
* Content-Disposition header mode for uploaded files.
|
|
490
|
+
* Controls how browsers handle file downloads.
|
|
491
|
+
*
|
|
492
|
+
* - `'inline'`: Display in browser if possible
|
|
493
|
+
* - `'attachment'`: Always prompt for download
|
|
494
|
+
* - `undefined`: Don't set header (use S3/browser defaults)
|
|
495
|
+
*/
|
|
496
|
+
contentDisposition?: "inline" | "attachment";
|
|
440
497
|
}
|
|
441
498
|
/**
|
|
442
499
|
* S3 Object Access Control List (ACL) values.
|
|
@@ -472,21 +529,21 @@ type S3ObjectACL = "private" | "public-read" | "public-read-write" | "authentica
|
|
|
472
529
|
* ```
|
|
473
530
|
*/
|
|
474
531
|
interface S3CollectionConfig extends CollectionStorageConfig {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
532
|
+
/**
|
|
533
|
+
* Override ACL for this collection.
|
|
534
|
+
* If not set, uses the adapter-level ACL setting.
|
|
535
|
+
*/
|
|
536
|
+
acl?: S3ObjectACL;
|
|
537
|
+
/**
|
|
538
|
+
* Override Cache-Control header for this collection.
|
|
539
|
+
* If not set, uses the adapter-level cacheControl setting.
|
|
540
|
+
*/
|
|
541
|
+
cacheControl?: string;
|
|
542
|
+
/**
|
|
543
|
+
* Override Content-Disposition for this collection.
|
|
544
|
+
* If not set, uses the adapter-level contentDisposition setting.
|
|
545
|
+
*/
|
|
546
|
+
contentDisposition?: "inline" | "attachment";
|
|
490
547
|
}
|
|
491
548
|
/**
|
|
492
549
|
* Type-safe collection storage map for S3.
|
|
@@ -500,79 +557,16 @@ type S3CollectionStorageMap = Record<string, boolean | S3CollectionConfig>;
|
|
|
500
557
|
* @internal
|
|
501
558
|
*/
|
|
502
559
|
interface ResolvedS3Config {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
560
|
+
bucket: string;
|
|
561
|
+
region: string;
|
|
562
|
+
endpoint?: string;
|
|
563
|
+
forcePathStyle: boolean;
|
|
564
|
+
acl: S3ObjectACL;
|
|
565
|
+
publicUrl?: string;
|
|
566
|
+
cacheControl: string;
|
|
567
|
+
contentDisposition?: "inline" | "attachment";
|
|
568
|
+
signedUrlExpiresIn: number;
|
|
512
569
|
}
|
|
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
570
|
/**
|
|
577
571
|
* Create an S3 storage plugin for Nextly.
|
|
578
572
|
*
|
|
@@ -588,286 +582,276 @@ interface ResolvedS3Config {
|
|
|
588
582
|
* @param config - S3 storage configuration
|
|
589
583
|
* @returns A StoragePlugin that MediaStorage can register
|
|
590
584
|
*
|
|
591
|
-
*
|
|
592
|
-
*
|
|
585
|
+
* Constructing the plugin never requires the bucket or region: a missing
|
|
586
|
+
* one is refused when storage is first used, not while the config loads.
|
|
593
587
|
*/
|
|
594
|
-
declare function s3Storage(config: S3StorageConfig): StoragePlugin;
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
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
|
-
|
|
588
|
+
export declare function s3Storage(config: S3StorageConfig): StoragePlugin;
|
|
589
|
+
export declare class S3StorageAdapter implements IStorageAdapter {
|
|
590
|
+
private config;
|
|
591
|
+
private client;
|
|
592
|
+
private resolvedConfig;
|
|
593
|
+
private isR2;
|
|
594
|
+
/**
|
|
595
|
+
* Create a new S3 storage adapter.
|
|
596
|
+
*
|
|
597
|
+
* The bucket and region are deliberately NOT checked here, and the SDK
|
|
598
|
+
* client is deliberately not built. This constructor runs while the host's
|
|
599
|
+
* config file is evaluated, so a throw would stop every command —
|
|
600
|
+
* including the schema-only ones that never touch storage. Both the checks
|
|
601
|
+
* and the client construction move to the first storage operation
|
|
602
|
+
* ({@link ensureClient} and {@link ensureConfigured}), which refuse with
|
|
603
|
+
* the same messages a missing bucket or region has always produced.
|
|
604
|
+
*
|
|
605
|
+
* @param config - S3 storage configuration
|
|
606
|
+
*/
|
|
607
|
+
constructor(config: S3StorageConfig);
|
|
608
|
+
/**
|
|
609
|
+
* Validate that bucket and region are present.
|
|
610
|
+
*
|
|
611
|
+
* @throws Error if bucket is not provided
|
|
612
|
+
* @throws Error if region is not provided
|
|
613
|
+
*/
|
|
614
|
+
private ensureConfigured;
|
|
615
|
+
/**
|
|
616
|
+
* Validate the stored configuration and build the SDK client, at the
|
|
617
|
+
* first use that needs them.
|
|
618
|
+
*
|
|
619
|
+
* The refusals are the ones the constructor used to throw, in the same
|
|
620
|
+
* order, so an operator with a genuinely misconfigured deployment sees
|
|
621
|
+
* the message they have always seen — at the moment the value was
|
|
622
|
+
* actually needed rather than at config load. The client is built once
|
|
623
|
+
* and reused.
|
|
624
|
+
*
|
|
625
|
+
* @throws Error if bucket is not provided
|
|
626
|
+
* @throws Error if region is not provided
|
|
627
|
+
*/
|
|
628
|
+
private ensureClient;
|
|
629
|
+
/**
|
|
630
|
+
* Build AWS credentials from config.
|
|
631
|
+
* Supports explicit credentials or falls back to SDK default chain.
|
|
632
|
+
*/
|
|
633
|
+
private buildCredentials;
|
|
634
|
+
/**
|
|
635
|
+
* Upload file to S3.
|
|
636
|
+
*
|
|
637
|
+
* Uses AWS SDK v3's Upload class from @aws-sdk/lib-storage which:
|
|
638
|
+
* - Automatically handles multipart upload for large files (>5MB)
|
|
639
|
+
* - Provides progress tracking capability
|
|
640
|
+
* - Includes retry logic
|
|
641
|
+
* - Optimizes upload performance
|
|
642
|
+
*
|
|
643
|
+
* @param buffer - File content as Buffer
|
|
644
|
+
* @param options - Upload options (filename, mimeType, folder, collection)
|
|
645
|
+
* @returns Upload result with URL and storage path
|
|
646
|
+
*/
|
|
647
|
+
upload(buffer: Buffer, options: UploadOptions): Promise<UploadResult>;
|
|
648
|
+
/**
|
|
649
|
+
* Write bytes at exactly `filePath`, beside a file already in the bucket.
|
|
650
|
+
*
|
|
651
|
+
* Core uses it to keep a file made from a stored one, such as a resized
|
|
652
|
+
* copy of an image, under a key derived from the original's. One request,
|
|
653
|
+
* since such a file is small, with the same cache setting and access as an
|
|
654
|
+
* upload, so it is served the way its original is.
|
|
655
|
+
*
|
|
656
|
+
* @experimental
|
|
657
|
+
*/
|
|
658
|
+
uploadAt(filePath: string, buffer: Buffer, options: {
|
|
659
|
+
mimeType: string;
|
|
660
|
+
}): Promise<UploadResult>;
|
|
661
|
+
/**
|
|
662
|
+
* Delete file from S3.
|
|
663
|
+
*
|
|
664
|
+
* @param filePath - Storage path/key to delete
|
|
665
|
+
*/
|
|
666
|
+
delete(filePath: string): Promise<void>;
|
|
667
|
+
/**
|
|
668
|
+
* Bulk delete files from S3 using a single API call per 1000 keys.
|
|
669
|
+
*
|
|
670
|
+
* Uses AWS SDK v3's DeleteObjectsCommand which supports up to 1000 keys per
|
|
671
|
+
* request. Automatically batches larger arrays and collects per-key results.
|
|
672
|
+
*
|
|
673
|
+
* @param filePaths - Storage paths/keys to delete
|
|
674
|
+
* @returns Object with arrays of successful and failed deletions
|
|
675
|
+
*/
|
|
676
|
+
bulkDelete(filePaths: string[]): Promise<BulkDeleteResult>;
|
|
677
|
+
/**
|
|
678
|
+
* Check if file exists in S3.
|
|
679
|
+
*
|
|
680
|
+
* Uses HeadObject command which is more efficient than GetObject
|
|
681
|
+
* for existence checks (doesn't download the file).
|
|
682
|
+
*
|
|
683
|
+
* @param filePath - Storage path/key to check
|
|
684
|
+
* @returns true if file exists, false otherwise
|
|
685
|
+
*/
|
|
686
|
+
exists(filePath: string): Promise<boolean>;
|
|
687
|
+
/**
|
|
688
|
+
* Get public URL for S3 file.
|
|
689
|
+
*
|
|
690
|
+
* Priority order:
|
|
691
|
+
* 1. Custom publicUrl (CDN or custom domain) if configured
|
|
692
|
+
* 2. Standard S3 URL based on region and bucket
|
|
693
|
+
*
|
|
694
|
+
* For R2: Requires publicUrl configuration (R2 has no default public URLs).
|
|
695
|
+
*
|
|
696
|
+
* @param filePath - Storage path/key
|
|
697
|
+
* @returns Public URL to access the file
|
|
698
|
+
* @throws Error if R2 is used without publicUrl configuration
|
|
699
|
+
*/
|
|
700
|
+
/**
|
|
701
|
+
* Every object in the bucket, by key, with when it was last written, a page
|
|
702
|
+
* of up to 1,000 at a time.
|
|
703
|
+
*/
|
|
704
|
+
list(): AsyncIterable<StoredFileEntry>;
|
|
705
|
+
getPublicUrl(filePath: string): string;
|
|
706
|
+
/**
|
|
707
|
+
* Get storage type identifier.
|
|
708
|
+
*
|
|
709
|
+
* Returns "s3" for all S3-compatible services (AWS S3, R2, MinIO, etc.)
|
|
710
|
+
* as they all use the S3 API.
|
|
711
|
+
*/
|
|
712
|
+
getType(): "s3";
|
|
713
|
+
/**
|
|
714
|
+
* Get adapter info including capabilities.
|
|
715
|
+
*
|
|
716
|
+
* @returns Adapter info with type, name, and capability flags
|
|
717
|
+
*/
|
|
718
|
+
getInfo(): StorageAdapterInfo;
|
|
719
|
+
/**
|
|
720
|
+
* Get file metadata from S3.
|
|
721
|
+
*
|
|
722
|
+
* Retrieves file information including size, content type, and timestamps
|
|
723
|
+
* using the HeadObject command.
|
|
724
|
+
*
|
|
725
|
+
* @param filePath - Storage path/key
|
|
726
|
+
* @returns File metadata or null if file not found
|
|
727
|
+
*/
|
|
728
|
+
getMetadata(filePath: string): Promise<FileMetadata | null>;
|
|
729
|
+
/**
|
|
730
|
+
* Read a stored object back as bytes, or `null` when it is not there.
|
|
731
|
+
*
|
|
732
|
+
* The contract declares this OPTIONAL and, until now, no adapter supplied
|
|
733
|
+
* it — so a caller reaching for `adapter.read` got `undefined` and fell
|
|
734
|
+
* through whatever branch followed. An optional member nothing implements is
|
|
735
|
+
* a contract that reads as a capability and behaves as an absence.
|
|
736
|
+
*
|
|
737
|
+
* BUFFERS rather than streams, because that is the declared return type and
|
|
738
|
+
* widening it here would make this adapter answer a different question from
|
|
739
|
+
* its siblings. That bounds what it should be used for: an asset the server
|
|
740
|
+
* must serve from its own origin — a font file, a small document — rather
|
|
741
|
+
* than arbitrarily large media, which belongs behind {@link getSignedUrl} or
|
|
742
|
+
* a public URL. A streaming variant is a separate contract member, not a
|
|
743
|
+
* quiet change to this one.
|
|
744
|
+
*
|
|
745
|
+
* `null` for a missing key rather than a throw, matching
|
|
746
|
+
* {@link getMetadata}: absence is an ordinary answer about the bucket, while
|
|
747
|
+
* a credential or network failure is not, so only the first is folded into
|
|
748
|
+
* the return value.
|
|
749
|
+
*
|
|
750
|
+
* @param filePath - Storage path/key
|
|
751
|
+
* @returns The object's bytes, or `null` when no such key exists
|
|
752
|
+
*/
|
|
753
|
+
read(filePath: string, options?: StorageReadOptions): Promise<Buffer | null>;
|
|
754
|
+
/**
|
|
755
|
+
* Generate signed URL for temporary private file access.
|
|
756
|
+
*
|
|
757
|
+
* Creates a pre-signed GetObject URL that grants temporary read access
|
|
758
|
+
* to private files. Useful for serving files from private buckets.
|
|
759
|
+
*
|
|
760
|
+
* @param filePath - Storage path/key
|
|
761
|
+
* @param expiresIn - URL validity duration in seconds (default: 3600)
|
|
762
|
+
* @returns Pre-signed URL for downloading the file
|
|
763
|
+
*/
|
|
764
|
+
getSignedUrl(filePath: string, expiresIn?: number): Promise<string>;
|
|
765
|
+
/**
|
|
766
|
+
* Generate pre-signed URL for client-side uploads.
|
|
767
|
+
*
|
|
768
|
+
* Creates a pre-signed PutObject URL that allows direct uploads from
|
|
769
|
+
* the browser to S3, bypassing server-side upload limits (e.g., Vercel's 4.5MB).
|
|
770
|
+
*
|
|
771
|
+
* The signature covers the `Content-Type` and, given `options.contentLength`,
|
|
772
|
+
* the `Content-Length`: the bytes never pass Nextly's upload checks, so S3
|
|
773
|
+
* itself refuses a body of another type or length. The browser sets the
|
|
774
|
+
* length from the body; it is not a header the client sends.
|
|
775
|
+
*
|
|
776
|
+
* It covers the configured `Cache-Control` too, which is returned in
|
|
777
|
+
* `headers`: S3 stores an object's Cache-Control only from the upload
|
|
778
|
+
* request's own header, so a browser upload is served with the same caching
|
|
779
|
+
* as a server one only when the client sends it. The client must send every
|
|
780
|
+
* header in `headers`, as it is; one left out fails the signature.
|
|
781
|
+
*
|
|
782
|
+
* @param key - Storage path/key for the upload
|
|
783
|
+
* @param mimeType - MIME type of the file being uploaded
|
|
784
|
+
* @param expiresIn - URL validity in seconds, at most the configured
|
|
785
|
+
* `signedUrlExpiresIn` (its default)
|
|
786
|
+
* @param options - `contentLength`: the exact size the upload may have
|
|
787
|
+
* @returns Client upload data with URL, method, and headers
|
|
788
|
+
*/
|
|
789
|
+
getPresignedUploadUrl(key: string, mimeType: string, expiresIn?: number, options?: {
|
|
790
|
+
contentLength?: number;
|
|
791
|
+
}): Promise<ClientUploadData>;
|
|
792
|
+
/**
|
|
793
|
+
* Check if an error is a "not found" error from S3.
|
|
794
|
+
*
|
|
795
|
+
* @param error - Error to check
|
|
796
|
+
* @returns true if error indicates file not found
|
|
797
|
+
*/
|
|
798
|
+
/**
|
|
799
|
+
* The object's bytes, refusing once more than `cap` have actually arrived.
|
|
800
|
+
*
|
|
801
|
+
* `ContentLength` is OPTIONAL in the SDK's response type, and this adapter
|
|
802
|
+
* explicitly supports MinIO, R2 and other compatible services — any of which
|
|
803
|
+
* may omit it or report it wrongly. A preflight check against metadata is
|
|
804
|
+
* therefore a courtesy that fails OPEN: trusting it alone leaves the cap
|
|
805
|
+
* unenforced exactly where an unusual backend is involved, which is where a
|
|
806
|
+
* caller most needs it.
|
|
807
|
+
*
|
|
808
|
+
* Counted while consuming, so an oversized body is abandoned partway rather
|
|
809
|
+
* than after it has all been buffered — the cap exists to bound memory, and
|
|
810
|
+
* one applied after `transformToByteArray` has already spent it.
|
|
811
|
+
*
|
|
812
|
+
* Falls back to buffering when the body is not async-iterable, which the SDK
|
|
813
|
+
* types permit. Stated rather than hidden: on that path the cap bounds what a
|
|
814
|
+
* caller RECEIVES rather than what the process allocates.
|
|
815
|
+
*/
|
|
816
|
+
private readCapped;
|
|
817
|
+
/**
|
|
818
|
+
* Refuse a read whose object is already known to exceed the caller's cap.
|
|
819
|
+
*
|
|
820
|
+
* Its own method rather than three conditions inside `read`, because the
|
|
821
|
+
* decision has nothing to do with the surrounding error handling and reads
|
|
822
|
+
* as noise there — and because `read`'s branching is the part a reviewer has
|
|
823
|
+
* to hold in their head to check the absent-versus-unavailable distinction.
|
|
824
|
+
*
|
|
825
|
+
* Both `undefined` cases mean "no opinion" and pass: a caller that named no
|
|
826
|
+
* cap has none, and a store that reported no length gives nothing to compare.
|
|
827
|
+
* The second is deliberately permissive — refusing an unmeasured object would
|
|
828
|
+
* reject valid reads whenever S3 omits the header.
|
|
829
|
+
*/
|
|
830
|
+
private refuseOverCap;
|
|
831
|
+
private isNotFoundError;
|
|
832
|
+
/**
|
|
833
|
+
* Get the S3 client instance.
|
|
834
|
+
* Useful for advanced operations not covered by the adapter interface.
|
|
835
|
+
*
|
|
836
|
+
* Handing out the client is itself a use of the adapter, so a caller
|
|
837
|
+
* without the configuration a client needs is refused here like any
|
|
838
|
+
* other operation.
|
|
839
|
+
*/
|
|
840
|
+
getClient(): S3Client;
|
|
841
|
+
/**
|
|
842
|
+
* Get the bucket name.
|
|
843
|
+
*/
|
|
844
|
+
getBucket(): string;
|
|
845
|
+
/**
|
|
846
|
+
* Get the AWS region.
|
|
847
|
+
*/
|
|
848
|
+
getRegion(): string;
|
|
849
|
+
/**
|
|
850
|
+
* Check if this adapter is configured for Cloudflare R2.
|
|
851
|
+
*/
|
|
852
|
+
isCloudflareR2(): boolean;
|
|
813
853
|
}
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
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 };
|
|
854
|
+
export declare const PACKAGE_NAME = "@nextly/storage-s3";
|
|
855
|
+
export declare const PACKAGE_VERSION = "0.1.0";
|
|
856
|
+
export type { ResolvedS3Config, S3CollectionConfig, S3CollectionStorageMap, S3ObjectACL, S3StorageConfig };
|
|
857
|
+
//# sourceMappingURL=index.d.ts.map
|