Skip to content

Commit

Permalink
chore: merge develop changes
Browse files Browse the repository at this point in the history
  • Loading branch information
utsabc committed Nov 10, 2023
2 parents 003aec7 + 0996e81 commit 12a1764
Show file tree
Hide file tree
Showing 264 changed files with 955 additions and 699 deletions.
35 changes: 30 additions & 5 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@koa/router": "^12.0.0",
"@ndhoule/extend": "^2.0.0",
"@pyroscope/nodejs": "^0.2.6",
"@rudderstack/integrations-lib": "^0.1.8",
"@rudderstack/workflow-engine": "^0.5.7",
"ajv": "^8.12.0",
"ajv-draft-04": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/networkhandler/genericNetworkHandler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { NetworkError } = require('@rudderstack/integrations-lib');
const { isHttpStatusSuccess } = require('../../v0/util/index');
const { proxyRequest, prepareProxyRequest } = require('../network');
const { getDynamicErrorType, processAxiosResponse } = require('../utils/networkUtils');
const { NetworkError } = require('../../v0/util/errorTypes');
const tags = require('../../v0/util/tags');

/**
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/utils/networkUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable eqeqeq */
const lodash = require('lodash');
const { isEmpty } = require('lodash');
const { AbortedError } = require('@rudderstack/integrations-lib');
const {
isHttpStatusRetryable,
isDefinedAndNotNullAndNotEmpty,
Expand All @@ -9,7 +10,6 @@ const {
isHttpStatusSuccess,
getErrorStatusCode,
} = require('../../v0/util');
const { AbortedError } = require('../../v0/util/errorTypes');
const tags = require('../../v0/util/tags');
const { HTTP_STATUS_CODES } = require('../../v0/util/constant');

Expand Down
2 changes: 1 addition & 1 deletion src/cdk/v1/autopilot/transform.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Utils } = require('rudder-transformer-cdk');
const { InstrumentationError } = require('../../../v0/util/errorTypes');
const { InstrumentationError } = require('@rudderstack/integrations-lib');

function identifyPostMapper(event, mappedPayload) {
const { message } = event;
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/v1/dcm_floodlight/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
removeUndefinedAndNullValues,
isDefinedAndNotNull,
} = require('rudder-transformer-cdk/build/utils');
const { ConfigurationError, InstrumentationError } = require('@rudderstack/integrations-lib');
const {
getIntegrationsObj,
isEmpty,
Expand All @@ -14,7 +15,6 @@ const {
} = require('../../../v0/util');
const { GENERIC_TRUE_VALUES, GENERIC_FALSE_VALUES } = require('../../../constants');
const { BASE_URL, BLACKLISTED_CHARACTERS } = require('./config');
const { ConfigurationError, InstrumentationError } = require('../../../v0/util/errorTypes');

// append properties to endpoint
// eg: ${BASE_URL}key1=value1;key2=value2;....
Expand Down
8 changes: 4 additions & 4 deletions src/cdk/v1/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const path = require('path');
const basePath = path.resolve(__dirname);
ConfigFactory.init({ basePath, loggingMode: 'production' });

const tags = require('../../v0/util/tags');
const { generateErrorObject } = require('../../v0/util');
const {
InstrumentationError,
TransformationError,
ConfigurationError,
InstrumentationError,
} = require('../../v0/util/errorTypes');
} = require('@rudderstack/integrations-lib');
const tags = require('../../v0/util/tags');
const { generateErrorObject } = require('../../v0/util');

const defTags = {
[tags.TAG_NAMES.IMPLEMENTATION]: tags.IMPLEMENTATIONS.CDK_V1,
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/v2/bindings/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const {
InstrumentationError,
ConfigurationError,
NetworkError,
} = require('../../../v0/util/errorTypes');
} = require('@rudderstack/integrations-lib');
const { isHttpStatusSuccess } = require('../../../v0/util');
const { getDynamicErrorType } = require('../../../adapters/utils/networkUtils');
const tags = require('../../../v0/util/tags');
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/v2/destinations/dcm_floodlight/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const lodash = require('lodash');
const { InstrumentationError } = require('@rudderstack/integrations-lib');
const { getValueFromPropertiesOrTraits, getHashFromArray } = require('../../../../v0/util');
const { GENERIC_TRUE_VALUES, GENERIC_FALSE_VALUES } = require('../../../../constants');
const { InstrumentationError } = require('../../../../v0/util/errorTypes');

