Add POST /v1/links/bulk for atomic bulk link creation#112
Merged
Conversation
Lets customers mint up to 100 links from a shared template in one call, either with caller-supplied vanity slugs or auto-generated IDs. Gated on a verified custom domain (the intended use case is campaign codes / affiliate slugs under a customer's own domain) so bulk-created links also skip the 30-day expiry that applies to free-tier links. All-or-nothing via a Mongo transaction: a race that takes one of our chosen ids rolls back the whole batch and surfaces every conflict in one response so the caller can fix and retry in one pass. Quota is pre-checked once via a new QuotaChecker::check_n so a batch is one decision rather than failing partway through. Exposed as the create_links MCP tool too — service-layer choke point keeps both transports going through the same validation, quota, and transaction 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.
|
Every CreateLinkInput field is already pub Option<T>, so the if-let chain was unwrapping just to re-wrap through builder methods that take T. The struct literal is the same code without the round trip. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
POST /v1/links/bulkendpoint creates up to 100 links from a shared template in one atomic call. Two modes: caller-suppliedcustom_idsor auto-generated viacount. Gated on a verified custom domain (intended use case: campaign codes / affiliate slugs under a customer's own domain).QuotaChecker::check_n— batch is one decision, not N. Counts as one unit against the rate limiter.create_linksMCP tool too. Service-layer choke point means both transports go through the same validation, quota, and transaction path (per CLAUDE.md "quota lives in services").Response shape
Success (
201):{ "links": [{"link_id": "partner-acme", "url": "https://go.acme.com/partner-acme"}, ...] }Per-row failures (
400 invalid_batch) carry every problem at once:{ "error": "2 item(s) failed validation", "code": "invalid_batch", "errors": [ {"index": 1, "custom_id": "bad id!", "code": "invalid_custom_id", "message": "..."}, {"index": 4, "custom_id": "promo-2", "code": "link_id_taken", "message": "..."} ] }Test plan
cargo fmt -- --check,cargo clippy --all-targets -- -D warnings,cargo test(97 lib + 145 integration) all greeninsert_many_with_session) isn't exercised by tests since the mock repo skips the session. The duplicate-detection + rollback contract is covered, but the actual transaction round trip is not.🤖 Generated with Claude Code