Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Oct 28, 2025

Summary by CodeRabbit

  • Refactor
    • Simplified workspace ID handling across multiple API endpoints and internal functions. Workspace identifiers in responses and error messages are now presented in their raw form instead of with prefix transformation.
    • Removed legacy database migration script.

@vercel
Copy link
Contributor

vercel bot commented Oct 28, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Oct 28, 2025 7:43pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 28, 2025

Walkthrough

The PR systematically removes prefixWorkspaceId utility usage across the codebase, replacing prefixed workspace ID transformations with raw IDs. Affected areas include API endpoints, error messages, data transformations, and a migration script. One migration script file is deleted entirely.

Changes

Cohort / File(s) Summary
API Routes – Workspace ID Responses
apps/web/app/(ee)/api/admin/impersonate/route.ts, apps/web/app/api/workspaces/route.ts, apps/web/app/api/workspaces/[idOrSlug]/route.ts
Removed prefixWorkspaceId usage from workspace response payloads; now return raw id fields directly
API Routes – Error Messages
apps/web/app/api/analytics/route.ts, apps/web/app/api/callback/plain/workspace/route.ts, apps/web/app/api/oauth/userinfo/route.ts
Updated error and status messages to use raw workspace.id instead of prefixed variant
Library API Utilities – Workspace ID
apps/web/lib/api/domains/get-domain-or-throw.ts, apps/web/lib/api/links/get-link-or-throw.ts, apps/web/lib/api/tokens/permissions.ts
Removed prefixWorkspaceId from error message interpolations; now use raw workspaceId directly
Link Transformation & Analytics
apps/web/lib/api/links/utils/transform-link.ts, apps/web/lib/tinybird/record-link.ts
Updated workspaceId and workspace_id assignments to use raw project/workspace IDs without prefixing
Edge Config & UI Utilities
apps/web/lib/edge-config/get-feature-flags.ts, apps/web/lib/swr/use-domains.ts
Removed prefixWorkspaceId transformations and import; now compare and use raw workspace IDs
Migration Script Removal
apps/web/scripts/migrations/backfill-referral-links.ts
Deleted migration script that created referral links using prefixed workspace IDs

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Multiple modules affected: Changes span API routes, lib utilities, data transformations, and scripts, requiring review across different functional domains
  • Homogeneous pattern: While the refactoring follows a consistent approach (removing prefixing), each file context must be verified to ensure downstream code handles raw IDs correctly
  • Breaking change potential: Workspace ID format changes in API responses and error messages; confirm no client-side code depends on the prefixed format
  • Specific areas for attention:
    • API response payloads (workspaces/route.ts, workspaces/[idOrSlug]/route.ts) – verify client expectations for ID format
    • Tinybird analytics schema change (record-link.ts) – ensure analytics pipeline handles unprefixed workspace IDs
    • Migration script deletion (backfill-referral-links.ts) – confirm no ongoing dependencies exist

Possibly related PRs

Suggested reviewers

  • devkiran
  • TWilson023

Poem

🐰 Hop, hop—goodbye prefixes long,
Raw IDs now dance all day strong,
Workspace IDs flow unadorned and free,
Simpler, cleaner—as IDs should be!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Remove prefixWorkspaceId" directly and accurately describes the primary objective of the changeset. Across all twelve modified files, the pull request systematically removes the prefixWorkspaceId import and eliminates its usage throughout the codebase, including API routes, library utilities, and a migration script. The title is concise, specific, and immediately conveys the core change without vague language or unnecessary details. A teammate scanning the repository history would clearly understand that this PR removes a utility function used for workspace ID transformation.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch remove-workspaceid-prefix

📜 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 69de8fd and 7abc1d3.

