@mccaskie-labs/workbench-site 0.14.1 → 0.15.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,19 @@
1
1
  # @mccaskie-labs/workbench-site
2
2
 
3
+ ## 0.15.1
4
+
5
+ ### Patch Changes
6
+
7
+ - A page with a tool's own section names the words that section draws, in a comment beside the call, so the project's strings check finds them in use.
8
+ - A "needs you" count's word (such as Bookings' "Booking requests to answer") goes into the strings catalogue only with the admins' dashboard, where it is said. A site that adds Admin home later gets the words of the counts it already has.
9
+ - A tool's own section that ends the page has the same space under it as the site's sections, so it doesn't touch the footer.
10
+
11
+ ## 0.15.0
12
+
13
+ ### Minor Changes
14
+
15
+ - A private link page: a recipe with `private: true` is a public page opened from an emailed link with its token in the address, such as a booking's or a waiting list's. The site helper's new `private` option draws it out of search engines (noindex) and every cache (`private, no-store`), with `referrer-policy: same-origin`, no visitor count, no look preview or design mode, and never framed. Only a public page with an address can be one. The generated pages test checks each such page's headers. An unchanged helper from 0.14.0 or 0.14.1 is brought up to date.
16
+
3
17
  ## 0.14.1
4
18
 
5
19
  ### Patch Changes
package/README.md CHANGED
@@ -63,4 +63,4 @@ Each section takes plain words (escaped) and returns HTML with `wb-site-*` class
63
63
 
64
64
  ## A tool's own pages
65
65
 
66
- A tool's pages are recipes in its own package (`docs/site-planner.md` §5). Export them as `RECIPES` (a `readonly Recipe[]`, the type from this package) from a `./recipes` subpath in the package's `exports`. `npx workbench-site` gathers them from every Workbench package the project has installed, beside this package's own. Each recipe follows the same rules: ids unique across every package, words under `page.<id>.`, files only in `src/pages/` and `workbench/forms/`, and a `needsYou` count when its admin page has something waiting. A section only the tool can draw (a slot picker) is `{ kind: "tool", from: "<package>", fn: "<export>", words: [<its word keys>] }`: the export is a `ToolSectionFunction`, called with (request, env, ctx) before the page is drawn, which gives back a function that draws the section's HTML with the page's words, in the tool's own `wb-<tool>-*` classes.
66
+ A tool's pages are recipes in its own package (`docs/site-planner.md` §5). Export them as `RECIPES` (a `readonly Recipe[]`, the type from this package) from a `./recipes` subpath in the package's `exports`. `npx workbench-site` gathers them from every Workbench package the project has installed, beside this package's own. Each recipe follows the same rules: ids unique across every package, words under `page.<id>.`, files only in `src/pages/` and `workbench/forms/`, and a `needsYou` count when its admin page has something waiting. A section only the tool can draw (a slot picker) is `{ kind: "tool", from: "<package>", fn: "<export>", words: [<its word keys>] }`: the export is a `ToolSectionFunction`, called with (request, env, ctx) before the page is drawn, which gives back a function that draws the section's HTML with the page's words, in the tool's own `wb-<tool>-*` classes. A page opened from an emailed link that carries a token (a booking's manage link) sets `private: true`: it stays a public page, but out of search engines and caches, with no referrer, no visitor count and no framing.
package/dist/builder.js CHANGED
@@ -156,12 +156,21 @@ export function buildSite(o) {
156
156
  return fail();
157
157
  }
158
158
  const words = { ...strings };
159
+ // A "needs you" count's word is said only on the admins' dashboard (src/pages/needs.ts), so it comes with the dashboard.
160
+ const countWord = (r) => r.needsYou?.label;
159
161
  for (const id of added) {
160
162
  const r = byId.get(id);
161
163
  for (const k of recipeKeys(r))
162
- if (!(k in words))
164
+ if (!(k in words) && (dashboard || k !== countWord(r)))
163
165
  words[k] = r.words[k];
164
166
  }
167
+ if (dashboard)
168
+ for (const p of pages) {
169
+ const r = byId.get(p.recipe);
170
+ const k = r && countWord(r);
171
+ if (r && k && p.path !== null && !(k in words))
172
+ words[k] = r.words[k];
173
+ }
165
174
  writes[stringsPath] = `${JSON.stringify(words, null, 2)}\n`;
166
175
  // The dependency the page files import.
167
176
  let pkg;
@@ -306,7 +315,7 @@ function pageFile(r, version, base, pathOf) {
306
315
  if (s.kind !== "tool")
307
316
  return [s, sectionCode(s, pathOf, r.path)];
308
317
  n += 1;
309
- tools.push({ name: `tool${n}`, from: s.from, fn: s.fn });
318
+ tools.push({ name: `tool${n}`, from: s.from, fn: s.fn, words: s.words });
310
319
  return [s, `tool${n}(w)`];
311
320
  })
