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

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Nov 3, 2025

Summary by CodeRabbit

  • New Features

    • Partner groups now support domain-based link validation for programs.
    • A default limit for additional partner links (10) is enforced across imports and creation flows.
  • Refactor

    • URL validation options simplified and related defaults renamed for clarity.
  • Tests

    • Tests updated to align with the new default additional-links value.

@vercel
Copy link
Contributor

vercel bot commented Nov 3, 2025

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

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Nov 3, 2025 2:39am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 3, 2025

Walkthrough

Adds domain-derived additionalLinks and maxPartnerLinks to PartnerGroup create/upsert payloads across import and creation flows, renames a constant, introduces DEFAULT_ADDITIONAL_PARTNER_LINKS, and removes the PartnerUrlValidationMode enum from the Prisma schema.

Changes

Cohort / File(s) Summary
Partner group creation enrichment
apps/web/lib/actions/partners/create-program.ts, apps/web/lib/firstpromoter/import-campaigns.ts, apps/web/lib/rewardful/import-campaigns.ts, apps/web/lib/partnerstack/import-groups.ts
Import getDomainWithoutWWW and DEFAULT_ADDITIONAL_PARTNER_LINKS; add additionalLinks: [{ domain: getDomainWithoutWWW(program.url)!, validationMode: "domain" }] and maxPartnerLinks: DEFAULT_ADDITIONAL_PARTNER_LINKS to PartnerGroup create/upsert payloads.
Group links limits / constants
apps/web/lib/zod/schemas/groups.ts
Rename MAX_DEFAULT_PARTNER_LINKSMAX_DEFAULT_LINKS_PER_GROUP (value preserved) and add DEFAULT_ADDITIONAL_PARTNER_LINKS = 10.
Constant rename usage
apps/web/app/(ee)/api/cron/groups/remap-default-links/route.ts, apps/web/app/(ee)/api/groups/[groupIdOrSlug]/default-links/route.ts, apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/group-default-links.tsx
Replace usages of MAX_DEFAULT_PARTNER_LINKS with MAX_DEFAULT_LINKS_PER_GROUP.
Tests updated
apps/web/tests/partner-groups/index.test.ts
Update test to use DEFAULT_ADDITIONAL_PARTNER_LINKS instead of hard-coded value for expected maxPartnerLinks.
Prisma schema change
packages/prisma/schema/program.prisma
Remove the PartnerUrlValidationMode enum declaration.

Sequence Diagram(s)

sequenceDiagram
  participant Program
  participant Utils as getDomainWithoutWWW
  participant Service as Import/Create Flow
  participant DB as Prisma (PartnerGroup)

  Program->>Service: trigger create/upsert partner group (program.url, name, ...)
  Service->>Utils: getDomainWithoutWWW(program.url)
  Utils-->>Service: domain
  Service->>DB: create/upsert PartnerGroup { name, slug, ..., additionalLinks: [{domain, validationMode:"domain"}], maxPartnerLinks }
  DB-->>Service: created/updated group
  Service-->>Program: return result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review focus:
    • Verify consistent usage of getDomainWithoutWWW and handling of nullable program.url.
    • Confirm constants rename propagated correctly and localizations/messages updated.
    • Check removal of PartnerUrlValidationMode for leftover references or migration implications.

Possibly related PRs

Suggested reviewers

  • devkiran

Poem

🐰 I hop through domains to snip the "www",
Seed a link or two and set the cap at ten,
I tuck validation where it's meant to be,
Constants renamed, schemas trimmed with glee.
Hooray — enriched groups sprout for every program!

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "Enable additionalLinks by default" accurately reflects the primary change in the changeset. The core modification across multiple files (create-program.ts, import-campaigns.ts, import-groups.ts, rewardful/import-campaigns.ts, and the test file) is the addition of additionalLinks with a default value (DEFAULT_ADDITIONAL_PARTNER_LINKS set to 10) and maxPartnerLinks to partner group creation flows. The title is concise, specific, and clearly communicates the main objective from the developer's perspective without being overly verbose or vague. While the changeset includes secondary refactoring (constant renaming and enum removal), the title appropriately focuses on the primary feature addition.
✨ 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 fix-additional-links

📜 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 b254a8b and cc735a0.

📒 Files selected for processing (9)
  • apps/web/app/(ee)/api/cron/groups/remap-default-links/route.ts (2 hunks)
  • apps/web/app/(ee)/api/groups/[groupIdOrSlug]/default-links/route.ts (2 hunks)
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/group-default-links.tsx (3 hunks)
  • apps/web/lib/actions/partners/create-program.ts (2 hunks)
  • apps/web/lib/firstpromoter/import-campaigns.ts (2 hunks)
  • apps/web/lib/partnerstack/import-groups.ts (2 hunks)
  • apps/web/lib/rewardful/import-campaigns.ts (2 hunks)
  • apps/web/lib/zod/schemas/groups.ts (1 hunks)
  • apps/web/tests/partner-groups/index.test.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • apps/web/lib/rewardful/import-campaigns.ts
  • apps/web/lib/firstpromoter/import-campaigns.ts
  • apps/web/lib/partnerstack/import-groups.ts
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-06-06T07:59:03.120Z
Learnt from: devkiran
Repo: dubinc/dub PR: 2177
File: apps/web/lib/api/links/bulk-create-links.ts:66-84
Timestamp: 2025-06-06T07:59:03.120Z
Learning: In apps/web/lib/api/links/bulk-create-links.ts, the team accepts the risk of potential undefined results from links.find() operations when building invalidLinks arrays, because existing links are fetched from the database based on the input links, so matches are expected to always exist.

