diff --git a/components/mailgenius/actions/get-daily-limit/get-daily-limit.mjs b/components/mailgenius/actions/get-daily-limit/get-daily-limit.mjs new file mode 100644 index 0000000000000..be43034f60fb3 --- /dev/null +++ b/components/mailgenius/actions/get-daily-limit/get-daily-limit.mjs @@ -0,0 +1,22 @@ +import app from "../../mailgenius.app.mjs"; + +export default { + key: "mailgenius-get-daily-limit", + name: "Get Daily Limit", + description: "Returns daily limit for api token, how many email tests are used in last 24 hours and how many are still remaining for use. [See the documentation](https://app.mailgenius.com/api-docs/index.html)", + version: "0.0.1", + type: "action", + props: { + app, + }, + + async run({ $ }) { + const response = await this.app.getDailyLimit({ + $, + }); + + $.export("$summary", `Your account has '${response.daily_tests_remaining}' remaining tests today`); + + return response; + }, +}; diff --git a/components/mailgenius/actions/get-email-audit/get-email-audit.mjs b/components/mailgenius/actions/get-email-audit/get-email-audit.mjs new file mode 100644 index 0000000000000..174de39139a19 --- /dev/null +++ b/components/mailgenius/actions/get-email-audit/get-email-audit.mjs @@ -0,0 +1,22 @@ +import app from "../../mailgenius.app.mjs"; + +export default { + key: "mailgenius-get-email-audit", + name: "Get Email Audit", + description: "Returns generated test email, limit exceeded if daily limit is reached. [See the documentation](https://app.mailgenius.com/api-docs/index.html)", + version: "0.0.1", + type: "action", + props: { + app, + }, + + async run({ $ }) { + const response = await this.app.emailAudit({ + $, + }); + + $.export("$summary", `Your test email is: ${response.test_email}. Please send an email to this address using the account you want to test`); + + return response; + }, +}; diff --git a/components/mailgenius/actions/get-email-result/get-email-result.mjs b/components/mailgenius/actions/get-email-result/get-email-result.mjs new file mode 100644 index 0000000000000..9a0635812f1b1 --- /dev/null +++ b/components/mailgenius/actions/get-email-result/get-email-result.mjs @@ -0,0 +1,29 @@ +import app from "../../mailgenius.app.mjs"; + +export default { + key: "mailgenius-get-email-result", + name: "Get Email Results", + description: "Returns the results of the test. [See the documentation](https://app.mailgenius.com/api-docs/index.html)", + version: "0.0.1", + type: "action", + props: { + app, + slug: { + propDefinition: [ + app, + "slug", + ], + }, + }, + + async run({ $ }) { + const response = await this.app.emailResult({ + $, + slug: this.slug, + }); + + $.export("$summary", `The test results are '${response.status}'`); + + return response; + }, +}; diff --git a/components/mailgenius/mailgenius.app.mjs b/components/mailgenius/mailgenius.app.mjs index 441b1c947f246..f851d3c6e8ec7 100644 --- a/components/mailgenius/mailgenius.app.mjs +++ b/components/mailgenius/mailgenius.app.mjs @@ -1,11 +1,71 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "mailgenius", - propDefinitions: {}, + propDefinitions: { + slug: { + type: "string", + label: "Model", + description: "Specifies the model to be used for the request", + async options() { + const response = await this.getEmails(); + const emailsSlugs = response.test_emails; + return emailsSlugs.map(({ + slug, test_email, + }) => ({ + value: slug, + label: test_email, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://app.mailgenius.com"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + Authorization: `Bearer ${this.$auth.api_token}`, + accept: "*/*", + }, + }); + }, + async emailAudit(args = {}) { + return this._makeRequest({ + path: "/external/api/email-audit", + ...args, + }); + }, + async emailResult({ + slug, ...args + }) { + return this._makeRequest({ + path: `/external/api/email-result/${slug}`, + ...args, + }); + }, + async getDailyLimit(args = {}) { + return this._makeRequest({ + path: "/external/api/daily_limit", + ...args, + }); + }, + async getEmails(args = {}) { + return this._makeRequest({ + path: "/external/api/audits", + ...args, + }); }, }, }; diff --git a/components/mailgenius/package.json b/components/mailgenius/package.json index ac13cf5374a5a..f9923cd985cd9 100644 --- a/components/mailgenius/package.json +++ b/components/mailgenius/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/mailgenius", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream MailGenius Components", "main": "mailgenius.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/pnpm-lock.yaml b/pnpm-lock.yaml index a3ea0d1fcb593..d8e28e7a0d953 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6114,7 +6114,11 @@ importers: specifier: ^2.0.5 version: 2.3.0 - components/mailgenius: {} + components/mailgenius: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/mailgun: dependencies: