Skip to content

Commit

Permalink
fix: conflict resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
AASHISH MALIK committed Dec 8, 2024
2 parents c333688 + 313710c commit d565ce6
Show file tree
Hide file tree
Showing 28 changed files with 538 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dt-test-and-report-code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 1
fetch-depth: 0

- name: Setup Node
uses: actions/[email protected]
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/prepare-for-staging-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ jobs:
runs-on: ubuntu-latest
needs: [generate-tag-names, build-transformer-image, build-user-transformer-image]
env:
TF_IMAGE_REPOSITORY: rudderstack/rudder-transformer
TAG_NAME: ${{ needs.generate-tag-names.outputs.tag_name }}
UT_TAG_NAME: ${{ needs.generate-tag-names.outputs.tag_name_ut }}
steps:
Expand Down Expand Up @@ -113,6 +114,7 @@ jobs:
git checkout -b $BRANCH_NAME
cd helm-charts/shared-services/per-az/environment/staging
yq eval -i ".rudder-transformer.image.repository=\"$TF_IMAGE_REPOSITORY\"" staging.yaml
yq eval -i ".rudder-transformer.image.tag=\"$TAG_NAME\"" staging.yaml
yq eval -i ".user-transformer.image.tag=\"$TAG_NAME\"" staging.yaml
git add staging.yaml
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ jobs:

- name: Filter JS/TS Files
run: |
echo "${{ steps.files.outputs.added_modified }}" | tr ' ' '\n' | grep -E '\.(js|ts|jsx|tsx)$' > changed_files.txt
if [ ! -s changed_files.txt ]; then
changed_files=$(echo "${{ steps.files.outputs.added_modified }}" | tr ' ' '\n' | grep -E '\.(js|ts|jsx|tsx)$' || true)
if [ -z "$changed_files" ]; then
echo "No JS/TS files to format or lint."
exit 0
fi
Expand Down
6 changes: 6 additions & 0 deletions src/util/prometheus.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,12 @@ class Prometheus {
type: 'gauge',
labelNames: ['destination_id'],
},
{
name: 'mailjet_packing_size',
help: 'mailjet_packing_size',
type: 'gauge',
labelNames: ['group'],
},
{
name: 'hs_batch_size',
help: 'hs_batch_size',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
getClickConversionPayloadAndEndpoint,
getConsentsDataFromIntegrationObj,
getCallConversionPayload,
updateConversion,
} = require('./utils');
const helper = require('./helper');

