idea-aws 4.0.5 → 4.0.7

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.
@@ -1,5 +1,5 @@
1
1
  import * as DDB from '@aws-sdk/lib-dynamodb';
2
- import { AttributeValue, TransactWriteItem } from '@aws-sdk/client-dynamodb';
2
+ import { TransactWriteItem } from '@aws-sdk/client-dynamodb';
3
3
  import * as DDBUtils from '@aws-sdk/util-dynamodb';
4
4
  import { Logger } from './logger';
5
5
  /**
@@ -16,7 +16,7 @@ export declare class DynamoDB {
16
16
  * @data the data in DynamoDB's original format to convert in plain objects
17
17
  * @options the options to use to convert the data
18
18
  */
19
- unmarshall(data: Record<string, AttributeValue>, options?: DDBUtils.unmarshallOptions): Record<string, any>;
19
+ unmarshall(data: Record<string, any>, options?: DDBUtils.unmarshallOptions): Record<string, any>;
20
20
  /**
21
21
  * Returns an IUID: IDEA's Unique IDentifier, which is an id unique through an IDEA's AWS account and region.
22
22
  * Note: no need of an auth check for external uses: the permissions depend from the context in which it's executed.
@@ -72,8 +72,8 @@ export declare class DynamoDB {
72
72
  * @param keys the keys of the objects to retrieve
73
73
  * @param ignoreErr if set, ignore the errors and continue the bulk op.
74
74
  */
75
- batchGet(table: string, keys: Record<string, AttributeValue>[], ignoreErr?: boolean): Promise<any[]>;
76
- protected batchGetHelper(table: string, keys: Record<string, AttributeValue>[], resultElements: Record<string, any>[], ignoreErr: boolean, currentChunk?: number, chunkSize?: number): Promise<Record<string, any>[]>;
75
+ batchGet(table: string, keys: Record<string, any>[], ignoreErr?: boolean): Promise<any[]>;
76
+ protected batchGetHelper(table: string, keys: Record<string, any>[], resultElements: Record<string, any>[], ignoreErr: boolean, currentChunk?: number, chunkSize?: number): Promise<Record<string, any>[]>;
77
77
  /**
78
78
  * Put an array of items in a DynamoDB table, avoiding the limits of DynamoDB's BatchWriteItem.
79
79
  * In case of errors, it will retry with a random back-off mechanism until the timeout.
@@ -89,8 +89,8 @@ export declare class DynamoDB {
89
89
  * @param table the target DynamoDB table
90
90
  * @param keys the keys to delete
91
91
  */
92
- batchDelete(table: string, keys: Record<string, AttributeValue>[]): Promise<void>;
93
- protected batchWriteHelper(table: string, itemsOrKeys: Record<string, any>[] | Record<string, AttributeValue>[], isPut: boolean, currentChunk?: number, chunkSize?: number): Promise<void>;
92
+ batchDelete(table: string, keys: Record<string, any>[]): Promise<void>;
93
+ protected batchWriteHelper(table: string, itemsOrKeys: Record<string, any>[], isPut: boolean, currentChunk?: number, chunkSize?: number): Promise<void>;
94
94
  protected batchWriteChunkWithRetries(table: string, params: DDB.BatchWriteCommandInput): Promise<void>;
95
95
  /**
96
96
  * Query a DynamoDB table, avoiding the limits of DynamoDB's Query.
package/dist/src/ses.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import * as AWSSES from '@aws-sdk/client-sesv2';
2
+ import * as AWSSESv2 from '@aws-sdk/client-sesv2';
3
3
  import { SentMessageInfo as NodemailerSentMessageInfo } from 'nodemailer';
4
4
  import { Headers } from 'nodemailer/lib/mailer';
5
5
  import { Logger } from './logger';
@@ -7,13 +7,13 @@ import { Logger } from './logger';
7
7
  * A wrapper for AWS Simple Email Service.
8
8
  */
