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: handling invalid timestamp for adjust source #3866

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/v0/sources/adjust/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Message = require('../message');
const { CommonUtils } = require('../../../util/common');
const { excludedFieldList } = require('./config');
const { extractCustomFields, generateUUID } = require('../../util');
const { processTimestamp } = require('./utils');

// ref : https://help.adjust.com/en/article/global-callbacks#general-recommended-placeholders
// import mapping json using JSON.parse to preserve object key order
Expand Down Expand Up @@ -43,11 +44,10 @@ const processEvent = (inputEvent) => {
message.properties = { ...message.properties, ...customProperties };

if (formattedPayload.created_at) {
const ts = new Date(formattedPayload.created_at * 1000).toISOString();
const ts = processTimestamp(formattedPayload.created_at);
message.setProperty('originalTimestamp', ts);
message.setProperty('timestamp', ts);
}

// adjust does not has the concept of user but we need to set some random anonymousId in order to make the server accept the message
message.anonymousId = generateUUID();
return message;
Expand Down
14 changes: 14 additions & 0 deletions src/v0/sources/adjust/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { TransformationError } = require('@rudderstack/integrations-lib');

const processTimestamp = (rawTimestamp) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better name would be getTimestamp I believe. Let's make this minor change

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we keep in the outside utils? can this be useful in other destination built down the line?

try {
const createdAt = Number(rawTimestamp);
return new Date(createdAt * 1000).toISOString();
} catch (error) {
throw new TransformationError(`[Adjust] Invalid timestamp "${rawTimestamp}": ${error.message}`);
}
};

module.exports = {
processTimestamp,
};
53 changes: 53 additions & 0 deletions test/integrations/sources/adjust/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,57 @@ export const data = [
defaultMockFns();
},
},
{
name: 'adjust',
description: 'Simple track call with wrong created at',
module: 'source',
version: 'v0',
skipGo: 'FIXME',
input: {
request: {
body: [
{
id: 'adjust',
query_parameters: {
gps_adid: ['38400000-8cf0-11bd-b23e-10b96e40000d'],
adid: ['18546f6171f67e29d1cb983322ad1329'],
tracker_token: ['abc'],
custom: ['custom'],
tracker_name: ['dummy'],
created_at: ['test'],
event_name: ['Click'],
},
updated_at: '2023-02-10T12:16:07.251Z',
created_at: 'test',
},
],
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
},
pathSuffix: '',
},
output: {
response: {
status: 200,
body: [
{
error: '[Adjust] Invalid timestamp "test": Invalid time value',
statTags: {
destinationId: 'Non determinable',
errorCategory: 'transformation',
implementation: 'native',
module: 'source',
workspaceId: 'Non determinable',
},
statusCode: 400,
},
],
},
},
mockFns: () => {
defaultMockFns();
},
},
];
Loading