Expand Down Expand Up @@ -48,6 +49,9 @@ const getConversions = (message, metadata, { Config }, event, conversionType) =>
filteredCustomerId,
eventLevelConsentsData,
);
convertedPayload.payload.conversions[0] = updateConversion(
convertedPayload.payload.conversions[0],
);
payload = convertedPayload.payload;
endpoint = convertedPayload.endpoint;
} else if (conversionType === 'store') {
Expand Down
62 changes: 51 additions & 11 deletions src/v0/destinations/google_adwords_offline_conversions/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,35 @@ const getStoreConversionPayload = (message, Config, event) => {
return payload;
};

const hasClickId = (conversion) => {
const { gbraid, wbraid, gclid } = conversion;
return gclid || wbraid || gbraid;
};
const populateUserIdentifier = ({ email, phone, properties, payload, UserIdentifierSource }) => {
const copiedPayload = cloneDeep(payload);
// userIdentifierSource
// if userIdentifierSource doesn't exist in properties
// then it is taken from the webapp config
if (!properties.userIdentifierSource && UserIdentifierSource !== 'none') {
set(
copiedPayload,
'conversions[0].userIdentifiers[0].userIdentifierSource',
UserIdentifierSource,
);
// one of email or phone must be provided when none of gclid, wbraid and gbraid provided
}
if (!email && !phone) {
if (!hasClickId(copiedPayload.conversions[0])) {
throw new InstrumentationError(
`Either an email address or a phone number is required for user identification when none of gclid, wbraid, or gbraid is provided.`,
);
} else {
// we are deleting userIdentifiers if any one of gclid, wbraid and gbraid is there but email or phone is not present
delete copiedPayload.conversions[0].userIdentifiers;
}
}
return copiedPayload;
};
const getClickConversionPayloadAndEndpoint = (
message,
Config,
Expand All @@ -335,7 +364,7 @@ const getClickConversionPayloadAndEndpoint = (
updatedClickMapping = removeHashToSha256TypeFromMappingJson(updatedClickMapping);
}

const payload = constructPayload(message, updatedClickMapping);
let payload = constructPayload(message, updatedClickMapping);

const endpoint = CLICK_CONVERSION.replace(':customerId', filteredCustomerId);

Expand All @@ -353,17 +382,8 @@ const getClickConversionPayloadAndEndpoint = (
set(payload, 'conversions[0].cartData.items', itemList);
}

// userIdentifierSource
// if userIdentifierSource doesn't exist in properties
// then it is taken from the webapp config
if (!properties.userIdentifierSource && UserIdentifierSource !== 'none') {
set(payload, 'conversions[0].userIdentifiers[0].userIdentifierSource', UserIdentifierSource);
payload = populateUserIdentifier({ email, phone, properties, payload, UserIdentifierSource });

// one of email or phone must be provided
if (!email && !phone) {
throw new InstrumentationError(`Either of email or phone is required for user identifier`);
}
}
// either of email or phone should be passed
// defaultUserIdentifier depends on the webapp configuration
// Ref - https://developers.google.com/google-ads/api/rest/reference/rest/v11/customers/uploadClickConversions#ClickConversion
Expand Down Expand Up @@ -411,6 +431,25 @@ const getConsentsDataFromIntegrationObj = (message) => {
return integrationObj?.consents || {};
};

/**
* remove redundant ids
* @param {*} conversionCopy
*/
const updateConversion = (conversion) => {
const conversionCopy = cloneDeep(conversion);
if (conversionCopy.gclid) {
delete conversionCopy.wbraid;
delete conversionCopy.gbraid;
}
if (conversionCopy.wbraid && conversionCopy.gbraid) {
throw new InstrumentationError(`You can't use both wbraid and gbraid.`);
}
if (conversionCopy.wbraid || conversionCopy.gbraid) {
delete conversionCopy.userIdentifiers;
}
return conversionCopy;
};

module.exports = {
validateDestinationConfig,
generateItemListFromProducts,
Expand All @@ -423,4 +462,5 @@ module.exports = {
getExisitingUserIdentifier,
getConsentsDataFromIntegrationObj,
getCallConversionPayload,
updateConversion,
};
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ describe('getClickConversionPayloadAndEndpoint util tests', () => {
};
expect(() =>
getClickConversionPayloadAndEndpoint(fittingPayload, config, '9625812972'),
).toThrow('Either of email or phone is required for user identifier');
).toThrow(
'Either an email address or a phone number is required for user identification when none of gclid, wbraid, or gbraid is provided.',
);
});

it('finaliseConsent', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/v0/destinations/mailjet/transform.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const lodash = require('lodash');
const { TransformationError, InstrumentationError } = require('@rudderstack/integrations-lib');
const stats = require('../../../util/stats');
const {
getSuccessRespEvents,
defaultRequestConfig,
Expand Down Expand Up @@ -105,6 +106,9 @@ const batchEvents = (successRespList) => {
const eventChunks = lodash.chunk(eventGroups[combination], MAX_BATCH_SIZE);
// eventChunks = [[e1,e2,e3,..batchSize],[e1,e2,e3,..batchSize]..]
eventChunks.forEach((chunk) => {
stats.gauge('mailjet_packing_size', chunk.length, {
group: combination,
});
const batchEventResponse = generateBatchedPaylaodForArray(chunk, combination);
batchedResponseList.push(
getSuccessRespEvents(
Expand Down
38 changes: 21 additions & 17 deletions src/v0/util/facebookUtils/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ const errorDetailsMap = {
"Object with ID 'PIXEL_ID' / 'DATASET_ID' / 'AUDIENCE_ID' does not exist, cannot be loaded due to missing permissions, or does not support this operation",
)
.build(),
default: new ErrorDetailsExtractorBuilder().setStatus(400).setMessageField('message').build(),
default: new ErrorDetailsExtractorBuilder()
.setStatus(400)
.setMessageField('error_user_msg')
.build(),
},
1: {
// An unknown error occurred.
Expand All @@ -107,66 +110,64 @@ const errorDetailsMap = {
.setStat({
[TAG_NAMES.ERROR_TYPE]: ERROR_TYPES.AUTH,
})
.setMessage(
'The session has been invalidated because the user changed their password or Facebook has changed the session for security reasons',
)
.setMessageField('error_user_msg')
.build(),

463: new ErrorDetailsExtractorBuilder()
.setStatus(400)
.setStat({
[TAG_NAMES.ERROR_TYPE]: ERROR_TYPES.AUTH,
})
.setMessageField('message')
.setMessageField('error_user_msg')
.build(),
default: new ErrorDetailsExtractorBuilder()
.setStatus(400)
.setStat({
[TAG_NAMES.ERROR_TYPE]: ERROR_TYPES.AUTH,
})
.setMessage('Invalid OAuth 2.0 access token')
.setMessageField('error_user_msg')
.build(),
},
3: {
default: new ErrorDetailsExtractorBuilder()
.setStatus(400)
.setMessage('Capability or permissions issue.')
.setMessageField('error_user_msg')
.build(),
},
2: {
default: new ErrorDetailsExtractorBuilder()
.setStatus(500)
.setMessage('Temporary issue due to downtime.')
.setMessageField('error_user_msg')
.build(),
},
341: {
default: new ErrorDetailsExtractorBuilder()
.setStatus(500)
.setMessage('Application limit reached: Temporary issue due to downtime or throttling')
.setMessageField('error_user_msg')
.build(),
},
368: {
default: new ErrorDetailsExtractorBuilder()
.setStatus(500)
.setMessage('Temporarily blocked for policies violations.')
.setMessageField('error_user_msg')
.build(),
},
5000: {
default: new ErrorDetailsExtractorBuilder()
.setStatus(500)
.setMessage('Unknown Error Code')
.setMessageField('error_user_msg')
.build(),
},
4: {
default: new ErrorDetailsExtractorBuilder()
.setStatus(429)
.setMessage('API Too Many Calls')
.setMessageField('error_user_msg')
.build(),
},
17: {
default: new ErrorDetailsExtractorBuilder()
.setStatus(429)
.setMessage('API User Too Many Calls')
.setMessageField('error_user_msg')
.build(),
},
// facebook custom audience related error codes
Expand All @@ -176,9 +177,7 @@ const errorDetailsMap = {
294: {
default: new ErrorDetailsExtractorBuilder()
.setStatus(400)
.setMessage(
'Missing permission. Please make sure you have ads_management permission and the application is included in the allowlist',
)
.setMessageField('error_user_msg')
.build(),
},
1487301: {
Expand Down Expand Up @@ -214,7 +213,10 @@ const errorDetailsMap = {
.build(),
},
200: {
default: new ErrorDetailsExtractorBuilder().setStatus(403).setMessageField('message').build(),
default: new ErrorDetailsExtractorBuilder()
.setStatus(403)
.setMessageField('error_user_msg')
.build(),
},
21009: {
default: new ErrorDetailsExtractorBuilder().setStatus(500).setMessageField('message').build(),
Expand All @@ -236,9 +238,11 @@ const getStatus = (error) => {
const isErrorDetailEmpty = isEmpty(errorDetail);
if (isErrorDetailEmpty) {
// Unhandled error response
const errorMessage = get(error?.error || error, 'error_user_msg');
return {
status: errorStatus,
stats: { [TAG_NAMES.META]: METADATA.UNHANDLED_STATUS_CODE },
errorMessage: errorMessage || JSON.stringify(error),
};
}
errorStatus = errorDetail.status;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
/* eslint-disable @typescript-eslint/naming-convention */
const lodash = require('lodash');
const get = require('get-value');
// const { RedisError } = require('@rudderstack/integrations-lib');
const stats = require('../../../../util/stats');
const {
getShopifyTopic,
// createPropertiesForEcomEvent,
extractEmailFromPayload,
getAnonymousIdAndSessionId,
// getHashLineItems,
} = require('../../../../v0/sources/shopify/util');
// const logger = require('../../../logger');
const { getShopifyTopic, extractEmailFromPayload } = require('../../../../v0/sources/shopify/util');
const { removeUndefinedAndNullValues, isDefinedAndNotNull } = require('../../../../v0/util');
// const { RedisDB } = require('../../../util/redis/redisConnector');
const Message = require('../../../../v0/sources/message');
const { EventType } = require('../../../../constants');
const {
Expand All @@ -28,6 +19,7 @@ const {
const {
createPropertiesForEcomEventFromWebhook,
getProductsFromLineItems,
getAnonymousIdFromAttributes,
} = require('./serverSideUtlis');

const NO_OPERATION_SUCCESS = {
Expand Down Expand Up @@ -128,12 +120,9 @@ const processEvent = async (inputEvent, metricMetadata) => {
message.setProperty('traits.email', email);
}
}
// attach anonymousId if the event is track event using note_attributes
if (message.type !== EventType.IDENTIFY) {
const { anonymousId } = await getAnonymousIdAndSessionId(
message,
{ shopifyTopic, ...metricMetadata },
null,
);
const anonymousId = getAnonymousIdFromAttributes(event);
if (isDefinedAndNotNull(anonymousId)) {
message.setProperty('anonymousId', anonymousId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const {
getProductsFromLineItems,
createPropertiesForEcomEventFromWebhook,
getAnonymousIdFromAttributes,
} = require('./serverSideUtlis');

const { constructPayload } = require('../../../../v0/util');
Expand Down Expand Up @@ -109,4 +110,21 @@ describe('serverSideUtils.js', () => {
});
});
});

describe('getAnonymousIdFromAttributes', () => {
// Handles empty note_attributes array gracefully
it('should return null when note_attributes is an empty array', async () => {
const event = { note_attributes: [] };
const result = await getAnonymousIdFromAttributes(event);
expect(result).toBeNull();
});

it('get anonymousId from noteAttributes', async () => {
const event = {
note_attributes: [{ name: 'rudderAnonymousId', value: '123456' }],
};
const result = await getAnonymousIdFromAttributes(event);
expect(result).toEqual('123456');
});
});
});
Loading

0 comments on commit d565ce6

Please sign in to comment.