Skip to content

Commit

Permalink
feat: initial changes, move instrumentation to v2 file
Browse files Browse the repository at this point in the history
  • Loading branch information
yashasvibajpai committed Feb 25, 2024
1 parent 41f4078 commit c82879e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/v0/destinations/redis/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const flatten = require('flat');
const { InstrumentationError } = require('@rudderstack/integrations-lib');
const { isEmpty, isObject } = require('../../util');
const { EventType } = require('../../../constants');
const { handleRecordEventsForRedis } = require('./transformV2');

// processValues:
// 1. removes keys with empty values or still an object(empty) after flattening
Expand Down Expand Up @@ -35,7 +36,10 @@ const transformSubEventTypeProfiles = (message, workspaceId, destinationId) => {
// form the hash
const hash = `${workspaceId}:${destinationId}:${message.context.sources.profiles_entity}:${message.context.sources.profiles_id_type}:${message.userId}`;
const key = `${message.context.sources.profiles_model}`;
const value = JSON.stringify(message.traits);
let value = JSON.stringify(message.traits);
if (message.type === EventType.RECORD) {
value = JSON.stringify(message.fields);

Check warning on line 41 in src/v0/destinations/redis/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/redis/transform.js#L41

Added line #L41 was not covered by tests
}
return {
message: {
hash,
Expand All @@ -48,6 +52,11 @@ const transformSubEventTypeProfiles = (message, workspaceId, destinationId) => {

const process = (event) => {
const { message, destination, metadata } = event;
// seperate record events
if (message.type === EventType.RECORD) {
return handleRecordEventsForRedis(message, destination, metadata);

Check warning on line 57 in src/v0/destinations/redis/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/redis/transform.js#L57

Added line #L57 was not covered by tests
}

const messageType = message && message.type && message.type.toLowerCase();

if (messageType !== EventType.IDENTIFY) {
Expand Down Expand Up @@ -102,4 +111,7 @@ const process = (event) => {
return result;
};

exports.process = process;
module.exports = {
process,
transformSubEventTypeProfiles,
};
45 changes: 45 additions & 0 deletions src/v0/destinations/redis/transformV2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const { transformSubEventTypeProfiles } = require('./transform');

// {
// "type": "record",
// "action": "delete", /* insert, delete */
// "channel": "sources",
// "context": {
// "sources": {
// "job_id": "2QZYNmlpjxJIoxywM1m2obqFyi7",
// "version": "v1.32.0",
// "job_run_id": "ck0c6g0u5hotr621tqu0",
// "task_run_id": "ck0c6g0u5hotr621tqug"
// "profiles_model": "some-model",
// "profiles_entity": "some-entity"
// "profiles_id_type": "some-id-type"
// },
// "externalId": [
// {
// "type": "FB_CUSTOM_AUDIENCE-21304823048",
// "identifierType": "EMAIL"
// }
// ],
// },
// "recordId": "a111",
// "messageId": "260f9a8d-91a7-46b0-9199-6da961dd6109",
// "fields": {
// MODEL_ID: '1691755780',
// VALID_AT: '2023-08-11T11:32:44.963062Z',
// USER_MAIN_ID: 'rid5530313526204a95efe71d98cd17d5a1',
// CHURN_SCORE_7_DAYS: 0.027986,
// PERCENTILE_CHURN_SCORE_7_DAYS: 0,
// },
// }

function handleRecordEventsForRedis(message, destination, metadata) {

Check warning on line 35 in src/v0/destinations/redis/transformV2.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/redis/transformV2.js#L35

Added line #L35 was not covered by tests
// fields -> traits
// metadata -> metadata
// context.sources.profiles_<$$$> -> context.sources.profiles_<$$$>
const { workspaceId } = metadata;
const destinationId = destination.ID;

Check warning on line 40 in src/v0/destinations/redis/transformV2.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/redis/transformV2.js#L39-L40

Added lines #L39 - L40 were not covered by tests

return transformSubEventTypeProfiles(message, workspaceId, destinationId);

Check warning on line 42 in src/v0/destinations/redis/transformV2.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/redis/transformV2.js#L42

Added line #L42 was not covered by tests
}

module.exports = { handleRecordEventsForRedis };

0 comments on commit c82879e

Please sign in to comment.