diff --git a/components/ai_textraction/ai_textraction.app.mjs b/components/ai_textraction/ai_textraction.app.mjs index 76f7d74706286..6d9749e003826 100644 --- a/components/ai_textraction/ai_textraction.app.mjs +++ b/components/ai_textraction/ai_textraction.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/attractwell/attractwell.app.mjs b/components/attractwell/attractwell.app.mjs index 926dc93c2b7eb..4b793833e3ef3 100644 --- a/components/attractwell/attractwell.app.mjs +++ b/components/attractwell/attractwell.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/deepimage/deepimage.app.mjs b/components/deepimage/deepimage.app.mjs index 82bd92e6c327a..6d3b6cac93c3f 100644 --- a/components/deepimage/deepimage.app.mjs +++ b/components/deepimage/deepimage.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/fluidforms/fluidforms.app.mjs b/components/fluidforms/fluidforms.app.mjs index 47b75d8066d22..e92ea8e9b831a 100644 --- a/components/fluidforms/fluidforms.app.mjs +++ b/components/fluidforms/fluidforms.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/gainsight_nxt/gainsight_nxt.app.mjs b/components/gainsight_nxt/gainsight_nxt.app.mjs index 6ce5726b22ebd..7e2c5ff525189 100644 --- a/components/gainsight_nxt/gainsight_nxt.app.mjs +++ b/components/gainsight_nxt/gainsight_nxt.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/gainsight_px/gainsight_px.app.mjs b/components/gainsight_px/gainsight_px.app.mjs index 63fdc568165d7..a871bea2efb9a 100644 --- a/components/gainsight_px/gainsight_px.app.mjs +++ b/components/gainsight_px/gainsight_px.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/nerv/nerv.app.mjs b/components/nerv/nerv.app.mjs index b7bbe093a1648..029b58080db69 100644 --- a/components/nerv/nerv.app.mjs +++ b/components/nerv/nerv.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/runpod/runpod.app.mjs b/components/runpod/runpod.app.mjs index b7ea347fb1b3c..96f6458376990 100644 --- a/components/runpod/runpod.app.mjs +++ b/components/runpod/runpod.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/runware/runware.app.mjs b/components/runware/runware.app.mjs index 65f4ad1fd31a0..c2dd1ce6d7cf9 100644 --- a/components/runware/runware.app.mjs +++ b/components/runware/runware.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/teach_n_go/teach_n_go.app.mjs b/components/teach_n_go/teach_n_go.app.mjs index 6da5c7afce2ad..732d4c6fc05d7 100644 --- a/components/teach_n_go/teach_n_go.app.mjs +++ b/components/teach_n_go/teach_n_go.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/the_magic_drip/actions/add-lead-to-campaign/add-lead-to-campaign.mjs b/components/the_magic_drip/actions/add-lead-to-campaign/add-lead-to-campaign.mjs new file mode 100644 index 0000000000000..f27a8ff603700 --- /dev/null +++ b/components/the_magic_drip/actions/add-lead-to-campaign/add-lead-to-campaign.mjs @@ -0,0 +1,72 @@ +import app from "../../the_magic_drip.app.mjs"; + +export default { + key: "the_magic_drip-add-lead-to-campaign", + name: "Add Lead to Campaign", + description: "Add a lead to a campaign. [See the documentation](https://docs.themagicdrip.com/api-reference/endpoint/post-v1campaignleads)", + version: "0.0.1", + type: "action", + props: { + app, + campaignId: { + propDefinition: [ + app, + "campaignId", + ], + }, + firstName: { + type: "string", + label: "First Name", + description: "First name of the lead", + optional: true, + }, + lastName: { + type: "string", + label: "Last Name", + description: "Last name of the lead", + }, + linkedInPublicUrl: { + type: "string", + label: "LinkedIn Public URL", + description: "LinkedIn public URL of the lead", + optional: true, + }, + company: { + type: "string", + label: "Company", + description: "Company of the lead", + optional: true, + }, + companyLinkedInUrl: { + type: "string", + label: "Company LinkedIn URL", + description: "LinkedIn URL of the company", + optional: true, + }, + customVariables: { + type: "object", + label: "Custom Variables", + description: "More information about the lead", + optional: true, + }, + }, + async run({ $ }) { + const { + app, campaignId, ...lead + } = this; + const response = await app.addLeadToCampaign({ + $, + campaignId, + data: { + leadsWithCustomVariables: [ + lead, + ], + }, + }); + $.export( + "$summary", + `Successfully added lead "${lead.lastName}" to campaign`, + ); + return response; + }, +}; diff --git a/components/the_magic_drip/actions/list-campaigns/list-campaigns.mjs b/components/the_magic_drip/actions/list-campaigns/list-campaigns.mjs new file mode 100644 index 0000000000000..ce20a7e7bd5cb --- /dev/null +++ b/components/the_magic_drip/actions/list-campaigns/list-campaigns.mjs @@ -0,0 +1,19 @@ +import app from "../../the_magic_drip.app.mjs"; + +export default { + key: "the_magic_drip-list-campaigns", + name: "List Campaigns", + description: "Retrieve all available campaigns. [See the documentation](https://docs.themagicdrip.com/api-reference/endpoint/get-v1campaign)", + version: "0.0.1", + type: "action", + props: { + app, + }, + async run({ $ }) { + const { campaigns } = await this.app.listCampaigns({ + $, + }); + $.export("$summary", `Sucessfully retrieved ${campaigns?.length ?? 0} campaigns`); + return campaigns; + }, +}; diff --git a/components/the_magic_drip/actions/list-templates/list-templates.mjs b/components/the_magic_drip/actions/list-templates/list-templates.mjs new file mode 100644 index 0000000000000..d99ab2b4a44c0 --- /dev/null +++ b/components/the_magic_drip/actions/list-templates/list-templates.mjs @@ -0,0 +1,19 @@ +import app from "../../the_magic_drip.app.mjs"; + +export default { + key: "the_magic_drip-list-templates", + name: "List Templates", + description: "Retrieve all available templates. [See the documentation](https://docs.themagicdrip.com/api-reference/endpoint/get-v1templates)", + version: "0.0.1", + type: "action", + props: { + app, + }, + async run({ $ }) { + const { templates } = await this.app.listTemplates({ + $, + }); + $.export("$summary", `Sucessfully retrieved ${templates?.length ?? 0} templates`); + return templates; + }, +}; diff --git a/components/the_magic_drip/actions/mark-campaign-active-or-inactive/mark-campaign-active-or-inactive.mjs b/components/the_magic_drip/actions/mark-campaign-active-or-inactive/mark-campaign-active-or-inactive.mjs new file mode 100644 index 0000000000000..a2ac55e62d25f --- /dev/null +++ b/components/the_magic_drip/actions/mark-campaign-active-or-inactive/mark-campaign-active-or-inactive.mjs @@ -0,0 +1,39 @@ +import app from "../../the_magic_drip.app.mjs"; + +export default { + key: "the_magic_drip-mark-campaign-active-or-inactive", + name: "Mark Campaign Active or Inactive", + description: "Marks a campaign as active or inactive. [See the documentation](https://docs.themagicdrip.com/api-reference/endpoint/post-v1campaign-active)", + version: "0.0.1", + type: "action", + props: { + app, + campaignId: { + propDefinition: [ + app, + "campaignId", + ], + }, + activate: { + type: "boolean", + label: "Activate", + description: "Set to `true` to activate, or `false` to deactivate the campaign", + }, + }, + async run({ $ }) { + const { + campaignId, activate, + } = this; + const response = await this.app.markCampaignActiveInactive({ + $, + campaignId, + activate, + }); + + $.export("$summary", `Successfully ${activate + ? "" + : "de"}activated campaign`); + + return response; + }, +}; diff --git a/components/the_magic_drip/package.json b/components/the_magic_drip/package.json index fe5597612c26b..b082e1ca3a97f 100644 --- a/components/the_magic_drip/package.json +++ b/components/the_magic_drip/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/the_magic_drip", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream The Magic Drip Components", "main": "the_magic_drip.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/components/the_magic_drip/sources/common.mjs b/components/the_magic_drip/sources/common.mjs new file mode 100644 index 0000000000000..1d3b3ab59a27e --- /dev/null +++ b/components/the_magic_drip/sources/common.mjs @@ -0,0 +1,56 @@ +import app from "../the_magic_drip.app.mjs"; +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; + +export default { + props: { + app, + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + db: "$.service.db", + }, + methods: { + _getSavedIds() { + return this.db.get("savedIds") || []; + }, + _setSavedIds(value) { + this.db.set("savedIds", value); + }, + getItemId(item) { + return item.id; + }, + getItemMetadata() { + return { + summary: "New event", + ts: Date.now(), + }; + }, + async getAndProcessData(maxEmits = 0) { + const savedIds = this._getSavedIds(); + const items = await this.getItems(); + + items?.filter?.((item) => !savedIds.includes(this.getItemId(item))).forEach((item, index) => { + if ((!maxEmits) || (index < maxEmits)) { + this.$emit(item, { + id: this.getItemId(item), + ...this.getItemMetadata(item), + }); + } + savedIds.push(this.getItemId(item)); + }); + + this._setSavedIds(savedIds); + }, + }, + hooks: { + async deploy() { + await this.getAndProcessData(5); + }, + }, + async run() { + await this.getAndProcessData(); + }, +}; diff --git a/components/the_magic_drip/sources/new-campaign-created/new-campaign-created.mjs b/components/the_magic_drip/sources/new-campaign-created/new-campaign-created.mjs new file mode 100644 index 0000000000000..deb1c88ac56ac --- /dev/null +++ b/components/the_magic_drip/sources/new-campaign-created/new-campaign-created.mjs @@ -0,0 +1,27 @@ +import common from "../common.mjs"; + +export default { + ...common, + key: "the_magic_drip-new-campaign-created", + name: "New Campaign Created", + description: "Emit new event when a campaign is created. [See the documentation](https://docs.themagicdrip.com/api-reference/endpoint/get-v1campaign)", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + async getItems() { + const { campaigns } = await this.app.listCampaigns(); + return campaigns; + }, + getItemId(item) { + return item.workflowId; + }, + getItemMetadata(item) { + return { + summary: `New Campaign: ${item.name}`, + ts: item.createdAt, + }; + }, + }, +}; diff --git a/components/the_magic_drip/sources/new-template-created/new-template-created.mjs b/components/the_magic_drip/sources/new-template-created/new-template-created.mjs new file mode 100644 index 0000000000000..9f7fa98c5d68f --- /dev/null +++ b/components/the_magic_drip/sources/new-template-created/new-template-created.mjs @@ -0,0 +1,27 @@ +import common from "../common.mjs"; + +export default { + ...common, + key: "the_magic_drip-new-template-created", + name: "New Template Created", + description: "Emit new event when a template is created. [See the documentation](https://docs.themagicdrip.com/api-reference/endpoint/get-v1templates)", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + async getItems() { + const { templates } = await this.app.listTemplates(); + return templates; + }, + getItemId(item) { + return item.templateId; + }, + getItemMetadata(item) { + return { + summary: `New Template: ${item.name}`, + ts: item.createdAt, + }; + }, + }, +}; diff --git a/components/the_magic_drip/the_magic_drip.app.mjs b/components/the_magic_drip/the_magic_drip.app.mjs index 0f4fb3f401b86..e233f9101d9b4 100644 --- a/components/the_magic_drip/the_magic_drip.app.mjs +++ b/components/the_magic_drip/the_magic_drip.app.mjs @@ -1,11 +1,80 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "the_magic_drip", - propDefinitions: {}, + propDefinitions: { + campaignId: { + type: "string", + label: "Campaign ID", + description: "Select a campaign", + async options() { + const { campaigns } = await this.listCampaigns(); + return campaigns?.map((campaign) => ({ + label: campaign.name, + value: campaign.workflowId, + })); + }, + }, + linkedinUrl: { + type: "string", + label: "LinkedIn URL", + description: "The LinkedIn URL of the lead", + optional: true, + }, + desiredState: { + type: "boolean", + label: "Desired State", + description: "Set to true to activate, false to deactivate the campaign", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.themagicdrip.com/v1"; + }, + async _makeRequest({ + $, path, headers, ...otherOpts + } = {}) { + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + "x-api-key": this.$auth.api_key, + }, + }); + }, + async listCampaigns(opts = {}) { + return this._makeRequest({ + path: "/campaign", + ...opts, + }); + }, + async addLeadToCampaign({ + campaignId, ...opts + }) { + return this._makeRequest({ + method: "POST", + path: `/campaign/leads/${campaignId}`, + ...opts, + }); + }, + async markCampaignActiveInactive({ + campaignId, activate, ...opts + }) { + return this._makeRequest({ + method: "POST", + path: `/campaign/${campaignId}/${activate + ? "active" + : "inactive"}`, + ...opts, + }); + }, + async listTemplates(opts = {}) { + return this._makeRequest({ + path: "/templates", + ...opts, + }); }, }, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c48a19d33f6b8..70650ceb80333 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10144,7 +10144,10 @@ importers: '@pipedream/platform': 3.0.3 components/the_magic_drip: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/the_odds_api: specifiers: