Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
- run: bun audit --audit-level=high
- run: bun run format:check
- run: bun run typecheck
# kit/speed: the copied proto passes buf lint, and the generated code matches it.
- run: bunx buf lint && bun run generate && git diff --exit-code src/speed/gen
- run: bun run test
# The published files: built, loadable, and free of anything app-specific (scripts/check-package.ts).
- run: bun run build
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to `@jgb-solutions/kit`. Versions follow semver.
- **Breaking:** `UiText` gains five strings, `shareOn` (with `{network}`), `shareByEmail`, `copyLink`, `linkCopied` and `shareMore`. The four shipped languages have them; an app that builds its own `UiText` object must add the five or it no longer type-checks.
- **To know when adopting:** the patterns' rules are in `ui/patterns.css`, not in `core.css`: import both. Share buttons ship in one quiet style; a network's brand colour is the app's to set, through `--share-tone` on that button.
- `kit/testing` (new): checks an app's browser tests run inside the page, so every app holds the same line. `checkTouchTargets` (every control has a 44 px touch area, no neighbour's touch area covers a button, no text under 12 px) and `adsAfterContent` (an ad never comes before the first block of content, or before the third search result). No dependency: pass them to your test runner's `page.evaluate`.
- `kit/speed` (new): typed clients for the Speed service, one per feature, starting with social cards. `createSocialCardsClient({ url, token, timeoutMs?, onFallback? })` speaks gRPC-Web over `fetch` (Connect-ES 2.3, protobuf-es 2.17), so it runs on Workers, Bun and Node: one call, no retries, a 1.5 s deadline, no redirects followed. `getCardOr(input, fallback)` never throws and never waits past the deadline: when Speed is slow, failing or not set up yet, it returns the app's own image or a colour, sized to the format, with `fromSpeed: false`. A circuit breaker per client skips Speed for 30 s after 3 failures in 30 s. `withFallback`, `CircuitBreaker` and `colorImage` are shared by every feature client. `getCard` throws a `SpeedError` with typed codes. `@connectrpc/connect`, `@connectrpc/connect-web` and `@bufbuild/protobuf` are new optional peer dependencies, needed only by this module. About 35 kB gzipped with them bundled, held by `check:size`.

## 0.9.0-beta.2

Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,28 @@ function AccountButton() {
- A menu, popover or tooltip works inside a `Dialog`: it draws above it, and Escape closes it before the dialog.
- The page's global stylesheet starts with `@layer ui-sdk;`. Under a Content-Security-Policy, pages with a menu, popover or tooltip need `style-src-attr 'unsafe-inline'` and a `<meta property="csp-nonce" nonce="…">`: UI SDK positions popups with inline styles. The core components, dialogs and drawers included, need neither.

### `@jgb-solutions/kit/speed`: the clients for Speed (server-side)

Typed clients for Speed, the service that does heavy work (drawing images) for an app's server, one per feature, over gRPC-Web on `fetch` (Connect-ES 2, protobuf-es 2): Cloudflare Workers, Bun and Node. Needs `@connectrpc/connect`, `@connectrpc/connect-web` and `@bufbuild/protobuf` (optional peers). The first feature is social cards, the share images for pages without one of their own:

```ts
import { createSocialCardsClient } from '@jgb-solutions/kit/speed'

const cards = createSocialCardsClient({ url: env.SPEED_URL, token: env.SPEED_TOKEN }) // once per isolate or process
const image = await cards.getCardOr(
{ locale: 'en', page: { title: 'Animals', emoji: ['🐶', '🐱'] } },
{ url: 'https://example.com/share.png' },
)
// { url, width, height, fromSpeed }
```

- **Speed never breaks a page.** `getCardOr` (and every feature's `…Or` call, built on `withFallback`) never throws and never waits past the deadline (1.5 s, no retries): when Speed is slow, failing or not set up yet (no `SPEED_URL`), it returns the app's own image (the logo on the brand colour is the recommended share image) or a colour, sized to the format. A circuit breaker skips Speed for 30 s after 3 failures in 30 s. `onFallback(reason)` counts them: `timeout`, `error`, `breaker-open`, `not-configured`.
- The same input always gives the same URL: cache it (KV, the Cache API or SQLite), but a fallback (`fromSpeed: false`) for 60 s at most. Prerendered pages ask while they are built.
- `getCard` is the call without the failover: `{ url, width, height, contentType, created, key }`, or a `SpeedError` with a `code`.
- `SPEED_TOKEN` is the app's key: server-side only. Mobile apps never call Speed; they ask their site, through its oRPC procedures.

More in [docs/speed.md](docs/speed.md): the failover, Workers and Bun, caching, updating the API.

## What goes in, and what never goes in

**In:** generic plumbing that several apps need in the same shape, written once and tested: checking a signed token, parsing a header, a retry or rate-limit helper, a typed client for a public protocol. Every module:
Expand Down
11 changes: 11 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# `bun run generate`: protoc-gen-es (protobuf-es 2) writes the messages and the service
# descriptor that Connect-ES 2 reads; no other plugin is needed since v2.
version: v2
inputs:
- directory: proto
plugins:
- local: protoc-gen-es
out: src/speed/gen
opt:
- target=ts
- import_extension=js
8 changes: 8 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The Speed service's API, copied from its own repository (see proto/README.md). Lint only:
# breaking changes are decided there, not here.
version: v2
modules:
- path: proto
lint:
use:
- STANDARD
41 changes: 41 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading