-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[Components] mailgenius #14754 #15056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+147
−7
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5907da2
Added actions
lcaresia 6a2db75
pnpm
lcaresia c98d30f
Update get-email-result.mjs
lcaresia cd38cd5
Done requests changes
lcaresia 65019d4
Merge branch 'master' into issue-14754
lcaresia 5f13942
Merge branch 'master' into issue-14754
lcaresia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
components/mailgenius/actions/get-daily-limit/get-daily-limit.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
22
components/mailgenius/actions/get-email-audit/get-email-audit.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }, | ||
| }; |
29 changes: 29 additions & 0 deletions
29
components/mailgenius/actions/get-email-result/get-email-result.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| }); | ||
| }, | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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": [ | ||
|
|
@@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.3" | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
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