fix: updating Mailjet client auth#19725
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
|
Thank you so much for submitting this! We've added it to our backlog to review, and our team has been notified. |
WalkthroughVersion bumps across Mailjet actions (0.0.3 → 0.0.4), a source ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Thanks for submitting this PR! When we review PRs, we follow the Pipedream component guidelines. If you're not familiar, here's a quick checklist:
|
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
components/mailjet/actions/send-message/send-message.mjs (4)
57-68: Add validation to enforce at least one content field is required.Both
textPartandhtmlPartare marked optional, but the Mailjet API requires at least one to be specified. The action should validate this constraint before making the API call to provide a clearer error message.✅ Proposed validation fix
Add this validation in the
runmethod after destructuring (around line 82):} = this; + if (!textPart && !htmlPart) { + throw new Error("At least one of 'Text Part' or 'HTML Part' must be provided."); + } + try { const { body: { Sent: response } } =
99-101: Add defensive check before accessing array element.The code assumes
response[0]exists without verification. While the API should return at least one result on success, adding a bounds check would prevent potential runtime errors.🛡️ Defensive coding suggestion
- $.export("$summary", `Successfully sent email message with ID ${response[0].MessageID}`); + if (!response || response.length === 0) { + throw new Error("No response received from Mailjet API"); + } + $.export("$summary", `Successfully sent email message with ID ${response[0].MessageID}`);
103-105: Consider preserving more error context for better debugging.The current error handling extracts only
statusMessage, which may lose important details like error codes or response body that could help troubleshoot API failures.🔍 Enhanced error handling
} catch (error) { - throw error.response?.res?.statusMessage ?? error; + const errorMessage = error.response?.res?.statusMessage; + const errorBody = error.response?.body; + throw new Error( + errorMessage + ? `Mailjet API error: ${errorMessage}${errorBody ? ` - ${JSON.stringify(errorBody)}` : ''}` + : error.message || error + ); }
87-89: Fix the Sender field type — it must be an object, not a boolean.The Mailjet Send API v3 expects the
"Sender"field to be an object with"Email"and optional"Name"properties (e.g.,{ "Email":"sender@example.com", "Name":"Sender Name" }), but the code passes a boolean value directly. This will cause the API call to fail. If the intent is to conditionally use a default sender address, transform the boolean flag into the proper object structure or omit the field when not needed.
|
Hi everyone, all test cases are passed! Ready for release! Test reports
|
|
Hi @maycon-pipedream, make sure you update the version of the source |
…HQ/pipedream into fix/mailjet-connection
|
/approve |
Fix Mailjet Authentication Issue
Problem
The Mailjet integration was failing to authenticate with a 401 Unauthorized error.
Root Cause
Two issues were identified:
Incorrect auth field reference in code: The app was referencing
this.$auth.api_key, but the Pipedream authentication configuration for Mailjet usesthis.$auth.public_keyandthis.$auth.secret_key.Incorrect authentication strategy configuration: In the Admin Apps configuration, the authentication field was set to
API_KEYinstead ofPublic_Key, causing the credentials to not be properly resolved.Changes Made
Updated the import statement to use the correct library name:
import Mailjet from "node-mailjet"toimport MailjetClient from "node-mailjet"Updated the
client()method inmailjet.app.mjsto use the correct authentication field names:this.$auth.api_keytothis.$auth.public_keyUpdated the client instantiation to use the proper
node-mailjetv6.x syntax:return new MailjetClient({
apiKey: this.$auth.public_key,
apiSecret: this.$auth.secret_key,
});
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.