prime-sdk 3.0.9-beta.0 → 3.1.0
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 +10 -0
- package/dist/external/aws/kms/kms.service.d.ts +2 -2
- package/dist/external/aws/s3/s3.service.d.ts +2 -0
- package/dist/external/aws/s3/s3.service.js +50 -0
- package/dist/external/aws/s3/s3.service.js.map +1 -1
- package/dist/external/aws/ses/ses.service.d.ts +2 -2
- package/dist/external/aws/sns/sns.service.d.ts +2 -2
- package/dist/external/aws/sqs/sqs.service.d.ts +1 -1
- package/dist/external/redis/interfaces/redis.interface.d.ts +0 -1
- package/dist/external/redis/redis.service.d.ts +0 -1
- package/dist/lib/cache/cache.d.ts +2 -3
- package/dist/lib/cache/interfaces/cache.interface.d.ts +1 -2
- package/dist/lib/crypto/crypto.module.d.ts +1 -1
- package/dist/lib/crypto/types/crypto.type.d.ts +0 -1
- package/dist/lib/documents/types/bedrock.type.d.ts +0 -1
- package/dist/lib/email/email.module.d.ts +1 -1
- package/dist/lib/entraID/utils/crypto.utils.d.ts +0 -1
- package/dist/lib/storage/interfaces/storage.interface.d.ts +1 -0
- package/dist/lib/storage/interfaces/storage.interface.js.map +1 -1
- package/dist/lib/storage/storage.d.ts +1 -1
- package/dist/lib/storage/storage.js +3 -0
- package/dist/lib/storage/storage.js.map +1 -1
- package/dist/lib/storage/types/storage.type.d.ts +1 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/external/aws/s3/s3.service.ts +70 -0
- package/src/lib/storage/interfaces/storage.interface.ts +1 -0
- package/src/lib/storage/storage.ts +4 -0
- package/src/lib/storage/types/storage.type.ts +1 -0
- package/.yarn/install-state.gz +0 -0
- package/.yarnrc.yml +0 -1
package/package.json
CHANGED
|
@@ -24,6 +24,9 @@ import {
|
|
|
24
24
|
ListFiles,
|
|
25
25
|
UploadFile,
|
|
26
26
|
} from '../../../lib/storage/types/storage.type';
|
|
27
|
+
import { Readable } from 'stream';
|
|
28
|
+
|
|
29
|
+
const PRESIGNED_PUT_EXPIRES_IN_SECONDS = 3600;
|
|
27
30
|
|
|
28
31
|
@Injectable()
|
|
29
32
|
export class S3 implements IStorage {
|
|
@@ -34,6 +37,7 @@ export class S3 implements IStorage {
|
|
|
34
37
|
Bucket: file.bucket,
|
|
35
38
|
Key: `${file.path}/${file.nameFile}`,
|
|
36
39
|
Body: file.file,
|
|
40
|
+
...(file.contentType && { ContentType: file.contentType }),
|
|
37
41
|
...(file.metadata && { Metadata: file.metadata }),
|
|
38
42
|
...(file.tagging && {
|
|
39
43
|
Tagging: file.tagging,
|
|
@@ -45,6 +49,72 @@ export class S3 implements IStorage {
|
|
|
45
49
|
return response;
|
|
46
50
|
}
|
|
47
51
|
|
|
52
|
+
async uploadFileViaPresignedUrl(file: UploadFile): Promise<void> {
|
|
53
|
+
const key = `${file.path}/${file.nameFile}`;
|
|
54
|
+
const contentType = file.contentType || 'application/octet-stream';
|
|
55
|
+
const body = await this.resolveFileBody(file.file);
|
|
56
|
+
|
|
57
|
+
const command = new PutObjectCommand({
|
|
58
|
+
Bucket: file.bucket,
|
|
59
|
+
Key: key,
|
|
60
|
+
ContentType: contentType,
|
|
61
|
+
...(file.metadata && { Metadata: file.metadata }),
|
|
62
|
+
...(file.tagging && { Tagging: file.tagging }),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const presignedUrl = await getSignedUrl(this.client, command, {
|
|
66
|
+
expiresIn: PRESIGNED_PUT_EXPIRES_IN_SECONDS,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const headers: Record<string, string> = {
|
|
70
|
+
'Content-Type': contentType,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
if (file.metadata) {
|
|
74
|
+
for (const [k, v] of Object.entries(file.metadata)) {
|
|
75
|
+
headers[`x-amz-meta-${k}`] = v;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (file.tagging) {
|
|
80
|
+
headers['x-amz-tagging'] = file.tagging;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const response = await fetch(presignedUrl, {
|
|
84
|
+
method: 'PUT',
|
|
85
|
+
headers,
|
|
86
|
+
body: new Uint8Array(body),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
if (!response.ok) {
|
|
90
|
+
throw new Error(
|
|
91
|
+
`s3_presigned_upload_failed: ${response.status} ${response.statusText}`,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private async resolveFileBody(
|
|
97
|
+
file: string | Readable | Buffer,
|
|
98
|
+
): Promise<Buffer> {
|
|
99
|
+
if (Buffer.isBuffer(file)) {
|
|
100
|
+
return file;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (typeof file === 'string') {
|
|
104
|
+
return Buffer.from(file);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const chunks: Buffer[] = [];
|
|
108
|
+
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
file.on('data', (chunk) =>
|
|
111
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)),
|
|
112
|
+
);
|
|
113
|
+
file.on('end', () => resolve(Buffer.concat(chunks)));
|
|
114
|
+
file.on('error', reject);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
48
118
|
async generateSignUrlFile(file: GetFile): Promise<string> {
|
|
49
119
|
const params = {
|
|
50
120
|
Bucket: file.bucket,
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
|
|
18
18
|
export interface IStorage {
|
|
19
19
|
uploadFile(file: UploadFile): Promise<PutObjectCommandOutput>;
|
|
20
|
+
uploadFileViaPresignedUrl(file: UploadFile): Promise<void>;
|
|
20
21
|
generateSignUrlFile(file: GetFile): Promise<string>;
|
|
21
22
|
getFile(file: GetFile): Promise<GetObjectCommandOutput>;
|
|
22
23
|
listFiles(data: ListFiles): Promise<ListObjectsV2CommandOutput>;
|
|
@@ -26,6 +26,10 @@ export class Storage {
|
|
|
26
26
|
return this.storage.uploadFile(file);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
async uploadFileViaPresignedUrl(file: UploadFile): Promise<void> {
|
|
30
|
+
return this.storage.uploadFileViaPresignedUrl(file);
|
|
31
|
+
}
|
|
32
|
+
|
|
29
33
|
async generateSignUrlFile(file: GetFile): Promise<string> {
|
|
30
34
|
return this.storage.generateSignUrlFile(file);
|
|
31
35
|
}
|
package/.yarn/install-state.gz
DELETED
|
Binary file
|
package/.yarnrc.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
nodeLinker: node-modules
|