Skip to content

Commit

Permalink
chore: addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Vikas Venkatraman authored and Vikas Venkatraman committed May 28, 2024
1 parent c90f42e commit ad86160
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,26 @@ const get = require('get-value');
const {
InstrumentationError,
ConfigurationError,
TransformationError,
getErrorRespEvents,
} = require('@rudderstack/integrations-lib');
const { schemaFields, typeFields, subTypeFields, getEndPoint } = require('./config');
const { schemaFields } = require('./config');
const { MappedToDestinationKey } = require('../../../constants');
const stats = require('../../../util/stats');
const {
getDestinationExternalIDInfoForRetl,
isDefinedAndNotNullAndNotEmpty,
checkSubsetOfArray,
defaultRequestConfig,
returnArrayOfSubarrays,
getSuccessRespEvents,
defaultPostRequestConfig,
defaultDeleteRequestConfig,
generateErrorObject,
} = require('../../util');
const {
ensureApplicableFormat,
getUpdatedDataElement,
getSchemaForEventMappedToDest,
batchingWithPayloadSize,
responseBuilderSimple,
getDataSource,
} = require('./util');

function getErrorMetaData(inputs, acceptedOperations) {
Expand All @@ -41,37 +39,6 @@ function getErrorMetaData(inputs, acceptedOperations) {
return metadata;
}

const getDataSource = (type, subType) => {
const dataSource = {};
if (type && type !== 'NA' && typeFields.includes(type)) {
dataSource.type = type;
}
if (subType && subType !== 'NA' && subTypeFields.includes(subType)) {
dataSource.sub_type = subType;
}
return dataSource;
};

const responseBuilderSimple = (payload, audienceId) => {
if (payload) {
const responseParams = payload.responseField;
const response = defaultRequestConfig();
response.endpoint = getEndPoint(audienceId);

if (payload.operationCategory === 'add') {
response.method = defaultPostRequestConfig.requestMethod;
}
if (payload.operationCategory === 'remove') {
response.method = defaultDeleteRequestConfig.requestMethod;
}

response.params = responseParams;
return response;
}
// fail-safety for developer error
throw new TransformationError(`Payload could not be constructed`);
};

const processRecordEventArray = (
recordChunksArray,
userSchema,
Expand Down Expand Up @@ -307,6 +274,4 @@ async function processRecordInputs(groupedRecordInputs) {

module.exports = {
processRecordInputs,
responseBuilderSimple,
getDataSource,
};
4 changes: 3 additions & 1 deletion src/v0/destinations/fb_custom_audience/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ const {
getSchemaForEventMappedToDest,
batchingWithPayloadSize,
generateAppSecretProof,
responseBuilderSimple,
getDataSource,
} = require('./util');
const { schemaFields, USER_ADD, USER_DELETE } = require('./config');

const { MappedToDestinationKey } = require('../../../constants');
const { processRecordInputs, responseBuilderSimple, getDataSource } = require('./transformV2');
const { processRecordInputs } = require('./recordTransform');

function extraKeysPresent(dictionary, keyList) {
// eslint-disable-next-line no-restricted-syntax
Expand Down
40 changes: 40 additions & 0 deletions src/v0/destinations/fb_custom_audience/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ const crypto = require('crypto');
const get = require('get-value');
const jsonSize = require('json-size');
const { InstrumentationError, ConfigurationError } = require('@rudderstack/integrations-lib');
const { TransformationError } = require('@rudderstack/integrations-lib');
const { typeFields, subTypeFields, getEndPoint } = require('./config');
const {
defaultRequestConfig,
defaultPostRequestConfig,
defaultDeleteRequestConfig,
} = require('../../util');
const stats = require('../../../util/stats');

const { isDefinedAndNotNull } = require('../../util');
Expand Down Expand Up @@ -220,11 +227,44 @@ const generateAppSecretProof = (accessToken, appSecret, dateNow) => {
return appsecretProof;
};

const getDataSource = (type, subType) => {
const dataSource = {};
if (type && type !== 'NA' && typeFields.includes(type)) {
dataSource.type = type;
}
if (subType && subType !== 'NA' && subTypeFields.includes(subType)) {
dataSource.sub_type = subType;
}
return dataSource;
};

const responseBuilderSimple = (payload, audienceId) => {
if (payload) {
const responseParams = payload.responseField;
const response = defaultRequestConfig();
response.endpoint = getEndPoint(audienceId);

if (payload.operationCategory === 'add') {
response.method = defaultPostRequestConfig.requestMethod;
}
if (payload.operationCategory === 'remove') {
response.method = defaultDeleteRequestConfig.requestMethod;
}

response.params = responseParams;
return response;
}
// fail-safety for developer error
throw new TransformationError(`Payload could not be constructed`);

Check warning on line 258 in src/v0/destinations/fb_custom_audience/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/fb_custom_audience/util.js#L258

Added line #L258 was not covered by tests
};

module.exports = {
prepareDataField,
getSchemaForEventMappedToDest,
batchingWithPayloadSize,
ensureApplicableFormat,
getUpdatedDataElement,
generateAppSecretProof,
responseBuilderSimple,
getDataSource,
};

0 comments on commit ad86160

Please sign in to comment.