diff --git a/components/_4dem/_4dem.app.mjs b/components/_4dem/_4dem.app.mjs index ac4d25fed41fa..269ef52ab7737 100644 --- a/components/_4dem/_4dem.app.mjs +++ b/components/_4dem/_4dem.app.mjs @@ -1,11 +1,145 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "_4dem", - propDefinitions: {}, + propDefinitions: { + name: { + type: "string", + label: "Name", + description: "Name of the sender", + }, + email: { + type: "string", + label: "Email", + description: "Email address", + }, + nominative: { + type: "string", + label: "Nominative", + description: "Sender nominativa, i.e. `My Company`", + }, + ivaFCode: { + type: "string", + label: "IVA Code", + description: "Sender IVA code, i.e. `IT123456789`", + }, + address: { + type: "string", + label: "Address", + description: "Sender address, i.e. `Via Roma 1`", + }, + city: { + type: "string", + label: "City", + description: "Sender city, i.e. `Torino`", + }, + province: { + type: "string", + label: "Province", + description: "Abbreviation of the province, i.e. `TO`", + }, + country: { + type: "string", + label: "Country", + description: "Sender country, i.e. `Italia`", + }, + cap: { + type: "string", + label: "Postal Code", + description: "Sender postal code, i.e. `10100`", + }, + telephone: { + type: "string", + label: "Telephone", + description: "Telephone number, i.e.`+393331234567`", + }, + senderId: { + type: "string", + label: "Sender ID", + description: "ID of the sender", + async options() { + const { data: sendersIds } = await this.getSenders(); + + return sendersIds.map(({ + id, name, + }) => ({ + value: id, + label: name, + })); + }, + }, + authCode: { + type: "string", + label: "Auth Code", + description: "Authenticator code sent to the provided email", + }, + subject: { + type: "string", + label: "Email Subject", + description: "Subject of the email", + }, + plain: { + type: "string", + label: "Plain Content", + description: "Plain content of the email", + optional: true, + }, + html: { + type: "string", + label: "HTML Content", + description: "HTML content of the email", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.4dem.it"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + Authorization: `Bearer ${this.$auth.oauth_access_token}`, + }, + }); + }, + async createSender(args = {}) { + return this._makeRequest({ + method: "post", + path: "/senders/email", + ...args, + }); + }, + async confirmEmail({ + senderId, ...args + }) { + return this._makeRequest({ + method: "post", + path: `/senders/email/${senderId}/confirm`, + ...args, + }); + }, + async createEmail(args = {}) { + return this._makeRequest({ + method: "post", + path: "/contents/emails", + ...args, + }); + }, + async getSenders(args = {}) { + return this._makeRequest({ + path: "/senders/email", + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/_4dem/actions/confirm-email/confirm-email.mjs b/components/_4dem/actions/confirm-email/confirm-email.mjs new file mode 100644 index 0000000000000..2f937f6da4e43 --- /dev/null +++ b/components/_4dem/actions/confirm-email/confirm-email.mjs @@ -0,0 +1,37 @@ +import app from "../../_4dem.app.mjs"; + +export default { + key: "_4dem-confirm-email", + name: "Confirm Email", + description: "Confirm sender email address. [See the documentation](https://api.4dem.it/#/operations/senders.email.confirm)", + version: "0.0.1", + type: "action", + props: { + app, + senderId: { + propDefinition: [ + app, + "senderId", + ], + }, + authCode: { + propDefinition: [ + app, + "authCode", + ], + }, + }, + async run({ $ }) { + const response = await this.app.confirmEmail({ + $, + senderId: this.senderId, + data: { + auth_code: this.authCode, + }, + }); + + $.export("$summary", "Successfully confirmed the sender email"); + + return response; + }, +}; diff --git a/components/_4dem/actions/create-email/create-email.mjs b/components/_4dem/actions/create-email/create-email.mjs new file mode 100644 index 0000000000000..fc1219709e2fc --- /dev/null +++ b/components/_4dem/actions/create-email/create-email.mjs @@ -0,0 +1,63 @@ +import app from "../../_4dem.app.mjs"; + +export default { + key: "_4dem-create-email", + name: "Create Email", + description: "Create a new email. [See the documentation](https://api.4dem.it/#/operations/contents.email.store)", + version: "0.0.1", + type: "action", + props: { + app, + name: { + propDefinition: [ + app, + "name", + ], + description: "Email Name", + }, + subject: { + propDefinition: [ + app, + "subject", + ], + }, + senderId: { + propDefinition: [ + app, + "senderId", + ], + }, + plain: { + propDefinition: [ + app, + "plain", + ], + }, + html: { + propDefinition: [ + app, + "html", + ], + }, + }, + async run({ $ }) { + const response = await this.app.createEmail({ + $, + data: { + name: this.name, + subject: this.subject, + sender: { + id: this.senderId, + }, + content: { + plain: this.plain, + html: this.html, + }, + }, + }); + + $.export("$summary", `Successfully created email '${this.name}'`); + + return response; + }, +}; diff --git a/components/_4dem/actions/create-sender/create-sender.mjs b/components/_4dem/actions/create-sender/create-sender.mjs new file mode 100644 index 0000000000000..8d620fc199dd9 --- /dev/null +++ b/components/_4dem/actions/create-sender/create-sender.mjs @@ -0,0 +1,95 @@ +import app from "../../_4dem.app.mjs"; + +export default { + key: "_4dem-create-sender", + name: "Create Sender", + description: "Create an email sender. You will need to confirm the email address used during creation. [See the documentation](https://api.4dem.it/#/operations/senders.email.store)", + version: "0.0.1", + type: "action", + props: { + app, + name: { + propDefinition: [ + app, + "name", + ], + }, + email: { + propDefinition: [ + app, + "email", + ], + }, + nominative: { + propDefinition: [ + app, + "nominative", + ], + }, + ivaFCode: { + propDefinition: [ + app, + "ivaFCode", + ], + }, + address: { + propDefinition: [ + app, + "address", + ], + }, + city: { + propDefinition: [ + app, + "city", + ], + }, + province: { + propDefinition: [ + app, + "province", + ], + }, + country: { + propDefinition: [ + app, + "country", + ], + }, + cap: { + propDefinition: [ + app, + "cap", + ], + }, + telephone: { + propDefinition: [ + app, + "telephone", + ], + }, + }, + async run({ $ }) { + const response = await this.app.createSender({ + $, + data: { + name: this.name, + email: this.email, + csa_data: { + nominative: this.nominative, + ivaFCode: this.ivaFCode, + address: this.address, + city: this.city, + province: this.province, + country: this.country, + cap: this.cap, + telephone: this.telephone, + }, + }, + }); + + $.export("$summary", "Successfully created the sender, now it's necessary to confirm it with the code sent to the provided email"); + + return response; + }, +}; diff --git a/components/_4dem/package.json b/components/_4dem/package.json index 08e44a4df37c6..2bbe4791dced8 100644 --- a/components/_4dem/package.json +++ b/components/_4dem/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/_4dem", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream 4Dem Components", "main": "_4dem.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.0" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index eb9bf6d73054f..263189e4efdc9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -99,7 +99,10 @@ importers: '@pipedream/platform': 1.6.0 components/_4dem: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.0 + dependencies: + '@pipedream/platform': 3.0.0 components/_8x8_connect: specifiers: {}