@nextlyhq/storage-s3 0.0.2-alpha.76 → 0.0.2-alpha.78
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 +2 -0
- package/dist/index.cjs +25 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -6
- package/dist/index.d.ts +30 -6
- package/dist/index.mjs +25 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
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-
|
|
5
|
+
// ../nextly/dist/nextly-error-CrvLpVnW.mjs
|
|
6
6
|
function isDbError(err) {
|
|
7
7
|
if (!err || typeof err !== "object") return false;
|
|
8
8
|
const obj = err;
|
|
@@ -116,6 +116,8 @@ 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,
|
|
@@ -177,7 +179,7 @@ const NEXTLY_ERROR_STATUS = {
|
|
|
177
179
|
NEXTLY_PER_LANGUAGE_STORAGE_CHANGED: 500,
|
|
178
180
|
NEXTLY_PER_LANGUAGE_STORAGE_MIXED: 500,
|
|
179
181
|
NEXTLY_PER_LANGUAGE_STORAGE_LANGUAGES_UNDECLARED: 500,
|
|
180
|
-
|
|
182
|
+
NEXTLY_POSTGRES_SCHEMA_MOVED: 500
|
|
181
183
|
};
|
|
182
184
|
({ ...Object.fromEntries([
|
|
183
185
|
"VALIDATION_ERROR",
|
|
@@ -876,7 +878,7 @@ var NextlyError = class NextlyError extends Error {
|
|
|
876
878
|
return NextlyError.isCode(err, "RATE_LIMITED");
|
|
877
879
|
}
|
|
878
880
|
};
|
|
879
|
-
// ../nextly/dist/validate-external-url-
|
|
881
|
+
// ../nextly/dist/validate-external-url-CukX0PbC.mjs
|
|
880
882
|
/** Default response body cap: reject anything larger before buffering it all. */
|
|
881
883
|
/**
|
|
882
884
|
* How many bytes a bounded external read may buffer, absent a caller's own cap.
|
|
@@ -1394,24 +1396,36 @@ var S3StorageAdapter = class {
|
|
|
1394
1396
|
* Creates a pre-signed PutObject URL that allows direct uploads from
|
|
1395
1397
|
* the browser to S3, bypassing server-side upload limits (e.g., Vercel's 4.5MB).
|
|
1396
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
|
+
*
|
|
1397
1404
|
* @param key - Storage path/key for the upload
|
|
1398
1405
|
* @param mimeType - MIME type of the file being uploaded
|
|
1399
|
-
* @param expiresIn - URL validity
|
|
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
|
|
1400
1409
|
* @returns Client upload data with URL, method, and headers
|
|
1401
1410
|
*/
|
|
1402
|
-
async getPresignedUploadUrl(key, mimeType, expiresIn) {
|
|
1411
|
+
async getPresignedUploadUrl(key, mimeType, expiresIn, options) {
|
|
1403
1412
|
const client = this.ensureClient();
|
|
1404
|
-
const
|
|
1413
|
+
const longest = this.resolvedConfig.signedUrlExpiresIn;
|
|
1414
|
+
const expiration = Math.min(expiresIn ?? longest, longest);
|
|
1405
1415
|
const commandParams = {
|
|
1406
1416
|
Bucket: this.resolvedConfig.bucket,
|
|
1407
1417
|
Key: key,
|
|
1408
1418
|
ContentType: mimeType,
|
|
1409
|
-
CacheControl: this.resolvedConfig.cacheControl
|
|
1419
|
+
CacheControl: this.resolvedConfig.cacheControl,
|
|
1420
|
+
...options?.contentLength !== void 0 ? { ContentLength: options.contentLength } : {}
|
|
1410
1421
|
};
|
|
1411
1422
|
if (!this.isR2) commandParams.ACL = this.resolvedConfig.acl;
|
|
1412
1423
|
const command = new _aws_sdk_client_s3.PutObjectCommand(commandParams);
|
|
1413
1424
|
return {
|
|
1414
|
-
uploadUrl: await (0, _aws_sdk_s3_request_presigner.getSignedUrl)(client, command, {
|
|
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
|
+
}),
|
|
1415
1429
|
path: key,
|
|
1416
1430
|
method: "PUT",
|
|
1417
1431
|
headers: { "Content-Type": mimeType },
|
|
@@ -1578,12 +1592,13 @@ function s3Storage(config) {
|
|
|
1578
1592
|
* @param filename - Original filename from the client
|
|
1579
1593
|
* @param mimeType - MIME type of the file
|
|
1580
1594
|
* @param collection - Collection slug this upload belongs to
|
|
1595
|
+
* @param options - The file's exact size, and the URL's lifetime
|
|
1581
1596
|
* @returns Client upload data with pre-signed URL
|
|
1582
1597
|
*/
|
|
1583
|
-
async getClientUploadUrl(filename, mimeType, collection) {
|
|
1598
|
+
async getClientUploadUrl(filename, mimeType, collection, options) {
|
|
1584
1599
|
const collectionConfig = config.collections[collection];
|
|
1585
1600
|
const key = generateStorageKey(filename, typeof collectionConfig === "object" ? collectionConfig.prefix : void 0);
|
|
1586
|
-
return adapter.getPresignedUploadUrl(key, mimeType);
|
|
1601
|
+
return adapter.getPresignedUploadUrl(key, mimeType, options?.expiresIn, { contentLength: options?.size });
|
|
1587
1602
|
},
|
|
1588
1603
|
/**
|
|
1589
1604
|
* Generate a signed URL for private file downloads.
|