Skip to content

Commit

Permalink
New Components - relavate (#11803)
Browse files Browse the repository at this point in the history
* relavate init

* new components

* pnpm-lock.yaml

* fix typo
  • Loading branch information
michelle0927 committed May 6, 2024
1 parent 3ad7fb6 commit f4dc25d
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import relavate from "../../relavate.app.mjs";

export default {
key: "relavate-create-affiliate-lead",
name: "Create Affiliate Lead",
description: "This component enables you to create a new affiliate lead for marketing. [See the documentation](https://api.relavate.co/#2a307851-9d54-42ea-9f54-3fb600b152a5)",
version: "0.0.1",
type: "action",
props: {
relavate,
campaignId: {
propDefinition: [
relavate,
"campaignId",
],
reloadProps: true,
},
status: {
type: "string",
label: "Status",
description: "The status of the lead being created",
options: [
"Pending",
"Won",
],
},
client: {
type: "string",
label: "Client",
description: "The company or name of the client",
},
},
async additionalProps() {
const props = {};
const partnerType = this.relavate.getPartnerType();
if (partnerType === "partner") {
props.vendorId = {
type: "string",
label: "Vendor ID",
description: "The ID of the vendor",
options: async () => await this.getVendorIdPropOptions(),
};
}
if (partnerType === "vendor") {
props.partnerId = {
type: "string",
label: "Partner ID",
description: "The ID of the partner",
options: async () => await this.getPartnerIdPropOptions(),
};
}
return props;
},
methods: {
async getVendorIdPropOptions() {
const vendors = await this.relavate.listVendors();
const vendorIds = vendors?.map(({ vendorID }) => vendorID );
const options = [];
for (const vendorId of vendorIds) {
const { name } = await this.relavate.getVendor({
vendorId,
});
options.push({
value: vendorId,
label: name,
});
}
return options;
},
async getPartnerIdPropOptions() {
const partners = await this.relavate.listPartners();
const partnerIds = partners?.map(({ partnerID }) => partnerID );
const options = [];
for (const partnerId of partnerIds) {
const { name } = await this.relavate.getPartner({
partnerId,
});
options.push({
value: partnerId,
label: name,
});
}
return options;
},
},
async run({ $ }) {
const response = await this.relavate.createAffiliateLead({
$,
params: {
campaignID: this.campaignId,
client: this.client,
status: this.status,
vendorID: this.vendorId,
partnerID: this.partnerId,
},
});
$.export("$summary", `Created affiliate lead with ID: ${response.id}`);
return response;
},
};
7 changes: 5 additions & 2 deletions components/relavate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/relavate",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Relavate Components",
"main": "relavate.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.6.5"
}
}
}
98 changes: 93 additions & 5 deletions components/relavate/relavate.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,99 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "relavate",
propDefinitions: {},
propDefinitions: {
campaignId: {
type: "string",
label: "Campaign ID",
description: "The ID of the campaign",
async options() {
const campaigns = await this.listCampaigns();
return campaigns?.map(({
id: value, name: label,
}) => ({
value,
label,
})) || [];
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://app.relavate.co/api";
},
_makeRequest(opts = {}) {
const {
$ = this,
path,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: `${this._baseUrl()}${path}`,
headers: {
"X-key": this.$auth.api_key,
"X-secret": this.$auth.api_secret,
"X-partnerType": this.$auth.partner_type,
},
});
},
getPartnerType() {
return this.$auth.partner_type;
},
getVendor({
vendorId, ...opts
}) {
return this._makeRequest({
path: `/vendors/${vendorId}`,
...opts,
});
},
getPartner({
partnerId, ...opts
}) {
return this._makeRequest({
path: `/partners/${partnerId}`,
...opts,
});
},
listVendors(opts = {}) {
return this._makeRequest({
path: "/partners/vendors/all",
...opts,
});
},
listPartners(opts = {}) {
return this._makeRequest({
path: "/vendors/partners/all",
...opts,
});
},
listCampaigns(opts = {}) {
return this._makeRequest({
path: "/affiliate-campaigns",
...opts,
});
},
listAffiliateLeads(opts = {}) {
return this._makeRequest({
path: "/affiliate-leads",
...opts,
});
},
listReferrals(opts = {}) {
return this._makeRequest({
path: "/referrals",
...opts,
});
},
createAffiliateLead(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/affiliate-leads",
...opts,
});
},
},
};
};
57 changes: 57 additions & 0 deletions components/relavate/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import relavate from "../../relavate.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";

export default {
props: {
relavate,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
_getStartDate() {
return this.db.get("startDate") || this._today();
},
_setStartDate(startDate) {
this.db.set("startDate", startDate);
},
_today() {
return new Date().toISOString()
.split("T")[0];
},
generateMeta(item) {
return {
id: item.id,
summary: this.getSummary(item),
ts: Date.parse(item.created_at),
};
},
getParams() {
return {};
},
getResourceFn() {
throw new Error("getResourceFn is not implemented");
},
getSummary() {
throw new Error("getSummary is not implemented");
},
},
async run() {
const resourceFn = this.getResourceFn();
const params = this.getParams();
const results = await resourceFn({
params,
});
if (!results?.length) {
return;
}
for (const item of results) {
const meta = this.generateMeta(item);
this.$emit(item, meta);
}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
type: "source",
key: "relavate-new-affiliate-campaign",
name: "New Affiliate Campaign",
description: "Emit new event when a new affiliate campaign is created.",
version: "0.0.1",
dedupe: "unique",
methods: {
...common.methods,
getResourceFn() {
return this.relavate.listCampaigns;
},
getSummary(campaign) {
return `New campaign: ${campaign.name}`;
},
},
sampleEmit,
};
15 changes: 15 additions & 0 deletions components/relavate/sources/new-affiliate-campaign/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
"id": 4,
"partnerID": 2,
"vendorID": 4,
"name": "Tracking link campaign",
"type": "Link",
"created_at": "2023-10-17T10:23:37.000000Z",
"updated_at": "2023-10-17T10:23:37.000000Z",
"status": "Active",
"campaignBaseURL": "https://nichols.com",
"campaignUrlPath": null,
"linkFormat": "vendorWebsite",
"couponCode": null,
"subtitle": null
}
39 changes: 39 additions & 0 deletions components/relavate/sources/new-referral/new-referral.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "relavate-new-referral",
name: "New Referral",
description: "Emit new event when a new referral is created in Relavate",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
_getStartDate() {
return this.db.get("startDate") || this._today();
},
_setStartDate(startDate) {
this.db.set("startDate", startDate);
},
_today() {
return new Date().toISOString()
.split("T")[0];
},
getResourceFn() {
return this.relavate.listReferrals;
},
getParams() {
const startDate = this._getStartDate();
this._setStartDate(this._today());
return {
startDate,
};
},
getSummary(referral) {
return `New referral with ID ${referral.id}`;
},
},
sampleEmit,
};
19 changes: 19 additions & 0 deletions components/relavate/sources/new-referral/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default {
"id": 4,
"vendorID": 4,
"partnerID": 2,
"company": "Sample Company",
"status": "New",
"revenue": 5000,
"frequency": "Annual",
"dateAdded": "2023-05-20",
"comment": "{\"ops\":[{\"insert\":\"This is a sample comment\"}]}",
"clientContactID": 7,
"created_at": "2023-10-17T09:52:11.000000Z",
"updated_at": "2023-10-17T09:54:28.000000Z",
"wonDate": null,
"lostDate": "2023-10-17",
"annualRevenue": 5000,
"lostID": 10,
"comment_text": "This is a sample comment"
}
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

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

0 comments on commit f4dc25d

Please sign in to comment.