@plitzi/sdk-server 0.38.8 → 0.38.9
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 +65 -0
- package/README.md +6 -1
- package/dist/core/createServer.notFound.test.d.ts +1 -0
- package/dist/core/oauth/consentPage.js +1 -9
- package/dist/core/unusedPort.d.ts +6 -0
- package/dist/core/unusedPort.js +20 -0
- package/dist/helpers/compress.js +1 -1
- package/dist/helpers/escapeHtml.d.ts +2 -0
- package/dist/helpers/escapeHtml.js +13 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/modules/actions/runtime/errors.d.ts +6 -0
- package/dist/modules/actions/runtime/errors.js +7 -1
- package/dist/modules/actions/runtime/runAction.js +2 -2
- package/dist/modules/functions/routes.js +2 -2
- package/dist/modules/project/serveProject.js +40 -12
- package/dist/modules/project/spaceFailure.d.ts +8 -0
- package/dist/modules/project/spaceFailure.js +76 -0
- package/dist/modules/runtime/runner.d.ts +1 -0
- package/dist/modules/runtime/runner.js +2 -3
- package/dist/modules/ssr/applySSRResult.d.ts +11 -0
- package/dist/modules/ssr/applySSRResult.js +14 -1
- package/dist/modules/ssr/buildBody.js +2 -0
- package/dist/modules/ssr/handler.js +2 -2
- package/dist/modules/ssr/prepareRender.d.ts +2 -0
- package/dist/modules/ssr/prepareRender.js +9 -3
- package/dist/modules/ssr/streamBody.js +3 -2
- package/package.json +3 -3
- package/skills/plitzi-authoring/recipes/detail-page.ts +4 -2
- package/skills/plitzi-authoring/reference/accessibility.md +2 -0
- package/skills/plitzi-authoring/reference/authoring-errors.md +3 -0
- package/skills/plitzi-authoring/reference/flows.md +2 -2
- package/skills/plitzi-authoring/reference/layouts.md +18 -0
- package/skills/plitzi-authoring/reference/recipes.md +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,70 @@
|
|
|
1
1
|
# @plitzi/sdk-server
|
|
2
2
|
|
|
3
|
+
## 0.38.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 64f4cd6: - **`unusedPort()`** (`@plitzi/sdk-server`): a port the system has just handed out, for a test to listen on. The
|
|
8
|
+
package's own tests and `@plitzi/sdk-mcp`'s listened on fixed ports in the ephemeral range (393xx), which any
|
|
9
|
+
outgoing connection of a test running beside them could take: CI failed with `EADDRINUSE` on runs with nothing
|
|
10
|
+
wrong. Every one now listens on a port the system gives it.
|
|
11
|
+
- **Brotli at quality 5** (`@plitzi/sdk-server`): `compression.brotliQuality`, for a page rendered for one request, is
|
|
12
|
+
5 (was 2). At 2 a 220 KB page came out larger than gzip — 36 KB against 31 — and at 5 it is 29 KB, for the CPU gzip
|
|
13
|
+
spends; on half a core ~0.1 ms a page.
|
|
14
|
+
- **`verify` checks the pages for signed-in visitors** (`@plitzi/cli`): a page that sends the browser to sign in is
|
|
15
|
+
checked again signed in as the account `.env` names — `PLITZI_CHECK_USER`, `PLITZI_CHECK_PASSWORD` (the environment
|
|
16
|
+
wins over `.env`). With none named, `verify` says how. `page check --as` reads the password from `.env` too, and
|
|
17
|
+
`page check` takes several pages, in one browser.
|
|
18
|
+
- **An address that shows nothing answers 404** (`@plitzi/sdk-shared`, `@plitzi/plitzi-sdk`, `@plitzi/sdk-server`):
|
|
19
|
+
one no page answers was sent to the home page with a 302 — every typo read as the home page. A page whose slug is
|
|
20
|
+
`'*'` is now the space's page for it, sent with status 404 (a folder may have its own; the deepest wins), and a page
|
|
21
|
+
gated off by a flag shows it too. Never kept in the page cache: an address asked for at random filled it. Only a slug
|
|
22
|
+
that IS `'*'`: a page answering a subtree by its own (`spaces/:spaceId/update/*`) stays a page like any other.
|
|
23
|
+
- **`authorSpace` gives a space with no `'*'` page a plain one** (`@plitzi/sdk-authoring`), in the home page's layout,
|
|
24
|
+
and says so: suggestion `not-found-page`. The project templates carry their own.
|
|
25
|
+
- **`notFound` on a server provider** (`@plitzi/sdk-elements`, `@plitzi/sdk-server`): an expression against its answer
|
|
26
|
+
(`{{ source.found == false }}`); when it is true the page is sent with status 404, rendered as written. Refused on a
|
|
27
|
+
browser provider (`not-found-in-browser`) and when it is not one expression (`not-found-not-a-template`).
|
|
28
|
+
- **`page check` and `verify` know a page sent with 404** (`@plitzi/cli`): it is said, not failed; the space's `'*'`
|
|
29
|
+
page is checked at an address no page has, and fails if it is not sent with 404.
|
|
30
|
+
- **A form field draws no background of its own** (`@plitzi/sdk-elements`): the `<input>` inside a form control's box
|
|
31
|
+
(`field`) took `background-color: inherit`, and painted a translucent box colour a second time — a darker box inside
|
|
32
|
+
the padding (Tremor's search). It is `transparent`: the box shows through it.
|
|
33
|
+
- **`space lint` offers `quiet` only where there is an element to put it on** (`@plitzi/cli`): a suggestion about what
|
|
34
|
+
the space lacks — `not-found-page` — is answered by writing it.
|
|
35
|
+
- **`feedback --previous`** (`@plitzi/cli`): the brief says what to do when an earlier report's link no longer opens —
|
|
36
|
+
say so, and ask the person for the highest id it had.
|
|
37
|
+
- **`start:prod` runs in production by itself** (`@plitzi/cli`): `NODE_ENV=production node …`. Without the variable a
|
|
38
|
+
deployed project was a development server — dev tools on, and every public action answering its `steps` and `trace`
|
|
39
|
+
(each step's result, what the `output` was meant to leave out). `doctor` says a `start:prod` that does not
|
|
40
|
+
(`start-prod-not-production`); `plitzi upgrade --write` rewrites the script.
|
|
41
|
+
- **A project's `ActionRefusal` reaches the flow** (`@plitzi/sdk-server`): a functions bundle carries its own copy of the
|
|
42
|
+
class, so `instanceof` never knew it and the run lost its reason (`{{ x.error }}` empty). Told apart by name now.
|
|
43
|
+
- **Plugins are not remounted after hydration** (`@plitzi/sdk-elements`): the registry wrapped each plugin again when
|
|
44
|
+
the host handed it over again, a new component type every time — the server's HTML thrown away, entrances replayed,
|
|
45
|
+
effects run twice. Each plugin component is wrapped once.
|
|
46
|
+
- **`start:dev` survives a space that does not author** (`@plitzi/sdk-server`): a restart while the space had an error
|
|
47
|
+
died, and fixing the space woke nothing. It comes up answering every page with what is wrong (503), and loads the
|
|
48
|
+
space the first time a save authors.
|
|
49
|
+
- **`page check` sees what is cut off at the screen's edge** (`@plitzi/sdk-authoring`, `@plitzi/cli`): a link or words an
|
|
50
|
+
ancestor hides past the viewport, which no sideways scroll shows (`cut-off`).
|
|
51
|
+
- **`page shot --click <element...> --sheet`** (`@plitzi/cli`): elements clicked in order — a name or a CSS selector,
|
|
52
|
+
inside a plugin too — pictured after each (`--frames`/`--every`), with how much changed, and every picture on one
|
|
53
|
+
contact sheet. The dev tools' badge is no longer in a picture: its shadow root is marked (`@plitzi/sdk-dev-tools`).
|
|
54
|
+
- **`formControl` is optional unless it says `required: true`** (`@plitzi/sdk-elements`), as an HTML field is. A field
|
|
55
|
+
left without `required` in an older space was required, and is not now.
|
|
56
|
+
- **`text({ decorative })`, `list({ label })`** (`@plitzi/sdk-elements`); **`writing-mode`, `text-orientation`** in the
|
|
57
|
+
CSS vocabulary (`@plitzi/sdk-shared`).
|
|
58
|
+
- **`unused-token` reads the plugins' stylesheets** (`@plitzi/sdk-authoring`): `authorSpace`'s `stylesheets`, which
|
|
59
|
+
`projectAuthoring` fills with every `.css` under `src/plugins/` — a token only a plugin used was said to be unused.
|
|
60
|
+
- **`id-taken` on a provider placed on two pages points at the layout they share** (`@plitzi/sdk-authoring`), not at
|
|
61
|
+
`scope()`, which renamed its source and every template reading it.
|
|
62
|
+
- **The welcome template's tokens keep their names** (`@plitzi/sdk-authoring`): `satisfies`, not an annotation, so
|
|
63
|
+
`tokens(variables).card` typechecks as the cheatsheet teaches.
|
|
64
|
+
- Updated dependencies [64f4cd6]
|
|
65
|
+
- @plitzi/sdk-shared@0.38.9
|
|
66
|
+
- @plitzi/plitzi-sdk@0.38.9
|
|
67
|
+
|
|
3
68
|
## 0.38.8
|
|
4
69
|
|
|
5
70
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -400,6 +400,11 @@ Beside the page adapters it offers `getSchema` and `getStyle`, read from the sam
|
|
|
400
400
|
path, or a function that may answer one — `saveSchema` and `saveStyle`, each writing its document back into the file. So an MCP server
|
|
401
401
|
([`@plitzi/sdk-mcp`](../mcp/README.md#adapters)) can run over it, with a `getGrant` of yours beside it.
|
|
402
402
|
|
|
403
|
+
In a test, listen on `await unusedPort()`: a port the system has just handed out, never a fixed number — one in the
|
|
404
|
+
system's ephemeral range can be taken by any outgoing connection of a test running beside it, and the listen fails with
|
|
405
|
+
`EADDRINUSE` on a run with nothing wrong. (`freePort(8080)` is the development server's: the next free one from a port
|
|
406
|
+
people expect.)
|
|
407
|
+
|
|
403
408
|
### `JsonAdaptersConfig`
|
|
404
409
|
|
|
405
410
|
| Option | Type | Description |
|
|
@@ -573,7 +578,7 @@ createServer({ compression: false, adapters });
|
|
|
573
578
|
|---|---|---|---|
|
|
574
579
|
| `encodings` | `('br' \| 'gzip')[]` | `['br', 'gzip']` | What this server offers, most preferred first; the first one the client accepts wins. `[]` disables compression. |
|
|
575
580
|
| `threshold` | `number` | `1024` | Responses smaller than this many bytes go out uncompressed. |
|
|
576
|
-
| `brotliQuality` | `number` | `
|
|
581
|
+
| `brotliQuality` | `number` | `5` | Brotli quality, 0–11, for a body compressed on every request (a page rendered for that request alone). The first quality under gzip's size for the CPU gzip spends: at 2 a 220 KB page came out larger than gzip (36 KB against 31; 29 at 5). On half a core it costs ~0.1 ms a page — 5–8% of the pages a second of a 6 KB page. |
|
|
577
582
|
| `keptBrotliQuality` | `number` | `6` | Brotli quality for a body compressed once and kept: a cached page, a static file such as the SDK bundle. Paid once; the bundle comes out 10% smaller than at 4, for the same memory. 9 needs ~40 MB more to compress the bundle, which a 128 MB server does not have. |
|
|
578
583
|
| `gzipLevel` | `number` | `6` | Gzip level, 0–9. |
|
|
579
584
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
+
import { escapeHtml } from "../../helpers/escapeHtml.js";
|
|
1
2
|
//#region src/core/oauth/consentPage.ts
|
|
2
|
-
var escapeHtml = (value) => value.replace(/[&<>"']/gu, (character) => {
|
|
3
|
-
switch (character) {
|
|
4
|
-
case "&": return "&";
|
|
5
|
-
case "<": return "<";
|
|
6
|
-
case ">": return ">";
|
|
7
|
-
case "\"": return """;
|
|
8
|
-
default: return "'";
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
3
|
var STYLES = `
|
|
12
4
|
:root { color-scheme: light dark; --bg: #f6f7f9; --panel: #ffffff; --ink: #16181d; --muted: #6b7280;
|
|
13
5
|
--line: #e2e5ea; --accent: #2563eb; --danger: #b91c1c; }
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A port the system has just handed out and nobody holds — what a test listens on. Never a fixed number: one in the
|
|
3
|
+
* system's ephemeral range (above 32768 on Linux) can be taken by any outgoing connection of a test running beside it,
|
|
4
|
+
* and the listen fails with `EADDRINUSE` on a run that has nothing wrong with it.
|
|
5
|
+
*/
|
|
6
|
+
export declare const unusedPort: (host?: string) => Promise<number>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createServer } from "node:net";
|
|
2
|
+
//#region src/core/unusedPort.ts
|
|
3
|
+
/**
|
|
4
|
+
* A port the system has just handed out and nobody holds — what a test listens on. Never a fixed number: one in the
|
|
5
|
+
* system's ephemeral range (above 32768 on Linux) can be taken by any outgoing connection of a test running beside it,
|
|
6
|
+
* and the listen fails with `EADDRINUSE` on a run that has nothing wrong with it.
|
|
7
|
+
*/
|
|
8
|
+
var unusedPort = (host = "127.0.0.1") => new Promise((resolve, reject) => {
|
|
9
|
+
const probe = createServer();
|
|
10
|
+
probe.once("error", reject);
|
|
11
|
+
probe.listen(0, host, () => {
|
|
12
|
+
const address = probe.address();
|
|
13
|
+
probe.close(() => {
|
|
14
|
+
if (typeof address === "object" && address) resolve(address.port);
|
|
15
|
+
else reject(/* @__PURE__ */ new Error(`The system gave no port on ${host}`));
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
//#endregion
|
|
20
|
+
export { unusedPort };
|
package/dist/helpers/compress.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/helpers/escapeHtml.ts
|
|
2
|
+
/** Text set inside HTML as text: never markup, whatever it holds. */
|
|
3
|
+
var escapeHtml = (value) => value.replace(/[&<>"']/gu, (character) => {
|
|
4
|
+
switch (character) {
|
|
5
|
+
case "&": return "&";
|
|
6
|
+
case "<": return "<";
|
|
7
|
+
case ">": return ">";
|
|
8
|
+
case "\"": return """;
|
|
9
|
+
default: return "'";
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
//#endregion
|
|
13
|
+
export { escapeHtml };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { createServer, resolveServices } from './core/createServer';
|
|
|
2
2
|
export { closeOnSignals } from './core/server/closeOnSignals';
|
|
3
3
|
export { loadFunctions, loadFunctionsSource, readFunctionsDir } from './modules/functions/load';
|
|
4
4
|
export { freePort } from './core/freePort';
|
|
5
|
+
export { unusedPort } from './core/unusedPort';
|
|
5
6
|
export { registerHealthCheck, buildHealthPayload } from './core/health';
|
|
6
7
|
export { consoleLogger, isLogged, logLevelOf, renderLogEvent, serverLog } from './helpers/serverLog';
|
|
7
8
|
export type { HealthCheckApp, HealthIdentity } from './core/health';
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { buildHealthPayload, registerHealthCheck } from "./core/health.js";
|
|
|
11
11
|
import { createServer } from "./core/createServer.js";
|
|
12
12
|
import { closeOnSignals } from "./core/server/closeOnSignals.js";
|
|
13
13
|
import { freePort } from "./core/freePort.js";
|
|
14
|
+
import { unusedPort } from "./core/unusedPort.js";
|
|
14
15
|
import { createCloudAdapters } from "./adapters/cloudAdapters.js";
|
|
15
16
|
import { createJsonAdapters } from "./adapters/jsonAdapters.js";
|
|
16
17
|
import { createAuthAdapters } from "./adapters/authAdapters.js";
|
|
@@ -19,4 +20,4 @@ import { authoringPreview, fixedSpace, presentsCredential, verifiedDomain, wildc
|
|
|
19
20
|
import { createSpaceAdapters } from "./adapters/space/index.js";
|
|
20
21
|
import { createLocalFontStore, hostedPathsOf } from "./core/fontStore.js";
|
|
21
22
|
import { createRedisPubSub } from "./modules/realtime/redisPubSub.js";
|
|
22
|
-
export { PREVIEW_TOKEN_PARAM, authoringPreview, buildHealthPayload, closeOnSignals, consoleLogger, createAuthAdapters, createCloudAdapters, createConnectorResolver, createJsonAdapters, createLocalFontStore, createMemoryCache, createMemoryDraftStore, createMemoryPubSub, createRedisPubSub, createServer, createSpaceAdapters, fetchConnectorRecords, fixedSpace, freePort, hostedPathsOf, isLogged, loadFunctions, loadFunctionsSource, logLevelOf, presentsCredential, readFunctionsDir, rebaseMedia, refuse, registerHealthCheck, renderLogEvent, resolveRscData, resolveServices, serverLog, takeDraftOverride, verifiedDomain, wildcardSubdomain, writeConnectorRecord };
|
|
23
|
+
export { PREVIEW_TOKEN_PARAM, authoringPreview, buildHealthPayload, closeOnSignals, consoleLogger, createAuthAdapters, createCloudAdapters, createConnectorResolver, createJsonAdapters, createLocalFontStore, createMemoryCache, createMemoryDraftStore, createMemoryPubSub, createRedisPubSub, createServer, createSpaceAdapters, fetchConnectorRecords, fixedSpace, freePort, hostedPathsOf, isLogged, loadFunctions, loadFunctionsSource, logLevelOf, presentsCredential, readFunctionsDir, rebaseMedia, refuse, registerHealthCheck, renderLogEvent, resolveRscData, resolveServices, serverLog, takeDraftOverride, unusedPort, verifiedDomain, wildcardSubdomain, writeConnectorRecord };
|
|
@@ -26,3 +26,9 @@ export declare class ActionRunError extends Error {
|
|
|
26
26
|
export declare class ActionRefusal extends Error {
|
|
27
27
|
constructor(message: string);
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether an error is a refusal — told apart by its NAME, never by `instanceof`: a functions bundle carries its own copy
|
|
31
|
+
* of the class (`functions/build.ts`), so a project's code loaded from one throws a refusal this class never made, and
|
|
32
|
+
* its reason was dropped on the way to the page.
|
|
33
|
+
*/
|
|
34
|
+
export declare const isActionRefusal: (error: unknown) => error is Error;
|
|
@@ -33,5 +33,11 @@ var ActionRefusal = class extends Error {
|
|
|
33
33
|
this.name = "ActionRefusal";
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* Whether an error is a refusal — told apart by its NAME, never by `instanceof`: a functions bundle carries its own copy
|
|
38
|
+
* of the class (`functions/build.ts`), so a project's code loaded from one throws a refusal this class never made, and
|
|
39
|
+
* its reason was dropped on the way to the page.
|
|
40
|
+
*/
|
|
41
|
+
var isActionRefusal = (error) => error instanceof Error && error.name === "ActionRefusal";
|
|
36
42
|
//#endregion
|
|
37
|
-
export { ActionRefusal, ActionRunError };
|
|
43
|
+
export { ActionRefusal, ActionRunError, isActionRefusal };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { serverLog } from "../../../helpers/serverLog.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ActionRunError, isActionRefusal } from "./errors.js";
|
|
3
3
|
import { runCancelKey } from "./guards.js";
|
|
4
4
|
import { createKvStore } from "./kvStore.js";
|
|
5
5
|
import { resolveLimits } from "./limits.js";
|
|
@@ -464,7 +464,7 @@ var createActionRunner = (config, registryFor, baseFetch = fetch) => {
|
|
|
464
464
|
});
|
|
465
465
|
} else {
|
|
466
466
|
failure = error instanceof Error ? error.message : String(error);
|
|
467
|
-
if (error
|
|
467
|
+
if (isActionRefusal(error)) refusal = redact(error.message);
|
|
468
468
|
trace.push({
|
|
469
469
|
node: errorNode("error"),
|
|
470
470
|
status: "failed",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { serverLog } from "../../helpers/serverLog.js";
|
|
2
|
-
import {
|
|
2
|
+
import { isActionRefusal } from "../actions/runtime/errors.js";
|
|
3
3
|
import { pluginOfPath } from "./scope.js";
|
|
4
4
|
import { functionContextFor } from "./context.js";
|
|
5
5
|
import { functionLimitsFor } from "./config.js";
|
|
@@ -69,7 +69,7 @@ var withoutCookies = (response) => {
|
|
|
69
69
|
* of anything else the visitor gets that it failed, and the server's log gets why.
|
|
70
70
|
*/
|
|
71
71
|
var failed = (visit, key, error) => {
|
|
72
|
-
if (error
|
|
72
|
+
if (isActionRefusal(error) || error instanceof FunctionFailure && error.reason === "refused") return Response.json({ error: error.message }, { status: 400 });
|
|
73
73
|
serverLog.error("Functions", `route ${key} of space ${String(visit.spaceId)} failed`, error);
|
|
74
74
|
const stopped = error instanceof FunctionFailure && error.reason !== "error";
|
|
75
75
|
return Response.json({ error: stopped ? "This route ran out of what it may spend" : "This route failed" }, { status: stopped ? 503 : 500 });
|
|
@@ -10,12 +10,15 @@ import { createFileKv } from "../actions/runtime/fileKv.js";
|
|
|
10
10
|
import { loadRuntime, loadRuntimeModule } from "../runtime/bundle.js";
|
|
11
11
|
import { serveRuntime } from "../runtime/stages.js";
|
|
12
12
|
import { projectPlugins, watchProjectPlugins } from "./plugins.js";
|
|
13
|
+
import { createSpaceFailure } from "./spaceFailure.js";
|
|
13
14
|
import { watchSpace } from "./watchSpace.js";
|
|
14
15
|
import path from "node:path";
|
|
15
16
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
16
17
|
import { assertProjectLayout, layoutFindingText } from "@plitzi/sdk-shared/project/layout";
|
|
17
18
|
import { DATA_DIR, DEV_SERVER_FILE, FUNCTIONS_DIR, KV_FILE, PROJECT_TMP, PUBLIC_DIR, RUNTIME_BUNDLE, RUNTIME_ENTRY } from "@plitzi/sdk-shared/project/paths";
|
|
18
19
|
import { projectModule, projectRoot } from "@plitzi/sdk-shared/project/root";
|
|
20
|
+
import { EMPTY_SCHEMA } from "@plitzi/sdk-shared/schema/schemaConstants";
|
|
21
|
+
import { EMPTY_STYLE_SCHEMA } from "@plitzi/sdk-shared/style/styleConstants";
|
|
19
22
|
//#region src/modules/project/serveProject.ts
|
|
20
23
|
/**
|
|
21
24
|
* The errors whose message is the whole report — every problem, where it is and what to write instead — and whose
|
|
@@ -63,14 +66,32 @@ var actionLookups = (actions, connectors) => ({
|
|
|
63
66
|
getConnector: (_spaceId, connectorId) => Promise.resolve(connectors.get(connectorId)),
|
|
64
67
|
listScheduledSpaces: () => Promise.resolve([SPACE_ID])
|
|
65
68
|
});
|
|
66
|
-
/**
|
|
67
|
-
|
|
69
|
+
/**
|
|
70
|
+
* The space this project serves, authored from its own source — or Plitzi's, named for `/health`.
|
|
71
|
+
*
|
|
72
|
+
* While developing, one that does not author is not the end of the server: it comes up saying why (`spaceFailure`),
|
|
73
|
+
* named after the project's folder, and serves the space the first time a save authors. A deployment refuses to start.
|
|
74
|
+
*/
|
|
75
|
+
var spaceToServe = async ({ space, cloud }, developing, root) => {
|
|
68
76
|
if (!space) return { name: cloud.name };
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
try {
|
|
78
|
+
const authored = await space();
|
|
79
|
+
return {
|
|
80
|
+
space: authored,
|
|
81
|
+
name: authored.schema.definition.permanentUrl
|
|
82
|
+
};
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (!developing) throw error;
|
|
85
|
+
return {
|
|
86
|
+
failure: isReport(error) ? error.message : error instanceof Error ? error.stack ?? error.message : String(error),
|
|
87
|
+
name: path.basename(root)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
/** What is served of a space that has not authored yet: nothing — every page answers with why (`spaceFailure`). */
|
|
92
|
+
var NOTHING_AUTHORED = {
|
|
93
|
+
schema: EMPTY_SCHEMA.schema,
|
|
94
|
+
style: EMPTY_STYLE_SCHEMA
|
|
74
95
|
};
|
|
75
96
|
var startProject = async (options) => {
|
|
76
97
|
const { actions, connectors = /* @__PURE__ */ new Map(), serverOptions = {} } = options;
|
|
@@ -85,16 +106,22 @@ var startProject = async (options) => {
|
|
|
85
106
|
const port = process.env.PORT ? Number(process.env.PORT) : developing ? await freePort(8080, host) : 8080;
|
|
86
107
|
/** Where people reach this server: `PUBLIC_URL` behind a proxy, its own address otherwise. */
|
|
87
108
|
const publicUrl = (process.env.PUBLIC_URL ?? `http://127.0.0.1:${String(port)}`).replace(/\/+$/, "");
|
|
88
|
-
const { space, name } = await spaceToServe(options);
|
|
109
|
+
const { space, failure, name } = await spaceToServe(options, developing, root);
|
|
89
110
|
const plugins = await projectPlugins(root);
|
|
90
|
-
const held = space
|
|
111
|
+
const held = options.space ? { ...space ? { documents: {
|
|
91
112
|
schema: space.schema,
|
|
92
113
|
style: space.style
|
|
93
|
-
} };
|
|
114
|
+
} } : {} } : void 0;
|
|
115
|
+
const spaceFailure = createSpaceFailure();
|
|
116
|
+
if (failure !== void 0) {
|
|
117
|
+
spaceFailure.fail(failure);
|
|
118
|
+
console.error(`[author] ${failure}`);
|
|
119
|
+
console.error("[author] The server is up: fix the space and save, and the page loads it.");
|
|
120
|
+
}
|
|
94
121
|
const speaks = !isFleetWorker();
|
|
95
122
|
for (const warning of speaks ? space?.warnings ?? [] : []) console.warn(`[author] ${warning.message}`);
|
|
96
123
|
const adapters = held ? createJsonAdapters({
|
|
97
|
-
offlineData: () => held.documents,
|
|
124
|
+
offlineData: () => held.documents ?? NOTHING_AUTHORED,
|
|
98
125
|
deployment: {
|
|
99
126
|
spaceId: SPACE_ID,
|
|
100
127
|
environment: "main",
|
|
@@ -132,7 +159,7 @@ var startProject = async (options) => {
|
|
|
132
159
|
...serverOptions.action,
|
|
133
160
|
...actions ? { lookups: actionLookups(actions, connectors) } : {}
|
|
134
161
|
}
|
|
135
|
-
}, { preAuth: runtime ? [runtime.stage] : [] });
|
|
162
|
+
}, { preAuth: [spaceFailure.stage, ...runtime ? [runtime.stage] : []] });
|
|
136
163
|
server.listen(port, host);
|
|
137
164
|
const url = `http://127.0.0.1:${String(port)}`;
|
|
138
165
|
if (speaks) {
|
|
@@ -146,6 +173,7 @@ var startProject = async (options) => {
|
|
|
146
173
|
}
|
|
147
174
|
const watching = developing ? [...held ? [watchSpace(root, (authored) => {
|
|
148
175
|
held.documents = authored;
|
|
176
|
+
spaceFailure.clear();
|
|
149
177
|
server.reloadPages();
|
|
150
178
|
})] : [], watchProjectPlugins(root, server, plugins)] : [];
|
|
151
179
|
const close = async () => {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Stage } from '../../core/http/types';
|
|
2
|
+
export declare const createSpaceFailure: () => {
|
|
3
|
+
stage: Stage;
|
|
4
|
+
/** The space did not author: every page says why, until it does. */
|
|
5
|
+
fail: (message: string) => void;
|
|
6
|
+
/** It authored: the pages are the space's again. */
|
|
7
|
+
clear: () => void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { DEV_RELOAD_PATH } from "../../core/http/stages/devReload.js";
|
|
2
|
+
import { escapeHtml } from "../../helpers/escapeHtml.js";
|
|
3
|
+
//#region src/modules/project/spaceFailure.ts
|
|
4
|
+
/**
|
|
5
|
+
* The page a project's server answers with while its space does not author — while developing only.
|
|
6
|
+
*
|
|
7
|
+
* A `start:dev` that restarted on a save to the server's code (`src/functions/`, `src/config/`…) while the space had an
|
|
8
|
+
* error of its own died on it: Node then waits for a change to the server's code, never to `src/space/`, so fixing the
|
|
9
|
+
* space woke nothing and the page was gone with no word in the browser. Up instead, it answers every page with what is
|
|
10
|
+
* wrong, and loads again the moment a save authors — the same reload a page showing the space waits for — or when the
|
|
11
|
+
* server it reached restarts.
|
|
12
|
+
*/
|
|
13
|
+
var pageOf = (message) => `<!doctype html>
|
|
14
|
+
<html lang="en">
|
|
15
|
+
<head>
|
|
16
|
+
<meta charset="utf-8">
|
|
17
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
18
|
+
<title>The space does not author</title>
|
|
19
|
+
<style>
|
|
20
|
+
:root { color-scheme: light dark; }
|
|
21
|
+
body { margin: 0; padding: 48px 24px; font: 15px/1.5 ui-sans-serif, system-ui, sans-serif; }
|
|
22
|
+
main { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
|
|
23
|
+
pre { margin: 0; padding: 16px; border-radius: 8px; background: color-mix(in srgb, currentColor 8%, transparent);
|
|
24
|
+
white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.5 ui-monospace, monospace; }
|
|
25
|
+
</style>
|
|
26
|
+
</head>
|
|
27
|
+
<body>
|
|
28
|
+
<main>
|
|
29
|
+
<h1>The space does not author</h1>
|
|
30
|
+
<p>Fix it and save: this page loads again the moment it authors. The server is still running.</p>
|
|
31
|
+
<pre>${escapeHtml(message)}</pre>
|
|
32
|
+
</main>
|
|
33
|
+
<script>
|
|
34
|
+
(() => {
|
|
35
|
+
let boot;
|
|
36
|
+
const events = new EventSource(${JSON.stringify(DEV_RELOAD_PATH)});
|
|
37
|
+
events.addEventListener('reload', () => location.reload());
|
|
38
|
+
events.addEventListener('hello', event => {
|
|
39
|
+
const next = JSON.parse(event.data).boot;
|
|
40
|
+
if (boot !== undefined && next !== boot) {
|
|
41
|
+
location.reload();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
boot = next;
|
|
45
|
+
});
|
|
46
|
+
})();
|
|
47
|
+
<\/script>
|
|
48
|
+
</body>
|
|
49
|
+
</html>
|
|
50
|
+
`;
|
|
51
|
+
/** A request for a page, as a browser asks for one — not for the server's data, its assets or its reload stream. */
|
|
52
|
+
var asksForPage = (method, accept) => method === "GET" && [accept].flat().some((value) => value?.includes("text/html"));
|
|
53
|
+
var createSpaceFailure = () => {
|
|
54
|
+
let failure;
|
|
55
|
+
const stage = (ctx) => {
|
|
56
|
+
if (failure === void 0 || !asksForPage(ctx.req.method, ctx.req.headers.accept)) return Promise.resolve(false);
|
|
57
|
+
ctx.res.setStatus(503);
|
|
58
|
+
ctx.res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
59
|
+
ctx.res.setHeader("Cache-Control", "no-store");
|
|
60
|
+
ctx.res.send(pageOf(failure));
|
|
61
|
+
return Promise.resolve(true);
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
stage,
|
|
65
|
+
/** The space did not author: every page says why, until it does. */
|
|
66
|
+
fail: (message) => {
|
|
67
|
+
failure = message;
|
|
68
|
+
},
|
|
69
|
+
/** It authored: the pages are the space's again. */
|
|
70
|
+
clear: () => {
|
|
71
|
+
failure = void 0;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
//#endregion
|
|
76
|
+
export { createSpaceFailure };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FunctionsDefinition } from '../functions/contract';
|
|
2
2
|
import { FunctionRunner } from '../functions/protocol';
|
|
3
|
+
/** A refusal, however it was made: the platform's class, or a bundle's own copy of it — known by its name. */
|
|
3
4
|
/**
|
|
4
5
|
* A runtime's functions as a runner: the same protocol as the sandbox's, answered by code loaded in this process. The
|
|
5
6
|
* driver is the sandbox's own (`createFunctionsDriver`), so a task behaves the same in both — its `ctx` is calls to the
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { ActionRefusal } from "../actions/runtime/errors.js";
|
|
1
|
+
import { ActionRefusal, isActionRefusal } from "../actions/runtime/errors.js";
|
|
2
2
|
import { changeKv } from "../actions/runtime/kvChange.js";
|
|
3
3
|
import { requestFromWire, responseOf, wireResponseFrom, wireResponseOf } from "../functions/capabilities.js";
|
|
4
4
|
import { FunctionFailure } from "../functions/protocol.js";
|
|
5
5
|
import { createFunctionsDriver, describeFunctions } from "../functions/driver.js";
|
|
6
6
|
//#region src/modules/runtime/runner.ts
|
|
7
7
|
/** A refusal, however it was made: the platform's class, or a bundle's own copy of it — known by its name. */
|
|
8
|
-
var isRefusal = (error) => error instanceof Error && error.name === "ActionRefusal";
|
|
9
8
|
/**
|
|
10
9
|
* A runtime's functions as a runner: the same protocol as the sandbox's, answered by code loaded in this process. The
|
|
11
10
|
* driver is the sandbox's own (`createFunctionsDriver`), so a task behaves the same in both — its `ctx` is calls to the
|
|
@@ -29,7 +28,7 @@ var createRuntimeRunner = (definition = {}) => ({
|
|
|
29
28
|
try {
|
|
30
29
|
return await driver.invoke(definition, invocation);
|
|
31
30
|
} catch (error) {
|
|
32
|
-
if (
|
|
31
|
+
if (isActionRefusal(error)) throw new FunctionFailure("refused", error.message);
|
|
33
32
|
throw error;
|
|
34
33
|
}
|
|
35
34
|
}
|
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
import { SSRRenderResult, SSRResponseHelpers } from '@plitzi/sdk-shared';
|
|
2
2
|
export declare const applySSRResult: (res: SSRResponseHelpers, result: SSRRenderResult) => boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Whether a render may be kept and served again: only a page that answered 200. A cached page is sent without the
|
|
5
|
+
* status it was rendered with, and a "not found" kept per address would let anybody asking for addresses at random
|
|
6
|
+
* push every real page out of the cache.
|
|
7
|
+
*/
|
|
8
|
+
export declare const isReusable: (result: SSRRenderResult) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* A page a server provider said shows nothing (`notFound`) answers 404 — unless the render decided something of its
|
|
11
|
+
* own first: a redirect, or a status the navigation set.
|
|
12
|
+
*/
|
|
13
|
+
export declare const withNotFound: (result: SSRRenderResult, notFound: boolean) => void;
|
|
@@ -10,5 +10,18 @@ var applySSRResult = (res, result) => {
|
|
|
10
10
|
if (result.status !== void 0) res.setStatus(result.status);
|
|
11
11
|
return false;
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Whether a render may be kept and served again: only a page that answered 200. A cached page is sent without the
|
|
15
|
+
* status it was rendered with, and a "not found" kept per address would let anybody asking for addresses at random
|
|
16
|
+
* push every real page out of the cache.
|
|
17
|
+
*/
|
|
18
|
+
var isReusable = (result) => result.status === void 0 || result.status === 200;
|
|
19
|
+
/**
|
|
20
|
+
* A page a server provider said shows nothing (`notFound`) answers 404 — unless the render decided something of its
|
|
21
|
+
* own first: a redirect, or a status the navigation set.
|
|
22
|
+
*/
|
|
23
|
+
var withNotFound = (result, notFound) => {
|
|
24
|
+
if (notFound && result.redirect === void 0 && result.status === void 0) result.status = 404;
|
|
25
|
+
};
|
|
13
26
|
//#endregion
|
|
14
|
-
export { applySSRResult };
|
|
27
|
+
export { applySSRResult, isReusable, withNotFound };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withNotFound } from "./applySSRResult.js";
|
|
1
2
|
import Component from "./Component.js";
|
|
2
3
|
import { prepareRender } from "./prepareRender.js";
|
|
3
4
|
import { renderToString } from "react-dom/server";
|
|
@@ -12,6 +13,7 @@ var buildBody = async (req, config, spaceId, environment, revision, renderFn, pl
|
|
|
12
13
|
ssrResult: result
|
|
13
14
|
})).trim();
|
|
14
15
|
metrics?.record("react", Math.round(performance.now() - reactStart));
|
|
16
|
+
withNotFound(result, prep.notFound);
|
|
15
17
|
if (result.redirect !== void 0) return {
|
|
16
18
|
result,
|
|
17
19
|
cacheable: prep.cacheable
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { buildHtmlCacheKey } from "../../helpers/cache/keys.js";
|
|
2
2
|
import { draftSessionCookie, takeDraftOverride } from "./preview.js";
|
|
3
|
-
import { applySSRResult } from "./applySSRResult.js";
|
|
3
|
+
import { applySSRResult, isReusable } from "./applySSRResult.js";
|
|
4
4
|
import { buildBody } from "./buildBody.js";
|
|
5
5
|
import { streamBody } from "./streamBody.js";
|
|
6
6
|
import { RequestMetrics } from "../../helpers/metrics.js";
|
|
@@ -63,7 +63,7 @@ var renderSSR = async (req, res, config, renderFn, pluginManager, caches) => {
|
|
|
63
63
|
metrics.log(`${req.method} ${req.path}`);
|
|
64
64
|
}
|
|
65
65
|
if (applySSRResult(res, result)) return;
|
|
66
|
-
if (htmlCache && cacheKey && body !== void 0 && cacheable) {
|
|
66
|
+
if (htmlCache && cacheKey && body !== void 0 && cacheable && isReusable(result)) {
|
|
67
67
|
const page = {
|
|
68
68
|
html: body,
|
|
69
69
|
compressed: {}
|
|
@@ -11,5 +11,7 @@ export type RenderPrep = {
|
|
|
11
11
|
};
|
|
12
12
|
/** False for a render that must not be served to anybody else from a cache: it carries this request's own runs. */
|
|
13
13
|
cacheable: boolean;
|
|
14
|
+
/** A server provider of the page said its address shows nothing (`notFound`): sent with status 404. */
|
|
15
|
+
notFound: boolean;
|
|
14
16
|
};
|
|
15
17
|
export declare const prepareRender: (req: SSRRequest, config: SSRPageServerConfig, spaceId: number, environment: Environment, revision: number, pluginManager: PluginManager, offlineDataCache?: TtlCache<string>, metrics?: RequestMetrics, offlineDataOverride?: OfflineDataRaw) => Promise<RenderPrep>;
|
|
@@ -20,7 +20,7 @@ import { sdkAssetVersion } from "../../core/sdkAssets.js";
|
|
|
20
20
|
import { buildServerInfo } from "../../helpers/buildServerInfo.js";
|
|
21
21
|
import { resolveDebugMode } from "../../helpers/resolveDebugMode.js";
|
|
22
22
|
import { flagUserFromSSR, flagValues, resolveFlags } from "@plitzi/sdk-shared/flags";
|
|
23
|
-
import {
|
|
23
|
+
import { collectServerElements, notFoundProvider } from "@plitzi/sdk-shared/schema/serverElements";
|
|
24
24
|
import { debugCookieName } from "@plitzi/sdk-shared/devTools";
|
|
25
25
|
import { themeFromCookies } from "@plitzi/sdk-shared/theme";
|
|
26
26
|
import { paintedKeys, paintedStateFor } from "@plitzi/sdk-shared/state/paintedState";
|
|
@@ -74,7 +74,8 @@ var prepareRender = async (req, config, spaceId, environment, revision, pluginMa
|
|
|
74
74
|
queryParams: req.query,
|
|
75
75
|
user: flagUserFromSSR(req.ctx.user)
|
|
76
76
|
}, flagOverrides)) : void 0;
|
|
77
|
-
const
|
|
77
|
+
const serverElements = rscEnabled && pageMatch !== void 0 ? collectServerElements(schema, pageMatch.pageId, void 0, pageFlags) : [];
|
|
78
|
+
const rscData = serverElements.length > 0 && config.adapters.getRscData ? await m("rsc", () => config.adapters.getRscData?.({
|
|
78
79
|
req,
|
|
79
80
|
spaceId: req.ctx.spaceDeployment?.spaceId ?? spaceId,
|
|
80
81
|
environment: req.ctx.spaceDeployment?.environment ?? environment,
|
|
@@ -84,6 +85,10 @@ var prepareRender = async (req, config, spaceId, environment, revision, pluginMa
|
|
|
84
85
|
flagOverrides
|
|
85
86
|
})) : rscPath ? { serverData: {} } : void 0;
|
|
86
87
|
const pageSeo = resolvePageSeo(schema, pageMatch?.pageId);
|
|
88
|
+
const notFound = pageMatch !== void 0 && rscData?.serverData !== void 0 ? notFoundProvider(serverElements, rscData.serverData, {
|
|
89
|
+
routeParams: pageMatch.routeParams,
|
|
90
|
+
queryParams: req.query
|
|
91
|
+
}) !== void 0 : false;
|
|
87
92
|
const server = buildServerInfo(req, config, {
|
|
88
93
|
rscPath,
|
|
89
94
|
rscData,
|
|
@@ -281,7 +286,8 @@ var prepareRender = async (req, config, spaceId, environment, revision, pluginMa
|
|
|
281
286
|
devReload: config.devReload === true,
|
|
282
287
|
offlineData: offlineDataStr
|
|
283
288
|
},
|
|
284
|
-
cacheable: actionRuns === void 0 && forcedFlags === void 0
|
|
289
|
+
cacheable: actionRuns === void 0 && forcedFlags === void 0,
|
|
290
|
+
notFound
|
|
285
291
|
};
|
|
286
292
|
};
|
|
287
293
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applySSRResult } from "./applySSRResult.js";
|
|
1
|
+
import { applySSRResult, isReusable, withNotFound } from "./applySSRResult.js";
|
|
2
2
|
import Component from "./Component.js";
|
|
3
3
|
import { prepareRender } from "./prepareRender.js";
|
|
4
4
|
import { renderToPipeableStream } from "react-dom/server";
|
|
@@ -30,7 +30,7 @@ var streamBody = async (req, res, config, spaceId, environment, revision, render
|
|
|
30
30
|
const tailBuf = Buffer.from(tail, "utf-8");
|
|
31
31
|
res.write(tailBuf);
|
|
32
32
|
res.end();
|
|
33
|
-
if (chunks && cacheKey && htmlCache) htmlCache.set(cacheKey, {
|
|
33
|
+
if (chunks && cacheKey && htmlCache && isReusable(result)) htmlCache.set(cacheKey, {
|
|
34
34
|
html: head + Buffer.concat(chunks).toString("utf-8") + tail,
|
|
35
35
|
compressed: {}
|
|
36
36
|
});
|
|
@@ -49,6 +49,7 @@ var streamBody = async (req, res, config, spaceId, environment, revision, render
|
|
|
49
49
|
res.setHeader("Server-Timing", metrics.toServerTimingHeader());
|
|
50
50
|
metrics.log(`${req.method} ${req.path}`);
|
|
51
51
|
}
|
|
52
|
+
withNotFound(result, prep.notFound);
|
|
52
53
|
if (applySSRResult(res, result)) {
|
|
53
54
|
abort();
|
|
54
55
|
resolve();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plitzi/sdk-server",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.9",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -96,8 +96,8 @@
|
|
|
96
96
|
"./dist/env.js"
|
|
97
97
|
],
|
|
98
98
|
"dependencies": {
|
|
99
|
-
"@plitzi/plitzi-sdk": "0.38.
|
|
100
|
-
"@plitzi/sdk-shared": "0.38.
|
|
99
|
+
"@plitzi/plitzi-sdk": "0.38.9",
|
|
100
|
+
"@plitzi/sdk-shared": "0.38.9",
|
|
101
101
|
"ejs": "^6.0.1",
|
|
102
102
|
"esbuild": "^0.28.2",
|
|
103
103
|
"jsonwebtoken": "^9.0.3",
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* eslint-disable quotes -- templates quote their own strings, and read best in the other quotes */
|
|
2
2
|
/**
|
|
3
3
|
* A page per record: a card links to `/products/<slug>`, and the detail page narrows the same file to the product its
|
|
4
|
-
* address names — with a message, not an empty page, when no product has that name
|
|
4
|
+
* address names — with a message, not an empty page, when no product has that name, and status 404: the provider is
|
|
5
|
+
* resolved on the server, and `notFound` says when its answer holds nothing for this address.
|
|
5
6
|
*/
|
|
6
7
|
import { apiContainer, heading, link, list, text, listItem } from '@plitzi/sdk-authoring';
|
|
7
8
|
|
|
@@ -48,7 +49,8 @@ export const recipe: SpaceSpec = {
|
|
|
48
49
|
apiContainer({
|
|
49
50
|
id: 'catalog-one',
|
|
50
51
|
query: '/data/products.json',
|
|
51
|
-
|
|
52
|
+
runtime: 'server',
|
|
53
|
+
notFound: "{{ not (source.data.products|find('slug', navigation.routeParams.slug)) }}",
|
|
52
54
|
children: [
|
|
53
55
|
list({
|
|
54
56
|
id: 'this-product',
|
|
@@ -38,6 +38,8 @@ image({ src: '/grain.png', decorative: true }) // an orname
|
|
|
38
38
|
image({ decorative: true, bind: { src: 'post.record.cover' } }) // a cover under its own headline adds nothing
|
|
39
39
|
image({ bind: { src: 'row.item.cover', alt: 'row.item.title' } }) // …unless it is alone in a link: then it names it
|
|
40
40
|
fontAwesome({ icon: 'fa-solid fa-triangle-exclamation', label: 'Overdue' }) // an icon that says something alone
|
|
41
|
+
text('福', { decorative: true }) // a seal or a mark drawn for the look alone
|
|
42
|
+
list({ label: 'Kinds of capsule', … }) // a group of options is named, as a group
|
|
41
43
|
```
|
|
42
44
|
|
|
43
45
|
## Clicks go on controls
|
|
@@ -101,6 +101,8 @@ The space is not written until these are fixed.
|
|
|
101
101
|
| `motion-invalid` | a `motion` with a preset, a trigger or a timing the page cannot play | `motion: { enter: 'fade-up', on: 'view' }` — the message lists the presets |
|
|
102
102
|
| `motion-no-tag` | a `motion` on an element with no tag of its own — nothing to move | the motion on what it wraps, or a `subType` on it |
|
|
103
103
|
| `no-pages` | a space with no pages | `pages: [{ id: 'home', name: 'Home', slug: '', body: [] }]` |
|
|
104
|
+
| `not-found-in-browser` | `notFound` on a provider asked from the browser — its answer arrives after the page was sent with its status | `runtime: 'server'` on the provider, or `visible` on the page's "not found" part instead |
|
|
105
|
+
| `not-found-not-a-template` | `notFound` that is not one `{{ expression }}` against the answer — never `true`, so never a 404 | `notFound: '{{ source.found == false }}'` |
|
|
104
106
|
| `notifications-shape` | `notifications` with a field it does not have, or a value that is not one CSS value | the field it suggests, or one it lists; one CSS value, like 'var(--card)', '12px' or '500' |
|
|
105
107
|
| `outside-ancestor` | an element that reads the state of an element it is not inside | nest it in the element the message names |
|
|
106
108
|
| `page-access-level` | an `accessLevel` that is not one the router reads | one of the values the message lists |
|
|
@@ -229,6 +231,7 @@ Nothing is wrong: the page renders as written. Each is a shorter way to the same
|
|
|
229
231
|
| `custom-css-slot` | a part of a built-in element dressed in `customCss` by the SDK's markup — a form control's `<input>`, a pager's buttons, a heading inside a markdown | a class on the slot of that part — `slots: { field: input }`, `elements.<type>.slots` — with its states |
|
|
230
232
|
| `heavy-animation` | keyframes animating what the browser repaints or lays out again on every frame — a size, a position, a blur, a shadow, or a colour in a loop — which stutters whenever the page is busy, most of all while it loads | `opacity` and `transform`: a size or a position is `translate`/`scale`, a blur or a shadow is the `opacity` of a layer carrying it; a loop that must animate anything else starts `paused` and runs under `[data-hydrated]` |
|
|
231
233
|
| `literal-colour` | a colour written out in a class where the space has a token of that value — it stays put in the dark scheme | `var(--token)` when it should follow the scheme; a token of one value of its own when it must stay the same in both |
|
|
234
|
+
| `not-found-page` | a space with no page of its own for an address no other page answers — a plain one was added, in the home page’s layout, sent with status 404 | a page whose slug is `'*'`: `{ id: 'not-found', name: 'Not found', slug: '*', layout: …, body: [...] }` |
|
|
232
235
|
| `repeated-on-pages` | the same block — a header, a footer, a side panel — written into several pages | a layout holding it once (`layouts`, and `layout: { id, slot }` on each page) — a component when only some pages of a layout carry it; a link marks its own page with the `current` state |
|
|
233
236
|
| `repeated-shape` | the same structure written again and again with different words — cards, rows, tiles | a component with props (`components`, `component(id, { props })`), or one `list` when they are rows of data side by side — a few cards a person rewords on the canvas can stay cards |
|
|
234
237
|
| `unused-class` | a class declared in `classes` that no element, binding, flow or other class names | remove it from `classes` — or wear it where it was meant to go |
|
|
@@ -131,8 +131,8 @@ form({
|
|
|
131
131
|
});
|
|
132
132
|
```
|
|
133
133
|
|
|
134
|
-
A `formControl` is `required
|
|
135
|
-
|
|
134
|
+
A `formControl` is optional unless it says `required: true`, as an HTML field is. A required field that is empty stops
|
|
135
|
+
the submit, and the browser says which.
|
|
136
136
|
|
|
137
137
|
## Notifications
|
|
138
138
|
|
|
@@ -124,6 +124,24 @@ pages: pageFamily(
|
|
|
124
124
|
|
|
125
125
|
Every page is now its content and nothing else, and every page is guaranteed the same structure.
|
|
126
126
|
|
|
127
|
+
## The page for an address nothing answers
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
{ id: 'not-found', name: 'Not found', slug: '*', layout: { id: 'site', slot: 'site-main' }, body: [ … ] }
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
- **`slug: '*'`** is the page of every address no other page answers — a mistyped link, a page taken down — sent with
|
|
134
|
+
status 404, in the layout you give it, so the visitor is still on the site with a way back. Its own address answers
|
|
135
|
+
404 too.
|
|
136
|
+
- **One per folder, if a section wants its own.** In a folder (`folder: 'docs'`) it answers that folder's unknown
|
|
137
|
+
addresses; the deepest folder's wins, the space's takes the rest. A page whose `flag` is off shows it too.
|
|
138
|
+
- **A space with none is given a plain one** — a title and a link home, in the home page's layout — and `author`
|
|
139
|
+
suggests writing your own (`not-found-page`): say it in the space's words.
|
|
140
|
+
- **A page that exists but finds nothing** — `/products/:slug` for a slug no product has — is sent with 404 too when
|
|
141
|
+
its server provider says so: `notFound: "{{ not (source.data.products|find('slug', navigation.routeParams.slug)) }}"`,
|
|
142
|
+
one expression against its answer, on a `runtime: 'server'` provider of the page (not of its layout, which every
|
|
143
|
+
page shares). The page renders as written: show its "not found" part with `visible`.
|
|
144
|
+
|
|
127
145
|
## Styles follow the same rule
|
|
128
146
|
|
|
129
147
|
- A role used on several pages is ONE class (`panelCard`, `pageTitle`), declared in the module that owns the area and
|
|
@@ -9,7 +9,7 @@ Each is a whole file that authors with no warning — CI holds it to that. Copy
|
|
|
9
9
|
| Data read by the page server (`--mode server`) | [recipes/server-data.ts](../recipes/server-data.ts) |
|
|
10
10
|
| An accordion, one answer open at a time | [recipes/accordion.ts](../recipes/accordion.ts) |
|
|
11
11
|
| Filter and sort a list from a select | [recipes/filter-a-list.ts](../recipes/filter-a-list.ts) |
|
|
12
|
-
| A page per record (`/products/:slug`), and "not found" | [recipes/detail-page.ts](../recipes/detail-page.ts) |
|
|
12
|
+
| A page per record (`/products/:slug`), and "not found" sent with 404 | [recipes/detail-page.ts](../recipes/detail-page.ts) |
|
|
13
13
|
| Link to a section of a page (`/#plans`) | [recipes/link-to-a-section.ts](../recipes/link-to-a-section.ts) |
|
|
14
14
|
| A carousel: slides with arrows, dots and autoplay; a marquee; a row that swipes | [recipes/carousel.ts](../recipes/carousel.ts) |
|
|
15
15
|
| Do something every few seconds — a ticker, a poll, a slideshow by hand | [recipes/every-few-seconds.ts](../recipes/every-few-seconds.ts) |
|