Skip to content

Improve partner invites / default link updates - #4291

Merged
steven-tey merged 2 commits into
mainfrom
api-fixes
Aug 7, 2026
Merged

Improve partner invites / default link updates#4291
steven-tey merged 2 commits into
mainfrom
api-fixes

Conversation

@steven-tey

@steven-tey steven-tey commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Partner profile invitations are limited to five attempts per hour.
    • Updating a default link can also update the associated program URL when applicable.
    • Updated link URLs now preserve configured UTM parameters.
  • Bug Fixes

    • Unchanged and duplicate default-link URLs receive clearer responses.
    • Missing links and domain changes are detected more accurately.
    • Invitation errors are surfaced correctly, while duplicate invitations retain their existing handling.

@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
dub Ready Ready Preview Aug 7, 2026 11:39pm

Request Review

@steven-tey

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review, any breaking changes?

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@steven-tey I will perform a full review of #4291. I will check for breaking changes in API contracts, data behavior, and existing invite and link flows.

✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7b78145c-9ca0-415b-8398-5b0f7e76a9a2

📥 Commits

Reviewing files that changed from the base of the PR and between 9856ca6 and 3307f68.

📒 Files selected for processing (1)
  • apps/web/app/(ee)/api/groups/[groupIdOrSlug]/default-links/[defaultLinkId]/route.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/app/(ee)/api/groups/[groupIdOrSlug]/default-links/[defaultLinkId]/route.ts

📝 Walkthrough

Walkthrough

The PR changes partner-group default-link updates and adds rate limiting and error propagation for partner-profile invitations.

Changes

Default-link updates

Layer / File(s) Summary
Transactional default-link PATCH
apps/web/app/(ee)/api/groups/[groupIdOrSlug]/default-links/[defaultLinkId]/route.ts
The PATCH handler identifies the default partner group, compares domains against the existing link, updates link and program URLs transactionally, applies UTM parameters, returns unchanged links directly, and reports duplicate destinations with a partner-specific conflict.

Partner invitation controls

Layer / File(s) Summary
Partner-profile invite guard
apps/web/app/(ee)/api/partner-profile/invites/route.ts, apps/web/lib/upstash/ratelimit-policies.ts, apps/web/lib/api/partners/invite-partner-user.ts
The policy limits partner-profile invitations to five attempts per hour per partner. The invite endpoint enforces the policy. The invitation helper maps duplicate records to conflicts and propagates other errors.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PATCHHandler
  participant DefaultLinkTransaction
  participant Program
  PATCHHandler->>DefaultLinkTransaction: update default-link URL and UTM parameters
  DefaultLinkTransaction->>Program: update program URL for the default partner group
  DefaultLinkTransaction-->>PATCHHandler: return updated link or duplicate-URL error
Loading

Possibly related PRs

  • dubinc/dub#3938: Changes cleanup behavior in the same default-link route.
  • dubinc/dub#4152: Changes another handler in the same default-link route.
  • dubinc/dub#4245: Introduces the dynamic UTM logic used by the default-link URL update.

Suggested reviewers: pepeladeira

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the two main changes: partner invite improvements and default link update behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch api-fixes

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/app/(ee)/api/groups/[groupIdOrSlug]/default-links/[defaultLinkId]/route.ts (1)

72-101: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Keep domain and URL changes in one transaction.

Lines 72-91 commit the domain change before the URL update at Lines 103-131. If the URL update fails with P2002, the route returns a conflict but leaves the program domain and all default-link domains changed. It also schedules queueDomainUpdate for that partial state.

Include the domain writes and URL writes in one transaction. Schedule queueDomainUpdate only after that transaction succeeds.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/web/app/`(ee)/api/groups/[groupIdOrSlug]/default-links/[defaultLinkId]/route.ts
around lines 72 - 101, Update the route’s transaction flow so the
program/default-link domain updates and the URL update operations are executed
together in a single prisma.$transaction, allowing URL conflicts to roll back
all changes. Move queueDomainUpdate out of the transaction and schedule it only
after the combined transaction completes successfully, preserving the existing
domain values passed to it.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@apps/web/app/`(ee)/api/groups/[groupIdOrSlug]/default-links/[defaultLinkId]/route.ts:
- Around line 161-162: Update the no-URL-change response in the default-link
route to return the persisted domain value when a domain-only update occurs.
Ensure the object passed to PartnerGroupDefaultLinkSchema.parse uses the updated
domain while preserving the existing defaultLink fields and response behavior
for requests with no changes.
- Around line 121-130: Update the transaction construction in the default-link
route to ensure the prisma.$transaction array contains only Prisma
queries/promises: conditionally include the program update for
DEFAULT_PARTNER_GROUP, or switch to an interactive transaction and call
tx.program.update only when the group matches. Preserve the existing update data
and skip it for other groups.

