@nextlyhq/storage-s3 0.0.2-alpha.75 → 0.0.2-alpha.77

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 CHANGED
@@ -101,6 +101,8 @@ s3Storage({
101
101
  });
102
102
  ```
103
103
 
104
+ With `clientUploads`, the browser asks for a pre-signed URL with the file's name, type and exact size. Nextly checks them first (name, extension, type allowlist, size; never an SVG), and the URL binds the type and the exact size, so S3 refuses any other file. The bytes themselves don't pass through Nextly, so their content is not checked.
105
+
104
106
  ## Main exports
105
107
 
106
108
  - `s3Storage`: plugin factory for `defineConfig.storage`
package/dist/index.cjs CHANGED
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let _aws_sdk_client_s3 = require("@aws-sdk/client-s3");
3
3
  let _aws_sdk_lib_storage = require("@aws-sdk/lib-storage");
4
4
  let _aws_sdk_s3_request_presigner = require("@aws-sdk/s3-request-presigner");
5
- // ../nextly/dist/nextly-error-BElDQWyI.mjs
5
+ // ../nextly/dist/nextly-error-C_MDZmJc.mjs
6
6
  function isDbError(err) {
7
7
  if (!err || typeof err !== "object") return false;
8
8
  const obj = err;
@@ -116,10 +116,14 @@ const NEXTLY_ERROR_STATUS = {
116
116
  NEXTLY_UPGRADE_TABLE_NAME_COLLISION: 409,
117
117
  NEXTLY_UPGRADE_IN_PROGRESS: 409,
118
118
  NEXTLY_MIGRATE_LOCK_BUSY: 409,
119
+ NEXTLY_TABLE_BUSY: 409,
120
+ NEXTLY_LOCK_HELD_BY_THIS_PROCESS: 500,
119
121
  NEXTLY_BASELINE_LOCK_NOT_HELD: 409,
120
122
  NEXTLY_RESOLVE_LOCK_NOT_HELD: 409,
121
123
  NEXTLY_BOOT_MIGRATIONS_NOT_RUN: 503,
122
124
  NEXTLY_BOOT_MIGRATIONS_PENDING: 503,
125
+ NEXTLY_DATABASE_NOT_SET_UP: 503,
126
+ NEXTLY_DATABASE_NOT_MIGRATED: 503,
123
127
  NEXTLY_CORE_DESTRUCTIVE_REFUSED: 409,
124
128
  NEXTLY_MIGRATION_DRIFT: 409,
125
129
  NEXTLY_MIGRATION_APPLY_FAILED: 500,
@@ -175,7 +179,7 @@ const NEXTLY_ERROR_STATUS = {
175
179
  NEXTLY_PER_LANGUAGE_STORAGE_CHANGED: 500,
176
180
  NEXTLY_PER_LANGUAGE_STORAGE_MIXED: 500,
177
181
  NEXTLY_PER_LANGUAGE_STORAGE_LANGUAGES_UNDECLARED: 500,
178
- NEXTLY_POSTGRES_SCHEMA_UNSUPPORTED: 500
182
+ NEXTLY_POSTGRES_SCHEMA_MOVED: 500
179
183
  };
180
184
  ({ ...Object.fromEntries([
181
185
  "VALIDATION_ERROR",
@@ -789,6 +793,19 @@ var NextlyError = class NextlyError extends Error {
789
793
  logContext: opts.logContext
790
794
  });
791
795
  }
796
+ /**
797
+ * A service outside Nextly failed, such as an email provider, where trying again may help: the
798
+ * job queue records it as an attempt's error and tries again.
799
+ */
800
+ static externalService(opts) {
801
+ return new NextlyError({
802
+ code: "EXTERNAL_SERVICE_ERROR",
803
+ publicMessage: opts.publicMessage,
804
+ logMessage: opts.logMessage,
805
+ cause: opts.cause,
806
+ logContext: opts.logContext
807
+ });
808
+ }
792
809
  static serviceUnavailable(opts) {
793
810
  return new NextlyError({
794
811
  code: "SERVICE_UNAVAILABLE",
@@ -861,7 +878,7 @@ var NextlyError = class NextlyError extends Error {
861
878
  return NextlyError.isCode(err, "RATE_LIMITED");
862
879
  }
863
880
  };
864
- // ../nextly/dist/validate-external-url-DNl_UEVd.mjs
881
+ // ../nextly/dist/validate-external-url-DF_HNT6F.mjs
865
882
  /** Default response body cap: reject anything larger before buffering it all. */
866
883
  /**
867
884
  * How many bytes a bounded external read may buffer, absent a caller's own cap.
@@ -1379,24 +1396,36 @@ var S3StorageAdapter = class {
1379
1396
  * Creates a pre-signed PutObject URL that allows direct uploads from
1380
1397
  * the browser to S3, bypassing server-side upload limits (e.g., Vercel's 4.5MB).
1381
1398
  *
1399
+ * The signature covers the `Content-Type` and, given `options.contentLength`,
1400
+ * the `Content-Length`: the bytes never pass Nextly's upload checks, so S3
1401
+ * itself refuses a body of another type or length. The browser sets the
1402
+ * length from the body; it is not a header the client sends.
1403
+ *
1382
1404
  * @param key - Storage path/key for the upload
1383
1405
  * @param mimeType - MIME type of the file being uploaded
1384
- * @param expiresIn - URL validity duration in seconds (default: 3600)
1406
+ * @param expiresIn - URL validity in seconds, at most the configured
1407
+ * `signedUrlExpiresIn` (its default)
1408
+ * @param options - `contentLength`: the exact size the upload may have
1385
1409
  * @returns Client upload data with URL, method, and headers
1386
1410
  */
1387
- async getPresignedUploadUrl(key, mimeType, expiresIn) {
1411
+ async getPresignedUploadUrl(key, mimeType, expiresIn, options) {
1388
1412
  const client = this.ensureClient();
1389
- const expiration = expiresIn ?? this.resolvedConfig.signedUrlExpiresIn;
1413
+ const longest = this.resolvedConfig.signedUrlExpiresIn;
1414
+ const expiration = Math.min(expiresIn ?? longest, longest);
1390
1415
  const commandParams = {
1391
1416
  Bucket: this.resolvedConfig.bucket,
1392
1417
  Key: key,
1393
1418
  ContentType: mimeType,
1394
- CacheControl: this.resolvedConfig.cacheControl
1419
+ CacheControl: this.resolvedConfig.cacheControl,
1420
+ ...options?.contentLength !== void 0 ? { ContentLength: options.contentLength } : {}
1395
1421
  };
1396
1422
  if (!this.isR2) commandParams.ACL = this.resolvedConfig.acl;
1397
1423
  const command = new _aws_sdk_client_s3.PutObjectCommand(commandParams);
1398
1424
  return {
1399
- uploadUrl: await (0, _aws_sdk_s3_request_presigner.getSignedUrl)(client, command, { expiresIn: expiration }),
1425
+ uploadUrl: await (0, _aws_sdk_s3_request_presigner.getSignedUrl)(client, command, {
1426
+ expiresIn: expiration,
1427
+ signableHeaders: /* @__PURE__ */ new Set(["content-type", "content-length"])
1428
+ }),
1400
1429
  path: key,
1401
1430
  method: "PUT",
1402
1431
  headers: { "Content-Type": mimeType },
@@ -1563,12 +1592,13 @@ function s3Storage(config) {
1563
1592
  * @param filename - Original filename from the client
1564
1593
  * @param mimeType - MIME type of the file
1565
1594
  * @param collection - Collection slug this upload belongs to
1595
+ * @param options - The file's exact size, and the URL's lifetime
1566
1596
  * @returns Client upload data with pre-signed URL
1567
1597
  */
1568
- async getClientUploadUrl(filename, mimeType, collection) {
1598
+ async getClientUploadUrl(filename, mimeType, collection, options) {
1569
1599
  const collectionConfig = config.collections[collection];
1570
1600
  const key = generateStorageKey(filename, typeof collectionConfig === "object" ? collectionConfig.prefix : void 0);
1571
- return adapter.getPresignedUploadUrl(key, mimeType);
1601
+ return adapter.getPresignedUploadUrl(key, mimeType, options?.expiresIn, { contentLength: options?.size });
1572
1602
  },
1573
1603
  /**
1574
1604
  * Generate a signed URL for private file downloads.