@foliwake/server 0.9.0 → 0.10.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/CHANGELOG.md +33 -0
- package/README.md +364 -7
- package/dist/blocks-header.d.ts +5 -0
- package/dist/blocks-header.js +47 -0
- package/dist/config-checks.d.ts +9 -0
- package/dist/config-checks.js +53 -0
- package/dist/config-parts.d.ts +50 -0
- package/dist/config-parts.js +190 -0
- package/dist/config-v3.d.ts +22 -0
- package/dist/config-v3.js +104 -0
- package/dist/config.d.ts +11 -11
- package/dist/config.js +7 -222
- package/dist/discovery.d.ts +48 -0
- package/dist/discovery.js +150 -0
- package/dist/handler.d.ts +46 -0
- package/dist/handler.js +153 -0
- package/dist/hook-endpoint.d.ts +35 -0
- package/dist/hook-endpoint.js +143 -0
- package/dist/page-title.d.ts +3 -0
- package/dist/page-title.js +16 -0
- package/dist/page.d.ts +12 -2
- package/dist/page.js +26 -10
- package/dist/preload.d.ts +1 -1
- package/dist/preload.js +4 -4
- package/dist/resolve.d.ts +31 -0
- package/dist/resolve.js +76 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/package.json +21 -3
- package/schemas/remote-3.schema.json +204 -0
package/dist/page.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// Reading a page from the origin (the envelope: the only thing an app caches) and preparing it per request
|
|
2
2
|
// (design §6.5, §9.4): check → rewrite media and links → the app's transform → check again.
|
|
3
3
|
import { createHash } from 'node:crypto';
|
|
4
|
+
import { BLOCKS_HEADER, parseBlocksHeader } from './blocks-header.js';
|
|
4
5
|
import { appOf, isLoopbackName, pageAllowed } from './config.js';
|
|
5
6
|
import { CODE_ID_PATTERN, LIMITS, PAGE_PATH_PATTERN } from './constants.js';
|
|
6
7
|
import { FoliwakePageError } from './errors.js';
|
|
7
8
|
import { checkBody, componentNames, elements, serialize } from './html.js';
|
|
9
|
+
import { firstHeading } from './page-title.js';
|
|
8
10
|
import { mediaRewriter } from './media-rewrite.js';
|
|
9
11
|
import { readLimited, TooLargeError } from './stream.js';
|
|
10
12
|
export { FoliwakePageError } from './errors.js';
|
|
@@ -93,6 +95,7 @@ export async function readEnvelope(config, client, site, channel, path) {
|
|
|
93
95
|
const pageId = header(response, 'x-page-id', PAGE_ID);
|
|
94
96
|
const generation = generationOf(header(response, 'x-site-generation', GENERATION));
|
|
95
97
|
const etag = response.headers.get('etag');
|
|
98
|
+
const blocks = parseBlocksHeader(response.headers.get(BLOCKS_HEADER));
|
|
96
99
|
let bytes;
|
|
97
100
|
try {
|
|
98
101
|
bytes = await readLimited(response, LIMITS.body);
|
|
@@ -110,7 +113,8 @@ export async function readEnvelope(config, client, site, channel, path) {
|
|
|
110
113
|
throw new FoliwakePageError('invalid', 'The body is not UTF-8.');
|
|
111
114
|
}
|
|
112
115
|
checkBody(html, path); // an invalid body is refused before anything caches it
|
|
113
|
-
|
|
116
|
+
const keptEtag = etag && etag.length <= 200 ? etag : null;
|
|
117
|
+
return { site, channel, path, html, codeRelease, htmlContract, lang, pageId, etag: keptEtag, generation, blocks };
|
|
114
118
|
}
|
|
115
119
|
function rewrite(nodes, config, channel, rewriteLink) {
|
|
116
120
|
const media = mediaRewriter(appOf(config), channel);
|
|
@@ -131,13 +135,24 @@ function rewrite(nodes, config, channel, rewriteLink) {
|
|
|
131
135
|
}
|
|
132
136
|
}
|
|
133
137
|
}
|
|
134
|
-
/**
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
+
/**
|
|
139
|
+
* The same-origin URL of the blocks module, or null without an entry.
|
|
140
|
+
*
|
|
141
|
+
* @param entry - The module inside the code release; default the config's `app.blocks.entry`.
|
|
142
|
+
*/
|
|
143
|
+
export function blocksUrlOf(config, channel, codeRelease, entry = appOf(config).blocks.entry) {
|
|
144
|
+
if (!entry)
|
|
138
145
|
return null;
|
|
139
|
-
const base = `${
|
|
140
|
-
return { base, url: `${base}${
|
|
146
|
+
const base = `${appOf(config).proxies.code}${channel === 'preview' ? '/preview' : ''}/${codeRelease}/`;
|
|
147
|
+
return { base, url: `${base}${entry}` };
|
|
148
|
+
}
|
|
149
|
+
/** The blocks a page mounts: the config's, or (version 3 without `app.blocks`) the ones its code release names. */
|
|
150
|
+
export function pageBlocksOf(config, envelope) {
|
|
151
|
+
const own = appOf(config).blocks;
|
|
152
|
+
const named = envelope.blocks ?? null;
|
|
153
|
+
if (!own.fromRelease || named === null)
|
|
154
|
+
return { entry: own.entry, major: own.major, eventPrefix: own.eventPrefix };
|
|
155
|
+
return { entry: named.entry, major: named.contract, eventPrefix: named.eventPrefix };
|
|
141
156
|
}
|
|
142
157
|
/** The React key of a prepared page: see `FoliwakePageData.identity`. */
|
|
143
158
|
function identityOf(envelope, mode, digest) {
|
|
@@ -152,7 +167,6 @@ function identityOf(envelope, mode, digest) {
|
|
|
152
167
|
* fills it). Throws FoliwakePageError('invalid') when the body or the transform's output is refused.
|
|
153
168
|
*/
|
|
154
169
|
export function preparePage(config, envelope, opts = {}) {
|
|
155
|
-
const app = appOf(config);
|
|
156
170
|
const mode = opts.mode ?? null;
|
|
157
171
|
if (mode !== null && (typeof mode !== 'string' || !MODE.test(mode)))
|
|
158
172
|
throw new FoliwakePageError('invalid', `mode must be a token [a-z][a-z0-9-], at most 32 characters`);
|
|
@@ -165,8 +179,9 @@ export function preparePage(config, envelope, opts = {}) {
|
|
|
165
179
|
html = opts.transform(html, envelope);
|
|
166
180
|
const final = checkBody(html, envelope.path); // a transform cannot add what the first check refused
|
|
167
181
|
html = serialize(final);
|
|
168
|
-
const
|
|
169
|
-
const
|
|
182
|
+
const named = pageBlocksOf(config, envelope);
|
|
183
|
+
const blocks = blocksUrlOf(config, envelope.channel, envelope.codeRelease, named.entry);
|
|
184
|
+
const contract = { major: named.major, eventPrefix: named.eventPrefix };
|
|
170
185
|
// The digest covers what the browser mounts: the final prepared body (after the app's transform, so two
|
|
171
186
|
// transforms of one envelope differ, and a missing ETag cannot collide) and every mount-defining setting.
|
|
172
187
|
const digest = createHash('sha256')
|
|
@@ -180,6 +195,7 @@ export function preparePage(config, envelope, opts = {}) {
|
|
|
180
195
|
path: envelope.path,
|
|
181
196
|
mode,
|
|
182
197
|
html,
|
|
198
|
+
title: firstHeading(final),
|
|
183
199
|
codeRelease: envelope.codeRelease,
|
|
184
200
|
htmlContract: envelope.htmlContract,
|
|
185
201
|
lang: envelope.lang,
|
package/dist/preload.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FoliwakePageData, PreloadHint } from '@foliwake/blocks-contract/page';
|
|
2
|
-
import {
|
|
2
|
+
import type { FoliwakeAppConfig } from './config.js';
|
|
3
3
|
import type { OriginClient } from './origin.js';
|
|
4
4
|
export type { PreloadHint } from '@foliwake/blocks-contract/page';
|
|
5
5
|
/** A path inside the code release the proxy would serve, or null. */
|
package/dist/preload.js
CHANGED
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
// optimisation: a failed read gives fewer hints, never an error. Every href is a same-origin proxy URL
|
|
13
13
|
// (`<proxies.code>[/preview]/<cd>/<path>`) that the code proxy's allow-list accepts, so CSP 'self' covers it.
|
|
14
14
|
import { KIT_PATH, KIT_SPECIFIER } from '@foliwake/blocks-contract/import-map';
|
|
15
|
-
import { appOf } from './config.js';
|
|
16
15
|
import { CODE_ROOTS, CODE_SEGMENT } from './constants.js';
|
|
17
16
|
import { readLimited } from './stream.js';
|
|
18
17
|
const MAX_MODULES = 48;
|
|
@@ -82,9 +81,10 @@ async function readText(client, channel, cd, file) {
|
|
|
82
81
|
}
|
|
83
82
|
/** Hints for a prepared page: modulepreload for its modules, preload as=style for its block stylesheets. */
|
|
84
83
|
export async function preloadHints(config, client, page) {
|
|
85
|
-
|
|
86
|
-
if (!page.codeBase || !page.codeRelease || !
|
|
84
|
+
// The entry is the page's (the config's, or the one its code release names), as preparePage chose it.
|
|
85
|
+
if (!page.codeBase || !page.codeRelease || !page.blocksUrl?.startsWith(page.codeBase))
|
|
87
86
|
return [];
|
|
87
|
+
const entry = page.blocksUrl.slice(page.codeBase.length);
|
|
88
88
|
const cd = page.codeRelease;
|
|
89
89
|
const descriptorText = await readText(client, page.channel, cd, 'components/components.json');
|
|
90
90
|
let declared = {};
|
|
@@ -96,7 +96,7 @@ export async function preloadHints(config, client, page) {
|
|
|
96
96
|
catch {
|
|
97
97
|
declared = {};
|
|
98
98
|
}
|
|
99
|
-
const roots = [
|
|
99
|
+
const roots = [entry];
|
|
100
100
|
const styles = [];
|
|
101
101
|
for (const name of page.blocks) {
|
|
102
102
|
const entry = declared[name];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type FoliwakeAppConfig } from './config.js';
|
|
2
|
+
import { type FetchDiscoveryOptions, type FoliwakeDiscovery } from './discovery.js';
|
|
3
|
+
export { PREVIEW_TOKEN_ENV } from './config-v3.js';
|
|
4
|
+
export { DISCOVERY_PATH, URL_ENV, type FoliwakeDiscovery } from './discovery.js';
|
|
5
|
+
/** The inputs of an app's config, as plain JSON. */
|
|
6
|
+
export interface FoliwakeConfigSnapshot {
|
|
7
|
+
/** FOLIWAKE_URL, or null. */
|
|
8
|
+
url: string | null;
|
|
9
|
+
/** The site's discovery document read from `url`, or null without it. */
|
|
10
|
+
discovery: FoliwakeDiscovery | null;
|
|
11
|
+
/** The config file's name (for messages) and text, or null when there is none. */
|
|
12
|
+
file: string | null;
|
|
13
|
+
text: string | null;
|
|
14
|
+
}
|
|
15
|
+
/** Options of `readConfigSnapshot` and `loadAppConfig`. */
|
|
16
|
+
export interface ReadSnapshotOptions extends FetchDiscoveryOptions {
|
|
17
|
+
cwd?: string;
|
|
18
|
+
/** Default process.env: FOLIWAKE_URL, FOLIWAKE_REMOTE. */
|
|
19
|
+
env?: NodeJS.ProcessEnv;
|
|
20
|
+
/** The config file (default FOLIWAKE_REMOTE, else ./foliwake.remote.json). */
|
|
21
|
+
file?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Reads the inputs: FOLIWAKE_URL and its discovery document (fetched now), and the config file when there is one
|
|
25
|
+
* (a file named explicitly or by FOLIWAKE_REMOTE must exist). Throws FoliwakeConfigError.
|
|
26
|
+
*/
|
|
27
|
+
export declare function readConfigSnapshot(opts?: ReadSnapshotOptions): Promise<FoliwakeConfigSnapshot>;
|
|
28
|
+
/** The app config of a snapshot (no I/O). Throws FoliwakeConfigError naming the field. */
|
|
29
|
+
export declare function configFromSnapshot(snapshot: FoliwakeConfigSnapshot): FoliwakeAppConfig;
|
|
30
|
+
/** readConfigSnapshot, then configFromSnapshot. */
|
|
31
|
+
export declare function loadAppConfig(opts?: ReadSnapshotOptions): Promise<FoliwakeAppConfig>;
|
package/dist/resolve.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Where an app's config comes from: FOLIWAKE_URL (the site's discovery document) with an optional version 3
|
|
2
|
+
// file, or a version 2 file alone. The inputs are read once into a snapshot (plain JSON: an app framework can
|
|
3
|
+
// inline it at build time, so nothing is fetched at run time); the config is computed from the snapshot.
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { CONFIG_ENV, CONFIG_FILE, configFilePath, parseFoliwakeConfig } from './config.js';
|
|
7
|
+
import { parseOverrides, resolveConfig } from './config-v3.js';
|
|
8
|
+
import { fetchDiscovery, URL_ENV } from './discovery.js';
|
|
9
|
+
import { FoliwakeConfigError } from './errors.js';
|
|
10
|
+
export { PREVIEW_TOKEN_ENV } from './config-v3.js';
|
|
11
|
+
export { DISCOVERY_PATH, URL_ENV } from './discovery.js';
|
|
12
|
+
async function readOptionalFile(file, required) {
|
|
13
|
+
try {
|
|
14
|
+
return await readFile(file, 'utf8');
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
const code = error.code;
|
|
18
|
+
if (code === 'ENOENT' && !required)
|
|
19
|
+
return null;
|
|
20
|
+
if (code === 'ENOENT')
|
|
21
|
+
throw new FoliwakeConfigError(`${file} does not exist.`);
|
|
22
|
+
throw new FoliwakeConfigError(`Cannot read ${file}: ${error.message}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const NOTHING = `Set ${URL_ENV} to the site's live URL (https://…), ` + `or create ${CONFIG_FILE} (version 2) in the app's root.`;
|
|
26
|
+
/**
|
|
27
|
+
* Reads the inputs: FOLIWAKE_URL and its discovery document (fetched now), and the config file when there is one
|
|
28
|
+
* (a file named explicitly or by FOLIWAKE_REMOTE must exist). Throws FoliwakeConfigError.
|
|
29
|
+
*/
|
|
30
|
+
export async function readConfigSnapshot(opts = {}) {
|
|
31
|
+
const env = opts.env ?? process.env;
|
|
32
|
+
const url = env[URL_ENV]?.trim() || null;
|
|
33
|
+
const file = configFilePath({ cwd: opts.cwd, file: opts.file, env });
|
|
34
|
+
const named = opts.file !== undefined || env[CONFIG_ENV] !== undefined;
|
|
35
|
+
const text = await readOptionalFile(file, named);
|
|
36
|
+
if (url === null && text === null)
|
|
37
|
+
throw new FoliwakeConfigError(NOTHING);
|
|
38
|
+
const discovery = url === null ? null : await fetchDiscovery(url, opts);
|
|
39
|
+
return { url, discovery, file: text === null ? null : path.basename(file), text };
|
|
40
|
+
}
|
|
41
|
+
function versionOf(text) {
|
|
42
|
+
try {
|
|
43
|
+
const parsed = JSON.parse(text);
|
|
44
|
+
return typeof parsed === 'object' && parsed !== null ? parsed.version : undefined;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return undefined; // the parser names the problem
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function withVersion2(discovery, text, file) {
|
|
51
|
+
const config = parseFoliwakeConfig(text, { file });
|
|
52
|
+
if (config.site !== discovery.site) {
|
|
53
|
+
const text = `"site" is ${config.site}, but ${URL_ENV} serves the site ${discovery.site}.`;
|
|
54
|
+
throw new FoliwakeConfigError(`${file}: ${text} Make them agree, or drop one.`);
|
|
55
|
+
}
|
|
56
|
+
return config;
|
|
57
|
+
}
|
|
58
|
+
/** The app config of a snapshot (no I/O). Throws FoliwakeConfigError naming the field. */
|
|
59
|
+
export function configFromSnapshot(snapshot) {
|
|
60
|
+
const { discovery, text } = snapshot;
|
|
61
|
+
const file = snapshot.file ?? CONFIG_FILE;
|
|
62
|
+
if (discovery === null) {
|
|
63
|
+
if (text === null)
|
|
64
|
+
throw new FoliwakeConfigError(NOTHING);
|
|
65
|
+
return parseFoliwakeConfig(text, { file });
|
|
66
|
+
}
|
|
67
|
+
if (text === null)
|
|
68
|
+
return resolveConfig(discovery);
|
|
69
|
+
if (versionOf(text) === 2)
|
|
70
|
+
return withVersion2(discovery, text, file);
|
|
71
|
+
return resolveConfig(discovery, parseOverrides(text, file));
|
|
72
|
+
}
|
|
73
|
+
/** readConfigSnapshot, then configFromSnapshot. */
|
|
74
|
+
export async function loadAppConfig(opts = {}) {
|
|
75
|
+
return configFromSnapshot(await readConfigSnapshot(opts));
|
|
76
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SERVER_SDK = "@foliwake/server/__FOLIWAKE_SERVER_VERSION__";
|
package/dist/version.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foliwake/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Server toolkit for apps that show Foliwake pages: config v2, origin client, envelope read, page check and preparation, code/media proxy handlers, CSP. Web Request/Response, no framework.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"foliwake": {
|
|
34
34
|
"plain": 2,
|
|
35
35
|
"blocksContract": 2,
|
|
36
|
-
"remoteConfig":
|
|
36
|
+
"remoteConfig": 3,
|
|
37
|
+
"discovery": 1
|
|
37
38
|
},
|
|
38
39
|
"exports": {
|
|
39
40
|
"./config": {
|
|
@@ -68,13 +69,30 @@
|
|
|
68
69
|
"types": "./dist/hook.d.ts",
|
|
69
70
|
"default": "./dist/hook.js"
|
|
70
71
|
},
|
|
72
|
+
"./handler": {
|
|
73
|
+
"types": "./dist/handler.d.ts",
|
|
74
|
+
"default": "./dist/handler.js"
|
|
75
|
+
},
|
|
76
|
+
"./hook-endpoint": {
|
|
77
|
+
"types": "./dist/hook-endpoint.d.ts",
|
|
78
|
+
"default": "./dist/hook-endpoint.js"
|
|
79
|
+
},
|
|
80
|
+
"./discovery": {
|
|
81
|
+
"types": "./dist/discovery.d.ts",
|
|
82
|
+
"default": "./dist/discovery.js"
|
|
83
|
+
},
|
|
84
|
+
"./resolve": {
|
|
85
|
+
"types": "./dist/resolve.d.ts",
|
|
86
|
+
"default": "./dist/resolve.js"
|
|
87
|
+
},
|
|
71
88
|
"./schemas/remote-2.schema.json": "./schemas/remote-2.schema.json",
|
|
89
|
+
"./schemas/remote-3.schema.json": "./schemas/remote-3.schema.json",
|
|
72
90
|
"./package.json": "./package.json"
|
|
73
91
|
},
|
|
74
92
|
"dependencies": {
|
|
75
93
|
"htmlparser2": "10.1.0",
|
|
76
94
|
"jose": "6.2.15",
|
|
77
|
-
"@foliwake/blocks-contract": "0.
|
|
95
|
+
"@foliwake/blocks-contract": "0.10.0"
|
|
78
96
|
},
|
|
79
97
|
"files": [
|
|
80
98
|
"dist/",
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://foliwake.dev/schemas/remote-3.schema.json",
|
|
4
|
+
"title": "foliwake.remote.json version 3",
|
|
5
|
+
"description": "Optional overrides of an app configured by FOLIWAKE_URL: the site's discovery document (/.well-known/foliwake.json) gives its origins and media CDN; this file holds the app's own settings and the NAMES of the variables holding credentials. No secrets. The TypeScript parser (@foliwake/server/resolve) is the authority; test/server-config-v3.test.js keeps both in step.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"required": [
|
|
9
|
+
"version"
|
|
10
|
+
],
|
|
11
|
+
"properties": {
|
|
12
|
+
"$schema": {
|
|
13
|
+
"type": "string"
|
|
14
|
+
},
|
|
15
|
+
"$comment": {
|
|
16
|
+
"type": "string"
|
|
17
|
+
},
|
|
18
|
+
"version": {
|
|
19
|
+
"const": 3
|
|
20
|
+
},
|
|
21
|
+
"site": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "Checked against the discovery document's site."
|
|
24
|
+
},
|
|
25
|
+
"live": {
|
|
26
|
+
"$ref": "#/$defs/channel"
|
|
27
|
+
},
|
|
28
|
+
"preview": {
|
|
29
|
+
"$ref": "#/$defs/channel",
|
|
30
|
+
"description": "Default auth: Basic, user preview, password from FOLIWAKE_PREVIEW_TOKEN."
|
|
31
|
+
},
|
|
32
|
+
"app": {
|
|
33
|
+
"type": "object",
|
|
34
|
+
"additionalProperties": false,
|
|
35
|
+
"properties": {
|
|
36
|
+
"pages": {
|
|
37
|
+
"description": "Page globs the app may read (query-index grammar: [a-z0-9_-] literals, * within a segment, ** as a whole segment; /x/** also matches /x).",
|
|
38
|
+
"type": "array",
|
|
39
|
+
"minItems": 1,
|
|
40
|
+
"maxItems": 20,
|
|
41
|
+
"items": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"maxLength": 200,
|
|
44
|
+
"pattern": "^/(?:(?:\\*\\*|[a-z0-9_*-]+)(?:/(?:\\*\\*|[a-z0-9_*-]+))*)?$"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"proxies": {
|
|
48
|
+
"description": "App-origin URL prefixes of the proxies. Not /, /_next, /api, /code, /media or below them; code and media differ and neither is inside the other.",
|
|
49
|
+
"type": "object",
|
|
50
|
+
"additionalProperties": false,
|
|
51
|
+
"properties": {
|
|
52
|
+
"code": {
|
|
53
|
+
"$ref": "#/$defs/prefix",
|
|
54
|
+
"default": "/foliwake/code"
|
|
55
|
+
},
|
|
56
|
+
"media": {
|
|
57
|
+
"$ref": "#/$defs/prefix",
|
|
58
|
+
"default": "/foliwake/media"
|
|
59
|
+
},
|
|
60
|
+
"pages": {
|
|
61
|
+
"type": "null"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"blocks": {
|
|
66
|
+
"type": "object",
|
|
67
|
+
"additionalProperties": false,
|
|
68
|
+
"properties": {
|
|
69
|
+
"entry": {
|
|
70
|
+
"description": "Path of the blocks module inside a code release; absent or null: bodies stay static.",
|
|
71
|
+
"type": [
|
|
72
|
+
"string",
|
|
73
|
+
"null"
|
|
74
|
+
],
|
|
75
|
+
"pattern": "^(?:scripts|components|_foliwake)(?:/[A-Za-z0-9_][A-Za-z0-9_.-]*){1,7}\\.js$"
|
|
76
|
+
},
|
|
77
|
+
"contract": {
|
|
78
|
+
"type": "string",
|
|
79
|
+
"pattern": "^foliwake-blocks/[1-9][0-9]{0,2}$",
|
|
80
|
+
"default": "foliwake-blocks/2"
|
|
81
|
+
},
|
|
82
|
+
"eventPrefix": {
|
|
83
|
+
"type": "string",
|
|
84
|
+
"pattern": "^[a-z][a-z0-9-]{0,31}$",
|
|
85
|
+
"default": "block"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"media": {
|
|
90
|
+
"description": "Live pictures through a transforming host (preview pictures always go through the media proxy).",
|
|
91
|
+
"type": [
|
|
92
|
+
"object",
|
|
93
|
+
"null"
|
|
94
|
+
],
|
|
95
|
+
"additionalProperties": false,
|
|
96
|
+
"required": [
|
|
97
|
+
"base"
|
|
98
|
+
],
|
|
99
|
+
"properties": {
|
|
100
|
+
"base": {
|
|
101
|
+
"type": "string",
|
|
102
|
+
"pattern": "^https://[^/?#@]+$"
|
|
103
|
+
},
|
|
104
|
+
"transform": {
|
|
105
|
+
"enum": [
|
|
106
|
+
"cloudflare-images",
|
|
107
|
+
null
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
"revalidate": {
|
|
113
|
+
"description": "Seconds before a cached envelope is stale (stale-while-revalidate; expire is 24 h).",
|
|
114
|
+
"type": "integer",
|
|
115
|
+
"minimum": 1,
|
|
116
|
+
"maximum": 86400,
|
|
117
|
+
"default": 300
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"description": "The app's own decisions; every key is optional. Without pages: [\"/**\"] (required when live uses a service token). Without blocks: each page's code release names its blocks module (X-Foliwake-Blocks). Without media: the discovery document's media CDN, if any."
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"$defs": {
|
|
124
|
+
"prefix": {
|
|
125
|
+
"type": "string",
|
|
126
|
+
"pattern": "^(?:/[a-z0-9-]+)+$"
|
|
127
|
+
},
|
|
128
|
+
"basicAuth": {
|
|
129
|
+
"type": "object",
|
|
130
|
+
"additionalProperties": false,
|
|
131
|
+
"required": [
|
|
132
|
+
"type",
|
|
133
|
+
"username",
|
|
134
|
+
"passwordEnv"
|
|
135
|
+
],
|
|
136
|
+
"properties": {
|
|
137
|
+
"type": {
|
|
138
|
+
"const": "basic"
|
|
139
|
+
},
|
|
140
|
+
"username": {
|
|
141
|
+
"type": "string",
|
|
142
|
+
"minLength": 1,
|
|
143
|
+
"maxLength": 128,
|
|
144
|
+
"pattern": "^[^:\\u0000-\\u001f\\u007f]+$"
|
|
145
|
+
},
|
|
146
|
+
"passwordEnv": {
|
|
147
|
+
"type": "string",
|
|
148
|
+
"pattern": "^[A-Z_][A-Z0-9_]{0,127}$",
|
|
149
|
+
"description": "The NAME of the environment variable holding the password."
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
"serviceTokenAuth": {
|
|
154
|
+
"description": "Each request carries a fresh ES256 JWT for its exact path (exp = iat + 60), signed with the private key in privateKeyEnv; the delivery checks it with the public key of kid.",
|
|
155
|
+
"type": "object",
|
|
156
|
+
"additionalProperties": false,
|
|
157
|
+
"required": [
|
|
158
|
+
"type",
|
|
159
|
+
"issuer",
|
|
160
|
+
"kid",
|
|
161
|
+
"privateKeyEnv"
|
|
162
|
+
],
|
|
163
|
+
"properties": {
|
|
164
|
+
"type": {
|
|
165
|
+
"const": "service-token"
|
|
166
|
+
},
|
|
167
|
+
"issuer": {
|
|
168
|
+
"type": "string",
|
|
169
|
+
"pattern": "^[A-Za-z0-9._:/-]{1,256}$",
|
|
170
|
+
"description": "The iss the delivery expects (its TOKEN_ISSUER)."
|
|
171
|
+
},
|
|
172
|
+
"kid": {
|
|
173
|
+
"type": "string",
|
|
174
|
+
"pattern": "^[A-Za-z0-9._-]{1,128}$",
|
|
175
|
+
"description": "The key id of the public key the delivery holds."
|
|
176
|
+
},
|
|
177
|
+
"privateKeyEnv": {
|
|
178
|
+
"type": "string",
|
|
179
|
+
"pattern": "^[A-Z_][A-Z0-9_]{0,127}$",
|
|
180
|
+
"description": "The NAME of the environment variable holding the ES256 private key as JWK JSON text."
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
"channel": {
|
|
185
|
+
"type": "object",
|
|
186
|
+
"additionalProperties": false,
|
|
187
|
+
"properties": {
|
|
188
|
+
"auth": {
|
|
189
|
+
"oneOf": [
|
|
190
|
+
{
|
|
191
|
+
"type": "null"
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"$ref": "#/$defs/basicAuth"
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
"$ref": "#/$defs/serviceTokenAuth"
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|