@nextlyhq/storage-s3 0.0.2-alpha.76 → 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 +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/dist/index.d.cts
CHANGED
|
@@ -168,15 +168,25 @@ interface StoragePlugin {
|
|
|
168
168
|
adapter: IStorageAdapter;
|
|
169
169
|
/**
|
|
170
170
|
* Handler for generating client-side upload URLs.
|
|
171
|
-
* Called when clientUploads is enabled for a collection
|
|
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.
|
|
172
175
|
*/
|
|
173
|
-
getClientUploadUrl?: (filename: string, mimeType: string, collection: string) => Promise<ClientUploadData>;
|
|
176
|
+
getClientUploadUrl?: (filename: string, mimeType: string, collection: string, options: ClientUploadOptions) => Promise<ClientUploadData>;
|
|
174
177
|
/**
|
|
175
178
|
* Handler for generating signed download URLs.
|
|
176
179
|
* Called when signedDownloads is enabled for a collection.
|
|
177
180
|
*/
|
|
178
181
|
getSignedDownloadUrl?: (path: string, expiresIn?: number) => Promise<string>;
|
|
179
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;
|
|
189
|
+
}
|
|
180
190
|
/**
|
|
181
191
|
* Data returned for client-side (direct) uploads.
|
|
182
192
|
* Contains pre-signed URL and headers for direct-to-storage uploads.
|
|
@@ -269,8 +279,13 @@ interface IStorageAdapter {
|
|
|
269
279
|
getMetadata?(filePath: string): Promise<FileMetadata | null>;
|
|
270
280
|
/** Generate signed URL for temporary private access (optional) */
|
|
271
281
|
getSignedUrl?(filePath: string, expiresIn?: number): Promise<string>;
|
|
272
|
-
/**
|
|
273
|
-
|
|
282
|
+
/**
|
|
283
|
+
* Generate pre-signed upload URL for client-side uploads (optional). With
|
|
284
|
+
* `options.contentLength`, the signature binds the body's exact length.
|
|
285
|
+
*/
|
|
286
|
+
getPresignedUploadUrl?(key: string, mimeType: string, expiresIn?: number, options?: {
|
|
287
|
+
contentLength?: number;
|
|
288
|
+
}): Promise<ClientUploadData>;
|
|
274
289
|
/**
|
|
275
290
|
* Every file the storage holds, a page at a time (optional). Used to find
|
|
276
291
|
* files no record refers to; a storage without it cannot be searched for
|
|
@@ -726,12 +741,21 @@ export declare class S3StorageAdapter implements IStorageAdapter {
|
|
|
726
741
|
* Creates a pre-signed PutObject URL that allows direct uploads from
|
|
727
742
|
* the browser to S3, bypassing server-side upload limits (e.g., Vercel's 4.5MB).
|
|
728
743
|
*
|
|
744
|
+
* The signature covers the `Content-Type` and, given `options.contentLength`,
|
|
745
|
+
* the `Content-Length`: the bytes never pass Nextly's upload checks, so S3
|
|
746
|
+
* itself refuses a body of another type or length. The browser sets the
|
|
747
|
+
* length from the body; it is not a header the client sends.
|
|
748
|
+
*
|
|
729
749
|
* @param key - Storage path/key for the upload
|
|
730
750
|
* @param mimeType - MIME type of the file being uploaded
|
|
731
|
-
* @param expiresIn - URL validity
|
|
751
|
+
* @param expiresIn - URL validity in seconds, at most the configured
|
|
752
|
+
* `signedUrlExpiresIn` (its default)
|
|
753
|
+
* @param options - `contentLength`: the exact size the upload may have
|
|
732
754
|
* @returns Client upload data with URL, method, and headers
|
|
733
755
|
*/
|
|
734
|
-
getPresignedUploadUrl(key: string, mimeType: string, expiresIn?: number
|
|
756
|
+
getPresignedUploadUrl(key: string, mimeType: string, expiresIn?: number, options?: {
|
|
757
|
+
contentLength?: number;
|
|
758
|
+
}): Promise<ClientUploadData>;
|
|
735
759
|
/**
|
|
736
760
|
* Generate a unique storage key with date-based prefix.
|
|
737
761
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -168,15 +168,25 @@ interface StoragePlugin {
|
|
|
168
168
|
adapter: IStorageAdapter;
|
|
169
169
|
/**
|
|
170
170
|
* Handler for generating client-side upload URLs.
|
|
171
|
-
* Called when clientUploads is enabled for a collection
|
|
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.
|
|
172
175
|
*/
|
|
173
|
-
getClientUploadUrl?: (filename: string, mimeType: string, collection: string) => Promise<ClientUploadData>;
|
|
176
|
+
getClientUploadUrl?: (filename: string, mimeType: string, collection: string, options: ClientUploadOptions) => Promise<ClientUploadData>;
|
|
174
177
|
/**
|
|
175
178
|
* Handler for generating signed download URLs.
|
|
176
179
|
* Called when signedDownloads is enabled for a collection.
|
|
177
180
|
*/
|
|
178
181
|
getSignedDownloadUrl?: (path: string, expiresIn?: number) => Promise<string>;
|
|
179
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;
|
|
189
|
+
}
|
|
180
190
|
/**
|
|
181
191
|
* Data returned for client-side (direct) uploads.
|
|
182
192
|
* Contains pre-signed URL and headers for direct-to-storage uploads.
|
|
@@ -269,8 +279,13 @@ interface IStorageAdapter {
|
|
|
269
279
|
getMetadata?(filePath: string): Promise<FileMetadata | null>;
|
|
270
280
|
/** Generate signed URL for temporary private access (optional) */
|
|
271
281
|
getSignedUrl?(filePath: string, expiresIn?: number): Promise<string>;
|
|
272
|
-
/**
|
|
273
|
-
|
|
282
|
+
/**
|
|
283
|
+
* Generate pre-signed upload URL for client-side uploads (optional). With
|
|
284
|
+
* `options.contentLength`, the signature binds the body's exact length.
|
|
285
|
+
*/
|
|
286
|
+
getPresignedUploadUrl?(key: string, mimeType: string, expiresIn?: number, options?: {
|
|
287
|
+
contentLength?: number;
|
|
288
|
+
}): Promise<ClientUploadData>;
|
|
274
289
|
/**
|
|
275
290
|
* Every file the storage holds, a page at a time (optional). Used to find
|
|
276
291
|
* files no record refers to; a storage without it cannot be searched for
|
|
@@ -726,12 +741,21 @@ export declare class S3StorageAdapter implements IStorageAdapter {
|
|
|
726
741
|
* Creates a pre-signed PutObject URL that allows direct uploads from
|
|
727
742
|
* the browser to S3, bypassing server-side upload limits (e.g., Vercel's 4.5MB).
|
|
728
743
|
*
|
|
744
|
+
* The signature covers the `Content-Type` and, given `options.contentLength`,
|
|
745
|
+
* the `Content-Length`: the bytes never pass Nextly's upload checks, so S3
|
|
746
|
+
* itself refuses a body of another type or length. The browser sets the
|
|
747
|
+
* length from the body; it is not a header the client sends.
|
|
748
|
+
*
|
|
729
749
|
* @param key - Storage path/key for the upload
|
|
730
750
|
* @param mimeType - MIME type of the file being uploaded
|
|
731
|
-
* @param expiresIn - URL validity
|
|
751
|
+
* @param expiresIn - URL validity in seconds, at most the configured
|
|
752
|
+
* `signedUrlExpiresIn` (its default)
|
|
753
|
+
* @param options - `contentLength`: the exact size the upload may have
|
|
732
754
|
* @returns Client upload data with URL, method, and headers
|
|
733
755
|
*/
|
|
734
|
-
getPresignedUploadUrl(key: string, mimeType: string, expiresIn?: number
|
|
756
|
+
getPresignedUploadUrl(key: string, mimeType: string, expiresIn?: number, options?: {
|
|
757
|
+
contentLength?: number;
|
|
758
|
+
}): Promise<ClientUploadData>;
|
|
735
759
|
/**
|
|
736
760
|
* Generate a unique storage key with date-based prefix.
|
|
737
761
|
*
|
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-
|
|
4
|
+
// ../nextly/dist/nextly-error-C_MDZmJc.mjs
|
|
5
5
|
function isDbError(err) {
|
|
6
6
|
if (!err || typeof err !== "object") return false;
|
|
7
7
|
const obj = err;
|
|
@@ -115,6 +115,8 @@ const NEXTLY_ERROR_STATUS = {
|
|
|
115
115
|
NEXTLY_UPGRADE_TABLE_NAME_COLLISION: 409,
|
|
116
116
|
NEXTLY_UPGRADE_IN_PROGRESS: 409,
|
|
117
117
|
NEXTLY_MIGRATE_LOCK_BUSY: 409,
|
|
118
|
+
NEXTLY_TABLE_BUSY: 409,
|
|
119
|
+
NEXTLY_LOCK_HELD_BY_THIS_PROCESS: 500,
|
|
118
120
|
NEXTLY_BASELINE_LOCK_NOT_HELD: 409,
|
|
119
121
|
NEXTLY_RESOLVE_LOCK_NOT_HELD: 409,
|
|
120
122
|
NEXTLY_BOOT_MIGRATIONS_NOT_RUN: 503,
|
|
@@ -176,7 +178,7 @@ const NEXTLY_ERROR_STATUS = {
|
|
|
176
178
|
NEXTLY_PER_LANGUAGE_STORAGE_CHANGED: 500,
|
|
177
179
|
NEXTLY_PER_LANGUAGE_STORAGE_MIXED: 500,
|
|
178
180
|
NEXTLY_PER_LANGUAGE_STORAGE_LANGUAGES_UNDECLARED: 500,
|
|
179
|
-
|
|
181
|
+
NEXTLY_POSTGRES_SCHEMA_MOVED: 500
|
|
180
182
|
};
|
|
181
183
|
({ ...Object.fromEntries([
|
|
182
184
|
"VALIDATION_ERROR",
|
|
@@ -875,7 +877,7 @@ var NextlyError = class NextlyError extends Error {
|
|
|
875
877
|
return NextlyError.isCode(err, "RATE_LIMITED");
|
|
876
878
|
}
|
|
877
879
|
};
|
|
878
|
-
// ../nextly/dist/validate-external-url-
|
|
880
|
+
// ../nextly/dist/validate-external-url-DF_HNT6F.mjs
|
|
879
881
|
/** Default response body cap: reject anything larger before buffering it all. */
|
|
880
882
|
/**
|
|
881
883
|
* How many bytes a bounded external read may buffer, absent a caller's own cap.
|
|
@@ -1393,24 +1395,36 @@ var S3StorageAdapter = class {
|
|
|
1393
1395
|
* Creates a pre-signed PutObject URL that allows direct uploads from
|
|
1394
1396
|
* the browser to S3, bypassing server-side upload limits (e.g., Vercel's 4.5MB).
|
|
1395
1397
|
*
|
|
1398
|
+
* The signature covers the `Content-Type` and, given `options.contentLength`,
|
|
1399
|
+
* the `Content-Length`: the bytes never pass Nextly's upload checks, so S3
|
|
1400
|
+
* itself refuses a body of another type or length. The browser sets the
|
|
1401
|
+
* length from the body; it is not a header the client sends.
|
|
1402
|
+
*
|
|
1396
1403
|
* @param key - Storage path/key for the upload
|
|
1397
1404
|
* @param mimeType - MIME type of the file being uploaded
|
|
1398
|
-
* @param expiresIn - URL validity
|
|
1405
|
+
* @param expiresIn - URL validity in seconds, at most the configured
|
|
1406
|
+
* `signedUrlExpiresIn` (its default)
|
|
1407
|
+
* @param options - `contentLength`: the exact size the upload may have
|
|
1399
1408
|
* @returns Client upload data with URL, method, and headers
|
|
1400
1409
|
*/
|
|
1401
|
-
async getPresignedUploadUrl(key, mimeType, expiresIn) {
|
|
1410
|
+
async getPresignedUploadUrl(key, mimeType, expiresIn, options) {
|
|
1402
1411
|
const client = this.ensureClient();
|
|
1403
|
-
const
|
|
1412
|
+
const longest = this.resolvedConfig.signedUrlExpiresIn;
|
|
1413
|
+
const expiration = Math.min(expiresIn ?? longest, longest);
|
|
1404
1414
|
const commandParams = {
|
|
1405
1415
|
Bucket: this.resolvedConfig.bucket,
|
|
1406
1416
|
Key: key,
|
|
1407
1417
|
ContentType: mimeType,
|
|
1408
|
-
CacheControl: this.resolvedConfig.cacheControl
|
|
1418
|
+
CacheControl: this.resolvedConfig.cacheControl,
|
|
1419
|
+
...options?.contentLength !== void 0 ? { ContentLength: options.contentLength } : {}
|
|
1409
1420
|
};
|
|
1410
1421
|
if (!this.isR2) commandParams.ACL = this.resolvedConfig.acl;
|
|
1411
1422
|
const command = new PutObjectCommand(commandParams);
|
|
1412
1423
|
return {
|
|
1413
|
-
uploadUrl: await getSignedUrl(client, command, {
|
|
1424
|
+
uploadUrl: await getSignedUrl(client, command, {
|
|
1425
|
+
expiresIn: expiration,
|
|
1426
|
+
signableHeaders: /* @__PURE__ */ new Set(["content-type", "content-length"])
|
|
1427
|
+
}),
|
|
1414
1428
|
path: key,
|
|
1415
1429
|
method: "PUT",
|
|
1416
1430
|
headers: { "Content-Type": mimeType },
|
|
@@ -1577,12 +1591,13 @@ function s3Storage(config) {
|
|
|
1577
1591
|
* @param filename - Original filename from the client
|
|
1578
1592
|
* @param mimeType - MIME type of the file
|
|
1579
1593
|
* @param collection - Collection slug this upload belongs to
|
|
1594
|
+
* @param options - The file's exact size, and the URL's lifetime
|
|
1580
1595
|
* @returns Client upload data with pre-signed URL
|
|
1581
1596
|
*/
|
|
1582
|
-
async getClientUploadUrl(filename, mimeType, collection) {
|
|
1597
|
+
async getClientUploadUrl(filename, mimeType, collection, options) {
|
|
1583
1598
|
const collectionConfig = config.collections[collection];
|
|
1584
1599
|
const key = generateStorageKey(filename, typeof collectionConfig === "object" ? collectionConfig.prefix : void 0);
|
|
1585
|
-
return adapter.getPresignedUploadUrl(key, mimeType);
|
|
1600
|
+
return adapter.getPresignedUploadUrl(key, mimeType, options?.expiresIn, { contentLength: options?.size });
|
|
1586
1601
|
},
|
|
1587
1602
|
/**
|
|
1588
1603
|
* Generate a signed URL for private file downloads.
|