Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 73 additions & 4 deletions components/growsurf/growsurf.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,80 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "growsurf",
propDefinitions: {},
propDefinitions: {
campaignId: {
type: "string",
label: "Campaign ID",
description: "The ID of a campaign",
async options() {
const { campaigns } = await this.listCampaigns();
return campaigns?.map((campaign) => ({
label: campaign.name,
value: campaign.id,
})) || [];
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.growsurf.com/v2";
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
headers: {
"Authorization": `Bearer ${this.$auth.api_key}`,
},
...opts,
});
},
listCampaigns(opts = {}) {
return this._makeRequest({
path: "/campaigns",
...opts,
});
},
listParticipants({
campaignId, ...opts
}) {
return this._makeRequest({
path: `/campaign/${campaignId}/participants`,
...opts,
});
},
listReferrals({
campaignId, ...opts
}) {
return this._makeRequest({
path: `/campaign/${campaignId}/referrals`,
...opts,
});
},
async *paginate({
fn, args, resourceKey, max,
}) {
args.params = args.params || {};
let hasMore = true;
let count = 0;
do {
const response = await fn(args);
const items = response[resourceKey];
if (!items?.length) {
return;
}
for (const item of items) {
yield item;
if (max && ++count >= max) {
return;
}
}
hasMore = response.nextId;
args.params.nextId = response.nextId;
} while (hasMore);
},
},
};
5 changes: 4 additions & 1 deletion components/growsurf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/growsurf",
"version": "0.0.4",
"version": "0.1.0",
"description": "Pipedream Growsurf Components",
"main": "growsurf.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import common from "../common/base.mjs";

export default {
...common,
key: "growsurf-campaign-completed",
name: "Campaign Completed",

Check warning on line 6 in components/growsurf/sources/campaign-completed/campaign-completed.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
description: "Emit new event when a campaign is completed. [See the documentation](https://docs.growsurf.com/developer-tools/rest-api/api-reference#get-campaigns)",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
async getResources() {
const { campaigns } = await this.growsurf.listCampaigns();
return campaigns.filter((campaign) => campaign.status === "COMPLETE");
},
generateMeta(campaign) {
return {
id: campaign.id,
summary: `Campaign Completed: ${campaign.name}`,
ts: Date.now(),
};
},
},
};
49 changes: 49 additions & 0 deletions components/growsurf/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import growsurf from "../../growsurf.app.mjs";
import {
DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, ConfigurationError,
} from "@pipedream/platform";

export default {
props: {
growsurf,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
_getLastTs() {
return this.db.get("lastTs") || 0;
},
_setLastTs(lastTs) {
this.db.set("lastTs", lastTs);
},
getResources() {
throw new ConfigurationError("getResources is not implemented");
},
generateMeta() {
throw new ConfigurationError("generateMeta is not implemented");
},
async processEvent(max) {
const results = await this.getResources(max);
if (!results.length) {
return;
}
for (const result of results) {
const meta = this.generateMeta(result);
this.$emit(result, meta);
}
},
},
hooks: {
async deploy() {
await this.processEvent(10);
},
},
async run() {
await this.processEvent();
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import common from "../common/base.mjs";

export default {
...common,
key: "growsurf-new-campaign-referral-made",
name: "New Campaign Referral Made",
description: "Emit new event when a new referral is made for a campaign. [See the documentation](https://docs.growsurf.com/developer-tools/rest-api/api-reference#get-referrals-and-invites)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
...common.props,
campaignId: {
propDefinition: [
common.props.growsurf,
"campaignId",
],
},
},
methods: {
...common.methods,
async getResources(max) {
const results = this.growsurf.paginate({
fn: this.growsurf.listReferrals,
args: {
campaignId: this.campaignId,
params: {
sortBy: "createdAt",
desc: true,
},
},
resourceKey: "referrals",
max,
});
const referrals = [];
const lastTs = this._getLastTs();
let maxTs = lastTs;
for await (const referral of results) {
const ts = referral.createdAt;
if (ts > lastTs) {
referrals.push(referral);
maxTs = Math.max(ts, maxTs);
} else {
break;
}
}
this._setLastTs(maxTs);
return referrals;
},
generateMeta(referral) {
return {
id: referral.id,
summary: `New Campaign Referral Made: ${referral.email || referral.id}`,
ts: referral.createdAt,
};
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import common from "../common/base.mjs";

export default {
...common,
key: "growsurf-new-participant-added",
name: "New Participant Added",
description: "Emit new event when a new participant is added to a campaign. [See the documentation](https://docs.growsurf.com/developer-tools/rest-api/api-reference#get-participants)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
...common.props,
campaignId: {
propDefinition: [
common.props.growsurf,
"campaignId",
],
},
},
methods: {
...common.methods,
async getResources(max) {
const results = this.growsurf.paginate({
fn: this.growsurf.listParticipants,
args: {
campaignId: this.campaignId,
params: {
limit: 100,
},
},
resourceKey: "participants",
});
const participants = [];
const lastTs = this._getLastTs();
let maxTs = lastTs;
for await (const participant of results) {
const ts = participant.createdAt;
if (ts > lastTs) {
participants.push(participant);
maxTs = Math.max(ts, maxTs);
}
}
this._setLastTs(maxTs);
if (max && participants.length > max) {
participants.length = max;
}
return participants;
},
generateMeta(participant) {
const name = [
participant.firstName,
participant.lastName,
].filter(Boolean).join(" ") || participant.email || participant.id;
return {
id: participant.id,
summary: `New Participant Added: ${name}`,
ts: participant.createdAt,
};
},
},
};
15 changes: 9 additions & 6 deletions pnpm-lock.yaml

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

Loading