Applied to files:

  • apps/web/app/(ee)/api/groups/[groupIdOrSlug]/default-links/route.ts
  • apps/web/app/(ee)/api/cron/groups/remap-default-links/route.ts
  • apps/web/tests/partner-groups/index.test.ts
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/group-default-links.tsx
📚 Learning: 2025-08-14T05:00:23.224Z
Learnt from: devkiran
Repo: dubinc/dub PR: 2735
File: apps/web/app/api/og/program/route.tsx:63-64
Timestamp: 2025-08-14T05:00:23.224Z
Learning: In Dub's partner program system, the default partner group will always exist. When programs are created, a default partner group is automatically upserted using DEFAULT_PARTNER_GROUP constant, so accessing program.groups[0] in contexts where the default group is queried is safe.

Applied to files:

  • apps/web/app/(ee)/api/groups/[groupIdOrSlug]/default-links/route.ts
  • apps/web/lib/actions/partners/create-program.ts
📚 Learning: 2025-10-15T01:05:43.266Z
Learnt from: steven-tey
Repo: dubinc/dub PR: 2958
File: apps/web/app/app.dub.co/(dashboard)/[slug]/settings/members/page-client.tsx:432-457
Timestamp: 2025-10-15T01:05:43.266Z
Learning: In apps/web/app/app.dub.co/(dashboard)/[slug]/settings/members/page-client.tsx, defer refactoring the custom MenuItem component (lines 432-457) to use the shared dub/ui MenuItem component to a future PR, as requested by steven-tey.

Applied to files:

  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/group-default-links.tsx
📚 Learning: 2025-09-17T17:44:03.965Z
Learnt from: TWilson023
Repo: dubinc/dub PR: 2857
File: apps/web/lib/actions/partners/update-program.ts:96-0
Timestamp: 2025-09-17T17:44:03.965Z
Learning: In apps/web/lib/actions/partners/update-program.ts, the team prefers to keep the messagingEnabledAt update logic simple by allowing client-provided timestamps rather than implementing server-controlled timestamp logic to avoid added complexity.

Applied to files:

  • apps/web/lib/actions/partners/create-program.ts
🧬 Code graph analysis (5)
apps/web/app/(ee)/api/groups/[groupIdOrSlug]/default-links/route.ts (2)
apps/web/lib/zod/schemas/groups.ts (1)
  • MAX_DEFAULT_LINKS_PER_GROUP (22-22)
apps/web/lib/api/errors.ts (1)
  • DubApiError (75-92)
apps/web/app/(ee)/api/cron/groups/remap-default-links/route.ts (1)
apps/web/lib/zod/schemas/groups.ts (1)
  • MAX_DEFAULT_LINKS_PER_GROUP (22-22)
apps/web/tests/partner-groups/index.test.ts (1)
apps/web/lib/zod/schemas/groups.ts (1)
  • DEFAULT_ADDITIONAL_PARTNER_LINKS (25-25)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/group-default-links.tsx (1)
apps/web/lib/zod/schemas/groups.ts (1)
  • MAX_DEFAULT_LINKS_PER_GROUP (22-22)
apps/web/lib/actions/partners/create-program.ts (1)
apps/web/lib/zod/schemas/groups.ts (1)
  • DEFAULT_ADDITIONAL_PARTNER_LINKS (25-25)
⏰ 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 (5)
apps/web/app/(ee)/api/groups/[groupIdOrSlug]/default-links/route.ts (1)

11-11: LGTM! Clear and consistent constant rename.

The rename from MAX_DEFAULT_PARTNER_LINKS to MAX_DEFAULT_LINKS_PER_GROUP improves clarity and better describes the constant's purpose. All usages are updated correctly.

Also applies to: 93-96

apps/web/tests/partner-groups/index.test.ts (1)

7-10: LGTM! Excellent use of constant instead of magic number.

Replacing the hardcoded 10 with DEFAULT_ADDITIONAL_PARTNER_LINKS improves test maintainability and makes the intent clearer.

Also applies to: 26-26

apps/web/app/(ee)/api/cron/groups/remap-default-links/route.ts (1)

7-7: LGTM! Consistent constant usage.

The rename to MAX_DEFAULT_LINKS_PER_GROUP is applied correctly in both the import and the Prisma query take clause, maintaining consistency across the codebase.

Also applies to: 89-89

apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/links/group-default-links.tsx (1)

8-8: LGTM! UI properly reflects the renamed constant.

The constant rename is applied consistently throughout the component, including the user-facing tooltip message. The limit enforcement logic remains correct.

Also applies to: 31-31, 100-100

