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: mautic: support self hosted instance #1909

Merged
merged 12 commits into from
Mar 10, 2023
28,445 changes: 15,072 additions & 13,373 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 8 additions & 12 deletions src/v0/destinations/mautic/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ const {
} = require('../../util');

const {
validateEmail,
deduceAddressFields,
deduceStateField,
validatePayload,
searchContactIds,
validateGroupCall,
getEndpoint,
} = require('./utils');

const { EventType } = require('../../../constants');
const { BASE_URL, mappingConfig, ConfigCategories } = require('./config');
const { mappingConfig, ConfigCategories } = require('./config');

const {
TransformationError,
Expand Down Expand Up @@ -154,21 +154,17 @@ const identifyResponseBuilder = async (message, Config, endpoint) => {

const process = async (event) => {
const { message, destination } = event;
const { password, subDomainName, userName } = destination.Config;
const endpoint = `${BASE_URL.replace('subDomainName', subDomainName)}`;
const { password } = destination.Config;
if (!password) {
throw new ConfigurationError(
'Invalid password value specified in the destination configuration',
);
}
if (!subDomainName) {
throw new ConfigurationError(
'Invalid sub-domain value specified in the destination configuration',
);
}
if (!validateEmail(userName)) {
throw new ConfigurationError('Invalid user name provided in the destination configuration');
}


// if both are present we will be taking endpoint after checking the domainMethod selected
const endpoint = getEndpoint(destination.Config);


// Validating if message type is even given or not
if (!message.type) {
Expand Down
14 changes: 13 additions & 1 deletion src/v0/destinations/mautic/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-return-assign, no-param-reassign, no-restricted-syntax */
const get = require('get-value');
const { getFieldValueFromMessage } = require('../../util');
const { lookupFieldMap } = require('./config');
const { BASE_URL, lookupFieldMap } = require('./config');
const { httpGET } = require('../../../adapters/network');
const {
processAxiosResponse,
Expand Down Expand Up @@ -194,6 +194,17 @@ const searchContactIds = async (message, Config, baseUrl) => {
return Object.keys(contacts);
};

const getEndpoint = (Config) => {
const { subDomainName, domainName, domainMethod } = Config;
let endpoint = `${BASE_URL.replace('subDomainName', subDomainName)}`;
if (domainMethod === 'domainNameOption' && domainName) {
endpoint = `${domainName}/api`;
}
if (!subDomainName && !domainName) {
throw new ConfigurationError('Please Provide either subDomain or Domain Name');
}
return endpoint;
};
module.exports = {
deduceStateField,
validateEmail,
Expand All @@ -202,4 +213,5 @@ module.exports = {
validateGroupCall,
validatePayload,
searchContactIds,
getEndpoint,
};
234 changes: 219 additions & 15 deletions test/__tests__/data/mautic.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,45 @@
}
},
{
"description": "Invalid userName",
"description": "Password Not Provided for Authentication",
"input": {
"message": {
"anonymousId": "anon-id-new",
"context": {
"ip": "14.5.67.21",
"library": {
"name": "http"
},
"traits": {
"firstName": "Anant",
"lastName": "jain"
}
},
"messageId": "25ea6605-c788-4cab-8fed-2cf0b831c4a8",
"originalTimestamp": "2020-02-02T00:23:09.544Z",
"receivedAt": "2022-08-17T10:40:21.162+05:30",
"request_ip": "[::1]",
"rudderId": "daf823fb-e8d3-413a-8313-d34cd756f968",
"sentAt": "2022-08-17T10:40:21.728+05:30",
"timestamp": "2020-02-02T05:53:08.977+05:30",
"type": "identify",
"userId": "identified user id"
},
"destination": {
"Config": {
"lookUpField": "email",
"password": "",
"subDomainName": "testapi3",
"userName": "abcdef@gmail.com"
}
}
},
"output": {
"error": "Invalid password value specified in the destination configuration"
}
},
{
"description": "Empty Sub-Domain and Domain Field ",
"input": {
"message": {
"anonymousId": "anon-id-new",
Expand Down Expand Up @@ -206,17 +244,18 @@
"Config": {
"lookUpField": "email",
"password": "abcdefghij1234",
"subDomainName": "testapi3",
"userName": "abcdef"
"subDomainName": "",
"domainName": "",
"userName": "abcdef@gmail.com"
}
}
},
"output": {
"error": "Invalid user name provided in the destination configuration"
"error": "Please Provide either subDomain or Domain Name"
}
},
{
"description": "Password Not Provided for Authentication",
"description": "both Sub-Domain and Domain Field are given, domainMethod is subDomainNameOption",
"input": {
"message": {
"anonymousId": "anon-id-new",
Expand All @@ -227,7 +266,19 @@
},
"traits": {
"firstName": "Anant",
"lastName": "jain"
"lastName": "jain",
"role": "Manager",
"address": "Flat No 58 ABC building XYZ Area near PQRS , 354408",
"hasPurchased": "yes",
"email": "hijibi@gmail.com",
"title": "Mr",
"phone": "9876543212",
"state": "Uttar Pradesh",
"zipcode": "243001",
"prospectOrCustomer": "Prospect",
"country": "India",
"website": "abc.com",
"subscriptionStatus": "New"
}
},
"messageId": "25ea6605-c788-4cab-8fed-2cf0b831c4a8",
Expand All @@ -243,18 +294,53 @@
"destination": {
"Config": {
"lookUpField": "email",
"password": "",
"subDomainName": "testapi3",
"password": "abcdefghij1234",
"subDomainName": "test",
"domainMethod": "subDomainNameOption",
"domainName": "https://testmautic.com/",
"userName": "abcdef@gmail.com"
}
}
},
"output": {
"error": "Invalid password value specified in the destination configuration"
"version": "1",
"type": "REST",
"method": "POST",
"endpoint": "https://test.mautic.net/api/contacts/new",
"headers": {
"Content-Type": "application/json",
"Authorization": "Basic YWJjZGVmQGdtYWlsLmNvbTphYmNkZWZnaGlqMTIzNA=="
},
"params": {},
"body": {
"JSON": {
"email": "hijibi@gmail.com",
"title": "Mr",
"last_active": "2020-02-02T00:23:09.544Z",
"firstname": "Anant",
"lastname": "jain",
"phone": "9876543212",
"website": "abc.com",
"state": "Uttar Pradesh",
"zipcode": "243001",
"ipAddress": "14.5.67.21",
"country": "India",
"haspurchased": "yes",
"role": "Manager",
"subscription_status": "New",
"prospect_or_customer": "Prospect",
"address1": "Flat No 58 ABC building XYZ Area near PQRS , 354408",
"address2": ""
},
"JSON_ARRAY": {},
"XML": {},
"FORM": {}
},
"files": {}
}
},
{
"description": "Empty Sub-Domain Field ",
"description": "both Sub-Domain and Domain Field are given, domainMethod is domainNameOption",
"input": {
"message": {
"anonymousId": "anon-id-new",
Expand All @@ -269,7 +355,92 @@
"role": "Manager",
"address": "Flat No 58 ABC building XYZ Area near PQRS , 354408",
"hasPurchased": "yes",
"email": "abc@xyz.com",
"email": "hijibi@gmail.com",
"title": "Mr",
"phone": "9876543212",
"state": "Uttar Pradesh",
"zipcode": "243001",
"prospectOrCustomer": "Prospect",
"country": "India",
"website": "abc.com",
"subscriptionStatus": "New"
}
},
"messageId": "25ea6605-c788-4cab-8fed-2cf0b831c4a8",
"originalTimestamp": "2020-02-02T00:23:09.544Z",
"receivedAt": "2022-08-17T10:40:21.162+05:30",
"request_ip": "[::1]",
"rudderId": "daf823fb-e8d3-413a-8313-d34cd756f968",
"sentAt": "2022-08-17T10:40:21.728+05:30",
"timestamp": "2020-02-02T05:53:08.977+05:30",
"type": "identify",
"userId": "identified user id"
},
"destination": {
"Config": {
"lookUpField": "email",
"password": "abcdefghij1234",
"subDomainName": "test",
"domainMethod": "domainNameOption",
"domainName": "https://testmautic.com",
"userName": "abcdef@gmail.com"
}
}
},
"output": {
"version": "1",
"type": "REST",
"method": "POST",
"endpoint": "https://testmautic.com/api/contacts/new",
"headers": {
"Content-Type": "application/json",
"Authorization": "Basic YWJjZGVmQGdtYWlsLmNvbTphYmNkZWZnaGlqMTIzNA=="
},
"params": {},
"body": {
"JSON": {
"email": "hijibi@gmail.com",
"title": "Mr",
"last_active": "2020-02-02T00:23:09.544Z",
"firstname": "Anant",
"lastname": "jain",
"phone": "9876543212",
"website": "abc.com",
"state": "Uttar Pradesh",
"zipcode": "243001",
"ipAddress": "14.5.67.21",
"country": "India",
"haspurchased": "yes",
"role": "Manager",
"subscription_status": "New",
"prospect_or_customer": "Prospect",
"address1": "Flat No 58 ABC building XYZ Area near PQRS , 354408",
"address2": ""
},
"JSON_ARRAY": {},
"XML": {},
"FORM": {}
},
"files": {}
}
},
{
"description": " Sub-Domain Not given and Domain Field is given, domainMethod is subDomainNameOption",
"input": {
"message": {
"anonymousId": "anon-id-new",
"context": {
"ip": "14.5.67.21",
"library": {
"name": "http"
},
"traits": {
"firstName": "Anant",
"lastName": "jain",
"role": "Manager",
"address": "Flat No 58 ABC building XYZ Area near PQRS , 354408",
"hasPurchased": "yes",
"email": "hijibi@gmail.com",
"title": "Mr",
"phone": "9876543212",
"state": "Uttar Pradesh",
Expand All @@ -295,12 +466,47 @@
"lookUpField": "email",
"password": "abcdefghij1234",
"subDomainName": "",
"domainMethod": "domainNameOption",
"domainName": "https://testmautic.com",
"userName": "abcdef@gmail.com"
}
}
},
"output": {
"error": "Invalid sub-domain value specified in the destination configuration"
"version": "1",
"type": "REST",
"method": "POST",
"endpoint": "https://testmautic.com/api/contacts/new",
"headers": {
"Content-Type": "application/json",
"Authorization": "Basic YWJjZGVmQGdtYWlsLmNvbTphYmNkZWZnaGlqMTIzNA=="
},
"params": {},
"body": {
"JSON": {
"email": "hijibi@gmail.com",
"title": "Mr",
"last_active": "2020-02-02T00:23:09.544Z",
"firstname": "Anant",
"lastname": "jain",
"phone": "9876543212",
"website": "abc.com",
"state": "Uttar Pradesh",
"zipcode": "243001",
"ipAddress": "14.5.67.21",
"country": "India",
"haspurchased": "yes",
"role": "Manager",
"subscription_status": "New",
"prospect_or_customer": "Prospect",
"address1": "Flat No 58 ABC building XYZ Area near PQRS , 354408",
"address2": ""
},
"JSON_ARRAY": {},
"XML": {},
"FORM": {}
},
"files": {}
}
},
{
Expand Down Expand Up @@ -863,7 +1069,6 @@
}
}
},

"output": {
"version": "1",
"type": "REST",
Expand Down Expand Up @@ -1035,7 +1240,6 @@
"files": {}
}
},

{
"description": " Group contact with campaign with contactId found by lookUpField with no operation field",
"input": {
Expand Down Expand Up @@ -1086,4 +1290,4 @@
"error": "Could not find any contact ID on lookup"
}
}
]
]
Loading