Skip to content

Commit

Permalink
Merge branch 'develop', remote-tracking branch 'origin' into chore.la…
Browse files Browse the repository at this point in the history
…bels-int-api
  • Loading branch information
Sai Sankeerth committed Jul 5, 2024
3 parents 0890d1d + 56e5267 + 277c1f0 commit b9686ce
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 258 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [1.70.1](https://github.com/rudderlabs/rudder-transformer/compare/v1.70.0...v1.70.1) (2024-07-03)

### Bug Fixes

* revert fb pixel change ([769161a](https://github.com/rudderlabs/rudder-transformer/commit/a0026152e4763569dc05693af1639e5a44d47b05))

## [1.70.0](https://github.com/rudderlabs/rudder-transformer/compare/v1.69.1...v1.70.0) (2024-07-01)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rudder-transformer",
"version": "1.70.0",
"version": "1.70.1",
"description": "",
"homepage": "https://github.com/rudderlabs/rudder-transformer#readme",
"bugs": {
Expand Down
4 changes: 2 additions & 2 deletions src/cdk/v2/destinations/zapier/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ steps:
condition: $.context.messageType === {{$.EventType.TRACK}}
template: |
const trackEventsMap = $.getHashFromArray(.destination.Config.trackEventsToZap);
const eventName = .message.event;
const eventName = .message.event.toLowerCase();
(eventName && trackEventsMap[eventName]) ?
($.context.endpoint = trackEventsMap[eventName])
else:
name: endpointForOthers
template: |
const pageScreenEventsMap = $.getHashFromArray(.destination.Config.pageScreenEventsToZap);
const pageName = .message.name;
const pageName = .message.name.toLowerCase();
(pageName && pageScreenEventsMap[pageName]) ?
($.context.endpoint = pageScreenEventsMap[pageName])
- name: buildResponse
Expand Down
14 changes: 7 additions & 7 deletions src/v0/destinations/drip/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const {
} = require('./util');
const { JSON_MIME_TYPE } = require('../../util/constant');

const identifyResponseBuilder = async (message, { Config }) => {
const identifyResponseBuilder = async (message, { Config }, metadata) => {
const id = getDestinationExternalID(message, 'dripId');

let email = getFieldValueFromMessage(message, 'email');
Expand Down Expand Up @@ -117,7 +117,7 @@ const identifyResponseBuilder = async (message, { Config }) => {
response.method = defaultPostRequestConfig.requestMethod;
const campaignId = getDestinationExternalID(message, 'dripCampaignId') || Config.campaignId;
if (campaignId && email) {
const check = await createUpdateUser(finalpayload, Config, basicAuth);
const check = await createUpdateUser(finalpayload, Config, basicAuth, metadata);
if (!check) {
throw new NetworkInstrumentationError('Unable to create/update user.');
}
Expand All @@ -139,7 +139,7 @@ const identifyResponseBuilder = async (message, { Config }) => {
return response;
};

const trackResponseBuilder = async (message, { Config }) => {
const trackResponseBuilder = async (message, { Config }, metadata) => {
const id = getDestinationExternalID(message, 'dripId');

let email = getValueFromMessage(message, [
Expand All @@ -162,7 +162,7 @@ const trackResponseBuilder = async (message, { Config }) => {
event = event.trim().toLowerCase();

if (!Config.enableUserCreation && !id) {
const check = await userExists(Config, email);
const check = await userExists(Config, email, metadata);
if (!check) {
throw new NetworkInstrumentationError(
'User creation mode is disabled and user does not exist. Track call aborted.',
Expand Down Expand Up @@ -239,7 +239,7 @@ const trackResponseBuilder = async (message, { Config }) => {
};

const process = async (event) => {
const { message, destination } = event;
const { message, destination, metadata } = event;
if (!message.type) {
throw new InstrumentationError('Message Type is not present. Aborting message.');
}
Expand All @@ -255,10 +255,10 @@ const process = async (event) => {
let response;
switch (messageType) {
case EventType.IDENTIFY:
response = await identifyResponseBuilder(message, destination);
response = await identifyResponseBuilder(message, destination, metadata);
break;
case EventType.TRACK:
response = await trackResponseBuilder(message, destination);
response = await trackResponseBuilder(message, destination, metadata);
break;
default:
throw new InstrumentationError(`Message type ${messageType} not supported`);
Expand Down
125 changes: 65 additions & 60 deletions src/v0/destinations/drip/util.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { NetworkError, AbortedError } = require('@rudderstack/integrations-lib');
const myAxios = require('../../../util/myAxios');
const { getDynamicErrorType } = require('../../../adapters/utils/networkUtils');
const logger = require('../../../logger');
const { constructPayload, isDefinedAndNotNull } = require('../../util');
const { ENDPOINT, productMapping } = require('./config');
const tags = require('../../util/tags');
const { JSON_MIME_TYPE } = require('../../util/constant');
const { handleHttpRequest } = require('../../../adapters/network');

const isValidEmail = (email) => {
const re =
Expand All @@ -19,82 +19,87 @@ const isValidTimestamp = (timestamp) => {
return re.test(String(timestamp));
};

const userExists = async (Config, id) => {
const userExists = async (Config, id, metadata) => {
const basicAuth = Buffer.from(Config.apiKey).toString('base64');
let response;
try {
response = await myAxios.get(
`${ENDPOINT}/v2/${Config.accountId}/subscribers/${id}`,
{
headers: {
Authorization: `Basic ${basicAuth}`,
'Content-Type': JSON_MIME_TYPE,
},
},
{
destType: 'drip',
feature: 'transformation',
requestMethod: 'GET',
endpointPath: '/subscribers/id',
module: 'router',

const { httpResponse } = await handleHttpRequest(
'get',
`${ENDPOINT}/v2/${Config.accountId}/subscribers/${id}`,
{
headers: {
Authorization: `Basic ${basicAuth}`,
'Content-Type': JSON_MIME_TYPE,
},
);
if (response && response.status) {
return response.status === 200;
},
{
metadata,
destType: 'drip',
feature: 'transformation',
requestMethod: 'GET',
endpointPath: '/subscribers/id',
module: 'router',
},
);
if (httpResponse.success) {
if (httpResponse.response.status) {
return httpResponse.response.status === 200;
}
throw new NetworkError(
'Invalid response.',
response?.status,
httpResponse.response?.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(response?.status),
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(httpResponse.response.status),
},
response,
httpResponse.response,
);
} catch (error) {
let errMsg = '';
let errStatus = 400;
if (error.response) {
errStatus = error.response.status || 400;
errMsg = error.response.data
? JSON.stringify(error.response.data)
: 'error response not found';
}
throw new NetworkError(`Error occurred while checking user : ${errMsg}`, errStatus, {
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(errStatus),
});
}

const error = httpResponse.response?.response;
let errMsg = '';
let errStatus = 400;
if (error) {
errStatus = error.status || 400;
errMsg = error.data ? JSON.stringify(error.data) : 'error response not found';
}
throw new NetworkError(`Error occurred while checking user : ${errMsg}`, errStatus, {
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(errStatus),
});
};

const createUpdateUser = async (finalpayload, Config, basicAuth) => {
try {
const response = await myAxios.post(
`${ENDPOINT}/v2/${Config.accountId}/subscribers`,
finalpayload,
{
headers: {
Authorization: `Basic ${basicAuth}`,
'Content-Type': JSON_MIME_TYPE,
},
},
{
destType: 'drip',
feature: 'transformation',
requestMethod: 'POST',
endpointPath: '/subscribers',
module: 'router',
const createUpdateUser = async (finalpayload, Config, basicAuth, metadata) => {
const { httpResponse } = await handleHttpRequest(
'post',
`${ENDPOINT}/v2/${Config.accountId}/subscribers`,
finalpayload,
{
headers: {
Authorization: `Basic ${basicAuth}`,
'Content-Type': JSON_MIME_TYPE,
},
);
},
{
metadata,
destType: 'drip',
feature: 'transformation',
requestMethod: 'POST',
endpointPath: '/subscribers',
module: 'router',
},
);
if (httpResponse.success) {
const { response } = httpResponse;
if (response) {
return response.status === 200 || response.status === 201;
}
throw new AbortedError('Invalid response.');
} catch (error) {
let errMsg = '';
if (error.response && error.response.data) {
errMsg = JSON.stringify(error.response.data);
}
throw new AbortedError(`Error occurred while creating or updating user : ${errMsg}`);
}

const error = httpResponse.response;
let errMsg = '';
if (error.response && error.response.data) {
errMsg = JSON.stringify(error.response.data);
}
throw new AbortedError(`Error occurred while creating or updating user : ${errMsg}`);
};

const createList = (productList) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,5 @@
"context.traits.action_source",
"properties.action_source"
]
},
{
"destKey": "advertiser_tracking_enabled",
"sourceKeys": "context.device.adTrackingEnabled",
"required": false
}
]
11 changes: 7 additions & 4 deletions src/v0/destinations/kustomer/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const constructKustomerPayload = (message, category, email) => {

// Main process function responsible for building payload for all
// type of events.
const responseBuilderSimple = async (message, category, destination) => {
const responseBuilderSimple = async (message, category, destination, metadata) => {
let payload = {};

// Reference for base endpoint
Expand Down Expand Up @@ -119,6 +119,7 @@ const responseBuilderSimple = async (message, category, destination) => {
storedState = await fetchKustomer(
`${BASE_ENDPOINT}/v1/customers/email=${userEmail}`,
destination,
metadata,
);
}
// If response.userExists flag is false
Expand All @@ -128,6 +129,7 @@ const responseBuilderSimple = async (message, category, destination) => {
storedState = await fetchKustomer(
`${BASE_ENDPOINT}/v1/customers/externalId=${userId}`,
destination,
metadata,
);
}
// If response.userExists flag is still false
Expand All @@ -137,6 +139,7 @@ const responseBuilderSimple = async (message, category, destination) => {
storedState = await fetchKustomer(
`${BASE_ENDPOINT}/v1/customers/externalId=${get(message, 'anonymousId')}`,
destination,
metadata,
);
}
// URL to use for creating new Kustomer
Expand Down Expand Up @@ -206,7 +209,7 @@ const responseBuilderSimple = async (message, category, destination) => {
throw new TransformationError('Payload could not be constructed');
};

const processEvent = (message, destination) => {
const processEvent = (message, destination, metadata) => {
if (!message.type) {
throw new InstrumentationError('Event type is required');
}
Expand All @@ -227,10 +230,10 @@ const processEvent = (message, destination) => {
default:
throw new InstrumentationError(`Event type ${message.type} is not supported`);
}
return responseBuilderSimple(message, category, destination);
return responseBuilderSimple(message, category, destination, metadata);
};

const process = (event) => processEvent(event.message, event.destination);
const process = (event) => processEvent(event.message, event.destination, event.metadata);

const processRouterDest = async (inputs, reqMetadata) => {
const respList = await simpleProcessRouterDest(inputs, process, reqMetadata);
Expand Down
Loading

0 comments on commit b9686ce

Please sign in to comment.