@mccaskie-labs/workbench-site 0.14.1 → 0.15.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
@@ -1,5 +1,11 @@
1
1
  # @mccaskie-labs/workbench-site
2
2
 
3
+ ## 0.15.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 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.
8
+
3
9
  ## 0.14.1
4
10
 
5
11
  ### 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
@@ -331,7 +331,7 @@ function pageFile(r, version, base, pathOf) {
331
331
  const block = pre.length > 0;
332
332
  const waits = list || needs || owned || tools.length > 0;
333
333
  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)}` : "";
334
+ const area = r.area === "members" || r.area === "admin" ? `, area: ${JSON.stringify(r.area)}` : r.private ? ", private: true" : "";
335
335
  const prefix = `page.${r.id.replace(/-/g, "_")}.`;
336
336
  const frame = r.frames[0];
337
337
  const others = r.frames.slice(1);
@@ -607,6 +607,8 @@ const staging = () => testEnv({ WORKBENCH_ENV: "staging", WORKBENCH_GATEWAY_KEY:
607
607
  const MISSING = "/no-page-is-here-" + "x".repeat(8);
608
608
  /** What each page answers with: 200, but 404 for Not found and 500 for Something went wrong. */
609
609
  const STATUS: Readonly<Record<string, number>> = ${JSON.stringify(status)};
610
+ // Pages opened from a private link: out of search engines and caches.
611
+ const PRIVATE: ReadonlySet<string> = new Set(${JSON.stringify(pages.filter((p) => byId.get(p.recipe)?.private).map((p) => p.recipe))});
610
612
  const files = import.meta.glob<string>("../src/pages/*.ts", { query: "?raw", import: "default", eager: true });
611
613
 
612
614
  describe("site pages", () => {
@@ -629,7 +631,12 @@ ${enquiries ? " // The enquiries table isn't reached: each test says what it ho
629
631
  expect(html.split('<div class="wb-ui-guide">')[0]!.match(/<h1[ >]/g)?.length).toBe(1);
630
632
  // A word that's missing shows as "undefined" (the scripts a form brings may say it).
631
633
  expect(html.replace(/<script[^>]*>[\\s\\S]*?<\\/script>/g, "")).not.toContain("undefined");
632
- if (page.access !== "public") expect(html).toContain('<meta name="robots" content="noindex">');
634
+ if (page.access !== "public" || PRIVATE.has(page.recipe)) expect(html).toContain('<meta name="robots" content="noindex">');
635
+ if (PRIVATE.has(page.recipe)) {
636
+ expect(res.headers.get("cache-control")).toBe("private, no-store");
637
+ expect(res.headers.get("referrer-policy")).toBe("same-origin");
638
+ expect(html).not.toContain("cloudflareinsights");
639
+ }
633
640
  // In the site layout brand.json names (or its look's), as workbench-ui styles wrote it.
634
641
  expect(html).toContain(\`data-header="\${LAYOUT.header}"\`);
635
642
  expect(html).toContain(\`data-footer="\${LAYOUT.footer}"\`);
@@ -803,7 +810,7 @@ describe("enquiries", () => {
803
810
  }
804
811
  /** src/pages/site.ts: written once, then the project's. */
805
812
  /** 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"]);
813
+ const PAST_HELPERS = new Set(["dcf7ed6a", "ccd7d6a5", "c1d44c4f", "ffc5d608", "ee2ade9e", "9ee82f4f", "80cd163b", "3fa81665"]);
807
814
  /** FNV-1a, 32 bits: enough to know a file is one of a few texts, never a check of who wrote it. */
808
815
  function fnv(s) {
809
816
  let h = 0x811c9dc5;
@@ -874,6 +881,8 @@ export interface PageOptions {
874
881
  status?: number;
875
882
  /** Members and admin pages stay out of search engines; admin pages show the admin menu. */
876
883
  area?: "members" | "admin";
884
+ /** A public page opened from a private link: out of search engines and caches, no referrer, no visitor count, never framed. */
885
+ private?: boolean;
877
886
  /** The look to show instead of the page's own: the style guide's switch. Admin pages default to "admin". */
878
887
  view?: "light" | "dark" | "admin";
879
888
  /** Stylesheets after the site's own, such as the style guide's. */
@@ -892,9 +901,11 @@ export function sitePage(request: Request, env: Env, o: PageOptions, sections: (
892
901
  const link = ([label, href]: readonly [string, string, ...string[]]) => ({ label: w(label), href });
893
902
  // ?wb-look= and ?wb-scheme=: a public page in another look, for the look
894
903
  // 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");
904
+ // Members, admin and private link pages are someone's own.
905
+ const own = o.area !== undefined || o.private === true;
906
+ const preview = own ? null : previewAttributes(request.url, config.WORKBENCH_ENV !== "production");
896
907
  // 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);
908
+ const design = !own && config.WORKBENCH_ENV !== "production" && designModeOn(request);
898
909
  const html = frame({
899
910
  frame: o.frame,
900
911
  title: w(o.title),
@@ -907,8 +918,8 @@ export function sitePage(request: Request, env: Env, o: PageOptions, sections: (
907
918
  lang: locale,
908
919
  stylesheets: [...STYLESHEETS, ...(o.stylesheets ?? [])],
909
920
  // Visitor counts only on public pages.
910
- head: o.area ? "" : beacon(env),
911
- noindex: o.area !== undefined,
921
+ head: own ? "" : beacon(env),
922
+ noindex: own,
912
923
  // The theme's admin look: the project's accent and fonts on light neutrals.
913
924
  admin: o.view ? o.view === "admin" : o.area === "admin",
914
925
  ...(o.view === "light" || o.view === "dark" ? { scheme: o.view } : {}),
@@ -921,10 +932,12 @@ export function sitePage(request: Request, env: Env, o: PageOptions, sections: (
921
932
  headers: {
922
933
  "content-type": "text/html; charset=utf-8",
923
934
  // 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'",
935
+ "content-security-policy": own ? "frame-ancestors 'none'" : "frame-ancestors 'self'",
936
+ // A private link's token stays on this site.
937
+ ...(o.private ? { "referrer-policy": "same-origin" } : {}),
925
938
  "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" }),
939
+ // All of staging is owner-only, and members, admin and private link pages are someone's own, so never kept by a cache.
940
+ ...(config.WORKBENCH_ENV === "production" && !own ? {} : { "cache-control": "private, no-store" }),
928
941
  },
929
942
  });
930
943
  }
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/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.0",
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",