---

Outside diff comments:
In
`@apps/web/app/`(ee)/api/groups/[groupIdOrSlug]/default-links/[defaultLinkId]/route.ts:
- Around line 72-101: Update the route’s transaction flow so the
program/default-link domain updates and the URL update operations are executed
together in a single prisma.$transaction, allowing URL conflicts to roll back
all changes. Move queueDomainUpdate out of the transaction and schedule it only
after the combined transaction completes successfully, preserving the existing
domain values passed to it.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4c797763-bb00-4257-a0c4-a7b3b851e00f

📥 Commits

Reviewing files that changed from the base of the PR and between 3789004 and 9856ca6.

📒 Files selected for processing (4)
  • apps/web/app/(ee)/api/groups/[groupIdOrSlug]/default-links/[defaultLinkId]/route.ts
  • apps/web/app/(ee)/api/partner-profile/invites/route.ts
  • apps/web/lib/api/partners/invite-partner-user.ts
  • apps/web/lib/upstash/ratelimit-policies.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/app/(ee)/api/groups/[groupIdOrSlug]/default-links/[defaultLinkId]/route.ts (1)

72-131: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Make the full default-link PATCH atomic.

domain changes commit at Lines 73-88 before the URL update transaction starts at Lines 105-131. If the default-link URL update hits a P2002 conflict, the returned 409 leaves the program domain and default-link domains already changed. Move the domain and URL writes into one interactional Prisma transaction, and queue queueDomainUpdate and publish the QStash job only after it succeeds.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/web/app/`(ee)/api/groups/[groupIdOrSlug]/default-links/[defaultLinkId]/route.ts
around lines 72 - 131, Make the PATCH handler’s complete default-link update
atomic by moving the domain updates and URL/default-group program updates into a
single Prisma transaction. Ensure a URL uniqueness conflict rolls back every
write, and invoke queueDomainUpdate plus any QStash publishing only after the
transaction succeeds; update the surrounding PATCH flow rather than changing the
individual update payloads.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/lib/api/partners/invite-partner-user.ts`:
- Line 41: Update the route handler in route.ts that catches rejections from
invitePartnerUser to rethrow existing DubApiError instances unchanged,
preserving their codes, and convert unexpected errors into an appropriate 5xx
DubApiError response. Keep invitePartnerUser’s throw error behavior intact.

---

Outside diff comments:
In
`@apps/web/app/`(ee)/api/groups/[groupIdOrSlug]/default-links/[defaultLinkId]/route.ts:
- Around line 72-131: Make the PATCH handler’s complete default-link update
atomic by moving the domain updates and URL/default-group program updates into a
single Prisma transaction. Ensure a URL uniqueness conflict rolls back every
write, and invoke queueDomainUpdate plus any QStash publishing only after the
transaction succeeds; update the surrounding PATCH flow rather than changing the
individual update payloads.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 20682e11-c10e-490e-a492-6a394de8b09e

📥 Commits

Reviewing files that changed from the base of the PR and between 3789004 and 9856ca6.

📒 Files selected for processing (4)
  • apps/web/app/(ee)/api/groups/[groupIdOrSlug]/default-links/[defaultLinkId]/route.ts
  • apps/web/app/(ee)/api/partner-profile/invites/route.ts
  • apps/web/lib/api/partners/invite-partner-user.ts
  • apps/web/lib/upstash/ratelimit-policies.ts

Comment thread apps/web/lib/api/partners/invite-partner-user.ts
@steven-tey
steven-tey merged commit fa4bb09 into main Aug 7, 2026
12 checks passed
@steven-tey
steven-tey deleted the api-fixes branch August 7, 2026 23:52
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