📒 Files selected for processing (14)
  • apps/web/app/(ee)/api/admin/impersonate/route.ts (0 hunks)
  • apps/web/app/api/analytics/route.ts (1 hunks)
  • apps/web/app/api/callback/plain/workspace/route.ts (1 hunks)
  • apps/web/app/api/oauth/userinfo/route.ts (1 hunks)
  • apps/web/app/api/workspaces/[idOrSlug]/route.ts (0 hunks)
  • apps/web/app/api/workspaces/route.ts (2 hunks)
  • apps/web/lib/api/domains/get-domain-or-throw.ts (1 hunks)
  • apps/web/lib/api/links/get-link-or-throw.ts (1 hunks)
  • apps/web/lib/api/links/utils/transform-link.ts (1 hunks)
  • apps/web/lib/api/tokens/permissions.ts (1 hunks)
  • apps/web/lib/edge-config/get-feature-flags.ts (0 hunks)
  • apps/web/lib/swr/use-domains.ts (1 hunks)
  • apps/web/lib/tinybird/record-link.ts (1 hunks)
  • apps/web/scripts/migrations/backfill-referral-links.ts (0 hunks)
💤 Files with no reviewable changes (4)
  • apps/web/app/api/workspaces/[idOrSlug]/route.ts
  • apps/web/app/(ee)/api/admin/impersonate/route.ts
  • apps/web/lib/edge-config/get-feature-flags.ts
  • apps/web/scripts/migrations/backfill-referral-links.ts
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-26T15:05:55.081Z
Learnt from: TWilson023
PR: dubinc/dub#2736
File: apps/web/lib/swr/use-bounty.ts:11-16
Timestamp: 2025-08-26T15:05:55.081Z
Learning: In the Dub codebase, workspace authentication and route structures prevent endless loading states when workspaceId or similar route parameters are missing, so gating SWR loading states on parameter availability is often unnecessary.

Applied to files:

  • apps/web/lib/swr/use-domains.ts
🧬 Code graph analysis (3)
apps/web/app/api/workspaces/route.ts (1)
apps/web/lib/zod/schemas/workspaces.ts (1)
  • WorkspaceSchema (15-134)
apps/web/lib/api/domains/get-domain-or-throw.ts (1)
apps/web/lib/api/errors.ts (1)
  • DubApiError (75-92)
apps/web/lib/swr/use-domains.ts (1)
packages/utils/src/constants/dub-domains.ts (1)
  • DUB_DOMAINS (3-152)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (11)
apps/web/lib/api/links/get-link-or-throw.ts (1)

95-95: LGTM!

The error message now uses the raw workspace ID, which aligns with the broader refactor to remove workspace ID prefixing across the codebase.

apps/web/lib/api/tokens/permissions.ts (1)

31-31: LGTM!

The error message now displays raw workspace IDs, consistent with the PR's goal to remove workspace ID prefixing.

apps/web/app/api/analytics/route.ts (1)

59-59: LGTM!

The error message now uses the raw workspace ID directly, aligning with the removal of workspace ID prefixing.

apps/web/lib/api/domains/get-domain-or-throw.ts (1)

40-46: LGTM!

Both error messages now use raw workspace IDs, eliminating the prefixing transformation in domain validation errors.

apps/web/lib/swr/use-domains.ts (1)

67-74: LGTM!

The conditional checks now compare raw workspace IDs directly, which is consistent with the removal of workspace ID prefixing throughout the codebase. This change assumes that the workspaceId value now contains the raw ID rather than a prefixed version.

apps/web/app/api/oauth/userinfo/route.ts (1)

62-62: Verify external OAuth consumers handle unprefixed workspace IDs and confirm migration strategy.

The verification script found that external OAuth consumers do exist (e.g., Stripe app). The concern about workspace ID format changes is valid. However, I need to examine the actual endpoint implementation and any migration/versioning strategy to complete the verification.The web search provides general OAuth userinfo patterns but not Dub-specific implementation details. Based on the evidence from the shell script output and analysis, I can now provide a reasoned response.

Verify that OAuth consumers can handle the unprefixed workspace ID format change and confirm migration support.

