Skip to content

Commit

Permalink
Merge branch 'develop' into feat.x_audience
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 authored Sep 6, 2024
2 parents 14b7019 + f7783d8 commit ad18883
Show file tree
Hide file tree
Showing 10 changed files with 6,008 additions and 458 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"type": "alias",
"previousId": "[email protected]",
"userId": "12345",
"context": {},
"receivedAt": "2024-03-03T04:48:29.000Z",
"request_ip": "192.0.2.30",
"messageId": "00000000-0000-0000-0000-000000000000"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
{
"userId": "1",
"originalTimestamp": "2020-09-28T19:53:31.900Z",
"context": {},
"traits": {
"firstName": "John",
"lastName": "doe",
Expand Down
6,236 changes: 5,800 additions & 436 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@aws-sdk/client-personalize": "^3.616.0",
"@aws-sdk/client-s3": "^3.474.0",
"@aws-sdk/credential-providers": "^3.391.0",
"@aws-sdk/lib-storage": "^3.600.0",
"@aws-sdk/lib-storage": "^3.637.0",
"@bugsnag/js": "^7.20.2",
"@datadog/pprof": "^3.1.0",
"@koa/router": "^12.0.0",
Expand Down Expand Up @@ -145,7 +145,7 @@
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-sonarjs": "^0.19.0",
"eslint-plugin-unicorn": "^46.0.1",
"glob": "^10.3.3",
Expand All @@ -163,7 +163,7 @@
"standard-version": "^9.5.0",
"supertest": "^6.3.3",
"swagger-cli": "^4.0.4",
"ts-jest": "^29.1.0",
"ts-jest": "^29.2.5",
"typescript": "^5.0.4"
},
"overrides": {
Expand Down
16 changes: 13 additions & 3 deletions src/cdk/v2/destinations/webhook_v2/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ const { groupBy } = require('lodash');
const { createHash } = require('crypto');
const { ConfigurationError } = require('@rudderstack/integrations-lib');
const { BatchUtils } = require('@rudderstack/workflow-engine');
const { base64Convertor, applyCustomMappings, isEmptyObject } = require('../../../../v0/util');
const {
base64Convertor,
applyCustomMappings,
isEmptyObject,
applyJSONStringTemplate,
} = require('../../../../v0/util');

const getAuthHeaders = (config) => {
let headers;
Expand Down Expand Up @@ -36,8 +41,13 @@ const getCustomMappings = (message, mapping) => {
}
};

// TODO: write a func to evaluate json path template
const addPathParams = (message, webhookUrl) => webhookUrl;
const addPathParams = (message, webhookUrl) => {
try {
return applyJSONStringTemplate(message, `\`${webhookUrl}\``);
} catch (e) {
throw new ConfigurationError(`[Webhook]:: Error in url template: ${e.message}`);
}
};

const excludeMappedFields = (payload, mapping) => {
const rawPayload = { ...payload };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const sha256 = require('sha256');
const SqlString = require('sqlstring');
const isString = require('lodash/isString');
const { get, set, cloneDeep } = require('lodash');
const {
AbortedError,
Expand Down Expand Up @@ -271,7 +272,9 @@ const getAddConversionPayload = (message, Config) => {

const userIdentifierInfo = {
email:
hashUserIdentifier && isDefinedAndNotNull(email) ? sha256(email.trim()).toString() : email,
hashUserIdentifier && isString(email) && isDefinedAndNotNull(email)
? sha256(email.trim()).toString()
: email,
phone:
hashUserIdentifier && isDefinedAndNotNull(phone) ? sha256(phone.trim()).toString() : phone,
address: buildAndGetAddress(message, hashUserIdentifier),
Expand Down Expand Up @@ -367,7 +370,9 @@ const getClickConversionPayloadAndEndpoint = (

const userIdentifierInfo = {
email:
hashUserIdentifier && isDefinedAndNotNull(email) ? sha256(email.trim()).toString() : email,
hashUserIdentifier && isString(email) && isDefinedAndNotNull(email)
? sha256(email.trim()).toString()
: email,
phone:
hashUserIdentifier && isDefinedAndNotNull(phone) ? sha256(phone.trim()).toString() : phone,
};
Expand Down
37 changes: 34 additions & 3 deletions test/integrations/destinations/webhook_v2/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const destinations: Destination[] = [
},
{
Config: {
webhookUrl: 'http://abc.com/contact/$traits.userId',
webhookUrl: 'http://abc.com/contacts',
auth: 'basicAuth',
username: 'test-user',
password: '',
Expand Down Expand Up @@ -92,7 +92,7 @@ const destinations: Destination[] = [
},
{
Config: {
webhookUrl: 'http://abc.com/contacts/$.traits.userId/',
webhookUrl: 'http://abc.com/contacts/{{$.traits.email}}/',
auth: 'apiKeyAuth',
apiKeyName: 'x-api-key',
apiKeyValue: 'test-api-key',
Expand All @@ -114,7 +114,7 @@ const destinations: Destination[] = [
},
{
Config: {
webhookUrl: 'http://abc.com/contacts/$.traits.userId/',
webhookUrl: 'http://abc.com/contacts/{{$.traits.email}}/',
auth: 'apiKeyAuth',
apiKeyName: 'x-api-key',
apiKeyValue: 'test-api-key',
Expand Down Expand Up @@ -247,6 +247,37 @@ const destinations: Destination[] = [
Transformations: [],
WorkspaceID: 'test-workspace-id',
},
{
Config: {
webhookUrl: 'http://abc.com/contacts/{{$.traits.phone}}',
auth: 'noAuth',
method: 'POST',
format: 'JSON',
isBatchingEnabled: true,
maxBatchSize: 4,
headers: [
{
to: "$.'content-type'",
from: "'application/json'",
},
{
to: '$.key',
from: '.traits.key',
},
],
},
DestinationDefinition: {
DisplayName: displayName,
ID: '123',
Name: destTypeInUpperCase,
Config: { cdkV2Enabled: true },
},
Enabled: true,
ID: '123',
Name: destTypeInUpperCase,
Transformations: [],
WorkspaceID: 'test-workspace-id',
},
];

const traits = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const configuration: ProcessorTestData[] = [
output: transformResultBuilder({
method: 'DELETE',
userId: '',
endpoint: 'http://abc.com/contacts/$.traits.userId/',
endpoint: 'http://abc.com/contacts/[email protected]/',
headers: {
'x-api-key': 'test-api-key',
},
Expand Down
146 changes: 141 additions & 5 deletions test/integrations/destinations/webhook_v2/router/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,48 @@ const routerRequest3 = {
destType,
};

// TODO: add failure testcases
const routerRequest4 = {
input: [
{
message: {
type: 'identify',
userId: 'userId1',
traits: { ...traits, key: 'value1' },
},
metadata: generateMetadata(1),
destination: destinations[6],
},
{
message: {
type: 'identify',
userId: 'userId1',
traits: { ...traits, key: 'value1' },
},
metadata: generateMetadata(2),
destination: destinations[6],
},
{
message: {
type: 'identify',
userId: 'userId1',
traits,
},
metadata: generateMetadata(3),
destination: destinations[6],
},
{
message: {
type: 'identify',
userId: 'userId1',
traits: { ...traits, phone: '2234567890' },
},
metadata: generateMetadata(4),
destination: destinations[6],
},
],
destType,
};

export const data = [
{
id: 'webhook_v2-router-test-1',
Expand All @@ -147,7 +188,7 @@ export const data = [
version: '1',
type: 'REST',
method: 'GET',
endpoint: 'http://abc.com/contacts/$.traits.userId/',
endpoint: 'http://abc.com/contacts/[email protected]/',
headers: {
'x-api-key': 'test-api-key',
},
Expand Down Expand Up @@ -196,7 +237,7 @@ export const data = [
version: '1',
type: 'REST',
method: 'GET',
endpoint: 'http://abc.com/contact/$traits.userId',
endpoint: 'http://abc.com/contacts',
headers: {
Authorization: 'Basic dGVzdC11c2VyOg==',
'content-type': 'application/json',
Expand Down Expand Up @@ -228,7 +269,7 @@ export const data = [
version: '1',
type: 'REST',
method: 'GET',
endpoint: 'http://abc.com/contact/$traits.userId',
endpoint: 'http://abc.com/contacts',
headers: {
Authorization: 'Basic dGVzdC11c2VyOg==',
'content-type': 'application/json',
Expand Down Expand Up @@ -260,7 +301,7 @@ export const data = [
version: '1',
type: 'REST',
method: 'GET',
endpoint: 'http://abc.com/contact/$traits.userId',
endpoint: 'http://abc.com/contacts',
headers: {
Authorization: 'Basic dGVzdC11c2VyOg==',
'content-type': 'application/json',
Expand Down Expand Up @@ -347,4 +388,99 @@ export const data = [
},
},
},
{
id: 'webhook_v2-router-test-4',
name: destType,
description: 'Batch multiple requests based on webhook url and headers',
scenario: 'Framework',
successCriteria: 'All events should be transformed successfully and status code should be 200',
feature: 'router',
module: 'destination',
version: 'v0',
input: {
request: {
body: routerRequest4,
method: 'POST',
},
},
output: {
response: {
status: 200,
body: {
output: [
{
batchedRequest: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'http://abc.com/contacts/1234567890',
headers: {
'content-type': 'application/json',
key: 'value1',
},
params: {},
body: {
JSON: {},
JSON_ARRAY: { batch: '[]' },
XML: {},
FORM: {},
},
files: {},
},
metadata: [generateMetadata(1), generateMetadata(2)],
batched: true,
statusCode: 200,
destination: destinations[6],
},
{
batchedRequest: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'http://abc.com/contacts/1234567890',
headers: {
'content-type': 'application/json',
},
params: {},
body: {
JSON: {},
JSON_ARRAY: { batch: '[]' },
XML: {},
FORM: {},
},
files: {},
},
metadata: [generateMetadata(3)],
batched: true,
statusCode: 200,
destination: destinations[6],
},
{
batchedRequest: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'http://abc.com/contacts/2234567890',
headers: {
'content-type': 'application/json',
},
params: {},
body: {
JSON: {},
JSON_ARRAY: { batch: '[]' },
XML: {},
FORM: {},
},
files: {},
},
metadata: [generateMetadata(4)],
batched: true,
statusCode: 200,
destination: destinations[6],
},
],
},
},
},
},
];
12 changes: 7 additions & 5 deletions test/integrations/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ const generateAlphanumericId = (size = 36) =>
export const getTestDataFilePaths = (dirPath: string, opts: OptionValues): string[] => {
const globPattern = join(dirPath, '**', 'data.ts');
let testFilePaths = globSync(globPattern);
let filteredTestFilePaths: string[] = testFilePaths;

if (opts.destination || opts.source) {
testFilePaths = testFilePaths.filter((testFile) =>
testFile.includes(`${opts.destination}/` || opts.source),
const destinationOrSource = opts.destination || opts.source;
if (destinationOrSource) {
filteredTestFilePaths = testFilePaths.filter(
(testFile) => destinationOrSource && testFile.includes(`${destinationOrSource}/`),
);
}
if (opts.feature) {
testFilePaths = testFilePaths.filter((testFile) => testFile.includes(opts.feature));
filteredTestFilePaths = testFilePaths.filter((testFile) => testFile.includes(opts.feature));
}
return testFilePaths;
return filteredTestFilePaths;
};

export const getTestData = (filePath): TestCaseData[] => {
Expand Down

0 comments on commit ad18883

Please sign in to comment.