-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* relavate init * new components * pnpm-lock.yaml * fix typo
- Loading branch information
1 parent
3ad7fb6
commit f4dc25d
Showing
9 changed files
with
354 additions
and
8 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
components/relavate/actions/create-affiliate-lead/create-affiliate-lead.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [ | ||
|
@@ -11,5 +11,8 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^1.6.5" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}, | ||
}; |
22 changes: 22 additions & 0 deletions
22
components/relavate/sources/new-affiliate-campaign/new-affiliate-campaign.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
components/relavate/sources/new-affiliate-campaign/test-event.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.