From the verification, I found:

  1. Existing OAuth Consumer: The codebase contains an internal OAuth consumer (packages/stripe-app/src/utils/oauth.ts line 71) that calls /api/oauth/userinfo

  2. Workspace ID Format Functions:

    • prefixWorkspaceId is used only in audit logs (audit log context, not general OAuth)
    • normalizeWorkspaceId is used more broadly for workspace ID handling
    • No evidence of prefixed workspace IDs being a standard OAuth response format in the codebase
  3. No Versioning Evidence: The shell output shows no API versioning or deprecation warnings for the OAuth endpoint

  4. Risk Assessment: Without seeing the actual API response schema or consumer SDK code, I cannot confirm:

    • Whether external OAuth applications depend on the prefixed format
    • Whether this change includes a deprecation period or migration path
    • Whether the API documentation has been updated
apps/web/lib/api/links/utils/transform-link.ts (1)

49-49: Since the initial script output and web searches don't provide definitive visibility into the actual code change, I need to examine the repository directly:Based on the evidence gathered, particularly from the webhook documentation which shows workspaceId with the "ws_" prefix format (e.g., "ws_cm022sis60003ikt1syy7kfhl"), combined with the codebase references showing that workspace IDs are expected to be formatted as "ws_xxx", the review comment's concern about a breaking change is valid.

However, without direct access to the file's previous state and confirmation that link.projectId contains the unprefixed ID, I cannot definitively verify whether this specific change at line 49 breaks API contracts.

Verify that API consumers can handle unprefixed workspaceId.

The concern is valid: webhook event documentation shows workspaceId consistently returns the prefixed format (e.g., "ws_cm022sis60003ikt1syy7kfhl"). If the change now returns link.projectId directly without the ws_ prefix, this would be a breaking change for:

  • Webhook consumers expecting prefixed format
  • SDK clients that parse or validate workspaceId format
  • API integrations relying on the standardized prefix for identification

Ensure that:

  1. Webhook events are also updated if they expose this field
  2. API documentation is updated to clarify the format change
  3. SDK code is tested against both prefixed and unprefixed values, or updated to handle the new format
apps/web/app/api/callback/plain/workspace/route.ts (1)

162-162: Remove the review comment — workspace ID is display-only and not sent to Plain API.

The workspace ID is only rendered in the Plain dashboard UI via plainCopySection(), which creates a text display with a copy button. The Plain API methods (upsertCustomer, getCustomerByEmail, addCustomerToCustomerGroups, updateCompanyTier) never receive the workspace ID as a parameter. They use externalId, email, customerId, companyDomainName, and plan tier identifiers instead. The change from prefixWorkspaceId(id) to id is cosmetic and has no impact on Plain integration compatibility.

Likely an incorrect or invalid review comment.

apps/web/app/api/workspaces/route.ts (2)

171-171: LGTM: Consistent response shape.

The POST handler now returns the same unprefixed workspace ID format as the GET handler, improving API consistency.


51-53: No breaking change detected—database stores prefixed workspace IDs.

The change removes the explicit prefixWorkspaceId() call, but analysis shows this is not a breaking change. The codebase generates workspace IDs with the ws_ prefix (via createWorkspaceId()), and these prefixed IDs are stored directly in the database. The prefixWorkspaceId() function only adds the prefix if not already present, so both the old and new code return identical results when the database contains prefixed IDs (e.g., ws_clrei1gld0002vs9mzn93p8ik).

The change simplifies the response path without altering the actual data returned to API consumers.

apps/web/lib/tinybird/record-link.ts (1)

42-51: No data consistency issue exists—the normalization layer already handles both prefixed and unprefixed workspace IDs.

The removal of prefixWorkspaceId was intentional (confirmed by git history: "Remove prefixWorkspaceId for new Tinybird links metadata"). The dub_links_metadata_pipe.pipe contains existing normalization logic that strips the "ws_" prefix from all data, regardless of whether it arrives with or without a prefix:

CASE WHEN startsWith(workspace_id, 'ws_c')
THEN replace(workspace_id, 'ws_', '')
ELSE workspace_id
END

All Tinybird queries (v3_timeseries, v3_count, v3_group_by, etc.) operate through pipes that apply this normalization, so both old prefixed and new unprefixed data are processed consistently. Backfill scripts confirm this pattern is intentional—they all ingest unprefixed workspace IDs directly. No query layer bypasses this normalization.

Likely an incorrect or invalid review comment.


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.

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.

2 participants