diff --git a/src/v0/destinations/fb_custom_audience/transformV2.js b/src/v0/destinations/fb_custom_audience/recordTransform.js similarity index 86% rename from src/v0/destinations/fb_custom_audience/transformV2.js rename to src/v0/destinations/fb_custom_audience/recordTransform.js index fd36d26a13..f863ca84c2 100644 --- a/src/v0/destinations/fb_custom_audience/transformV2.js +++ b/src/v0/destinations/fb_custom_audience/recordTransform.js @@ -4,21 +4,17 @@ 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 { @@ -26,6 +22,8 @@ const { getUpdatedDataElement, getSchemaForEventMappedToDest, batchingWithPayloadSize, + responseBuilderSimple, + getDataSource, } = require('./util'); function getErrorMetaData(inputs, acceptedOperations) { @@ -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, @@ -307,6 +274,4 @@ async function processRecordInputs(groupedRecordInputs) { module.exports = { processRecordInputs, - responseBuilderSimple, - getDataSource, }; diff --git a/src/v0/destinations/fb_custom_audience/transform.js b/src/v0/destinations/fb_custom_audience/transform.js index 0cc3bcbbda..80d22165ca 100644 --- a/src/v0/destinations/fb_custom_audience/transform.js +++ b/src/v0/destinations/fb_custom_audience/transform.js @@ -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 diff --git a/src/v0/destinations/fb_custom_audience/util.js b/src/v0/destinations/fb_custom_audience/util.js index aece635a15..401b601869 100644 --- a/src/v0/destinations/fb_custom_audience/util.js +++ b/src/v0/destinations/fb_custom_audience/util.js @@ -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'); @@ -220,6 +227,37 @@ 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`); +}; + module.exports = { prepareDataField, getSchemaForEventMappedToDest, @@ -227,4 +265,6 @@ module.exports = { ensureApplicableFormat, getUpdatedDataElement, generateAppSecretProof, + responseBuilderSimple, + getDataSource, };