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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion docs/speed.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: '…' }
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion proto/README.md
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 10 additions & 0 deletions proto/speed/socialcards/v1/social_cards.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions src/speed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
22 changes: 21 additions & 1 deletion src/speed/gen/speed/socialcards/v1/social_cards_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { Message } from '@bufbuild/protobuf'
export const file_speed_socialcards_v1_social_cards: GenFile =
/*@__PURE__*/
fileDesc(
'CidzcGVlZC9zb2NpYWxjYXJkcy92MS9zb2NpYWxfY2FyZHMucHJvdG8SFHNwZWVkLnNvY2lhbGNhcmRzLnYxIt4BCg5HZXRDYXJkUmVxdWVzdBIsCgZsb2NhbGUYASABKA4yHC5zcGVlZC5zb2NpYWxjYXJkcy52MS5Mb2NhbGUSMAoGZm9ybWF0GAIgASgOMiAuc3BlZWQuc29jaWFsY2FyZHMudjEuQ2FyZEZvcm1hdBIwCgVlbW9qaRgKIAEoCzIfLnNwZWVkLnNvY2lhbGNhcmR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ZFJlc3BvbnNlYgZwcm90bzM',
)

/**
Expand Down Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -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
}

/**
Expand Down
20 changes: 16 additions & 4 deletions src/speed/social-cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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. */
Expand Down Expand Up @@ -97,19 +109,19 @@ export function toRequest(input: GetCardInput): Omit<GetCardRequest, '$typeName'
if (locale === undefined) throw new SpeedError('invalid_input', `Speed: unknown locale ${JSON.stringify(input.locale)}`)
if (format === undefined) throw new SpeedError('invalid_input', `Speed: unknown format ${JSON.stringify(input.format)}`)
if (input.emoji) {
const { emoji, title, subtitle = '', label = '' } = input.emoji
const { emoji, title, subtitle = '', label = '', address = '' } = input.emoji
return {
locale,
format,
template: { case: 'emoji', value: { $typeName: 'speed.socialcards.v1.EmojiCard', emoji, title, subtitle, label } },
template: { case: 'emoji', value: { $typeName: 'speed.socialcards.v1.EmojiCard', emoji, title, subtitle, label, address } },
}
}
if (input.page) {
const { title, subtitle = '', emoji = [] } = input.page
const { title, subtitle = '', emoji = [], address = '' } = input.page
return {
locale,
format,
template: { case: 'page', value: { $typeName: 'speed.socialcards.v1.PageCard', title, subtitle, emoji: [...emoji] } },
template: { case: 'page', value: { $typeName: 'speed.socialcards.v1.PageCard', title, subtitle, emoji: [...emoji], address } },
}
}
throw new SpeedError('invalid_input', 'Speed: give an emoji or a page template')
Expand Down
Loading