@capybara-hq/plugin-sdk 0.1.0-rc.49 → 0.1.0-rc.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,6 +57,9 @@ Rules that the schema cannot show:
57
57
  - `agents`: at most 64 templates (see `agent-templates`).
58
58
  - `themes`: at most 10 `<id>.json` files; the id is the file's base name. A theme file is checked
59
59
  by `parseThemeFile` (schema `https://capybarahq.com/schemas/theme.v1.schema.json`).
60
+ Besides schemes and `fonts`, it may set `logo` (`mark`, `wordmark`, `favicon`, `illustration`,
61
+ `appIcon`, `appIconMaskable`), `decoration` (`dither` or `none`), `avatars` (at most 12 presets) and
62
+ `hideAvatarPresets`; every file it names is checked and packed, and nothing else is served.
60
63
  - `setupGuides` (at most 8): `{ id, place, template? }`. Each guide is a Markdown document at
61
64
  `guides/<id>.md` (English, required) and `guides/<id>.zh.md` (Chinese, optional), shown where a
62
65
  person sets up what the plugin brings. `place` is `channel-connection` (New channel and the channel
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The ten built-in pixel-animal agent avatars (drawn by `@capybara-hq/design`), in the picker's
3
+ * order. A theme may hide them (`hideAvatarPresets`) and may not reuse their ids for its own
4
+ * presets (`avatars`). The kernel's preset ids are this list; the design package keeps a copy.
5
+ */
6
+ export declare const BUILTIN_AVATAR_PRESET_IDS: readonly ["capybara", "black-bear", "panda", "elephant", "fox", "owl", "penguin", "rabbit", "turtle", "whale"];
7
+ /** One of {@link BUILTIN_AVATAR_PRESET_IDS}. */
8
+ export type BuiltinAvatarPresetId = (typeof BUILTIN_AVATAR_PRESET_IDS)[number];
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The ten built-in pixel-animal agent avatars (drawn by `@capybara-hq/design`), in the picker's
3
+ * order. A theme may hide them (`hideAvatarPresets`) and may not reuse their ids for its own
4
+ * presets (`avatars`). The kernel's preset ids are this list; the design package keeps a copy.
5
+ */
6
+ export const BUILTIN_AVATAR_PRESET_IDS = [
7
+ "capybara",
8
+ "black-bear",
9
+ "panda",
10
+ "elephant",
11
+ "fox",
12
+ "owl",
13
+ "penguin",
14
+ "rabbit",
15
+ "turtle",
16
+ "whale",
17
+ ];
@@ -55,3 +55,19 @@ export interface IdentitySource {
55
55
  codeVerifier?: string;
56
56
  }): Promise<ExternalIdentity>;
57
57
  }
