feat(affiliate): require partnerCode at registration#12392
Conversation
Drop kebab-case support: regex is now /^[a-z0-9]{3,32}$/ in both the
affiliate-dashboard form and the public-api request schema. Extract
parsePartnerCode into lib/format alongside parseBps so RegisterCard
mirrors the BPS validation shape.
Also surface body.message in throwFromResponse so NestJS-style error
responses (e.g. "Partner code already taken") render instead of just
the error label ("Conflict").
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 15 minutes and 25 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughPartner-code claim was removed; partnerCode and bps are validated and submitted during registration. UI, hook, API schemas, and public API route exports were updated to reflect the single-step registration flow. ChangesPartner Code Registration Refactoring
🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/affiliate-dashboard/src/components/settings/RegisterCard.tsx (1)
48-67: ⚡ Quick winMemoize derived values and the click handler per project React guidelines.
handleClickis an event handler passed toButton(Line 75), andparsedBps/parsedCode/disabledare derived values recomputed every render.As per coding guidelines: "ALWAYS use `useCallback` for event handlers and functions passed as props" and "ALWAYS use `useMemo` for derived values and computed properties".♻️ Wrap with useMemo/useCallback
-import { useState } from 'react' +import { useCallback, useMemo, useState } from 'react'- const parsedBps = parseBps(bps) - const parsedCode = parsePartnerCode(partnerCode) - - const disabled = partnerCode === '' || bps === '' - - const handleClick = (): void => { + const parsedBps = useMemo(() => parseBps(bps), [bps]) + const parsedCode = useMemo(() => parsePartnerCode(partnerCode), [partnerCode]) + + const disabled = useMemo(() => partnerCode === '' || bps === '', [partnerCode, bps]) + + const handleClick = useCallback((): void => { if (parsedCode === null) { return onValidationError({ type: 'error', text: `Partner code must be 3–32 lowercase letters or numbers (e.g. mypartnercode)`, }) } if (parsedBps === null) { return onValidationError({ type: 'error', text: `Affiliate BPS must be a number between ${MIN_BPS} and ${MAX_BPS}`, }) } onRegister({ bps: parsedBps, partnerCode: parsedCode }) - } + }, [parsedCode, parsedBps, onRegister, onValidationError])🤖 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 `@packages/affiliate-dashboard/src/components/settings/RegisterCard.tsx` around lines 48 - 67, The derived values parsedBps, parsedCode and disabled should be memoized and the event handler handleClick should be wrapped in useCallback to avoid recreating them each render; wrap parsedBps = parseBps(bps) and parsedCode = parsePartnerCode(partnerCode) in useMemo (dependent on bps/partnerCode), compute disabled via useMemo (dependent on partnerCode and bps or the memoized parsed values), and wrap handleClick in useCallback (dependent on parsedBps, parsedCode, onValidationError, onRegister, MIN_BPS, MAX_BPS) before passing it to the Button to satisfy the project guidelines.
🤖 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 `@packages/public-api/src/routes/affiliate/types.ts`:
- Around line 40-46: Update UpdateAffiliateRequestSchema so its bps field
enforces the same upper bound as creation: add .max(1000) to the optional bps
validator (i.e., change the bps definition on UpdateAffiliateRequestSchema to
mirror CreateAffiliateRequestSchema). This ensures requests validated by
UpdateAffiliateRequestSchema (used via UpdateAffiliateRequestSchema.safeParse in
updateAffiliate.ts) cannot set bps > 1000 before forwarding upstream.
---
Nitpick comments:
In `@packages/affiliate-dashboard/src/components/settings/RegisterCard.tsx`:
- Around line 48-67: The derived values parsedBps, parsedCode and disabled
should be memoized and the event handler handleClick should be wrapped in
useCallback to avoid recreating them each render; wrap parsedBps = parseBps(bps)
and parsedCode = parsePartnerCode(partnerCode) in useMemo (dependent on
bps/partnerCode), compute disabled via useMemo (dependent on partnerCode and bps
or the memoized parsed values), and wrap handleClick in useCallback (dependent
on parsedBps, parsedCode, onValidationError, onRegister, MIN_BPS, MAX_BPS)
before passing it to the Button to satisfy the project guidelines.
🪄 Autofix (Beta)
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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1f08d719-fab9-45d3-8975-b18fe7fbea90
📒 Files selected for processing (10)
packages/affiliate-dashboard/src/components/settings/ClaimCodeCard.tsxpackages/affiliate-dashboard/src/components/settings/RegisterCard.tsxpackages/affiliate-dashboard/src/components/settings/SettingsTab.tsxpackages/affiliate-dashboard/src/hooks/useAffiliateActions.tspackages/affiliate-dashboard/src/lib/api.tspackages/affiliate-dashboard/src/lib/format.tspackages/public-api/src/index.tspackages/public-api/src/routes/affiliate/claimPartnerCode.tspackages/public-api/src/routes/affiliate/index.tspackages/public-api/src/routes/affiliate/types.ts
💤 Files with no reviewable changes (4)
- packages/public-api/src/routes/affiliate/claimPartnerCode.ts
- packages/public-api/src/routes/affiliate/index.ts
- packages/public-api/src/index.ts
- packages/affiliate-dashboard/src/components/settings/ClaimCodeCard.tsx
|
Actionable comments posted: 0 |
UpdateAffiliateRequestSchema was missing the .max(1000) constraint that CreateAffiliateRequestSchema enforces, letting PATCH bypass the cap. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Description
Unifies affiliate registration into a single
POST /v1/affiliatecall requiring bothpartnerCodeandbps, replacing the prior two-step flow (register → claim-code). The standalone claim-code route and its dashboard UI are removed.Validation tightened:
partnerCodeis now/^[a-z0-9]{3,32}$/— lowercase letters and digits only, 3–32 chars (no kebab-case, no uppercase). Enforced consistently across the dashboard form, public-api request schema, and swap-service DTO. Closes a prior bypass where swap-service accepted codes the dashboard rejected.Also: dashboard now surfaces NestJS-style
body.message(e.g. "Partner code already taken") instead of just the error label ("Conflict"). ExtractedparsePartnerCodeintolib/formatto mirrorparseBps.Issue (if applicable)
closes #
Risk
Low. No on-chain transactions, no wallet interactions, no state-management changes. Touches the affiliate-dashboard UI and the public-api affiliate routes only. The removed
claim-coderoute returns 404 going forward — partners using it would need to migrate to the unified register call (no known external consumers).Testing
Engineering
Partner Code+Affiliate BPS→ Register → confirm row appears in dashboard and config invalidates.ab(too short)Acme(uppercase)my-code(hyphen)my_code(underscore)my code(space)" acme "→ trimmed toacme, accepted.-1,1001, empty all rejected with the BPS error.POST /v1/affiliate/claim-codereturns 404 (route removed).Operations
Screenshots (if applicable)
Summary by CodeRabbit
New Features
Bug Fixes
Refactor