@nextlyhq/storage-s3 0.0.2-alpha.80 → 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
@@ -100,6 +100,66 @@ interface StorageAdapterInfo {
100
100
  supportsSignedUrls: boolean;
101
101
  /** Whether this adapter supports client-side (direct) uploads */
102
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;
103
163
  }
104
164
  /**
105
165
  * Per-collection storage configuration.
@@ -306,6 +366,48 @@ interface IStorageAdapter {
306
366
  * them, which is said rather than taken as "none".
307
367
  */
308
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>;
309
411
  }
310
412
  /**
311
413
  * S3 storage adapter configuration.
@@ -658,6 +760,37 @@ export declare class S3StorageAdapter implements IStorageAdapter {
658
760
  uploadAt(filePath: string, buffer: Buffer, options: {
659
761
  mimeType: string;
660
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>;
661
794
  /**
662
795
  * Delete file from S3.
663
796
  *
@@ -751,6 +884,25 @@ export declare class S3StorageAdapter implements IStorageAdapter {
751
884
  * @returns The object's bytes, or `null` when no such key exists
752
885
  */
753
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>;
754
906
  /**
755
907
  * Generate signed URL for temporary private file access.
756
908
  *
@@ -789,6 +941,13 @@ export declare class S3StorageAdapter implements IStorageAdapter {
789
941
  getPresignedUploadUrl(key: string, mimeType: string, expiresIn?: number, options?: {
790
942
  contentLength?: number;
791
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;
792
951
  /**
793
952
  * Check if an error is a "not found" error from S3.
794
953
  *
package/dist/index.d.ts CHANGED
@@ -100,6 +100,66 @@ interface StorageAdapterInfo {
100
100
  supportsSignedUrls: boolean;
101
101
  /** Whether this adapter supports client-side (direct) uploads */
102
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;
103
163
  }
104
164
  /**
105
165
  * Per-collection storage configuration.
@@ -306,6 +366,48 @@ interface IStorageAdapter {
306
366
  * them, which is said rather than taken as "none".
307
367
  */
308
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>;
309
411
  }
310
412
  /**
311
413
  * S3 storage adapter configuration.
@@ -658,6 +760,37 @@ export declare class S3StorageAdapter implements IStorageAdapter {
658
760
  uploadAt(filePath: string, buffer: Buffer, options: {
659
761
  mimeType: string;
660
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>;
661
794
  /**
662
795
  * Delete file from S3.
663
796
  *
@@ -751,6 +884,25 @@ export declare class S3StorageAdapter implements IStorageAdapter {
751
884
  * @returns The object's bytes, or `null` when no such key exists
752
885
  */
753
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>;
754
906
  /**
755
907
  * Generate signed URL for temporary private file access.
756
908
  *
@@ -789,6 +941,13 @@ export declare class S3StorageAdapter implements IStorageAdapter {
789
941
  getPresignedUploadUrl(key: string, mimeType: string, expiresIn?: number, options?: {
790
942
  contentLength?: number;
791
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;
792
951
  /**
793
952
  * Check if an error is a "not found" error from S3.
794
953
  *
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DeleteObjectCommand, DeleteObjectsCommand, GetObjectCommand, HeadObjectCommand, ListObjectsV2Command, PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
2
2
  import { Upload } from "@aws-sdk/lib-storage";
3
3
  import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
4
- // ../nextly/dist/nextly-error-jIKkC0DY.mjs
4
+ // ../nextly/dist/nextly-error-D8GUAFzw.mjs
5
5
  function isDbError(err) {
6
6
  if (!err || typeof err !== "object") return false;
7
7
  const obj = err;
@@ -85,6 +85,7 @@ const NEXTLY_ERROR_STATUS = {
85
85
  RANGE_NOT_SATISFIABLE: 416,
86
86
  CONFLICT: 409,
87
87
  STALE_VERSION: 409,
88
+ COLLECTION_BEING_CHANGED: 409,
88
89
  VERSION_REQUIRED: 428,
89
90
  DUPLICATE: 409,
90
91
  RATE_LIMITED: 429,
@@ -916,7 +917,7 @@ var NextlyError = class NextlyError extends Error {
916
917
  return NextlyError.isCode(err, "RATE_LIMITED");
917
918
  }
918
919
  };
919
- // ../nextly/dist/validate-external-url-ZJNqaKd2.mjs
920
+ // ../nextly/dist/validate-external-url-Dpn-k4nU.mjs
920
921
  /** Default response body cap: reject anything larger before buffering it all. */
