Fix affiliate tracking URL origin - #136
Conversation
Greptile SummaryThis PR extracts affiliate tracking URL construction into a shared
Confidence Score: 3/5Safe to merge for non-production environments, but the apply endpoint now returns a different tracking_url shape that no test documents and no client migration was noted. The helper extraction is clean and the two routes with updated tests behave correctly. The concern is apply/route.ts: it previously returned a shareable /ref/{code} short link as tracking_url, and now returns the raw /api/affiliates/click?ugig_ref={code} endpoint. Any affiliate dashboard or API consumer that stores and displays that URL will silently receive a less readable URL, and there is no test for this endpoint to assert the new format. src/app/api/affiliates/offers/[id]/apply/route.ts — the tracking_url format changed without a corresponding test; confirm whether /ref/{code} or /api/affiliates/click?ugig_ref={code} is the intended shareable link for affiliates. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant ApplyRoute as POST /offers/[id]/apply
participant AffiliatesRoute as GET /offers/[id]/affiliates
participant RefRoute as GET /ref/[code]
participant ClickRoute as GET /api/affiliates/click
participant Helper as tracking-url.ts
Client->>ApplyRoute: POST apply
ApplyRoute->>Helper: getAffiliateBaseUrl(request.url)
Helper-->>ApplyRoute: "NEXT_PUBLIC_APP_URL || request origin"
ApplyRoute->>Helper: buildAffiliateTrackingUrl(baseUrl, code)
Helper-->>ApplyRoute: "baseUrl/api/affiliates/click?ugig_ref=code"
ApplyRoute-->>Client: "{ tracking_url: .../api/affiliates/click?ugig_ref=... }"
Client->>AffiliatesRoute: GET affiliates list
AffiliatesRoute->>Helper: getAffiliateBaseUrl(request.url)
AffiliatesRoute->>Helper: buildAffiliateTrackingUrl(baseUrl, code)
Helper-->>AffiliatesRoute: "baseUrl/api/affiliates/click?ugig_ref=code"
AffiliatesRoute-->>Client: "[{ tracking_url: .../api/affiliates/click?ugig_ref=... }]"
Client->>RefRoute: GET /ref/[code]
RefRoute->>Helper: getAffiliateBaseUrl(request.url)
RefRoute->>Helper: buildAffiliateTrackingUrl(baseUrl, code)
Helper-->>RefRoute: "baseUrl/api/affiliates/click?ugig_ref=code"
RefRoute-->>Client: "307 Redirect to /api/affiliates/click?ugig_ref=code"
Client->>ClickRoute: "GET /api/affiliates/click?ugig_ref=code"
Reviews (1): Last reviewed commit: "Fix affiliate short-link origin" | Re-trigger Greptile |
| return NextResponse.json({ | ||
| application, | ||
| tracking_code: trackingCode, | ||
| tracking_url: `${process.env.NEXT_PUBLIC_APP_URL || "https://ugig.net"}/ref/${trackingCode}`, | ||
| tracking_url: buildAffiliateTrackingUrl(getAffiliateBaseUrl(request.url), trackingCode), | ||
| }, { status: 201 }); |
There was a problem hiding this comment.
tracking_url format changed from short /ref/ link to raw click endpoint
The old response returned …/ref/{trackingCode} — the purpose-built short link that affiliates share with customers. This PR changes it to …/api/affiliates/click?ugig_ref={trackingCode}, which is the internal click-tracking handler that /ref/[code] redirects to. Any client or affiliate dashboard that stores or displays the tracking_url from the apply response will now see and distribute the raw API URL instead of the clean shareable link. Both resolve to the same destination, but this is a breaking change to the response contract that isn't covered by a test for apply/route.ts.
Summary
NEXT_PUBLIC_APP_URLor the current request origin instead of hardcoding production linksFixes #135
Validation
pnpm test:run src/lib/affiliates/tracking-url.test.ts 'src/app/api/affiliates/offers/[id]/affiliates/route.test.ts'pnpm exec eslint src/lib/affiliates/tracking-url.ts src/lib/affiliates/tracking-url.test.ts 'src/app/api/affiliates/offers/[id]/affiliates/route.ts' 'src/app/api/affiliates/offers/[id]/affiliates/route.test.ts' 'src/app/api/affiliates/offers/[id]/apply/route.ts'pnpm type-checkgit diff --checkBounty / payment
Submitted for the active uGig affiliate-program testing task. SOL receive address:
27sdMYXofqoM9qR13bZhccRNYeEgYn5EoHXTSJn4QWKP.Payment fallback: PayPal cultofrozen@gmail.com