Skip to content

Commit d704991

Browse files
committed
Initial AI-generated code (w/ eslint fixes)
1 parent 491fb31 commit d704991

File tree

8 files changed

+381
-4
lines changed

8 files changed

+381
-4
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import the_magic_drip from "../../the_magic_drip.app.mjs";
2+
3+
export default {
4+
key: "the_magic_drip-add-lead-to-campaign",
5+
name: "Add Lead to Campaign",
6+
description: "Adds a single lead to a campaign. [See the documentation]()",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
the_magic_drip,
11+
campaignId: {
12+
propDefinition: [
13+
the_magic_drip,
14+
"campaignId",
15+
],
16+
},
17+
company: {
18+
propDefinition: [
19+
the_magic_drip,
20+
"company",
21+
],
22+
optional: true,
23+
},
24+
linkedinUrl: {
25+
propDefinition: [
26+
the_magic_drip,
27+
"linkedinUrl",
28+
],
29+
optional: true,
30+
},
31+
},
32+
async run({ $ }) {
33+
const response = await this.the_magic_drip.addLeadToCampaign({
34+
campaignId: this.campaignId,
35+
company: this.company,
36+
linkedinUrl: this.linkedinUrl,
37+
});
38+
$.export(
39+
"$summary",
40+
`Added ${response.totalLeadsAddedToWorkflow} lead(s) to campaign ${this.campaignId}`,
41+
);
42+
return response;
43+
},
44+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import the_magic_drip from "../../the_magic_drip.app.mjs";
2+
3+
export default {
4+
key: "the_magic_drip-list-campaigns",
5+
name: "List Campaigns",
6+
description: "Lists all available campaigns. [See the documentation](https://docs.themagicdrip.com/api-reference/introduction)",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
the_magic_drip,
11+
},
12+
async run({ $ }) {
13+
const response = await this.the_magic_drip.listCampaigns();
14+
$.export("$summary", `Listed ${response.campaigns.length} campaigns`);
15+
return response.campaigns;
16+
},
17+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import the_magic_drip from "../../the_magic_drip.app.mjs";
2+
3+
export default {
4+
key: "the_magic_drip-list-templates",
5+
name: "List Templates",
6+
description: "Lists all available templates. [See the documentation]()",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
the_magic_drip,
11+
},
12+
async run({ $ }) {
13+
const templates = await this.the_magic_drip.listTemplates();
14+
$.export("$summary", `Listed ${templates.templates.length} templates`);
15+
return templates;
16+
},
17+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import the_magic_drip from "../../the_magic_drip.app.mjs";
2+
3+
export default {
4+
key: "the_magic_drip-mark-campaign-active-inactive",
5+
name: "Mark Campaign Active/Inactive",
6+
description: "Marks a campaign as active or inactive. [See the documentation]()",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
the_magic_drip,
11+
campaignId: {
12+
propDefinition: [
13+
the_magic_drip,
14+
"campaignId",
15+
],
16+
},
17+
desiredState: {
18+
type: "boolean",
19+
label: "Desired State",
20+
description: "Set to true to activate, false to deactivate the campaign",
21+
},
22+
},
23+
async run({ $ }) {
24+
const response = await this.the_magic_drip.markCampaignActiveInactive({
25+
campaignId: this.campaignId,
26+
desiredState: this.desiredState,
27+
});
28+
29+
$.export("$summary", `Marked campaign ${this.campaignId} as ${this.desiredState
30+
? "active"
31+
: "inactive"}.`);
32+
33+
return response;
34+
},
35+
};

