@brydio/manifest 0.1.0-alpha.6 → 0.1.0-alpha.61

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.
package/README.md CHANGED
@@ -11,7 +11,7 @@ export const manifest = defineManifest({
11
11
  name: 'checklist',
12
12
  version: '0.1.0',
13
13
  screens: { home: { entry: 'screens/home.js' } },
14
- placements: [{ kind: 'project-tab', screen: 'home', label: 'Checklist' }],
14
+ placements: [{ kind: 'project-widget', screen: 'home', label: 'Checklist', sizes: ['medium', 'large'] }],
15
15
  });
16
16
  ```
17
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brydio/manifest",
3
- "version": "0.1.0-alpha.6",
3
+ "version": "0.1.0-alpha.61",
4
4
  "description": "The shape of a Brydio app's manifest, its collections' schemas, and the checks that say what is wrong with one.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -10,11 +10,15 @@
10
10
  "url": "https://github.com/nakel-ola/brydio-sdk",
11
11
  "directory": "packages/manifest"
12
12
  },
13
- "gitHead": "24bd1c63c437a96b40313077a85181cb4a5f6476",
13
+ "gitHead": "3b1b248522223b5b75fd9b5480c6cc7106dc6e87",
14
14
  "exports": {
15
15
  ".": {
16
16
  "types": "./src/index.d.ts",
17
17
  "default": "./src/index.js"
18
+ },
19
+ "./look": {
20
+ "types": "./src/look.d.ts",
21
+ "default": "./src/look.js"
18
22
  }
19
23
  },
20
24
  "files": [
@@ -0,0 +1,42 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * An anonymous collection (P13): answers nobody can tie back to the person
4
+ * who gave them. Mirrors Brydio's `apps/api/src/apps/manifest/anonymous.ts`;
5
+ * the two change together.
6
+ *
7
+ * An app only declares it: which structured field groups the answers (a
8
+ * form, a survey round: a number, a choice, a date), and how many answers a
9
+ * group must hold before any of them is read. Brydio does the rest in the store, never the app: no writer kept
10
+ * on the record, times cut to the day, no live change told, no update, a
11
+ * create naming its own writer refused, and reads only of a whole group of
12
+ * at least `minimum` answers.
13
+ */
14
+ export declare const ANONYMOUS_LIMITS: {
15
+ /** The fewest answers a group, or a narrowed read of one, may be read at. */
16
+ readonly minimum: 5;
17
+ /** The most an app may ask for. */
18
+ readonly maximum: 1000;
19
+ };
20
+ /** What the store writes as `created_by` on every anonymous record. */
21
+ export declare const ANONYMOUS_WRITER = "anonymous";
22
+ export declare const anonymousSchema: z.ZodObject<{
23
+ group: z.ZodString;
24
+ minimum: z.ZodOptional<z.ZodNumber>;
25
+ }, z.core.$strict>;
26
+ export type AnonymousDeclared = z.infer<typeof anonymousSchema>;
27
+ /** As the host reads it, on `CollectionSpec.anonymous`. */
28
+ export interface AnonymousSpec {
29
+ group: string;
30
+ minimum: number;
31
+ }
32
+ export type AnonymousProblemCode = 'data_anonymous_group' | 'data_anonymous_member' | 'data_anonymous_minimum' | 'data_anonymous_coedit';
33
+ export declare function anonymousProblems(collection: string, declared: {
34
+ schema: Record<string, unknown>;
35
+ anonymous?: AnonymousDeclared;
36
+ }): {
37
+ code: AnonymousProblemCode;
38
+ collection: string;
39
+ field?: string;
40
+ message: string;
41
+ }[];
42
+ export declare function anonymousSpec(declared: AnonymousDeclared): AnonymousSpec;
@@ -0,0 +1,86 @@
1
+ import { z } from 'zod';
2
+ import { FIELD_LIMITS, isStructured, parseFieldType, } from "./field-types.js";
3
+ /**
4
+ * An anonymous collection (P13): answers nobody can tie back to the person
5
+ * who gave them. Mirrors Brydio's `apps/api/src/apps/manifest/anonymous.ts`;
6
+ * the two change together.
7
+ *
8
+ * An app only declares it: which structured field groups the answers (a
9
+ * form, a survey round: a number, a choice, a date), and how many answers a
10
+ * group must hold before any of them is read. Brydio does the rest in the store, never the app: no writer kept
11
+ * on the record, times cut to the day, no live change told, no update, a
12
+ * create naming its own writer refused, and reads only of a whole group of
13
+ * at least `minimum` answers.
14
+ */
15
+ export const ANONYMOUS_LIMITS = {
16
+ /** The fewest answers a group, or a narrowed read of one, may be read at. */
17
+ minimum: 5,
18
+ /** The most an app may ask for. */
19
+ maximum: 1000,
20
+ };
21
+ /** What the store writes as `created_by` on every anonymous record. */
22
+ export const ANONYMOUS_WRITER = 'anonymous';
23
+ export const anonymousSchema = z
24
+ .object({
25
+ /** A structured field of the same collection, never a member: which group an answer belongs to. */
26
+ group: z.string().min(1).max(FIELD_LIMITS.nameChars),
27
+ /** At least 5, the default. */
28
+ minimum: z.number().int().max(ANONYMOUS_LIMITS.maximum).optional(),
29
+ })
30
+ .strict();
31
+ export function anonymousProblems(collection, declared) {
32
+ const anonymous = declared.anonymous;
33
+ if (!anonymous)
34
+ return [];
35
+ const problems = [];
36
+ const types = new Map();
37
+ for (const [field, raw] of Object.entries(declared.schema)) {
38
+ try {
39
+ types.set(field, parseFieldType(raw));
40
+ }
41
+ catch {
42
+ // Refused as a field type already.
43
+ }
44
+ }
45
+ // Kept in plain, so a read can name its group; words never are.
46
+ const group = types.get(anonymous.group);
47
+ if (!group || !isStructured(group) || group.kind === 'member') {
48
+ problems.push({
49
+ code: 'data_anonymous_group',
50
+ collection,
51
+ field: anonymous.group,
52
+ message: `${collection}.anonymous.group must name one of its structured fields (a number, choice, date, boolean, token or project); ${anonymous.group} is not.`,
53
+ });
54
+ }
55
+ if (anonymous.minimum !== undefined && anonymous.minimum < ANONYMOUS_LIMITS.minimum) {
56
+ problems.push({
57
+ code: 'data_anonymous_minimum',
58
+ collection,
59
+ message: `${collection}.anonymous.minimum is at least ${ANONYMOUS_LIMITS.minimum}: fewer answers than that can be told apart.`,
60
+ });
61
+ }
62
+ for (const [field, type] of types) {
63
+ // A member field names a person on the record, which is what this is for not doing.
64
+ if (type.kind === 'member') {
65
+ problems.push({
66
+ code: 'data_anonymous_member',
67
+ collection,
68
+ field,
69
+ message: `${collection} is anonymous, so it can't name a member: ${field} would.`,
70
+ });
71
+ }
72
+ // Writing together shows who is typing, and changes a record after it is given.
73
+ if (type.coedit) {
74
+ problems.push({
75
+ code: 'data_anonymous_coedit',
76
+ collection,
77
+ field,
78
+ message: `${collection} is anonymous, so its answers can't be written together: ${field} would be.`,
79
+ });
80
+ }
81
+ }
82
+ return problems;
83
+ }
84
+ export function anonymousSpec(declared) {
85
+ return { group: declared.group, minimum: declared.minimum ?? ANONYMOUS_LIMITS.minimum };
86
+ }
package/src/base.d.ts CHANGED
@@ -32,6 +32,15 @@ export declare const linksSchema: z.ZodObject<{
32
32
  terms: z.ZodOptional<z.ZodString>;
33
33
  support: z.ZodOptional<z.ZodString>;
34
34
  }, z.core.$strip>;
