diff --git a/index.js b/index.js index ed2ad7c..8f2d0ed 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ const zlib = require('zlib'); const { Buffer } = require('buffer'); const { promisify } = require('util'); -const AWS = require('aws-sdk'); +const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3'); const sharp = require('sharp'); const _ = require('lodash'); const debug = require('debug')('nodemailer-base64-to-s3'); @@ -46,14 +46,7 @@ const base64ToS3 = (options = {}) => { if (_.startsWith(opts.dir, '/')) opts.dir = opts.dir.slice(1); // prepare AWS upload using config - const s3 = new AWS.S3(opts.aws); - - // we cannot currently use this since it does not return a promise - // - // await s3obj.upload({ Body }).promise(); - // - // so instead we use promisify to convert it to a promise - const upload = promisify(s3.upload).bind(s3); + const s3Client = new S3Client(opts.aws); async function compile(mail, fn) { try { @@ -124,6 +117,7 @@ const base64ToS3 = (options = {}) => { const Key = `${opts.dir}${fileName}`; const obj = { + ...opts.aws.params, Key, ACL: 'public-read', Body, @@ -135,7 +129,9 @@ const base64ToS3 = (options = {}) => { // use a fallback dir if the upload fails // but only if the environment is not production try { - const data = cache[Key] ? cache[Key] : await upload(obj); + const data = cache[Key] + ? cache[Key] + : await s3Client.send(new PutObjectCommand(obj)); if (cache[Key]) debug(`hitting cache for ${Key}`); const replacement = isSANB(opts.cloudFrontDomainName) diff --git a/package.json b/package.json index 79fc21d..fd1862d 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "Nick Baugh (http://niftylettuce.com/)" ], "dependencies": { - "aws-sdk": "^2.1152.0", + "@aws-sdk/client-s3": "^3.373.0", "debug": "^4.3.4", "is-string-and-not-blank": "^0.0.2", "lodash": "^4.17.21", @@ -30,7 +30,7 @@ "cheerio": "^1.0.0-rc.11", "cross-env": "^7.0.3", "dotenv": "^16.0.1", - "eslint": "^8.17.0", + "eslint": "8.39.0", "eslint-config-xo-lass": "^2.0.1", "fixpack": "^4.0.0", "husky": "^8.0.1", diff --git a/test/test.js b/test/test.js index 6a7000f..06662d6 100644 --- a/test/test.js +++ b/test/test.js @@ -30,6 +30,7 @@ transport.use( dir: 'nodemailer/', cloudFrontDomainName: process.env.AWS_CLOUDFRONT_DOMAIN, aws: { + region: process.env.AWS_REGION, accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, params: {