components/the_magic_drip/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2+
import the_magic_drip from "../../the_magic_drip.app.mjs";
3+
4+
export default {
5+
key: "the_magic_drip-new-campaign-created",
6+
name: "New Campaign Created",
7+
description: "Emit new event when a campaign is created. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
the_magic_drip,
13+
db: "$.service.db",
14+
timer: {
15+
type: "$.interface.timer",
16+
default: {
17+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
18+
},
19+
},
20+
},
21+
hooks: {
22+
async deploy() {
23+
const lastRunAt = new Date(0).toISOString();
24+
const newCampaigns = await this.the_magic_drip.pollNewCampaigns(lastRunAt);
25+
const sortedCampaigns = newCampaigns.sort(
26+
(a, b) => new Date(b.createdAt) - new Date(a.createdAt),
27+
).slice(0, 50);
28+
29+
for (const campaign of sortedCampaigns) {
30+
this.$emit(
31+
campaign,
32+
{
33+
id: campaign.id || campaign.createdAt,
34+
summary: `New Campaign: ${campaign.name}`,
35+
ts: Date.parse(campaign.createdAt),
36+
},
37+
);
38+
}
39+
40+
const latestCreatedAt = sortedCampaigns.length
41+
? sortedCampaigns[0].createdAt
42+
: lastRunAt;
43+
await this.db.set("lastRunAt", latestCreatedAt);
44+
},
45+
async activate() {
46+
// No action needed on activate for polling source
47+
},
48+
async deactivate() {
49+
// No action needed on deactivate for polling source
50+
},
51+
},
52+
async run() {
53+
const lastRunAt = (await this.db.get("lastRunAt")) || new Date(0).toISOString();
54+
const newCampaigns = await this.the_magic_drip.pollNewCampaigns(lastRunAt);
55+
const sortedCampaigns = newCampaigns.sort(
56+
(a, b) => new Date(b.createdAt) - new Date(a.createdAt),
57+
);
58+
59+
for (const campaign of sortedCampaigns) {
60+
this.$emit(
61+
campaign,
62+
{
63+
id: campaign.id || campaign.createdAt,
64+
summary: `New Campaign: ${campaign.name}`,
65+
ts: Date.parse(campaign.createdAt),
66+
},
67+
);
68+
}
69+
70+
if (newCampaigns.length) {
71+
const latestCreatedAt = newCampaigns.reduce((latest, campaign) => {
72+
return new Date(campaign.createdAt) > new Date(latest)
73+
? campaign.createdAt
74+
: latest;
75+
}, lastRunAt);
76+
await this.db.set("lastRunAt", latestCreatedAt);
77+
}
78+
},
79+
};
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2+
import the_magic_drip from "../../the_magic_drip.app.mjs";
3+
4+
export default {
5+
key: "the_magic_drip-new-template-created",
6+
name: "New Template Created",
7+
description: "Emits a new event when a template is created. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
the_magic_drip,
13+
db: "$.service.db",
14+
timer: {
15+
type: "$.interface.timer",
16+
default: {
17+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
18+
},
19+
},
20+
},
21+
methods: {
22+
_getLastRunAt() {
23+
return this.db.get("lastRunAt") || new Date(0).toISOString();
24+
},
25+
_setLastRunAt(timestamp) {
26+
return this.db.set("lastRunAt", timestamp);
27+
},
28+
},
29+
hooks: {
30+
async deploy() {
31+
const lastRunAt = new Date(0).toISOString();
32+
const newTemplates = await this.the_magic_drip.pollNewTemplates(lastRunAt);
33+
const sortedTemplates = newTemplates.sort(
34+
(a, b) => new Date(b.createdAt) - new Date(a.createdAt),
35+
);
36+
const latest50Templates = sortedTemplates.slice(0, 50);
37+
for (const template of latest50Templates) {
38+
this.$emit(template, {
39+
id: template.templateId || template.createdAt,
40+
summary: `New Template: ${template.name}`,
41+
ts: Date.parse(template.createdAt) || Date.now(),
42+
});
43+
}
44+
const newLastRunAt =
45+
latest50Templates.length > 0
46+
? latest50Templates[0].createdAt
47+
: lastRunAt;
48+
await this._setLastRunAt(newLastRunAt);
49+
},
50+
async activate() {
51+
// No webhook setup required
52+
},
53+
async deactivate() {
54+
// No webhook teardown required
55+
},
56+
},
57+
async run() {
58+
const lastRunAt = await this._getLastRunAt();
59+
const newTemplates = await this.the_magic_drip.pollNewTemplates(lastRunAt);
60+
const sortedNewTemplates = newTemplates.sort(
61+
(a, b) => new Date(a.createdAt) - new Date(b.createdAt),
62+
);
63+
for (const template of sortedNewTemplates) {
64+
this.$emit(template, {
65+
id: template.templateId || template.createdAt,
66+
summary: `New Template: ${template.name}`,
67+
ts: Date.parse(template.createdAt) || Date.now(),
68+
});
69+
}
70+
if (newTemplates.length > 0) {
71+
const latestCreatedAt = newTemplates.reduce((max, t) =>
72+
new Date(t.createdAt) > new Date(max)
73+
? t.createdAt
74+
: max,
75+
lastRunAt);
76+
await this._setLastRunAt(latestCreatedAt);
77+
}
78+
},
79+
};

0 commit comments

Comments
 (0)