idea-aws 4.0.13 → 4.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/dist/src/cognito.js +3 -2
- package/dist/src/comprehend.js +3 -2
- package/dist/src/dynamoDB.d.ts +2 -2
- package/dist/src/dynamoDB.js +2 -1
- package/dist/src/logger.d.ts +1 -1
- package/dist/src/logger.js +3 -2
- package/dist/src/metrics.d.ts +1 -1
- package/dist/src/metrics.js +3 -3
- package/dist/src/s3.d.ts +37 -6
- package/dist/src/s3.js +27 -14
- package/dist/src/ses.d.ts +2 -2
- package/dist/src/ses.js +2 -1
- package/dist/src/sns.d.ts +2 -2
- package/dist/src/sns.js +2 -1
- package/dist/src/translate.d.ts +1 -1
- package/dist/src/translate.js +2 -1
- package/package.json +1 -1
package/dist/src/cognito.js
CHANGED
|
@@ -30,8 +30,9 @@ const idea_toolbox_1 = require("idea-toolbox");
|
|
|
30
30
|
* A wrapper for AWS Cognito.
|
|
31
31
|
*/
|
|
32
32
|
class Cognito {
|
|
33
|
-
constructor(params
|
|
34
|
-
|
|
33
|
+
constructor(params) {
|
|
34
|
+
const options = Object.assign({}, params);
|
|
35
|
+
this.cognito = new CognitoIP.CognitoIdentityProviderClient({ region: options.region });
|
|
35
36
|
}
|
|
36
37
|
/**
|
|
37
38
|
* Change the region in which to find the user pool.
|
package/dist/src/comprehend.js
CHANGED
|
@@ -29,8 +29,9 @@ const AmazonComprehend = __importStar(require("@aws-sdk/client-comprehend"));
|
|
|
29
29
|
* A wrapper for Amazon Comprehend.
|
|
30
30
|
*/
|
|
31
31
|
class Comprehend {
|
|
32
|
-
constructor(params
|
|
33
|
-
|
|
32
|
+
constructor(params) {
|
|
33
|
+
const options = Object.assign({}, params);
|
|
34
|
+
this.comprehend = new AmazonComprehend.ComprehendClient({ region: options.region });
|
|
34
35
|
}
|
|
35
36
|
/**
|
|
36
37
|
* Inspects text and returns an inference of the prevailing sentiment (POSITIVE, NEUTRAL, MIXED, or NEGATIVE).
|
package/dist/src/dynamoDB.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ import { Logger } from './logger';
|
|
|
7
7
|
export declare class DynamoDB {
|
|
8
8
|
protected dynamo: DDB.DynamoDBDocument;
|
|
9
9
|
logger: Logger;
|
|
10
|
-
constructor(
|
|
11
|
-
debug
|
|
10
|
+
constructor(params?: {
|
|
11
|
+
debug?: boolean;
|
|
12
12
|
});
|
|
13
13
|
/**
|
|
14
14
|
* Convert a JSON object from DynamoDB format to simple JSON.
|
package/dist/src/dynamoDB.js
CHANGED
|
@@ -38,8 +38,9 @@ const logger_1 = require("./logger");
|
|
|
38
38
|
* A wrapper for AWS DynamoDB.
|
|
39
39
|
*/
|
|
40
40
|
class DynamoDB {
|
|
41
|
-
constructor(
|
|
41
|
+
constructor(params) {
|
|
42
42
|
this.logger = new logger_1.Logger();
|
|
43
|
+
const options = Object.assign({}, params, { debug: true });
|
|
43
44
|
this.dynamo = DDB.DynamoDBDocument.from(new client_dynamodb_1.DynamoDB(), {
|
|
44
45
|
marshallOptions: { convertEmptyValues: true, removeUndefinedValues: true, convertClassInstanceToMap: true }
|
|
45
46
|
});
|
package/dist/src/logger.d.ts
CHANGED
package/dist/src/logger.js
CHANGED
|
@@ -5,8 +5,9 @@ exports.Logger = void 0;
|
|
|
5
5
|
* Manage structured logging.
|
|
6
6
|
*/
|
|
7
7
|
class Logger {
|
|
8
|
-
constructor(
|
|
9
|
-
|
|
8
|
+
constructor(params) {
|
|
9
|
+
const options = Object.assign({}, params, { level: process.env.LOG_LEVEL });
|
|
10
|
+
this.level = (options.level ?? 'DEBUG').toUpperCase();
|
|
10
11
|
this.originalLevel = this.level;
|
|
11
12
|
}
|
|
12
13
|
isEnabled(level) {
|
package/dist/src/metrics.d.ts
CHANGED
package/dist/src/metrics.js
CHANGED
|
@@ -6,9 +6,9 @@ const metrics_1 = require("@aws-lambda-powertools/metrics");
|
|
|
6
6
|
* A wrapper for simple uses of CloudWatch Metrics.
|
|
7
7
|
*/
|
|
8
8
|
class CloudWatchMetrics {
|
|
9
|
-
constructor(
|
|
10
|
-
const
|
|
11
|
-
this.metrics = new metrics_1.Metrics({ namespace: project });
|
|
9
|
+
constructor(params) {
|
|
10
|
+
const options = Object.assign({}, params, { project: 'unknownProject' });
|
|
11
|
+
this.metrics = new metrics_1.Metrics({ namespace: options.project });
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Get the raw Metrics object. To use for custom purposes.
|
package/dist/src/s3.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ export declare class S3 {
|
|
|
12
12
|
protected DEFAULT_DOWNLOAD_BUCKET_SEC_TO_EXP: number;
|
|
13
13
|
protected DEFAULT_UPLOAD_BUCKET_SEC_TO_EXP: number;
|
|
14
14
|
logger: Logger;
|
|
15
|
-
constructor(
|
|
16
|
-
debug
|
|
15
|
+
constructor(params?: {
|
|
16
|
+
debug?: boolean;
|
|
17
17
|
});
|
|
18
18
|
/**
|
|
19
19
|
* Create a download link of a piece of data (through S3).
|
|
@@ -22,14 +22,12 @@ export declare class S3 {
|
|
|
22
22
|
createDownloadURLFromData(data: BodyDataTypes, options?: CreateDownloadURLFromDataOptions): Promise<SignedURL>;
|
|
23
23
|
/**
|
|
24
24
|
* Get a signed URL to put a file on a S3 bucket.
|
|
25
|
-
* @param expires seconds after which the signed URL expires
|
|
26
25
|
*/
|
|
27
|
-
signedURLPut(bucket: string, key: string,
|
|
26
|
+
signedURLPut(bucket: string, key: string, options?: SignedURLOptions): Promise<SignedURL>;
|
|
28
27
|
/**
|
|
29
28
|
* Get a signed URL to get a file on a S3 bucket.
|
|
30
|
-
* @param expires seconds after which the signed URL expires
|
|
31
29
|
*/
|
|
32
|
-
signedURLGet(bucket: string, key: string,
|
|
30
|
+
signedURLGet(bucket: string, key: string, options?: SignedURLOptions): Promise<SignedURL>;
|
|
33
31
|
/**
|
|
34
32
|
* Make a copy of an object of the bucket.
|
|
35
33
|
*/
|
|
@@ -83,6 +81,25 @@ export interface CreateDownloadURLFromDataOptions {
|
|
|
83
81
|
* Seconds to URL expiration; default: `180`.
|
|
84
82
|
*/
|
|
85
83
|
secToExp?: number;
|
|
84
|
+
/**
|
|
85
|
+
* The suggested name for the file once it's downloaded/saved.
|
|
86
|
+
* Note: the string is cleaned to ensure maximum compatibility with every OS.
|
|
87
|
+
*/
|
|
88
|
+
filename?: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Options for generating a signed URL.
|
|
92
|
+
*/
|
|
93
|
+
export interface SignedURLOptions {
|
|
94
|
+
/**
|
|
95
|
+
* Seconds to URL expiration; default: `180` for GET, `300` for PUT.
|
|
96
|
+
*/
|
|
97
|
+
secToExp?: number;
|
|
98
|
+
/**
|
|
99
|
+
* The suggested name for the file once it's downloaded/saved.
|
|
100
|
+
* Note: the string is cleaned to ensure maximum compatibility with every OS.
|
|
101
|
+
*/
|
|
102
|
+
filename?: string;
|
|
86
103
|
}
|
|
87
104
|
/**
|
|
88
105
|
* Options for copying an object.
|
|
@@ -117,6 +134,11 @@ export interface GetObjectOptions {
|
|
|
117
134
|
* Enum: JSON; useful to cast the result.
|
|
118
135
|
*/
|
|
119
136
|
type?: GetObjectTypes;
|
|
137
|
+
/**
|
|
138
|
+
* The suggested name for the file once it's downloaded/saved.
|
|
139
|
+
* Note: the string is cleaned to ensure maximum compatibility with every OS.
|
|
140
|
+
*/
|
|
141
|
+
filename?: string;
|
|
120
142
|
}
|
|
121
143
|
/**
|
|
122
144
|
* The managed types to convert objects coming from an S3 bucket.
|
|
@@ -153,6 +175,11 @@ export interface PutObjectOptions {
|
|
|
153
175
|
* A set of metadata as attributes
|
|
154
176
|
*/
|
|
155
177
|
metadata?: any;
|
|
178
|
+
/**
|
|
179
|
+
* The suggested name for the file once it's downloaded/saved.
|
|
180
|
+
* Note: the string is cleaned to ensure maximum compatibility with every OS.
|
|
181
|
+
*/
|
|
182
|
+
filename?: string;
|
|
156
183
|
}
|
|
157
184
|
/**
|
|
158
185
|
* Options for deleting an object.
|
|
@@ -180,3 +207,7 @@ export interface ListObjectsOptions {
|
|
|
180
207
|
*/
|
|
181
208
|
prefix?: string;
|
|
182
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Clean a filename to be compatible with most OS.
|
|
212
|
+
*/
|
|
213
|
+
export declare const cleanFilename: (filename: string) => string;
|
package/dist/src/s3.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.GetObjectTypes = exports.S3 = void 0;
|
|
26
|
+
exports.cleanFilename = exports.GetObjectTypes = exports.S3 = void 0;
|
|
27
27
|
const AWSS3 = __importStar(require("@aws-sdk/client-s3"));
|
|
28
28
|
const lib_storage_1 = require("@aws-sdk/lib-storage");
|
|
29
29
|
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
@@ -33,12 +33,13 @@ const logger_1 = require("./logger");
|
|
|
33
33
|
* A wrapper for AWS Simple Storage Service.
|
|
34
34
|
*/
|
|
35
35
|
class S3 {
|
|
36
|
-
constructor(
|
|
36
|
+
constructor(params) {
|
|
37
37
|
this.DEFAULT_DOWNLOAD_BUCKET_PREFIX = 'common';
|
|
38
38
|
this.DEFAULT_DOWNLOAD_BUCKET = 'idea-downloads';
|
|
39
39
|
this.DEFAULT_DOWNLOAD_BUCKET_SEC_TO_EXP = 180;
|
|
40
40
|
this.DEFAULT_UPLOAD_BUCKET_SEC_TO_EXP = 300;
|
|
41
41
|
this.logger = new logger_1.Logger();
|
|
42
|
+
const options = Object.assign({}, params, { debug: true });
|
|
42
43
|
this.s3 = new AWSS3.S3Client();
|
|
43
44
|
this.logger.level = options.debug ? 'DEBUG' : 'INFO';
|
|
44
45
|
}
|
|
@@ -56,26 +57,28 @@ class S3 {
|
|
|
56
57
|
const params = { Bucket: options.bucket, Key: options.key, Body: data, ContentType: options.contentType };
|
|
57
58
|
const upload = new lib_storage_1.Upload({ client: this.s3, params });
|
|
58
59
|
await upload.done();
|
|
59
|
-
return this.signedURLGet(options.bucket, options.key, options.secToExp);
|
|
60
|
+
return this.signedURLGet(options.bucket, options.key, { secToExp: options.secToExp, filename: options.filename });
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
62
63
|
* Get a signed URL to put a file on a S3 bucket.
|
|
63
|
-
* @param expires seconds after which the signed URL expires
|
|
64
64
|
*/
|
|
65
|
-
async signedURLPut(bucket, key,
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
async signedURLPut(bucket, key, options) {
|
|
66
|
+
const putParams = { Bucket: bucket, Key: key };
|
|
67
|
+
if (options.filename)
|
|
68
|
+
putParams.ContentDisposition = `attachment; filename ="${(0, exports.cleanFilename)(options.filename)}"`;
|
|
69
|
+
const expiresIn = options.secToExp || this.DEFAULT_UPLOAD_BUCKET_SEC_TO_EXP;
|
|
70
|
+
const url = await (0, s3_request_presigner_1.getSignedUrl)(this.s3, new AWSS3.PutObjectCommand(putParams), { expiresIn });
|
|
69
71
|
return new idea_toolbox_1.SignedURL({ url });
|
|
70
72
|
}
|
|
71
73
|
/**
|
|
72
74
|
* Get a signed URL to get a file on a S3 bucket.
|
|
73
|
-
* @param expires seconds after which the signed URL expires
|
|
74
75
|
*/
|
|
75
|
-
async signedURLGet(bucket, key,
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
async signedURLGet(bucket, key, options) {
|
|
77
|
+
const getParams = { Bucket: bucket, Key: key };
|
|
78
|
+
if (options.filename)
|
|
79
|
+
getParams.ResponseContentDisposition = `attachment; filename ="${(0, exports.cleanFilename)(options.filename)}"`;
|
|
80
|
+
const expiresIn = options.secToExp || this.DEFAULT_DOWNLOAD_BUCKET_SEC_TO_EXP;
|
|
81
|
+
const url = await (0, s3_request_presigner_1.getSignedUrl)(this.s3, new AWSS3.GetObjectCommand(getParams), { expiresIn });
|
|
79
82
|
return new idea_toolbox_1.SignedURL({ url });
|
|
80
83
|
}
|
|
81
84
|
/**
|
|
@@ -95,7 +98,10 @@ class S3 {
|
|
|
95
98
|
*/
|
|
96
99
|
async getObject(options) {
|
|
97
100
|
this.logger.debug(`S3 get object: ${options.key}`);
|
|
98
|
-
const
|
|
101
|
+
const params = { Bucket: options.bucket, Key: options.key };
|
|
102
|
+
if (!options.type && options.filename)
|
|
103
|
+
params.ResponseContentDisposition = `attachment; filename ="${(0, exports.cleanFilename)(options.filename)}"`;
|
|
104
|
+
const command = new AWSS3.GetObjectCommand(params);
|
|
99
105
|
const result = await this.s3.send(command);
|
|
100
106
|
switch (options.type) {
|
|
101
107
|
case GetObjectTypes.JSON:
|
|
@@ -117,6 +123,8 @@ class S3 {
|
|
|
117
123
|
params.ACL = options.acl;
|
|
118
124
|
if (options.metadata)
|
|
119
125
|
params.Metadata = options.metadata;
|
|
126
|
+
if (options.filename)
|
|
127
|
+
params.ContentDisposition = `attachment; filename ="${(0, exports.cleanFilename)(options.filename)}"`;
|
|
120
128
|
this.logger.debug(`S3 put object: ${options.key}`);
|
|
121
129
|
return await this.s3.send(new AWSS3.PutObjectCommand(params));
|
|
122
130
|
}
|
|
@@ -166,3 +174,8 @@ var GetObjectTypes;
|
|
|
166
174
|
GetObjectTypes["JSON"] = "JSON";
|
|
167
175
|
GetObjectTypes["TEXT"] = "TEXT";
|
|
168
176
|
})(GetObjectTypes || (exports.GetObjectTypes = GetObjectTypes = {}));
|
|
177
|
+
/**
|
|
178
|
+
* Clean a filename to be compatible with most OS.
|
|
179
|
+
*/
|
|
180
|
+
const cleanFilename = (filename) => filename.replace(/[^a-z0-9-.\s]/gi, '_');
|
|
181
|
+
exports.cleanFilename = cleanFilename;
|
package/dist/src/ses.d.ts
CHANGED
|
@@ -9,9 +9,9 @@ import { Logger } from './logger';
|
|
|
9
9
|
export declare class SES {
|
|
10
10
|
protected ses: AWSSES.SESv2Client;
|
|
11
11
|
logger: Logger;
|
|
12
|
-
constructor(
|
|
12
|
+
constructor(params?: {
|
|
13
13
|
region?: string;
|
|
14
|
-
debug
|
|
14
|
+
debug?: boolean;
|
|
15
15
|
});
|
|
16
16
|
getTemplate(templateName: string): Promise<AWSSES.EmailTemplateContent>;
|
|
17
17
|
setTemplate(templateName: string, subject: string, content: string, isHTML?: boolean): Promise<void>;
|
package/dist/src/ses.js
CHANGED
|
@@ -33,8 +33,9 @@ const logger_1 = require("./logger");
|
|
|
33
33
|
* A wrapper for AWS Simple Email Service.
|
|
34
34
|
*/
|
|
35
35
|
class SES {
|
|
36
|
-
constructor(
|
|
36
|
+
constructor(params) {
|
|
37
37
|
this.logger = new logger_1.Logger();
|
|
38
|
+
const options = Object.assign({}, params, { debug: true });
|
|
38
39
|
this.ses = new AWSSES.SESv2Client({ region: options.region });
|
|
39
40
|
this.logger.level = options.debug ? 'DEBUG' : 'INFO';
|
|
40
41
|
}
|
package/dist/src/sns.d.ts
CHANGED
package/dist/src/sns.js
CHANGED
|
@@ -31,8 +31,9 @@ const logger_1 = require("./logger");
|
|
|
31
31
|
* A wrapper for AWS Simple Notification Service.
|
|
32
32
|
*/
|
|
33
33
|
class SNS {
|
|
34
|
-
constructor(
|
|
34
|
+
constructor(params) {
|
|
35
35
|
this.logger = new logger_1.Logger();
|
|
36
|
+
const options = Object.assign({}, params, { debug: true });
|
|
36
37
|
this.logger.level = options.debug ? 'DEBUG' : 'INFO';
|
|
37
38
|
}
|
|
38
39
|
/**
|
package/dist/src/translate.d.ts
CHANGED
package/dist/src/translate.js
CHANGED
|
@@ -33,7 +33,8 @@ class Translate {
|
|
|
33
33
|
/**
|
|
34
34
|
* Initialize a new Translate helper object.
|
|
35
35
|
*/
|
|
36
|
-
constructor(
|
|
36
|
+
constructor(params) {
|
|
37
|
+
const options = Object.assign({}, params);
|
|
37
38
|
this.translate = new AWSTranslate.TranslateClient({ region: options.region });
|
|
38
39
|
this.sourceLanguageCode = 'en';
|
|
39
40
|
this.targetLanguageCode = 'en';
|