@plitzi/sdk-server 0.39.0 → 0.39.1

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
@@ -1,5 +1,15 @@
1
1
  # @plitzi/sdk-server
2
2
 
3
+ ## 0.39.1
4
+
5
+ ### Patch Changes
6
+
7
+ - f174a61: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
8
+ `@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
9
+ - Updated dependencies [f174a61]
10
+ - @plitzi/plitzi-sdk@0.39.1
11
+ - @plitzi/sdk-shared@0.39.1
12
+
3
13
  ## 0.39.0
4
14
 
5
15
  ### Minor Changes
@@ -22,6 +22,16 @@ export type ProjectServerOptions = Partial<Omit<ServerConfig, SetByProject>> & {
22
22
  * (`https://aiko.example.com:8080`, `process.env.OAUTH_CALLBACK_ORIGIN`).
23
23
  */
24
24
  functions?: Pick<FunctionsConfig, 'oauth'>;
25
+ /**
26
+ * Run once the server answers — `main.ts` is the CLI's, so this is where a project does something then: ask its home
27
+ * once, so the first visitor does not wait for its sources to answer cold. Not awaited: the server is already up, and
28
+ * what it does is said if it fails, never lost. Run by the process that speaks for the project, once — not by each of
29
+ * a fleet's workers.
30
+ */
31
+ onListening?: (served: {
32
+ url: string;
33
+ server: SSRServer;
34
+ }) => void | Promise<void>;
25
35
  };
26
36
  /** A space authored in the project — `authorProjectSpace` of `@plitzi/sdk-authoring/node` — and what it warned of. */
