@keemakr/ui-sdk 1.7.0 → 1.8.0
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 +163 -1
- package/catalog.json +7 -19
- package/dist/build.js +48 -2
- package/dist/check-cli.d.ts +9 -0
- package/dist/check-cli.js +145 -0
- package/dist/check.d.ts +166 -0
- package/dist/check.js +408 -0
- package/dist/cli.js +5 -1
- package/dist/define.d.ts +7 -1
- package/dist/define.js +3 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -2
- package/dist/media.d.ts +12 -0
- package/dist/media.js +19 -1
- package/dist/negotiate.d.ts +11 -2
- package/dist/negotiate.js +24 -1
- package/dist/node-limits.d.ts +3 -3
- package/dist/node-limits.js +2 -2
- package/dist/page.d.ts +307 -0
- package/dist/page.js +482 -0
- package/dist/reach.d.ts +66 -0
- package/dist/reach.js +151 -0
- package/dist/schema.d.ts +46 -0
- package/dist/schema.js +80 -8
- package/dist/stories.d.ts +63 -0
- package/dist/stories.js +297 -0
- package/dist/testkit.d.ts +13 -2
- package/dist/testkit.js +8 -2
- package/dist/ui-build.d.ts +46 -0
- package/dist/ui-build.js +61 -0
- package/dist/ui-nodes.d.ts +195 -0
- package/dist/ui-nodes.js +197 -0
- package/dist/ui.d.ts +61 -0
- package/dist/ui.js +22 -0
- package/package.json +22 -2
package/dist/reach.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// What each client draws of one node type, computed from the rows negotiation itself uses
|
|
2
|
+
// (CLIENT_RELEASES, CHANNEL_BUILDS and the frozen schemas in negotiate.ts). Nothing here is typed
|
|
3
|
+
// by hand: when a release row changes, every reader of this function changes with it.
|
|
4
|
+
//
|
|
5
|
+
// It is for the builder: its checks and its preview read it. No public page shows it as a pill
|
|
6
|
+
// (a reach pill on the public catalogue was hand-typed and wrong both ways).
|
|
7
|
+
import { CHANNEL_BUILDS, CLIENT_RELEASES, CORE_DRAWN_NODE_TYPES, UI_SDK_SNAPSHOTS, compareVersions, nodeSetForClient, releasesOf, } from './negotiate.js';
|
|
8
|
+
/** Core's own module-screen renderer (dash), which draws this package's schema. */
|
|
9
|
+
export const CORE_RENDERER = 'dash';
|
|
10
|
+
/** Node types whose stand-in is a table rather than text (negotiate.ts `fallbackNode`). */
|
|
11
|
+
const TABLE_FALLBACK_TYPES = new Set(['heatmap']);
|
|
12
|
+
const CURRENT = UI_SDK_SNAPSHOTS.current;
|
|
13
|
+
const isNodeType = (name) => CURRENT.nodes.includes(name) ||
|
|
14
|
+
CORE_DRAWN_NODE_TYPES.includes(name);
|
|
15
|
+
/**
|
|
16
|
+
* The nodes each feature sits on (negotiate.ts documents each one beside `UiFeature`). `any` is a
|
|
17
|
+
* feature of the screen (breadcrumbs, header facts) or of a press or button that can sit on many
|
|
18
|
+
* nodes. Typed against every UiFeature, so a new feature does not compile until it is listed.
|
|
19
|
+
*/
|
|
20
|
+
const FEATURE_NODES = {
|
|
21
|
+
breadcrumbs: 'any',
|
|
22
|
+
'button.disabled': 'any',
|
|
23
|
+
'section.row': ['section'],
|
|
24
|
+
'form.field_kinds': ['form'],
|
|
25
|
+
'form.confirm': ['form'],
|
|
26
|
+
'press.chat': 'any',
|
|
27
|
+
'form.radio': ['form'],
|
|
28
|
+
'table.cells': ['table'],
|
|
29
|
+
'header.meta': 'any',
|
|
30
|
+
'tabs.many': ['tabs'],
|
|
31
|
+
'choice.action': ['choice_cards'],
|
|
32
|
+
'markdown.links': ['markdown'],
|
|
33
|
+
'form.disabled': ['form'],
|
|
34
|
+
'press.seek': 'any',
|
|
35
|
+
'edit.inline': ['text', 'markdown', 'details', 'table'],
|
|
36
|
+
'timeline.time_tag': ['timeline'],
|
|
37
|
+
'stat.bar': ['stat'],
|
|
38
|
+
'stat.sparkline': ['stat'],
|
|
39
|
+
'section.action': ['section'],
|
|
40
|
+
// A meter in a calendar entry's details, or in the header meta (screen-level, so any node).
|
|
41
|
+
'facts.meter': 'any',
|
|
42
|
+
'form.show_when': ['form'],
|
|
43
|
+
'press.focus': 'any',
|
|
44
|
+
'press.app': 'any',
|
|
45
|
+
'pending.open': ['pending_request'],
|
|
46
|
+
'form.allowed_days': ['form'],
|
|
47
|
+
'section.roles': ['section'],
|
|
48
|
+
'media.url': ['image', 'video'],
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* The nodes negotiation replaces or drops outright, rather than keeping without the feature, when
|
|
52
|
+
* a client lacks it (negotiate.ts, beside each UiFeature): a form with a confirm or a disabled
|
|
53
|
+
* submit becomes one line (a disabled secondary send is only dropped); a body button that is
|
|
54
|
+
* disabled or carries a chat or seek press becomes muted text; a control with a focus or app press
|
|
55
|
+
* is dropped; choice cards whose only presses are ones the client lacks become one line of titles.
|
|
56
|
+
*/
|
|
57
|
+
const FEATURE_REPLACES = {
|
|
58
|
+
'form.confirm': ['form'],
|
|
59
|
+
'form.disabled': ['form'],
|
|
60
|
+
'button.disabled': ['button'],
|
|
61
|
+
'press.chat': ['button', 'choice_cards'],
|
|
62
|
+
'press.seek': ['button', 'choice_cards'],
|
|
63
|
+
'press.focus': ['button', 'choice_cards'],
|
|
64
|
+
'press.app': ['button', 'choice_cards'],
|
|
65
|
+
// An image or a video whose src is a URL becomes its stand-in line (a URL poster is only dropped).
|
|
66
|
+
'media.url': ['image', 'video'],
|
|
67
|
+
};
|
|
68
|
+
function featureFitsNode(feature, nodeType) {
|
|
69
|
+
const nodes = FEATURE_NODES[feature];
|
|
70
|
+
return nodes === 'any' || nodes.includes(nodeType);
|
|
71
|
+
}
|
|
72
|
+
function levelOf(nodeType, draws, feature) {
|
|
73
|
+
// Core expands a core-drawn node (a dataset) into plain blocks before any client sees it.
|
|
74
|
+
if (CORE_DRAWN_NODE_TYPES.includes(nodeType)) {
|
|
75
|
+
return { level: 'core_expands', label: 'core expands it into plain blocks' };
|
|
76
|
+
}
|
|
77
|
+
if (!draws.nodes.includes(nodeType)) {
|
|
78
|
+
const fallbackAs = TABLE_FALLBACK_TYPES.has(nodeType) ? 'table' : 'text';
|
|
79
|
+
return { level: 'fallback', fallbackAs, label: `not drawn, fallback ${fallbackAs}` };
|
|
80
|
+
}
|
|
81
|
+
if (feature && !draws.features.includes(feature)) {
|
|
82
|
+
if (FEATURE_REPLACES[feature]?.includes(nodeType)) {
|
|
83
|
+
return { level: 'replaced', label: `replaced or dropped without ${feature}` };
|
|
84
|
+
}
|
|
85
|
+
return { level: 'without_feature', label: `drawn, without ${feature}` };
|
|
86
|
+
}
|
|
87
|
+
return { level: 'drawn', label: 'drawn' };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* What core's renderer and each client draw of `nodeType` (and, when given, of one feature of
|
|
91
|
+
* it). By default each client is read at its newest stable release; `versions` reads an older
|
|
92
|
+
* one and `channel: 'dev'` reads the dev-channel build. Core's renderer comes first, then the
|
|
93
|
+
* clients in the order CLIENT_RELEASES first names them. Throws on a node type this package does
|
|
94
|
+
* not know, or a feature of another node: a caller asking about a typo must not be told
|
|
95
|
+
* "fallback" as if the question were real.
|
|
96
|
+
*/
|
|
97
|
+
export function reachByClient(nodeType, options = {}) {
|
|
98
|
+
if (!isNodeType(nodeType)) {
|
|
99
|
+
throw new Error(`reachByClient: unknown node type "${nodeType}"`);
|
|
100
|
+
}
|
|
101
|
+
const { feature, versions = {}, channel = 'stable', releases = CLIENT_RELEASES, builds = CHANNEL_BUILDS, } = options;
|
|
102
|
+
if (feature && !featureFitsNode(feature, nodeType)) {
|
|
103
|
+
throw new Error(`reachByClient: feature "${feature}" is not a feature of "${nodeType}"`);
|
|
104
|
+
}
|
|
105
|
+
const reach = [
|
|
106
|
+
{
|
|
107
|
+
client: CORE_RENDERER,
|
|
108
|
+
since: 'current',
|
|
109
|
+
parses: 'current',
|
|
110
|
+
...levelOf(nodeType, CURRENT, feature),
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
const clients = [...new Set(releases.map((row) => row.client))];
|
|
114
|
+
for (const client of clients) {
|
|
115
|
+
const build = channel === 'dev' ? builds.find((row) => row.client === client) : undefined;
|
|
116
|
+
if (build) {
|
|
117
|
+
reach.push({
|
|
118
|
+
client,
|
|
119
|
+
since: 'dev channel',
|
|
120
|
+
parses: build.parses,
|
|
121
|
+
...levelOf(nodeType, build.draws, feature),
|
|
122
|
+
});
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const version = versions[client];
|
|
126
|
+
if (version !== undefined) {
|
|
127
|
+
// nodeSetForClient decides what that version draws; the row it read is named the same way.
|
|
128
|
+
const set = nodeSetForClient(client, version, releases);
|
|
129
|
+
const row = releasesOf(client, releases)
|
|
130
|
+
.filter((r) => compareVersions(r.since, version) <= 0)
|
|
131
|
+
.at(-1);
|
|
132
|
+
reach.push({
|
|
133
|
+
client,
|
|
134
|
+
since: row?.since ?? 'floor',
|
|
135
|
+
parses: set.parses ?? 'current',
|
|
136
|
+
...levelOf(nodeType, set, feature),
|
|
137
|
+
});
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const newest = releasesOf(client, releases).at(-1);
|
|
141
|
+
if (!newest)
|
|
142
|
+
continue;
|
|
143
|
+
reach.push({
|
|
144
|
+
client,
|
|
145
|
+
since: newest.since,
|
|
146
|
+
parses: newest.parses,
|
|
147
|
+
...levelOf(nodeType, newest.draws, feature),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return reach;
|
|
151
|
+
}
|
package/dist/schema.d.ts
CHANGED
|
@@ -460,6 +460,32 @@ export declare const factCellSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
460
460
|
* hidden files cannot be named.
|
|
461
461
|
*/
|
|
462
462
|
export declare const mediaPathSchema: z.ZodString;
|
|
463
|
+
/**
|
|
464
|
+
* A host a module may name in a media URL: a DNS name such as
|
|
465
|
+
* "my-bucket.s3.eu-west-1.amazonaws.com". Exact, lowercase, with no scheme,
|
|
466
|
+
* port, path or wildcard. Never an IP address, `localhost`, or a `.local`,
|
|
467
|
+
* `.localhost` or `.internal` name, so a module cannot point core at a private
|
|
468
|
+
* network. A module lists these in entry.json as `manifest.mediaHosts`.
|
|
469
|
+
*/
|
|
470
|
+
export declare const mediaHostSchema: z.ZodString;
|
|
471
|
+
/** The hosts a module's media URLs may come from: `manifest.mediaHosts` in entry.json. */
|
|
472
|
+
export declare const mediaHostsSchema: z.ZodArray<z.ZodString>;
|
|
473
|
+
/**
|
|
474
|
+
* A signed https URL for a file in the module's own storage: an S3, R2 or
|
|
475
|
+
* Vercel Blob link that expires. Its host must be one the module lists in
|
|
476
|
+
* `manifest.mediaHosts`. Core checks that host before the screen reaches a
|
|
477
|
+
* viewer, then fetches the file itself and serves it from core's own origin,
|
|
478
|
+
* as it does a media path, so the viewer's browser still never contacts the
|
|
479
|
+
* host. No credentials in the URL, no port.
|
|
480
|
+
*/
|
|
481
|
+
export declare const mediaUrlSchema: z.ZodString;
|
|
482
|
+
/**
|
|
483
|
+
* Where a media block's file comes from: a path in the module's runtime, or a signed https URL.
|
|
484
|
+
* One string with the URL's cap (2048) rather than a union of the two, so the published caps
|
|
485
|
+
* (`NODE_LIMITS`, catalog.json) say 2048: a union publishes the smaller cap, and a module that
|
|
486
|
+
* trims a signed URL to 256 breaks its signature. Each shape's own rule still applies.
|
|
487
|
+
*/
|
|
488
|
+
export declare const mediaSourceSchema: z.ZodString;
|
|
463
489
|
declare const leafNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
464
490
|
type: z.ZodLiteral<"heading">;
|
|
465
491
|
text: z.ZodString;
|
|
@@ -5618,9 +5644,25 @@ export declare const surfaceSchema: z.ZodObject<{
|
|
|
5618
5644
|
key: z.ZodString;
|
|
5619
5645
|
screen: z.ZodString;
|
|
5620
5646
|
}, z.core.$strip>;
|
|
5647
|
+
/** The longest a screen may ask core to keep its tree: one hour. */
|
|
5648
|
+
export declare const SCREEN_CACHE_MAX_AGE_S = 3600;
|
|
5649
|
+
/**
|
|
5650
|
+
* A screen's consent to be kept by core (WS20-S16). Core may answer a repeat load of this screen
|
|
5651
|
+
* for the same person, with the same params, from the tree it last loaded, for up to `max_age_s`
|
|
5652
|
+
* seconds, while it loads the screen again in the background. A screen action, a dataset row added
|
|
5653
|
+
* on the screen's module, or a finished job drops every kept tree of the module. Leave it out when
|
|
5654
|
+
* a load must always be fresh (a live queue, a countdown). Core keeps nothing unless the company
|
|
5655
|
+
* has screen caching on; a core that predates the field ignores it.
|
|
5656
|
+
*/
|
|
5657
|
+
export declare const screenCacheSchema: z.ZodObject<{
|
|
5658
|
+
max_age_s: z.ZodNumber;
|
|
5659
|
+
}, z.core.$strict>;
|
|
5621
5660
|
export declare const screenRegistrationSchema: z.ZodObject<{
|
|
5622
5661
|
screen: z.ZodString;
|
|
5623
5662
|
surface: z.ZodString;
|
|
5663
|
+
cache: z.ZodOptional<z.ZodObject<{
|
|
5664
|
+
max_age_s: z.ZodNumber;
|
|
5665
|
+
}, z.core.$strict>>;
|
|
5624
5666
|
}, z.core.$strip>;
|
|
5625
5667
|
/** The complete generated UI portion of a module manifest. */
|
|
5626
5668
|
export declare const uiManifestSchema: z.ZodObject<{
|
|
@@ -5639,6 +5681,9 @@ export declare const uiManifestSchema: z.ZodObject<{
|
|
|
5639
5681
|
screenRegistry: z.ZodArray<z.ZodObject<{
|
|
5640
5682
|
screen: z.ZodString;
|
|
5641
5683
|
surface: z.ZodString;
|
|
5684
|
+
cache: z.ZodOptional<z.ZodObject<{
|
|
5685
|
+
max_age_s: z.ZodNumber;
|
|
5686
|
+
}, z.core.$strict>>;
|
|
5642
5687
|
}, z.core.$strip>>;
|
|
5643
5688
|
}, z.core.$strip>;
|
|
5644
5689
|
export type Press = z.infer<typeof pressSchema>;
|
|
@@ -5659,6 +5704,7 @@ export type SurfaceDefinition = z.infer<typeof surfaceDefinitionSchema>;
|
|
|
5659
5704
|
export type Surface = z.infer<typeof surfaceSchema>;
|
|
5660
5705
|
export type ScreenRegistration = z.infer<typeof screenRegistrationSchema>;
|
|
5661
5706
|
export type UiManifest = z.infer<typeof uiManifestSchema>;
|
|
5707
|
+
export type ScreenCache = z.infer<typeof screenCacheSchema>;
|
|
5662
5708
|
export type ScreenTreeInput = z.input<typeof screenTreeSchema>;
|
|
5663
5709
|
export type ActionResultInput = z.input<typeof actionResultSchema>;
|
|
5664
5710
|
export declare const screenJobRequestSchema: z.ZodObject<{
|
package/dist/schema.js
CHANGED
|
@@ -1501,6 +1501,59 @@ export const mediaPathSchema = z
|
|
|
1501
1501
|
.string()
|
|
1502
1502
|
.max(256)
|
|
1503
1503
|
.regex(/^[A-Za-z0-9][A-Za-z0-9._-]*(\/[A-Za-z0-9][A-Za-z0-9._-]*)*$/, 'a relative path of letters, digits, ".", "_" and "-", never a URL');
|
|
1504
|
+
/**
|
|
1505
|
+
* A host a module may name in a media URL: a DNS name such as
|
|
1506
|
+
* "my-bucket.s3.eu-west-1.amazonaws.com". Exact, lowercase, with no scheme,
|
|
1507
|
+
* port, path or wildcard. Never an IP address, `localhost`, or a `.local`,
|
|
1508
|
+
* `.localhost` or `.internal` name, so a module cannot point core at a private
|
|
1509
|
+
* network. A module lists these in entry.json as `manifest.mediaHosts`.
|
|
1510
|
+
*/
|
|
1511
|
+
export const mediaHostSchema = z
|
|
1512
|
+
.string()
|
|
1513
|
+
.max(253)
|
|
1514
|
+
.regex(/^(?=.*[a-z])[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)+$/, 'a lowercase host name such as "cdn.example.com": no scheme, port, path or wildcard')
|
|
1515
|
+
.refine((host) => !/\.(local|localhost|internal)$/.test(host), {
|
|
1516
|
+
message: 'a .local, .localhost or .internal host is not reachable from core',
|
|
1517
|
+
})
|
|
1518
|
+
.refine((host) => !/^[0-9.]+$/.test(host), { message: 'an IP address is not a media host' });
|
|
1519
|
+
/** The hosts a module's media URLs may come from: `manifest.mediaHosts` in entry.json. */
|
|
1520
|
+
export const mediaHostsSchema = z.array(mediaHostSchema).max(10);
|
|
1521
|
+
/**
|
|
1522
|
+
* A signed https URL for a file in the module's own storage: an S3, R2 or
|
|
1523
|
+
* Vercel Blob link that expires. Its host must be one the module lists in
|
|
1524
|
+
* `manifest.mediaHosts`. Core checks that host before the screen reaches a
|
|
1525
|
+
* viewer, then fetches the file itself and serves it from core's own origin,
|
|
1526
|
+
* as it does a media path, so the viewer's browser still never contacts the
|
|
1527
|
+
* host. No credentials in the URL, no port.
|
|
1528
|
+
*/
|
|
1529
|
+
export const mediaUrlSchema = z
|
|
1530
|
+
.string()
|
|
1531
|
+
.max(2048)
|
|
1532
|
+
.refine((value) => {
|
|
1533
|
+
if (!value.startsWith('https://'))
|
|
1534
|
+
return false;
|
|
1535
|
+
try {
|
|
1536
|
+
const url = new URL(value);
|
|
1537
|
+
return (url.protocol === 'https:' &&
|
|
1538
|
+
!url.username &&
|
|
1539
|
+
!url.password &&
|
|
1540
|
+
!url.port &&
|
|
1541
|
+
mediaHostSchema.safeParse(url.hostname).success);
|
|
1542
|
+
}
|
|
1543
|
+
catch {
|
|
1544
|
+
return false;
|
|
1545
|
+
}
|
|
1546
|
+
}, { message: 'a signed https URL on a named host, with no credentials or port' });
|
|
1547
|
+
/**
|
|
1548
|
+
* Where a media block's file comes from: a path in the module's runtime, or a signed https URL.
|
|
1549
|
+
* One string with the URL's cap (2048) rather than a union of the two, so the published caps
|
|
1550
|
+
* (`NODE_LIMITS`, catalog.json) say 2048: a union publishes the smaller cap, and a module that
|
|
1551
|
+
* trims a signed URL to 256 breaks its signature. Each shape's own rule still applies.
|
|
1552
|
+
*/
|
|
1553
|
+
export const mediaSourceSchema = z
|
|
1554
|
+
.string()
|
|
1555
|
+
.max(2048)
|
|
1556
|
+
.refine((value) => mediaPathSchema.safeParse(value).success || mediaUrlSchema.safeParse(value).success, { message: 'a media path, or a signed https URL on a named host with no credentials or port' });
|
|
1504
1557
|
/**
|
|
1505
1558
|
* The shape an `image` or `video` is drawn at. `3:4` and `9:16` are portrait:
|
|
1506
1559
|
* a clinical photograph, a phone-shot video. A client whose parse predates them
|
|
@@ -1508,15 +1561,16 @@ export const mediaPathSchema = z
|
|
|
1508
1561
|
*/
|
|
1509
1562
|
const aspect = z.enum(['auto', '1:1', '4:3', '16:9', '3:4', '9:16']);
|
|
1510
1563
|
/**
|
|
1511
|
-
* A picture from the module's runtime: a document scan, a
|
|
1512
|
-
* approve, a product photo. PNG, JPEG, WebP, GIF or AVIF, up to
|
|
1513
|
-
* SVG. `
|
|
1514
|
-
* `
|
|
1564
|
+
* A picture from the module's runtime or its storage: a document scan, a
|
|
1565
|
+
* creative to approve, a product photo. PNG, JPEG, WebP, GIF or AVIF, up to
|
|
1566
|
+
* 10 MB; never SVG. `src` is a media path or a signed https URL on one of the
|
|
1567
|
+
* module's `mediaHosts`. `alt` says what it shows. A picture that only
|
|
1568
|
+
* decorates says so with `decorative: true` and has no alt.
|
|
1515
1569
|
*/
|
|
1516
1570
|
const imageSchema = z
|
|
1517
1571
|
.object({
|
|
1518
1572
|
type: z.literal('image'),
|
|
1519
|
-
src:
|
|
1573
|
+
src: mediaSourceSchema,
|
|
1520
1574
|
alt: z.string().min(1).max(300).optional(),
|
|
1521
1575
|
decorative: z.boolean().default(false),
|
|
1522
1576
|
caption: z.string().max(200).optional(),
|
|
@@ -1540,7 +1594,7 @@ const imageSchema = z
|
|
|
1540
1594
|
}
|
|
1541
1595
|
});
|
|
1542
1596
|
/**
|
|
1543
|
-
* A video from the module's runtime, played with the browser's own controls,
|
|
1597
|
+
* A video from the module's runtime or its storage, played with the browser's own controls,
|
|
1544
1598
|
* never on its own: a call recording, a creative to approve. MP4 or WebM, up
|
|
1545
1599
|
* to 200 MB. `captions` names a WebVTT file for the words spoken in it.
|
|
1546
1600
|
*/
|
|
@@ -1548,10 +1602,11 @@ const videoSchema = z.object({
|
|
|
1548
1602
|
type: z.literal('video'),
|
|
1549
1603
|
/** Names the video for a `seek`, which moves its playhead. Unique among the screen's recordings. */
|
|
1550
1604
|
key: slug.optional(),
|
|
1551
|
-
|
|
1605
|
+
/** A media path or a signed https URL on one of the module's `mediaHosts`. */
|
|
1606
|
+
src: mediaSourceSchema,
|
|
1552
1607
|
/** Names the video for screen readers: "Ad cut A, 15 seconds". */
|
|
1553
1608
|
title: z.string().min(1).max(120),
|
|
1554
|
-
poster:
|
|
1609
|
+
poster: mediaSourceSchema.optional(),
|
|
1555
1610
|
captions: mediaPathSchema.optional(),
|
|
1556
1611
|
caption: z.string().max(200).optional(),
|
|
1557
1612
|
aspect: aspect.default('16:9'),
|
|
@@ -3199,9 +3254,26 @@ export const surfaceSchema = surfaceDefinitionSchema.extend({
|
|
|
3199
3254
|
key: slug,
|
|
3200
3255
|
screen: slug,
|
|
3201
3256
|
});
|
|
3257
|
+
/** The longest a screen may ask core to keep its tree: one hour. */
|
|
3258
|
+
export const SCREEN_CACHE_MAX_AGE_S = 3600;
|
|
3259
|
+
/**
|
|
3260
|
+
* A screen's consent to be kept by core (WS20-S16). Core may answer a repeat load of this screen
|
|
3261
|
+
* for the same person, with the same params, from the tree it last loaded, for up to `max_age_s`
|
|
3262
|
+
* seconds, while it loads the screen again in the background. A screen action, a dataset row added
|
|
3263
|
+
* on the screen's module, or a finished job drops every kept tree of the module. Leave it out when
|
|
3264
|
+
* a load must always be fresh (a live queue, a countdown). Core keeps nothing unless the company
|
|
3265
|
+
* has screen caching on; a core that predates the field ignores it.
|
|
3266
|
+
*/
|
|
3267
|
+
export const screenCacheSchema = z
|
|
3268
|
+
.object({
|
|
3269
|
+
max_age_s: z.number().int().min(1).max(SCREEN_CACHE_MAX_AGE_S),
|
|
3270
|
+
})
|
|
3271
|
+
.strict();
|
|
3202
3272
|
export const screenRegistrationSchema = z.object({
|
|
3203
3273
|
screen: slug,
|
|
3204
3274
|
surface: slug,
|
|
3275
|
+
/** Generated from the screen's `defineScreen({ cache })`. Absent: core never keeps it. */
|
|
3276
|
+
cache: screenCacheSchema.optional(),
|
|
3205
3277
|
});
|
|
3206
3278
|
/** The complete generated UI portion of a module manifest. */
|
|
3207
3279
|
export const uiManifestSchema = z
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type DatasetDeclaration, type DatasetDeclarationInput, type DatasetQueryRequest, type DatasetQueryRequestInput, type DatasetQueryResponse, type DatasetRow } from './dataset.js';
|
|
2
|
+
import { type ScreenTree, type ScreenTreeInput } from './schema.js';
|
|
3
|
+
/**
|
|
4
|
+
* How the sample rows look.
|
|
5
|
+
* - `plain`: ordinary rows, with a blank optional value now and then.
|
|
6
|
+
* - `long_text`: every text value as long as a dataset allows, and as many tags as it allows.
|
|
7
|
+
* - `error`: rows the platform refuses (no key), so a view shows what a failed read looks like.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SAMPLE_VARIANTS: readonly ["plain", "long_text", "error"];
|
|
10
|
+
export type SampleVariant = (typeof SAMPLE_VARIANTS)[number];
|
|
11
|
+
/** One sample page. */
|
|
12
|
+
export interface Story {
|
|
13
|
+
/** Unique in its file. */
|
|
14
|
+
name: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
/** The page: a screen tree, as a module's load handler or the builder writes it. */
|
|
17
|
+
tree: ScreenTreeInput;
|
|
18
|
+
/** Every dataset the tree places, declared as a module declares it. */
|
|
19
|
+
datasets?: DatasetDeclarationInput[];
|
|
20
|
+
}
|
|
21
|
+
/** What a `*.stories.ts` file exports: checked, with the defaults applied. */
|
|
22
|
+
export interface Stories {
|
|
23
|
+
title: string;
|
|
24
|
+
stories: LoadedStory[];
|
|
25
|
+
}
|
|
26
|
+
export interface LoadedStory {
|
|
27
|
+
name: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
tree: ScreenTree;
|
|
30
|
+
datasets: DatasetDeclaration[];
|
|
31
|
+
}
|
|
32
|
+
export declare class StoryError extends Error {
|
|
33
|
+
readonly story: string;
|
|
34
|
+
constructor(story: string, message: string);
|
|
35
|
+
}
|
|
36
|
+
/** The dataset names a tree places, in order, each once. */
|
|
37
|
+
export declare function datasetsPlaced(tree: ScreenTree): string[];
|
|
38
|
+
/**
|
|
39
|
+
* Check a stories file: every tree passes the screen schema, every dataset declaration passes the
|
|
40
|
+
* dataset schema and is declared once, every dataset a tree places is declared, and no two stories
|
|
41
|
+
* share a name.
|
|
42
|
+
* Throws a `StoryError` naming the story.
|
|
43
|
+
*/
|
|
44
|
+
export declare function defineStories(file: {
|
|
45
|
+
title: string;
|
|
46
|
+
stories: readonly Story[];
|
|
47
|
+
}): Stories;
|
|
48
|
+
/**
|
|
49
|
+
* `count` synthetic rows for a dataset, the same on every call with the same arguments. Every row
|
|
50
|
+
* has a unique key (1, 2, 3 … for a number key; `<dataset>-1` … for a text one) and a value of the
|
|
51
|
+
* declared type for every field. An enum field walks its options in order.
|
|
52
|
+
*
|
|
53
|
+
* `error` rows leave out the key, which the platform refuses (`datasetResponseIssues`): at least
|
|
54
|
+
* one row, so even an empty page shows the failure.
|
|
55
|
+
*/
|
|
56
|
+
export declare function sampleRows(dataset: DatasetDeclarationInput | DatasetDeclaration, count: number, variant?: SampleVariant, seed?: number): DatasetRow[];
|
|
57
|
+
/**
|
|
58
|
+
* Answer one dataset query from `rows`, as a module would: the asked keys only, then the equality
|
|
59
|
+
* filters, the search over text fields, the sort, and one page of `limit` rows from the cursor (an
|
|
60
|
+
* offset), with `total` and, while more rows follow, `nextCursor`. It does not check the rows: core checks every
|
|
61
|
+
* answer against the declaration (`datasetResponseIssues`), so `error` rows fail there.
|
|
62
|
+
*/
|
|
63
|
+
export declare function sampleAnswer(dataset: DatasetDeclarationInput | DatasetDeclaration, rows: readonly DatasetRow[], request?: DatasetQueryRequestInput | DatasetQueryRequest): DatasetQueryResponse;
|