921
922
  /**
922
923
  * How many bytes a bounded external read may buffer, absent a caller's own cap.
@@ -1117,6 +1118,12 @@ function generateStorageKey(filename, folder) {
1117
1118
  * ```
1118
1119
  */
1119
1120
  /**
1121
+ * The Cache-Control a private object is stored and answered with: no cache,
1122
+ * shared or the browser's own, may keep a copy, so every later request has to
1123
+ * come back through Nextly's checked route.
1124
+ */
1125
+ const PRIVATE_CACHE_CONTROL = "private, no-store";
1126
+ /**
1120
1127
  * S3 Storage Adapter
1121
1128
  *
1122
1129
  * Implements the IStorageAdapter interface for AWS S3 and S3-compatible services.
@@ -1249,12 +1256,13 @@ var S3StorageAdapter = class {
1249
1256
  uploadParams.ContentDisposition = disposition === "attachment" ? `attachment; filename="${filename}"` : "inline";
1250
1257
  }
1251
1258
  uploadParams.Metadata = { "original-filename": options.filename };
1259
+ const url = this.getPublicUrl(key);
1252
1260
  await new Upload({
1253
1261
  client,
1254
1262
  params: uploadParams
1255
1263
  }).done();
1256
1264
  return {
1257
- url: this.getPublicUrl(key),
1265
+ url,
1258
1266
  path: key
1259
1267
  };
1260
1268
  }
@@ -1278,13 +1286,74 @@ var S3StorageAdapter = class {
1278
1286
  CacheControl: this.resolvedConfig.cacheControl
1279
1287
  };
1280
1288
  if (!this.isR2) params.ACL = this.resolvedConfig.acl;
1289
+ const url = this.getPublicUrl(filePath);
1281
1290
  await client.send(new PutObjectCommand(params));
1282
1291
  return {
1283
- url: this.getPublicUrl(filePath),
1292
+ url,
1284
1293
  path: filePath
1285
1294
  };
1286
1295
  }
1287
1296
  /**
1297
+ * Store a private file at exactly `key`, the key core made for it.
1298
+ *
1299
+ * Unlike {@link upload}: no public address is formed (so an R2 bucket needs
1300
+ * no `publicUrl`), the original file name goes into neither the key nor the
1301
+ * object's metadata, the object is stored never to be cached, and its ACL is
1302
+ * `private` whatever the adapter's own `acl` says (R2 has no ACLs, and keeps
1303
+ * a bucket private unless public access is turned on for it).
1304
+ *
1305
+ * @experimental
1306
+ */
1307
+ async putPrivate(key, buffer, options) {
1308
+ const client = this.ensureClient();
1309
+ const params = {
1310
+ Bucket: this.resolvedConfig.bucket,
1311
+ Key: key,
1312
+ Body: buffer,
1313
+ ContentType: options.mimeType,
1314
+ CacheControl: PRIVATE_CACHE_CONTROL
1315
+ };
1316
+ if (!this.isR2) params.ACL = "private";
1317
+ await new Upload({
1318
+ client,
1319
+ params
1320
+ }).done();
1321
+ }
1322
+ /**
1323
+ * A pre-signed URL a browser sends one private file to, at exactly `key`.
1324
+ * Binds the type and exact length as {@link getPresignedUploadUrl} does,
1325
+ * and writes the object private and never cached.
1326
+ *
1327
+ * @experimental
1328
+ */
1329
+ async getPrivateUploadUrl(key, mimeType, options) {
1330
+ return this.presignPut(key, mimeType, {
1331
+ cacheControl: PRIVATE_CACHE_CONTROL,
1332
+ acl: "private",
1333
+ expiresIn: options.expiresIn,
1334
+ contentLength: options.contentLength
1335
+ });
1336
+ }
1337
+ /**
1338
+ * A link to a private file that lasts `options.expiresIn` seconds (at most
1339
+ * the configured `signedUrlExpiresIn`). The bucket answers it with the
1340
+ * given Content-Disposition and type, and with a Cache-Control that lets no
1341
+ * cache keep it, whatever the object itself was stored with.
1342
+ *
1343
+ * @experimental
1344
+ */
1345
+ async getPrivateDownloadUrl(key, options) {
1346
+ const client = this.ensureClient();
1347
+ const command = new GetObjectCommand({
1348
+ Bucket: this.resolvedConfig.bucket,
1349
+ Key: key,
1350
+ ResponseContentDisposition: options.contentDisposition,
1351
+ ResponseCacheControl: PRIVATE_CACHE_CONTROL,
1352
+ ...options.contentType !== void 0 ? { ResponseContentType: options.contentType } : {}
1353
+ });
1354
+ return getSignedUrl(client, command, { expiresIn: Math.min(options.expiresIn, this.resolvedConfig.signedUrlExpiresIn) });
1355
+ }
1356
+ /**
1288
1357
  * Delete file from S3.
1289
1358
  *
1290
1359
  * @param filePath - Storage path/key to delete
@@ -1394,7 +1463,7 @@ var S3StorageAdapter = class {
1394
1463
  getPublicUrl(filePath) {
1395
1464
  this.ensureConfigured();
1396
1465
  if (this.resolvedConfig.publicUrl) return `${this.resolvedConfig.publicUrl.replace(/\/$/, "")}/${filePath}`;
1397
- if (this.isR2) throw new Error("@nextly/storage-s3: Cloudflare R2 requires publicUrl configuration.\n\nR2 does not have default public URLs like AWS S3. Configure one of:\n1. Public bucket URL: publicUrl: 'https://pub-xxx.r2.dev'\n2. Custom domain: publicUrl: 'https://cdn.example.com'\n\nSet up public access in the Cloudflare R2 dashboard.");
1466
+ if (this.isR2) throw new Error("@nextly/storage-s3: Cloudflare R2 requires publicUrl configuration.\n\nR2 does not have default public URLs like AWS S3. Configure one of:\n1. Public bucket URL: publicUrl: 'https://pub-xxx.r2.dev'\n2. Custom domain: publicUrl: 'https://cdn.example.com'\n\nSet up public access in the Cloudflare R2 dashboard. A collection of private files needs none: its files have no public address.");
1398
1467
  return `https://${this.resolvedConfig.bucket}.s3.${this.resolvedConfig.region}.amazonaws.com/${filePath}`;
1399
1468
  }
1400
1469
  /**
@@ -1416,7 +1485,8 @@ var S3StorageAdapter = class {
1416
1485
  type: "s3",
1417
1486
  name: "S3StorageAdapter",
1418
1487
  supportsSignedUrls: true,
1419
- supportsClientUploads: true
1488
+ supportsClientUploads: true,
1489
+ supportsPrivateFiles: !this.resolvedConfig.publicUrl
1420
1490
  };
1421
1491
  }
1422
1492
  /**
@@ -1494,6 +1564,61 @@ var S3StorageAdapter = class {
1494
1564
  }
1495
1565
  }
1496
1566
  /**
1567
+ * The stored object's size and type, without reading it, or `null` when the
1568
+ * key is not in the bucket. A missing bucket throws rather than reading as a
1569
+ * missing key, as for {@link read}.
1570
+ *
1571
+ * @experimental
1572
+ */
1573
+ async head(filePath) {
1574
+ const client = this.ensureClient();
1575
+ try {
1576
+ const response = await client.send(new HeadObjectCommand({
1577
+ Bucket: this.resolvedConfig.bucket,
1578
+ Key: filePath
1579
+ }));
1580
+ if (response.ContentLength === void 0) throw new Error("@nextly/storage-s3: the bucket did not report the object's size");
1581
+ return {
1582
+ size: response.ContentLength,
1583
+ ...response.ContentType !== void 0 ? { contentType: response.ContentType } : {},
1584
+ ...response.LastModified !== void 0 ? { lastModified: response.LastModified } : {}
1585
+ };
1586
+ } catch (error) {
1587
+ if (error instanceof Error && error.name === "NoSuchBucket") throw error;
1588
+ if (this.isNotFoundError(error)) return null;
1589
+ throw error;
1590
+ }
1591
+ }
1592
+ /**
1593
+ * The stored object as a stream, or `null` when the key is not in the
1594
+ * bucket, for a response that should not buffer a whole file.
1595
+ *
1596
+ * The deadline covers the bucket's answer only, then is cleared: the body
1597
+ * flows as fast as its reader takes it, and a deadline on the whole
1598
+ * transfer would cut off a slow but healthy download.
1599
+ *
1600
+ * @experimental
1601
+ */
1602
+ async readStream(filePath, options) {
1603
+ const client = this.ensureClient();
1604
+ const answered = new AbortController();
1605
+ const timer = setTimeout(() => answered.abort(), resolveReadBounds(options).timeoutMs);
1606
+ try {
1607
+ const response = await client.send(new GetObjectCommand({
1608
+ Bucket: this.resolvedConfig.bucket,
1609
+ Key: filePath
1610
+ }), { abortSignal: answered.signal });
1611
+ if (response.Body === void 0) return new ReadableStream({ start: (controller) => controller.close() });
1612
+ return response.Body.transformToWebStream();
1613
+ } catch (error) {
1614
+ if (error instanceof Error && error.name === "NoSuchBucket") throw error;
1615
+ if (this.isNotFoundError(error)) return null;
1616
+ throw error;
1617
+ } finally {
1618
+ clearTimeout(timer);
1619
+ }
1620
+ }
1621
+ /**
1497
1622
  * Generate signed URL for temporary private file access.
1498
1623
  *
1499
1624
  * Creates a pre-signed GetObject URL that grants temporary read access
@@ -1536,17 +1661,31 @@ var S3StorageAdapter = class {
1536
1661
  * @returns Client upload data with URL, method, and headers
1537
1662
  */
