@foliwake/server 0.3.0 → 0.5.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 CHANGED
@@ -7,6 +7,47 @@ minor release may break; breaking changes are marked **BREAKING**.
7
7
 
8
8
  Entries are written from the changesets of each pull request (`.changeset/`, CONTRIBUTING.md), newest first.
9
9
 
10
+ ## 0.5.0
11
+
12
+ ### Patch Changes
13
+
14
+ - fa06260: The `homepage` of every package is its page on the public SDK documentation site,
15
+ `https://sdk.foliwake.dev/reference/packages/<name>`. No API change.
16
+ - Updated dependencies [fa06260]
17
+ - @foliwake/blocks-contract@0.5.0
18
+
19
+ ## 0.4.0
20
+
21
+ ### Minor Changes
22
+
23
+ - 70af3e5: **BREAKING**: the old forms are removed; only the current ones remain.
24
+
25
+ - The kit's only specifier is `@foliwake/block-kit`. The import map of a code release no longer maps
26
+ `foliwake`; `LEGACY_KIT_SPECIFIER` and `KIT_SPECIFIERS` are removed from `@foliwake/blocks-contract/import-map`
27
+ (use `KIT_SPECIFIER`). `@foliwake/site-check` refuses a bare `foliwake` import, preload hints follow only
28
+ `@foliwake/block-kit`, and new projects map only `@foliwake/block-kit` (jsconfig, Storybook).
29
+ - `@foliwake/block-kit/block-kit-1.js` (the kit of blocks contract 1) is removed, with its `exports` entry;
30
+ `@foliwake/site-check` no longer treats `_foliwake/block-kit-1.js` as an engine file, and the Storybook
31
+ starter no longer aliases relative `_foliwake/` imports.
32
+ - An origin answer without `X-Code-Release` is an error (`FoliwakePageError` `invalid`), not a body shown
33
+ without blocks. `codeRelease` of `PageEnvelope` and `FoliwakePageData` is `CodeReleaseId` (never null),
34
+ and the client error code `NO_CODE_RELEASE` is removed.
35
+ - A `foliwake.remote.json` with any `version` other than 2 is refused with one "unsupported version" error.
36
+
37
+ Added (not breaking): `defineBlock(name, setup, { autoReady: false })` in `@foliwake/block-kit`. The kit then
38
+ sends `ready` only when the block sends it (`ctx.emit('ready', …)`), so a setup that cannot run leaves the root
39
+ without `ready`. The default (`autoReady: true`) is unchanged: after a setup that did not send `ready`, the kit
40
+ sends it.
41
+
42
+ ### Patch Changes
43
+
44
+ - 1cc3743: Documentation: the READMEs name the kit's specifier `@foliwake/block-kit` everywhere, link to sibling
45
+ packages instead of guides that are not public, and say which features need the Foliwake CLI, which is not
46
+ public yet. The `@foliwake/next` README shows how to write the cached read yourself. The starters' loader comment names HTML contract 2. No API change.
47
+ - Updated dependencies [1cc3743]
48
+ - Updated dependencies [70af3e5]
49
+ - @foliwake/blocks-contract@0.4.0
50
+
10
51
  ## 0.3.0
11
52
 
12
53
  ### Minor Changes
package/README.md CHANGED
@@ -48,7 +48,7 @@ The config file sits in the app's root and holds no secrets, only the names of t
48
48
  ```
49
49
 
50
50
  An endpoint is open (no `auth`), behind HTTP Basic (`"type": "basic"`), or behind a delivery that checks
51
- service tokens, such as the Cloudflare Worker (`packages/worker-origin`):
51
+ service tokens (for example an edge worker in front of the site's storage):
52
52
 
53
53
  ```json
