Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: airship array handling #4011

Merged
merged 9 commits into from
Feb 5, 2025
1 change: 1 addition & 0 deletions src/constants/destinationCanonicalNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ const DestCanonicalNames = {
wunderkind: ['wunderkind', 'Wunderkind', 'WUNDERKIND'],
cordial: ['cordial', 'Cordial', 'CORDIAL'],
clevertap: ['clevertap', 'Clevertap', 'CleverTap', 'CLEVERTAP'],
airship: ['airship', 'Airship', 'AIRSHIP'],
};

module.exports = { DestHandlerMap, DestCanonicalNames };
72 changes: 8 additions & 64 deletions src/v0/destinations/airship/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const {
groupMapping,
BASE_URL_EU,
BASE_URL_US,
RESERVED_TRAITS_MAPPING,
AIRSHIP_TRACK_EXCLUSION,
} = require('./config');

Expand All @@ -25,6 +24,7 @@ const {
convertToUuid,
} = require('../../util');
const { JSON_MIME_TYPE } = require('../../util/constant');
const { prepareAttributePayload, prepareTagPayload } = require('./utils');

const DEFAULT_ACCEPT_HEADER = 'application/vnd.urbanairship+json; version=3';

Expand All @@ -37,7 +37,7 @@ const transformSessionId = (rawSessionId) => {
};

const identifyResponseBuilder = (message, { Config }) => {
const tagPayload = constructPayload(message, identifyMapping);
const initialTagPayload = constructPayload(message, identifyMapping);
const { apiKey, dataCenter } = Config;

if (!apiKey)
Expand All @@ -55,38 +55,10 @@ const identifyResponseBuilder = (message, { Config }) => {
}

// Creating tags and attribute payload
tagPayload.add = { rudderstack_integration: [] };
tagPayload.remove = { rudderstack_integration: [] };
let timestamp = getFieldValueFromMessage(message, 'timestamp');
timestamp = new Date(timestamp).toISOString().replace(/\.\d{3}/, '');
const tagPayload = prepareTagPayload(traits, initialTagPayload);

// Creating attribute payload
const attributePayload = { attributes: [] };
Object.keys(traits).forEach((key) => {
// tags
if (typeof traits[key] === 'boolean') {
const tag = key.toLowerCase().replace(/\./g, '_');
if (traits[key] === true) {
tagPayload.add.rudderstack_integration.push(tag);
}
if (traits[key] === false) {
tagPayload.remove.rudderstack_integration.push(tag);
}
}
// attribute
if (typeof traits[key] !== 'boolean') {
const attribute = { action: 'set' };
const keyMapped = RESERVED_TRAITS_MAPPING[key] || RESERVED_TRAITS_MAPPING[key.toLowerCase()];
if (keyMapped) {
attribute.key = keyMapped;
} else {
attribute.key = key.replace(/\./g, '_');
}
attribute.value = traits[key];
attribute.timestamp = timestamp;
attributePayload.attributes.push(attribute);
}
});
const attributePayload = prepareAttributePayload(traits, message);

let tagResponse;
let attributeResponse;
Expand Down Expand Up @@ -183,7 +155,7 @@ const trackResponseBuilder = async (message, { Config }) => {
};

const groupResponseBuilder = (message, { Config }) => {
const tagPayload = constructPayload(message, groupMapping);
const initTagPayload = constructPayload(message, groupMapping);
const { apiKey, dataCenter } = Config;

if (!apiKey)
Expand All @@ -200,37 +172,9 @@ const groupResponseBuilder = (message, { Config }) => {
);
}

tagPayload.add = { rudderstack_integration_group: [] };
tagPayload.remove = { rudderstack_integration_group: [] };
let timestamp = getFieldValueFromMessage(message, 'timestamp');
timestamp = new Date(timestamp).toISOString().replace(/\.\d{3}/, '');

const attributePayload = { attributes: [] };
Object.keys(traits).forEach((key) => {
// tags
if (typeof traits[key] === 'boolean') {
const tag = key.toLowerCase().replace(/\./g, '_');
if (traits[key] === true) {
tagPayload.add.rudderstack_integration_group.push(tag);
}
if (traits[key] === false) {
tagPayload.remove.rudderstack_integration_group.push(tag);
}
}
// attribute
if (typeof traits[key] !== 'boolean') {
const attribute = { action: 'set' };
const keyMapped = RESERVED_TRAITS_MAPPING[key.toLowerCase()];
if (keyMapped) {
attribute.key = keyMapped;
} else {
attribute.key = key.replace(/\./g, '_');
}
attribute.value = traits[key];
attribute.timestamp = timestamp;
attributePayload.attributes.push(attribute);
}
});
const tagPayload = prepareTagPayload(traits, initTagPayload, 'group');

const attributePayload = prepareAttributePayload(traits, message);

let tagResponse;
let attributeResponse;
Expand Down
Loading
Loading