27
37
  export type ProjectSpace = AuthoredDocuments & {
@@ -184,7 +184,8 @@ var NOTHING_AUTHORED = {
184
184
  style: EMPTY_STYLE_SCHEMA
185
185
  };
186
186
  var startProject = async (options) => {
187
- const { actions, connectors = /* @__PURE__ */ new Map(), serverOptions = {} } = options;
187
+ const { actions, connectors = /* @__PURE__ */ new Map(), serverOptions: given = {} } = options;
188
+ const { onListening, ...serverOptions } = given;
188
189
  const root = projectRoot();
189
190
  const developing = process.env.NODE_ENV !== "production";
190
191
  const layout = assertProjectLayout(root, {
@@ -308,6 +309,12 @@ var startProject = async (options) => {
308
309
  });
309
310
  await server.listen(port, host);
310
311
  reserved?.release();
312
+ if (speaks && onListening) Promise.resolve().then(() => onListening({
313
+ url: localUrl,
314
+ server
315
+ })).catch((error) => {
316
+ console.error(`onListening (src/config/serverOptions.ts) failed, and the server goes on serving: ${error instanceof Error ? error.message : String(error)}`);
317
+ });
311
318
  if (speaks) {
312
319
  mkdirSync(path.join(root, PROJECT_TMP), { recursive: true });
313
320
  const record = process.env[SERVER_RECORD_ENV] || DEV_SERVER_FILE;
@@ -25,7 +25,7 @@ import { flagUserFromSSR, flagValues, resolveFlags } from "@plitzi/sdk-shared/fl
25
25
  import { collectServerElements, notFoundProvider, pageElementTypes, pageHeadTags, pageNotFound, pageServerContext, pageWithheldOf, spaceIdentity, withholdPages } from "@plitzi/sdk-shared/schema";
26
26
  import { debugCookieName } from "@plitzi/sdk-shared/devTools";
27
27
  import { themeFromCookies } from "@plitzi/sdk-shared/theme/cookie";
28
- import { paintedKeys, paintedStateFor } from "@plitzi/sdk-shared/state";
28
+ import { paintedStateFor } from "@plitzi/sdk-shared/state";
29
29
  import { fontUrlResolver, fontsToHead } from "@plitzi/sdk-shared/style";
30
30
  import { pluginDeclarationOf, pluginTypesOf } from "@plitzi/sdk-shared/plugins";
31
31
  //#region src/modules/ssr/prepareRender.tsx
@@ -173,9 +173,10 @@ var prepareRender = async (req, config, spaceId, environment, revision, pluginMa
173
173
  * tool a toolbar shows, their name in an avatar — would reach the page only after hydration, and be swapped in over
174
174
  * the defaults the server drew. Read here, the server draws with it, and the page starts from the same values: it
175
175
  * travels as the SDK's `state`, the starting `runtime.state`, in the render and in the payload alike, or the client
176
- * would hydrate other markup. Only the keys the space declares, and only with `keepState` on.
176
+ * would hydrate other markup. Only the keys the space declares, only with `keepState` on, and of an entry another
177
+ * account wrote than the one this request proved, only the browser's (`browserState`).
177
178
  */
178
- const paintedState = schema?.settings.keepState ? paintedStateFor(req.headers.cookie, ssrPaintedCookieName(requestAuthority(req)), paintedKeys(schema.settings)) : void 0;
179
+ const paintedState = schema?.settings.keepState ? paintedStateFor(req.headers.cookie, ssrPaintedCookieName(requestAuthority(req)), schema.settings, req.ctx.user?.id) : void 0;
179
180
  /**
180
181
  * The two layers of the space's flags this server answers for. Its own (`config.flags`), asked per space when it
181
182
  * serves several; and the ones a tester forced from the dev tools, read from their cookie — only for a page allowed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-server",
3
- "version": "0.39.0",
3
+ "version": "0.39.1",
4
4
  "license": "AGPL-3.0",
5
5
  "files": [
6
6
  "dist",
@@ -114,8 +114,8 @@
114
114
  "./dist/env.js"
115
115
  ],
116
116
  "dependencies": {
117
- "@plitzi/plitzi-sdk": "0.39.0",
118
- "@plitzi/sdk-shared": "0.39.0",
117
+ "@plitzi/plitzi-sdk": "0.39.1",
118
+ "@plitzi/sdk-shared": "0.39.1",
119
119
  "ejs": "^7.0.2",
120
120
  "esbuild": "^0.28.2",
121
121
  "jsonwebtoken": "^9.0.3",
@@ -88,6 +88,9 @@ row's panel is drawn as `<id>-<row>`, and the row's button points at its own. Wo
88
88
  A part that opens and closes on its own — a question and its answer, many open at once — needs no state at all:
89
89
  `container({ subType: 'details', children: [container({ subType: 'summary', children: [text('Question')] }), …] })`
90
90
  (`open: true` to start open), the browser's own disclosure, announced as one. The accordion recipe is for one-at-a-time.
91
+ Results, a menu or a set of options someone goes through with the keyboard sit in `focusGroup({ label, children })`:
92
+ ↑/↓ move between the controls inside, ←/→ to the first of the next or previous list, and ↓ from a search field inside
93
+ goes down into them — Tab alone took a stop per result.
91
94
 
92
95
  ## The page has an outline
93
96
 
@@ -154,8 +154,9 @@ The space is not written until these are fixed.
154
154
  | `source-field-unknown` | a path into a typed source that its sample does not have | read a field the sample has, or add the field to the sample |
155
155
  | `source-name-missing` | a source named by nothing — most often a field read off a list row that has no types | write the row's field as text (`${r.item}.field`), or give the list `items` a typed source's path |
156
156
  | `space-identity-invalid` | the space's `siteName`, `language`, `favicon`, `shareImage` or `themeColor` written as nothing a head reads | `siteName: 'My site'`, `language: 'en'`, `favicon: '/favicon.svg'`, `shareImage: '/og.png'`, `themeColor: { light: '#fbf7f0', dark: '#0b0a10' }` |
157
+ | `state-browser-not-kept` | a `browserState` key the space does not keep — transient, or not in `keptState` | keep it, or leave it out of `browserState` |
157
158
  | `state-kept-and-transient` | `keptState` (the only keys kept) and `transientState` (the keys left out) both said | one of the two: `keptState` when few keys are kept, `transientState` when few are not |
158
- | `state-key-list` | `settings.transientState` / `paintedState` that is not a list of top-level state keys | `transientState: ['demoStep']` — a dotted path names its top key |
159
+ | `state-key-list` | `settings.transientState` / `paintedState` / `browserState` that is not a list of top-level state keys | `transientState: ['demoStep']` — a dotted path names its top key |
159
160
  | `state-painted-and-transient` | a state key both painted (kept for the server) and transient (never kept) | remove it from one of the two |
160
161
  | `state-painted-not-kept` | a `paintedState` key that `keptState` does not keep — the server draws with what is kept | add it to `keptState`, or leave it out of `paintedState` |
161
162
  | `state-shape` | a state given a rule set's keys (`pseudos`, `variants`, `ancestors`…): a state holds plain CSS | a pseudo-element's state goes under the pseudo-element — `pseudos: { before: { states: { hover: { opacity: '1' } } } }`; an ancestor's, under `ancestors` |
@@ -205,6 +206,7 @@ The space renders, and renders something you probably did not mean. Fix every on
205
206
  | --- | --- | --- |
206
207
  | `action-output-path` | a read of `.data` on a provider fed by a server action — it publishes the action’s output at its root, and `.data` is a `query` provider’s answer | the output’s own field — `apiContainer_feed.stories`, not `apiContainer_feed.data.stories` |
207
208
  | `animation-name-unknown` | `animation-name` naming keyframes the space does not declare — nothing plays | declare them in the space's `keyframes`, or name one it has |
209
+ | `browser-state-without-keep-state` | `browserState` without `keepState` — nothing is kept in the first place | `settings.keepState: true`, or remove `browserState` |
208
210
  | `click-on-static-element` | a click flow on a container, text, heading, image or list item — no keyboard reaches it | the flow on a `button` (it holds children) or a `link` |
209
211
  | `colour-without-dark` | a colour token with no dark value | `{ light, dark, default }` |
210
212
  | `condition-starts-visible` | a computed visibility that shows until its data answers | `visible: { source, template }` |
@@ -281,7 +283,7 @@ Nothing is wrong: the page renders as written. Each is a shorter way to the same
281
283
  | `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: [...] }` |
282
284
  | `plugin-custom-host` | a `custom` element naming, by `renderType`, a plugin whose declaration the space was handed | place it from its declaration — `const seatPicker = defineElement(declaration)`, then `seatPicker({ id, … })`: typed by what it declares (a `definePlugin` declaration carries its attributes), the element the builder adds too |
283
285
  | `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, written in its area’s folder and listed in the space’s `components`; a link marks its own page with the `current` state |
284
- | `repeated-shape` | the same structure written again and again with different words — cards, rows, tiles; copies that bind different data, read their own template or render on the server are controls, not repeats | 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 |
286
+ | `repeated-shape` | the same structure written again and again with different words — cards, rows, tiles. Copies that read their data in a form of their own (their template) or render on the server are no repeats, and neither are copies side by side wired to different sources or state keys — controls written alike; copies apart that read different sources are one component, each instance handed its own | a component with props (`components`, `component(id, { props })`) — a source a copy reads handed in as a bound `json` prop (`component(id, { bind: [{ to: 'items', source }] })`, read inside as `props.items`) — or one `list` when they are rows of data side by side; a few cards a person rewords on the canvas can stay cards |
285
287
  | `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 |
286
288
  | `unused-component` | a component no page, layout or other component places | remove it from `components`, or place it where it was meant to go |
287
289
  | `unused-plugin` | a plugin the project declares that no page, layout or component places — built and shipped, drawn nowhere | place it where it was meant to go, or remove its folder from `src/plugins/` |
@@ -48,15 +48,15 @@ same flags, decided on the server. Use the step builders — they fill in where
48
48
 
49
49
  Name the trigger (`named('changed', on('onChange'))`) and read its payload as `{{ changed.<field> }}`:
50
50
 
51
- | Trigger | Payload |
52
- | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------- |
53
- | `onChange` (formControl) | `value` (a boolean for a checkbox or switch), `name` |
54
- | `onSubmit` (form) | `values` (by control `name`), `actionUrl`, `method` |
55
- | `onPageLoad` (page) | `pageId`, `routeParams`, `queryParams` |
56
- | `onApiSuccess` / `onApiError` (apiContainer) | `url`, `method`, `status`, `data` |
57
- | `onModalOpen` / `onModalClose`, `onDialogOpen` / `onDialogClose` / `onDialogAccept` / `onDialogReject` | `metadata` — what `openModal` / `openDialog` was handed |
58
- | `onPageChange` (pagination) | `page` |
59
- | `onThemeChange` (themeToggle) | `theme` |
51
+ | Trigger | Payload |
52
+ | ------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------- |
53
+ | `onChange` (formControl) | `value` (a boolean for a checkbox or switch, the `File` for a file), `name` |
54
+ | `onSubmit` (form) | `values` (by control `name`), `actionUrl`, `method` |
55
+ | `onPageLoad` (page) | `pageId`, `routeParams`, `queryParams` |
56
+ | `onApiSuccess` / `onApiError` (apiContainer) | `url`, `method`, `status`, `data` |
57
+ | `onModalOpen` / `onModalClose`, `onDialogOpen` / `onDialogClose` / `onDialogAccept` / `onDialogReject` | `metadata` — what `openModal` / `openDialog` was handed |
58
+ | `onPageChange` (pagination) | `page` |
59
+ | `onThemeChange` (themeToggle) | `theme` |
60
60
 
61
61
  ## Reading what came before
62
62
 
@@ -34,3 +34,15 @@ settings: { keepState: true, paintedState: ['shapesPick', 'name', 'color'], tran
34
34
  Only what the first paint shows, and small values: the cookie travels with every request and holds a few kilobytes
35
35
  (over that, the page falls back to the defaults and the dev tools say so). Never a secret — a key, a token — and never
36
36
  a key that is also in `transientState` (`authorSpace` refuses it).
37
+
38
+ Filed under whoever is signed in, what was kept goes when somebody else signs in — the guest's, too, when they sign
39
+ in. A choice made of the BROWSER rather than of the person — the cookie consent — is then asked again on every change
40
+ of account. List those keys in `browserState`: kept in an entry of their own that signing in, out or as somebody else
41
+ does not take away, and restored without waiting for auth. A key of the browser's is a kept one (`authorSpace` refuses
42
+ one that is transient or not in `keptState`), and may be painted too:
43
+
44
+ ```ts
45
+ settings: { keepState: true, paintedState: ['consent'], browserState: ['consent'] }
46
+ ```
47
+
48
+ Never something that belongs to an account — a workspace, a name: the next person on the browser would be handed it.
@@ -58,7 +58,8 @@ const NebulaRun = ({ shipColor = 'amber', best = 0, className }: NebulaRunProps)
58
58
  ```
59
59
 
60
60
  - **Render `RootElement`**, not a `div`: it carries the element's id, classes and `data-plitzi-el`, so the CSS
61
- authored on the element applies, the builder can select it and a test can find it.
61
+ authored on the element applies, the builder can select it and a test can find it. It is a `div` unless `tag` says
62
+ otherwise — `tag="span"` for an effect inside a line of text, `tag="section"`, `tag="button"`.
62
63
  - **Render the same thing on the server and on the first client pass** — a plugin is drawn on the server first. A
63
64
  clock, a random number or anything read from `window` belongs in an effect; a hydration mismatch discards the whole
64
65
  tree, not the plugin. A preference per device (a tab, muted) is never read from `localStorage` while rendering: write
@@ -196,7 +197,9 @@ belongs to the editor.
196
197
 
197
198
  A plugin's stylesheet ships in a layer below the space's (`plitzi-sdk-plugin`): the space's classes and `customCss`
198
199
  win over it whatever their specificity. Write it as
199
- `.css` files the plugin imports (in the server's head, its tokens seen) — never a CSS string in TypeScript.
200
+ `.css` files the plugin imports (in the server's head, its tokens seen) — never a CSS string in TypeScript. It comes
201
+ with the plugin: linked on the pages that draw it, on no other. A stylesheet several plugins need — a design system's —
202
+ is imported by each that uses it, never by one for the rest: those go unstyled on every page without that one.
200
203
 
201
204
  A file a library needs whole is imported as Vite imports it, and travels inside the bundle: `worker.js?raw` is its
202
205
  text (a worker, started from `URL.createObjectURL(new Blob([source]))`), `engine.wasm?inline` a data URI. Images and
@@ -38,8 +38,7 @@ export const space: SpaceSpec = {
38
38
  };
39
39
  ```
40
40
 
41
- A journey is held by an e2e test; an element check holds what one element makes of a state. `plitzi test --unit` runs
42
- no browser.
41
+ `plitzi test --unit` runs the element checks alone, no browser.
43
42
 
44
43
  - **Read with the space.** A test the space no longer answers — a page renamed, an element removed, a relation that is
45
44
  none — is the warning `test-unreadable` of `lintSpace` and `author`, wherever the space was changed: a `plitzi space
@@ -55,7 +54,8 @@ no browser.
55
54
  `settings.visitorRoles` — give; a page for signed-in visitors opens). A role the space removed since is warned. Declared in the tests alone — no real account, no password — so the API answers it as a
56
55
  guest: a journey with an account reads and moves, never writes.
57
56
  - **A `type` step names the element** — a form control's id — and replaces what the field inside it held; a select is
58
- chosen from (its option's value or label), a date, a time or a range set whole.
57
+ chosen from (its option's value or label), a date, a time or a range set whole, a file field given a real file of the
58
+ kind it names: `e2e.type('photo', 'me.png')`.
59
59
  - **A point of an element**: `e2e.click('map', { x: 30, y: 60 })` (and `hover`) lands at that percent of its box — a
60
60
  marker a canvas draws has no element of its own. `e2e.scroll(id)` brings it into view; with `{ dx, dy }` its own
61
61
  content scrolls.