Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions components/mailgenius/actions/get-daily-limit/get-daily-limit.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
};
22 changes: 22 additions & 0 deletions components/mailgenius/actions/get-email-audit/get-email-audit.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
};
Original file line number Diff line number Diff line change
@@ -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;
},
Comment on lines +19 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling and response validation.

The current implementation could be more robust with the following improvements:

  1. Add error handling for the API call
  2. Validate the response structure
  3. Add null checks for the status field in the summary message

Consider applying this improvement:

 async run({ $ }) {
-    const response = await this.app.emailResult({
-      $,
-      slug: this.slug,
-    });
+    try {
+      const response = await this.app.emailResult({
+        $,
+        slug: this.slug,
+      });
+      
+      if (!response || typeof response !== 'object') {
+        throw new Error('Invalid response from MailGenius API');
+      }
 
-    $.export("$summary", `The test results are '${response.status}'`);
+      const status = response.status ?? 'unknown';
+      $.export("$summary", `The test results are '${status}'`);
 
-    return response;
+      return response;
+    } catch (error) {
+      throw new Error(`Failed to get email results: ${error.message}`);
+    }
   },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async run({ $ }) {
const response = await this.app.emailResult({
$,
slug: this.slug,
});
$.export("$summary", `The test results are '${response.status}'`);
return response;
},
async run({ $ }) {
try {
const response = await this.app.emailResult({
$,
slug: this.slug,
});
if (!response || typeof response !== 'object') {
throw new Error('Invalid response from MailGenius API');
}
const status = response.status ?? 'unknown';
$.export("$summary", `The test results are '${status}'`);
return response;
} catch (error) {
throw new Error(`Failed to get email results: ${error.message}`);
}
},

};
68 changes: 64 additions & 4 deletions components/mailgenius/mailgenius.app.mjs
Original file line number Diff line number Diff line change
@@ -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,
});
},
},
};
7 changes: 5 additions & 2 deletions components/mailgenius/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/mailgenius",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream MailGenius Components",
"main": "mailgenius.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
41 changes: 28 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading