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 - 2) #1685

Merged
merged 1 commit 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
4 changes: 2 additions & 2 deletions src/v0/destinations/salesforce/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ async function process(event) {
return response;
}

const processRouterDest = async inputs => {
const processRouterDest = async (inputs, reqMetadata) => {
const errorRespEvents = checkInvalidRtTfEvents(inputs, "SALESFORCE");
if (errorRespEvents.length > 0) {
return errorRespEvents;
Expand Down Expand Up @@ -387,7 +387,7 @@ const processRouterDest = async inputs => {
input.destination
);
} catch (error) {
return handleRtTfSingleEventError(input, error, "SALESFORCE");
return handleRtTfSingleEventError(input, error, reqMetadata);
}
})
);
Expand Down
14 changes: 7 additions & 7 deletions src/v0/destinations/sendgrid/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
defaultPutRequestConfig,
defaultPostRequestConfig,
defaultBatchRequestConfig,
handleRtTfSingleEventError,
removeUndefinedAndNullValues
} = require("../../util");
const {
Expand Down Expand Up @@ -254,7 +255,7 @@ const batchEvents = successRespList => {
return batchedResponseList;
};

const processRouterDest = async inputs => {
const processRouterDest = async (inputs, reqMetadata) => {
if (!Array.isArray(inputs) || inputs.length <= 0) {
const respEvents = getErrorRespEvents(null, 400, "Invalid event array");
return [respEvents];
Expand Down Expand Up @@ -282,13 +283,12 @@ const processRouterDest = async 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
44 changes: 9 additions & 35 deletions src/v0/destinations/serenytics/transform.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const { EventType } = require("../../../constants");
const {
getErrorRespEvents,
getSuccessRespEvents,
getHashFromArrayWithDuplicate,
ErrorMessage
ErrorMessage,
simpleProcessRouterDest,
getHashFromArrayWithDuplicate
} = require("../../util");
const {
ConfigurationError,
Expand Down Expand Up @@ -138,37 +137,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,
"SERENTICS",
process,
reqMetadata
);
return respList;
};
Expand Down
9 changes: 7 additions & 2 deletions src/v0/destinations/sfmc/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,13 @@ const process = async event => {
return response;
};

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

Expand Down
40 changes: 7 additions & 33 deletions src/v0/destinations/shynet/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const {
constructPayload,
defaultRequestConfig,
removeUndefinedAndNullValues,
getSuccessRespEvents,
getErrorRespEvents,
simpleProcessRouterDest,
generateUUID
} = require("../../util");
const { InstrumentationError } = require("../../util/errorTypes");
Expand Down Expand Up @@ -56,37 +55,12 @@ function process(event) {
}
}

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 ? error.response.status : error.code || 400,
error.message || "Error occurred while processing payload."
);
}
})
const processRouterDest = async (inputs, reqMetadata) => {
const respList = await simpleProcessRouterDest(
inputs,
"SHYNET",
process,
reqMetadata
);
return respList;
};
Expand Down
41 changes: 8 additions & 33 deletions src/v0/destinations/signl4/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ const { populatePayload } = require("./utils");
const {
defaultRequestConfig,
defaultPostRequestConfig,
getErrorRespEvents,
getSuccessRespEvents,
simpleProcessRouterDest,
removeUndefinedAndNullAndEmptyValues
} = require("../../util");
const {
Expand Down Expand Up @@ -76,38 +75,14 @@ const process = async 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];
}

return 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 ? error.response.status : error.code || 400,
error.message || "Error occurred while processing payload."
);
}
})
const processRouterDest = async (inputs, reqMetadata) => {
const respList = await simpleProcessRouterDest(
inputs,
"SIGNL4",
process,
reqMetadata
);
return respList;
};

module.exports = { process, processRouterDest };
41 changes: 8 additions & 33 deletions src/v0/destinations/singular/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ const { BASE_URL } = require("./config");
const {
defaultRequestConfig,
defaultGetRequestConfig,
getSuccessRespEvents,
getErrorRespEvents
simpleProcessRouterDest
} = require("../../util");

const {
Expand Down Expand Up @@ -70,38 +69,14 @@ const process = event => {
return processEvent(event.message, event.destination);
};

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

const respList = 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(
process(input),
[input.metadata],
input.destination
);
} catch (error) {
return getErrorRespEvents(
[input.metadata],
error.response ? error.response.status : error.code || 400,
error.message || "Error occurred while processing payload."
);
}
})
const processRouterDest = async (inputs, reqMetadata) => {
const respList = await simpleProcessRouterDest(
inputs,
"SINGULAR",
process,
reqMetadata
);
return respList;
};

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

Expand Down Expand Up @@ -335,37 +334,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 ? error.response.status : error.code || 400,
error.message || "Error occurred while processing payload."
);
}
})
const processRouterDest = async (inputs, reqMetadata) => {
const respList = await simpleProcessRouterDest(
inputs,
"SLACK",
process,
reqMetadata
);
return respList;
};
Expand Down
4 changes: 2 additions & 2 deletions src/v0/destinations/snapchat_conversion/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ function getEventChunks(event, eventsChunk) {
eventsChunk.push(event);
}

const processRouterDest = async inputs => {
const processRouterDest = async (inputs, reqMetadata) => {
const errorRespEvents = checkInvalidRtTfEvents(inputs, "SNAPCHAT_CONVERSION");
if (errorRespEvents.length > 0) {
return errorRespEvents;
Expand Down Expand Up @@ -419,7 +419,7 @@ const processRouterDest = async inputs => {
const errRespEvent = handleRtTfSingleEventError(
event,
error,
"SNAPCHAT_CONVERSION"
reqMetadata
);
errorRespList.push(errRespEvent);
}
Expand Down
8 changes: 5 additions & 3 deletions src/v0/destinations/snapchat_custom_audience/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,13 @@ const processEvent = (metadata, message, destination) => {
const process = event => {
return processEvent(event.metadata, event.message, event.destination);
};
const processRouterDest = async inputs => {

const processRouterDest = async (inputs, reqMetadata) => {
const respList = await simpleProcessRouterDest(
inputs,
"snapchat_custom_audience",
process
"SNAPCHAT_CUSTOM_AUDIENCE",
process,
reqMetadata
);
return respList;
};
Expand Down
Loading