idea-aws 3.11.5 → 3.11.8

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.
File without changes
package/README.md CHANGED
@@ -14,7 +14,7 @@ import { ResourceController } from 'idea-aws';
14
14
 
15
15
  ## Documentation
16
16
 
17
- Documentation generated with TypeDoc: [link](https://uatisdeproblem.github.io/IDEA-AWS).
17
+ Documentation generated with TypeDoc: [link](https://iter-idea.github.io/IDEA-AWS).
18
18
 
19
19
  ## Notes
20
20
 
package/dist/index.js CHANGED
@@ -1,25 +1,13 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./src/genericController"), exports);
14
- __exportStar(require("./src/resourceController"), exports);
15
- __exportStar(require("./src/streamController"), exports);
16
- __exportStar(require("./src/dynamoDB"), exports);
17
- __exportStar(require("./src/cognito"), exports);
18
- __exportStar(require("./src/comprehend"), exports);
19
- __exportStar(require("./src/s3"), exports);
20
- __exportStar(require("./src/secretsManager"), exports);
21
- __exportStar(require("./src/ses"), exports);
22
- __exportStar(require("./src/sns"), exports);
23
- __exportStar(require("./src/translate"), exports);
24
- __exportStar(require("./src/attachments"), exports);
25
- __exportStar(require("./src/logger"), exports);
1
+ export * from './src/genericController';
2
+ export * from './src/resourceController';
3
+ export * from './src/streamController';
4
+ export * from './src/dynamoDB';
5
+ export * from './src/cognito';
6
+ export * from './src/comprehend';
7
+ export * from './src/s3';
8
+ export * from './src/secretsManager';
9
+ export * from './src/ses';
10
+ export * from './src/sns';
11
+ export * from './src/translate';
12
+ export * from './src/attachments';
13
+ export * from './src/logger';
@@ -1,20 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Attachments = void 0;
4
- const dynamoDB_1 = require("./dynamoDB");
5
- const s3_1 = require("./s3");
1
+ import { DynamoDB } from './dynamoDB';
2
+ import { S3 } from './s3';
6
3
  /**
7
4
  * A custom class that takes advantage of DynamoDB and S3 to easily manage attachments.
8
5
  */
9
- class Attachments {
6
+ export class Attachments {
10
7
  constructor() {
11
8
  /**
12
9
  * The bucket where from to retrieve the attachments. Fallback to IDEA's default one.
13
10
  */
14
11
  this.S3_ATTACHMENTS_BUCKET = process.env['S3_ATTACHMENTS_BUCKET'] || 'idea-attachments';
15
12
  this.IUID_ATTACHMENTS_PREFIX = process.env['IUID_ATTACHMENTS_PREFIX'] || 'ATT';
16
- this.dynamo = new dynamoDB_1.DynamoDB();
17
- this.s3 = new s3_1.S3();
13
+ this.dynamo = new DynamoDB();
14
+ this.s3 = new S3();
18
15
  }
19
16
  /**
20
17
  * Get a signedURL to put an attachment.
@@ -35,4 +32,3 @@ class Attachments {
35
32
  return signedURL;
36
33
  }
37
34
  }
38
- exports.Attachments = Attachments;
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Cognito = void 0;
4
- const aws_sdk_1 = require("aws-sdk");
5
- const idea_toolbox_1 = require("idea-toolbox");
1
+ import { CognitoIdentityServiceProvider } from 'aws-sdk';
2
+ import { CognitoUser, isEmpty } from 'idea-toolbox';
6
3
  /**
7
4
  * A wrapper for AWS Cognito.
8
5
  */
9
- class Cognito {
6
+ export class Cognito {
10
7
  constructor(params = {}) {
11
- this.cognito = new aws_sdk_1.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18', region: params.region });
8
+ this.cognito = new CognitoIdentityServiceProvider({ apiVersion: '2016-04-18', region: params.region });
12
9
  }
13
10
  /**
14
11
  * Change the region in which to find the user pool.
@@ -16,7 +13,7 @@ class Cognito {
16
13
  */
17
14
  setRegion(region) {
18
15
  // there is no quick way to change the region without re-creating the object
19
- this.cognito = new aws_sdk_1.CognitoIdentityServiceProvider({ apiVersion: this.cognito.config.apiVersion, region });
16
+ this.cognito = new CognitoIdentityServiceProvider({ apiVersion: this.cognito.config.apiVersion, region });
20
17
  }
21
18
  /**
22
19
  * Get the attributes of the user, from the authorizer claims.
@@ -43,8 +40,8 @@ class Cognito {
43
40
  mapCognitoUserAttributesAsPlainObject(user) {
44
41
  const userAttributes = {};
45
42
  (user.Attributes || user.UserAttributes || []).forEach((a) => (userAttributes[a.Name] = a.Value));
46
- if (!user.userId)
47
- user.userId = user.sub;
43
+ if (!userAttributes.userId)
44
+ userAttributes.userId = userAttributes.sub;
48
45
  return userAttributes;
49
46
  }
50
47
  /**
@@ -78,7 +75,7 @@ class Cognito {
78
75
  params.PaginationToken = options.pagination;
79
76
  const res = await this.cognito.listUsers(params).promise();
80
77
  const pagination = res.PaginationToken;
81
- const users = options.users.concat(res.Users.map(u => new idea_toolbox_1.CognitoUser(this.mapCognitoUserAttributesAsPlainObject(u))));
78
+ const users = options.users.concat(res.Users.map(u => new CognitoUser(this.mapCognitoUserAttributesAsPlainObject(u))));
82
79
  if (pagination)
83
80
  return await this.getAllUsers(cognitoUserPoolId, { pagination, users });
84
81
  else
@@ -92,7 +89,7 @@ class Cognito {
92
89
  const email = typeof cognitoUserOrEmail === 'string'
93
90
  ? cognitoUserOrEmail
94
91
  : cognitoUserOrEmail.email;
95
- if ((0, idea_toolbox_1.isEmpty)(email, 'email'))
92
+ if (isEmpty(email, 'email'))
96
93
  throw new Error('INVALID_EMAIL');
97
94
  const UserAttributes = [
98
95
  { Name: 'email', Value: email },
@@ -124,7 +121,7 @@ class Cognito {
124
121
  * Resend the password to a user who never logged in.
125
122
  */
126
123
  async resendPassword(email, cognitoUserPoolId, options = {}) {
127
- if ((0, idea_toolbox_1.isEmpty)(email, 'email'))
124
+ if (isEmpty(email, 'email'))
128
125
  throw new Error('Invalid email');
129
126
  const params = {
130
127
  UserPoolId: cognitoUserPoolId,
@@ -139,7 +136,7 @@ class Cognito {
139
136
  * Delete a user by its email (username), in the pool specified.
140
137
  */
141
138
  async deleteUser(email, cognitoUserPoolId) {
142
- if ((0, idea_toolbox_1.isEmpty)(email, 'email'))
139
+ if (isEmpty(email, 'email'))
143
140
  throw new Error('Invalid email');
144
141
  await this.cognito.adminDeleteUser({ UserPoolId: cognitoUserPoolId, Username: email }).promise();
145
142
  }
@@ -181,7 +178,7 @@ class Cognito {
181
178
  * Change the email address (== username) associated to a user.
182
179
  */
183
180
  async updateEmail(email, newEmail, cognitoUserPoolId) {
184
- if ((0, idea_toolbox_1.isEmpty)(newEmail, 'email'))
181
+ if (isEmpty(newEmail, 'email'))
185
182
  throw new Error('Invalid new email');
186
183
  await this.cognito
187
184
  .adminUpdateUserAttributes({
@@ -274,14 +271,14 @@ class Cognito {
274
271
  const usersInGroupList = await this.cognito
275
272
  .listUsersInGroup({ UserPoolId: cognitoUserPoolId, GroupName: group })
276
273
  .promise();
277
- const users = usersInGroupList.Users.map(u => new idea_toolbox_1.CognitoUser(this.mapCognitoUserAttributesAsPlainObject(u)));
274
+ const users = usersInGroupList.Users.map(u => new CognitoUser(this.mapCognitoUserAttributesAsPlainObject(u)));
278
275
  return users;
279
276
  }
280
277
  /**
281
278
  * Add a user (by email) to a group in the user pool.
282
279
  */
283
280
  async addUserToGroup(email, group, cognitoUserPoolId) {
284
- const user = new idea_toolbox_1.CognitoUser(await this.getUserByEmail(email, cognitoUserPoolId));
281
+ const user = new CognitoUser(await this.getUserByEmail(email, cognitoUserPoolId));
285
282
  await this.cognito
286
283
  .adminAddUserToGroup({ UserPoolId: cognitoUserPoolId, GroupName: group, Username: user.userId })
287
284
  .promise();
@@ -290,10 +287,9 @@ class Cognito {
290
287
  * Remove a user (by email) from a group in the user pool.
291
288
  */
292
289
  async removeUserFromGroup(email, group, cognitoUserPoolId) {
293
- const user = new idea_toolbox_1.CognitoUser(await this.getUserByEmail(email, cognitoUserPoolId));
290
+ const user = new CognitoUser(await this.getUserByEmail(email, cognitoUserPoolId));
294
291
  await this.cognito
295
292
  .adminRemoveUserFromGroup({ UserPoolId: cognitoUserPoolId, GroupName: group, Username: user.userId })
296
293
  .promise();
297
294
  }
298
295
  }
299
- exports.Cognito = Cognito;
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Comprehend = void 0;
4
- const aws_sdk_1 = require("aws-sdk");
1
+ import { Comprehend as AmazonComprehend } from 'aws-sdk';
5
2
  /**
6
3
  * A wrapper for Amazon Comprehend.
7
4
  */
8
- class Comprehend {
5
+ export class Comprehend {
9
6
  constructor() {
10
- this.comprehend = new aws_sdk_1.Comprehend({ apiVersion: '2017-11-27' });
7
+ this.comprehend = new AmazonComprehend({ apiVersion: '2017-11-27' });
11
8
  }
12
9
  /**
13
10
  * Inspects text and returns an inference of the prevailing sentiment (POSITIVE, NEUTRAL, MIXED, or NEGATIVE).
@@ -21,4 +18,3 @@ class Comprehend {
21
18
  return result.Sentiment;
22
19
  }
23
20
  }
24
- exports.Comprehend = Comprehend;
@@ -1,25 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DynamoDB = void 0;
4
- const aws_sdk_1 = require("aws-sdk");
5
- const uuid_1 = require("uuid");
6
- const nanoid_1 = require("nanoid");
7
- const NanoID = (0, nanoid_1.customAlphabet)('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 25);
8
- const shortid_1 = require("shortid");
9
- const logger_1 = require("./logger");
10
- const logger = new logger_1.Logger();
1
+ import { DynamoDB as DDB } from 'aws-sdk';
2
+ import { v4 as UUIDV4 } from 'uuid';
3
+ import { customAlphabet as AlphabetNanoID } from 'nanoid';
4
+ const NanoID = AlphabetNanoID('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 25);
5
+ import { characters as ShortIdCharacters, generate as ShortIdGenerate } from 'shortid';
6
+ import { Logger } from './logger';
7
+ const logger = new Logger();
11
8
  /**
12
9
  * A wrapper for AWS DynamoDB.
13
10
  */
14
- class DynamoDB {
11
+ export class DynamoDB {
15
12
  constructor() {
16
- this.dynamo = new aws_sdk_1.DynamoDB.DocumentClient();
13
+ this.dynamo = new DDB.DocumentClient();
17
14
  }
18
15
  /**
19
16
  * Convert a JSON object from dynamoDB format to simple JSON.
20
17
  */
21
18
  unmarshall(data, options) {
22
- return aws_sdk_1.DynamoDB.Converter.unmarshall(data, options);
19
+ return DDB.Converter.unmarshall(data, options);
23
20
  }
24
21
  /**
25
22
  * Returns an IUID: IDEA's Unique IDentifier, which is an id unique through all IDEA's projects.
@@ -70,13 +67,13 @@ class DynamoDB {
70
67
  result = `${project}_${id}`;
71
68
  break;
72
69
  case 'IUID':
73
- id = (0, uuid_1.v4)();
70
+ id = UUIDV4();
74
71
  result = `${project}_${id}`;
75
72
  break;
76
73
  case 'ISID':
77
74
  // avoid _ characters (to avoid concatenation problems with ids) -- it must be anyway 64 chars-long
78
- (0, shortid_1.characters)('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-@');
79
- id = (0, shortid_1.generate)();
75
+ ShortIdCharacters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-@');
76
+ id = ShortIdGenerate();
80
77
  result = id;
81
78
  break;
82
79
  }
@@ -305,4 +302,3 @@ class DynamoDB {
305
302
  return this.dynamo.createSet(array, options);
306
303
  }
307
304
  }
308
- exports.DynamoDB = DynamoDB;
@@ -1,27 +1,24 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GenericController = void 0;
4
- const dynamoDB_1 = require("./dynamoDB");
5
- const cognito_1 = require("./cognito");
6
- const s3_1 = require("./s3");
7
- const ses_1 = require("./ses");
8
- const sns_1 = require("./sns");
9
- const translate_1 = require("./translate");
10
- const comprehend_1 = require("./comprehend");
11
- const secretsManager_1 = require("./secretsManager");
12
- const attachments_1 = require("./attachments");
13
- const logger_1 = require("./logger");
1
+ import { DynamoDB } from './dynamoDB';
2
+ import { Cognito } from './cognito';
3
+ import { S3 } from './s3';
4
+ import { SES } from './ses';
5
+ import { SNS } from './sns';
6
+ import { Translate } from './translate';
7
+ import { Comprehend } from './comprehend';
8
+ import { SecretsManager } from './secretsManager';
9
+ import { Attachments } from './attachments';
10
+ import { Logger } from './logger';
14
11
  /**
15
12
  * An abstract class to inherit to manage some resources with an AWS Lambda function.
16
13
  */
17
- class GenericController {
14
+ export class GenericController {
18
15
  /**
19
16
  * Initialize a new GenericController helper object.
20
17
  * @param event the event that invoked the AWS lambda function
21
18
  * @param callback the callback to resolve or reject the execution
22
19
  */
23
20
  constructor(event, callback, options = {}) {
24
- this.logger = new logger_1.Logger();
21
+ this.logger = new Logger();
25
22
  this.event = event;
26
23
  this.callback = callback;
27
24
  this.tables = options.tables || {};
@@ -44,7 +41,7 @@ class GenericController {
44
41
  */
45
42
  get dynamoDB() {
46
43
  if (!this._dynamoDB)
47
- this._dynamoDB = new dynamoDB_1.DynamoDB();
44
+ this._dynamoDB = new DynamoDB();
48
45
  return this._dynamoDB;
49
46
  }
50
47
  set dynamoDB(dynamoDB) {
@@ -55,7 +52,7 @@ class GenericController {
55
52
  */
56
53
  get cognito() {
57
54
  if (!this._cognito)
58
- this._cognito = new cognito_1.Cognito();
55
+ this._cognito = new Cognito();
59
56
  return this._cognito;
60
57
  }
61
58
  set cognito(cognito) {
@@ -66,7 +63,7 @@ class GenericController {
66
63
  */
67
64
  get s3() {
68
65
  if (!this._s3)
69
- this._s3 = new s3_1.S3();
66
+ this._s3 = new S3();
70
67
  return this._s3;
71
68
  }
72
69
  set s3(s3) {
@@ -77,7 +74,7 @@ class GenericController {
77
74
  */
78
75
  get ses() {
79
76
  if (!this._ses)
80
- this._ses = new ses_1.SES();
77
+ this._ses = new SES();
81
78
  return this._ses;
82
79
  }
83
80
  set ses(ses) {
@@ -88,7 +85,7 @@ class GenericController {
88
85
  */
89
86
  get sns() {
90
87
  if (!this._sns)
91
- this._sns = new sns_1.SNS();
88
+ this._sns = new SNS();
92
89
  return this._sns;
93
90
  }
94
91
  set sns(sns) {
@@ -99,7 +96,7 @@ class GenericController {
99
96
  */
100
97
  get translate() {
101
98
  if (!this._translate)
102
- this._translate = new translate_1.Translate();
99
+ this._translate = new Translate();
103
100
  return this._translate;
104
101
  }
105
102
  set translate(translate) {
@@ -110,7 +107,7 @@ class GenericController {
110
107
  */
111
108
  get comprehend() {
112
109
  if (!this._comprehend)
113
- this._comprehend = new comprehend_1.Comprehend();
110
+ this._comprehend = new Comprehend();
114
111
  return this._comprehend;
115
112
  }
116
113
  set comprehend(comprehend) {
@@ -121,7 +118,7 @@ class GenericController {
121
118
  */
122
119
  get secrets() {
123
120
  if (!this._secrets)
124
- this._secrets = new secretsManager_1.SecretsManager();
121
+ this._secrets = new SecretsManager();
125
122
  return this._secrets;
126
123
  }
127
124
  set secrets(secrets) {
@@ -136,11 +133,10 @@ class GenericController {
136
133
  */
137
134
  get attachments() {
138
135
  if (!this._attachments)
139
- this._attachments = new attachments_1.Attachments();
136
+ this._attachments = new Attachments();
140
137
  return this._attachments;
141
138
  }
142
139
  set attachments(attachments) {
143
140
  this._attachments = attachments;
144
141
  }
145
142
  }
146
- exports.GenericController = GenericController;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Logger = void 0;
4
1
  /**
5
2
  * Manage structured logging.
6
3
  */
7
- class Logger {
4
+ export class Logger {
8
5
  constructor({ level = process.env.LOG_LEVEL } = {}) {
9
6
  this.level = (level || 'DEBUG').toUpperCase();
10
7
  this.originalLevel = this.level;
@@ -48,6 +45,5 @@ class Logger {
48
45
  this.level = this.originalLevel;
49
46
  }
50
47
  }
51
- exports.Logger = Logger;
52
48
  // levels here are identical to bunyan practices (https://github.com/trentm/node-bunyan#levels)
53
49
  const LogLevels = { DEBUG: 20, INFO: 30, WARN: 40, ERROR: 50 };
@@ -125,12 +125,12 @@ export declare abstract class ResourceController extends GenericController {
125
125
  t(key: string, interpolateParams?: any): string;
126
126
  /**
127
127
  * Interpolates a string to replace parameters.
128
- * "This is a {{ key }}" ==> "This is a value", with params = { key: "value" }
128
+ * `"This is a {{ key }}"` ==> `"This is a value", with params = { key: "value" }`.
129
129
  */
130
130
  private interpolate;
131
131
  /**
132
132
  * Gets a value from an object by composed key.
133
- * getValue({ key1: { keyA: 'valueI' }}, 'key1.keyA') ==> 'valueI'
133
+ * `getValue({ key1: { keyA: 'valueI' }}, 'key1.keyA')` ==> `'valueI'`.
134
134
  */
135
135
  private getValue;
136
136
  /**
@@ -1,19 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RCError = exports.ResourceController = void 0;
4
- require("source-map-support/register");
5
- const fs_1 = require("fs");
6
- const aws_sdk_1 = require("aws-sdk");
7
- const idea_toolbox_1 = require("idea-toolbox");
8
- const logger_1 = require("./logger");
9
- const genericController_1 = require("./genericController");
1
+ import 'source-map-support/register';
2
+ import { existsSync, readFileSync } from 'fs';
3
+ import { Lambda, EventBridge } from 'aws-sdk';
4
+ import { APIRequestLog, CognitoUser } from 'idea-toolbox';
5
+ import { Logger } from './logger';
6
+ import { GenericController } from './genericController';
10
7
  /**
11
8
  * An abstract class to inherit to manage API requests (AWS API Gateway) in an AWS Lambda function.
12
9
  */
13
- class ResourceController extends genericController_1.GenericController {
10
+ export class ResourceController extends GenericController {
14
11
  constructor(event, callback, options = {}) {
15
12
  super(event, callback, options);
16
- this.logger = new logger_1.Logger();
13
+ this.logger = new Logger();
17
14
  this.templateMatcher = /{{\s?([^{}\s]*)\s?}}/g;
18
15
  ///
19
16
  /// REQUEST HANDLERS
@@ -109,7 +106,7 @@ class ResourceController extends genericController_1.GenericController {
109
106
  const authorizer = event.requestContext?.authorizer ?? {};
110
107
  const contextFromAuthorizer = authorizer.lambda ?? authorizer.jwt?.claims ?? {};
111
108
  this.principalId = contextFromAuthorizer.principalId ?? contextFromAuthorizer.sub ?? null;
112
- this.cognitoUser = authorizer.jwt?.claims ? new idea_toolbox_1.CognitoUser(authorizer.jwt?.claims) : null;
109
+ this.cognitoUser = authorizer.jwt?.claims ? new CognitoUser(authorizer.jwt?.claims) : null;
113
110
  this.stage = event.requestContext.stage;
114
111
  this.httpMethod = event.requestContext.http.method;
115
112
  this.resource = event.routeKey.replace('+', ''); // {proxy+} -> {proxy}
@@ -125,7 +122,7 @@ class ResourceController extends genericController_1.GenericController {
125
122
  this.authorization = event.headers.Authorization;
126
123
  this.claims = event.requestContext.authorizer?.claims || {};
127
124
  this.principalId = this.claims.sub;
128
- this.cognitoUser = this.principalId ? new idea_toolbox_1.CognitoUser(this.claims) : null;
125
+ this.cognitoUser = this.principalId ? new CognitoUser(this.claims) : null;
129
126
  this.stage = event.requestContext.stage;
130
127
  this.httpMethod = event.httpMethod;
131
128
  this.resource = event.resource.replace('+', ''); // {proxy+} -> {proxy}
@@ -242,7 +239,7 @@ class ResourceController extends genericController_1.GenericController {
242
239
  * Store the log associated to the request (no response/error handling).
243
240
  */
244
241
  storeLog(succeeded) {
245
- const log = new idea_toolbox_1.APIRequestLog({
242
+ const log = new APIRequestLog({
246
243
  logId: this.logRequestsWithKey,
247
244
  userId: this.principalId,
248
245
  resource: this.resource,
@@ -263,7 +260,7 @@ class ResourceController extends genericController_1.GenericController {
263
260
  * Search for the specified file path in both the Lambda function's main folder and the layers folder.
264
261
  */
265
262
  sharedResourceExists(filePath) {
266
- return (0, fs_1.existsSync)(`assets/${filePath}`) || (0, fs_1.existsSync)(`/opt/nodejs/assets/${filePath}`);
263
+ return existsSync(`assets/${filePath}`) || existsSync(`/opt/nodejs/assets/${filePath}`);
267
264
  }
268
265
  /**
269
266
  * Load a shared resource in the back-end (translation, template, etc.).
@@ -271,11 +268,11 @@ class ResourceController extends genericController_1.GenericController {
271
268
  */
272
269
  loadSharedResource(filePath) {
273
270
  let path = null;
274
- if ((0, fs_1.existsSync)(`assets/${filePath}`))
271
+ if (existsSync(`assets/${filePath}`))
275
272
  path = `assets/${filePath}`;
276
- else if ((0, fs_1.existsSync)(`/opt/nodejs/assets/${filePath}`))
273
+ else if (existsSync(`/opt/nodejs/assets/${filePath}`))
277
274
  path = `/opt/nodejs/assets/${filePath}`;
278
- return path ? (0, fs_1.readFileSync)(path, { encoding: 'utf-8' }) : null;
275
+ return path ? readFileSync(path, { encoding: 'utf-8' }) : null;
279
276
  }
280
277
  ///
281
278
  /// MANAGE INTERNAL API REQUESTS (lambda invokes masked as API requests)
@@ -299,7 +296,7 @@ class ResourceController extends genericController_1.GenericController {
299
296
  Payload: this.mapEventForInternalApiRequest(params),
300
297
  Qualifier: params.stage || this.stage
301
298
  };
302
- const res = await new aws_sdk_1.Lambda().invoke(lambdaInvokeParams).promise();
299
+ const res = await new Lambda().invoke(lambdaInvokeParams).promise();
303
300
  const payload = JSON.parse(res.Payload);
304
301
  const body = JSON.parse(payload.body);
305
302
  if (Number(payload.statusCode) !== 200)
@@ -313,7 +310,7 @@ class ResourceController extends genericController_1.GenericController {
313
310
  DetailType: params.eventBridge.target,
314
311
  Detail: this.mapEventForInternalApiRequest(params)
315
312
  };
316
- return await new aws_sdk_1.EventBridge().putEvents({ Entries: [request] }).promise();
313
+ return await new EventBridge().putEvents({ Entries: [request] }).promise();
317
314
  }
318
315
  mapEventForInternalApiRequest(params) {
319
316
  const event = JSON.parse(JSON.stringify(this.event));
@@ -379,7 +376,7 @@ class ResourceController extends genericController_1.GenericController {
379
376
  }
380
377
  /**
381
378
  * Interpolates a string to replace parameters.
382
- * "This is a {{ key }}" ==> "This is a value", with params = { key: "value" }
379
+ * `"This is a {{ key }}"` ==> `"This is a value", with params = { key: "value" }`.
383
380
  */
384
381
  interpolate(expr, params) {
385
382
  if (!params || !expr)
@@ -391,7 +388,7 @@ class ResourceController extends genericController_1.GenericController {
391
388
  }
392
389
  /**
393
390
  * Gets a value from an object by composed key.
394
- * getValue({ key1: { keyA: 'valueI' }}, 'key1.keyA') ==> 'valueI'
391
+ * `getValue({ key1: { keyA: 'valueI' }}, 'key1.keyA')` ==> `'valueI'`.
395
392
  */
396
393
  getValue(target, key) {
397
394
  const keys = typeof key === 'string' ? key.split('.') : [key];
@@ -416,14 +413,12 @@ class ResourceController extends genericController_1.GenericController {
416
413
  return value !== undefined && value !== null;
417
414
  }
418
415
  }
419
- exports.ResourceController = ResourceController;
420
416
  /**
421
417
  * Explicitly define a specific type of error to use in the RC's handler, to distinguish it from the normal errors.
422
418
  */
423
- class RCError extends Error {
419
+ export class RCError extends Error {
424
420
  constructor(message) {
425
421
  super(message);
426
422
  Object.setPrototypeOf(this, RCError.prototype);
427
423
  }
428
424
  }
429
- exports.RCError = RCError;
package/dist/src/s3.js CHANGED
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetObjectTypes = exports.S3 = void 0;
4
- const aws_sdk_1 = require("aws-sdk");
5
- const idea_toolbox_1 = require("idea-toolbox");
6
- const logger_1 = require("./logger");
7
- const logger = new logger_1.Logger();
1
+ import { S3 as AWSS3 } from 'aws-sdk';
2
+ import { SignedURL } from 'idea-toolbox';
3
+ import { Logger } from './logger';
4
+ const logger = new Logger();
8
5
  /**
9
6
  * A wrapper for AWS Simple Storage Service.
10
7
  */
11
- class S3 {
8
+ export class S3 {
12
9
  /**
13
10
  * Initialize a new S3 helper object.
14
11
  */
@@ -17,7 +14,7 @@ class S3 {
17
14
  this.DEFAULT_DOWNLOAD_BUCKET = 'idea-downloads';
18
15
  this.DEFAULT_DOWNLOAD_BUCKET_SEC_TO_EXP = 180;
19
16
  this.DEFAULT_UPLOAD_BUCKET_SEC_TO_EXP = 300;
20
- this.s3 = new aws_sdk_1.S3({ apiVersion: '2006-03-01', signatureVersion: 'v4' });
17
+ this.s3 = new AWSS3({ apiVersion: '2006-03-01', signatureVersion: 'v4' });
21
18
  }
22
19
  /**
23
20
  * Create a download link of a piece of data (through S3).
@@ -40,7 +37,7 @@ class S3 {
40
37
  * @param expires seconds after which the signed URL expires
41
38
  */
42
39
  signedURLPut(bucket, key, expires) {
43
- return new idea_toolbox_1.SignedURL({
40
+ return new SignedURL({
44
41
  url: this.s3.getSignedUrl('putObject', {
45
42
  Bucket: bucket,
46
43
  Key: key,
@@ -53,7 +50,7 @@ class S3 {
53
50
  * @param expires seconds after which the signed URL expires
54
51
  */
55
52
  signedURLGet(bucket, key, expires) {
56
- return new idea_toolbox_1.SignedURL({
53
+ return new SignedURL({
57
54
  url: this.s3.getSignedUrl('getObject', {
58
55
  Bucket: bucket,
59
56
  Key: key,
@@ -131,12 +128,11 @@ class S3 {
131
128
  }
132
129
  }
133
130
  }
134
- exports.S3 = S3;
135
131
  /**
136
132
  * The managed types to convert objects coming from an S3 bucket.
137
133
  */
138
- var GetObjectTypes;
134
+ export var GetObjectTypes;
139
135
  (function (GetObjectTypes) {
140
136
  GetObjectTypes["JSON"] = "JSON";
141
137
  GetObjectTypes["TEXT"] = "TEXT";
142
- })(GetObjectTypes = exports.GetObjectTypes || (exports.GetObjectTypes = {}));
138
+ })(GetObjectTypes || (GetObjectTypes = {}));
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SecretsManager = void 0;
4
- const aws_sdk_1 = require("aws-sdk");
1
+ import { SecretsManager as AWSSecretsManager } from 'aws-sdk';
5
2
  /**
6
3
  * A wrapper for AWS Secrets manager.
7
4
  */
8
- class SecretsManager {
5
+ export class SecretsManager {
9
6
  constructor() {
10
- this.sm = new aws_sdk_1.SecretsManager();
7
+ this.sm = new AWSSecretsManager();
11
8
  }
12
9
  /**
13
10
  * Get a secret string from the Secret Manager by its id.
@@ -17,4 +14,3 @@ class SecretsManager {
17
14
  return result.SecretString;
18
15
  }
19
16
  }
20
- exports.SecretsManager = SecretsManager;
package/dist/src/ses.js CHANGED
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SES = void 0;
4
- const aws_sdk_1 = require("aws-sdk");
5
- const nodemailer_1 = require("nodemailer");
6
- const dynamoDB_1 = require("./dynamoDB");
7
- const logger_1 = require("./logger");
8
- const logger = new logger_1.Logger();
1
+ import { SES as AWSSES } from 'aws-sdk';
2
+ import { createTransport as NodemailerCreateTransport } from 'nodemailer';
3
+ import { DynamoDB } from './dynamoDB';
4
+ import { Logger } from './logger';
5
+ const logger = new Logger();
9
6
  /**
10
7
  * A wrapper for AWS Simple Email Service.
11
8
  */
12
- class SES {
9
+ export class SES {
13
10
  constructor(params = {}) {
14
- this.ses = new aws_sdk_1.SES({ region: params.region });
11
+ this.ses = new AWSSES({ region: params.region });
15
12
  }
16
13
  //
17
14
  // CONFIG
@@ -63,7 +60,7 @@ class SES {
63
60
  if (this.ses.config.region === sesParams.region)
64
61
  ses = this.ses;
65
62
  else
66
- ses = new aws_sdk_1.SES({ region: sesParams.region });
63
+ ses = new AWSSES({ region: sesParams.region });
67
64
  logger.debug('SES send templated email');
68
65
  return await ses.sendTemplatedEmail(request).promise();
69
66
  }
@@ -85,7 +82,7 @@ class SES {
85
82
  if (!teamId)
86
83
  return null;
87
84
  try {
88
- return await new dynamoDB_1.DynamoDB().get({ TableName: 'idea_teamsSES', Key: { teamId } });
85
+ return await new DynamoDB().get({ TableName: 'idea_teamsSES', Key: { teamId } });
89
86
  }
90
87
  catch (err) {
91
88
  return null;
@@ -103,7 +100,7 @@ class SES {
103
100
  if (this.ses.config.region === sesParams.region)
104
101
  ses = this.ses;
105
102
  else
106
- ses = new aws_sdk_1.SES({ region: sesParams.region });
103
+ ses = new AWSSES({ region: sesParams.region });
107
104
  logger.debug('SES send email');
108
105
  return await ses.sendEmail(request).promise();
109
106
  }
@@ -127,9 +124,9 @@ class SES {
127
124
  if (this.ses.config.region === sesParams.region)
128
125
  ses = this.ses;
129
126
  else
130
- ses = new aws_sdk_1.SES({ region: sesParams.region });
127
+ ses = new AWSSES({ region: sesParams.region });
131
128
  logger.debug('SES send email (Nodemailer)');
132
- return await (0, nodemailer_1.createTransport)({ SES: ses }).sendMail(mailOptions);
129
+ return await NodemailerCreateTransport({ SES: ses }).sendMail(mailOptions);
133
130
  }
134
131
  prepareEmailDestination(emailData) {
135
132
  return {
@@ -152,4 +149,3 @@ class SES {
152
149
  return message;
153
150
  }
154
151
  }
155
- exports.SES = SES;
package/dist/src/sns.js CHANGED
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SNS = void 0;
4
- const aws_sdk_1 = require("aws-sdk");
5
- const idea_toolbox_1 = require("idea-toolbox");
1
+ import { SNS as AWSSNS } from 'aws-sdk';
2
+ import { PushNotificationsPlatforms, logger } from 'idea-toolbox';
6
3
  /**
7
4
  * A wrapper for AWS Simple Notification Service.
8
5
  */
9
- class SNS {
6
+ export class SNS {
10
7
  /**
11
8
  * Create a new endpoint in the SNS platform specified.
12
9
  * @return platform endpoint ARN
@@ -14,20 +11,20 @@ class SNS {
14
11
  async createPushPlatormEndpoint(platform, token, snsParams) {
15
12
  let platformARN;
16
13
  switch (platform) {
17
- case idea_toolbox_1.PushNotificationsPlatforms.APNS:
14
+ case PushNotificationsPlatforms.APNS:
18
15
  platformARN = snsParams.appleArn;
19
16
  break;
20
- case idea_toolbox_1.PushNotificationsPlatforms.APNS_SANDBOX:
17
+ case PushNotificationsPlatforms.APNS_SANDBOX:
21
18
  platformARN = snsParams.appleDevArn;
22
19
  break;
23
- case idea_toolbox_1.PushNotificationsPlatforms.FCM:
20
+ case PushNotificationsPlatforms.FCM:
24
21
  platformARN = snsParams.androidArn;
25
22
  break;
26
23
  default:
27
24
  throw new Error('Unsupported platform');
28
25
  }
29
- (0, idea_toolbox_1.logger)('SNS ADD PLATFORM ENDPOINT');
30
- const result = await new aws_sdk_1.SNS({ apiVersion: '2010-03-31', region: snsParams.region })
26
+ logger('SNS ADD PLATFORM ENDPOINT');
27
+ const result = await new AWSSNS({ apiVersion: '2010-03-31', region: snsParams.region })
31
28
  .createPlatformEndpoint({ PlatformApplicationArn: platformARN, Token: token })
32
29
  .promise();
33
30
  return result.EndpointArn;
@@ -41,13 +38,13 @@ class SNS {
41
38
  structuredMessage = { default: JSON.stringify(snsParams.json) };
42
39
  else
43
40
  switch (snsParams.platform) {
44
- case idea_toolbox_1.PushNotificationsPlatforms.APNS:
41
+ case PushNotificationsPlatforms.APNS:
45
42
  structuredMessage = { APNS: JSON.stringify({ aps: { alert: snsParams.message } }) };
46
43
  break;
47
- case idea_toolbox_1.PushNotificationsPlatforms.APNS_SANDBOX:
44
+ case PushNotificationsPlatforms.APNS_SANDBOX:
48
45
  structuredMessage = { APNS_SANDBOX: JSON.stringify({ aps: { alert: snsParams.message } }) };
49
46
  break;
50
- case idea_toolbox_1.PushNotificationsPlatforms.FCM:
47
+ case PushNotificationsPlatforms.FCM:
51
48
  structuredMessage = {
52
49
  GCM: JSON.stringify({ notification: { body: snsParams.message, title: snsParams.message } })
53
50
  };
@@ -55,10 +52,9 @@ class SNS {
55
52
  default:
56
53
  throw new Error('Unsupported platform');
57
54
  }
58
- (0, idea_toolbox_1.logger)('SNS PUBLISH IN TOPIC');
59
- return await new aws_sdk_1.SNS({ apiVersion: '2010-03-31', region: snsParams.region })
55
+ logger('SNS PUBLISH IN TOPIC');
56
+ return await new AWSSNS({ apiVersion: '2010-03-31', region: snsParams.region })
60
57
  .publish({ MessageStructure: 'json', Message: JSON.stringify(structuredMessage), TargetArn: snsParams.endpoint })
61
58
  .promise();
62
59
  }
63
60
  }
64
- exports.SNS = SNS;
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StreamController = void 0;
4
- const genericController_1 = require("./genericController");
5
- const logger_1 = require("./logger");
6
- const logger = new logger_1.Logger();
1
+ import { GenericController } from './genericController';
2
+ import { Logger } from './logger';
3
+ const logger = new Logger();
7
4
  /**
8
5
  * An abstract class to inherit to manage AWS DDB streams in an AWS Lambda function.
9
6
  */
10
- class StreamController extends genericController_1.GenericController {
7
+ export class StreamController extends GenericController {
11
8
  constructor(event, callback, options = {}) {
12
9
  super(event, callback, options);
13
10
  this.records = event.Records || [];
14
11
  logger.info(`START STREAM: ${this.records.length || 0} records`);
15
12
  }
16
13
  }
17
- exports.StreamController = StreamController;
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Translate = void 0;
4
- const aws_sdk_1 = require("aws-sdk");
5
- const idea_toolbox_1 = require("idea-toolbox");
1
+ import { Translate as AWSTranslate } from 'aws-sdk';
2
+ import { PDFTemplateSectionTypes } from 'idea-toolbox';
6
3
  /**
7
4
  * A wrapper for Amazon Translate.
8
5
  */
9
- class Translate {
6
+ export class Translate {
10
7
  /**
11
8
  * Initialize a new Translate helper object.
12
9
  */
13
10
  constructor() {
14
- this.translate = new aws_sdk_1.Translate({ apiVersion: '2017-07-01' });
11
+ this.translate = new AWSTranslate({ apiVersion: '2017-07-01' });
15
12
  this.sourceLanguageCode = 'en';
16
13
  this.targetLanguageCode = 'en';
17
14
  this.terminologyNames = new Array();
@@ -72,10 +69,10 @@ class Translate {
72
69
  const toTranslate = new Set();
73
70
  // gather the terms to translate from contents available on this level
74
71
  template
75
- .filter(s => s.isEither(idea_toolbox_1.PDFTemplateSectionTypes.ROW, idea_toolbox_1.PDFTemplateSectionTypes.HEADER))
72
+ .filter(s => s.isEither(PDFTemplateSectionTypes.ROW, PDFTemplateSectionTypes.HEADER))
76
73
  .forEach(s => {
77
74
  switch (s.type) {
78
- case idea_toolbox_1.PDFTemplateSectionTypes.ROW:
75
+ case PDFTemplateSectionTypes.ROW:
79
76
  s.columns
80
77
  .filter((_, index) => s.doesColumnContainAField(index))
81
78
  .forEach(field => {
@@ -93,7 +90,7 @@ class Translate {
93
90
  }
94
91
  });
95
92
  break;
96
- case idea_toolbox_1.PDFTemplateSectionTypes.HEADER:
93
+ case PDFTemplateSectionTypes.HEADER:
97
94
  toTranslate.add(s.title[sourceLanguage]);
98
95
  break;
99
96
  }
@@ -101,13 +98,13 @@ class Translate {
101
98
  // gather inner sections in a flat structure for further elaboraton
102
99
  const innerSections = new Array();
103
100
  template
104
- .filter(s => s.isEither(idea_toolbox_1.PDFTemplateSectionTypes.INNER_SECTION, idea_toolbox_1.PDFTemplateSectionTypes.REPEATED_INNER_SECTION))
101
+ .filter(s => s.isEither(PDFTemplateSectionTypes.INNER_SECTION, PDFTemplateSectionTypes.REPEATED_INNER_SECTION))
105
102
  .forEach(s => {
106
103
  switch (s.type) {
107
- case idea_toolbox_1.PDFTemplateSectionTypes.INNER_SECTION:
104
+ case PDFTemplateSectionTypes.INNER_SECTION:
108
105
  innerSections.push({ data: entity[s.context], template: s.innerTemplate });
109
106
  break;
110
- case idea_toolbox_1.PDFTemplateSectionTypes.REPEATED_INNER_SECTION:
107
+ case PDFTemplateSectionTypes.REPEATED_INNER_SECTION:
111
108
  entity[s.context].forEach((element) => innerSections.push({ data: element, template: s.innerTemplate }));
112
109
  break;
113
110
  }
@@ -121,4 +118,3 @@ class Translate {
121
118
  return toTranslate;
122
119
  }
123
120
  }
124
- exports.Translate = Translate;
package/package.json CHANGED
@@ -1,19 +1,20 @@
1
1
  {
2
2
  "name": "idea-aws",
3
- "version": "3.11.5",
3
+ "version": "3.11.8",
4
4
  "description": "AWS wrappers to use in IDEA's back-ends",
5
+ "type": "module",
5
6
  "main": "dist/index.js",
6
7
  "types": "dist/index.d.ts",
7
8
  "scripts": {
8
9
  "lint": "eslint --ext .ts",
9
10
  "compile": "tsc --build",
10
- "docs": "typedoc",
11
+ "docs": "typedoc index.ts",
11
12
  "build": "./build.sh",
12
13
  "publishPackage": "./build.sh && npm publish"
13
14
  },
14
15
  "repository": {
15
16
  "type": "git",
16
- "url": "git+https://github.com/uatisdeproblem/IDEA-AWS.git"
17
+ "url": "git+https://github.com/iter-idea/IDEA-AWS.git"
17
18
  },
18
19
  "keywords": [
19
20
  "idea",
@@ -31,19 +32,19 @@
31
32
  "author": "ITER IDEA <info@iter-idea.com> (https://iter-idea.com)",
32
33
  "license": "ISC",
33
34
  "bugs": {
34
- "url": "https://github.com/uatisdeproblem/IDEA-AWS/issues"
35
+ "url": "https://github.com/iter-idea/IDEA-AWS/issues"
35
36
  },
36
- "homepage": "https://uatisdeproblem.github.io/IDEA-AWS",
37
+ "homepage": "https://iter-idea.github.io/IDEA-AWS",
37
38
  "dependencies": {
38
- "idea-toolbox": "^6.5.14",
39
- "nanoid": "^3.2.0",
40
- "nodemailer": "^6.7.2",
39
+ "idea-toolbox": "^6.5.17",
40
+ "nanoid": "^4.0.0",
41
+ "nodemailer": "^6.7.5",
41
42
  "shortid": "^2.2.16",
42
43
  "source-map-support": "^0.5.21",
43
44
  "uuid": "^8.3.2"
44
45
  },
45
46
  "devDependencies": {
46
- "@tsconfig/node14": "^1.0.0",
47
+ "@tsconfig/node16": "^1.0.3",
47
48
  "@types/aws-lambda": "^8.10.91",
48
49
  "@types/node": "^14.14.26",
49
50
  "@types/nodemailer": "^6.4.4",
@@ -53,7 +54,7 @@
53
54
  "@typescript-eslint/parser": "^4.31.1",
54
55
  "aws-sdk": "^2.991.0",
55
56
  "eslint": "^7.32.0",
56
- "typedoc": "^0.22.4",
57
+ "typedoc": "^0.23.2",
57
58
  "typescript": "^4.4.3"
58
59
  }
59
60
  }