Skip to content

Commit

Permalink
feat: add originalResults field to the SendMessageInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmcconville committed Dec 14, 2023
1 parent 8d4abaa commit e8c1230
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Models, Client } from 'postmark'
import { Models, Client } from 'postmark';

declare module 'nodemailer-postmark-transport' {
type Callback<T> = (error: (Error | null), result: (T | null)) => void;
Expand All @@ -7,6 +7,7 @@ declare module 'nodemailer-postmark-transport' {
messageId?: string;
accepted: Array<Models.MessageSendingResponse>;
rejected: Array<Models.MessageSendingResponse>;
originalResults: Array<Models.MessageSendingResponse>;
}

export interface PostmarkTransportOptions {
Expand Down
13 changes: 7 additions & 6 deletions lib/postmark-transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,16 @@ PostmarkTransport.prototype._requestFactory = function (method) {
const accepted = [];
const rejected = [];

this.client[method](payload, (err, results) => {
this.client[method](payload, (err, originalResults) => {
if (err) {
return callback(err);
}

if (!Array.isArray(results)) {
results = [results];
if (!Array.isArray(originalResults)) {
originalResults = [originalResults];
}

results.forEach((result) => {
originalResults.forEach((result) => {
if (result.ErrorCode === 0) {
accepted.push(result);
} else {
Expand All @@ -220,9 +220,10 @@ PostmarkTransport.prototype._requestFactory = function (method) {
});

return callback(null, {
messageId: (results[0] || {}).MessageID,
messageId: (originalResults[0] || {}).MessageID,
accepted: accepted,
rejected: rejected
rejected: rejected,
originalResults
});
});
};
Expand Down

0 comments on commit e8c1230

Please sign in to comment.