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

feat: sendgrid idetify and user deletion support #1571

Merged
merged 8 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
7 changes: 6 additions & 1 deletion __mocks__/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const {
freshsalesGetRequestHandler,
freshsalesPostRequestHandler
} = require("./freshsales.mock");
const { sendgridGetRequestHandler } = require("./sendgrid.mock");

const urlDirectoryMap = {
"api.hubapi.com": "hs",
Expand All @@ -45,7 +46,8 @@ const urlDirectoryMap = {
"active.campaigns.rudder.com": "active_campaigns",
"api.aptrinsic.com": "gainsight_px",
"api.profitwell.com": "profitwell",
"ruddertest2.mautic.net": "mautic"
"ruddertest2.mautic.net": "mautic",
"api.sendgrid.com": "sendgrid"
};

const fs = require("fs");
Expand Down Expand Up @@ -141,6 +143,9 @@ function get(url, options) {
if (url.includes("https://domain-rudder.myfreshworks.com/crm/sales/api")) {
return Promise.resolve(freshsalesGetRequestHandler(url));
}
if (url.includes("https://api.sendgrid.com/v3/marketing/field_definitions")) {
return Promise.resolve(sendgridGetRequestHandler(url));
}
return new Promise((resolve, reject) => {
if (mockData) {
resolve({ data: mockData, status: 200 });
Expand Down
148 changes: 148 additions & 0 deletions __mocks__/data/sendgrid/response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"https://api.sendgrid.com/v3/marketing/field_definitions": {
"custom_fields": [
{
"id": "w1_T",
"name": "user_name",
"field_type": "Text",
"_metadata": {
"self": "https://api.sendgrid.com/v3/marketing/field_definitions/w1_T"
}
}
],
"reserved_fields": [
{
"id": "_rf0_T",
"name": "first_name",
"field_type": "Text"
},
{
"id": "_rf1_T",
"name": "last_name",
"field_type": "Text"
},
{
"id": "_rf2_T",
"name": "email",
"field_type": "Text"
},
{
"id": "_rf3_T",
"name": "alternate_emails",
"field_type": "Text"
},
{
"id": "_rf4_T",
"name": "address_line_1",
"field_type": "Text"
},
{
"id": "_rf5_T",
"name": "address_line_2",
"field_type": "Text"
},
{
"id": "_rf6_T",
"name": "city",
"field_type": "Text"
},
{
"id": "_rf7_T",
"name": "state_province_region",
"field_type": "Text"
},
{
"id": "_rf8_T",
"name": "postal_code",
"field_type": "Text"
},
{
"id": "_rf9_T",
"name": "country",
"field_type": "Text"
},
{
"id": "_rf10_T",
"name": "phone_number",
"field_type": "Text"
},
{
"id": "_rf11_T",
"name": "whatsapp",
"field_type": "Text"
},
{
"id": "_rf12_T",
"name": "line",
"field_type": "Text"
},
{
"id": "_rf13_T",
"name": "facebook",
"field_type": "Text"
},
{
"id": "_rf14_T",
"name": "unique_name",
"field_type": "Text"
},
{
"id": "_rf15_T",
"name": "email_domains",
"field_type": "Text",
"read_only": true
},
{
"id": "_rf16_D",
"name": "last_clicked",
"field_type": "Date",
"read_only": true
},
{
"id": "_rf17_D",
"name": "last_opened",
"field_type": "Date",
"read_only": true
},
{
"id": "_rf18_D",
"name": "last_emailed",
"field_type": "Date",
"read_only": true
},
{
"id": "_rf19_T",
"name": "singlesend_id",
"field_type": "Text",
"read_only": true
},
{
"id": "_rf20_T",
"name": "automation_id",
"field_type": "Text",
"read_only": true
},
{
"id": "_rf21_D",
"name": "created_at",
"field_type": "Date",
"read_only": true
},
{
"id": "_rf22_D",
"name": "updated_at",
"field_type": "Date",
"read_only": true
},
{
"id": "_rf23_T",
"name": "contact_id",
"field_type": "Text",
"read_only": true
}
],
"_metadata": {
"self": "https://api.sendgrid.com/v3/marketing/field_definitions"
}
}
}
37 changes: 37 additions & 0 deletions __mocks__/sendgrid.mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const fs = require("fs");
const path = require("path");

const urlDirectoryMap = {
"api.sendgrid.com": "sendgrid"
};

const getData = url => {
let directory = "";
Object.keys(urlDirectoryMap).forEach(key => {
if (url.includes(key)) {
directory = urlDirectoryMap[key];
}
});
if (directory) {
const dataFile = fs.readFileSync(
path.resolve(__dirname, `./data/${directory}/response.json`)
);
const data = JSON.parse(dataFile);
return data[url];
}
return {};
};

const sendgridGetRequestHandler = url => {
const mockData = getData(url);
if (mockData) {
return { data: mockData, status: 200 };
}
return new Promise((resolve, reject) => {
resolve({ error: "Request failed", status: 404 });
});
};

module.exports = {
sendgridGetRequestHandler
};
Loading