apps/web/lib/zod/schemas/groups.ts (1)

21-26: LGTM! Clear constant naming and well-documented intent.

The constant renaming and addition improve code clarity:

  • MAX_DEFAULT_LINKS_PER_GROUP (5) better describes the limit on auto-created default links per group
  • DEFAULT_ADDITIONAL_PARTNER_LINKS (10) provides a sensible default for the maxPartnerLinks setting
  • Comments clearly explain each constant's purpose

The separation between "default links" (auto-created) and "additional links" (custom partner links) is now more explicit.


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
Contributor

@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

♻️ Duplicate comments (3)
apps/web/lib/partnerstack/import-groups.ts (1)

58-64: Verify null handling for getDomainWithoutWWW.

The code assumes getDomainWithoutWWW(program.url) will never return null since program.url is verified earlier (lines 23-25). However, if the URL format is invalid, getDomainWithoutWWW might still return null, causing a type mismatch in the additionalLinks array.

This is the same concern as in create-program.ts. Please verify the function's behavior with malformed URLs.

apps/web/lib/rewardful/import-campaigns.ts (1)

66-72: Verify null handling for getDomainWithoutWWW.

Same concern as in other files: getDomainWithoutWWW(program.url) might return null if the URL format is invalid, even though program.url is validated for existence earlier (lines 28-30).

This is the same concern flagged in create-program.ts and partnerstack/import-groups.ts.

apps/web/lib/firstpromoter/import-campaigns.ts (1)

67-73: Verify null handling for getDomainWithoutWWW.

The non-null assertion on program.url! is safe due to the early return at line 27. However, getDomainWithoutWWW might still return null if the URL format is invalid, causing a potential type mismatch in the additionalLinks array.

This is the same concern flagged in the other files.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 662cba6 and b254a8b.

📒 Files selected for processing (5)
  • apps/web/lib/actions/partners/create-program.ts (2 hunks)
  • apps/web/lib/firstpromoter/import-campaigns.ts (2 hunks)
  • apps/web/lib/partnerstack/import-groups.ts (2 hunks)
  • apps/web/lib/rewardful/import-campaigns.ts (2 hunks)
  • packages/prisma/schema/program.prisma (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/prisma/schema/program.prisma
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: devkiran
Repo: dubinc/dub PR: 2735
File: apps/web/lib/actions/partners/delete-reward.ts:33-41
Timestamp: 2025-08-14T05:17:51.825Z
Learning: In the partner groups system, a rewardId can only belong to one group, establishing a one-to-one relationship between rewards and groups. This means using Prisma's `update` method (rather than `updateMany`) is appropriate when updating groups by rewardId.
Learnt from: devkiran
Repo: dubinc/dub PR: 2754
File: apps/web/lib/partnerstack/schemas.ts:47-52
Timestamp: 2025-08-16T11:14:00.667Z
Learning: The PartnerStack API always includes the `group` field in partner responses, so the schema should use `.nullable()` rather than `.nullish()` since the field is never omitted/undefined.
📚 Learning: 2025-06-06T07:59:03.120Z
Learnt from: devkiran
Repo: dubinc/dub PR: 2177
File: apps/web/lib/api/links/bulk-create-links.ts:66-84
Timestamp: 2025-06-06T07:59:03.120Z
Learning: In apps/web/lib/api/links/bulk-create-links.ts, the team accepts the risk of potential undefined results from links.find() operations when building invalidLinks arrays, because existing links are fetched from the database based on the input links, so matches are expected to always exist.

Applied to files:

  • apps/web/lib/partnerstack/import-groups.ts
  • apps/web/lib/actions/partners/create-program.ts
  • apps/web/lib/rewardful/import-campaigns.ts
📚 Learning: 2025-09-17T17:44:03.965Z
Learnt from: TWilson023
Repo: dubinc/dub PR: 2857
File: apps/web/lib/actions/partners/update-program.ts:96-0
Timestamp: 2025-09-17T17:44:03.965Z
Learning: In apps/web/lib/actions/partners/update-program.ts, the team prefers to keep the messagingEnabledAt update logic simple by allowing client-provided timestamps rather than implementing server-controlled timestamp logic to avoid added complexity.

Applied to files:

  • apps/web/lib/actions/partners/create-program.ts
📚 Learning: 2025-08-14T05:00:23.224Z
Learnt from: devkiran
Repo: dubinc/dub PR: 2735
File: apps/web/app/api/og/program/route.tsx:63-64
Timestamp: 2025-08-14T05:00:23.224Z
Learning: In Dub's partner program system, the default partner group will always exist. When programs are created, a default partner group is automatically upserted using DEFAULT_PARTNER_GROUP constant, so accessing program.groups[0] in contexts where the default group is queried is safe.

Applied to files:

  • apps/web/lib/actions/partners/create-program.ts
⏰ 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

@steven-tey
Copy link
Collaborator Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 3, 2025

✅ Actions performed

Full review triggered.

@steven-tey steven-tey merged commit 09f5f35 into main Nov 3, 2025
8 checks passed
@steven-tey steven-tey deleted the fix-additional-links branch November 3, 2025 02:45
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