1538
1663
  async getPresignedUploadUrl(key, mimeType, expiresIn, options) {
1664
+ return this.presignPut(key, mimeType, {
1665
+ cacheControl: this.resolvedConfig.cacheControl,
1666
+ acl: this.resolvedConfig.acl,
1667
+ expiresIn,
1668
+ contentLength: options?.contentLength
1669
+ });
1670
+ }
1671
+ /**
1672
+ * Sign one direct upload at exactly `key`: the type, the length when given,
1673
+ * and the Cache-Control are signed, so S3 refuses a body that differs. The
1674
+ * one signer for public and private uploads alike, which differ only in the
1675
+ * caching and access they write.
1676
+ */
1677
+ async presignPut(key, mimeType, put) {
1539
1678
  const client = this.ensureClient();
1540
1679
  const longest = this.resolvedConfig.signedUrlExpiresIn;
1541
- const expiration = Math.min(expiresIn ?? longest, longest);
1680
+ const expiration = Math.min(put.expiresIn ?? longest, longest);
1542
1681
  const commandParams = {
1543
1682
  Bucket: this.resolvedConfig.bucket,
1544
1683
  Key: key,
1545
1684
  ContentType: mimeType,
1546
- CacheControl: this.resolvedConfig.cacheControl,
1547
- ...options?.contentLength !== void 0 ? { ContentLength: options.contentLength } : {}
1685
+ CacheControl: put.cacheControl,
1686
+ ...put.contentLength !== void 0 ? { ContentLength: put.contentLength } : {}
1548
1687
  };
1549
- if (!this.isR2) commandParams.ACL = this.resolvedConfig.acl;
1688
+ if (!this.isR2) commandParams.ACL = put.acl;
1550
1689
  const command = new PutObjectCommand(commandParams);
1551
1690
  return {
1552
1691
  uploadUrl: await getSignedUrl(client, command, {
@@ -1561,7 +1700,7 @@ var S3StorageAdapter = class {
1561
1700
  method: "PUT",
1562
1701
  headers: {
1563
1702
  "Content-Type": mimeType,
1564
- "Cache-Control": this.resolvedConfig.cacheControl
1703
+ "Cache-Control": put.cacheControl
1565
1704
  },
1566
1705
  expiresAt: new Date(Date.now() + expiration * 1e3)
1567
1706
  };