Repository navigation
kit/speed: the Speed client, starting with social cards, with a shared failover - #33
Merged
Merged
Conversation
createSocialCardsClient({ url, token, timeoutMs? }).getCard(input) over gRPC-Web on fetch
(Connect-ES 2.3, protobuf-es 2.17): Bearer token, a 1.5 s deadline, no retries, typed SpeedError
codes, redirects refused (sent as 'manual': Workers refuse Connect's 'error' before 2026-12-22).
socialCardOr(defaultUrl, promise) never throws and falls back to the app's own card.
The proto is copied from Speed's repository at 10648f9 (proto/README.md); bun run generate
rewrites src/speed/gen, and CI checks the two match. Optional peers; 34.5 kB gzipped, budget 40 kB.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
withFallback never throws and never waits past its deadline; it returns { url, width, height,
fromSpeed }, with the app's own image or a hex colour (an inline SVG of the format's size).
CircuitBreaker per client: 3 failures in 30 s skip Speed for 30 s, then one trial call.
onFallback(reason): timeout, error, breaker-open, not-configured. No SPEED_URL or SPEED_TOKEN:
the fallback at once, so apps ship before Speed is live. getCardOr replaces socialCardOr.
From the security review: printable-ASCII tokens only, the client's own deadline (a fetch that
ignores its signal can't hang it), answers with a user:password address or a malformed key are
refused, a caller's abort is 'canceled' (not 'timeout'), redirect bodies are cancelled.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
kit-showcase | 0362784 | Commit Preview URL Branch Preview URL |
Dec 06 2026, 08:08 AM |
…changed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # CHANGELOG.md # package.json # scripts/check-package.ts
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.
A new module,
@jgb-solutions/kit/speed: typed clients for the Speed service, one per feature, called from an app's server. The first feature is social cards. Every feature shares one failover, so Speed never breaks or slows a page.What
fetch, through Connect-ES 2.3 with messages from protobuf-es 2.17. The same code runs on Cloudflare Workers, Bun and Node.createSocialCardsClient({ url, token, timeoutMs?, onFallback?, breaker? }):authorization: Bearerheader.getCard(input)returns{ url, width, height, contentType, created, key }. On failure it throws aSpeedErrorwith a typedcode:timeout,canceled,unauthenticated,forbidden,invalid_input,rate_limited,unavailable,bad_response,not_configuredorfailed.getCardOr(input, fallback)never throws and never waits past the deadline. It returns{ url, width, height, fromSpeed }.withFallbackandcolorImage.CircuitBreaker, one per client: after 3 failures in 30 s it skips Speed for 30 s, then lets one trial call through.onFallback(reason), where the reason istimeout,error,breaker-openornot-configured.SPEED_URLorSPEED_TOKEN: the fallback comes back at once, so an app can ship before Speed is live.redirect: 'error'. Workers refuse that before compatibility date 2026-12-22 unless thefetch_redirect_errorflag is set, so without a fix every call would fail and silently fall back. The client sendsredirect: 'manual'and refuses any 3xx itself. The token never goes to another address.proto/speed/socialcards/v1/social_cards.protois copied unchanged from Speed's repository at 10648f9 (seeproto/README.md).bun run generate(buf, then protoc-gen-es) rewritessrc/speed/gen/. A new CI step runsbuf lintand fails if the generated code no longer matches the proto.@connectrpc/connect,@connectrpc/connect-weband@bufbuild/protobufare optional peers, needed only by this module.check-packageallows exactly those three for./speed.docs/speed.md, covering:SPEED_URLandSPEED_TOKEN;Checks
bun run test, 281 pass. 25 of them are new for Speed, all with a fake fetch and no network: building the request, mapping the answer, the Bearer header, the deadline, a fetch that ignores its abort signal, error mapping, redirects, settings checks, the fallback in every form, and the breaker with a fake clock.bun check,bun fmt --check,bunx buf lint,bun run check:package.bun run check:sizeputs the client at 35.84 kB gzipped against a new 40 kB budget, with Connect-ES and protobuf-es bundled in.bun audit: no vulnerabilities.getCardandgetCardOr;Docs/skills
protobuf), including its TypeScriptbuf.gentemplate.target,import_extension);defaultTimeoutMsand theredirect: 'error'fetch option.fetch_redirect_errorbehaviour, from a write-up on workerd PR #8973.Security review
An independent review of the diff found nothing high-severity. Fixed here:
user:passwordaddress or a malformedkeyis refused;canceled;The base
urlmust be HTTPS (plain HTTP only on localhost), with no userinfo, query or fragment. The token is never in a message, and the docs say to logcode, notcause. Onlyexample.comhosts appear.bun auditis clean.buf is at 1.76.0, now that kit#32 has removed kit's 3-day
minimumReleaseAge; regenerating gave identical code.🤖 Generated with Claude Code