diff --git a/CHANGELOG.md b/CHANGELOG.md index bb4da09..2d16a42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to `@jgb-solutions/kit`. Versions follow semver. +## 0.9.0-beta.4 + +A beta, published under npm's `next` tag; `latest` stays 0.8.1. + +- `kit/speed`: social cards take an optional `address` on both templates (`emoji` and `page`): the page's address, host and path without a scheme (`example.com/fr/emoji/chien`), shown in the card's footer in place of the app's domain. It is part of the card's identity, so the same page always gets the same card. The proto copy is regenerated from Speed's (`EmojiCard.address = 5`, `PageCard.address = 4`). + ## 0.9.0-beta.3 A beta, published under npm's `next` tag; `latest` stays 0.8.1. diff --git a/docs/speed.md b/docs/speed.md index f1f1569..0825a45 100644 --- a/docs/speed.md +++ b/docs/speed.md @@ -83,7 +83,7 @@ the server's, for images it asks Speed for. const card = await cards.getCard({ locale: 'fr', // en, fr, es or ht: the text is already in this language format: 'link', // link 1200×630 (the default), square 1080×1080, portrait 1000×1500, story 1080×1920 - emoji: { emoji: '🐶', title: 'Chien', subtitle: 'Un ami fidèle', label: 'Animaux' }, + emoji: { emoji: '🐶', title: 'Chien', subtitle: 'Un ami fidèle', label: 'Animaux', address: 'example.com/fr/emoji/chien' }, // or: page: { title: 'Animaux', subtitle: '…', emoji: ['🐶', '🐱'] } }) // { url: 'https://…/….png', width: 1200, height: 630, contentType: 'image/png', created: true, key: '…' } @@ -93,6 +93,8 @@ const card = await cards.getCard({ `canceled`, `unauthenticated`, `forbidden`, `invalid_input`, `rate_limited`, `unavailable`, `bad_response`, `not_configured` or `failed`. Pass `{ signal }` as its second argument to stop it sooner. Pages should use `getCardOr`. +- **The page's address** (`address`, optional on both templates) shows in the card's footer in place of + the app's domain: host and path, no scheme, up to 80 characters. It is part of the card's identity. - **Same input, same URL.** Speed draws a card once and stores it; asking again returns the stored URL. - **Checked answers.** A card whose address isn't HTTPS (or carries a user name or password), without a size, or with a malformed `key` is refused as `bad_response`. `key` is an identifier: never use it as a diff --git a/package.json b/package.json index f3b7819..22aa5b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jgb-solutions/kit", - "version": "0.9.0-beta.3", + "version": "0.9.0-beta.4", "description": "One package for JGB Solutions apps, in tree-shakable namespaces: Cloudflare Access, Better Auth (kit/access, kit/auth…) the admin panel kit (kit/admin, React 19), the shared sign-in and account pages (kit/account, web and Expo), and the design system (kit/tokens, kit/ui). An app bundles only the subpaths it imports.", "license": "MIT", "author": "JGB Solutions", diff --git a/proto/README.md b/proto/README.md index 78a0c8a..83278f8 100644 --- a/proto/README.md +++ b/proto/README.md @@ -1,6 +1,6 @@ # Speed's API, copied `speed/socialcards/v1/social_cards.proto` is a copy of the Speed service's own definition (package -`speed.socialcards.v1`), taken unchanged from the service's repository at commit `10648f9`. The service owns +`speed.socialcards.v1`), taken unchanged from the service's repository at commit `dbcbe91` (its main, with the optional `address` fields). The service owns it: changes are made there first, then copied here, and `bun run generate` rewrites `src/speed/gen/` from it (buf and protobuf-es's `protoc-gen-es`). CI fails if the generated code no longer matches this file. diff --git a/proto/speed/socialcards/v1/social_cards.proto b/proto/speed/socialcards/v1/social_cards.proto index 85910f2..863fead 100644 --- a/proto/speed/socialcards/v1/social_cards.proto +++ b/proto/speed/socialcards/v1/social_cards.proto @@ -63,6 +63,11 @@ message EmojiCard { string subtitle = 3; // A small line above the name, e.g. its category. Up to 40 characters. string label = 4; + // Optional page address shown in the card's footer instead of the app's + // domain: host and path without a scheme, e.g. + // "example.com/ht/emoji/firecracker". Up to 80 characters, no + // spaces; it must start with a host name. Part of the card's key. + string address = 5; } // Any other page (home, category, list): a title, a line and up to 4 emoji. @@ -73,6 +78,11 @@ message PageCard { string subtitle = 2; // 0 to 4 emoji, each as in EmojiCard.emoji. repeated string emoji = 3; + // Optional page address shown in the card's footer instead of the app's + // domain: host and path without a scheme, e.g. + // "example.com/ht/emoji/firecracker". Up to 80 characters, no + // spaces; it must start with a host name. Part of the card's key. + string address = 4; } message GetCardResponse { diff --git a/src/speed.test.ts b/src/speed.test.ts index 21cb91e..bd21c86 100644 --- a/src/speed.test.ts +++ b/src/speed.test.ts @@ -99,6 +99,19 @@ describe('createSocialCardsClient', () => { expect(call?.request.template.value).toMatchObject({ title: 'Bèt', subtitle: '', emoji: ['🐶', '🐱'] }) }) + test("sends the page's address when given, and an empty one when not", async () => { + const speed = fakeSpeed(() => card()) + const cards = createSocialCardsClient({ url: URL_BASE, token: TOKEN, fetch: speed.fetch }) + await cards.getCard({ locale: 'fr', emoji: { emoji: '🧨', title: 'Pétard', address: 'example.com/fr/emoji/petard' } }) + await cards.getCardOr({ locale: 'en', page: { title: 'Animals', address: 'example.com/en/animals' } }, { url: '/og.png' }) + await cards.getCard({ locale: 'en', page: { title: 'Home' } }) + expect(speed.seen.map((call) => call.request.template.value?.address)).toEqual([ + 'example.com/fr/emoji/petard', + 'example.com/en/animals', + '', + ]) + }) + test('maps the answer', async () => { const cards = createSocialCardsClient({ url: URL_BASE, token: TOKEN, fetch: fakeSpeed(() => card({ created: false })).fetch }) expect(await cards.getCard({ locale: 'en', page: { title: 'Home' } })).toEqual({ diff --git a/src/speed/gen/speed/socialcards/v1/social_cards_pb.ts b/src/speed/gen/speed/socialcards/v1/social_cards_pb.ts index b571c67..24e7d71 100644 --- a/src/speed/gen/speed/socialcards/v1/social_cards_pb.ts +++ b/src/speed/gen/speed/socialcards/v1/social_cards_pb.ts @@ -12,7 +12,7 @@ import type { Message } from '@bufbuild/protobuf' export const file_speed_socialcards_v1_social_cards: GenFile = /*@__PURE__*/ fileDesc( - 'CidzcGVlZC9zb2NpYWxjYXJkcy92MS9zb2NpYWxfY2FyZHMucHJvdG8SFHNwZWVkLnNvY2lhbGNhcmRzLnYxIt4BCg5HZXRDYXJkUmVxdWVzdBIsCgZsb2NhbGUYASABKA4yHC5zcGVlZC5zb2NpYWxjYXJkcy52MS5Mb2NhbGUSMAoGZm9ybWF0GAIgASgOMiAuc3BlZWQuc29jaWFsY2FyZHMudjEu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nYxLkdldENhcmRSZXF1ZXN0GiUuc3BlZWQuc29jaWFsY2FyZHMudjEuR2V0Q2FyZFJlc3BvbnNlYgZwcm90bzM', ) /** @@ -92,6 +92,16 @@ export type EmojiCard = Message<'speed.socialcards.v1.EmojiCard'> & { * @generated from field: string label = 4; */ label: string + + /** + * Optional page address shown in the card's footer instead of the app's + * domain: host and path without a scheme, e.g. + * "example.com/ht/emoji/firecracker". Up to 80 characters, no + * spaces; it must start with a host name. Part of the card's key. + * + * @generated from field: string address = 5; + */ + address: string } /** @@ -126,6 +136,16 @@ export type PageCard = Message<'speed.socialcards.v1.PageCard'> & { * @generated from field: repeated string emoji = 3; */ emoji: string[] + + /** + * Optional page address shown in the card's footer instead of the app's + * domain: host and path without a scheme, e.g. + * "example.com/ht/emoji/firecracker". Up to 80 characters, no + * spaces; it must start with a host name. Part of the card's key. + * + * @generated from field: string address = 4; + */ + address: string } /** diff --git a/src/speed/social-cards.ts b/src/speed/social-cards.ts index a51e25a..8afacdd 100644 --- a/src/speed/social-cards.ts +++ b/src/speed/social-cards.ts @@ -23,6 +23,12 @@ export type EmojiCardInput = { subtitle?: string /** A small line above the name (its category, say), up to 40 characters. */ label?: string + /** + * The page's address in the card's footer, in place of the app's domain: host and path, no scheme + * (`example.com/fr/emoji/chien`). Up to 80 characters, no spaces, starting with a host name. Part of + * the card's identity: a different address is a different card. + */ + address?: string } /** Any other page (home, category, list): a title, a line and up to 4 emoji. */ @@ -33,6 +39,12 @@ export type PageCardInput = { subtitle?: string /** 0 to 4 emoji. */ emoji?: readonly string[] + /** + * The page's address in the card's footer, in place of the app's domain: host and path, no scheme + * (`example.com/fr/emoji/chien`). Up to 80 characters, no spaces, starting with a host name. Part of + * the card's identity: a different address is a different card. + */ + address?: string } /** What to draw: one typed template, never HTML. The app's colours, logo and fonts live in Speed. */ @@ -97,19 +109,19 @@ export function toRequest(input: GetCardInput): Omit