feat: template referral system#778
Open
selenaalpha77-sketch wants to merge 1 commit intoMerit-Systems:masterfrom
Open
feat: template referral system#778selenaalpha77-sketch wants to merge 1 commit intoMerit-Systems:masterfrom
selenaalpha77-sketch wants to merge 1 commit intoMerit-Systems:masterfrom
Conversation
When a user scaffolds an app from an external GitHub template via echo-start, automatically register the template creator as a referrer on the new app. Changes: - echo-start: reads echo.config.json from the cloned template, sanitizes and validates the referralCode field, calls the Echo API to register the template creator as referrer, then removes echo.config.json from the project - New API endpoint POST /api/v1/apps/template-referral: registers a referral code as the template referrer for an app (no auth required, idempotent, first-come-first-served per app) - Prisma schema: adds templateReferrerCodeId to EchoApp and the inverse templateReferredApps relation on ReferralCode - Migration: ALTER TABLE echo_apps to add templateReferrerCodeId column - Docs: documents the template referral feature in referrals.mdx Template creators add echo.config.json to their repo with their referral code. echo-start handles the rest automatically, non-blocking — failures are silent. Closes Merit-Systems#612
Contributor
|
@selenaalpha77-sketch is attempting to deploy a commit to the Merit Systems Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Comment on lines
+75
to
+79
| await db.echoApp.update({ | ||
| where: { id: echoAppId }, | ||
| data: { templateReferrerCodeId: code.id }, | ||
| }); | ||
|
|
Contributor
There was a problem hiding this comment.
Suggested change
| await db.echoApp.update({ | |
| where: { id: echoAppId }, | |
| data: { templateReferrerCodeId: code.id }, | |
| }); | |
| // Use updateMany with a conditional where clause to make this atomic. | |
| // This prevents race conditions where two concurrent requests could both | |
| // pass the check above and race to update the app. | |
| const result = await db.echoApp.updateMany({ | |
| where: { id: echoAppId, templateReferrerCodeId: null }, | |
| data: { templateReferrerCodeId: code.id }, | |
| }); | |
| // If count is 0, another request already registered a referrer | |
| if (result.count === 0) { | |
| return NextResponse.json({ | |
| success: true, | |
| message: 'Template referrer already registered', | |
| }); | |
| } | |
Race condition in template referral registration allows second concurrent request to overwrite first, violating "first-come-first-served" semantics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the template referral system requested in #612.
When a user scaffolds an app from an external GitHub template via
echo-start, the template creator is automatically registered as a referrer on the new app.What changed
echo-startCLIecho.config.jsonfrom the cloned template directoryreferralCodefieldPOST /api/v1/apps/template-referralto register the template creator as referrerecho.config.jsonfrom the scaffolded project (template metadata, not app code)New API endpoint:
POST /api/v1/apps/template-referraltemplateReferrerCodeIdon the app (idempotent, first-come-first-served)Prisma schema + migration
templateReferrerCodeIdtoEchoAppDocs
How it works
echo.config.jsonto their repo with their referral codenpx echo-start --template https://github.com/creator/template --app-id <id>echo-startreads the code, calls the Echo API, registers the creator as referrerecho.config.jsonis deleted from the new project/claim #612