-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add groupId and tenantId to trackClickResponseSchema #3241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds optional nullable Changes
Estimated code review effortπ― 3 (Moderate) | β±οΈ ~25 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touchesβ Failed checks (1 warning)
β Passed checks (2 passed)
β¨ Finishing touches
π§ͺ Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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
Caution
Some comments are outside the diff and canβt be posted inline due to platform limitations.
β οΈ Outside diff range comments (1)
apps/web/lib/planetscale/get-link-with-partner.ts (1)
10-22: Update the TypeScript interface to include the new fields.The
QueryResultinterface'spartnerproperty is missing the newly addedgroupIdandtenantIdfields, creating a type mismatch with the actual return value constructed at lines 94-95.Apply this diff to update the interface:
interface QueryResult extends EdgeLinkProps { partner?: { id: string; name: string; image: string | null; + groupId: string | null; + tenantId: string | null; } | null; discount?: { id: string; amount: number; type: "percentage" | "flat"; maxDuration: number | null; } | null; }
π Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
π Files selected for processing (3)
apps/web/app/(ee)/api/track/click/route.ts(1 hunks)apps/web/lib/planetscale/get-link-with-partner.ts(3 hunks)apps/web/tests/tracks/track-click.test.ts(1 hunks)
π§° Additional context used
π§ Learnings (3)
π Common learnings
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-08-14T05:57:35.546Z
Learnt from: devkiran
Repo: dubinc/dub PR: 2735
File: apps/web/lib/actions/partners/update-discount.ts:60-66
Timestamp: 2025-08-14T05:57:35.546Z
Learning: In the partner groups system, discounts should always belong to a group. The partnerGroup relation should never be null when updating discounts, so optional chaining on partnerGroup?.id may be unnecessary defensive programming.
Applied to files:
apps/web/lib/planetscale/get-link-with-partner.ts
π Learning: 2025-08-16T11:14:00.667Z
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.
Applied to files:
apps/web/app/(ee)/api/track/click/route.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
π Additional comments (2)
apps/web/lib/planetscale/get-link-with-partner.ts (2)
44-45: LGTM!The SQL query correctly fetches
groupIdandtenantIdfrom the already-joinedProgramEnrollmenttable.
70-96: LGTM!The destructuring correctly extracts the new fields from the query result, and they're properly included in the partner object construction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and canβt be posted inline due to platform limitations.
β οΈ Outside diff range comments (1)
apps/web/lib/planetscale/get-partner-enrollment-info.ts (1)
56-60: Remove deprecatedgroupfield for consistent return shape.The early return includes
group: null, but the success path (lines 63-81) only returnspartneranddiscount. This creates an inconsistent return type. Since callers no longer destructure agroupfield, remove it from the early return.Apply this diff:
if (!result) { return { partner: null, - group: null, discount: null, }; }
π Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
π Files selected for processing (5)
apps/web/lib/api/groups/get-groups.ts(1 hunks)apps/web/lib/api/links/create-link.ts(2 hunks)apps/web/lib/api/links/update-link.ts(2 hunks)apps/web/lib/planetscale/get-partner-enrollment-info.ts(3 hunks)apps/web/lib/types.ts(1 hunks)
π§° Additional context used
π§ Learnings (3)
π 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/api/links/update-link.tsapps/web/lib/api/links/create-link.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/api/links/update-link.ts
π Learning: 2025-08-14T05:57:35.546Z
Learnt from: devkiran
Repo: dubinc/dub PR: 2735
File: apps/web/lib/actions/partners/update-discount.ts:60-66
Timestamp: 2025-08-14T05:57:35.546Z
Learning: In the partner groups system, discounts should always belong to a group. The partnerGroup relation should never be null when updating discounts, so optional chaining on partnerGroup?.id may be unnecessary defensive programming.
Applied to files:
apps/web/lib/planetscale/get-partner-enrollment-info.ts
𧬠Code graph analysis (2)
apps/web/lib/api/links/update-link.ts (1)
apps/web/lib/planetscale/get-partner-enrollment-info.ts (1)
getPartnerEnrollmentInfo(18-82)
apps/web/lib/api/links/create-link.ts (1)
apps/web/lib/planetscale/get-partner-enrollment-info.ts (1)
getPartnerEnrollmentInfo(18-82)
β° 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 (9)
apps/web/lib/api/links/update-link.ts (2)
173-176: LGTM! Destructuring aligns with updated return shape.The removal of
groupfrom the destructuring is correct, asgetPartnerEnrollmentInfonow returnsgroupIdandtenantIdwithin thepartnerobject instead of as a separategroupfield.
189-191: LGTM! Conditional programEnrollment logic is correct.The conditional spread correctly derives
programEnrollment.groupIdfrompartner.groupIdwhen present, replacing the previous approach that used a separategroupvalue.apps/web/lib/api/links/create-link.ts (2)
144-147: LGTM! Consistent with the updated return shape.The destructuring correctly extracts only
partneranddiscount, matching the changes inupdate-link.tsand the updatedgetPartnerEnrollmentInfosignature.
160-162: LGTM! Conditional logic matches update-link flow.The conditional spread correctly derives
programEnrollment.groupIdfrompartner.groupId, consistent with the implementation inupdate-link.ts.apps/web/lib/types.ts (1)
191-194: LGTM! Type extension correctly reflects the updated partner structure.The addition of optional
groupIdandtenantIdfields toRedisLinkProps.partneraligns with the partner object shape returned bygetPartnerEnrollmentInfoand enables caching of program enrollment context.apps/web/lib/planetscale/get-partner-enrollment-info.ts (3)
14-14: LGTM! Interface extension is correct.The addition of
tenantIdto theQueryResultinterface correctly reflects the SQL query results and matches the nullable type of the database field.
43-44: LGTM! SQL query correctly selects the new fields.The query appropriately selects
groupIdandtenantIdfrom theProgramEnrollmenttable, which will be included in the returned partner object.
68-69: LGTM! Partner object correctly includes new fields.The addition of
groupIdandtenantIdto the returned partner object aligns with the type changes inRedisLinkPropsand enables callers to access program enrollment context through the partner object.apps/web/lib/api/groups/get-groups.ts (1)
77-77: The SQL injection risk is properly mitigated by Zod schema validation.The
getGroupsQuerySchemavalidates bothsortByandsortOrderusing strict enums:
sortByis limited to a whitelist of aggregate columns: createdAt, totalPartners, totalClicks, totalLeads, totalSales, totalSaleAmount, totalConversions, totalCommissionssortOrderis limited to "asc" or "desc"This enum validation prevents SQL injection. The table prefix logic is also correctβonly "createdAt" receives the "pg." prefix because other sortBy values are computed aliases, not table columns. No action required.
Likely an incorrect or invalid review comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
π§Ή Nitpick comments (1)
apps/web/lib/api/links/utils/transform-link.ts (1)
16-21: Type definition is correct; consider simplifying if undefined vs null distinction is unnecessary.The type uses both optional (
?:) and nullable (| null), allowing three states: undefined, null, or string. This is valid TypeScript, but if the distinction between "not set" (undefined) and "explicitly null" isn't needed, you could simplify to justgroupId?: stringorgroupId: string | null.Looking at the usage in
format-redis-link.ts, the truthy check treats both undefined and null identically, so the extra optionality might not be necessary. However, if API contracts or future logic need to distinguish these states, the current typing is appropriate.
π Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
π Files selected for processing (2)
apps/web/lib/api/links/utils/transform-link.ts(1 hunks)apps/web/lib/upstash/format-redis-link.ts(1 hunks)
π§° Additional context used
π§ Learnings (2)
π Common learnings
Learnt from: devkiran
Repo: dubinc/dub PR: 2735
File: apps/web/lib/actions/partners/update-discount.ts:60-66
Timestamp: 2025-08-14T05:57:35.546Z
Learning: In the partner groups system, discounts should always belong to a group. The partnerGroup relation should never be null when updating discounts, so optional chaining on partnerGroup?.id may be unnecessary defensive programming.
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-08-14T05:57:35.546Z
Learnt from: devkiran
Repo: dubinc/dub PR: 2735
File: apps/web/lib/actions/partners/update-discount.ts:60-66
Timestamp: 2025-08-14T05:57:35.546Z
Learning: In the partner groups system, discounts should always belong to a group. The partnerGroup relation should never be null when updating discounts, so optional chaining on partnerGroup?.id may be unnecessary defensive programming.
Applied to files:
apps/web/lib/upstash/format-redis-link.ts
𧬠Code graph analysis (1)
apps/web/lib/api/links/utils/transform-link.ts (1)
apps/web/lib/types.ts (1)
PartnerProps(457-460)
β° 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 (1)
apps/web/lib/upstash/format-redis-link.ts (1)
59-60: LGTM! Conditional inclusion follows existing patterns.The conditional spread pattern correctly adds
groupIdandtenantIdto the partner object when they have truthy values, consistent with the existing code style in this file. Filtering out null/undefined values is appropriate for Redis storage.
Summary by CodeRabbit
New Features
Behavior Changes
Tests
βοΈ Tip: You can customize this high-level summary in your review settings.