// valid flag should be provided [1|true] or [0|false]
const mapFlagValue = (key, value) => {
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/v2/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'path';
import fs from 'fs/promises';
import { WorkflowExecutionError, WorkflowCreationError } from '@rudderstack/workflow-engine';
import { PlatformError } from '@rudderstack/integrations-lib';
import logger from '../../logger';
import { generateErrorObject } from '../../v0/util';
import { PlatformError } from '../../v0/util/errorTypes';
import tags from '../../v0/util/tags';
import { CatchErr } from '../../util/types';

Expand Down
9 changes: 7 additions & 2 deletions src/controllers/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ export class SourceController {
const { version, source }: { version: string; source: string } = ctx.params;
const integrationService = ServiceSelector.getNativeSourceService();
try {
const resplist = await integrationService.sourceTransformRoutine(
events,
const { implementationVersion, input } = ControllerUtility.adaptInputToVersion(
source,
version,
events,
);
const resplist = await integrationService.sourceTransformRoutine(
input,
source,
implementationVersion,
requestMetadata,
);
ctx.body = resplist;
Expand Down
149 changes: 149 additions & 0 deletions src/controllers/util/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import { ControllerUtility } from './index';

describe('adaptInputToVersion', () => {
it('should return the input unchanged when the implementation version is not found', () => {
const sourceType = 'NA_SOURCE';
const requestVersion = 'v0';
const input = [
{ key1: 'val1', key2: 'val2' },
{ key1: 'val1', key2: 'val2' },
{ key1: 'val1', key2: 'val2' },
];
const expected = {
implementationVersion: undefined,
input: [
{ key1: 'val1', key2: 'val2' },
{ key1: 'val1', key2: 'val2' },
{ key1: 'val1', key2: 'val2' },
],
};

const result = ControllerUtility.adaptInputToVersion(sourceType, requestVersion, input);

expect(result).toEqual(expected);
});
it('should return the input unchanged when the implementation version and request version are the same i.e. v0', () => {
const sourceType = 'pipedream';
const requestVersion = 'v0';
const input = [
{ key1: 'val1', key2: 'val2' },
{ key1: 'val1', key2: 'val2' },
{ key1: 'val1', key2: 'val2' },
];
const expected = {
implementationVersion: 'v0',
input: [
{ key1: 'val1', key2: 'val2' },
{ key1: 'val1', key2: 'val2' },
{ key1: 'val1', key2: 'val2' },
],
};

const result = ControllerUtility.adaptInputToVersion(sourceType, requestVersion, input);

expect(result).toEqual(expected);
});
it('should return the input unchanged when the implementation version and request version are the same i.e. v1', () => {
const sourceType = 'webhook';
const requestVersion = 'v1';
const input = [
{
event: { key1: 'val1', key2: 'val2' },
source: { id: 'source_id', config: { configField1: 'configVal1' } },
},
{
event: { key1: 'val1', key2: 'val2' },
source: { id: 'source_id', config: { configField1: 'configVal1' } },
},
{
event: { key1: 'val1', key2: 'val2' },
source: { id: 'source_id', config: { configField1: 'configVal1' } },
},
];
const expected = {
implementationVersion: 'v1',
input: [
{
event: { key1: 'val1', key2: 'val2' },
source: { id: 'source_id', config: { configField1: 'configVal1' } },
},
{
event: { key1: 'val1', key2: 'val2' },
source: { id: 'source_id', config: { configField1: 'configVal1' } },
},
{
event: { key1: 'val1', key2: 'val2' },
source: { id: 'source_id', config: { configField1: 'configVal1' } },
},
],
};

const result = ControllerUtility.adaptInputToVersion(sourceType, requestVersion, input);

expect(result).toEqual(expected);
});
it('should convert input from v0 to v1 when the request version is v0 and the implementation version is v1', () => {
const sourceType = 'webhook';
const requestVersion = 'v0';
const input = [
{ key1: 'val1', key2: 'val2' },
{ key1: 'val1', key2: 'val2' },
{ key1: 'val1', key2: 'val2' },
];
const expected = {
implementationVersion: 'v1',
input: [
{ event: { key1: 'val1', key2: 'val2' }, source: undefined },
{ event: { key1: 'val1', key2: 'val2' }, source: undefined },
{ event: { key1: 'val1', key2: 'val2' }, source: undefined },
],
};

const result = ControllerUtility.adaptInputToVersion(sourceType, requestVersion, input);

expect(result).toEqual(expected);
});

it('should convert input from v1 to v0 format when the request version is v1 and the implementation version is v0', () => {
const sourceType = 'pipedream';
const requestVersion = 'v1';
const input = [
{
event: { key1: 'val1', key2: 'val2' },
source: { id: 'source_id', config: { configField1: 'configVal1' } },
},
{
event: { key1: 'val1', key2: 'val2' },
source: { id: 'source_id', config: { configField1: 'configVal1' } },
},
{
event: { key1: 'val1', key2: 'val2' },
source: { id: 'source_id', config: { configField1: 'configVal1' } },
},
];
const expected = {
implementationVersion: 'v0',
input: [
{ key1: 'val1', key2: 'val2' },
{ key1: 'val1', key2: 'val2' },
{ key1: 'val1', key2: 'val2' },
],
};

const result = ControllerUtility.adaptInputToVersion(sourceType, requestVersion, input);

expect(result).toEqual(expected);
});

// Should return an empty array when the input is an empty array
it('should return an empty array when the input is an empty array', () => {
const sourceType = 'pipedream';
const requestVersion = 'v1';
const input = [];
const expected = { implementationVersion: 'v0', input: [] };

const result = ControllerUtility.adaptInputToVersion(sourceType, requestVersion, input);

expect(result).toEqual(expected);
});
});
Loading

0 comments on commit 12a1764

Please sign in to comment.