Skip to content

Commit

Permalink
feat(destination): onboard pipedream (#1703)
Browse files Browse the repository at this point in the history
* feat(destination): onboard pipedream

* feat(destination): error classes incorporated

* refactor: incorporated new error classes

Co-authored-by: Anant <anant@rudderstack.com>
  • Loading branch information
anantjain45823 and anantrudder committed Jan 2, 2023
1 parent 927fa95 commit f03e86a
Show file tree
Hide file tree
Showing 6 changed files with 813 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/constants/destinationCanonicalNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ const DestCanonicalNames = {
"gainsight px",
"Gainsight Px"
],
awin: ["awin", "Awin", "AWIN"],
pipedream: ["Pipedream", "PipeDream", "pipedream", "PIPEDREAM"],
ga4: ["GA4", "ga4", "Ga4", "Google Analytics 4", "googleAnalytics4"],
awin: ["awin", "Awin", "AWIN"]
};
Expand Down
22 changes: 22 additions & 0 deletions src/v0/destinations/pipedream/transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { simpleProcessRouterDest } = require("../../util");
const { processEvent } = require("../webhook/transform");

const DESTINATION = "pipedream";

const process = event => {
const response = processEvent({ ...event, DESTINATION });
return response;
};
const processRouterDest = async (inputs, reqMetadata) => {
const destNameRichInputs = inputs.map(input => {
return { ...input, DESTINATION };
});
const respList = await simpleProcessRouterDest(
destNameRichInputs,
processEvent,
reqMetadata
);
return respList;
};

module.exports = { process, processRouterDest };
35 changes: 24 additions & 11 deletions src/v0/destinations/webhook/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ const {
defaultPatchRequestConfig,
defaultGetRequestConfig,
defaultRequestConfig,
getHashFromArray,
getFieldValueFromMessage,
flattenJson,
isDefinedAndNotNull,
getHashFromArray,
simpleProcessRouterDest,
defaultDeleteRequestConfig,
getIntegrationsObj
} = require("../../util");

const { EventType } = require("../../../constants");
const { ConfigurationError } = require("../../util/errorTypes");

