vls-s3 1.0.0 → 1.2.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/SECURITY.MD ADDED
@@ -0,0 +1,7 @@
1
+ # Security Policy
2
+
3
+ ## Reporting a Vulnerability
4
+
5
+ To securely report a vulnerability, please [Contact us!](mailto:security@useinsider.com?subject=[GitHub]_Vulnerability!).
6
+
7
+ <!-- E26CADE3-DF7C-4FF8-A30A-4DD2F28E06BF -->
@@ -0,0 +1,16 @@
1
+ import { PutObjectCommandInput, GetObjectCommandInput, PutObjectCommandOutput } from '@aws-sdk/client-s3';
2
+ export declare class LambdaS3Client {
3
+ private client;
4
+ private readonly config;
5
+ constructor(config: Config);
6
+ private getClient;
7
+ uploadFile(payload: Omit<PutObjectCommandInput, 'Bucket'>): Promise<PutObjectCommandOutput>;
8
+ getSignedURL(payload: Omit<GetObjectCommandInput, 'Bucket'>, expiresIn?: number): Promise<string>;
9
+ }
10
+ type Config = {
11
+ bucketName: string;
12
+ region?: string;
13
+ accessKey?: string;
14
+ accessKeyID?: string;
15
+ };
16
+ export {};
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LambdaS3Client = void 0;
4
+ const client_s3_1 = require("@aws-sdk/client-s3");
5
+ const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
6
+ class LambdaS3Client {
7
+ constructor(config) {
8
+ this.client = null;
9
+ this.config = config;
10
+ }
11
+ getClient() {
12
+ if (!this.client) {
13
+ this.client = new client_s3_1.S3Client({
14
+ region: this.config.region ?? process.env.REGION,
15
+ ...(this.config.accessKeyID && this.config.accessKey
16
+ ? {
17
+ credentials: {
18
+ accessKeyId: this.config.accessKeyID,
19
+ secretAccessKey: this.config.accessKey
20
+ }
21
+ }
22
+ : {})
23
+ });
24
+ }
25
+ return this.client;
26
+ }
27
+ async uploadFile(payload) {
28
+ const client = this.getClient();
29
+ return await client.send(new client_s3_1.PutObjectCommand({
30
+ Bucket: this.config.bucketName,
31
+ ...payload
32
+ }));
33
+ }
34
+ async getSignedURL(payload, expiresIn = 3 * 24 * 60 * 60) {
35
+ const client = this.getClient();
36
+ return await (0, s3_request_presigner_1.getSignedUrl)(client, new client_s3_1.GetObjectCommand({
37
+ Bucket: this.config.bucketName,
38
+ ...payload
39
+ }), {
40
+ expiresIn
41
+ });
42
+ }
43
+ }
44
+ exports.LambdaS3Client = LambdaS3Client;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "vls-s3",
3
- "version": "1.0.0",
4
- "main": "dist/s3.js",
5
- "types": "dist/s3.d.ts",
3
+ "version": "1.2.0",
4
+ "main": "dist/lambda-s3-client.js",
5
+ "types": "dist/lambda-s3-client.d.ts",
6
6
  "scripts": {
7
7
  "check-format": "prettier . --check",
8
8
  "fix-format": "prettier . --write",
@@ -0,0 +1,72 @@
1
+ import {
2
+ GetObjectCommand,
3
+ PutObjectCommand,
4
+ PutObjectCommandInput,
5
+ S3Client,
6
+ GetObjectCommandInput,
7
+ PutObjectCommandOutput
8
+ } from '@aws-sdk/client-s3';
9
+ import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
10
+
11
+ export class LambdaS3Client {
12
+ private client: S3Client | null = null;
13
+ private readonly config: Config;
14
+
15
+ constructor(config: Config) {
16
+ this.config = config;
17
+ }
18
+
19
+ private getClient(): S3Client {
20
+ if (!this.client) {
21
+ this.client = new S3Client({
22
+ region: this.config.region ?? process.env.REGION,
23
+ ...(this.config.accessKeyID && this.config.accessKey
24
+ ? {
25
+ credentials: {
26
+ accessKeyId: this.config.accessKeyID,
27
+ secretAccessKey: this.config.accessKey
28
+ }
29
+ }
30
+ : {})
31
+ });
32
+ }
33
+
34
+ return this.client;
35
+ }
36
+
37
+ async uploadFile(payload: Omit<PutObjectCommandInput, 'Bucket'>): Promise<PutObjectCommandOutput> {
38
+ const client = this.getClient();
39
+
40
+ return await client.send(
41
+ new PutObjectCommand({
42
+ Bucket: this.config.bucketName,
43
+ ...payload
44
+ })
45
+ );
46
+ }
47
+
48
+ async getSignedURL(
49
+ payload: Omit<GetObjectCommandInput, 'Bucket'>,
50
+ expiresIn: number = 3 * 24 * 60 * 60
51
+ ): Promise<string> {
52
+ const client = this.getClient();
53
+
54
+ return await getSignedUrl(
55
+ client,
56
+ new GetObjectCommand({
57
+ Bucket: this.config.bucketName,
58
+ ...payload
59
+ }),
60
+ {
61
+ expiresIn
62
+ }
63
+ );
64
+ }
65
+ }
66
+
67
+ type Config = {
68
+ bucketName: string;
69
+ region?: string;
70
+ accessKey?: string;
71
+ accessKeyID?: string;
72
+ };
package/dist/s3.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { PutObjectCommandInput, GetObjectCommandInput } from '@aws-sdk/client-s3';
2
- export declare class S3Client {
3
- private readonly bucketName;
4
- constructor(bucketName: string);
5
- uploadFile(payload: Omit<PutObjectCommandInput, 'Bucket'>): Promise<void>;
6
- getSignedURL(payload: Omit<GetObjectCommandInput, 'Bucket'>, expiresIn?: number): Promise<string>;
7
- }
package/dist/s3.js DELETED
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.S3Client = void 0;
4
- const client_s3_1 = require("@aws-sdk/client-s3");
5
- const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
6
- const awsS3Client = new client_s3_1.S3Client({ region: process.env.REGION });
7
- class S3Client {
8
- constructor(bucketName) {
9
- this.bucketName = bucketName;
10
- }
11
- async uploadFile(payload) {
12
- await awsS3Client.send(new client_s3_1.PutObjectCommand({
13
- Bucket: this.bucketName,
14
- ...payload
15
- }));
16
- }
17
- async getSignedURL(payload, expiresIn = 3 * 24 * 60 * 60) {
18
- return await (0, s3_request_presigner_1.getSignedUrl)(awsS3Client, new client_s3_1.GetObjectCommand({
19
- Bucket: this.bucketName,
20
- ...payload
21
- }), {
22
- expiresIn
23
- });
24
- }
25
- }
26
- exports.S3Client = S3Client;
package/src/s3.ts DELETED
@@ -1,43 +0,0 @@
1
- import {
2
- GetObjectCommand,
3
- PutObjectCommand,
4
- PutObjectCommandInput,
5
- S3Client as AWSS3Client,
6
- GetObjectCommandInput
7
- } from '@aws-sdk/client-s3';
8
- import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
9
-
10
- const awsS3Client = new AWSS3Client({ region: process.env.REGION });
11
-
12
- export class S3Client {
13
- private readonly bucketName: string;
14
-
15
- constructor(bucketName: string) {
16
- this.bucketName = bucketName;
17
- }
18
-
19
- async uploadFile(payload: Omit<PutObjectCommandInput, 'Bucket'>): Promise<void> {
20
- await awsS3Client.send(
21
- new PutObjectCommand({
22
- Bucket: this.bucketName,
23
- ...payload
24
- })
25
- );
26
- }
27
-
28
- async getSignedURL(
29
- payload: Omit<GetObjectCommandInput, 'Bucket'>,
30
- expiresIn: number = 3 * 24 * 60 * 60
31
- ): Promise<string> {
32
- return await getSignedUrl(
33
- awsS3Client,
34
- new GetObjectCommand({
35
- Bucket: this.bucketName,
36
- ...payload
37
- }),
38
- {
39
- expiresIn
40
- }
41
- );
42
- }
43
- }