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

feat: upgrade adjust source to v2 spec #3911

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/controllers/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class ControllerUtility {
if (this.sourceVersionMap?.size > 0) {
return this.sourceVersionMap;
}
const versions = ['v0', 'v1'];
const versions = ['v0', 'v1', 'v2'];
versions.forEach((version) => {
const files = fs.readdirSync(path.resolve(__dirname, `../../${version}/sources`), {
withFileTypes: true,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
const lodash = require('lodash');
const path = require('path');
const fs = require('fs');
const { TransformationError } = require('@rudderstack/integrations-lib');
const logger = require('../../../logger');
const Message = require('../message');
const Message = require('../../../v0/sources/message');
const { CommonUtils } = require('../../../util/common');
const { excludedFieldList } = require('./config');
const { extractCustomFields, generateUUID } = require('../../util');
const { extractCustomFields, generateUUID } = require('../../../v0/util');
const { convertToISODate } = 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
const mapping = JSON.parse(fs.readFileSync(path.resolve(__dirname, './mapping.json'), 'utf-8'));

const formatProperties = (input) => {
const { query_parameters: qParams } = input;
const formatProperties = (qParams) => {
// const { query_parameters: qParams } = input;
logger.debug(`[Adjust] Input event: query_params: ${JSON.stringify(qParams)}`);
if (!qParams) {
throw new TransformationError('Query_parameters is missing');
throw new TransformationError('query parameters are missing');

Check warning on line 19 in src/v2/sources/adjust/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v2/sources/adjust/transform.js#L19

Added line #L19 was not covered by tests
}

if (qParams.writeKey !== undefined && Object.keys(qParams).length === 1) {
throw new TransformationError('query parameters are missing');
}

const formattedOutput = {};
Object.entries(qParams).forEach(([key, [value]]) => {
formattedOutput[key] = value;
if (key !== 'writeKey') {
formattedOutput[key] = value;
}
});
return formattedOutput;
};

const processEvent = (inputEvent) => {
const message = new Message(`Adjust`);
const event = lodash.cloneDeep(inputEvent);
const formattedPayload = formatProperties(event);
const formattedPayload = formatProperties(inputEvent.request.query_parameters);

// event type is always track
const eventType = 'track';
message.setEventType(eventType);
Expand Down
File renamed without changes.
87 changes: 58 additions & 29 deletions test/integrations/sources/adjust/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,38 @@ const defaultMockFns = () => {
jest.spyOn(utils, 'generateUUID').mockReturnValueOnce('97fcd7b2-cc24-47d7-b776-057b7b199513');
};

// adjust can only take v2 spec requests as there is no way to know which sources need to
export const data = [
{
name: 'adjust',
description: 'Simple track call',
module: 'source',
version: 'v0',
version: 'v2',
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: ['1404214665'],
event_name: ['Click'],
request: {
method: 'POST',
url: 'www.somerandom.site?writeKey=writekeyvalue&gps_adid=38400000-8cf0-11bd-b23e-10b96e40000d&adid=18546f6171f67e29d1cb983322ad1329&tracker_token=abc&custom=custom&tracker_name=dummy&created_at=1404214665&event_name=Click',
proto: 'HTTP/2.0',
query_parameters: {
gps_adid: ['38400000-8cf0-11bd-b23e-10b96e40000d'],
adid: ['18546f6171f67e29d1cb983322ad1329'],
tracker_token: ['abc'],
custom: ['custom'],
tracker_name: ['dummy'],
created_at: ['1404214665'],
event_name: ['Click'],
writeKey: 'writeKey',
},
body: {
id: 'adjust',
updated_at: '2023-02-10T12:16:07.251Z',
created_at: '2023-02-10T12:05:04.402Z',
},
},
updated_at: '2023-02-10T12:16:07.251Z',
created_at: '2023-02-10T12:05:04.402Z',
source: {},
},
],
method: 'POST',
Expand Down Expand Up @@ -83,17 +93,27 @@ export const data = [
},
{
name: 'adjust',
description: 'Simple track call with no query parameters',
description: 'Simple track call with no [external] query parameters',
module: 'source',
version: 'v0',
version: 'v2',
skipGo: 'FIXME',
input: {
request: {
body: [
{
id: 'adjust',
updated_at: '2023-02-10T12:16:07.251Z',
created_at: '2023-02-10T12:05:04.402Z',
request: {
method: 'POST',
url: 'www.somerandom.site?writeKey=writekeyvalue',
proto: 'HTTP/2.0',
body: {
id: 'adjust',
updated_at: '2023-02-10T12:16:07.251Z',
created_at: '2023-02-10T12:05:04.402Z',
},
query_parameters: {
writeKey: 'writeKey',
},
},
},
],
method: 'POST',
Expand All @@ -108,7 +128,7 @@ export const data = [
status: 200,
body: [
{
error: 'Query_parameters is missing',
error: 'query parameters are missing',
statTags: {
destinationId: 'Non determinable',
errorCategory: 'transformation',
Expand All @@ -135,18 +155,27 @@ export const data = [
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'],
request: {
method: 'POST',
url: 'www.somerandom.site?writeKey=writekeyvalue&gps_adid=38400000-8cf0-11bd-b23e-10b96e40000d&adid=18546f6171f67e29d1cb983322ad1329&tracker_token=abc&custom=custom&tracker_name=dummy&created_at=1404214665&event_name=Click',
proto: 'HTTP/2.0',
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'],
writeKey: 'writeKey',
},
body: {
id: 'adjust',
updated_at: '2023-02-10T12:16:07.251Z',
created_at: 'test',
},
},
updated_at: '2023-02-10T12:16:07.251Z',
created_at: 'test',
source: {},
},
],
method: 'POST',
Expand Down
Loading