Expand All @@ -24,17 +25,17 @@ const getPropertyParams = message => {
}
return flattenJson(message.properties);
};
const processEvent = event => {
const { DESTINATION, message, destination } = event;

function process(event) {
const { message, destination } = event;
const integrationsObj = getIntegrationsObj(message, "webhook");
const integrationsObj = getIntegrationsObj(message, DESTINATION);
// set context.ip from request_ip if it is missing
if (!get(message, "context.ip") && isDefinedAndNotNull(message.request_ip)) {
set(message, "context.ip", message.request_ip);
}
const response = defaultRequestConfig();
const url = destination.Config.webhookUrl;
const method = destination.Config.webhookMethod;
const url = destination.Config[`${DESTINATION}Url`];
const method = destination.Config[`${DESTINATION}Method`];
const { headers } = destination.Config;

if (url) {
Expand Down Expand Up @@ -65,8 +66,8 @@ function process(event) {
response.params = getPropertyParams(message);
break;
}
default:
case defaultPostRequestConfig.requestMethod: {
case defaultPostRequestConfig.requestMethod:
default: {
response.method = defaultPostRequestConfig.requestMethod;
response.body.JSON = message;
response.headers = {
Expand Down Expand Up @@ -150,11 +151,23 @@ function process(event) {
return response;
}
throw new ConfigurationError("Invalid URL in destination config");
}
};
const DESTINATION = "webhook";
const process = event => {
const response = processEvent({ ...event, DESTINATION });
return response;
};

const processRouterDest = async (inputs, reqMetadata) => {
const respList = await simpleProcessRouterDest(inputs, process, reqMetadata);
const destNameRichInputs = inputs.map(input => {
return { ...input, DESTINATION };
});
const respList = await simpleProcessRouterDest(
destNameRichInputs,
processEvent,
reqMetadata
);
return respList;
};

module.exports = { process, processRouterDest };
module.exports = { processEvent, process, processRouterDest };
249 changes: 249 additions & 0 deletions test/__tests__/data/pipedream.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
[
{
"description": "Dynamic Header and Append Header",
"input": {
"message": {
"anonymousId": "c82cbdff-e5be-4009-ac78-cdeea09ab4b1",
"context": {
"device": {
"id": "df16bffa-5c3d-4fbb-9bce-3bab098129a7R",
"manufacturer": "Xiaomi",
"model": "Redmi 6",
"name": "xiaomi"
},
"network": {
"carrier": "Banglalink"
},
"os": {
"name": "android",
"version": "8.1.0"
},
"traits": {
"address": {
"city": "Dhaka",
"country": "Bangladesh"
},
"anonymousId": "c82cbdff-e5be-4009-ac78-cdeea09ab4b1"
}
},
"event": "spin_result",
"integrations": {
"All": true
},
"message_id": "a80f82be-9bdc-4a9f-b2a5-15621ee41df8",
"properties": {
"additional_bet_index": 0,
"battle_id": "N/A",
"featureGameType": "N/A",
"win_amount": 0
},
"timestamp": "2019-09-01T15:46:51.693229+05:30",
"type": "track",
"header": {
"dynamic_header_key_string": "dynamic_header_value_string",
"dynamic_header_key_num": 10,
"dynamic_header_key_object": {
"k1": "v1"
}
},
"appendPath": "/product/search?string=value"
},
"destination": {
"Config": {
"pipedreamUrl": "http://6b0e6a60.ngrok.io",
"headers": [
{
"from": "",
"to": ""
},
{
"from": "test2",
"to": "value2"
}
]
}
}
},
"output": {
"body": {
"XML": {},
"JSON_ARRAY": {},
"JSON": {
"anonymousId": "c82cbdff-e5be-4009-ac78-cdeea09ab4b1",
"context": {
"device": {
"id": "df16bffa-5c3d-4fbb-9bce-3bab098129a7R",
"manufacturer": "Xiaomi",
"model": "Redmi 6",
"name": "xiaomi"
},
"network": {
"carrier": "Banglalink"
},
"os": {
"name": "android",
"version": "8.1.0"
},
"traits": {
"address": {
"city": "Dhaka",
"country": "Bangladesh"
},
"anonymousId": "c82cbdff-e5be-4009-ac78-cdeea09ab4b1"
}
},
"event": "spin_result",
"integrations": {
"All": true
},
"message_id": "a80f82be-9bdc-4a9f-b2a5-15621ee41df8",
"properties": {
"additional_bet_index": 0,
"battle_id": "N/A",
"featureGameType": "N/A",
"win_amount": 0
},
"timestamp": "2019-09-01T15:46:51.693229+05:30",
"type": "track"
},
"FORM": {}
},
"files": {},
"endpoint": "http://6b0e6a60.ngrok.io/product/search?string=value",
"userId": "c82cbdff-e5be-4009-ac78-cdeea09ab4b1",
"headers": {
"content-type": "application/json",
"test2": "value2",
"dynamic_header_key_string": "dynamic_header_value_string"
},
"version": "1",
"params": {},
"type": "REST",
"method": "POST"
}
},
{
"description": "Dynamic Header",
"input": {
"message": {
"anonymousId": "c82cbdff-e5be-4009-ac78-cdeea09ab4b1",
"context": {
"device": {
"id": "df16bffa-5c3d-4fbb-9bce-3bab098129a7R",
"manufacturer": "Xiaomi",
"model": "Redmi 6",
"name": "xiaomi"
},
"network": {
"carrier": "Banglalink"
},
"os": {
"name": "android",
"version": "8.1.0"
},
"traits": {
"address": {
"city": "Dhaka",
"country": "Bangladesh"
},
"anonymousId": "c82cbdff-e5be-4009-ac78-cdeea09ab4b1"
}
},
"event": "spin_result",
"integrations": {
"All": true
},
"message_id": "a80f82be-9bdc-4a9f-b2a5-15621ee41df8",
"properties": {
"additional_bet_index": 0,
"battle_id": "N/A",
"featureGameType": "N/A",
"win_amount": 0
},
"timestamp": "2019-09-01T15:46:51.693229+05:30",
"type": "track",
"header": {
"dynamic_header_key_string": "dynamic_header_value_string",
"dynamic_header_key_num": 10,
"dynamic_header_key_object": {
"k1": "v1"
}
}
},
"destination": {
"Config": {
"pipedreamUrl": "http://6b0e6a60.ngrok.io",
"pipedreamMethod": "PUT",
"headers": [
{
"from": "",
"to": ""
},
{
"from": "test2",
"to": "value2"
}
]
}
}
},
"output": {
"body": {
"XML": {},
"JSON_ARRAY": {},
"JSON": {
"anonymousId": "c82cbdff-e5be-4009-ac78-cdeea09ab4b1",
"context": {
"device": {
"id": "df16bffa-5c3d-4fbb-9bce-3bab098129a7R",
"manufacturer": "Xiaomi",
"model": "Redmi 6",
"name": "xiaomi"
},
"network": {
"carrier": "Banglalink"
},
"os": {
"name": "android",
"version": "8.1.0"
},
"traits": {
"address": {
"city": "Dhaka",
"country": "Bangladesh"
},
"anonymousId": "c82cbdff-e5be-4009-ac78-cdeea09ab4b1"
}
},
"event": "spin_result",
"integrations": {
"All": true
},
"message_id": "a80f82be-9bdc-4a9f-b2a5-15621ee41df8",
"properties": {
"additional_bet_index": 0,
"battle_id": "N/A",
"featureGameType": "N/A",
"win_amount": 0
},
"timestamp": "2019-09-01T15:46:51.693229+05:30",
"type": "track"
},
"FORM": {}
},
"files": {},
"endpoint": "http://6b0e6a60.ngrok.io",
"userId": "c82cbdff-e5be-4009-ac78-cdeea09ab4b1",
"headers": {
"content-type": "application/json",
"test2": "value2",
"dynamic_header_key_string": "dynamic_header_value_string"
},
"version": "1",
"params": {},
"type": "REST",
"method": "PUT"
}
}
]

Loading

0 comments on commit f03e86a

Please sign in to comment.