58
+ /**
59
+ * Thrown by an identity source's `callback` when it refuses the account on purpose (a hosted domain
60
+ * or tenant the platform does not allow, a consumer account where only organization accounts are
61
+ * allowed): the login page then says the account is not allowed (`sso.account_not_allowed`) instead
62
+ * of a provider error. The message is logged by the kernel and never shown to the person. Throw it
63
+ * only after the response itself was verified (ID token, nonce, PKCE); every other failure stays a
64
+ * plain error.
65
+ */
66
+ export declare class IdentitySourceRefused extends Error {
67
+ constructor(message: string);
68
+ }
69
+ /**
70
+ * Whether `err` is an {@link IdentitySourceRefused}: any `Error` whose `name` is
71
+ * `"IdentitySourceRefused"`, so a plugin that bundles another copy of the SDK still matches.
72
+ */
73
+ export declare function isIdentitySourceRefused(err: unknown): boolean;
package/dist/identity.js CHANGED
@@ -1 +1,21 @@
1
- export {};
1
+ /**
2
+ * Thrown by an identity source's `callback` when it refuses the account on purpose (a hosted domain
3
+ * or tenant the platform does not allow, a consumer account where only organization accounts are
4
+ * allowed): the login page then says the account is not allowed (`sso.account_not_allowed`) instead
5
+ * of a provider error. The message is logged by the kernel and never shown to the person. Throw it
6
+ * only after the response itself was verified (ID token, nonce, PKCE); every other failure stays a
7
+ * plain error.
8
+ */
9
+ export class IdentitySourceRefused extends Error {
10
+ constructor(message) {
11
+ super(message);
12
+ this.name = "IdentitySourceRefused";
13
+ }
14
+ }
15
+ /**
16
+ * Whether `err` is an {@link IdentitySourceRefused}: any `Error` whose `name` is
17
+ * `"IdentitySourceRefused"`, so a plugin that bundles another copy of the SDK still matches.
18
+ */
19
+ export function isIdentitySourceRefused(err) {
20
+ return err instanceof Error && err.name === "IdentitySourceRefused";
21
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.49";
1
+ export declare const SDK_VERSION = "0.1.0-rc.50";
2
2
  export * from "./agent-template.js";
3
+ export * from "./avatar-presets.js";
3
4
  export * from "./bootstrap.js";
4
5
  export * from "./cards.js";
5
6
  export * from "./channel.js";
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
- export const SDK_VERSION = "0.1.0-rc.49";
1
+ export const SDK_VERSION = "0.1.0-rc.50";
2
2
  export * from "./agent-template.js";
3
+ export * from "./avatar-presets.js";
3
4
  export * from "./bootstrap.js";
4
5
  export * from "./cards.js";
5
6
  export * from "./channel.js";
@@ -21,17 +21,33 @@ export declare function sanitizeThemeSvg(bytes: Uint8Array): {
21
21
  export declare function checkWoff2(bytes: Uint8Array): string | undefined;
22
22
  /**
23
23
  * A PNG logo: the PNG signature, an `IHDR` first chunk with a height of at least
24
- * {@link THEME_LIMITS}`.pngMinHeight` pixels, and at most {@link THEME_LIMITS}`.pngBytes`.
24
+ * {@link THEME_LIMITS}`.pngMinHeight` pixels, and at most `maxBytes` (default
25
+ * {@link THEME_LIMITS}`.pngBytes`; an app icon allows {@link THEME_LIMITS}`.appIconBytes`).
25
26
  */
26
- export declare function checkPng(bytes: Uint8Array): string | undefined;
27
+ export declare function checkPng(bytes: Uint8Array, maxBytes?: number): string | undefined;
27
28
  /**
28
- * Resolves and checks the asset files of a parsed theme: each `fonts[].file` ({@link checkWoff2})
29
- * and `logo.mark` / `logo.favicon` (`.svg` through {@link sanitizeThemeSvg}, `.png` through
30
- * {@link checkPng}); the favicon must be square (SVG viewBox or PNG width = height). `files` holds the plugin's files keyed by their path without a leading
31
- * `./`; the returned `assets` (the sanitized SVG bytes, the other files unchanged) use the same
32
- * keys. Errors are `<field>: <reason>`, English; the total input size of the theme's distinct
33
- * assets must stay within {@link THEME_LIMITS}`.assetsBytes`. That limit is per plugin, so a
34
- * caller reading several themes also checks the sum over all of them (distinct paths).
29
+ * Every asset a parsed theme names, in order: `fonts.<i>.file`, `logo.mark`, `logo.favicon`,
30
+ * `logo.illustration`, `logo.appIcon`, `logo.appIconMaskable`, `avatars.<i>.file`. `ref` is the
31
+ * path as written (an optional leading `./`). The one list every reader of theme assets uses (the
32
+ * checks, packing, the catalog and delivery), so a file the theme does not name is never read or
33
+ * served.
34
+ */
35
+ export declare function themeAssetRefs(theme: ParsedTheme): {
36
+ field: string;
37
+ ref: string;
38
+ }[];
39
+ /**
40
+ * Resolves and checks the asset files of a parsed theme ({@link themeAssetRefs}), each by its
41
+ * kind: `fonts[].file` ({@link checkWoff2}); `logo.mark` and `logo.illustration` (`.svg` through
42
+ * {@link sanitizeThemeSvg}, `.png` through {@link checkPng}); `logo.favicon` and `avatars[].file`
43
+ * likewise and square (SVG viewBox or PNG width = height); `logo.appIcon` and
44
+ * `logo.appIconMaskable` PNG only, square, at least {@link THEME_LIMITS}`.appIconMinSize` px and at
45
+ * most {@link THEME_LIMITS}`.appIconBytes`. `files` holds the plugin's files keyed by their path
46
+ * without a leading `./`; the returned `assets` (the sanitized SVG bytes, the other files
47
+ * unchanged) use the same keys. Errors are `<field>: <reason>`, English; the total input size of
48
+ * the theme's distinct assets must stay within {@link THEME_LIMITS}`.assetsBytes`. That limit is
49
+ * per plugin, so a caller reading several themes also checks the sum over all of them (distinct
50
+ * paths).
35
51
  */
36
52
  export declare function validateThemeAssets(theme: ParsedTheme, files: Map<string, Uint8Array>): {
37
53
  assets: Map<string, Uint8Array>;
@@ -2,10 +2,11 @@ import { SaxesParser } from "saxes";
2
2
  import { isSafePackagePath } from "./plugin-package.js";
3
3
  import { THEME_LIMITS } from "./theme.js";
4
4
  /**
5
- * Checks of a theme's asset files (themes spec §4.2-§4.4): woff2 fonts, PNG logos and the SVG
6
- * sanitizer. The sanitized SVG is served to every browser, so {@link sanitizeThemeSvg} is a trust
7
- * boundary: the output is re-serialized from the parsed tree (never the input bytes), elements are
8
- * allowlisted, every attribute value and text node is escaped on output.
5
+ * Checks of a theme's asset files (themes spec §4.2-§4.4, theme brand coverage spec §1): woff2
6
+ * fonts, PNG logos, app icons and avatars, and the SVG sanitizer. The sanitized SVG is served to
7
+ * every browser, so {@link sanitizeThemeSvg} is a trust boundary: the output is re-serialized from
8
+ * the parsed tree (never the input bytes), elements are allowlisted, every attribute value and text
9
+ * node is escaped on output.
9
10
  */
10
11
  const SVG_NS = "http://www.w3.org/2000/svg";
11
12
  const XLINK_NS = "http://www.w3.org/1999/xlink";
@@ -356,16 +357,17 @@ export function checkWoff2(bytes) {
356
357
  }
357
358
  /**
358
359
  * A PNG logo: the PNG signature, an `IHDR` first chunk with a height of at least
359
- * {@link THEME_LIMITS}`.pngMinHeight` pixels, and at most {@link THEME_LIMITS}`.pngBytes`.
360
+ * {@link THEME_LIMITS}`.pngMinHeight` pixels, and at most `maxBytes` (default
361
+ * {@link THEME_LIMITS}`.pngBytes`; an app icon allows {@link THEME_LIMITS}`.appIconBytes`).
360
362
  */
361
- export function checkPng(bytes) {
362
- const r = readPng(bytes);
363
+ export function checkPng(bytes, maxBytes = THEME_LIMITS.pngBytes) {
364
+ const r = readPng(bytes, maxBytes);
363
365
  return typeof r === "string" ? r : undefined;
364
366
  }
365
367
  /** {@link checkPng}, returning the IHDR size when the PNG passes. */
366
- function readPng(bytes) {
367
- if (bytes.length > THEME_LIMITS.pngBytes) {
368
- return `PNG is larger than ${THEME_LIMITS.pngBytes} bytes`;
368
+ function readPng(bytes, maxBytes) {
369
+ if (bytes.length > maxBytes) {
370
+ return `PNG is larger than ${maxBytes} bytes`;
369
371
  }
370
372
  if (!startsWith(bytes, PNG_SIG))
371
373
  return "image is not a PNG file (no PNG signature)";
@@ -383,13 +385,51 @@ function readPng(bytes) {
383
385
  return { width, height };
384
386
  }
385
387
  /**
386
- * Resolves and checks the asset files of a parsed theme: each `fonts[].file` ({@link checkWoff2})
387
- * and `logo.mark` / `logo.favicon` (`.svg` through {@link sanitizeThemeSvg}, `.png` through
388
- * {@link checkPng}); the favicon must be square (SVG viewBox or PNG width = height). `files` holds the plugin's files keyed by their path without a leading
389
- * `./`; the returned `assets` (the sanitized SVG bytes, the other files unchanged) use the same
390
- * keys. Errors are `<field>: <reason>`, English; the total input size of the theme's distinct
391
- * assets must stay within {@link THEME_LIMITS}`.assetsBytes`. That limit is per plugin, so a
392
- * caller reading several themes also checks the sum over all of them (distinct paths).
388
+ * Every asset a parsed theme names, in order: `fonts.<i>.file`, `logo.mark`, `logo.favicon`,
389
+ * `logo.illustration`, `logo.appIcon`, `logo.appIconMaskable`, `avatars.<i>.file`. `ref` is the
390
+ * path as written (an optional leading `./`). The one list every reader of theme assets uses (the
391
+ * checks, packing, the catalog and delivery), so a file the theme does not name is never read or
392
+ * served.
393
+ */
394
+ export function themeAssetRefs(theme) {
395
+ return refsWithKind(theme).map(({ field, ref }) => ({ field, ref }));
396
+ }
397
+ /** The kind each logo field is checked as, in {@link themeAssetRefs} order. */
398
+ const LOGO_ASSETS = [
399
+ ["mark", "image"],
400
+ ["favicon", "favicon"],
401
+ ["illustration", "image"],
402
+ ["appIcon", "appIcon"],
403
+ ["appIconMaskable", "appIcon"],
404
+ ];
405
+ /** {@link themeAssetRefs} with the kind each file is checked as. */
406
+ function refsWithKind(theme) {
407
+ const refs = [];
408
+ theme.fonts?.forEach((f, i) => {
409
+ refs.push({ field: `fonts.${i}.file`, ref: f.file, kind: "font" });
410
+ });
411
+ for (const [key, kind] of LOGO_ASSETS) {
412
+ const ref = theme.logo?.[key];
413
+ if (ref !== undefined)
414
+ refs.push({ field: `logo.${key}`, ref, kind });
415
+ }
416
+ theme.avatars?.forEach((a, i) => {
417
+ refs.push({ field: `avatars.${i}.file`, ref: a.file, kind: "avatar" });
418
+ });
419
+ return refs;
420
+ }
421
+ /**
422
+ * Resolves and checks the asset files of a parsed theme ({@link themeAssetRefs}), each by its
423
+ * kind: `fonts[].file` ({@link checkWoff2}); `logo.mark` and `logo.illustration` (`.svg` through
424
+ * {@link sanitizeThemeSvg}, `.png` through {@link checkPng}); `logo.favicon` and `avatars[].file`
425
+ * likewise and square (SVG viewBox or PNG width = height); `logo.appIcon` and
426
+ * `logo.appIconMaskable` PNG only, square, at least {@link THEME_LIMITS}`.appIconMinSize` px and at
427
+ * most {@link THEME_LIMITS}`.appIconBytes`. `files` holds the plugin's files keyed by their path
428
+ * without a leading `./`; the returned `assets` (the sanitized SVG bytes, the other files
429
+ * unchanged) use the same keys. Errors are `<field>: <reason>`, English; the total input size of
430
+ * the theme's distinct assets must stay within {@link THEME_LIMITS}`.assetsBytes`. That limit is
431
+ * per plugin, so a caller reading several themes also checks the sum over all of them (distinct
432
+ * paths).
393
433
  */
394
434
  export function validateThemeAssets(theme, files) {
395
435
  const assets = new Map();
@@ -415,13 +455,16 @@ export function validateThemeAssets(theme, files) {
415
455
  assets.set(path, r);
416
456
  };
417
457
  const font = (b) => checkWoff2(b) ?? b;
458
+ const notSquare = (what, w, h) => `${what} must be square, not ${w} x ${h}`;
459
+ /** A logo image (`mark` rules); `square` names what must be square, or is undefined. */
418
460
  const image = (ref, square) => (b) => {
419
- const notSquare = (w, h) => `favicon must be square, not ${w} x ${h}`;
420
461
  if (/\.png$/i.test(ref)) {
421
- const r = readPng(b);
462
+ const r = readPng(b, THEME_LIMITS.pngBytes);
422
463
  if (typeof r === "string")
423
464
  return r;
424
- return square && r.width !== r.height ? notSquare(r.width, r.height) : b;
465
+ return square !== undefined && r.width !== r.height
466
+ ? notSquare(square, r.width, r.height)
467
+ : b;
425
468
  }
426
469
  if (!/\.svg$/i.test(ref))
427
470
  return "must be a .svg or .png file";
@@ -429,15 +472,30 @@ export function validateThemeAssets(theme, files) {
429
472
  if ("error" in r)
430
473
  return r.error;
431
474
  const [, , w, h] = r.viewBox;
432
- return square && w !== h ? notSquare(w, h) : new TextEncoder().encode(r.svg);
475
+ return square !== undefined && w !== h
476
+ ? notSquare(square, w, h)
477
+ : new TextEncoder().encode(r.svg);
433
478
  };
434
- theme.fonts?.forEach((f, i) => {
435
- resolve(`fonts.${i}.file`, f.file, font);
436
- });
437
- for (const key of ["mark", "favicon"]) {
438
- const ref = theme.logo?.[key];
439
- if (ref !== undefined)
440
- resolve(`logo.${key}`, ref, image(ref, key === "favicon"));
479
+ const appIcon = (ref) => (b) => {
480
+ if (!/\.png$/i.test(ref))
481
+ return "must be a .png file";
482
+ const r = readPng(b, THEME_LIMITS.appIconBytes);
483
+ if (typeof r === "string")
484
+ return r;
485
+ if (r.width !== r.height)
486
+ return notSquare("app icon", r.width, r.height);
487
+ if (r.width < THEME_LIMITS.appIconMinSize) {
488
+ return `app icon must be at least ${THEME_LIMITS.appIconMinSize} px, not ${r.width}`;
489
+ }
490
+ return b;
491
+ };
492
+ for (const { field, ref, kind } of refsWithKind(theme)) {
493
+ const check = kind === "font"
494
+ ? font
495
+ : kind === "appIcon"
496
+ ? appIcon(ref)
497
+ : image(ref, kind === "favicon" ? "favicon" : kind === "avatar" ? "avatar" : undefined);
498
+ resolve(field, ref, check);
441
499
  }
442
500
  let total = 0;
443
501
  for (const n of sizes.values())
package/dist/theme.d.ts CHANGED
@@ -1,20 +1,22 @@
1
1
  import { z } from "zod";
2
+ import { type BuiltinAvatarPresetId } from "./avatar-presets.js";
2
3
  import { type LocalizedName } from "./plugin-package.js";
3
4
  import { type MergedScheme, type ThemeScheme } from "./theme-readability.js";
4
5
  /**
5
6
  * A theme file `themes/<id>.json` (themes spec §4): a partial override of the design tokens per
6
- * scheme, optional fonts and an optional logo. The id is the file's base name
7
+ * scheme, optional fonts, an optional logo and the brand fields (theme brand coverage spec §1:
8
+ * illustration, app icons, decoration, avatar presets). The id is the file's base name
7
9
  * ({@link themeIdOf}, `CATALOG_ITEM_NAME_RE`).
8
10
  *
9
11
  * {@link parseThemeFile} is the CSS-injection boundary: every token value is parsed against the
10
12
  * grammar `tokens.json` uses (`#RRGGBB`, `rgba(r,g,b,a)`, shadows `<x> <y> <blur> [<spread>]
11
13
  * <color>`) and re-rendered from its parts in canonical form. Asset paths (`fonts[].file`,
12
- * `logo.*`) are relative to the plugin root (an optional leading `./`) and every segment is limited
13
- * to `[A-Za-z0-9._-]`, so they need no escaping inside `url(...)`. Font families are limited to
14
- * letters, digits, spaces and `-`. Free text (`name`, `description`, `logo.wordmark`) carries no
15
- * control, format, line / paragraph separator or lone surrogate characters; it is text for the UI,
16
- * never CSS. Whether the files exist and their size / signature / SVG rules are checked by
17
- * the reader of the package, with {@link THEME_LIMITS}.
14
+ * `logo.*`, `avatars[].file`) are relative to the plugin root (an optional leading `./`) and every
15
+ * segment is limited to `[A-Za-z0-9._-]`, so they need no escaping inside `url(...)`. Font
16
+ * families are limited to letters, digits, spaces and `-`. Free text (`name`, `description`,
17
+ * `logo.wordmark`, `avatars[].name`) carries no control, format, line / paragraph separator or
18
+ * lone surrogate characters; it is text for the UI, never CSS. Whether the files exist and their
19
+ * size / signature / SVG rules are checked by the reader of the package, with {@link THEME_LIMITS}.
18
20
  *
19
21
  * The committed JSON Schema (`schemas/theme.v1.schema.json`) is generated from
20
22
  * {@link ThemeFileSchema} (the shape only) by `pnpm gen:package-schemas`; token names, value
@@ -26,7 +28,7 @@ export declare const THEME_LIMITS: {
26
28
  readonly fileBytes: number;
27
29
  /** Themes per plugin. */
28
30
  readonly perPlugin: 10;
29
- /** Total bytes of a plugin's theme assets (fonts and logos). */
31
+ /** Total bytes of a plugin's theme assets (fonts, logos, app icons and avatars). */
30
32
  readonly assetsBytes: number;
31
33
  /** Fonts per theme. */
32
34
  readonly fonts: 8;
@@ -38,9 +40,21 @@ export declare const THEME_LIMITS: {
38
40
  readonly pngBytes: number;
39
41
  /** Minimum pixel height of a logo PNG. */
40
42
  readonly pngMinHeight: 64;
41
- /** Characters of the wordmark. */
43
+ /** Characters of the wordmark (and of each avatar preset name). */
42
44
  readonly wordmark: 24;
45
+ /** Avatar presets per theme. */
46
+ readonly avatars: 12;
47
+ /** Bytes of an app icon PNG. */
48
+ readonly appIconBytes: 1048576;
49
+ /** Minimum pixel size of an app icon PNG (square). */
50
+ readonly appIconMinSize: 512;
43
51
  };
52
+ /** The id of a theme's avatar preset (`avatars[].id`); never a built-in preset id. */
53
+ export declare const THEME_AVATAR_ID_RE: RegExp;
54
+ /** The sign-in page background decoration (the dither columns) a theme asks for; omitted means
55
+ * `dither`. */
56
+ export declare const THEME_DECORATIONS: readonly ["dither", "none"];
57
+ export type ThemeDecoration = (typeof THEME_DECORATIONS)[number];
44
58
  /** A theme of the plugin: a `./…/<id>.json` file ({@link ThemeFile}). */
45
59
  export interface PluginThemeRef {
46
60
  path: string;
@@ -74,6 +88,24 @@ export interface ThemeLogo {
74
88
  wordmark?: string;
75
89
  /** `.svg` or `.png` path inside the plugin. */
76
90
  favicon?: string;
91
+ /** The empty-state art: `.svg` or `.png` path inside the plugin, the `mark` rules. */
92
+ illustration?: string;
93
+ /** Apple touch and manifest `any` icon: a square `.png` path, ≥ 512 px, ≤ 1 MiB. */
94
+ appIcon?: string;
95
+ /** Manifest `maskable` icon: a square `.png` path, ≥ 512 px, ≤ 1 MiB; requires `appIcon`. */
96
+ appIconMaskable?: string;
97
+ }
98
+ /** An agent avatar preset the theme adds to the picker. */
99
+ export interface ThemeAvatarPreset {
100
+ /** {@link THEME_AVATAR_ID_RE}, unique in the theme, not a built-in preset id. */
101
+ id: string;
102
+ /** Each ≤ 24 characters, the wordmark's character rules. */
103
+ name: {
104
+ en: string;
105
+ zh?: string;
106
+ };
107
+ /** A square `.svg` or `.png` path inside the plugin (PNG ≥ 64 px, the `mark` size limits). */
108
+ file: string;
77
109
  }
78
110
  /** `themes/<id>.json`. */
79
111
  export interface ThemeFile {
@@ -86,6 +118,12 @@ export interface ThemeFile {
86
118
  schemes: Partial<Record<ThemeScheme, ThemeSchemeOverride>>;
87
119
  fonts?: ThemeFont[];
88
120
  logo?: ThemeLogo;
121
+ /** Omitted means `dither`; readers apply the default. */
122
+ decoration?: ThemeDecoration;
123
+ /** At most {@link THEME_LIMITS}`.avatars`. */
124
+ avatars?: ThemeAvatarPreset[];
125
+ /** Built-in presets not offered; hiding all of them requires at least one `avatars` entry. */
126
+ hideAvatarPresets?: BuiltinAvatarPresetId[];
89
127
  }
90
128
  /**
91
129
  * A theme file after {@link parseThemeFile}: values canonical. It holds only the file's own
package/dist/theme.js CHANGED
@@ -1,21 +1,23 @@
1
1
  import { z } from "zod";
2
+ import { BUILTIN_AVATAR_PRESET_IDS } from "./avatar-presets.js";
2
3
  import { CATALOG_ITEM_NAME_RE, isSafePackagePath } from "./plugin-package.js";
3
4
  import { checkThemeReadability } from "./theme-readability.js";
4
5
  import { THEME_OVERRIDABLE, THEME_TOKENS } from "./theme-tokens.generated.js";
5
6
  /**
6
7
  * A theme file `themes/<id>.json` (themes spec §4): a partial override of the design tokens per
7
- * scheme, optional fonts and an optional logo. The id is the file's base name
8
+ * scheme, optional fonts, an optional logo and the brand fields (theme brand coverage spec §1:
9
+ * illustration, app icons, decoration, avatar presets). The id is the file's base name
8
10
  * ({@link themeIdOf}, `CATALOG_ITEM_NAME_RE`).
9
11
  *
10
12
  * {@link parseThemeFile} is the CSS-injection boundary: every token value is parsed against the
11
13
  * grammar `tokens.json` uses (`#RRGGBB`, `rgba(r,g,b,a)`, shadows `<x> <y> <blur> [<spread>]
12
14
  * <color>`) and re-rendered from its parts in canonical form. Asset paths (`fonts[].file`,
13
- * `logo.*`) are relative to the plugin root (an optional leading `./`) and every segment is limited
14
- * to `[A-Za-z0-9._-]`, so they need no escaping inside `url(...)`. Font families are limited to
15
- * letters, digits, spaces and `-`. Free text (`name`, `description`, `logo.wordmark`) carries no
16
- * control, format, line / paragraph separator or lone surrogate characters; it is text for the UI,
17
- * never CSS. Whether the files exist and their size / signature / SVG rules are checked by
18
- * the reader of the package, with {@link THEME_LIMITS}.
15
+ * `logo.*`, `avatars[].file`) are relative to the plugin root (an optional leading `./`) and every
16
+ * segment is limited to `[A-Za-z0-9._-]`, so they need no escaping inside `url(...)`. Font
17
+ * families are limited to letters, digits, spaces and `-`. Free text (`name`, `description`,
18
+ * `logo.wordmark`, `avatars[].name`) carries no control, format, line / paragraph separator or
19
+ * lone surrogate characters; it is text for the UI, never CSS. Whether the files exist and their
20
+ * size / signature / SVG rules are checked by the reader of the package, with {@link THEME_LIMITS}.
19
21
  *
20
22
  * The committed JSON Schema (`schemas/theme.v1.schema.json`) is generated from
21
23
  * {@link ThemeFileSchema} (the shape only) by `pnpm gen:package-schemas`; token names, value
@@ -27,7 +29,7 @@ export const THEME_LIMITS = {
27
29
  fileBytes: 64 * 1024,
28
30
  /** Themes per plugin. */
29
31
  perPlugin: 10,
30
- /** Total bytes of a plugin's theme assets (fonts and logos). */
32
+ /** Total bytes of a plugin's theme assets (fonts, logos, app icons and avatars). */
31
33
  assetsBytes: 16 * 1024 * 1024,
32
34
  /** Fonts per theme. */
33
35
  fonts: 8,
@@ -39,9 +41,20 @@ export const THEME_LIMITS = {
39
41
  pngBytes: 256 * 1024,
40
42
  /** Minimum pixel height of a logo PNG. */
41
43
  pngMinHeight: 64,
42
- /** Characters of the wordmark. */
44
+ /** Characters of the wordmark (and of each avatar preset name). */
43
45
  wordmark: 24,
46
+ /** Avatar presets per theme. */
47
+ avatars: 12,
48
+ /** Bytes of an app icon PNG. */
49
+ appIconBytes: 1_048_576,
50
+ /** Minimum pixel size of an app icon PNG (square). */
51
+ appIconMinSize: 512,
44
52
  };
53
+ /** The id of a theme's avatar preset (`avatars[].id`); never a built-in preset id. */
54
+ export const THEME_AVATAR_ID_RE = /^[a-z0-9][a-z0-9-]{0,31}$/;
55
+ /** The sign-in page background decoration (the dither columns) a theme asks for; omitted means
56
+ * `dither`. */
57
+ export const THEME_DECORATIONS = ["dither", "none"];
45
58
  /** `themes/neon-grid.json` → `neon-grid`. */
46
59
  export function themeIdOf(path) {
47
60
  return (path.split("/").pop() ?? "").replace(/\.json$/, "");
@@ -53,6 +66,8 @@ const FORBIDDEN_CHARS_RE = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\p{Cs}]/u;
53
66
  const PATH_SEGMENT_RE = /^[A-Za-z0-9._-]+$/;
54
67
  const FORBIDDEN_CHARS_MESSAGE = "must not contain control, format, line / paragraph separator or lone surrogate characters";
55
68
  const IMAGE_RE = /\.(?:svg|png)$/i;
69
+ const PNG_RE = /\.png$/i;
70
+ const BUILTIN_AVATARS = new Set(BUILTIN_AVATAR_PRESET_IDS);
56
71
  const MAX_VALUE_CHARS = 256;
57
72
  const text = (max, what) => z
58
73
  .string()
@@ -60,6 +75,14 @@ const text = (max, what) => z
60
75
  .max(max)
61
76
  .regex(/\S/, { message: `${what} must not be blank` })
62
77
  .refine((t) => !FORBIDDEN_CHARS_RE.test(t), { message: `${what} ${FORBIDDEN_CHARS_MESSAGE}` });
78
+ /** Short free text (the wordmark, avatar names): not blank, ≤ 24 characters, no forbidden ones. */
79
+ const shortText = (what) => z
80
+ .string()
81
+ .regex(/\S/, { message: `${what} must not be blank` })
82
+ .refine((w) => [...w].length <= THEME_LIMITS.wordmark, {
83
+ message: `${what} must be at most ${THEME_LIMITS.wordmark} characters`,
84
+ })
85
+ .refine((w) => !FORBIDDEN_CHARS_RE.test(w), { message: `${what} ${FORBIDDEN_CHARS_MESSAGE}` });
63
86
  /** A plugin-root relative path (optional `./`), each segment `[A-Za-z0-9._-]`, no `.` / `..`. */
64
87
  const isPlainAssetPath = (p) => {
65
88
  const rest = p.replace(/^\.\//, "");
@@ -81,7 +104,15 @@ const schemeOverride = z.strictObject({
81
104
  .strictObject({ sm: radius.optional(), md: radius.optional(), bubble: radius.optional() })
82
105
  .optional(),
83
106
  });
84
- const shape = z.strictObject({
107
+ const avatarPreset = z.strictObject({
108
+ id: z.string().regex(THEME_AVATAR_ID_RE, {
109
+ message: "id must match ^[a-z0-9][a-z0-9-]{0,31}$",
110
+ }),
111
+ name: z.strictObject({ en: shortText("name.en"), zh: shortText("name.zh").optional() }),
112
+ file: assetPath("file", IMAGE_RE, ".svg or .png"),
113
+ });
114
+ const shape = z
115
+ .strictObject({
85
116
  $schema: z.string().max(512).optional(),
86
117
  name: z.strictObject({ zh: text(100, "name.zh"), en: text(100, "name.en") }),
87
118
  description: z
@@ -110,19 +141,67 @@ const shape = z.strictObject({
110
141
  logo: z
111
142
  .strictObject({
112
143
  mark: assetPath("mark", IMAGE_RE, ".svg or .png").optional(),
113
- wordmark: z
114
- .string()
115
- .regex(/\S/, { message: "wordmark must not be blank" })
116
- .refine((w) => [...w].length <= THEME_LIMITS.wordmark, {
117
- message: `wordmark must be at most ${THEME_LIMITS.wordmark} characters`,
118
- })
119
- .refine((w) => !FORBIDDEN_CHARS_RE.test(w), {
120
- message: `wordmark ${FORBIDDEN_CHARS_MESSAGE}`,
121
- })
122
- .optional(),
144
+ wordmark: shortText("wordmark").optional(),
123
145
  favicon: assetPath("favicon", IMAGE_RE, ".svg or .png").optional(),
146
+ illustration: assetPath("illustration", IMAGE_RE, ".svg or .png").optional(),
147
+ appIcon: assetPath("appIcon", PNG_RE, ".png").optional(),
148
+ appIconMaskable: assetPath("appIconMaskable", PNG_RE, ".png").optional(),
149
+ })
150
+ .superRefine((l, ctx) => {
151
+ if (l.appIconMaskable !== undefined && l.appIcon === undefined) {
152
+ ctx.addIssue({
153
+ code: "custom",
154
+ path: ["appIconMaskable"],
155
+ message: "appIconMaskable requires appIcon",
156
+ });
157
+ }
158
+ })
159
+ .optional(),
160
+ decoration: z.enum(THEME_DECORATIONS).optional(),
161
+ avatars: z
162
+ .array(avatarPreset)
163
+ .max(THEME_LIMITS.avatars)
164
+ .superRefine((list, ctx) => {
165
+ const seen = new Set();
166
+ list.forEach((a, i) => {
167
+ if (BUILTIN_AVATARS.has(a.id)) {
168
+ ctx.addIssue({
169
+ code: "custom",
170
+ path: [i, "id"],
171
+ message: `id must not be a built-in avatar preset id (${a.id})`,
172
+ });
173
+ }
174
+ else if (seen.has(a.id)) {
175
+ ctx.addIssue({
176
+ code: "custom",
177
+ path: [i, "id"],
178
+ message: `duplicate avatar id ${a.id}`,
179
+ });
180
+ }
181
+ seen.add(a.id);
182
+ });
124
183
  })
125
184
  .optional(),
185
+ hideAvatarPresets: z
186
+ .array(z.enum(BUILTIN_AVATAR_PRESET_IDS))
187
+ .superRefine((list, ctx) => {
188
+ list.forEach((id, i) => {
189
+ if (list.indexOf(id) !== i) {
190
+ ctx.addIssue({ code: "custom", path: [i], message: `duplicate hidden preset ${id}` });
191
+ }
192
+ });
193
+ })
194
+ .optional(),
195
+ })
196
+ .superRefine((t, ctx) => {
197
+ const hidden = new Set(t.hideAvatarPresets ?? []);
198
+ if (hidden.size === BUILTIN_AVATAR_PRESET_IDS.length && (t.avatars?.length ?? 0) === 0) {
199
+ ctx.addIssue({
200
+ code: "custom",
201
+ path: ["hideAvatarPresets"],
202
+ message: "hiding every built-in avatar preset requires at least one entry in avatars",
203
+ });
204
+ }
126
205
  });
127
206
  /**
128
207
  * The zod schema of a theme file's shape (strict objects). Token names and values are only
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.49",
3
+ "version": "0.1.0-rc.50",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -212,9 +212,86 @@
212
212
  "favicon": {
213
213
  "type": "string",
214
214
  "maxLength": 512
215
+ },
216
+ "illustration": {
217
+ "type": "string",
218
+ "maxLength": 512
219
+ },
220
+ "appIcon": {
221
+ "type": "string",
222
+ "maxLength": 512
223
+ },
224
+ "appIconMaskable": {
225
+ "type": "string",
226
+ "maxLength": 512
215
227
  }
216
228
  },
217
229
  "additionalProperties": false
230
+ },
231
+ "decoration": {
232
+ "type": "string",
233
+ "enum": [
234
+ "dither",
235
+ "none"
236
+ ]
237
+ },
238
+ "avatars": {
239
+ "maxItems": 12,
240
+ "type": "array",
241
+ "items": {
242
+ "type": "object",
243
+ "properties": {
244
+ "id": {
245
+ "type": "string",
246
+ "pattern": "^[a-z0-9][a-z0-9-]{0,31}$"
247
+ },
248
+ "name": {
249
+ "type": "object",
250
+ "properties": {
251
+ "en": {
252
+ "type": "string",
253
+ "pattern": "\\S"
254
+ },
255
+ "zh": {
256
+ "type": "string",
257
+ "pattern": "\\S"
258
+ }
259
+ },
260
+ "required": [
261
+ "en"
262
+ ],
263
+ "additionalProperties": false
264
+ },
265
+ "file": {
266
+ "type": "string",
267
+ "maxLength": 512
268
+ }
269
+ },
270
+ "required": [
271
+ "id",
272
+ "name",
273
+ "file"
274
+ ],
275
+ "additionalProperties": false
276
+ }
277
+ },
278
+ "hideAvatarPresets": {
279
+ "type": "array",
280
+ "items": {
281
+ "type": "string",
282
+ "enum": [
283
+ "capybara",
284
+ "black-bear",
285
+ "panda",
286
+ "elephant",
287
+ "fox",
288
+ "owl",
289
+ "penguin",
290
+ "rabbit",
291
+ "turtle",
292
+ "whale"
293
+ ]
294
+ }
218
295
  }
219
296
  },
220
297
  "required": [