Extract /v1/attribution/* into its own api slice#115
Merged
Conversation
The three SDK-authenticated attribution endpoints — click, install,
identify — were living in `api/links/routes.rs` because they touch
data on `LinksRepository`. But the URL surface (`/v1/attribution/*`)
and the auth gate (`pk_live_` SDK keys, not `rl_live_` secret keys)
make them logically distinct. Burying them under links makes
`api/links/routes.rs` less focused and less greppable.
Transport-only split: the data domain stays unified — Attribution
documents and the related DTOs live in `services/links/models.rs`
alongside the Link document. The new `api/attribution/` slice imports
those DTOs and reuses three helpers from `api/links/routes.rs` made
`pub(crate)`: `check_link_resolvable` (shared link-status gate),
`detect_platform`, and `Platform` (UA-based platform detection).
Duplicating either would risk policy drift between resolve and
attribution paths.
Removes the `sdk` route group from `api/links/mod.rs` and registers
`api/attribution::router` from `api/mod.rs`. OpenAPI registration
moves the three attribution paths under the new module path; schema
names are unchanged so the spec output is byte-identical.
`get_link_timeseries` stays in `api/links/routes.rs` — link-scoped
analytics under `/v1/links/{link_id}/timeseries`, not an SDK
attribution path.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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
The three SDK-authenticated attribution endpoints —
click,install,identify— were living inapi/links/routes.rsbecause they touch data onLinksRepository. But the URL surface (/v1/attribution/*) and the auth gate (pk_live_SDK keys, notrl_live_secret keys) make them logically distinct. Burying them under links madeapi/links/routes.rsless focused.This is a transport-only split — the data domain stays unified.
What moved
api/links/routes.rs::attribution_clickapi/attribution/routes.rs::attribution_clickapi/links/routes.rs::attribution_reportapi/attribution/routes.rs::attribution_reportapi/links/routes.rs::link_attributionapi/attribution/routes.rs::link_attributionapi/links/mod.rs::sdkroute groupapi/attribution/mod.rs::routerWhat stayed
Attributiondocument,AttributionReportRequest,ClickRequest,LinkAttributionRequest,AttributionResponseall stay inservices/links/models.rsnext to theLinkdocument. The new slice imports them.get_link_timeseriesstays inapi/links/routes.rs— it's link-scoped analytics under/v1/links/{link_id}/timeseries, not an SDK attribution path.Helpers reused via
pub(crate)Three helpers in
api/links/routes.rsare used by both link resolve flow and the new attribution slice. Made thempub(crate)rather than duplicating:check_link_resolvable(link)— link-status / expiry gatePlatformenumdetect_platform(user_agent)— UA-based detectionDuplicating either would risk policy drift between the resolve path and the attribution path.
pub(crate)keeps them as the single source of truth without leaking outside the crate.OpenAPI
The three attribution paths now register under
attribution::routes::*instead oflinks::routes::*. Schema names are unchanged, so the generated OpenAPI document is byte-identical.Test plan
cargo fmt -- --checkcargo clippy --all-targets -- -D warningscargo test— 107 lib + 145 integration tests pass🤖 Generated with Claude Code