@cn-shell/aws-utils
Version:
A Cloud Native extension for AWS
121 lines (120 loc) • 3.29 kB
JavaScript
;
var __createBinding =
(this && this.__createBinding) ||
(Object.create
? function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, {
enumerable: true,
get: function() {
return m[k];
},
});
}
: function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
});
var __setModuleDefault =
(this && this.__setModuleDefault) ||
(Object.create
? function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}
: function(o, v) {
o["default"] = v;
});
var __importStar =
(this && this.__importStar) ||
function(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault =
(this && this.__importDefault) ||
function(mod) {
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SESv2 = void 0;
// imports here
const Aws = __importStar(require("./aws-base"));
const sesv2_1 = __importDefault(require("aws-sdk/clients/sesv2"));
// import AWS from "aws-sdk/global";
// AWS.config.logger = console;
// S3 consts here
const SES_API_VER = "2019-09-27";
const SES_CHARSET = "UTF-8";
// Class Bucket here
class SESv2 extends Aws.Base {
// Constructor here
constructor(name, opts) {
super(name, opts);
// Create AWS service objects
this._ses = new sesv2_1.default({
region: this._region,
apiVersion: SES_API_VER,
});
this._source = `${opts.source}@${opts.domain}`;
this._replyTo = `${opts.replyTo}@${opts.domain}`;
this._arn = opts.arn;
}
// Public and Private methods here
async start() {
return true;
}
async stop() {}
async healthCheck() {
return true;
}
async send(request) {
let params = {
Destination: {
ToAddresses: request.to,
CcAddresses: request.cc,
BccAddresses: request.bcc,
},
Content: {},
FromEmailAddress: this._source,
ReplyToAddresses: [this._replyTo],
FromEmailAddressIdentityArn: this._arn,
};
// This is crap but if you mark Html or Text as undefiend the API errors
if (request.bodyIsHtml) {
params.Content = {
Simple: {
Body: {
Html: { Data: request.body, Charset: SES_CHARSET },
},
Subject: { Data: request.subject, Charset: SES_CHARSET },
},
};
} else {
params.Content = {
Simple: {
Body: {
Text: { Data: request.body, Charset: SES_CHARSET },
},
Subject: { Data: request.subject, Charset: SES_CHARSET },
},
};
}
let res = await this._ses
.sendEmail(params)
.promise()
.catch(e => {
this.error("send Error: (%s: %s). Request was (%j)", e.code, e, params);
});
if (typeof res === "object") {
return res === null || res === void 0 ? void 0 : res.MessageId;
}
return;
}
}
exports.SESv2 = SESv2;