feat: --ref affiliate referral code on install and login#279
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds an optional ChangesAffiliate ref propagation through CLI login flow
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
|
Paired backend PR: activeloopai/deeplake-api#272 (parks the code and records the signup). |
Coverage ReportScope: files changed in this PR. Enforced threshold: 90% per metric (per file via
File Coverage — 3 files changed
Generated for commit 5dde712. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@src/cli/index.ts`:
- Around line 198-205: The parseRef function currently accepts any argument
following the `--ref` flag as a referral code, including other flags. When using
the `--ref` format without an equals sign, add a validation check to ensure the
next argument does not start with `--` before assigning it to the raw variable,
since an argument starting with `--` is another flag and should not be treated
as a referral code value. If the next argument is a flag, return undefined
instead.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 4094be62-d871-4f04-a7bc-f576cf0d3459
📒 Files selected for processing (5)
src/cli/auth.tssrc/cli/index.tssrc/commands/auth.tstests/cli/affiliate-ref.test.tstests/cli/cli-auth.test.ts
khustup2
left a comment
There was a problem hiding this comment.
Approved. Clean CLI-only change; X-Hivemind-Referrer contract matches the backend (deeplake-api #272, now merged). parseRef correctly rejects a following flag as the code (--ref --skip-auth → undefined), and header trim/omit is right. CI green. Inert until backend ships and affiliate_codes are populated.
What
Adds a
--ref <code>flag tohivemind installandhivemind loginthatcarries an affiliate/influencer campaign code so a new signup can be
attributed to the referrer.
The code only matters for a genuinely new registration; the backend ignores it
for already-registered users.
Changes
src/cli/index.ts—parseRef()(mirrorsparseToken), threads the codeinto the install and login paths, documents the flag in
USAGE.src/cli/auth.ts—ensureLoggedIn(ref)passes it tologin.src/commands/auth.ts— sends it as theX-Hivemind-Referrerheader onPOST /auth/device/code(same pattern asX-Hivemind-Install-Id). Trimmedhere; the backend lowercases + validates against its affiliate registry.
The header is omitted entirely when no
--refis given.Tests
tests/cli/affiliate-ref.test.ts— header construction (trim / omit) and thatrequestDeviceCodeputsX-Hivemind-Referreron the wire only when a ref isgiven.
tests/cli/cli-auth.test.ts— asserts the ref threads through tologin().tsc,npm run build, and theclisuite stay green.Pairs with
The deeplake-api PR that parks the code at
/auth/device/codeand records thesignup attribution. The flag is inert until that backend ships and codes exist.
Summary by CodeRabbit
New Features
--ref <code>flag for authentication commands (e.g.,hivemind install --ref <code>andhivemind login --ref <code>), applying the code during the login flow.Tests
--refparsing/forwarding and that the referral header is sent (or omitted) correctly during device-code authorization.