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: marketo: migrate config fields and fix test cases #2789

Merged
merged 21 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
27 changes: 13 additions & 14 deletions src/cdk/v2/destinations/gladly/utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
const get = require('get-value');
const { InstrumentationError } = require('@rudderstack/integrations-lib');
const {
base64Convertor,
getDestinationExternalID,
} = require('../../../../v0/util');
const { base64Convertor, getDestinationExternalID } = require('../../../../v0/util');
const { MappedToDestinationKey } = require('../../../../constants');

const reservedCustomAttributes = [
Expand Down Expand Up @@ -35,7 +32,6 @@ const getEndpoint = (destination) => {
return `https://${domain}/api/v1/customer-profiles`;
};


const getFieldValue = (field) => {
if (field) {
if (Array.isArray(field)) {
Expand All @@ -44,7 +40,7 @@ const getFieldValue = (field) => {
return [{ original: field }];
}
return undefined;
}
};

const formatFieldForRETl = (message, fieldName) => {
const identifierType = get(message, identifierTypeKey);
Expand All @@ -70,15 +66,16 @@ const formatField = (message, fieldName) => {
return formatFieldForRETl(message, fieldName);
}
return formatFieldForEventStream(message, fieldName);

};

const getCustomAttributes = (message) => {
const mappedToDestination = get(message, MappedToDestinationKey);
// for rETL
if (mappedToDestination) {
if (message?.traits?.customAttributes && typeof message.traits.customAttributes === 'object') {
return Object.keys(message.traits.customAttributes).length > 0 ? message.traits.customAttributes : undefined;
return Object.keys(message.traits.customAttributes).length > 0
? message.traits.customAttributes
: undefined;
}
return undefined;
}
Expand Down Expand Up @@ -140,25 +137,27 @@ const getCustomerId = (message) => {

const validatePayload = (payload) => {
if (!(payload?.phones || payload?.emails || payload?.id || payload?.externalCustomerId)) {
throw new InstrumentationError('One of phone, email, userId or GladlyCustomerId is required for an identify call');
throw new InstrumentationError(
'One of phone, email, userId or GladlyCustomerId is required for an identify call',
);
}
};

const getQueryParams = (payload) => {
if (payload.emails && payload.emails.length > 0) {
return `email=${encodeURIComponent(payload.emails[0].original)}`
return `email=${encodeURIComponent(payload.emails[0].original)}`;
}

if (payload.phones && payload.phones.length > 0) {
return `phoneNumber=${encodeURIComponent(payload.phones[0].original)}`
return `phoneNumber=${encodeURIComponent(payload.phones[0].original)}`;
}

if (payload.externalCustomerId) {
return `externalCustomerId=${encodeURIComponent(payload.externalCustomerId)}`
return `externalCustomerId=${encodeURIComponent(payload.externalCustomerId)}`;
}

return undefined;
}
};

module.exports = {
getHeaders,
Expand All @@ -171,5 +170,5 @@ module.exports = {
formatFieldForRETl,
getCustomAttributes,
getExternalCustomerId,
formatFieldForEventStream
formatFieldForEventStream,
};
2 changes: 1 addition & 1 deletion src/constants/destinationCanonicalNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const DestCanonicalNames = {
'twitter_ads',
'TWITTER_ADS',
],
BRAZE: ['BRAZE', 'Braze', 'braze']
BRAZE: ['BRAZE', 'Braze', 'braze'],
};

module.exports = { DestHandlerMap, DestCanonicalNames };
9 changes: 7 additions & 2 deletions src/services/destination/cdkV2Integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class CDKV2DestinationService implements DestinationService {
destinationType,
event,
tags.FEATURES.PROCESSOR,
requestMetadata
requestMetadata,
);

stats.increment('event_transform_success', {
Expand Down Expand Up @@ -127,7 +127,12 @@ export class CDKV2DestinationService implements DestinationService {
metaTo.metadata = destInputArray[0].metadata;
try {
const doRouterTransformationResponse: RouterTransformationResponse[] =
await processCdkV2Workflow(destinationType, destInputArray, tags.FEATURES.ROUTER, requestMetadata);
await processCdkV2Workflow(
destinationType,
destInputArray,
tags.FEATURES.ROUTER,
requestMetadata,
);
return DestinationPostTransformationService.handleRouterTransformSuccessEvents(
doRouterTransformationResponse,
undefined,
Expand Down
32 changes: 11 additions & 21 deletions src/util/openfaas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,24 +247,13 @@
try {
if (testMode) await awaitFunctionReadiness(name);
return await invokeFunction(name, events);

} catch (error) {
logger.error(`Error while invoking ${name}: ${error.message}`);
errorRaised = error;

if (
error.statusCode === 404 &&
error.message.includes(`error finding function ${name}`)
) {
if (error.statusCode === 404 && error.message.includes(`error finding function ${name}`)) {
removeFunctionFromCache(name);
await setupFaasFunction(
name,
null,
versionId,
libraryVersionIDs,
testMode,
trMetadata,
);
await setupFaasFunction(name, null, versionId, libraryVersionIDs, testMode, trMetadata);
throw new RetryRequestError(`${name} not found`);
}

Expand All @@ -284,22 +273,23 @@
} finally {
// delete the function created, if it's called as part of testMode
if (testMode) {
deleteFunction(name).catch((err) =>
logger.error(`[Faas] Error while deleting ${name}: ${err.message}`))
deleteFunction(name).catch((err) =>
logger.error(`[Faas] Error while deleting ${name}: ${err.message}`),

Check warning on line 277 in src/util/openfaas/index.js

View check run for this annotation

Codecov / codecov/patch

src/util/openfaas/index.js#L277

Added line #L277 was not covered by tests
);
}

// setup the tags for observability and then fire the stats
const tags = {
identifier: "openfaas",
identifier: 'openfaas',
testMode: testMode,
errored: errorRaised ? true : false,
statusCode: errorRaised ? errorRaised.statusCode : HTTP_STATUS_CODES.OK, // default statuscode is 200OK
...events.length && events[0].metadata ? getMetadata(events[0].metadata) : {},
...events.length && events[0].metadata ? getTransformationMetadata(events[0].metadata) : {},
}
...(events.length && events[0].metadata ? getMetadata(events[0].metadata) : {}),
...(events.length && events[0].metadata ? getTransformationMetadata(events[0].metadata) : {}),
};

stats.counter('user_transform_function_input_events', events.length, tags)
stats.timing('user_transform_function_latency', startTime, tags)
stats.counter('user_transform_function_input_events', events.length, tags);
stats.timing('user_transform_function_latency', startTime, tags);
}
};

Expand Down
12 changes: 6 additions & 6 deletions src/v0/destinations/marketo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const formatConfig = (destination) => ({
ID: destination.ID,
...destination.Config,
customActivityEventMap: getHashFromArray(
destination.Config.customActivityEventMap,
'from',
'to',
destination.Config.rudderEventsMapping,
koladilip marked this conversation as resolved.
Show resolved Hide resolved
'event',
'marketoActivityId',
false,
),
customActivityPropertyMap: getHashFromArray(
Expand All @@ -27,9 +27,9 @@ const formatConfig = (destination) => ({
false,
),
customActivityPrimaryKeyMap: getHashFromArray(
destination.Config.customActivityPrimaryKeyMap,
'from',
'to',
destination.Config.rudderEventsMapping,
'event',
'marketoPrimarykey',
false,
),
leadTraitMapping: getHashFromArray(destination.Config.leadTraitMapping, 'from', 'to', false),
Expand Down
9 changes: 3 additions & 6 deletions test/__tests__/data/am_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -1074,9 +1074,7 @@
"CHILD_KEY_102": "value_103"
},
"name_trait": "Company",
"value_trait": [
"ABC"
]
"value_trait": ["ABC"]
},
"sentAt": "2020-10-20T07:54:58.983Z"
},
Expand Down Expand Up @@ -4313,8 +4311,7 @@
"All": true
},
"messageId": "1662393883248-509420bf-b812-4f8d-bdb2-8c811bfde87f",
"properties": {
},
"properties": {},
"originalTimestamp": "2022-09-05T16:04:43.250Z",
"type": "screen",
"userId": "User Android"
Expand Down Expand Up @@ -4943,4 +4940,4 @@
}
}
}
]
]
6 changes: 2 additions & 4 deletions test/__tests__/data/am_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,7 @@
"JSON_ARRAY": {},
"FORM": {
"api_key": "abcde",
"identification": [
"{\"group_type\":\"Company\",\"group_value\":\"ABC\"}"
]
"identification": ["{\"group_type\":\"Company\",\"group_value\":\"ABC\"}"]
}
},
"files": {},
Expand Down Expand Up @@ -4468,4 +4466,4 @@
"files": {},
"userId": "anon-id-new"
}
]
]
Loading
Loading