Skip to content

Conversation

@arcoraven
Copy link
Contributor

@arcoraven arcoraven commented Jun 8, 2025

[SDK] Fix: Make service API key optional to allow services to pass through auth

Notes for the reviewer

This PR makes the serviceApiKey parameter optional in the service-utils package to support services that pass through user-provided authentication (like analytics) and should not have any authed access on their own.

How to test

Added unit tests to verify that empty headers are returned when no auth method and no serviceApiKey is provided.

Summary by CodeRabbit

  • New Features
    • Service API key is now optional, allowing access to certain services without authentication.
  • Bug Fixes
    • Improved handling of authentication headers when no API key or authentication method is provided.
  • Tests
    • Added tests to verify correct behavior when API key is omitted or undefined.

@vercel
Copy link

vercel bot commented Jun 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 8, 2025 10:33am
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 8, 2025 10:33am
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 8, 2025 10:33am
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 8, 2025 10:33am
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 8, 2025 10:33am

@changeset-bot
Copy link

changeset-bot bot commented Jun 8, 2025

🦋 Changeset detected

Latest commit: 8655147

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@thirdweb-dev/service-utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 8, 2025

Walkthrough

The changes make the service API key optional in the @thirdweb-dev/service-utils package, affecting the authentication flow. The CoreServiceConfig type and the getAuthHeaders function were updated to support optional API keys, and additional tests were added to verify unauthenticated access scenarios.

Changes

File(s) Change Summary
packages/service-utils/src/core/api.ts Made serviceApiKey in CoreServiceConfig optional; added comment explaining the rationale.
packages/service-utils/src/core/get-auth-headers.ts Updated getAuthHeaders to accept optional serviceApiKey, refactored logic, and adjusted return type.
packages/service-utils/src/core/get-auth-headers.test.ts Added tests for cases where no authentication method or API key is provided.
.changeset/good-swans-bet.md Added a changeset describing the patch and its implications.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ServiceUtils

    Client->>ServiceUtils: getAuthHeaders(authData, serviceApiKey?)
    alt With authData
        ServiceUtils-->>Client: Return headers with auth info
    else With serviceApiKey
        ServiceUtils-->>Client: Return headers with API key
    else Neither present
        ServiceUtils-->>Client: Return empty headers {}
    end
Loading

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6378f37 and 8655147.

📒 Files selected for processing (4)
  • .changeset/good-swans-bet.md (1 hunks)
  • packages/service-utils/src/core/api.ts (1 hunks)
  • packages/service-utils/src/core/get-auth-headers.test.ts (1 hunks)
  • packages/service-utils/src/core/get-auth-headers.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Size
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Lint Packages
  • GitHub Check: Build Packages
  • GitHub Check: Unit Tests
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (5)
packages/service-utils/src/core/get-auth-headers.test.ts (1)

115-123: LGTM! Good test coverage for optional serviceApiKey scenarios.

The new test cases properly verify the behavior when serviceApiKey is omitted or explicitly undefined, ensuring the function returns empty headers as expected for unauthenticated scenarios.

.changeset/good-swans-bet.md (1)

1-6: LGTM! Changeset properly documents the patch.

The changeset correctly categorizes this as a patch release and provides a clear description of the authentication flexibility enhancement.

packages/service-utils/src/core/api.ts (1)

23-24: LGTM! Well-documented type change for optional serviceApiKey.

The comment clearly explains the rationale for making serviceApiKey optional, and the type change correctly reflects the new authentication flexibility for pass-through services.

packages/service-utils/src/core/get-auth-headers.ts (2)

12-13: LGTM! Proper parameter and return type updates.

Making serviceApiKey optional and changing the return type to HeadersInit correctly aligns with the authentication flexibility requirements and HTTP standards.


36-46: LGTM! Well-structured authentication fallback logic.

The explicit case for serviceApiKey and the default empty return properly handle the optional authentication flow while maintaining the correct priority order for authentication methods.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Jun 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.57%. Comparing base (6378f37) to head (8655147).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7305   +/-   ##
=======================================
  Coverage   55.57%   55.57%           
=======================================
  Files         909      909           
  Lines       58673    58673           
  Branches     4158     4158           
=======================================
  Hits        32607    32607           
  Misses      25959    25959           
  Partials      107      107           
Flag Coverage Δ
packages 55.57% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 8, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 62.57 KB (0%) 1.3 s (0%) 475 ms (+42.41% 🔺) 1.8 s
thirdweb (cjs) 345.55 KB (0%) 7 s (0%) 2.4 s (+2.85% 🔺) 9.3 s
thirdweb (minimal + tree-shaking) 5.7 KB (0%) 114 ms (0%) 35 ms (+8.71% 🔺) 149 ms
thirdweb/chains (tree-shaking) 531 B (0%) 11 ms (0%) 18 ms (+44.79% 🔺) 28 ms
thirdweb/react (minimal + tree-shaking) 19.56 KB (0%) 392 ms (0%) 217 ms (+381.93% 🔺) 608 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants