diff --git a/components/catch_all_verifier/catch_all_verifier.app.mjs b/components/catch_all_verifier/catch_all_verifier.app.mjs index 1b1bb9b8cbcfe..24aac4e360628 100644 --- a/components/catch_all_verifier/catch_all_verifier.app.mjs +++ b/components/catch_all_verifier/catch_all_verifier.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/ditlead/actions/list-campaigns/list-campaigns.mjs b/components/ditlead/actions/list-campaigns/list-campaigns.mjs new file mode 100644 index 0000000000000..859efd4687a29 --- /dev/null +++ b/components/ditlead/actions/list-campaigns/list-campaigns.mjs @@ -0,0 +1,20 @@ +import ditlead from "../../ditlead.app.mjs"; + +export default { + key: "ditlead-list-campaigns", + name: "List Campaigns", + description: "List campaigns in Ditlead. [See the documentation](https://ditlead.com/developer/api#tag/Campaign/paths/~1v1~1campaign/get)", + version: "0.0.1", + type: "action", + props: { + ditlead, + }, + async run({ $ }) { + const { data } = await this.ditlead.listCampaigns({ + $, + }); + + $.export("$summary", `Successfully listed ${data.length} campaigns`); + return data; + }, +}; diff --git a/components/ditlead/common/constants.mjs b/components/ditlead/common/constants.mjs new file mode 100644 index 0000000000000..02202e049eed4 --- /dev/null +++ b/components/ditlead/common/constants.mjs @@ -0,0 +1,18 @@ +export const WEBHOOK_EVENT_TYPES = [ + "email.bounced", + "email.opened", + "contact.replied", + "contact.created", + "contact.contacted", + "contact.started_campaign", + "contact.restarted_campaign", + "contact.completed_campaign", + "contact.unsubscribed", + "campaign.scheduled", + "campaign.started", + "campaign.paused", + "campaign.restarted", + "campaign.completed", + "campaign.limit", + "campaign.errored", +]; diff --git a/components/ditlead/ditlead.app.mjs b/components/ditlead/ditlead.app.mjs index 57c6ae77c00b7..8ae0c581c2516 100644 --- a/components/ditlead/ditlead.app.mjs +++ b/components/ditlead/ditlead.app.mjs @@ -1,11 +1,41 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "ditlead", propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _makeRequest({ + $, headers, ...args + }) { + return axios($, { + baseURL: "https://api.ditlead.com/v1", + headers: { + ...headers, + Authorization: `Bearer ${this.$auth.api_key}`, + }, + ...args, + }); + }, + createWebhook(args) { + return this._makeRequest({ + method: "POST", + url: "/webhook", + ...args, + }); + }, + deleteWebhook(args) { + return this._makeRequest({ + method: "DELETE", + url: "/webhook", + ...args, + }); + }, + listCampaigns(args) { + return this._makeRequest({ + url: "/campaign", + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/ditlead/package.json b/components/ditlead/package.json index f0c802e4069d8..42834691f72bb 100644 --- a/components/ditlead/package.json +++ b/components/ditlead/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/ditlead", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream DitLead Components", "main": "ditlead.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/ditlead/sources/common/base.mjs b/components/ditlead/sources/common/base.mjs new file mode 100644 index 0000000000000..35d4e12bb87ba --- /dev/null +++ b/components/ditlead/sources/common/base.mjs @@ -0,0 +1,49 @@ +import ditlead from "../../ditlead.app.mjs"; + +export default { + props: { + ditlead, + db: "$.service.db", + http: "$.interface.http", + }, + hooks: { + async activate() { + const { id } = await this.ditlead.createWebhook({ + data: { + url: this.http.endpoint, + name: "Pipedream Source", + eventId: this.getEventTypes(), + }, + }); + this._setWebhookId(id); + }, + async deactivate() { + await this.ditlead.deleteWebhook({ + data: { + subscriptionId: this._getWebhookId(), + }, + }); + }, + }, + methods: { + getEventTypes() { + throw new Error("Event types not specified for this component"); + }, + _setWebhookId(value) { + this.db.set("webhookId", value); + }, + _getWebhookId() { + return this.db.get("webhookId"); + }, + + }, + async run(event) { + const { body } = event; + const ts = Date.now(); + this.$emit(body, { + id: ts, + summary: "New event", + ts, + }); + }, +}; diff --git a/components/ditlead/sources/new-webhook-event/new-webhook-event.mjs b/components/ditlead/sources/new-webhook-event/new-webhook-event.mjs new file mode 100644 index 0000000000000..a7299c4cdbd0f --- /dev/null +++ b/components/ditlead/sources/new-webhook-event/new-webhook-event.mjs @@ -0,0 +1,27 @@ +import common from "../common/base.mjs"; +import { WEBHOOK_EVENT_TYPES } from "../../common/constants.mjs"; + +export default { + ...common, + key: "ditlead-new-webhook-event", + name: "New Webhook Event", + description: "Emit new events according to the selected event types. [See the documentation](https://ditlead.com/developer/api#tag/Webhook/paths/~1v1~1webhook/post)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + ...common.props, + eventTypes: { + type: "string[]", + label: "Event Types", + description: "Select one or more event types to listen for.", + options: WEBHOOK_EVENT_TYPES, + }, + }, + methods: { + ...common.methods, + getEventTypes() { + return this.eventTypes; + }, + }, +}; diff --git a/components/membado/membado.app.mjs b/components/membado/membado.app.mjs index 76fe2e29b095e..fe9b6c49fb177 100644 --- a/components/membado/membado.app.mjs +++ b/components/membado/membado.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/planpoint/planpoint.app.mjs b/components/planpoint/planpoint.app.mjs index 1281d198e4450..ccb4fbf919274 100644 --- a/components/planpoint/planpoint.app.mjs +++ b/components/planpoint/planpoint.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/szybkisms/szybkisms.app.mjs b/components/szybkisms/szybkisms.app.mjs index 019735da8412b..4380b4edb9b54 100644 --- a/components/szybkisms/szybkisms.app.mjs +++ b/components/szybkisms/szybkisms.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7e34e33e8f9b6..a84004a1b2201 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3569,7 +3569,11 @@ importers: components/dispatch: {} - components/ditlead: {} + components/ditlead: + dependencies: + '@pipedream/platform': + specifier: 3.0.3 + version: 3.0.3 components/dixa: dependencies: @@ -12886,8 +12890,7 @@ importers: components/systeme_io: {} - components/szybkisms: - specifiers: {} + components/szybkisms: {} components/t2m_url_shortener: {}