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
19 changes: 10 additions & 9 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,22 @@ 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, userName } = destination.Config;
if (!password) {
throw new ConfigurationError(
'Invalid password value specified in the destination configuration',
);
}
if (!subDomainName) {
if (!userName) {
throw new ConfigurationError(
'Invalid sub-domain value specified in the destination configuration',
'Invalid userName 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,
};
Loading