312
321
  .filter((x) => x[1] !== null);
@@ -325,13 +334,17 @@ function pageFile(r, version, base, pathOf) {
325
334
  ...(list ? [" const enquiries = await listEnquiries(env, ctx);"] : []),
326
335
  ...(needs ? [" // Each tool's count, read at once (src/pages/needs.ts).", " const needs = await readNeeds(env, ctx);"] : []),
327
336
  ...(guide ? [" // ?view=light, dark or admin: the switch at the top of the guide.", " const view = guideView(request.url);"] : []),
328
- ...tools.map((t) => ` const ${t.name} = await ${t.fn}(request, env, ctx);`),
337
+ ...tools.flatMap((t) => [
338
+ // The words the tool draws itself, named here so the strings check finds them in use.
339
+ ...(t.words.length ? [` // ${t.fn} draws its own words: ${t.words.map((k) => JSON.stringify(k)).join(", ")}.`] : []),
340
+ ` const ${t.name} = await ${t.fn}(request, env, ctx);`,
341
+ ]),
329
342
  ...(owned ? [" // The words the owner changed on the Settings page (\"Your pages' words\").", " const words = await ownerWords(env);"] : []),
330
343
  ];
331
344
  const block = pre.length > 0;
332
345
  const waits = list || needs || owned || tools.length > 0;
333
346
  const toolImports = [...new Set(tools.map((t) => t.from))].sort().map((from) => `import { ${[...new Set(tools.filter((t) => t.from === from).map((t) => t.fn))].sort().join(", ")} } from "${from}";`);
334
- const area = r.area === "members" || r.area === "admin" ? `, area: ${JSON.stringify(r.area)}` : "";
347
+ const area = r.area === "members" || r.area === "admin" ? `, area: ${JSON.stringify(r.area)}` : r.private ? ", private: true" : "";
335
348
  const prefix = `page.${r.id.replace(/-/g, "_")}.`;
336
349
  const frame = r.frames[0];
337
350
  const others = r.frames.slice(1);
