Skip to content

Commit

Permalink
chore: small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 committed Sep 3, 2024
1 parent 9ccebdf commit fe95d2b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
"WUNDERKIND": true,
"CLICKSEND": true,
"ZOHO": true,
"CORDIAL": true
"CORDIAL": true,
"X_AUDIENCE": true
},
"regulations": [
"BRAZE",
Expand Down
18 changes: 14 additions & 4 deletions src/v0/destinations/x_audience/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const {
removeUndefinedAndNullAndEmptyValues,
InstrumentationError,
ConfigurationError,
} = require('@rudderstack/integrations-lib');
const { handleRtTfSingleEventError } = require('../../util');
const { batchEvents, buildResponseWithJSON, getUserDetails } = require('./utils');
Expand All @@ -16,6 +17,13 @@ const processRecordEvent = (message, config) => {
if (type !== 'record') {
throw new InstrumentationError(`[X AUDIENCE]: ${type} is not supported`);
}
const { accountId, audienceId } = { config };
if (accountId) {
throw new ConfigurationError('[X AUDIENCE]: Account Id not found');
}
if (audienceId) {
throw new ConfigurationError('[X AUDIENCE]: Audience Id not found');
}
const { effective_at, expires_at } = fields;
const users = [getUserDetails(fields, config)];

Expand All @@ -30,14 +38,16 @@ const processRecordEvent = (message, config) => {
};
const process = (event) => {
const { message, destination, metadata } = event;
const { config } = destination;
const payload = [processRecordEvent(message, config)];
return buildResponseWithJSON(payload, config, metadata);
const { Config } = destination;

const payload = [processRecordEvent(message, Config)];
return buildResponseWithJSON(payload, Config, metadata);
};
const processRouterDest = async (inputs, reqMetadata) => {
const responseList = []; // list containing single track event payload
const errorRespList = []; // list of error
const { destination } = inputs[0];
const { Config } = destination;
inputs.map(async (event) => {
try {
if (event.message.statusCode) {
Expand All @@ -46,7 +56,7 @@ const processRouterDest = async (inputs, reqMetadata) => {
} else {
// if not transformed
responseList.push({
message: processRecordEvent(event.message, destination?.config),
message: processRecordEvent(event.message, Config),
metadata: event.metadata,
destination,
});
Expand Down
11 changes: 6 additions & 5 deletions src/v0/destinations/x_audience/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ const getOAuthFields = ({ secret }) => {
};

// Docs: https://developer.x.com/en/docs/x-ads-api/audiences/api-reference/custom-audience-user
const buildResponseWithJSON = (JSON, config, metadata) => {
const buildResponseWithJSON = (payload, config, metadata) => {
const response = defaultRequestConfig();
response.endpoint = BASE_URL.replace(':account_id', config.accountId).replace(
const accountId = Object.values(JSON.parse(config.accountId))[0];
response.endpoint = BASE_URL.replace(':account_id', accountId).replace(
':audience_id',
config.audienceId,
);
response.method = defaultPostRequestConfig.requestMethod;
response.body.JSON = JSON;
response.body.JSON = payload;
// required to be in accordance with oauth package
const request = {
url: response.endpoint,
Expand Down Expand Up @@ -86,7 +87,7 @@ const getFinalResponseList = (operationObjectList, destination) => {
) {
respList.push(
getSuccessRespEvents(
buildResponseWithJSON(currentBatchedRequest, destination.config, metadataWithSecret),
buildResponseWithJSON(currentBatchedRequest, destination.Config, metadataWithSecret),
currentMetadataList,
destination,
true,
Expand All @@ -102,7 +103,7 @@ const getFinalResponseList = (operationObjectList, destination) => {
// pushing the remainder operation payloads as well
respList.push(
getSuccessRespEvents(
buildResponseWithJSON(currentBatchedRequest, destination.config, metadataWithSecret),
buildResponseWithJSON(currentBatchedRequest, destination.Config, metadataWithSecret),
currentMetadataList,
destination,
true,
Expand Down
4 changes: 2 additions & 2 deletions test/integrations/destinations/x_audience/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export const authHeaderConstant =
'"OAuth oauth_consumer_key="validConsumerKey", oauth_nonce="j8kZvaJQRTaLX8h460CgHNs6rCEArNOW", oauth_signature="uAu%2FGdA6qPGW88pjVd7%2FgnAlHtM%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1725014809", oauth_token="validAccessToken", oauth_version="1.0"';

export const destination = {
config: {
accountId: '1234',
Config: {
accountId: '{"Dummy Name":"1234"}',
audienceId: 'dummyId',
},
ID: 'xpixel-1234',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const data = [
request: {
body: [
{
destination: { ...destination, config: { ...destination.config, enableHash: true } },
destination: { ...destination, Config: { ...destination.Config, enableHash: true } },
message: {
type: 'record',
action: 'insert',
Expand Down

0 comments on commit fe95d2b

Please sign in to comment.