Skip to content

Commit

Permalink
fix: adding uuid transformation for airship (#3884)
Browse files Browse the repository at this point in the history
* fix: adding uuid transformation for airship

* fix: adding doc refs
  • Loading branch information
shrouti1507 authored Nov 18, 2024
1 parent c43f0bd commit a80f874
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"truncate-utf8-bytes": "^1.0.2",
"ua-parser-js": "^1.0.37",
"unset-value": "^2.0.1",
"uuid": "^9.0.0",
"uuid": "^9.0.1",
"valid-url": "^1.0.9",
"zod": "^3.22.4"
},
Expand Down
4 changes: 4 additions & 0 deletions src/v0/destinations/airship/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const {
simpleProcessRouterDest,
} = require('../../util');
const { JSON_MIME_TYPE } = require('../../util/constant');
const { transformSessionId } = require('./utils');

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

Expand Down Expand Up @@ -128,6 +129,9 @@ const trackResponseBuilder = async (message, { Config }) => {

name = name.toLowerCase();
const payload = constructPayload(message, trackMapping);
if (isDefinedAndNotNullAndNotEmpty(payload.session_id)) {
payload.session_id = transformSessionId(payload.session_id);
}
let properties = {};
properties = extractCustomFields(message, properties, ['properties'], AIRSHIP_TRACK_EXCLUSION);
if (!isEmptyObject(properties)) {
Expand Down
12 changes: 12 additions & 0 deletions src/v0/destinations/airship/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { v5 } = require('uuid');

// ref : https://docs.airship.com/api/ua/#operation-api-custom-events-post
const transformSessionId = (rawSessionId) => {
const NAMESPACE = v5.DNS;
const uuidV5 = v5(rawSessionId, NAMESPACE);
return uuidV5;
};

module.exports = {
transformSessionId,
};
6 changes: 3 additions & 3 deletions test/integrations/destinations/airship/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2296,7 +2296,7 @@ export const data = [
},
{
name: 'airship',
description: 'Test 22',
description: 'Test 22 : session id gets converted to v5 uuid format',
feature: 'processor',
module: 'destination',
version: 'v0',
Expand All @@ -2321,7 +2321,7 @@ export const data = [
ip: '0.0.0.0',
os: { name: '', version: '' },
screen: { density: 2 },
sessionId: '3049dc4c-5a95-4ccd-a3e7-d74a7e411f22',
sessionId: '1731403898',
},
type: 'track',
messageId: '84e26acc-56a5-4835-8233-591137fca468',
Expand Down Expand Up @@ -2365,7 +2365,7 @@ export const data = [
user: { named_user_id: 'testuserId1' },
body: {
name: 'product_clicked',
session_id: '3049dc4c-5a95-4ccd-a3e7-d74a7e411f22',
session_id: 'd5627eac-795d-5005-9bb4-2c7c0af6cab0',
},
},
JSON_ARRAY: {},
Expand Down

0 comments on commit a80f874

Please sign in to comment.