Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mailjet source operating on array instead object #2999

Merged
merged 5 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/v0/sources/mailjet/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ const path = require('path');
const fs = require('fs');
const md5 = require('md5');
const Message = require('../message');
const { CommonUtils } = require('../../../util/common');

// ref : https://dev.mailjet.com/email/guides/webhooks/
// import mapping json using JSON.parse to preserve object key order
const mapping = JSON.parse(fs.readFileSync(path.resolve(__dirname, './mapping.json'), 'utf-8'));

function process(event) {
const processEvent = (event) => {
const message = new Message(`MailJet`);

// event type is always track
const eventType = 'track';

message.setEventType(eventType);

message.setEventName(event.event);

message.setPropertiesV2(event, mapping);

if (event.time) {
Expand Down Expand Up @@ -46,6 +43,12 @@ function process(event) {
message.userId = md5(event.email);
}
return message;
}
};

// This fucntion just converts the incoming payload to array of already not and sends it to processEvent
const process = (events) => {
const eventsArray = CommonUtils.toArray(events);
return eventsArray.map(processEvent);
};

module.exports = { process };
258 changes: 189 additions & 69 deletions test/__tests__/data/mailjet_source.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
[
{
"description": "MailJet email open event",
"input": {
"event": "open",
"time": 1664443614,
"MessageID": 94857068804950690,
"Message_GUID": "54d6cdec-f659-4547-8926-13d9c4126b82",
"email": "[email protected]",
"mj_campaign_id": 108760,
"mj_contact_id": 399962859,
"customcampaign": "mj.nl=58424",
"ip": "66.249.84.231",
"geo": "US",
"agent": "Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko Firefox/11.0 (via ggpht.com GoogleImageProxy)",
"CustomID": "",
"Payload": ""
},
"output": {
"Message": {
"input": [
{
"event": "open",
"time": 1664443614,
"MessageID": 94857068804950690,
"Message_GUID": "54d6cdec-f659-4547-8926-13d9c4126b82",
"email": "[email protected]",
"mj_campaign_id": 108760,
"mj_contact_id": 399962859,
"customcampaign": "mj.nl=58424",
"ip": "66.249.84.231",
"geo": "US",
"agent": "Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko Firefox/11.0 (via ggpht.com GoogleImageProxy)",
"CustomID": "",
"Payload": ""
}
],
"output": [
{
"context": {
"library": {
"name": "unknown",
Expand Down Expand Up @@ -52,10 +54,10 @@
"originalTimestamp": "2022-09-29T09:26:54.000Z",
"userId": "5b6a3426dba2cb24e4f0aeec43bee9d7"
}
}
]
},
{
"description": "MailJet email bounce event",
"description": "MailJet email bounce event where input event is of type ",
"input": {
"event": "bounce",
"time": 1664444171,
Expand All @@ -70,8 +72,8 @@
"error_related_to": "system",
"error": "connection issue"
},
"output": {
"Message": {
"output": [
{
"context": {
"library": {
"name": "unknown",
Expand Down Expand Up @@ -102,23 +104,25 @@
"originalTimestamp": "2022-09-29T09:36:11.000Z",
"userId": "5b6a3426dba2cb24e4f0aeec43bee9d7"
}
}
]
},
{
"description": "MailJet email sent event",
"input": {
"event": "sent",
"time": 1664444171,
"MessageID": 92886743924596480,
"Message_GUID": "0230c73a-2b77-4aea-8ef2-ed15d0edc5fd",
"email": "[email protected]",
"mj_campaign_id": 108892,
"mj_contact_id": 372651182,
"customcampaign": "mj.nl=58486",
"smtp_reply": "250 2.0.0 OK DMARC:Quarantine 1664444171 u17-20020adfdd51000000b0022cc3f2bf13si3225188wrm.271 - gsmtp"
},
"output": {
"Message": {
"input": [
{
"event": "sent",
"time": 1664444171,
"MessageID": 92886743924596480,
"Message_GUID": "0230c73a-2b77-4aea-8ef2-ed15d0edc5fd",
"email": "[email protected]",
"mj_campaign_id": 108892,
"mj_contact_id": 372651182,
"customcampaign": "mj.nl=58486",
"smtp_reply": "250 2.0.0 OK DMARC:Quarantine 1664444171 u17-20020adfdd51000000b0022cc3f2bf13si3225188wrm.271 - gsmtp"
}
],
"output": [
{
"context": {
"library": {
"name": "unknown",
Expand Down Expand Up @@ -149,26 +153,28 @@
"originalTimestamp": "2022-09-29T09:36:11.000Z",
"userId": "5b6a3426dba2cb24e4f0aeec43bee9d7"
}
}
]
},
{
"description": "MailJet email bounce event",
"input": {
"event": "bounce",
"time": 1664444170,
"MessageID": 56013522696710744,
"Message_GUID": "dbe4f0a3-4a5a-4784-a724-a9794d3c0444",
"email": "[email protected]",
"mj_campaign_id": 108892,
"mj_contact_id": 373142182,
"customcampaign": "mj.nl=58486",
"blocked": false,
"hard_bounce": false,
"error_related_to": "system",
"error": "connection issue"
},
"output": {
"Message": {
"input": [
{
"event": "bounce",
"time": 1664444170,
"MessageID": 56013522696710744,
"Message_GUID": "dbe4f0a3-4a5a-4784-a724-a9794d3c0444",
"email": "[email protected]",
"mj_campaign_id": 108892,
"mj_contact_id": 373142182,
"customcampaign": "mj.nl=58486",
"blocked": false,
"hard_bounce": false,
"error_related_to": "system",
"error": "connection issue"
}
],
"output": [
{
"context": {
"library": {
"name": "unknown",
Expand Down Expand Up @@ -199,25 +205,27 @@
"originalTimestamp": "2022-09-29T09:36:10.000Z",
"userId": "5b6a3426dba2cb24e4f0aeec43bee9d7"
}
}
]
},
{
"description": "MailJet when no email is present",
"input": {
"event": "bounce",
"time": 1664444170,
"MessageID": 56013522696710744,
"Message_GUID": "dbe4f0a3-4a5a-4784-a724-a9794d3c0444",
"mj_campaign_id": 108892,
"mj_contact_id": 373142182,
"customcampaign": "mj.nl=58486",
"blocked": false,
"hard_bounce": false,
"error_related_to": "system",
"error": "connection issue"
},
"output": {
"Message": {
"input": [
{
"event": "bounce",
"time": 1664444170,
"MessageID": 56013522696710744,
"Message_GUID": "dbe4f0a3-4a5a-4784-a724-a9794d3c0444",
"mj_campaign_id": 108892,
"mj_contact_id": 373142182,
"customcampaign": "mj.nl=58486",
"blocked": false,
"hard_bounce": false,
"error_related_to": "system",
"error": "connection issue"
}
],
"output": [
{
"context": {
"library": {
"name": "unknown",
Expand All @@ -244,6 +252,118 @@
},
"originalTimestamp": "2022-09-29T09:36:10.000Z"
}
}
]
},
{
"description": "MailJet Multiple payloads in single request",
"input": [
{
"event": "open",
"time": 1704458040,
"MessageID": 987654,
"Message_GUID": "876r-oihugyf-7tfygh",
"email": "[email protected]",
"mj_campaign_id": 321,
"mj_contact_id": 123,
"customcampaign": "test_campaign",
"url": "https://www.example.com/",
"ip": "ip_info",
"geo": "some geo info",
"agent": "mailjet api test"
},
{
"event": "click",
"time": 1704458041,
"MessageID": 12345234567,
"Message_GUID": "12345-kjhgfd-2efv",
"email": "[email protected]",
"mj_campaign_id": 12,
"mj_contact_id": 32532,
"customcampaign": "test_campaign",
"url": "https://www.example.com/",
"ip": "ip_info",
"geo": "some geo info",
"agent": "mailjet api test"
}
],
"output": [
{
"context": {
"library": {
"name": "unknown",
"version": "unknown"
},
"ip": "ip_info",
"integration": {
"name": "MailJet"
},
"traits": {
"email": "[email protected]"
},
"page": {
"url": "https://www.example.com/"
},
"userAgent": "mailjet api test",
"externalId": [
{
"type": "mailjetContactId",
"id": 123
}
]
},
"integrations": {
"MailJet": false
},
"type": "track",
"event": "open",
"properties": {
"customcampaign": "test_campaign",
"mj_campaign_id": 321,
"ip": "ip_info",
"url": "https://www.example.com/"
},
"userId": "593a5aff0b445b3b77a6d9676b7ec86e",
"originalTimestamp": "2024-01-05T12:34:00.000Z"
},
{
"context": {
"library": {
"name": "unknown",
"version": "unknown"
},
"page": {
"url": "https://www.example.com/"
},

"integration": {
"name": "MailJet"
},
"traits": {
"email": "[email protected]"
},
"userAgent": "mailjet api test",
"ip": "ip_info",
"externalId": [
{
"type": "mailjetContactId",
"id": 32532
}
]
},
"integrations": {
"MailJet": false
},
"type": "track",
"event": "click",
"properties": {
"customcampaign": "test_campaign",
"mj_campaign_id": 12,
"ip": "ip_info",
"url": "https://www.example.com/"
},
"userId": "593a5aff0b445b3b77a6d9676b7ec86e",
"originalTimestamp": "2024-01-05T12:34:01.000Z"
}
]
}
]
2 changes: 1 addition & 1 deletion test/__tests__/mailjet_source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ testData.forEach((data, index) => {
it(`${name} Tests: payload: ${index}`, () => {
try {
const output = transformer.process(data.input);
expect(output).toEqual(data.output.Message);
expect(output).toEqual(data.output);
} catch (error) {
expect(error.message).toEqual(data.output);
}
Expand Down
Loading