Skip to content

refactor: resend client options#865

Open
Shubhdeep12 wants to merge 4 commits intoresend:canaryfrom
Shubhdeep12:feat/resend-options
Open

refactor: resend client options#865
Shubhdeep12 wants to merge 4 commits intoresend:canaryfrom
Shubhdeep12:feat/resend-options

Conversation

@Shubhdeep12
Copy link
Contributor

@Shubhdeep12 Shubhdeep12 commented Mar 3, 2026

  • updated the resend constructor to accept optional client options for base URL, user agent and custom fetch.
  • added a new type -> ResendClientOptions.
  • updated tests

Summary by cubic

Add support for per-client options in the Resend constructor (baseUrl, userAgent, custom fetch) to improve configurability and testing. Client options now take precedence over env vars and allow explicit empty values.

  • New Features
    • New ResendClientOptions type; exported from resend and index.
    • fetchRequest uses instance baseUrl and fetch; tests assert fetch URLs and client-option error paths.

Written for commit 38ba8fc. Summary will update on new commits.

@Shubhdeep12 Shubhdeep12 requested a review from a team as a code owner March 3, 2026 02:03
@Shubhdeep12 Shubhdeep12 requested a review from drish March 3, 2026 02:03
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 3, 2026

Open in StackBlitz

npm i https://pkg.pr.new/resend@865

commit: e8039ba

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

3 issues found across 4 files

Confidence score: 3/5

  • There is a concrete behavior risk in src/resend.ts: using baseUrl ?? default means an empty-string env/config value is treated as valid, which can produce relative request URLs instead of using the intended API host.
  • This lands in moderate-risk territory because the top issue is medium severity (6/10) with high confidence (9/10) and can affect real request routing at runtime.
  • The tests in src/broadcasts/broadcasts.spec.ts and src/emails/emails.spec.ts are currently weak on URL assertions, so they may pass even when baseUrl handling is broken, reducing safety against regressions.
  • Pay close attention to src/resend.ts, src/broadcasts/broadcasts.spec.ts, and src/emails/emails.spec.ts - fix empty-string baseUrl fallback behavior and add explicit request-URL assertions.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/broadcasts/broadcasts.spec.ts">

<violation number="1" location="src/broadcasts/broadcasts.spec.ts:286">
P2: Client-options fetch-failure test is non-diagnostic because it relies on globally mocked fetch without asserting the request URL, so it may pass even if `baseUrl` is ignored.</violation>
</file>

<file name="src/resend.ts">

<violation number="1" location="src/resend.ts:66">
P2: Using nullish coalescing for `baseUrl` allows empty-string config/env values, causing relative request URLs instead of falling back to the default API host.</violation>
</file>

<file name="src/emails/emails.spec.ts">

<violation number="1" location="src/emails/emails.spec.ts:410">
P2: Client-options test does not verify `baseUrl` usage, so it can pass without proving the option is honored.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

…ass; add fetch call assertions in broadcasts and emails tests
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/resend.ts">

<violation number="1" location="src/resend.ts:66">
P2: Using `||` instead of `??` for client option precedence causes explicit empty-string overrides to be ignored, introducing a behavioral regression.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/resend.ts">

<violation number="1" location="src/resend.ts:66">
P2: Using `??` for `baseUrl`/`userAgent` allows empty strings to bypass defaults, causing invalid or unintended request targets instead of safe fallback.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

this._key = apiKey;

this.baseUrl =
options?.baseUrl ?? (getEnv('RESEND_BASE_URL') || defaultBaseUrl);
Copy link
Contributor

Choose a reason for hiding this comment

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

P2: Using ?? for baseUrl/userAgent allows empty strings to bypass defaults, causing invalid or unintended request targets instead of safe fallback.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/resend.ts, line 66:

<comment>Using `??` for `baseUrl`/`userAgent` allows empty strings to bypass defaults, causing invalid or unintended request targets instead of safe fallback.</comment>

<file context>
@@ -63,9 +63,9 @@ export class Resend {
 
     this.baseUrl =
-      options?.baseUrl || getEnv('RESEND_BASE_URL') || defaultBaseUrl;
+      options?.baseUrl ?? (getEnv('RESEND_BASE_URL') || defaultBaseUrl);
     const userAgent =
-      options?.userAgent || getEnv('RESEND_USER_AGENT') || defaultUserAgent;
</file context>

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.

1 participant