35
+ /**
36
+ * One of an app's two images, in its two variants (ADR-A20): `color` for a
37
+ * tile and the app's own page, `mono` for the sidebar, where the theme tints
38
+ * it. Both are `./`-prefixed paths inside the app.
39
+ */
40
+ export declare const brandImagesSchema: z.ZodObject<{
41
+ color: z.ZodString;
42
+ mono: z.ZodString;
43
+ }, z.core.$strip>;
35
44
  export declare const requiresSchema: z.ZodObject<{
36
45
  servers: z.ZodDefault<z.ZodArray<z.ZodString>>;
37
46
  integrations: z.ZodDefault<z.ZodArray<z.ZodString>>;
@@ -57,7 +66,14 @@ export declare const baseManifestSchema: z.ZodObject<{
57
66
  terms: z.ZodOptional<z.ZodString>;
58
67
  support: z.ZodOptional<z.ZodString>;
59
68
  }, z.core.$strip>>;
60
- icon: z.ZodOptional<z.ZodString>;
69
+ logo: z.ZodOptional<z.ZodObject<{
70
+ color: z.ZodString;
71
+ mono: z.ZodString;
72
+ }, z.core.$strip>>;
73
+ icon: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
74
+ color: z.ZodString;
75
+ mono: z.ZodString;
76
+ }, z.core.$strip>]>>;
61
77
  brandColor: z.ZodOptional<z.ZodString>;
