From b3d9aabfbe9b852e9d23555b6c44fd3469945c74 Mon Sep 17 00:00:00 2001 From: Vinay Teki Date: Mon, 2 Dec 2024 23:01:13 +0530 Subject: [PATCH] chore: upgrade adjust source to v2 spec --- src/controllers/util/index.ts | 2 +- src/{v0 => v2}/sources/adjust/config.ts | 0 src/{v0 => v2}/sources/adjust/mapping.json | 0 src/{v0 => v2}/sources/adjust/transform.js | 24 +++--- src/{v0 => v2}/sources/adjust/utils.js | 0 src/{v0 => v2}/sources/adjust/utils.test.js | 0 test/integrations/sources/adjust/data.ts | 87 ++++++++++++++------- 7 files changed, 74 insertions(+), 39 deletions(-) rename src/{v0 => v2}/sources/adjust/config.ts (100%) rename src/{v0 => v2}/sources/adjust/mapping.json (100%) rename src/{v0 => v2}/sources/adjust/transform.js (76%) rename src/{v0 => v2}/sources/adjust/utils.js (100%) rename src/{v0 => v2}/sources/adjust/utils.test.js (100%) diff --git a/src/controllers/util/index.ts b/src/controllers/util/index.ts index ab2a0f5dc3..f44c688706 100644 --- a/src/controllers/util/index.ts +++ b/src/controllers/util/index.ts @@ -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, diff --git a/src/v0/sources/adjust/config.ts b/src/v2/sources/adjust/config.ts similarity index 100% rename from src/v0/sources/adjust/config.ts rename to src/v2/sources/adjust/config.ts diff --git a/src/v0/sources/adjust/mapping.json b/src/v2/sources/adjust/mapping.json similarity index 100% rename from src/v0/sources/adjust/mapping.json rename to src/v2/sources/adjust/mapping.json diff --git a/src/v0/sources/adjust/transform.js b/src/v2/sources/adjust/transform.js similarity index 76% rename from src/v0/sources/adjust/transform.js rename to src/v2/sources/adjust/transform.js index f68e87d476..6a27e81d10 100644 --- a/src/v0/sources/adjust/transform.js +++ b/src/v2/sources/adjust/transform.js @@ -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'); } + + 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); diff --git a/src/v0/sources/adjust/utils.js b/src/v2/sources/adjust/utils.js similarity index 100% rename from src/v0/sources/adjust/utils.js rename to src/v2/sources/adjust/utils.js diff --git a/src/v0/sources/adjust/utils.test.js b/src/v2/sources/adjust/utils.test.js similarity index 100% rename from src/v0/sources/adjust/utils.test.js rename to src/v2/sources/adjust/utils.test.js diff --git a/test/integrations/sources/adjust/data.ts b/test/integrations/sources/adjust/data.ts index 107bb444c4..a8e04ad97e 100644 --- a/test/integrations/sources/adjust/data.ts +++ b/test/integrations/sources/adjust/data.ts @@ -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', @@ -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', @@ -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', @@ -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',