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: router tranform refacor for destinations (batch - 3) #1686

Merged
merged 3 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
40 changes: 7 additions & 33 deletions src/v0/destinations/kissmetrics/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const {
defaultGetRequestConfig,
defaultRequestConfig,
getFieldValueFromMessage,
getSuccessRespEvents,
getErrorRespEvents
simpleProcessRouterDest
} = require("../../util");
const { ENDPOINT } = require("./config");
const { InstrumentationError } = require("../../util/errorTypes");
Expand Down Expand Up @@ -371,37 +370,12 @@ function process(event) {
return respList;
}

const processRouterDest = async inputs => {
if (!Array.isArray(inputs) || inputs.length <= 0) {
const respEvents = getErrorRespEvents(null, 400, "Invalid event array");
return [respEvents];
}

const respList = await Promise.all(
inputs.map(async input => {
try {
if (input.message.statusCode) {
// already transformed event
return getSuccessRespEvents(
input.message,
[input.metadata],
input.destination
);
}
// if not transformed
return getSuccessRespEvents(
await process(input),
[input.metadata],
input.destination
);
} catch (error) {
return getErrorRespEvents(
[input.metadata],
error.response?.status || error.code || 400,
error.message || "Error occurred while processing payload."
);
}
})
const processRouterDest = async (inputs, reqMetadata) => {
const respList = await simpleProcessRouterDest(
inputs,
"KISSMETRICS",
process,
reqMetadata
);
return respList;
};
Expand Down
9 changes: 7 additions & 2 deletions src/v0/destinations/klaviyo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,13 @@ const process = async event => {
return result;
};

const processRouterDest = async inputs => {
const respList = await simpleProcessRouterDest(inputs, "KLAVIYO", process);
const processRouterDest = async (inputs, reqMetadata) => {
const respList = await simpleProcessRouterDest(
inputs,
"KLAVIYO",
process,
reqMetadata
);
return respList;
};

Expand Down
40 changes: 7 additions & 33 deletions src/v0/destinations/kochava/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const {
} = require("./config");
const {
defaultRequestConfig,
getSuccessRespEvents,
getErrorRespEvents,
simpleProcessRouterDest,
formatTimeStamp,
isAppleFamily
} = require("../../util");
Expand Down Expand Up @@ -176,37 +175,12 @@ function process(event) {
return processMessage(event.message, event.destination);
}

const processRouterDest = async inputs => {
if (!Array.isArray(inputs) || inputs.length <= 0) {
const respEvents = getErrorRespEvents(null, 400, "Invalid event array");
return [respEvents];
}

const respList = await Promise.all(
inputs.map(async input => {
try {
if (input.message.statusCode) {
// already transformed event
return getSuccessRespEvents(
input.message,
[input.metadata],
input.destination
);
}
// if not transformed
return getSuccessRespEvents(
await process(input),
[input.metadata],
input.destination
);
} catch (error) {
return getErrorRespEvents(
[input.metadata],
error.response?.status || error.code || 400,
error.message || "Error occurred while processing payload."
);
}
})
const processRouterDest = async (inputs, reqMetadata) => {
const respList = await simpleProcessRouterDest(
inputs,
"KOCHAVA",
process,
reqMetadata
);
return respList;
};
Expand Down
9 changes: 7 additions & 2 deletions src/v0/destinations/kustomer/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,13 @@ const process = event => {
return processEvent(event.message, event.destination);
};

const processRouterDest = async inputs => {
const respList = await simpleProcessRouterDest(inputs, "KUSTOMER", process);
const processRouterDest = async (inputs, reqMetadata) => {
const respList = await simpleProcessRouterDest(
inputs,
"KUSTOMER",
process,
reqMetadata
);
return respList;
};

Expand Down
40 changes: 7 additions & 33 deletions src/v0/destinations/leanplum/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const {
defaultPostRequestConfig,
defaultRequestConfig,
constructPayload,
getSuccessRespEvents,
getErrorRespEvents
simpleProcessRouterDest
} = require("../../util");
const { InstrumentationError } = require("../../util/errorTypes");

Expand Down Expand Up @@ -107,37 +106,12 @@ function process(event) {
return processSingleMessage(event.message, event.destination);
}

const processRouterDest = async inputs => {
if (!Array.isArray(inputs) || inputs.length <= 0) {
const respEvents = getErrorRespEvents(null, 400, "Invalid event array");
return [respEvents];
}

const respList = await Promise.all(
inputs.map(async input => {
try {
if (input.message.statusCode) {
// already transformed event
return getSuccessRespEvents(
input.message,
[input.metadata],
input.destination
);
}
// if not transformed
return getSuccessRespEvents(
await process(input),
[input.metadata],
input.destination
);
} catch (error) {
return getErrorRespEvents(
[input.metadata],
error.response?.status || error.code || 400,
error.message || "Error occurred while processing payload."
);
}
})
const processRouterDest = async (inputs, reqMetadata) => {
const respList = await simpleProcessRouterDest(
inputs,
"LEANPLUM",
process,
reqMetadata
);
return respList;
};
Expand Down
40 changes: 7 additions & 33 deletions src/v0/destinations/lytics/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const {
removeUndefinedAndNullValues,
defaultRequestConfig,
flattenJson,
getSuccessRespEvents,
getErrorRespEvents
simpleProcessRouterDest
} = require("../../util");
const { InstrumentationError } = require("../../util/errorTypes");

Expand Down Expand Up @@ -73,37 +72,12 @@ const process = event => {
return processEvent(event.message, event.destination);
};

const processRouterDest = async inputs => {
if (!Array.isArray(inputs) || inputs.length <= 0) {
const respEvents = getErrorRespEvents(null, 400, "Invalid event array");
return [respEvents];
}

const respList = await Promise.all(
inputs.map(async input => {
try {
if (input.message.statusCode) {
// already transformed event
return getSuccessRespEvents(
input.message,
[input.metadata],
input.destination
);
}
// if not transformed
return getSuccessRespEvents(
await process(input),
[input.metadata],
input.destination
);
} catch (error) {
return getErrorRespEvents(
[input.metadata],
error.response?.status || error.code || 400,
error.message || "Error occurred while processing payload."
);
}
})
const processRouterDest = async (inputs, reqMetadata) => {
const respList = await simpleProcessRouterDest(
inputs,
"LYTICS",
process,
reqMetadata
);
return respList;
};
Expand Down
4 changes: 2 additions & 2 deletions src/v0/destinations/mailchimp/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const batchEvents = successRespList => {
return batchedResponseList;
};

const processRouterDest = async inputs => {
const processRouterDest = async (inputs, reqMetadata) => {
const errorRespEvents = checkInvalidRtTfEvents(inputs, "MAILCHIMP");
if (errorRespEvents.length > 0) {
return errorRespEvents;
Expand Down Expand Up @@ -159,7 +159,7 @@ const processRouterDest = async inputs => {
const errRespEvent = handleRtTfSingleEventError(
event,
error,
"MAILCHIMP"
reqMetadata
);
batchErrorRespList.push(errRespEvent);
}
Expand Down
18 changes: 9 additions & 9 deletions src/v0/destinations/mailjet/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ const {
getErrorRespEvents,
getSuccessRespEvents,
defaultRequestConfig,
defaultPostRequestConfig,
defaultBatchRequestConfig,
removeUndefinedAndNullValues,
defaultPostRequestConfig
handleRtTfSingleEventError,
removeUndefinedAndNullValues
} = require("../../util");

const { MAX_BATCH_SIZE } = require("./config");
Expand Down Expand Up @@ -131,7 +132,7 @@ const batchEvents = successRespList => {
return batchedResponseList;
};

const processRouterDest = inputs => {
const processRouterDest = (inputs, reqMetadata) => {
if (!Array.isArray(inputs) || inputs.length <= 0) {
const respEvents = getErrorRespEvents(null, 400, "Invalid event array");
return [respEvents];
Expand Down Expand Up @@ -159,13 +160,12 @@ const processRouterDest = inputs => {
successRespList.push(transformedPayload);
}
} catch (error) {
batchErrorRespList.push(
getErrorRespEvents(
[event.metadata],
error.response ? error.response.status : 400,
error.message || "Error occurred while processing payload."
)
const errRespEvent = handleRtTfSingleEventError(
event,
error,
reqMetadata
);
batchErrorRespList.push(errRespEvent);
}
});

Expand Down
7 changes: 3 additions & 4 deletions src/v0/destinations/mailmodo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const {
ConfigCategory,
IDENTIFY_MAX_BATCH_SIZE,
mappingConfig,
BASE_URL,
DESTINATION
BASE_URL
} = require("./config");
const {
defaultRequestConfig,
Expand Down Expand Up @@ -209,7 +208,7 @@ function getEventChunks(event, identifyEventChunks, eventResponseList) {
}
}

const processRouterDest = inputs => {
const processRouterDest = (inputs, reqMetadata) => {
if (!Array.isArray(inputs) || inputs.length <= 0) {
const respEvents = getErrorRespEvents(null, 400, "Invalid event array");
return [respEvents];
Expand Down Expand Up @@ -240,7 +239,7 @@ const processRouterDest = inputs => {
const errRespEvent = handleRtTfSingleEventError(
event,
error,
DESTINATION
reqMetadata
);
errorRespList.push(errRespEvent);
}
Expand Down
15 changes: 4 additions & 11 deletions src/v0/destinations/marketo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const {
getErrorRespEvents,
isDefinedAndNotNull,
generateErrorObject,
checkInvalidRtTfEvents
checkInvalidRtTfEvents,
handleRtTfSingleEventError
} = require("../../util");
const Cache = require("../../util/cache");
const { USER_LEAD_CACHE_TTL, AUTH_CACHE_TTL } = require("../../util/constant");
Expand Down Expand Up @@ -490,7 +491,7 @@ const process = async event => {
return response;
};

const processRouterDest = async inputs => {
const processRouterDest = async (inputs, reqMetadata) => {
// Token needs to be generated for marketo which will be done on input level.
// If destination information is not present Error should be thrown
const errorRespEvents = checkInvalidRtTfEvents(inputs, DESTINATION);
Expand Down Expand Up @@ -542,15 +543,7 @@ const processRouterDest = async inputs => {
input.destination
);
} catch (error) {
logger.error("Router transformation Error for Marketo:");
const errObj = generateErrorObject(error);
logger.error(errObj);
return getErrorRespEvents(
[input.metadata],
error.status || 500,
error.message || "Error occurred while processing payload.",
errObj.statTags
);
return handleRtTfSingleEventError(input, error, reqMetadata);
}
})
);
Expand Down
Loading