62
78
  brandColorDark: z.ZodOptional<z.ZodString>;
63
79
  defaultPrompts: z.ZodOptional<z.ZodArray<z.ZodString>>;
package/src/base.js CHANGED
@@ -32,6 +32,15 @@ export const linksSchema = z.object({
32
32
  terms: z.string().optional(),
33
33
  support: z.string().optional(),
34
34
  });
35
+ /**
36
+ * One of an app's two images, in its two variants (ADR-A20): `color` for a
37
+ * tile and the app's own page, `mono` for the sidebar, where the theme tints
38
+ * it. Both are `./`-prefixed paths inside the app.
39
+ */
40
+ export const brandImagesSchema = z.object({
41
+ color: z.string(),
42
+ mono: z.string(),
43
+ });
35
44
  export const requiresSchema = z.object({
36
45
  servers: z.array(z.string()).default([]),
37
46
  integrations: z.array(z.string()).default([]),
@@ -49,7 +58,10 @@ export const baseManifestSchema = z.object({
49
58
  license: z.string().max(MANIFEST_LIMITS.licenseChars).optional(),
50
59
  keywords: z.array(z.string()).max(MANIFEST_LIMITS.keywords).optional(),
51
60
  links: linksSchema.optional(),
52
- icon: z.string().optional(),
61
+ /** Required to publish (ADR-A20); optional here so every stored manifest still reads. */
62
+ logo: brandImagesSchema.optional(),
63
+ /** The two-variant icon (ADR-A20), or the one path every app had before it, still read. */
64
+ icon: z.union([z.string(), brandImagesSchema]).optional(),
53
65
  brandColor: z.string().optional(),
54
66
  brandColorDark: z.string().optional(),
55
67
  defaultPrompts: z.array(z.string()).max(MANIFEST_LIMITS.defaultPrompts).optional(),
package/src/bundle.d.ts CHANGED
@@ -11,11 +11,22 @@
11
11
  */
12
12
  /** 1 MB per version, every file counted, the manifest included. */
13
13
  export declare const BUNDLE_MAX_BYTES: number;
14
+ /**
15
+ * What a bundle with frame screens may carry beside its code (PB27): their
16
+ * pages, styles, images and media, 4 MB of them, on top of the 1 MB of code.
17
+ */
18
+ export declare const FRAME_ASSETS_MAX_BYTES: number;
14
19
  /** The manifest, at the root of every published bundle. Never stored, never hashed. */
15
20
  export declare const BUNDLE_MANIFEST = "app.json";
16
21
  export declare const BUNDLE_PATH_MAX_CHARS = 200;
17
22
  /** The files of one bundle, by path inside it. */
18
23
  export type BundleFiles = ReadonlyMap<string, Uint8Array>;
24
+ /** What a frame screen's page may load from its own bundle (PB27), by extension. No fonts. Brydio's list. */
25
+ export declare const FRAME_ASSET_TYPES: Readonly<Record<string, string>>;
26
+ /** Whether a file is a frame screen's asset rather than code. */
27
+ export declare const isFrameAsset: (path: string) => boolean;
28
+ /** The type a file is served with, or null for one the store never holds. Brydio's answer. */
29
+ export declare function contentTypeOf(path: string): string | null;
19
30
  /**
20
31
  * Whether a path can name a file inside a bundle: relative, forward slashes,
21
32
  * no empty, `.` or `..` segment, no hidden segment, plain printable ASCII.
@@ -23,7 +34,14 @@ export type BundleFiles = ReadonlyMap<string, Uint8Array>;
23
34
  export declare function isBundlePath(path: string): boolean;
24
35
  /** Whether a path is a script a bundle can hold. */
25
36
  export declare const isScriptPath: (path: string) => boolean;
26
- /** The files the store keeps and the fingerprint covers: every one but the root manifest. */
37
+ /**
38
+ * The logo and icon files the bundle's manifest names (ADR-A20), by path: the
39
+ * one kind of file beside code a bundle may hold, and only at those paths.
40
+ * Brydio keeps them with the version, never as code, so they are not in the
41
+ * fingerprint.
42
+ */
43
+ export declare function brandOf(files: BundleFiles): BundleFiles;
44
+ /** The files the store keeps and the fingerprint covers: every one but the root manifest and its brand images. */
27
45
  export declare function codeOf(files: BundleFiles): BundleFiles;
28
46
  /**
29
47
  * The fingerprint: sha256, lowercase hex, over the sorted list of the code
@@ -47,6 +65,8 @@ export interface BundleProblem {
47
65
  * and words: every path first, then the manifest, then the code, then the size.
48
66
  */
49
67
  export declare function bundleProblem(files: BundleFiles): BundleProblem | null;
50
- /** Every file's bytes, the manifest included: what the cap is measured on. */
68
+ /** Every file's bytes, the manifest included. */
51
69
  export declare const bundleBytes: (files: BundleFiles) => number;
70
+ /** A frame screen's pages, styles, images and media, which have a cap of their own (PB27). */
71
+ export declare const frameAssetBytes: (files: BundleFiles) => number;
52
72
  export declare function sizeOf(bytes: number): string;
package/src/bundle.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { createHash } from 'node:crypto';
2
+ import { brandPathsOf } from "./requirements.js";
3
+ import { framePagesOf } from "./screen-kinds.js";
2
4
  /**
3
5
  * What a bundle may hold, and the fingerprint its code is served under
4
6
  * (contracts §11, A7-F02).
@@ -12,10 +14,41 @@ import { createHash } from 'node:crypto';
12
14
  */
13
15
  /** 1 MB per version, every file counted, the manifest included. */
14
16
  export const BUNDLE_MAX_BYTES = 1024 * 1024;
17
+ /**
18
+ * What a bundle with frame screens may carry beside its code (PB27): their
19
+ * pages, styles, images and media, 4 MB of them, on top of the 1 MB of code.
20
+ */
21
+ export const FRAME_ASSETS_MAX_BYTES = 4 * 1024 * 1024;
15
22
  /** The manifest, at the root of every published bundle. Never stored, never hashed. */
16
23
  export const BUNDLE_MANIFEST = 'app.json';
17
24
  export const BUNDLE_PATH_MAX_CHARS = 200;
18
25
  const SCRIPT = /\.m?js$/;
26
+ /** What a frame screen's page may load from its own bundle (PB27), by extension. No fonts. Brydio's list. */
27
+ export const FRAME_ASSET_TYPES = {
28
+ html: 'text/plain; charset=utf-8',
29
+ css: 'text/css; charset=utf-8',
30
+ png: 'image/png',
31
+ jpg: 'image/jpeg',
32
+ jpeg: 'image/jpeg',
33
+ gif: 'image/gif',
34
+ webp: 'image/webp',
35
+ avif: 'image/avif',
36
+ svg: 'image/svg+xml',
37
+ mp4: 'video/mp4',
38
+ webm: 'video/webm',
39
+ mp3: 'audio/mpeg',
40
+ ogg: 'audio/ogg',
41
+ wav: 'audio/wav',
42
+ };
43
+ const extensionOf = (path) => /\.([a-z0-9]+)$/i.exec(path)?.[1]?.toLowerCase() ?? '';
44
+ /** Whether a file is a frame screen's asset rather than code. */
45
+ export const isFrameAsset = (path) => !SCRIPT.test(path) && Object.prototype.hasOwnProperty.call(FRAME_ASSET_TYPES, extensionOf(path));
46
+ /** The type a file is served with, or null for one the store never holds. Brydio's answer. */
47
+ export function contentTypeOf(path) {
48
+ if (SCRIPT.test(path))
49
+ return 'text/javascript; charset=utf-8';
50
+ return isFrameAsset(path) ? FRAME_ASSET_TYPES[extensionOf(path)] : null;
51
+ }
19
52
  /**
20
53
  * Whether a path can name a file inside a bundle: relative, forward slashes,
21
54
  * no empty, `.` or `..` segment, no hidden segment, plain printable ASCII.
@@ -29,9 +62,32 @@ export function isBundlePath(path) {
29
62
  }
30
63
  /** Whether a path is a script a bundle can hold. */
31
64
  export const isScriptPath = (path) => isBundlePath(path) && SCRIPT.test(path);
32
- /** The files the store keeps and the fingerprint covers: every one but the root manifest. */
65
+ /**
66
+ * The logo and icon files the bundle's manifest names (ADR-A20), by path: the
67
+ * one kind of file beside code a bundle may hold, and only at those paths.
68
+ * Brydio keeps them with the version, never as code, so they are not in the
69
+ * fingerprint.
70
+ */
71
+ export function brandOf(files) {
72
+ const named = new Set(brandPathsOf(manifestIn(files)).values());
73
+ return new Map([...files].filter(([path]) => named.has(path)));
74
+ }
75
+ /** The bundle's manifest, read leniently: anything unreadable names no files. */
76
+ function manifestIn(files) {
77
+ const bytes = files.get(BUNDLE_MANIFEST);
78
+ if (!bytes)
79
+ return null;
80
+ try {
81
+ return JSON.parse(new TextDecoder().decode(bytes));
82
+ }
83
+ catch {
84
+ return null;
85
+ }
86
+ }
87
+ /** The files the store keeps and the fingerprint covers: every one but the root manifest and its brand images. */
33
88
  export function codeOf(files) {
34
- return new Map([...files].filter(([path]) => path !== BUNDLE_MANIFEST));
89
+ const brand = brandOf(files);
90
+ return new Map([...files].filter(([path]) => path !== BUNDLE_MANIFEST && !brand.has(path)));
35
91
  }
36
92
  const sha256 = (bytes) => createHash('sha256').update(bytes).digest('hex');
37
93
  /**
@@ -54,16 +110,25 @@ export function bundleHash(files) {
54
110
  * and words: every path first, then the manifest, then the code, then the size.
55
111
  */
56
112
  export function bundleProblem(files) {
113
+ const brand = brandOf(files);
114
+ const pages = framePagesOf(manifestIn(files));
115
+ const framed = pages.size > 0;
57
116
  for (const path of files.keys()) {
58
117
  if (!isBundlePath(path)) {
59
118
  return { code: 'bundle_path_invalid', message: `"${JSON.stringify(path).slice(1, -1)}" is not a path a bundle can hold.`, file: path };
60
119
  }
61
- if (path !== BUNDLE_MANIFEST && !SCRIPT.test(path)) {
62
- return {
63
- code: 'bundle_file_not_code',
64
- message: `"${path}" is not a script. A bundle holds only .js files and ${BUNDLE_MANIFEST}.`,
65
- file: path,
66
- };
120
+ if (path !== BUNDLE_MANIFEST && !brand.has(path) && !SCRIPT.test(path)) {
121
+ // A frame screen's page, styles, images and media (PB27); nothing else.
122
+ const asset = framed && isFrameAsset(path) && (!path.endsWith('.html') || pages.has(path));
123
+ if (!asset) {
124
+ return {
125
+ code: 'bundle_file_not_code',
126
+ message: framed
127
+ ? `"${path}" is not a script, a frame screen's page, a stylesheet, an image or media. A bundle holds only those and ${BUNDLE_MANIFEST}.`
128
+ : `"${path}" is not a script. A bundle holds only .js files and ${BUNDLE_MANIFEST}.`,
129
+ file: path,
130
+ };
131
+ }
67
132
  }
68
133
  }
69
134
  if (!files.has(BUNDLE_MANIFEST)) {
@@ -72,9 +137,21 @@ export function bundleProblem(files) {
72
137
  if (codeOf(files).size === 0) {
73
138
  return { code: 'bundle_empty', message: 'That bundle has no screens in it, only a manifest.' };
74
139
  }
75
- const total = bundleBytes(files);
140
+ const assets = [...files].filter(([path]) => isFrameAsset(path) && !brand.has(path));
141
+ const assetBytes = assets.reduce((sum, [, bytes]) => sum + bytes.length, 0);
142
+ if (assetBytes > FRAME_ASSETS_MAX_BYTES) {
143
+ const [largest] = [...assets].sort(([, a], [, b]) => b.length - a.length);
144
+ return {
145
+ code: 'bundle_too_large',
146
+ message: `The frame screens' pages, styles, images and media are ${sizeOf(assetBytes)}, over the ${sizeOf(FRAME_ASSETS_MAX_BYTES)} cap. ` +
147
+ `The largest is "${largest[0]}" at ${sizeOf(largest[1].length)}.`,
148
+ file: largest[0],
149
+ };
150
+ }
151
+ const counted = [...files].filter(([path]) => !(isFrameAsset(path) && !brand.has(path)));
152
+ const total = counted.reduce((sum, [, bytes]) => sum + bytes.length, 0);
76
153
  if (total > BUNDLE_MAX_BYTES) {
77
- const [largest] = [...files].sort(([, a], [, b]) => b.length - a.length);
154
+ const [largest] = [...counted].sort(([, a], [, b]) => b.length - a.length);
78
155
  return {
79
156
  code: 'bundle_too_large',
80
157
  message: `That bundle is ${sizeOf(total)}, over the ${sizeOf(BUNDLE_MAX_BYTES)} cap. ` +
@@ -84,8 +161,13 @@ export function bundleProblem(files) {
84
161
  }
85
162
  return null;
86
163
  }
87
- /** Every file's bytes, the manifest included: what the cap is measured on. */
164
+ /** Every file's bytes, the manifest included. */
88
165
  export const bundleBytes = (files) => [...files.values()].reduce((sum, bytes) => sum + bytes.length, 0);
166
+ /** A frame screen's pages, styles, images and media, which have a cap of their own (PB27). */
167
+ export const frameAssetBytes = (files) => {
168
+ const brand = brandOf(files);
169
+ return [...files].filter(([path]) => isFrameAsset(path) && !brand.has(path)).reduce((sum, [, bytes]) => sum + bytes.length, 0);
170
+ };
89
171
  export function sizeOf(bytes) {
90
172
  if (bytes < 1024)
91
173
  return `${bytes} bytes`;
@@ -0,0 +1,40 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * The confirmation email of a public form (FO04). Mirrors Brydio's
4
+ * `apps/api/src/apps/manifest/confirm-email.ts`; the two change together.
5
+ *
6
+ * An app only declares it: which field of a `publicSubmit` collection holds
7
+ * the visitor's address, and a short plain text to say. Brydio decides the
8
+ * rest — when it is sent, to whom, how often, from whom — so an anonymous
9
+ * page can never be used to send anybody anything else.
10
+ */
11
+ export declare const CONFIRM_LIMITS: {
12
+ readonly subjectChars: 120;
13
+ readonly messageChars: 600;
14
+ };
15
+ export declare const confirmEmailSchema: z.ZodObject<{
16
+ field: z.ZodString;
17
+ subject: z.ZodOptional<z.ZodString>;
18
+ message: z.ZodOptional<z.ZodString>;
19
+ link: z.ZodOptional<z.ZodBoolean>;
20
+ }, z.core.$strict>;
21
+ export type ConfirmEmailDeclared = z.infer<typeof confirmEmailSchema>;
22
+ /** As the host reads it, on `CollectionSpec.confirmEmail`. */
23
+ export interface ConfirmEmailSpec {
24
+ field: string;
25
+ subject: string | null;
26
+ message: string | null;
27
+ link: boolean;
28
+ }
29
+ export type ConfirmProblemCode = 'data_confirm_submit' | 'data_confirm_field' | 'data_confirm_text';
30
+ export declare function confirmEmailProblems(collection: string, declared: {
31
+ schema: Record<string, unknown>;
32
+ publicSubmit?: boolean;
33
+ confirmEmail?: ConfirmEmailDeclared;
34
+ }): {
35
+ code: ConfirmProblemCode;
36
+ collection: string;
37
+ field?: string;
38
+ message: string;
39
+ }[];
40
+ export declare function confirmEmailSpec(declared: ConfirmEmailDeclared): ConfirmEmailSpec;
@@ -0,0 +1,78 @@
1
+ import { z } from 'zod';
2
+ import { FIELD_LIMITS, parseFieldType } from "./field-types.js";
3
+ /**
4
+ * The confirmation email of a public form (FO04). Mirrors Brydio's
5
+ * `apps/api/src/apps/manifest/confirm-email.ts`; the two change together.
6
+ *
7
+ * An app only declares it: which field of a `publicSubmit` collection holds
8
+ * the visitor's address, and a short plain text to say. Brydio decides the
9
+ * rest — when it is sent, to whom, how often, from whom — so an anonymous
10
+ * page can never be used to send anybody anything else.
11
+ */
12
+ export const CONFIRM_LIMITS = {
13
+ subjectChars: 120,
14
+ messageChars: 600,
15
+ };
16
+ export const confirmEmailSchema = z
17
+ .object({
18
+ /** A `string` field of the same collection: the visitor's address. */
19
+ field: z.string().min(1).max(FIELD_LIMITS.nameChars),
20
+ subject: z.string().min(1).max(CONFIRM_LIMITS.subjectChars).optional(),
21
+ /** Plain text; a blank line starts a new paragraph. */
22
+ message: z.string().min(1).max(CONFIRM_LIMITS.messageChars).optional(),
23
+ /** One button back to the public page the visitor answered. */
24
+ link: z.boolean().optional(),
25
+ })
26
+ .strict();
27
+ /** A link, an address a client would turn into one, or markup. */
28
+ const NOT_PLAIN = /(?:[a-z][a-z0-9+.-]*:\/\/|www\.|[<>]|\]\(|mailto:)/i;
29
+ export function confirmEmailProblems(collection, declared) {
30
+ const confirm = declared.confirmEmail;
31
+ if (!confirm)
32
+ return [];
33
+ const problems = [];
34
+ if (!declared.publicSubmit) {
35
+ problems.push({
36
+ code: 'data_confirm_submit',
37
+ collection,
38
+ message: `${collection} sends a confirmation email but visitors can't submit to it: mark it publicSubmit.`,
39
+ });
40
+ }
41
+ const raw = declared.schema[confirm.field];
42
+ let kind = null;
43
+ try {
44
+ kind = raw === undefined ? null : parseFieldType(raw).kind;
45
+ }
46
+ catch {
47
+ kind = null;
48
+ }
49
+ if (kind !== 'string') {
50
+ problems.push({
51
+ code: 'data_confirm_field',
52
+ collection,
53
+ field: confirm.field,
54
+ message: `${collection}.confirmEmail.field must name one of its string fields; ${confirm.field} is not.`,
55
+ });
56
+ }
57
+ for (const [key, text] of [
58
+ ['subject', confirm.subject],
59
+ ['message', confirm.message],
60
+ ]) {
61
+ if (text !== undefined && NOT_PLAIN.test(text)) {
62
+ problems.push({
63
+ code: 'data_confirm_text',
64
+ collection,
65
+ message: `${collection}.confirmEmail.${key} is plain text: no links, addresses or markup.`,
66
+ });
67
+ }
68
+ }
69
+ return problems;
70
+ }
71
+ export function confirmEmailSpec(declared) {
72
+ return {
73
+ field: declared.field,
74
+ subject: declared.subject?.trim() || null,
75
+ message: declared.message?.trim() || null,
76
+ link: declared.link === true,
77
+ };
78
+ }
package/src/define.d.ts CHANGED
@@ -11,7 +11,7 @@
11
11
  * name: 'issues',
12
12
  * version: '0.1.0',
13
13
  * screens: { board: { entry: 'screens/board.js' } },
14
- * placements: [{ kind: 'project-tab', screen: 'bord' }], // error: "bord" is not a screen
14
+ * placements: [{ kind: 'project-widget', screen: 'bord', sizes: ['large'] }], // error: "bord" is not a screen
15
15
  * });
16
16
  * ```
17
17
  */
package/src/define.js CHANGED
@@ -11,7 +11,7 @@
11
11
  * name: 'issues',
12
12
  * version: '0.1.0',
13
13
  * screens: { board: { entry: 'screens/board.js' } },
14
- * placements: [{ kind: 'project-tab', screen: 'bord' }], // error: "bord" is not a screen
14
+ * placements: [{ kind: 'project-widget', screen: 'bord', sizes: ['large'] }], // error: "bord" is not a screen
15
15
  * });
16
16
  * ```
17
17
  */
@@ -12,7 +12,7 @@ import { type ZodType } from 'zod';
12
12
  * and everything downstream — the store, the generated tools, the screen's
13
13
  * form — reads that shape, never the manifest's spelling.
14
14
  */
15
- export type FieldKind = 'string' | 'text' | 'enum' | 'member' | 'project' | 'date' | 'number' | 'boolean' | 'string[]' | 'token';
15
+ export type FieldKind = 'string' | 'text' | 'enum' | 'member' | 'project' | 'date' | 'number' | 'boolean' | 'string[]' | 'token' | 'canvas' | 'ref';
16
16
  export interface FieldType {
17
17
  kind: FieldKind;
18
18
  /** Written with a trailing `?`: may be left out on create. */
@@ -27,6 +27,25 @@ export interface FieldType {
27
27
  * changes, and a value with no label reads as itself.
28
28
  */
29
29
  labels?: Readonly<Record<string, string>>;
30
+ /**
31
+ * Written by several people at once (`tasks/docs-wiki` DW01): a `text`
32
+ * field drawn with `bry-rich-text bind` is one fragment of a shared Yjs
33
+ * document the host keeps. Such a field leaves the record's `version`
34
+ * check, and a tool's change to it merges into the live text.
35
+ */
36
+ coedit?: boolean;
37
+ /**
38
+ * Kept in the plain `fields` column although its kind is not (P5): an
39
+ * open-schema table's multi-select and link lists, and the field naming a
40
+ * row's table. Set by the host only, never parsed from a manifest.
41
+ */
42
+ plain?: boolean;
43
+ /**
44
+ * The most entries a `string[]` holds, when not `FIELD_LIMITS.listEntries`:
45
+ * a collection's readers or editors field takes `READERS_LIMIT` (P16,
46
+ * DW06). Set by the host only, never parsed from a manifest.
47
+ */
48
+ maxEntries?: number;
30
49
  }
31
50
  /**
32
51
  * The bounds a schema and a record are held to (A3-F01-S03).
@@ -37,7 +56,7 @@ export interface FieldType {
37
56
  */
38
57
  export declare const FIELD_LIMITS: {
39
58
  /** Collections one app may keep. */
40
- readonly collections: 20;
59
+ readonly collections: 40;
41
60
  /** Fields one collection may have. */
42
61
  readonly fields: 40;
43
62
  /** Values one choice may allow. */
@@ -74,9 +93,13 @@ export declare const FIELD_NAME: RegExp;
74
93
  export declare const COLLECTION_NAME: RegExp;
75
94
  /** A field type the manifest wrote that Brydio does not have, or a bad list. */
76
95
  export declare class FieldTypeInvalid extends Error {
77
- readonly code: 'data_field_type_unknown' | 'data_enum_empty' | 'data_enum_too_many' | 'data_enum_value_invalid' | 'data_enum_duplicate' | 'data_default_not_allowed' | 'data_default_on_required' | 'data_default_invalid' | 'data_labels_not_allowed' | 'data_label_invalid' | 'data_label_unknown_value' | 'data_field_key_unknown';
78
- constructor(code: 'data_field_type_unknown' | 'data_enum_empty' | 'data_enum_too_many' | 'data_enum_value_invalid' | 'data_enum_duplicate' | 'data_default_not_allowed' | 'data_default_on_required' | 'data_default_invalid' | 'data_labels_not_allowed' | 'data_label_invalid' | 'data_label_unknown_value' | 'data_field_key_unknown', message: string);
96
+ readonly code: 'data_field_type_unknown' | 'data_enum_empty' | 'data_enum_too_many' | 'data_enum_value_invalid' | 'data_enum_duplicate' | 'data_default_not_allowed' | 'data_default_on_required' | 'data_default_invalid' | 'data_labels_not_allowed' | 'data_label_invalid' | 'data_label_unknown_value' | 'data_field_key_unknown' | 'data_coedit_not_text';
97
+ constructor(code: 'data_field_type_unknown' | 'data_enum_empty' | 'data_enum_too_many' | 'data_enum_value_invalid' | 'data_enum_duplicate' | 'data_default_not_allowed' | 'data_default_on_required' | 'data_default_invalid' | 'data_labels_not_allowed' | 'data_label_invalid' | 'data_label_unknown_value' | 'data_field_key_unknown' | 'data_coedit_not_text', message: string);
79
98
  }
99
+ /** The longest record id a `ref` field holds. */
100
+ export declare const REF_CHARS = 128;
101
+ /** What a record id looks like: letters, digits, `_` and `-`; never words. */
102
+ export declare const REF_FORMAT: RegExp;
80
103
  /**
81
104
  * One field's manifest spelling, as a type.
82
105
  *
@@ -87,6 +110,16 @@ export declare class FieldTypeInvalid extends Error {
87
110
  export declare function parseFieldType(raw: unknown): FieldType;
88
111
  /** How long a choice value's label may be. */
89
112
  export declare const LABEL_CHARS = 60;
113
+ /** True for a field several people write at once, through the co-editing layer. */
114
+ export declare const isCoedited: (type: FieldType) => boolean;
115
+ /**
116
+ * What a drawing's field holds in the record (WB01): a summary the host writes
117
+ * from the live board, so a list, search and the assistant can say what is on
118
+ * it. The drawing itself lives only in the co-edited document.
119
+ */
120
+ export declare const CANVAS_SUMMARY_CHARS = 10000;
121
+ /** A collection's co-edited fields, by name. */
122
+ export declare const coeditedFields: (fields: Readonly<Record<string, FieldType>>) => string[];
90
123
  /** How a choice's value reads to a person: its label, or the value itself. */
91
124
  export declare const labelOfValue: (type: FieldType, value: string) => string;
92
125
  /** True for a type whose value lands in the plain `fields` column. */
@@ -127,7 +160,10 @@ type Optional<T> = T extends `${string}?` ? true : T extends {
127
160
  /** The TypeScript type of one field's value, from its manifest spelling. */
128
161
  export type FieldValue<T> = T extends {
129
162
  type: infer U;
130
- } ? FieldValue<U> : T extends readonly (infer V)[] ? V : T extends 'number' | 'number?' ? number : T extends 'boolean' | 'boolean?' ? boolean : T extends 'string[]' | 'string[]?' ? string[] : T extends 'token' | 'token?' ? (typeof COLOUR_TOKENS)[number] : T extends string ? string : never;
163
+ } ? FieldValue<U> : T extends readonly (infer V)[] ? V : T extends 'number' | 'number?' ? number : T extends 'boolean' | 'boolean?' ? boolean : T extends 'string[]' | 'string[]?' ? string[] : T extends 'token' | 'token?' ? (typeof COLOUR_TOKENS)[number] : T extends 'canvas' | 'canvas?' ? {
164
+ elements: number;
165
+ text: string;
166
+ } : T extends string ? string : never;
131
167
  type Simplify<T> = {
132
168
  [K in keyof T]: T[K];
133
169
  } & {};