Skip to content

Set user agent#5

Merged
leonid-shevtsov merged 1 commit intomainfrom
set-user-agent
Mar 5, 2026
Merged

Set user agent#5
leonid-shevtsov merged 1 commit intomainfrom
set-user-agent

Conversation

@leonid-shevtsov
Copy link
Copy Markdown
Contributor

@leonid-shevtsov leonid-shevtsov commented Feb 19, 2026

Set custom user agent for this extension

Summary by CodeRabbit

  • Chores
    • Introduced a standardized USER_AGENT value and ensured it is included when creating the Mailtrap client to keep the library version synchronized.
    • This change improves consistency in how the application identifies itself to the email testing service, aiding compatibility and traceability across deployments.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 19, 2026

📝 Walkthrough

Walkthrough

Added a USER_AGENT constant and passed it as the userAgent option when constructing MailtrapClient in functions/src/mailtrap.ts, replacing the previous instantiation that omitted a user agent.

Changes

Cohort / File(s) Summary
User Agent Configuration
functions/src/mailtrap.ts
Introduce USER_AGENT constant and supply it to new MailtrapClient({ userAgent: USER_AGENT }), ensuring outgoing requests include the library user agent.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 I nibble on code with a curious cheer,

I set a USER_AGENT so Mailtrap will hear,
Now requests hop along with the version in tow,
Synchronized steps in a tidy little row,
🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Set user agent' directly and clearly describes the main change: adding a USER_AGENT constant and passing it to MailtrapClient, which aligns perfectly with the PR's objective of setting a custom user agent for the extension.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch set-user-agent

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@functions/src/mailtrap.ts`:
- Around line 5-7: Prettier is failing on the USER_AGENT declaration in
mailtrap.ts; run the formatter (prettier --write functions/src/mailtrap.ts or
npm run format:write) to fix CI, and to prevent future drift replace the
hardcoded "1.0.0" in the USER_AGENT constant with a derived value from
package.json (e.g., import package.json version or use createRequire to read it)
so USER_AGENT in mailtrap.ts always uses package.json.version; ensure tsconfig
has resolveJsonModule enabled or use createRequire if JSON imports aren't
supported.
- Around line 31-34: Remove the invalid userAgent option from the MailtrapClient
constructor: when creating the client (the new MailtrapClient call that assigns
to client using apiToken and USER_AGENT), drop the userAgent property since
mailtrap@4.0.0 only accepts token plus optional
testInboxId/accountId/bulk/sandbox; if a custom user agent is required consult
the SDK for supported configuration or use another HTTP-layer mechanism, but do
not pass USER_AGENT into the MailtrapClient constructor.

Comment thread functions/src/mailtrap.ts Outdated
Comment on lines +5 to +7
// Keep version in sync with functions/package.json
const USER_AGENT =
"mailtrap-firebase/1.0.0 (https://github.com/mailtrap/mailtrap-firebase)";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Fix Prettier formatting to unblock CI; consider deriving version from package.json.

The CI pipeline reports a Prettier formatting check failure for this file. Run prettier --write functions/src/mailtrap.ts (or npm run format:write) before merging.

Separately, the "1.0.0" version is hardcoded with a // Keep version in sync comment, creating a silent drift risk — future version bumps in package.json won't automatically update this string. Consider importing the version directly:

♻️ Proposed refactor: derive version from `package.json`
+import { version } from "../package.json" assert { type: "json" };
+
 // Keep version in sync with functions/package.json
-const USER_AGENT =
-  "mailtrap-firebase/1.0.0 (https://github.com/mailtrap/mailtrap-firebase)";
+const USER_AGENT = `mailtrap-firebase/${version} (https://github.com/mailtrap/mailtrap-firebase)`;

Requires "resolveJsonModule": true in tsconfig.json (likely already set for Firebase Functions projects). If JSON imports with assert aren't supported by the target, use a createRequire approach instead.

📝 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
// Keep version in sync with functions/package.json
const USER_AGENT =
"mailtrap-firebase/1.0.0 (https://github.com/mailtrap/mailtrap-firebase)";
import { version } from "../package.json" assert { type: "json" };
// Keep version in sync with functions/package.json
const USER_AGENT = `mailtrap-firebase/${version} (https://github.com/mailtrap/mailtrap-firebase)`;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@functions/src/mailtrap.ts` around lines 5 - 7, Prettier is failing on the
USER_AGENT declaration in mailtrap.ts; run the formatter (prettier --write
functions/src/mailtrap.ts or npm run format:write) to fix CI, and to prevent
future drift replace the hardcoded "1.0.0" in the USER_AGENT constant with a
derived value from package.json (e.g., import package.json version or use
createRequire to read it) so USER_AGENT in mailtrap.ts always uses
package.json.version; ensure tsconfig has resolveJsonModule enabled or use
createRequire if JSON imports aren't supported.

Comment thread functions/src/mailtrap.ts
Comment on lines +31 to +34
const client = new MailtrapClient({
token: apiToken,
userAgent: USER_AGENT,
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find TypeScript declaration files in mailtrap package
find node_modules/mailtrap -name "*.d.ts" -type f 2>/dev/null | head -20

Repository: mailtrap/mailtrap-firebase

Length of output: 52


🏁 Script executed:

#!/bin/bash
# Search for userAgent in mailtrap dist files
rg -n "userAgent" node_modules/mailtrap/dist --include="*.d.ts" -A2 -B2

Repository: mailtrap/mailtrap-firebase

Length of output: 511


🏁 Script executed:

#!/bin/bash
# Find constructor/options type definitions in mailtrap
rg -n "ClientOptions|MailtrapClientOptions|interface.*Options|constructor" node_modules/mailtrap/dist --include="*.d.ts" -A10 | head -100

Repository: mailtrap/mailtrap-firebase

Length of output: 511


🏁 Script executed:

#!/bin/bash
# First, verify the mailtrap package exists and explore its structure
ls -la node_modules/mailtrap/ 2>/dev/null | head -20

Repository: mailtrap/mailtrap-firebase

Length of output: 52


🏁 Script executed:

#!/bin/bash
# Find any .ts or .d.ts files in mailtrap
find node_modules/mailtrap -type f \( -name "*.d.ts" -o -name "*.ts" \) 2>/dev/null

Repository: mailtrap/mailtrap-firebase

Length of output: 52


🏁 Script executed:

#!/bin/bash
# Search for userAgent in the mailtrap directory with proper rg syntax
rg "userAgent" node_modules/mailtrap 2>/dev/null | head -20

Repository: mailtrap/mailtrap-firebase

Length of output: 52


🏁 Script executed:

#!/bin/bash
# Search for MailtrapClient constructor and options with proper syntax
rg "MailtrapClient|ClientOptions" node_modules/mailtrap 2>/dev/null | head -30

Repository: mailtrap/mailtrap-firebase

Length of output: 52


🏁 Script executed:

#!/bin/bash
# Check the project's package.json for mailtrap version
cat package.json | grep -A5 -B5 "mailtrap"

Repository: mailtrap/mailtrap-firebase

Length of output: 114


🏁 Script executed:

#!/bin/bash
# Also check lock files
if [ -f package-lock.json ]; then
  cat package-lock.json | grep -A20 '"mailtrap"' | head -30
fi

Repository: mailtrap/mailtrap-firebase

Length of output: 52


🌐 Web query:

mailtrap npm v4.0.0 MailtrapClient constructor options documentation

💡 Result:

In mailtrap npm v4.0.0, MailtrapClient is constructed as:

new MailtrapClient({
  token: string,        // required
  testInboxId?: number, // optional
  accountId?: number,   // optional
  bulk?: boolean,       // optional (default: false)
  sandbox?: boolean,    // optional (default: false)
})
  • token is required and is used as a Bearer token in the Authorization header. [1]
  • bulk and sandbox default to false; enabling both at once throws an error (they’re incompatible). [1]
  • To use client.testing, both testInboxId and accountId must be provided (otherwise it throws). [1]
  • The config shape is defined as MailtrapClientConfig in the SDK types. [2]

Sources: Mailtrap Node.js SDK v4.0.0 source (MailtrapClient.ts, types/mailtrap.ts). [1] [2]


Remove userAgent from the MailtrapClient constructor—it is not a valid option in mailtrap@4.0.0.

The official v4.0.0 MailtrapClient constructor only accepts token (required), and testInboxId, accountId, bulk, and sandbox (optional). The userAgent key is silently ignored and will not be sent by the client. Either remove it or find the correct mechanism in the mailtrap SDK to set a custom user agent if supported.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@functions/src/mailtrap.ts` around lines 31 - 34, Remove the invalid userAgent
option from the MailtrapClient constructor: when creating the client (the new
MailtrapClient call that assigns to client using apiToken and USER_AGENT), drop
the userAgent property since mailtrap@4.0.0 only accepts token plus optional
testInboxId/accountId/bulk/sandbox; if a custom user agent is required consult
the SDK for supported configuration or use another HTTP-layer mechanism, but do
not pass USER_AGENT into the MailtrapClient constructor.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
functions/src/mailtrap.ts (1)

30-33: ⚠️ Potential issue | 🟠 Major

userAgent may not be a valid MailtrapClient option in mailtrap@4.0.0.

If unsupported, the property is ignored and the custom UA is never sent (PR objective not achieved). Please verify the SDK config type/API and switch to the supported mechanism for setting headers/user-agent.

#!/bin/bash
set -euo pipefail

# 1) Confirm installed mailtrap version
node -e 'const p=require("./package.json"); console.log("root deps mailtrap=", p.dependencies?.mailtrap || p.devDependencies?.mailtrap || "not declared in root package.json")' || true
node -e 'try{const p=require("./functions/package.json"); console.log("functions deps mailtrap=", p.dependencies?.mailtrap || p.devDependencies?.mailtrap || "not declared in functions/package.json")}catch(e){console.log("functions/package.json not found")}'

# 2) Inspect SDK type definitions for constructor config and userAgent support
rg -n --type-add 'dts:*.d.ts' --type dts -C3 'class\s+MailtrapClient|interface\s+.*Config|type\s+.*Config|userAgent' node_modules/mailtrap 2>/dev/null || true

# 3) Narrow check: look for userAgent in constructor config surface
rg -n --type-add 'dts:*.d.ts' --type dts -C2 'userAgent' node_modules/mailtrap 2>/dev/null || true
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@functions/src/mailtrap.ts` around lines 30 - 33, The MailtrapClient
constructor currently passes userAgent (USER_AGENT) which may not be a valid
option; verify the SDK's config type for MailtrapClient and if userAgent isn't
supported, stop passing it and instead set the UA via the supported mechanism
(e.g., the constructor's supported headers/agent option or by configuring the
client's default request headers or underlying HTTP client). Locate the
MailtrapClient instantiation (new MailtrapClient({ token: apiToken, userAgent:
USER_AGENT })) and replace the unsupported userAgent field with the
SDK-supported approach (e.g., headers: { 'User-Agent': USER_AGENT } or
configuring the client's request defaults or middleware per the mailtrap SDK
types). Ensure the change compiles against the SDK typings and that the created
client (client) sends the custom User-Agent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@functions/src/mailtrap.ts`:
- Around line 30-33: The MailtrapClient constructor currently passes userAgent
(USER_AGENT) which may not be a valid option; verify the SDK's config type for
MailtrapClient and if userAgent isn't supported, stop passing it and instead set
the UA via the supported mechanism (e.g., the constructor's supported
headers/agent option or by configuring the client's default request headers or
underlying HTTP client). Locate the MailtrapClient instantiation (new
MailtrapClient({ token: apiToken, userAgent: USER_AGENT })) and replace the
unsupported userAgent field with the SDK-supported approach (e.g., headers: {
'User-Agent': USER_AGENT } or configuring the client's request defaults or
middleware per the mailtrap SDK types). Ensure the change compiles against the
SDK typings and that the created client (client) sends the custom User-Agent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 24c10001-0475-470b-bc44-1f05aa1d897f

📥 Commits

Reviewing files that changed from the base of the PR and between 82b625b and 1162b47.

📒 Files selected for processing (1)
  • functions/src/mailtrap.ts

@leonid-shevtsov leonid-shevtsov merged commit 662783e into main Mar 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants