ag-common 0.0.870 → 0.0.871

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.
@@ -113,11 +113,16 @@ export declare function getPresignedPostURL({ bucket, key, maxMb, }: {
113
113
  * Generate a presigned PUT URL for direct browser upload.
114
114
  * Unlike getPresignedPostURL (which returns url + fields for multipart form),
115
115
  * this returns a single URL for a simple PUT request.
116
+ *
117
+ * If contentLength is provided, the upload MUST match that exact size
118
+ * or the request will be rejected (signature mismatch).
116
119
  */
117
- export declare function getPresignedPutUrl({ bucket, key, contentType, expiresIn, }: {
120
+ export declare function getPresignedPutUrl({ bucket, key, contentType, contentLength, expiresIn, }: {
118
121
  bucket: string;
119
122
  key: string;
120
123
  contentType: string;
124
+ /** Exact file size in bytes. If provided, upload must match this size. */
125
+ contentLength?: number;
121
126
  /** seconds until URL expires. default 600 (10 minutes) */
122
127
  expiresIn?: number;
123
128
  }): Promise<{
@@ -263,16 +263,17 @@ function getPresignedPostURL(_a) {
263
263
  * Generate a presigned PUT URL for direct browser upload.
264
264
  * Unlike getPresignedPostURL (which returns url + fields for multipart form),
265
265
  * this returns a single URL for a simple PUT request.
266
+ *
267
+ * If contentLength is provided, the upload MUST match that exact size
268
+ * or the request will be rejected (signature mismatch).
266
269
  */
267
270
  function getPresignedPutUrl(_a) {
268
- return __awaiter(this, arguments, void 0, function* ({ bucket, key, contentType, expiresIn = 600, }) {
271
+ return __awaiter(this, arguments, void 0, function* ({ bucket, key, contentType, contentLength, expiresIn = 600, }) {
269
272
  try {
270
- const command = new client_s3_1.PutObjectCommand({
271
- Bucket: bucket,
272
- Key: key,
273
- ContentType: contentType,
274
- });
275
- const url = yield (0, s3_request_presigner_1.getSignedUrl)(s3, command, { expiresIn });
273
+ const command = new client_s3_1.PutObjectCommand(Object.assign({ Bucket: bucket, Key: key, ContentType: contentType }, (contentLength !== undefined && { ContentLength: contentLength })));
274
+ const url = yield (0, s3_request_presigner_1.getSignedUrl)(s3, command, Object.assign({ expiresIn }, (contentLength !== undefined && {
275
+ signableHeaders: new Set(['content-length']),
276
+ })));
276
277
  return { data: url };
277
278
  }
278
279
  catch (e) {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.870",
2
+ "version": "0.0.871",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",