Skip to content

Commit

Permalink
fix(api): Added support for Ethereal authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Jun 19, 2024
1 parent 21a28a1 commit 56b2205
Show file tree
Hide file tree
Showing 5 changed files with 1,156 additions and 844 deletions.
5 changes: 4 additions & 1 deletion .ncurc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ module.exports = {
upgrade: true,
reject: [
// API changes break existing tests
'proxy'
'proxy',

// API changes
'eslint'
]
};
19 changes: 13 additions & 6 deletions lib/nodemailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const packageData = require('../package.json');

const ETHEREAL_API = (process.env.ETHEREAL_API || 'https://api.nodemailer.com').replace(/\/+$/, '');
const ETHEREAL_WEB = (process.env.ETHEREAL_WEB || 'https://ethereal.email').replace(/\/+$/, '');
const ETHEREAL_API_KEY = (process.env.ETHEREAL_API_KEY || '').replace(/\s*/g, '') || null;
const ETHEREAL_CACHE = ['true', 'yes', 'y', '1'].includes((process.env.ETHEREAL_CACHE || 'yes').toString().trim().toLowerCase());

let testAccount = false;
Expand Down Expand Up @@ -79,15 +80,21 @@ module.exports.createTestAccount = function (apiUrl, callback) {
let chunks = [];
let chunklen = 0;

let requestHeaders = {};
let requestBody = {
requestor: packageData.name,
version: packageData.version
};

if (ETHEREAL_API_KEY) {
requestHeaders.Authorization = 'Bearer ' + ETHEREAL_API_KEY;
}

let req = nmfetch(apiUrl + '/user', {
contentType: 'application/json',
method: 'POST',
body: Buffer.from(
JSON.stringify({
requestor: packageData.name,
version: packageData.version
})
)
headers: requestHeaders,
body: Buffer.from(JSON.stringify(requestBody))
});

req.on('readable', () => {
Expand Down
Loading

0 comments on commit 56b2205

Please sign in to comment.