idea-aws 4.2.1 → 4.3.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/attachments.d.ts +5 -8
- package/dist/src/attachments.js +10 -9
- package/dist/src/cognito.d.ts +23 -23
- package/dist/src/cognito.js +65 -69
- package/dist/src/comprehend.d.ts +1 -4
- package/dist/src/comprehend.js +6 -7
- package/dist/src/dynamoDB.d.ts +3 -22
- package/dist/src/dynamoDB.js +36 -85
- package/dist/src/genericController.d.ts +1 -1
- package/dist/src/genericController.js +4 -4
- package/dist/src/logger.d.ts +6 -15
- package/dist/src/logger.js +7 -45
- package/dist/src/metrics.d.ts +1 -1
- package/dist/src/metrics.js +3 -3
- package/dist/src/resourceController.d.ts +3 -2
- package/dist/src/resourceController.js +44 -32
- package/dist/src/s3.d.ts +27 -17
- package/dist/src/s3.js +34 -37
- package/dist/src/secretsManager.d.ts +4 -1
- package/dist/src/secretsManager.js +7 -3
- package/dist/src/ses.d.ts +1 -4
- package/dist/src/ses.js +4 -8
- package/dist/src/sns.d.ts +10 -16
- package/dist/src/sns.js +18 -23
- package/dist/src/ssm.d.ts +8 -2
- package/dist/src/ssm.js +10 -8
- package/dist/src/translate.d.ts +1 -4
- package/dist/src/translate.js +12 -4
- package/package.json +9 -12
package/dist/src/s3.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as AWSS3 from '@aws-sdk/client-s3';
|
|
2
2
|
import { BodyDataTypes } from '@aws-sdk/lib-storage';
|
|
3
3
|
import { SignedURL } from 'idea-toolbox';
|
|
4
|
-
import { Logger } from './logger';
|
|
5
4
|
/**
|
|
6
5
|
* A wrapper for AWS Simple Storage Service.
|
|
7
6
|
*/
|
|
@@ -11,10 +10,7 @@ export declare class S3 {
|
|
|
11
10
|
protected DEFAULT_DOWNLOAD_BUCKET: string;
|
|
12
11
|
protected DEFAULT_DOWNLOAD_BUCKET_SEC_TO_EXP: number;
|
|
13
12
|
protected DEFAULT_UPLOAD_BUCKET_SEC_TO_EXP: number;
|
|
14
|
-
|
|
15
|
-
constructor(params?: {
|
|
16
|
-
debug?: boolean;
|
|
17
|
-
});
|
|
13
|
+
constructor();
|
|
18
14
|
/**
|
|
19
15
|
* Create a download link of a piece of data (through S3).
|
|
20
16
|
* *Practically*, it uploads the file on an S3 bucket, generating and returning a url to it.
|
|
@@ -35,7 +31,15 @@ export declare class S3 {
|
|
|
35
31
|
/**
|
|
36
32
|
* Get an object from a S3 bucket.
|
|
37
33
|
*/
|
|
38
|
-
getObject(options: GetObjectOptions): Promise<
|
|
34
|
+
getObject(options: GetObjectOptions): Promise<AWSS3.GetObjectCommandOutput>;
|
|
35
|
+
/**
|
|
36
|
+
* Get an object from a S3 bucket and parse the content as a JSON object.
|
|
37
|
+
*/
|
|
38
|
+
getObjectAsJSON(options: GetObjectOptions): Promise<any>;
|
|
39
|
+
/**
|
|
40
|
+
* Get an object from a S3 bucket and convert the content to string.
|
|
41
|
+
*/
|
|
42
|
+
getObjectAsText(options: GetObjectOptions): Promise<string>;
|
|
39
43
|
/**
|
|
40
44
|
* Put an object in a S3 bucket.
|
|
41
45
|
*/
|
|
@@ -53,9 +57,9 @@ export declare class S3 {
|
|
|
53
57
|
*/
|
|
54
58
|
listObjectsKeys(options: ListObjectsOptions): Promise<string[]>;
|
|
55
59
|
/**
|
|
56
|
-
* Check whether an object
|
|
60
|
+
* Check whether an object exists in an S3 bucket.
|
|
57
61
|
*/
|
|
58
|
-
doesObjectExist(options:
|
|
62
|
+
doesObjectExist(options: HeadObjectOptions): Promise<boolean>;
|
|
59
63
|
}
|
|
60
64
|
/**
|
|
61
65
|
* Options for creating a download URL.
|
|
@@ -127,13 +131,9 @@ export interface GetObjectOptions {
|
|
|
127
131
|
*/
|
|
128
132
|
bucket: string;
|
|
129
133
|
/**
|
|
130
|
-
* The complete filepath
|
|
134
|
+
* The complete filepath (within the bucket) from which to acquire the file.
|
|
131
135
|
*/
|
|
132
136
|
key: string;
|
|
133
|
-
/**
|
|
134
|
-
* Enum: JSON; useful to cast the result.
|
|
135
|
-
*/
|
|
136
|
-
type?: GetObjectTypes;
|
|
137
137
|
/**
|
|
138
138
|
* The suggested name for the file once it's downloaded/saved.
|
|
139
139
|
* Note: the string is cleaned to ensure maximum compatibility with every OS.
|
|
@@ -141,11 +141,21 @@ export interface GetObjectOptions {
|
|
|
141
141
|
filename?: string;
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
144
|
-
*
|
|
144
|
+
* Options for getting the head (main metadata, without the content) of an object.
|
|
145
145
|
*/
|
|
146
|
-
export
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
export interface HeadObjectOptions {
|
|
147
|
+
/**
|
|
148
|
+
* The bucket from which to acquire the file.
|
|
149
|
+
*/
|
|
150
|
+
bucket: string;
|
|
151
|
+
/**
|
|
152
|
+
* The complete filepath (within the bucket) from which to acquire the file.
|
|
153
|
+
*/
|
|
154
|
+
key: string;
|
|
155
|
+
/**
|
|
156
|
+
* If set, the request will fail in case the object is empty (`ContentLength === 0`).
|
|
157
|
+
*/
|
|
158
|
+
emptyMeansNotFound?: boolean;
|
|
149
159
|
}
|
|
150
160
|
/**
|
|
151
161
|
* Options for putting an object.
|
package/dist/src/s3.js
CHANGED
|
@@ -23,25 +23,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.cleanFilename = exports.
|
|
26
|
+
exports.cleanFilename = 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");
|
|
30
30
|
const idea_toolbox_1 = require("idea-toolbox");
|
|
31
|
-
const logger_1 = require("./logger");
|
|
32
31
|
/**
|
|
33
32
|
* A wrapper for AWS Simple Storage Service.
|
|
34
33
|
*/
|
|
35
34
|
class S3 {
|
|
36
|
-
constructor(
|
|
35
|
+
constructor() {
|
|
37
36
|
this.DEFAULT_DOWNLOAD_BUCKET_PREFIX = 'common';
|
|
38
37
|
this.DEFAULT_DOWNLOAD_BUCKET = 'idea-downloads';
|
|
39
38
|
this.DEFAULT_DOWNLOAD_BUCKET_SEC_TO_EXP = 180;
|
|
40
39
|
this.DEFAULT_UPLOAD_BUCKET_SEC_TO_EXP = 300;
|
|
41
|
-
this.logger = new logger_1.Logger();
|
|
42
|
-
const options = Object.assign({}, params, { debug: true });
|
|
43
40
|
this.s3 = new AWSS3.S3Client();
|
|
44
|
-
this.logger.level = options.debug ? 'DEBUG' : 'INFO';
|
|
45
41
|
}
|
|
46
42
|
/**
|
|
47
43
|
* Create a download link of a piece of data (through S3).
|
|
@@ -51,9 +47,9 @@ class S3 {
|
|
|
51
47
|
// if needed, randomly generates the key
|
|
52
48
|
if (!options.key)
|
|
53
49
|
options.key = Date.now().toString().concat(Math.random().toString(36).slice(2));
|
|
54
|
-
options.key = `${options.prefix
|
|
55
|
-
options.bucket = options.bucket
|
|
56
|
-
options.secToExp = options.secToExp
|
|
50
|
+
options.key = `${options.prefix ?? this.DEFAULT_DOWNLOAD_BUCKET_PREFIX}/${options.key}`;
|
|
51
|
+
options.bucket = options.bucket ?? this.DEFAULT_DOWNLOAD_BUCKET;
|
|
52
|
+
options.secToExp = options.secToExp ?? this.DEFAULT_DOWNLOAD_BUCKET_SEC_TO_EXP;
|
|
57
53
|
const params = { Bucket: options.bucket, Key: options.key, Body: data, ContentType: options.contentType };
|
|
58
54
|
const upload = new lib_storage_1.Upload({ client: this.s3, params });
|
|
59
55
|
await upload.done();
|
|
@@ -66,7 +62,7 @@ class S3 {
|
|
|
66
62
|
const putParams = { Bucket: bucket, Key: key };
|
|
67
63
|
if (options.filename)
|
|
68
64
|
putParams.ContentDisposition = `attachment; filename ="${(0, exports.cleanFilename)(options.filename)}"`;
|
|
69
|
-
const expiresIn = options.secToExp
|
|
65
|
+
const expiresIn = options.secToExp ?? this.DEFAULT_UPLOAD_BUCKET_SEC_TO_EXP;
|
|
70
66
|
const url = await (0, s3_request_presigner_1.getSignedUrl)(this.s3, new AWSS3.PutObjectCommand(putParams), { expiresIn });
|
|
71
67
|
return new idea_toolbox_1.SignedURL({ url });
|
|
72
68
|
}
|
|
@@ -77,7 +73,7 @@ class S3 {
|
|
|
77
73
|
const getParams = { Bucket: bucket, Key: key };
|
|
78
74
|
if (options.filename)
|
|
79
75
|
getParams.ResponseContentDisposition = `attachment; filename ="${(0, exports.cleanFilename)(options.filename)}"`;
|
|
80
|
-
const expiresIn = options.secToExp
|
|
76
|
+
const expiresIn = options.secToExp ?? this.DEFAULT_DOWNLOAD_BUCKET_SEC_TO_EXP;
|
|
81
77
|
const url = await (0, s3_request_presigner_1.getSignedUrl)(this.s3, new AWSS3.GetObjectCommand(getParams), { expiresIn });
|
|
82
78
|
return new idea_toolbox_1.SignedURL({ url });
|
|
83
79
|
}
|
|
@@ -85,7 +81,7 @@ class S3 {
|
|
|
85
81
|
* Make a copy of an object of the bucket.
|
|
86
82
|
*/
|
|
87
83
|
async copyObject(options) {
|
|
88
|
-
|
|
84
|
+
console.debug(`S3 copy object: ${options.key}`);
|
|
89
85
|
const command = new AWSS3.CopyObjectCommand({
|
|
90
86
|
CopySource: options.copySource,
|
|
91
87
|
Bucket: options.bucket,
|
|
@@ -97,20 +93,26 @@ class S3 {
|
|
|
97
93
|
* Get an object from a S3 bucket.
|
|
98
94
|
*/
|
|
99
95
|
async getObject(options) {
|
|
100
|
-
|
|
96
|
+
console.debug(`S3 get object: ${options.key}`);
|
|
101
97
|
const params = { Bucket: options.bucket, Key: options.key };
|
|
102
|
-
if (
|
|
98
|
+
if (options.filename)
|
|
103
99
|
params.ResponseContentDisposition = `attachment; filename ="${(0, exports.cleanFilename)(options.filename)}"`;
|
|
104
100
|
const command = new AWSS3.GetObjectCommand(params);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
101
|
+
return await this.s3.send(command);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get an object from a S3 bucket and parse the content as a JSON object.
|
|
105
|
+
*/
|
|
106
|
+
async getObjectAsJSON(options) {
|
|
107
|
+
const result = await this.getObject(options);
|
|
108
|
+
return JSON.parse(await result.Body.transformToString('utf-8'));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get an object from a S3 bucket and convert the content to string.
|
|
112
|
+
*/
|
|
113
|
+
async getObjectAsText(options) {
|
|
114
|
+
const result = await this.getObject(options);
|
|
115
|
+
return await result.Body.transformToString('utf-8');
|
|
114
116
|
}
|
|
115
117
|
/**
|
|
116
118
|
* Put an object in a S3 bucket.
|
|
@@ -125,14 +127,14 @@ class S3 {
|
|
|
125
127
|
params.Metadata = options.metadata;
|
|
126
128
|
if (options.filename)
|
|
127
129
|
params.ContentDisposition = `attachment; filename ="${(0, exports.cleanFilename)(options.filename)}"`;
|
|
128
|
-
|
|
130
|
+
console.debug(`S3 put object: ${options.key}`);
|
|
129
131
|
return await this.s3.send(new AWSS3.PutObjectCommand(params));
|
|
130
132
|
}
|
|
131
133
|
/**
|
|
132
134
|
* Delete an object from an S3 bucket.
|
|
133
135
|
*/
|
|
134
136
|
async deleteObject(options) {
|
|
135
|
-
|
|
137
|
+
console.debug(`S3 delete object: ${options.key}`);
|
|
136
138
|
const deleteCommand = new AWSS3.DeleteObjectCommand({ Bucket: options.bucket, Key: options.key });
|
|
137
139
|
return await this.s3.send(deleteCommand);
|
|
138
140
|
}
|
|
@@ -140,7 +142,7 @@ class S3 {
|
|
|
140
142
|
* List the objects of an S3 bucket.
|
|
141
143
|
*/
|
|
142
144
|
async listObjects(options) {
|
|
143
|
-
|
|
145
|
+
console.debug(`S3 list object: ${options.prefix}`);
|
|
144
146
|
const command = new AWSS3.ListObjectsCommand({ Bucket: options.bucket, Prefix: options.prefix });
|
|
145
147
|
return await this.s3.send(command);
|
|
146
148
|
}
|
|
@@ -152,13 +154,16 @@ class S3 {
|
|
|
152
154
|
return result.Contents.map(obj => obj.Key);
|
|
153
155
|
}
|
|
154
156
|
/**
|
|
155
|
-
* Check whether an object
|
|
157
|
+
* Check whether an object exists in an S3 bucket.
|
|
156
158
|
*/
|
|
157
159
|
async doesObjectExist(options) {
|
|
158
160
|
try {
|
|
159
161
|
const command = new AWSS3.HeadObjectCommand({ Bucket: options.bucket, Key: options.key });
|
|
160
|
-
await this.s3.send(command);
|
|
161
|
-
|
|
162
|
+
const { ContentLength } = await this.s3.send(command);
|
|
163
|
+
if (options.emptyMeansNotFound)
|
|
164
|
+
return ContentLength > 0;
|
|
165
|
+
else
|
|
166
|
+
return true;
|
|
162
167
|
}
|
|
163
168
|
catch (err) {
|
|
164
169
|
return false;
|
|
@@ -166,14 +171,6 @@ class S3 {
|
|
|
166
171
|
}
|
|
167
172
|
}
|
|
168
173
|
exports.S3 = S3;
|
|
169
|
-
/**
|
|
170
|
-
* The managed types to convert objects coming from an S3 bucket.
|
|
171
|
-
*/
|
|
172
|
-
var GetObjectTypes;
|
|
173
|
-
(function (GetObjectTypes) {
|
|
174
|
-
GetObjectTypes["JSON"] = "JSON";
|
|
175
|
-
GetObjectTypes["TEXT"] = "TEXT";
|
|
176
|
-
})(GetObjectTypes || (exports.GetObjectTypes = GetObjectTypes = {}));
|
|
177
174
|
/**
|
|
178
175
|
* Clean a filename to be compatible with most OS.
|
|
179
176
|
*/
|
|
@@ -4,9 +4,12 @@ import * as AWSSecretsManager from '@aws-sdk/client-secrets-manager';
|
|
|
4
4
|
*/
|
|
5
5
|
export declare class SecretsManager {
|
|
6
6
|
protected sm: AWSSecretsManager.SecretsManagerClient;
|
|
7
|
+
protected cache: Map<string, string>;
|
|
7
8
|
constructor();
|
|
8
9
|
/**
|
|
9
10
|
* Get a secret string from the Secret Manager by its id.
|
|
10
11
|
*/
|
|
11
|
-
getStringById(secretId: string
|
|
12
|
+
getStringById(secretId: string, options?: {
|
|
13
|
+
noCache?: boolean;
|
|
14
|
+
}): Promise<string>;
|
|
12
15
|
}
|
|
@@ -30,15 +30,19 @@ const AWSSecretsManager = __importStar(require("@aws-sdk/client-secrets-manager"
|
|
|
30
30
|
*/
|
|
31
31
|
class SecretsManager {
|
|
32
32
|
constructor() {
|
|
33
|
+
this.cache = new Map();
|
|
33
34
|
this.sm = new AWSSecretsManager.SecretsManagerClient();
|
|
34
35
|
}
|
|
35
36
|
/**
|
|
36
37
|
* Get a secret string from the Secret Manager by its id.
|
|
37
38
|
*/
|
|
38
|
-
async getStringById(secretId) {
|
|
39
|
+
async getStringById(secretId, options = {}) {
|
|
40
|
+
if (!options.noCache && this.cache.has(secretId))
|
|
41
|
+
return this.cache.get(secretId);
|
|
39
42
|
const command = new AWSSecretsManager.GetSecretValueCommand({ SecretId: secretId });
|
|
40
|
-
const
|
|
41
|
-
|
|
43
|
+
const { SecretString } = await this.sm.send(command);
|
|
44
|
+
this.cache.set(secretId, SecretString);
|
|
45
|
+
return SecretString;
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
exports.SecretsManager = SecretsManager;
|
package/dist/src/ses.d.ts
CHANGED
|
@@ -2,16 +2,13 @@
|
|
|
2
2
|
import * as AWSSES from '@aws-sdk/client-sesv2';
|
|
3
3
|
import { SentMessageInfo as NodemailerSentMessageInfo } from 'nodemailer';
|
|
4
4
|
import { Headers } from 'nodemailer/lib/mailer';
|
|
5
|
-
import { Logger } from './logger';
|
|
6
5
|
/**
|
|
7
6
|
* A wrapper for AWS Simple Email Service.
|
|
8
7
|
*/
|
|
9
8
|
export declare class SES {
|
|
10
9
|
protected ses: AWSSES.SESv2Client;
|
|
11
|
-
|
|
12
|
-
constructor(params?: {
|
|
10
|
+
constructor(options?: {
|
|
13
11
|
region?: string;
|
|
14
|
-
debug?: boolean;
|
|
15
12
|
});
|
|
16
13
|
getTemplate(templateName: string): Promise<AWSSES.EmailTemplateContent>;
|
|
17
14
|
setTemplate(templateName: string, subject: string, content: string, isHTML?: boolean): Promise<void>;
|
package/dist/src/ses.js
CHANGED
|
@@ -28,16 +28,12 @@ const client_ses_1 = require("@aws-sdk/client-ses");
|
|
|
28
28
|
const AWSSES = __importStar(require("@aws-sdk/client-sesv2"));
|
|
29
29
|
const nodemailer_1 = require("nodemailer");
|
|
30
30
|
const dynamoDB_1 = require("./dynamoDB");
|
|
31
|
-
const logger_1 = require("./logger");
|
|
32
31
|
/**
|
|
33
32
|
* A wrapper for AWS Simple Email Service.
|
|
34
33
|
*/
|
|
35
34
|
class SES {
|
|
36
|
-
constructor(
|
|
37
|
-
this.logger = new logger_1.Logger();
|
|
38
|
-
const options = Object.assign({}, params, { debug: true });
|
|
35
|
+
constructor(options = {}) {
|
|
39
36
|
this.ses = new AWSSES.SESv2Client({ region: options.region });
|
|
40
|
-
this.logger.level = options.debug ? 'DEBUG' : 'INFO';
|
|
41
37
|
}
|
|
42
38
|
//
|
|
43
39
|
// CONFIG
|
|
@@ -108,7 +104,7 @@ class SES {
|
|
|
108
104
|
ses = this.ses;
|
|
109
105
|
else
|
|
110
106
|
ses = new AWSSES.SESv2Client({ region: sesParams.region });
|
|
111
|
-
|
|
107
|
+
console.debug('SES send templated email');
|
|
112
108
|
return await ses.send(command);
|
|
113
109
|
}
|
|
114
110
|
/**
|
|
@@ -148,7 +144,7 @@ class SES {
|
|
|
148
144
|
ses = this.ses;
|
|
149
145
|
else
|
|
150
146
|
ses = new AWSSES.SESv2Client({ region: sesParams.region });
|
|
151
|
-
|
|
147
|
+
console.debug('SES send email');
|
|
152
148
|
return await ses.send(command);
|
|
153
149
|
}
|
|
154
150
|
async sendEmailWithNodemailer(emailData, sesParams) {
|
|
@@ -169,7 +165,7 @@ class SES {
|
|
|
169
165
|
mailOptions.attachments = emailData.attachments;
|
|
170
166
|
// note: Nodemailer doesn't support SESv2 as of August 2023
|
|
171
167
|
const ses = new client_ses_1.SESClient({ region: sesParams.region });
|
|
172
|
-
|
|
168
|
+
console.debug('SES send email (Nodemailer)');
|
|
173
169
|
// note: this is a workaround to make Nodemailer works with AWS SDK 3;
|
|
174
170
|
// see: https://github.com/nodemailer/nodemailer/issues/1430
|
|
175
171
|
return await (0, nodemailer_1.createTransport)({ SES: { ses, aws: { SendRawEmailCommand: client_ses_1.SendRawEmailCommand } } }).sendMail(mailOptions);
|
package/dist/src/sns.d.ts
CHANGED
|
@@ -1,32 +1,27 @@
|
|
|
1
1
|
import * as AWSSNS from '@aws-sdk/client-sns';
|
|
2
2
|
import { PushNotificationsPlatforms } from 'idea-toolbox';
|
|
3
|
-
import { Logger } from './logger';
|
|
4
3
|
/**
|
|
5
4
|
* A wrapper for AWS Simple Notification Service.
|
|
6
5
|
*/
|
|
7
6
|
export declare class SNS {
|
|
8
|
-
|
|
9
|
-
constructor(
|
|
10
|
-
|
|
7
|
+
protected client: AWSSNS.SNSClient;
|
|
8
|
+
constructor(options?: {
|
|
9
|
+
region?: string;
|
|
11
10
|
});
|
|
12
11
|
/**
|
|
13
12
|
* Create a new endpoint in the SNS platform specified.
|
|
14
13
|
* @return platform endpoint ARN
|
|
15
14
|
*/
|
|
16
|
-
|
|
15
|
+
createPlatormEndpoint(platform: PushNotificationsPlatforms, token: string, options: SNSCreateEndpointParams): Promise<string>;
|
|
17
16
|
/**
|
|
18
17
|
* Publish a message to a SNS endpoint.
|
|
19
18
|
*/
|
|
20
|
-
publish(
|
|
19
|
+
publish(options: SNSPublishParams): Promise<AWSSNS.PublishCommandOutput>;
|
|
21
20
|
}
|
|
22
21
|
/**
|
|
23
|
-
* SNS
|
|
22
|
+
* Options for creating a SNS endpoint.
|
|
24
23
|
*/
|
|
25
|
-
export interface
|
|
26
|
-
/**
|
|
27
|
-
* SNS region.
|
|
28
|
-
*/
|
|
29
|
-
region: string;
|
|
24
|
+
export interface SNSCreateEndpointParams {
|
|
30
25
|
/**
|
|
31
26
|
* ARN to production of Apple's (iOS, MacOS) notification services.
|
|
32
27
|
*/
|
|
@@ -40,11 +35,10 @@ export interface SNSParams {
|
|
|
40
35
|
*/
|
|
41
36
|
androidArn?: string;
|
|
42
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Options to publish a message on a SNS endpoint.
|
|
40
|
+
*/
|
|
43
41
|
export interface SNSPublishParams {
|
|
44
|
-
/**
|
|
45
|
-
* SNS region.
|
|
46
|
-
*/
|
|
47
|
-
region: string;
|
|
48
42
|
/**
|
|
49
43
|
* The endpoint of the notification.
|
|
50
44
|
*/
|
package/dist/src/sns.js
CHANGED
|
@@ -26,72 +26,67 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.SNS = void 0;
|
|
27
27
|
const AWSSNS = __importStar(require("@aws-sdk/client-sns"));
|
|
28
28
|
const idea_toolbox_1 = require("idea-toolbox");
|
|
29
|
-
const logger_1 = require("./logger");
|
|
30
29
|
/**
|
|
31
30
|
* A wrapper for AWS Simple Notification Service.
|
|
32
31
|
*/
|
|
33
32
|
class SNS {
|
|
34
|
-
constructor(
|
|
35
|
-
this.
|
|
36
|
-
const options = Object.assign({}, params, { debug: true });
|
|
37
|
-
this.logger.level = options.debug ? 'DEBUG' : 'INFO';
|
|
33
|
+
constructor(options = {}) {
|
|
34
|
+
this.client = new AWSSNS.SNSClient({ region: options.region });
|
|
38
35
|
}
|
|
39
36
|
/**
|
|
40
37
|
* Create a new endpoint in the SNS platform specified.
|
|
41
38
|
* @return platform endpoint ARN
|
|
42
39
|
*/
|
|
43
|
-
async
|
|
40
|
+
async createPlatormEndpoint(platform, token, options) {
|
|
44
41
|
let platformARN;
|
|
45
42
|
switch (platform) {
|
|
46
43
|
case idea_toolbox_1.PushNotificationsPlatforms.APNS:
|
|
47
|
-
platformARN =
|
|
44
|
+
platformARN = options.appleArn;
|
|
48
45
|
break;
|
|
49
46
|
case idea_toolbox_1.PushNotificationsPlatforms.APNS_SANDBOX:
|
|
50
|
-
platformARN =
|
|
47
|
+
platformARN = options.appleDevArn;
|
|
51
48
|
break;
|
|
52
49
|
case idea_toolbox_1.PushNotificationsPlatforms.FCM:
|
|
53
|
-
platformARN =
|
|
50
|
+
platformARN = options.androidArn;
|
|
54
51
|
break;
|
|
55
52
|
default:
|
|
56
53
|
throw new Error('Unsupported platform');
|
|
57
54
|
}
|
|
58
|
-
|
|
59
|
-
const client = new AWSSNS.SNSClient({ region: snsParams.region });
|
|
55
|
+
console.debug('SNS add platform endpoint');
|
|
60
56
|
const command = new AWSSNS.CreatePlatformEndpointCommand({ PlatformApplicationArn: platformARN, Token: token });
|
|
61
|
-
const { EndpointArn } = await client.send(command);
|
|
57
|
+
const { EndpointArn } = await this.client.send(command);
|
|
62
58
|
return EndpointArn;
|
|
63
59
|
}
|
|
64
60
|
/**
|
|
65
61
|
* Publish a message to a SNS endpoint.
|
|
66
62
|
*/
|
|
67
|
-
async publish(
|
|
63
|
+
async publish(options) {
|
|
68
64
|
let structuredMessage;
|
|
69
|
-
if (
|
|
70
|
-
structuredMessage = { default: JSON.stringify(
|
|
65
|
+
if (options.json)
|
|
66
|
+
structuredMessage = { default: JSON.stringify(options.json) };
|
|
71
67
|
else
|
|
72
|
-
switch (
|
|
68
|
+
switch (options.platform) {
|
|
73
69
|
case idea_toolbox_1.PushNotificationsPlatforms.APNS:
|
|
74
|
-
structuredMessage = { APNS: JSON.stringify({ aps: { alert:
|
|
70
|
+
structuredMessage = { APNS: JSON.stringify({ aps: { alert: options.message } }) };
|
|
75
71
|
break;
|
|
76
72
|
case idea_toolbox_1.PushNotificationsPlatforms.APNS_SANDBOX:
|
|
77
|
-
structuredMessage = { APNS_SANDBOX: JSON.stringify({ aps: { alert:
|
|
73
|
+
structuredMessage = { APNS_SANDBOX: JSON.stringify({ aps: { alert: options.message } }) };
|
|
78
74
|
break;
|
|
79
75
|
case idea_toolbox_1.PushNotificationsPlatforms.FCM:
|
|
80
76
|
structuredMessage = {
|
|
81
|
-
GCM: JSON.stringify({ notification: { body:
|
|
77
|
+
GCM: JSON.stringify({ notification: { body: options.message, title: options.message } })
|
|
82
78
|
};
|
|
83
79
|
break;
|
|
84
80
|
default:
|
|
85
81
|
throw new Error('Unsupported platform');
|
|
86
82
|
}
|
|
87
|
-
|
|
88
|
-
const client = new AWSSNS.SNSClient({ region: snsParams.region });
|
|
83
|
+
console.debug('SNS publish in topic');
|
|
89
84
|
const command = new AWSSNS.PublishCommand({
|
|
90
85
|
MessageStructure: 'json',
|
|
91
86
|
Message: JSON.stringify(structuredMessage),
|
|
92
|
-
TargetArn:
|
|
87
|
+
TargetArn: options.endpoint
|
|
93
88
|
});
|
|
94
|
-
return await client.send(command);
|
|
89
|
+
return await this.client.send(command);
|
|
95
90
|
}
|
|
96
91
|
}
|
|
97
92
|
exports.SNS = SNS;
|
package/dist/src/ssm.d.ts
CHANGED
|
@@ -4,13 +4,19 @@ import * as AWSSystemsManager from '@aws-sdk/client-ssm';
|
|
|
4
4
|
*/
|
|
5
5
|
export declare class SystemsManager {
|
|
6
6
|
protected ssm: AWSSystemsManager.SSMClient;
|
|
7
|
+
protected cache: Map<string, string>;
|
|
7
8
|
constructor();
|
|
8
9
|
/**
|
|
9
10
|
* Get a parameter by its name (path).
|
|
10
11
|
*/
|
|
11
|
-
getParameterByName(name: string
|
|
12
|
+
getParameterByName(name: string, options?: {
|
|
13
|
+
noCache?: boolean;
|
|
14
|
+
withDecryption?: boolean;
|
|
15
|
+
}): Promise<string>;
|
|
12
16
|
/**
|
|
13
17
|
* Get a parameter (with decryption) by its name (path).
|
|
14
18
|
*/
|
|
15
|
-
getSecretByName(name: string
|
|
19
|
+
getSecretByName(name: string, options?: {
|
|
20
|
+
noCache?: boolean;
|
|
21
|
+
}): Promise<string>;
|
|
16
22
|
}
|
package/dist/src/ssm.js
CHANGED
|
@@ -30,23 +30,25 @@ const AWSSystemsManager = __importStar(require("@aws-sdk/client-ssm"));
|
|
|
30
30
|
*/
|
|
31
31
|
class SystemsManager {
|
|
32
32
|
constructor() {
|
|
33
|
+
this.cache = new Map();
|
|
33
34
|
this.ssm = new AWSSystemsManager.SSMClient();
|
|
34
35
|
}
|
|
35
36
|
/**
|
|
36
37
|
* Get a parameter by its name (path).
|
|
37
38
|
*/
|
|
38
|
-
async getParameterByName(name) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
async getParameterByName(name, options = {}) {
|
|
40
|
+
if (!options.noCache && this.cache.has(name))
|
|
41
|
+
return this.cache.get(name);
|
|
42
|
+
const command = new AWSSystemsManager.GetParameterCommand({ Name: name, WithDecryption: options.withDecryption });
|
|
43
|
+
const { Parameter } = await this.ssm.send(command);
|
|
44
|
+
this.cache.set(name, Parameter.Value);
|
|
45
|
+
return Parameter.Value;
|
|
42
46
|
}
|
|
43
47
|
/**
|
|
44
48
|
* Get a parameter (with decryption) by its name (path).
|
|
45
49
|
*/
|
|
46
|
-
async getSecretByName(name) {
|
|
47
|
-
|
|
48
|
-
const result = await this.ssm.send(command);
|
|
49
|
-
return result.Parameter.Value;
|
|
50
|
+
async getSecretByName(name, options = {}) {
|
|
51
|
+
return this.getParameterByName(name, { ...options, withDecryption: true });
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
exports.SystemsManager = SystemsManager;
|
package/dist/src/translate.d.ts
CHANGED
|
@@ -4,9 +4,6 @@ import { Languages, PDFEntity, PDFTemplateSection } from 'idea-toolbox';
|
|
|
4
4
|
* A wrapper for Amazon Translate.
|
|
5
5
|
*/
|
|
6
6
|
export declare class Translate {
|
|
7
|
-
/**
|
|
8
|
-
* The instance of Amazon Translate.
|
|
9
|
-
*/
|
|
10
7
|
protected translate: AWSTranslate.TranslateClient;
|
|
11
8
|
/**
|
|
12
9
|
* Default input language code.
|
|
@@ -23,7 +20,7 @@ export declare class Translate {
|
|
|
23
20
|
/**
|
|
24
21
|
* Initialize a new Translate helper object.
|
|
25
22
|
*/
|
|
26
|
-
constructor(
|
|
23
|
+
constructor(options?: {
|
|
27
24
|
region?: string;
|
|
28
25
|
});
|
|
29
26
|
/**
|
package/dist/src/translate.js
CHANGED
|
@@ -33,12 +33,20 @@ class Translate {
|
|
|
33
33
|
/**
|
|
34
34
|
* Initialize a new Translate helper object.
|
|
35
35
|
*/
|
|
36
|
-
constructor(
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
constructor(options = {}) {
|
|
37
|
+
/**
|
|
38
|
+
* Default input language code.
|
|
39
|
+
*/
|
|
39
40
|
this.sourceLanguageCode = 'en';
|
|
41
|
+
/**
|
|
42
|
+
* Default output language code.
|
|
43
|
+
*/
|
|
40
44
|
this.targetLanguageCode = 'en';
|
|
41
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Default terminology list.
|
|
47
|
+
*/
|
|
48
|
+
this.terminologyNames = [];
|
|
49
|
+
this.translate = new AWSTranslate.TranslateClient({ region: options.region });
|
|
42
50
|
}
|
|
43
51
|
/**
|
|
44
52
|
* Translates input text from the source language to the target language.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "idea-aws",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "AWS wrappers to use in IDEA's back-ends",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"cognito",
|
|
28
28
|
"comprehend",
|
|
29
29
|
"secretsManager",
|
|
30
|
-
"cloudWatch"
|
|
30
|
+
"cloudWatch",
|
|
31
|
+
"ssm"
|
|
31
32
|
],
|
|
32
33
|
"author": "ITER IDEA <info@iter-idea.com> (https://iter-idea.com)",
|
|
33
34
|
"license": "ISC",
|
|
@@ -36,13 +37,11 @@
|
|
|
36
37
|
},
|
|
37
38
|
"homepage": "https://iter-idea.github.io/IDEA-AWS",
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"@aws-lambda-powertools/metrics": "^1.
|
|
40
|
+
"@aws-lambda-powertools/metrics": "^1.17.0",
|
|
40
41
|
"idea-toolbox": "^7.0.1",
|
|
41
|
-
"nanoid": "^3.3.
|
|
42
|
-
"nodemailer": "^6.9.
|
|
43
|
-
"
|
|
44
|
-
"source-map-support": "^0.5.21",
|
|
45
|
-
"uuid": "^9.0.0"
|
|
42
|
+
"nanoid": "^3.3.7",
|
|
43
|
+
"nodemailer": "^6.9.8",
|
|
44
|
+
"source-map-support": "^0.5.21"
|
|
46
45
|
},
|
|
47
46
|
"peerDependencies": {
|
|
48
47
|
"@aws-sdk/client-cognito-identity-provider": "^3.388.0",
|
|
@@ -64,11 +63,9 @@
|
|
|
64
63
|
},
|
|
65
64
|
"devDependencies": {
|
|
66
65
|
"@tsconfig/node18": "^18.2.0",
|
|
67
|
-
"@types/aws-lambda": "^8.10.
|
|
66
|
+
"@types/aws-lambda": "^8.10.131",
|
|
68
67
|
"@types/node": "^18.17.4",
|
|
69
|
-
"@types/nodemailer": "^6.4.
|
|
70
|
-
"@types/shortid": "^0.0.29",
|
|
71
|
-
"@types/uuid": "^9.0.2",
|
|
68
|
+
"@types/nodemailer": "^6.4.14",
|
|
72
69
|
"@typescript-eslint/eslint-plugin": "^5.47.0",
|
|
73
70
|
"@typescript-eslint/parser": "^5.47.0",
|
|
74
71
|
"eslint": "^8.46.0",
|