9
9
  export declare class SES {
10
- protected ses: AWSSES.SESv2Client;
10
+ protected ses: AWSSESv2.SESv2Client;
11
11
  logger: Logger;
12
12
  constructor(options?: {
13
13
  region?: string;
14
14
  debug: boolean;
15
15
  });
16
- getTemplate(templateName: string): Promise<AWSSES.EmailTemplateContent>;
16
+ getTemplate(templateName: string): Promise<AWSSESv2.EmailTemplateContent>;
17
17
  setTemplate(templateName: string, subject: string, content: string, isHTML?: boolean): Promise<void>;
18
18
  deleteTemplate(templateName: string): Promise<void>;
19
19
  testTemplate(templateName: string, data: {
@@ -22,12 +22,12 @@ export declare class SES {
22
22
  /**
23
23
  * Send a templated email through AWS Simple Email Service.
24
24
  */
25
- sendTemplatedEmail(emailData: TemplatedEmailData, sesParams: SESParams): Promise<AWSSES.SendEmailCommandOutput>;
25
+ sendTemplatedEmail(emailData: TemplatedEmailData, sesParams: SESParams): Promise<AWSSESv2.SendEmailCommandOutput>;
26
26
  /**
27
27
  * Send an email through AWS Simple Email Service.
28
28
  * It supports IDEA's teams custom configuration.
29
29
  */
30
- sendEmail(emailData: EmailData, sesParams: SESParams): Promise<AWSSES.SendEmailResponse | NodemailerSentMessageInfo>;
30
+ sendEmail(emailData: EmailData, sesParams: SESParams): Promise<AWSSESv2.SendEmailResponse | NodemailerSentMessageInfo>;
31
31
  private searchForCustomSESConfigByTeamId;
32
32
  private sendEmailWithSES;
33
33
  private sendEmailWithNodemailer;
package/dist/src/ses.js CHANGED
@@ -24,7 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.SES = void 0;
27
- const AWSSES = __importStar(require("@aws-sdk/client-sesv2"));
27
+ const client_ses_1 = require("@aws-sdk/client-ses");
28
+ const AWSSESv2 = __importStar(require("@aws-sdk/client-sesv2"));
28
29
  const nodemailer_1 = require("nodemailer");
29
30
  const dynamoDB_1 = require("./dynamoDB");
30
31
  const logger_1 = require("./logger");
@@ -34,21 +35,21 @@ const logger_1 = require("./logger");
34
35
  class SES {
35
36
  constructor(options = { debug: true }) {
36
37
  this.logger = new logger_1.Logger();
37
- this.ses = new AWSSES.SESv2Client({ region: options.region });
38
+ this.ses = new AWSSESv2.SESv2Client({ region: options.region });
38
39
  this.logger.level = options.debug ? 'DEBUG' : 'INFO';
39
40
  }
40
41
  //
41
42
  // CONFIG
42
43
  //
43
44
  async getTemplate(templateName) {
44
- const command = new AWSSES.GetEmailTemplateCommand({ TemplateName: templateName });
45
+ const command = new AWSSESv2.GetEmailTemplateCommand({ TemplateName: templateName });
45
46
  const { TemplateContent } = await this.ses.send(command);
46
47
  return TemplateContent;
47
48
  }
48
49
  async setTemplate(templateName, subject, content, isHTML) {
49
50
  let isNew = false;
50
51
  try {
51
- const command = new AWSSES.GetEmailTemplateCommand({ TemplateName: templateName });
52
+ const command = new AWSSESv2.GetEmailTemplateCommand({ TemplateName: templateName });
52
53
  await this.ses.send(command);
53
54
  }
54
55
  catch (notFound) {
@@ -64,17 +65,17 @@ class SES {
64
65
  template.TemplateContent.Text = content;
65
66
  let command;
66
67
  if (isNew)
67
- command = new AWSSES.CreateEmailTemplateCommand(template);
68
+ command = new AWSSESv2.CreateEmailTemplateCommand(template);
68
69
  else
69
- command = new AWSSES.UpdateEmailTemplateCommand(template);
70
+ command = new AWSSESv2.UpdateEmailTemplateCommand(template);
70
71
  await this.ses.send(command);
71
72
  }
72
73
  async deleteTemplate(templateName) {
73
- const command = new AWSSES.DeleteEmailTemplateCommand({ TemplateName: templateName });
74
+ const command = new AWSSESv2.DeleteEmailTemplateCommand({ TemplateName: templateName });
74
75
  await this.ses.send(command);
75
76
  }
76
77
  async testTemplate(templateName, data) {
77
- const command = new AWSSES.TestRenderEmailTemplateCommand({
78
+ const command = new AWSSESv2.TestRenderEmailTemplateCommand({
78
79
  TemplateName: templateName,
79
80
  TemplateData: JSON.stringify(data)
80
81
  });
@@ -88,7 +89,7 @@ class SES {
88
89
  * Send a templated email through AWS Simple Email Service.
89
90
  */
90
91
  async sendTemplatedEmail(emailData, sesParams) {
91
- const command = new AWSSES.SendEmailCommand({
92
+ const command = new AWSSESv2.SendEmailCommand({
92
93
  Destination: this.prepareEmailDestination(emailData),
93
94
  Content: {
94
95
  Template: {
@@ -105,7 +106,7 @@ class SES {
105
106
  if (this.ses.config.region === sesParams.region)
106
107
  ses = this.ses;
107
108
  else
108
- ses = new AWSSES.SESv2Client({ region: sesParams.region });
109
+ ses = new AWSSESv2.SESv2Client({ region: sesParams.region });
109
110
  this.logger.debug('SES send templated email');
110
111
  return await ses.send(command);
111
112
  }
@@ -134,7 +135,7 @@ class SES {
134
135
  }
135
136
  }
136
137
  async sendEmailWithSES(emailData, sesParams) {
137
- const command = new AWSSES.SendEmailCommand({
138
+ const command = new AWSSESv2.SendEmailCommand({
138
139
  Destination: this.prepareEmailDestination(emailData),
139
140
  Content: { Simple: this.prepareEmailMessage(emailData) },
140
141
  ReplyToAddresses: emailData.replyToAddresses,
@@ -145,7 +146,7 @@ class SES {
145
146
  if (this.ses.config.region === sesParams.region)
146
147
  ses = this.ses;
147
148
  else
148
- ses = new AWSSES.SESv2Client({ region: sesParams.region });
149
+ ses = new AWSSESv2.SESv2Client({ region: sesParams.region });
149
150
  this.logger.debug('SES send email');
150
151
  return await ses.send(command);
151
152
  }
@@ -165,11 +166,8 @@ class SES {
165
166
  if (emailData.text)
166
167
  mailOptions.text = emailData.text;
167
168
  mailOptions.attachments = emailData.attachments;
168
- let ses;
169
- if (this.ses.config.region === sesParams.region)
170
- ses = this.ses;
171
- else
172
- ses = new AWSSES.SESv2Client({ region: sesParams.region });
169
+ // note: Nodemailer doesn't support SESv2 as of August 2023
170
+ const ses = new client_ses_1.SESClient({ region: sesParams.region });
173
171
  this.logger.debug('SES send email (Nodemailer)');
174
172
  return await (0, nodemailer_1.createTransport)({ SES: ses }).sendMail(mailOptions);
175
173
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "idea-aws",
3
- "version": "4.0.5",
3
+ "version": "4.0.7",
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",
@@ -52,6 +52,7 @@
52
52
  "@aws-sdk/client-lambda": "^3.388.0",
53
53
  "@aws-sdk/client-s3": "^3.388.0",
54
54
  "@aws-sdk/client-secrets-manager": "^3.389.0",
55
+ "@aws-sdk/client-ses": "^3.398.0",
55
56
  "@aws-sdk/client-sesv2": "^3.388.0",
56
57
  "@aws-sdk/client-sns": "^3.388.0",
57
58
  "@aws-sdk/client-translate": "^3.388.0",