vintasend-aws-s3-attachments 0.4.3 → 0.4.7
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws-s3-attachment-manager.d.ts","sourceRoot":"","sources":["../src/aws-s3-attachment-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oEAAoE,CAAC;AAC3G,OAAO,KAAK,EACX,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,MAAM,iCAAiC,CAAC;AAWzC,MAAM,WAAW,yBAAyB;IACzC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,WAAW,CAAC,EAAE;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;KACxB,CAAC;IAEF;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,mBAAoB,SAAQ,qBAAqB;IAC7D,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAS;gBAEd,MAAM,EAAE,yBAAyB;IAc7C;;;;;;;OAOG;IACG,UAAU,CACf,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,oBAAoB,CAAC;IA6ChC;;;;;;;;OAQG;IACH,yBAAyB,CACxB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACtC,cAAc;IAcjB;;;;;;;;;;OAUG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM/C;;;;;;;OAOG;IACG,sBAAsB,CAC3B,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACtC,OAAO,CAAC,IAAI,CAAC;IAehB;;;;;;OAMG;IACH,OAAO,CAAC,UAAU;CAMlB"}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
7
|
-
const node_stream_1 = require("node:stream");
|
|
8
|
-
const node_crypto_1 = require("node:crypto");
|
|
1
|
+
import { BaseAttachmentManager } from 'vintasend/dist/services/attachment-manager/base-attachment-manager';
|
|
2
|
+
import { S3Client, PutObjectCommand, GetObjectCommand, DeleteObjectCommand, } from '@aws-sdk/client-s3';
|
|
3
|
+
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
4
|
+
import { Readable } from 'node:stream';
|
|
5
|
+
import { randomUUID } from 'node:crypto';
|
|
9
6
|
/**
|
|
10
7
|
* AWS S3 AttachmentManager implementation for VintaSend.
|
|
11
8
|
*
|
|
@@ -18,12 +15,12 @@ const node_crypto_1 = require("node:crypto");
|
|
|
18
15
|
* is stored by the Backend in its database. The Backend calls this manager's
|
|
19
16
|
* uploadFile() method and stores the returned metadata.
|
|
20
17
|
*/
|
|
21
|
-
class S3AttachmentManager extends
|
|
18
|
+
export class S3AttachmentManager extends BaseAttachmentManager {
|
|
22
19
|
constructor(config) {
|
|
23
20
|
super();
|
|
24
21
|
this.bucket = config.bucket;
|
|
25
22
|
this.keyPrefix = config.keyPrefix || '';
|
|
26
|
-
this.s3Client = new
|
|
23
|
+
this.s3Client = new S3Client({
|
|
27
24
|
region: config.region,
|
|
28
25
|
credentials: config.credentials,
|
|
29
26
|
endpoint: config.endpoint,
|
|
@@ -46,10 +43,10 @@ class S3AttachmentManager extends base_attachment_manager_1.BaseAttachmentManage
|
|
|
46
43
|
// Detect content type if not provided
|
|
47
44
|
const finalContentType = contentType || this.detectContentType(filename);
|
|
48
45
|
// Generate unique S3 key
|
|
49
|
-
const fileId =
|
|
46
|
+
const fileId = randomUUID();
|
|
50
47
|
const key = this.buildS3Key(fileId, filename);
|
|
51
48
|
// Upload to S3
|
|
52
|
-
const putCommand = new
|
|
49
|
+
const putCommand = new PutObjectCommand({
|
|
53
50
|
Bucket: this.bucket,
|
|
54
51
|
Key: key,
|
|
55
52
|
Body: buffer,
|
|
@@ -117,7 +114,7 @@ class S3AttachmentManager extends base_attachment_manager_1.BaseAttachmentManage
|
|
|
117
114
|
if (!storageMetadata.key) {
|
|
118
115
|
throw new Error('Storage metadata must contain key for S3 file deletion');
|
|
119
116
|
}
|
|
120
|
-
const deleteCommand = new
|
|
117
|
+
const deleteCommand = new DeleteObjectCommand({
|
|
121
118
|
Bucket: this.bucket,
|
|
122
119
|
Key: storageMetadata.key,
|
|
123
120
|
});
|
|
@@ -137,7 +134,6 @@ class S3AttachmentManager extends base_attachment_manager_1.BaseAttachmentManage
|
|
|
137
134
|
return `${this.keyPrefix}${fileId}/${sanitizedFilename}`;
|
|
138
135
|
}
|
|
139
136
|
}
|
|
140
|
-
exports.S3AttachmentManager = S3AttachmentManager;
|
|
141
137
|
/**
|
|
142
138
|
* S3 AttachmentFile implementation.
|
|
143
139
|
*
|
|
@@ -158,7 +154,7 @@ class S3AttachmentFile {
|
|
|
158
154
|
* Use this for small files. For large files, prefer streaming.
|
|
159
155
|
*/
|
|
160
156
|
async read() {
|
|
161
|
-
const getCommand = new
|
|
157
|
+
const getCommand = new GetObjectCommand({
|
|
162
158
|
Bucket: this.bucket,
|
|
163
159
|
Key: this.key,
|
|
164
160
|
});
|
|
@@ -175,7 +171,7 @@ class S3AttachmentFile {
|
|
|
175
171
|
* Use this for large files to avoid loading everything into memory.
|
|
176
172
|
*/
|
|
177
173
|
async stream() {
|
|
178
|
-
const getCommand = new
|
|
174
|
+
const getCommand = new GetObjectCommand({
|
|
179
175
|
Bucket: this.bucket,
|
|
180
176
|
Key: this.key,
|
|
181
177
|
});
|
|
@@ -185,7 +181,7 @@ class S3AttachmentFile {
|
|
|
185
181
|
}
|
|
186
182
|
// Convert Node.js Readable to Web ReadableStream
|
|
187
183
|
const nodeStream = response.Body;
|
|
188
|
-
return
|
|
184
|
+
return Readable.toWeb(nodeStream);
|
|
189
185
|
}
|
|
190
186
|
/**
|
|
191
187
|
* Generate a presigned URL for accessing the file.
|
|
@@ -194,11 +190,11 @@ class S3AttachmentFile {
|
|
|
194
190
|
* @returns A presigned URL for secure file access
|
|
195
191
|
*/
|
|
196
192
|
async url(expiresIn = 3600) {
|
|
197
|
-
const getCommand = new
|
|
193
|
+
const getCommand = new GetObjectCommand({
|
|
198
194
|
Bucket: this.bucket,
|
|
199
195
|
Key: this.key,
|
|
200
196
|
});
|
|
201
|
-
return
|
|
197
|
+
return getSignedUrl(this.s3Client, getCommand, { expiresIn });
|
|
202
198
|
}
|
|
203
199
|
/**
|
|
204
200
|
* Delete this file from S3.
|
|
@@ -206,7 +202,7 @@ class S3AttachmentFile {
|
|
|
206
202
|
* Note: This is typically called by the AttachmentManager, not directly.
|
|
207
203
|
*/
|
|
208
204
|
async delete() {
|
|
209
|
-
const deleteCommand = new
|
|
205
|
+
const deleteCommand = new DeleteObjectCommand({
|
|
210
206
|
Bucket: this.bucket,
|
|
211
207
|
Key: this.key,
|
|
212
208
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,mBAAmB,EACnB,KAAK,yBAAyB,GAC9B,MAAM,6BAA6B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.S3AttachmentManager = void 0;
|
|
4
|
-
var aws_s3_attachment_manager_1 = require("./aws-s3-attachment-manager");
|
|
5
|
-
Object.defineProperty(exports, "S3AttachmentManager", { enumerable: true, get: function () { return aws_s3_attachment_manager_1.S3AttachmentManager; } });
|
|
1
|
+
export { S3AttachmentManager, } from './aws-s3-attachment-manager';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vintasend-aws-s3-attachments",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.7",
|
|
4
4
|
"description": "Implementation of AWS S3 Attachments for VintaSend",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
"author": "Hugo Bessa",
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@aws-sdk/client-s3": "^3.
|
|
20
|
-
"@aws-sdk/s3-request-presigner": "^3.
|
|
21
|
-
"vintasend": "^0.4.
|
|
19
|
+
"@aws-sdk/client-s3": "^3.981.0",
|
|
20
|
+
"@aws-sdk/s3-request-presigner": "^3.981.0",
|
|
21
|
+
"vintasend": "^0.4.7"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@types/jest": "^
|
|
25
|
-
"jest": "^
|
|
26
|
-
"ts-jest": "^29.
|
|
27
|
-
"typescript": "^5.
|
|
24
|
+
"@types/jest": "^30.0.0",
|
|
25
|
+
"jest": "^30.2.0",
|
|
26
|
+
"ts-jest": "^29.4.6",
|
|
27
|
+
"typescript": "^5.9.3"
|
|
28
28
|
}
|
|
29
29
|
}
|