54
54
  "live": {
@@ -172,8 +172,8 @@ export const settingsForBrowser = clientSettings(config);
172
172
  | | |
173
173
  | --- | --- |
174
174
  | Node.js | 22.22 or newer (Web `fetch`, `Request`, `Response`, streams) |
175
- | Foliwake origin | sends `X-Code-Release` with `.plain.html` (plain/2); a plain/1 origin gives bodies without blocks |
176
- | Config | `foliwake.remote.json` version 2 (version 1 files are refused) |
175
+ | Foliwake origin | plain/2: `X-Code-Release` with every `.plain.html` (a body without it is refused) |
176
+ | Config | `foliwake.remote.json` version 2 |
177
177
  | Blocks contract | `foliwake-blocks/2` |
178
178
 
179
179
  Changes per version, breaking ones marked: `CHANGELOG.md` in the package
@@ -194,11 +194,12 @@ Changes per version, breaking ones marked: `CHANGELOG.md` in the package
194
194
  - `preparePage` leaves `page.preload` empty; `preloadHints` fills it from the release's
195
195
  `components/components.json` (only blocks that declare a `.js` or `.css` get hints).
196
196
 
197
- ## Guides
197
+ ## See also
198
198
 
199
- - [Embed Foliwake pages in a React or Next app](https://docs.foliwake.dev/guide/embed-in-react): config keys,
200
- proxies, caching and troubleshooting.
201
- - [Configuration and storage](https://docs.foliwake.dev/guide/configuration-storage)
199
+ - [`@foliwake/next`](https://www.npmjs.com/package/@foliwake/next): this toolkit wired into a Next.js App
200
+ Router app.
201
+ - [`@foliwake/client`](https://www.npmjs.com/package/@foliwake/client) and
202
+ [`@foliwake/react`](https://www.npmjs.com/package/@foliwake/react): mount the prepared page in the browser.
202
203
 
203
204
  License: Apache-2.0.
204
205
 
@@ -557,10 +558,10 @@ interface OriginRequestOptions
557
558
 
558
559
  #### `blocksUrlOf()`
559
560
 
560
- The same-origin URL of the blocks module, or null (no entry, no code release, or `local` from a remote origin).
561
+ The same-origin URL of the blocks module, or null when the config names no blocks entry.
561
562
 
562
563
  ```ts
563
- function blocksUrlOf(config: FoliwakeAppConfig, channel: ChannelName, codeRelease: CodeReleaseId | null): {
564
+ function blocksUrlOf(config: FoliwakeAppConfig, channel: ChannelName, codeRelease: CodeReleaseId): {
564
565
  base: string;
565
566
  url: string;
566
567
  } | null
@@ -981,7 +982,7 @@ function resolveInRelease(from: string, specifier: string): string | null
981
982
 
982
983
  #### `staticImports()`
983
984
 
984
- The relative static import specifiers of an ES module's text, and the kit's (KIT_SPECIFIERS).
985
+ The relative static import specifiers of an ES module's text, and the kit's (KIT_SPECIFIER).
985
986
 
986
987
  ```ts
987
988
  function staticImports(source: string): string[]
package/dist/config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // `foliwake.remote.json` version 2 (schema schemas/remote-2.schema.json):
2
2
  // which Foliwake site an app reads, with which credential NAMES, and the app's settings. One parser for the
3
- // engine CLI (`foliwake dev --remote`) and the app packages. Version 1 is no longer read.
3
+ // engine CLI (`foliwake dev --remote`) and the app packages.
4
4
  //
5
5
  // No secrets: anything that looks like a stored secret refuses the file; credentials are variable names,
6
6
  // read on the server per origin request (./origin), never logged, never sent to a browser.
@@ -235,6 +235,9 @@ function parseApp(value, where) {
235
235
  revalidate,
236
236
  };
237
237
  }
238
+ function unsupportedVersion(file, version) {
239
+ return new FoliwakeConfigError(`${file}: unsupported "version" ${JSON.stringify(version)}; it must be 2.`);
240
+ }
238
241
  /** Parses the text of a version 2 config. Throws FoliwakeConfigError with a message that names the field. */
239
242
  export function parseFoliwakeConfig(text, opts = {}) {
240
243
  const file = opts.file ?? CONFIG_FILE;
@@ -249,11 +252,8 @@ export function parseFoliwakeConfig(text, opts = {}) {
249
252
  throw new FoliwakeConfigError(`${file} must be a JSON object {"version": 2, "site": …, "live": …, "preview": …, "app": …}.`);
250
253
  refuseSecrets(parsed, '', file);
251
254
  onlyKeys(parsed, ['$schema', '$comment', 'version', 'site', 'live', 'preview', 'app'], file);
252
- if (parsed.version === 1) {
253
- throw new FoliwakeConfigError(`${file}: version 1 is no longer read. Rewrite it as version 2: add "version": 2 and "site": "<site name>" (docs: website/guide/embed-in-react.md, "The config file").`);
254
- }
255
255
  if (parsed.version !== 2)
256
- throw new FoliwakeConfigError(`${file}: "version" must be 2.`);
256
+ throw unsupportedVersion(file, parsed.version);
257
257
  if (typeof parsed.site !== 'string' || !SITE.test(parsed.site))
258
258
  throw new FoliwakeConfigError(`${file} "site": the site name, [a-z0-9-], such as "my-site".`);
259
259
  const live = parsed.live === undefined ? null : parseEndpoint(parsed.live, `${file} "live"`, opts);
package/dist/page.d.ts CHANGED
@@ -28,8 +28,8 @@ export interface PrepareOptions {
28
28
  /** The app's own change of the body (allow-list, artwork, …); its output is checked again. */
29
29
  transform?: (html: string, envelope: PageEnvelope) => string;
30
30
  }
31
- /** The same-origin URL of the blocks module, or null (no entry, no code release, or `local` from a remote origin). */
32
- export declare function blocksUrlOf(config: FoliwakeAppConfig, channel: ChannelName, codeRelease: CodeReleaseId | null): {
31
+ /** The same-origin URL of the blocks module, or null when the config names no blocks entry. */
32
+ export declare function blocksUrlOf(config: FoliwakeAppConfig, channel: ChannelName, codeRelease: CodeReleaseId): {
33
33
  base: string;
34
34
  url: string;
35
35
  } | null;
package/dist/page.js CHANGED
@@ -29,17 +29,17 @@ function header(response, name, pattern, required = false) {
29
29
  throw new FoliwakePageError('invalid', `The origin answered an invalid ${name}.`);
30
30
  return value;
31
31
  }
32
+ const NO_CODE_RELEASE = 'The origin answered without X-Code-Release: it is not a plain/2 Foliwake origin.';
32
33
  function codeReleaseOf(response, client, channel) {
33
34
  const value = response.headers.get('x-code-release');
34
35
  if (value === null)
35
- return null; // plain/1 origin: the body is shown static
36
+ throw new FoliwakePageError('invalid', NO_CODE_RELEASE);
36
37
  if (CODE_ID_PATTERN.test(value))
37
38
  return value;
38
39
  if (value === 'local' && isLoopbackName(new URL(client.originOf(channel)).hostname))
39
40
  return 'local';
40
41
  throw new FoliwakePageError('invalid', 'The origin answered an invalid X-Code-Release.');
41
42
  }
42
- let warnedPlain1 = false;
43
43
  /**
44
44
  * Reads `<path>.plain.html` from the channel's origin. Primitive inputs only, no callbacks and no signal
45
45
  * (an internal 10 s timeout), so it can run inside a cache function. Refuses paths outside `app.pages`.
@@ -106,10 +106,6 @@ export async function readEnvelope(config, client, site, channel, path) {
106
106
  throw new FoliwakePageError('invalid', 'The body is not UTF-8.');
107
107
  }
108
108
  checkBody(html, path); // an invalid body is refused before anything caches it
109
- if (codeRelease === null && !warnedPlain1) {
110
- warnedPlain1 = true;
111
- console.warn(`[foliwake] the ${channel} site sends no X-Code-Release (plain/1): bodies are shown without blocks.`);
112
- }
113
109
  return { site, channel, path, html, codeRelease, htmlContract, lang, pageId, etag: etag && etag.length <= 200 ? etag : null, generation };
114
110
  }
115
111
  function rewrite(nodes, config, channel, rewriteLink) {
@@ -131,14 +127,19 @@ function rewrite(nodes, config, channel, rewriteLink) {
131
127
  }
132
128
  }
133
129
  }
134
- /** The same-origin URL of the blocks module, or null (no entry, no code release, or `local` from a remote origin). */
130
+ /** The same-origin URL of the blocks module, or null when the config names no blocks entry. */
135
131
  export function blocksUrlOf(config, channel, codeRelease) {
136
132
  const app = appOf(config);
137
- if (!app.blocks.entry || !codeRelease)
133
+ if (!app.blocks.entry)
138
134
  return null;
139
135
  const base = `${app.proxies.code}${channel === 'preview' ? '/preview' : ''}/${codeRelease}/`;
140
136
  return { base, url: `${base}${app.blocks.entry}` };
141
137
  }
138
+ /** The React key of a prepared page: see `FoliwakePageData.identity`. */
139
+ function identityOf(envelope, mode, digest) {
140
+ const { site, channel, path, etag, codeRelease } = envelope;
141
+ return [site, channel, path, etag ?? '', codeRelease, mode ?? '', digest].join('|');
142
+ }
142
143
  /**
143
144
  * Per request, after the cache: check → rewrite media/links → transform → check again → serialise.
144
145
  *
@@ -169,7 +170,7 @@ export function preparePage(config, envelope, opts = {}) {
169
170
  .digest('base64url')
170
171
  .slice(0, 22);
171
172
  return {
172
- identity: [envelope.site, envelope.channel, envelope.path, envelope.etag ?? '', envelope.codeRelease ?? '', mode ?? '', digest].join('|'),
173
+ identity: identityOf(envelope, mode, digest),
173
174
  site: envelope.site,
174
175
  channel: envelope.channel,
175
176
  path: envelope.path,
package/dist/preload.d.ts CHANGED
@@ -6,7 +6,7 @@ export type { PreloadHint } from '@foliwake/blocks-contract/page';
6
6
  export declare function codePath(relative: string): string | null;
7
7
  /** Resolves `specifier` against the module at `from` (both inside the release), or null when it leaves it. */
8
8
  export declare function resolveInRelease(from: string, specifier: string): string | null;
9
- /** The relative static import specifiers of an ES module's text, and the kit's (KIT_SPECIFIERS). */
9
+ /** The relative static import specifiers of an ES module's text, and the kit's (KIT_SPECIFIER). */
10
10
  export declare function staticImports(source: string): string[];
11
11
  /** Hints for a prepared page: modulepreload for its modules, preload as=style for its block stylesheets. */
12
12
  export declare function preloadHints(config: FoliwakeAppConfig, client: OriginClient, page: FoliwakePageData): Promise<PreloadHint[]>;
package/dist/preload.js CHANGED
@@ -6,12 +6,12 @@
6
6
  // - `components/components.json` says which blocks have a .js and a .css;
7
7
  // - each module's static relative imports are followed (`import … from "./x.js"`, `import "./x.js"`,
8
8
  // `export … from "./x.js"`; dynamic import() is not followed), depth ≤ 4, at most 48 modules. The kit's
9
- // specifiers (`@foliwake/block-kit`, and `foliwake` while it is mapped) are the release's block-kit (the
10
- // page's import map maps them to `_foliwake/block-kit.js`).
9
+ // specifier (`@foliwake/block-kit`) is the release's block-kit (the page's import map maps it to
10
+ // `_foliwake/block-kit.js`).
11
11
  // A code release is immutable, so results are kept in memory per (channel, code release, file). Hints are an
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
- import { KIT_PATH, KIT_SPECIFIERS } from '@foliwake/blocks-contract/import-map';
14
+ import { KIT_PATH, KIT_SPECIFIER } from '@foliwake/blocks-contract/import-map';
15
15
  import { appOf } from './config.js';
16
16
  import { CODE_ROOTS, CODE_SEGMENT } from './constants.js';
17
17
  import { readLimited } from './stream.js';
@@ -20,10 +20,9 @@ const MAX_DEPTH = 4;
20
20
  const FILE_LIMIT = 1024 * 1024;
21
21
  const CACHE_LIMIT = 2048;
22
22
  const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&');
23
- const KIT_ALTERNATIVES = KIT_SPECIFIERS.map(escapeRegExp).join('|');
24
23
  /** A static `import`/`export … from` of a relative module or of the kit. */
25
24
  const IMPORT_HEAD = '(?:^|[;\\s}])(?:import|export)\\s*(?:[\\w$*{}\\s,]*?\\s*from\\s*)?';
26
- const STATIC_IMPORT = new RegExp(`${IMPORT_HEAD}["'](\\.{1,2}\\/[^"'\\s]+|${KIT_ALTERNATIVES})["']`, 'g');
25
+ const STATIC_IMPORT = new RegExp(`${IMPORT_HEAD}["'](\\.{1,2}\\/[^"'\\s]+|${escapeRegExp(KIT_SPECIFIER)})["']`, 'g');
27
26
  const files = new Map();
28
27
  function remember(key, value) {
29
28
  if (files.size >= CACHE_LIMIT)
@@ -42,14 +41,14 @@ export function codePath(relative) {
42
41
  }
43
42
  /** Resolves `specifier` against the module at `from` (both inside the release), or null when it leaves it. */
44
43
  export function resolveInRelease(from, specifier) {
45
- if (KIT_SPECIFIERS.includes(specifier))
44
+ if (specifier === KIT_SPECIFIER)
46
45
  return KIT_PATH;
47
46
  const url = new URL(specifier, `https://release.invalid/${from}`);
48
47
  if (url.origin !== 'https://release.invalid' || url.search || url.hash)
49
48
  return null;
50
49
  return codePath(url.pathname.slice(1));
51
50
  }
52
- /** The relative static import specifiers of an ES module's text, and the kit's (KIT_SPECIFIERS). */
51
+ /** The relative static import specifiers of an ES module's text, and the kit's (KIT_SPECIFIER). */
53
52
  export function staticImports(source) {
54
53
  const out = new Set();
55
54
  for (const match of source.matchAll(STATIC_IMPORT))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foliwake/server",
3
- "version": "0.3.0",
3
+ "version": "0.5.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",
@@ -13,7 +13,7 @@
13
13
  "url": "git+https://github.com/foliwake/foliwake-js.git",
14
14
  "directory": "packages/server"
15
15
  },
16
- "homepage": "https://docs.foliwake.dev/reference/packages/server",
16
+ "homepage": "https://sdk.foliwake.dev/reference/packages/server",
17
17
  "bugs": {
18
18
  "url": "https://github.com/foliwake/foliwake-js/issues"
19
19
  },
@@ -70,7 +70,7 @@
70
70
  "dependencies": {
71
71
  "htmlparser2": "10.1.0",
72
72
  "jose": "6.2.15",
73
- "@foliwake/blocks-contract": "0.3.0"
73
+ "@foliwake/blocks-contract": "0.5.0"
74
74
  },
75
75
  "files": [
76
76
  "dist/",