Skip to content

Commit

Permalink
chore: onboard sfmc with record event to support mirror mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSudip committed Sep 6, 2024
1 parent f7783d8 commit 3e2cf8e
Showing 1 changed file with 51 additions and 13 deletions.
64 changes: 51 additions & 13 deletions src/v0/destinations/sfmc/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,29 +283,66 @@ const responseBuilderSimple = async ({ message, destination, metadata }, categor
throw new ConfigurationError(`Event type '${category.type}' not supported`);
};

const addResponseBuilder = ({
traits,
destinationExternalId,
identifierType,
subDomain,
externalKey,
token,
}) => {
const response = defaultRequestConfig();
response.method = defaultPutRequestConfig.requestMethod;
response.endpoint = `https://${subDomain}.${ENDPOINTS.INSERT_CONTACTS}${externalKey}/rows/${identifierType}:${destinationExternalId}`;
response.headers = {
'Content-Type': JSON_MIME_TYPE,
Authorization: `Bearer ${token}`,
};
response.body.JSON = {
values: {
...traits,
},
};
return response;
};

const retlResponseBuilder = async (message, destination, metadata) => {
const { clientId, clientSecret, subDomain, externalKey } = destination.Config;
const token = await accessTokenCache.get(metadata.destinationId, () =>
getToken(clientId, clientSecret, subDomain, metadata),
);

const { destinationExternalId, objectType, identifierType } = getDestinationExternalIDInfoForRetl(
message,
'SFMC',
);

// This part will handle the mirror mode
const { type, action } = message;
if (type === 'record') {
if (action === 'insert') {
return addResponseBuilder({

Check failure on line 324 in src/v0/destinations/sfmc/transform.js

View workflow job for this annotation

GitHub Actions / Check for formatting & lint errors

Use destructured variables over properties

Check failure on line 324 in src/v0/destinations/sfmc/transform.js

View workflow job for this annotation

GitHub Actions / Code Coverage

Use destructured variables over properties
traits: message.fields,

Check failure on line 325 in src/v0/destinations/sfmc/transform.js

View workflow job for this annotation

GitHub Actions / Check for formatting & lint errors

Use destructured variables over properties

Check failure on line 325 in src/v0/destinations/sfmc/transform.js

View workflow job for this annotation

GitHub Actions / Code Coverage

Use destructured variables over properties
destinationExternalId: message.fields[identifierType],
identifierType,
subDomain,
externalKey,
token,
});
}
}

// This part will handle the upsert mode

if (objectType?.toLowerCase() === 'data extension') {

Check failure on line 337 in src/v0/destinations/sfmc/transform.js

View workflow job for this annotation

GitHub Actions / Check for formatting & lint errors

Use destructured variables over properties

Check failure on line 337 in src/v0/destinations/sfmc/transform.js

View workflow job for this annotation

GitHub Actions / Code Coverage

Use destructured variables over properties
const response = defaultRequestConfig();
response.method = defaultPutRequestConfig.requestMethod;
response.endpoint = `https://${subDomain}.${ENDPOINTS.INSERT_CONTACTS}${externalKey}/rows/${identifierType}:${destinationExternalId}`;
response.headers = {
'Content-Type': JSON_MIME_TYPE,
Authorization: `Bearer ${token}`,
};
response.body.JSON = {
values: {
...message.traits,
},
};
return response;
return addResponseBuilder({
traits: message.traits,
destinationExternalId,
identifierType,
subDomain,
externalKey,
token,
});
}
throw new PlatformError('Unsupported object type for rETL use case');
};
Expand Down Expand Up @@ -344,6 +381,7 @@ const process = async (event) => {

const processRouterDest = async (inputs, reqMetadata) => {

Check warning on line 382 in src/v0/destinations/sfmc/transform.js

View workflow job for this annotation

GitHub Actions / Check for formatting & lint errors

Unexpected console statement

Check warning on line 382 in src/v0/destinations/sfmc/transform.js

View workflow job for this annotation

GitHub Actions / Code Coverage

Unexpected console statement
const respList = await simpleProcessRouterDest(inputs, process, reqMetadata);
console.log(JSON.stringify(respList));
return respList;
};

Expand Down

0 comments on commit 3e2cf8e

Please sign in to comment.