@@ -607,6 +620,8 @@ const staging = () => testEnv({ WORKBENCH_ENV: "staging", WORKBENCH_GATEWAY_KEY:
607
620
  const MISSING = "/no-page-is-here-" + "x".repeat(8);
608
621
  /** What each page answers with: 200, but 404 for Not found and 500 for Something went wrong. */
609
622
  const STATUS: Readonly<Record<string, number>> = ${JSON.stringify(status)};
623
+ // Pages opened from a private link: out of search engines and caches.
624
+ const PRIVATE: ReadonlySet<string> = new Set(${JSON.stringify(pages.filter((p) => byId.get(p.recipe)?.private).map((p) => p.recipe))});
610
625
  const files = import.meta.glob<string>("../src/pages/*.ts", { query: "?raw", import: "default", eager: true });
611
626
 
612
627
  describe("site pages", () => {
@@ -629,7 +644,12 @@ ${enquiries ? " // The enquiries table isn't reached: each test says what it ho
629
644
  expect(html.split('<div class="wb-ui-guide">')[0]!.match(/<h1[ >]/g)?.length).toBe(1);
630
645
  // A word that's missing shows as "undefined" (the scripts a form brings may say it).
631
646
  expect(html.replace(/<script[^>]*>[\\s\\S]*?<\\/script>/g, "")).not.toContain("undefined");
632
- if (page.access !== "public") expect(html).toContain('<meta name="robots" content="noindex">');
647
+ if (page.access !== "public" || PRIVATE.has(page.recipe)) expect(html).toContain('<meta name="robots" content="noindex">');
648
+ if (PRIVATE.has(page.recipe)) {
649
+ expect(res.headers.get("cache-control")).toBe("private, no-store");
650
+ expect(res.headers.get("referrer-policy")).toBe("same-origin");
651
+ expect(html).not.toContain("cloudflareinsights");
652
+ }
633
653
  // In the site layout brand.json names (or its look's), as workbench-ui styles wrote it.
634
654
  expect(html).toContain(\`data-header="\${LAYOUT.header}"\`);
635
655
  expect(html).toContain(\`data-footer="\${LAYOUT.footer}"\`);
@@ -803,7 +823,7 @@ describe("enquiries", () => {
803
823
  }
804
824
  /** src/pages/site.ts: written once, then the project's. */
805
825
  /** Each helper an earlier workbench-site wrote, by its FNV-1a hash: a project still holding one unchanged gets the newest. */
806
- const PAST_HELPERS = new Set(["dcf7ed6a", "ccd7d6a5", "c1d44c4f", "ffc5d608", "ee2ade9e", "9ee82f4f", "80cd163b"]);
826
+ const PAST_HELPERS = new Set(["dcf7ed6a", "ccd7d6a5", "c1d44c4f", "ffc5d608", "ee2ade9e", "9ee82f4f", "80cd163b", "3fa81665"]);
807
827
  /** FNV-1a, 32 bits: enough to know a file is one of a few texts, never a check of who wrote it. */
808
828
  function fnv(s) {
809
829
  let h = 0x811c9dc5;
@@ -874,6 +894,8 @@ export interface PageOptions {
874
894
  status?: number;
875
895
  /** Members and admin pages stay out of search engines; admin pages show the admin menu. */
876
896
  area?: "members" | "admin";
897
+ /** A public page opened from a private link: out of search engines and caches, no referrer, no visitor count, never framed. */
898
+ private?: boolean;
877
899
  /** The look to show instead of the page's own: the style guide's switch. Admin pages default to "admin". */
878
900
  view?: "light" | "dark" | "admin";
879
901
  /** Stylesheets after the site's own, such as the style guide's. */
@@ -892,9 +914,11 @@ export function sitePage(request: Request, env: Env, o: PageOptions, sections: (
892
914
  const link = ([label, href]: readonly [string, string, ...string[]]) => ({ label: w(label), href });
893
915
  // ?wb-look= and ?wb-scheme=: a public page in another look, for the look
894
916
  // previewer. Never on the live site, and never on a members or admin page.
895
- const preview = o.area ? null : previewAttributes(request.url, config.WORKBENCH_ENV !== "production");
917
+ // Members, admin and private link pages are someone's own.
918
+ const own = o.area !== undefined || o.private === true;
919
+ const preview = own ? null : previewAttributes(request.url, config.WORKBENCH_ENV !== "production");
896
920
  // Design mode (/admin/design): on the test site, a public page carries the design script, for the admin who turned it on.
897
- const design = !o.area && config.WORKBENCH_ENV !== "production" && designModeOn(request);
921
+ const design = !own && config.WORKBENCH_ENV !== "production" && designModeOn(request);
898
922
  const html = frame({
899
923
  frame: o.frame,
900
924
  title: w(o.title),
@@ -907,8 +931,8 @@ export function sitePage(request: Request, env: Env, o: PageOptions, sections: (
907
931
  lang: locale,
908
932
  stylesheets: [...STYLESHEETS, ...(o.stylesheets ?? [])],
909
933
  // Visitor counts only on public pages.
910
- head: o.area ? "" : beacon(env),
911
- noindex: o.area !== undefined,
934
+ head: own ? "" : beacon(env),
935
+ noindex: own,
912
936
  // The theme's admin look: the project's accent and fonts on light neutrals.
913
937
  admin: o.view ? o.view === "admin" : o.area === "admin",
914
938
  ...(o.view === "light" || o.view === "dark" ? { scheme: o.view } : {}),
@@ -921,10 +945,12 @@ export function sitePage(request: Request, env: Env, o: PageOptions, sections: (
921
945
  headers: {
922
946
  "content-type": "text/html; charset=utf-8",
923
947
  // Public pages may be framed by the site itself, for the look previewer; members and admin pages by nothing.
924
- "content-security-policy": o.area ? "frame-ancestors 'none'" : "frame-ancestors 'self'",
948
+ "content-security-policy": own ? "frame-ancestors 'none'" : "frame-ancestors 'self'",
949
+ // A private link's token stays on this site.
950
+ ...(o.private ? { "referrer-policy": "same-origin" } : {}),
925
951
  "x-content-type-options": "nosniff",
926
- // All of staging is owner-only, and members and admin pages are someone's own, so never kept by a cache.
927
- ...(config.WORKBENCH_ENV === "production" && !o.area ? {} : { "cache-control": "private, no-store" }),
952
+ // All of staging is owner-only, and members, admin and private link pages are someone's own, so never kept by a cache.
953
+ ...(config.WORKBENCH_ENV === "production" && !own ? {} : { "cache-control": "private, no-store" }),
928
954
  },
929
955
  });
930
956
  }
package/dist/recipe.d.ts CHANGED
@@ -202,6 +202,12 @@ export interface Recipe {
202
202
  tier: Tier;
203
203
  /** Sets the access rule the builder writes: public, members (signed in) or admin (signed in and one of the app's admins). Legal pages come with step 4. */
204
204
  area: Area;
205
+ /**
206
+ * A public page opened from a private link (a booking's or waiting list's emailed
207
+ * link, with its token in the address): it stays out of search engines and every
208
+ * cache, sends no referrer, carries no visitor count and is never framed.
209
+ */
210
+ private?: true;
205
211
  /** Its default address. Null for a page no address opens: Not found (status 404) and Something went wrong (status 500). */
206
212
  path: string | null;
207
213
  /** The answer's status: 404 for Not found, 500 for Something went wrong. Defaults to 200. */
package/dist/recipe.js CHANGED
@@ -145,6 +145,8 @@ export function recipeProblems(r, catalogue) {
145
145
  p("an admin page's address starts /admin");
146
146
  if (r.area !== "public" && r.path === null)
147
147
  p("a page with no path is public");
148
+ if (r.private !== undefined && (r.private !== true || r.area !== "public" || r.path === null))
149
+ p("only a public page with an address is a private link page");
148
150
  for (const s of r.sections) {
149
151
  if (s.kind === "account" && r.area !== "members")
150
152
  p("the account section is for members pages");
package/dist/styles.js CHANGED
@@ -74,6 +74,7 @@ export const SITE_STYLES = {
74
74
  states: [
75
75
  { selector: "[data-frame=\"landing\"]", about: "Landing frame: full width", css: `max-width:${v("width")}` },
76
76
  { selector: "[data-frame=\"column\"]", about: "Column frame: one reading-width column", css: `max-width:${v("reading")}` },
77
+ { selector: " > :last-child:not(.wb-site-section):not(.wb-site-columns)", about: "A tool's own section last on the page: the same space under it as under the site's sections", css: `margin-bottom:${v("section-space")}` },
77
78
  { selector: "[data-frame=\"two-columns\"]", about: "Two-columns frame: the first section across the top, the rest beside each other", css: `max-width:${v("width")}` },
78
79
  ],
79
80
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mccaskie-labs/workbench-site",
3
- "version": "0.14.1",
3
+ "version": "0.15.1",
4
4
  "description": "A Workbench project's standard pages: page recipes, the builder that turns them into thin page files calling Workbench's tools, and the page frames and sections they are drawn with (wb-site-*, restylable, on the project's theme tokens).",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",