Server-provided links: typed action URLs and generated link siblings in all seven SDKs
/opt/homebrew/bin/bash: child setpgid (73693 to 73693): Operation not permitted
Basecamp returns action URLs on its models: bookmark_url, subscription_url, bubble_up_url, a project's star_url, a notification's unread_url, and completion_url on todos and subtasks. Until now every SDK handed them back as bare strings, and acting on one meant parsing ids out of the URL or building a request by hand. This types those links and gives each operation that acts on one a generated sibling that takes the link. It is the first step of hypermedia support; resolving an arbitrary Basecamp URL to a resource (deep links) is out of scope, and SPEC §24 says so.
What
-
Spec. Two traits in
spec/basecamp-traits.smithy:@basecampLink(kind)marks a url member as a link of one of seven kinds: Bookmark, Unread, BubbleUp, Star, Subscription, TodoCompletion, SubtaskCompletion. It is on 79 members.@basecampLinkAction(kind, pathSuffix)marks the 17 operations that act on a kind.
Both surface in
openapi.jsonasx-basecamp-link/x-basecamp-link-action.make check-links(new, inmake check) holds the invariants:- every member kind has an action, and every action has a member;
- at most one operation per kind and method;
- one suffix per kind;
- no query or header input on an action.
-
Five new operations that the links address and the SDK lacked:
BookmarkReadable(PUT),MarkReadableUnread(POST),MarkReadableRead(DELETE),StarBucket(POST) andUnstarBucket(DELETE). All are public, naturally idempotent, regenerated in all seven SDKs and tested per the completeness bar. bc3 routes and serves them but doesn't document them. Their evidence is inspec/bc3-route-allowlist.yml, and the gap is inspec/api-gaps/link-addressed-routes.md. -
SPEC §24 Server-Provided Links:
- the typed link value per language;
- the
…ByLinksibling (the link replaces every path parameter, the account id included; body and return type are the id method's); - the validation algorithm and the reasons for it;
- the steelmanned alternatives: parsing ids out of the URL, and a generic
follow.
-
Validation, before any request or hook:
- The link must be absolute, carry no userinfo, query or fragment, and be on the configured origin.
- Path segments are judged as written: no empty,
.or..segment in any encoding, and no literal backslash. - The first segment must be the client's account id.
- The path must end with the kind's route suffix.
A link on the app host (
3.basecamp.com, whichGetMessagewrites) is moved to the API origin, as §14 does for downloads. Any other host is refused. A refused link is ausageerror. -
All seven SDKs. Generators emit the link types, the model accessors and the 17 siblings. Each SDK has one hand-written validator (listed in AGENTS.md). Siblings send through the operation's ordinary request path: auth, request hooks, retry keyed by the operation id, error mapping and decoding.
-
Conformance.
conformance/tests/links.jsonhas 14 cases, and every runner runs them with zero skips. They cover:- GET, PUT, POST with a body, and DELETE;
- a link without
.json; - an sgid carrying
%2F, sent byte for byte; - error mapping;
- refusals for another origin, another account, another kind, a relative link, a dot segment, a query, and a wildcard segment that is only
.json.
conformance/schema.jsongainslink, required exactly on…ByLinkoperations.
Decisions worth a look
-
Breaking, so labelled
breaking:- TypeScript brands link fields on model types, so code that builds a model with a plain string in one no longer compiles. Service models read them as branded strings; the raw openapi-fetch client (
client.GET,client.raw.GET) reads them as plainstring, because openapi-fetch's response mapping can't carry a brand. - Python's generated
TypedDictlink fields areNewTypes, so a typed fixture or mock that puts a plainstrin one fails mypy and pyright (nothing changes at runtime). - Go's generated
ClientInterfacegains the new operations and an…AtURLvariant per link operation.
MIGRATING.md has an Unreleased entry.
- TypeScript brands link fields on model types, so code that builds a model with a plain string in one no longer compiles. Service models read them as branded strings; the raw openapi-fetch client (
-
Validation is stricter than §8's continuation check (account segment and suffix). A link carries PUT/POST/DELETE, and a multi-identity app handing account A's link to account B's client would otherwise write into A with B's credential. Strict validation is the chosen trade-off. Step 1 also refuses whatever URL parsers repair or disagree on (whitespace, control and non-ASCII characters, a backslash before the path, a malformed
%escape, a non-digit port), because one such disagreement let a Rust link reach another account. The request goes to the configured origin with the link's path as written. A refusal never repeats the link's userinfo, query or fragment. -
Encoded slashes are accepted only in an sgid. A readable's sgid is standard Base64, and Rails writes its
/as%2Finside the segment.%2Fis allowed only in a*that ends the suffix (my/bookmarks/*,my/unreads/*), and no part between encoded slashes may be empty,.or... Every SDK has a test that the escape reaches the wire unchanged, and the Ruby, Go, Swift and TypeScript runners now record the path as sent rather than decoded. -
Untyped on purpose:
Card.completion_url: bc3 answers it with 404 because the controller finds only todos (spec/api-gaps/card-completion-url.md).UpcomingAssignable.completion_url.
-
The sgid routes without
.json, checked against bc3's source (bc3 8355de35, not exercised live). They are modeled without.jsonbecause a Smithy label can't share a segment with a literal, and a link may come either way:- Both routes take Rails' default optional format under
namespace "my"(routes.rb:576):resources :bookmarks(routes.rb:662) andpost/delete "unreads/:sgid"(routes.rb:705-708). So/my/bookmarks/<sgid>and/my/unreads/<sgid>route with or without.json. - The API mostly writes
.json(api_url_optionsis{ format: :json }, api_helper.rb:22-24). But api/messages/show.json.jbuilder:3 writesbookmark_urlon the app host without it, and api/recordings/show.json.jbuilder:3 writes it with no options at all. That is why the app-host rewrite and the optional.jsonboth exist. - Without
.json, the format comes from theAccept: application/jsonevery SDK sends. My::BookmarksController#update/#destroy answerformat.json { head :no_content }, and My::Readings::UnreadsController#create/#destroy answerhead :okwhatever the format.
- Both routes take Rails' default optional format under
-
Sibling hook info names the operation but carries no project or resource id; a link carries none the SDK reads.
-
On main after #1143 (request executor seam, 5f2885f7). Every
…ByLinksibling takes per-call request options and goes through the same request call as its id-addressed method, so the executor, cache policy (GET only), retry policy and the cross-origin credential rule apply unchanged. Link validation runs first: a refused link fires no hook and reaches no executor. Each SDK has tests that a sibling's options reach a fake executor, that a refused link calls it zero times, and that the%2Fsgid path reaches the executor's URL and the default executor's wire byte for byte. TypeScript drops its separate link-operation middleware for #1143'sbindOperation; Rust dropsOperation::for_linkforOperation::at. Page siblings from #1139 and link siblings are emitted side by side; TypeScript page siblings now name their item type (requestPage<Elem>), so a page item keeps its branded link fields. -
Swift will move
ServerLinks.swiftandGenerated/Links.swiftinto BasecampCore once the Swift target split lands.
Known per-SDK limits
- Python: a wrong kind is caught by mypy only through the typed service classes.
AccountClient's 58 service properties (andAsyncAccountClient's) are unannotated, which predates this PR. That is a follow-up of about 250 lines inclient.pyandasync_client.py, not part of this diff. - Kotlin: value-class accessors are name-mangled for Java callers.
- Ruby: no static types, so the link methods accept a link value or a string, and runtime validation decides.
Resolved elsewhere
- Python pagination userinfo leak (a
Linkheader carrying userinfo made httpx send Basic auth): fixed in #1139, where Python'ssame_originrefuses userinfo. - Kotlin
onOperationEndfiring twice on HTTP errors: fixed in #1143; the Kotlin link test now asserts it fires once.
Summary by cubic
Types Basecamp's model action URLs (bookmark_url, unread_url, bubble_up_url, star_url, subscription_url, and completion_url on todos and subtasks) and gives each of the seven SDKs a …ByLink sibling for every operation that acts on one. Siblings validate the link before sending anything — refusing characters, escapes, and ports parsers would repair, userinfo, query or fragment, empty or dot segments, encoded slashes outside the final sgid segment, and anything off the configured origin, account, or kind suffix — then send the operation to the link through its normal request path: auth, hooks, retry, error mapping, and decoding. Refusals name the link's origin and path at most. Adds the five operations the links address but the SDKs lacked (BookmarkReadable, MarkReadableUnread, MarkReadableRead, StarBucket, UnstarBucket). SPEC §24 documents the design; conformance runs 17 link cases with zero skips.
Bug Fixes
- TypeScript: bucket and sgid routes now map to their operation ids, so
StarBucketandMarkReadableUnreadretry on 429/503 with their own policy instead of the default.
Breaking
- TypeScript: link fields on models are now branded string types, so code that builds a model from a plain string no longer compiles; the raw client reads them as plain strings.
- Python: link fields are now NewTypes, so code typed against them that passes a plain string fails mypy; runtime behavior is unchanged.
- Go: the generated
ClientInterfacegains the new operations and an…AtURLvariant for each link operation.