@plitzi/sdk-server 0.39.2 → 0.39.4

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.
Files changed (66) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +49 -7
  3. package/dist/auth.d.ts +3 -2
  4. package/dist/auth.js +26 -107
  5. package/dist/cache.js +1 -1
  6. package/dist/chunks/{buildBody-W9D8ySNY.js → buildBody-BSC0UbjP.js} +352 -110
  7. package/dist/chunks/{core-TlrWmT4B.js → core-w7FIMpgv.js} +86 -4
  8. package/dist/chunks/{createServer-Bd_b7T3k.js → createServer-BQ0KE0Qu.js} +157 -34
  9. package/dist/chunks/{platform-DhdFYWm5.js → platform-C0AVlwpB.js} +2 -2
  10. package/dist/chunks/throttle-CRiZB6_A.js +330 -0
  11. package/dist/chunks/{token-B2uY9JzU.js → token-CBUubxtm.js} +1 -1
  12. package/dist/chunks/views/template.ejs +7 -0
  13. package/dist/core/auth/api/context.d.ts +4 -4
  14. package/dist/core/auth/api/values.d.ts +6 -0
  15. package/dist/core/auth/createAuth.d.ts +1 -1
  16. package/dist/core/auth/throttle.d.ts +54 -4
  17. package/dist/core/createServer.d.ts +1 -1
  18. package/dist/core/platform.d.ts +1 -1
  19. package/dist/core/services/iconFaces.d.ts +3 -0
  20. package/dist/core/services/llmsTxt.d.ts +15 -0
  21. package/dist/core/services/robotsTxt.d.ts +2 -8
  22. package/dist/core/services/securityTxt.d.ts +10 -0
  23. package/dist/handlers.js +1 -1
  24. package/dist/helpers/documentParts.d.ts +10 -0
  25. package/dist/helpers/paintedCookie.d.ts +15 -1
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +3 -3
  28. package/dist/modules/icons/glyphs.d.ts +21 -0
  29. package/dist/modules/icons/handler.d.ts +11 -0
  30. package/dist/modules/icons/spaceIcons.d.ts +26 -0
  31. package/dist/modules/rsc/connectorRscData.d.ts +4 -2
  32. package/dist/modules/rsc/resolveRscData.d.ts +4 -1
  33. package/dist/modules/ssr/csrfHint.d.ts +12 -0
  34. package/dist/modules/ssr/defaultFavicon.d.ts +1 -1
  35. package/dist/modules/ssr/spaceDocument.d.ts +8 -1
  36. package/dist/oauth.js +1 -1
  37. package/dist/platform.d.ts +1 -1
  38. package/dist/platform.js +1 -1
  39. package/dist/project.js +3 -3
  40. package/dist/spaces.js +1 -1
  41. package/dist/ssr.js +1 -1
  42. package/dist/types/config.d.ts +24 -0
  43. package/dist/types/index.d.ts +1 -1
  44. package/package.json +10 -8
  45. package/skills/plitzi-authoring/recipes/accordion.ts +3 -1
  46. package/skills/plitzi-authoring/recipes/carousel.ts +68 -63
  47. package/skills/plitzi-authoring/recipes/detail-page.ts +43 -33
  48. package/skills/plitzi-authoring/recipes/embed-and-svg.ts +16 -11
  49. package/skills/plitzi-authoring/recipes/every-few-seconds.ts +52 -42
  50. package/skills/plitzi-authoring/recipes/feature-flag.ts +7 -2
  51. package/skills/plitzi-authoring/recipes/filter-a-list.ts +39 -31
  52. package/skills/plitzi-authoring/recipes/forms-and-modals.ts +34 -28
  53. package/skills/plitzi-authoring/recipes/from-tailwind.ts +11 -6
  54. package/skills/plitzi-authoring/recipes/link-to-a-section.ts +11 -6
  55. package/skills/plitzi-authoring/recipes/link-with-data.ts +21 -16
  56. package/skills/plitzi-authoring/recipes/marquee.ts +17 -12
  57. package/skills/plitzi-authoring/recipes/plugin.ts +16 -10
  58. package/skills/plitzi-authoring/recipes/scroll-a-row.ts +30 -25
  59. package/skills/plitzi-authoring/recipes/server-data.ts +15 -10
  60. package/skills/plitzi-authoring/recipes/show-data.ts +32 -24
  61. package/skills/plitzi-authoring/recipes/style-a-page.ts +9 -4
  62. package/skills/plitzi-authoring/recipes/typed-data.ts +26 -21
  63. package/skills/plitzi-authoring/recipes/usable-without-sight.ts +16 -11
  64. package/skills/plitzi-authoring/reference/authoring-errors.md +3 -0
  65. package/skills/plitzi-authoring/reference/efficiency.md +2 -1
  66. package/dist/chunks/throttle-BH7JLIOF.js +0 -108
@@ -1,9 +1,9 @@
1
- import { schemaFromWire } from "@plitzi/sdk-shared/schema";
1
+ import { schemaForPage, schemaFromWire, splitSchema } from "@plitzi/sdk-shared/schema";
2
2
  import { compressBody, frameAncestorsOf, requestAuthority, requestOrigin } from "@plitzi/sdk-kernel/http";
3
3
  import { serverLog } from "@plitzi/sdk-kernel/log";
4
4
  import { flagsCookieName } from "@plitzi/sdk-shared/flags";
5
5
  import { TRUSTED_TYPES_POLICIES, getKeyDecoded, isRecord } from "@plitzi/sdk-shared/helpers";
6
- import { paintedKeys, paintedStateCookieName, paintedStateFor } from "@plitzi/sdk-shared/state";
6
+ import { paintedKeys, paintedStateCookieName, paintedStateFor, pickPainted } from "@plitzi/sdk-shared/state";
7
7
  import { frameAncestors, sessionCookieParams, sessionHintCookieName } from "@plitzi/sdk-kernel/identity";
8
8
  import { TtlCache } from "@plitzi/sdk-kernel/cache";
9
9
  import { debugCookieName } from "@plitzi/sdk-shared/devTools";
@@ -38,6 +38,44 @@ var requestPaintedState = (req, settings, account) => {
38
38
  state: paintedStateFor(req.headers.cookie, ssrPaintedCookieName(requestAuthority(req)), settings, account)
39
39
  };
40
40
  };
41
+ /** One answer a request: the render and its server providers read the same, and the deployment is asked once. */
42
+ var resolved = /* @__PURE__ */ new WeakMap();
43
+ /**
44
+ * `requestPaintedState` with the deployment's defaults (`paintedDefaults`) for the keys the cookie holds none of — for
45
+ * an account the request proved, never a guest: a guest's page is cached for every guest, and a default is an
46
+ * account's. Another account's entry holds nothing for this one (`paintedStateFor`), so after a change of account the
47
+ * defaults are this account's. A deployment that fails to answer is said in the log, and the page is drawn without.
48
+ */
49
+ var requestPaintedStateWithDefaults = (req, settings, scope, defaults) => {
50
+ const known = resolved.get(req);
51
+ if (known) return known;
52
+ const { account } = scope;
53
+ const painted = requestPaintedState(req, settings, account);
54
+ const missing = [...painted.keys].filter((key) => painted.state?.[key] === void 0);
55
+ const answer = !defaults || account === void 0 || missing.length === 0 ? Promise.resolve(painted) : (async () => {
56
+ try {
57
+ const given = await defaults({
58
+ spaceId: scope.spaceId,
59
+ environment: scope.environment,
60
+ account,
61
+ keys: missing
62
+ });
63
+ const added = pickPainted(given, new Set(missing));
64
+ return Object.keys(added).length > 0 ? {
65
+ keys: painted.keys,
66
+ state: {
67
+ ...painted.state,
68
+ ...added
69
+ }
70
+ } : painted;
71
+ } catch (error) {
72
+ serverLog.error("SSR", `paintedDefaults did not answer for ${missing.join(", ")}: drawn without`, error);
73
+ return painted;
74
+ }
75
+ })();
76
+ resolved.set(req, answer);
77
+ return answer;
78
+ };
41
79
  // src/helpers/cache/defaults.ts
42
80
  var DEFAULT_TTL_MS = {
43
81
  html: 3e5,
@@ -501,7 +539,7 @@ var styleSheetOf = (offlineData) => {
501
539
  sheets.set(offlineData.style, null);
502
540
  return;
503
541
  }
504
- const css = styleSheetCss(offlineData.style.cache);
542
+ const css = styleSheetCss(offlineData.style.cache, offlineData.schema.settings.customCss);
505
543
  const hash = digest(css);
506
544
  const sheet = {
507
545
  css,
@@ -535,6 +573,13 @@ var spaceDocument = (offlineData, { linkStyle = true } = {}) => {
535
573
  const sheet = linkStyle ? styleSheetOf(offlineData) : void 0;
536
574
  const data = sheet ? {
537
575
  ...offlineData,
576
+ schema: {
577
+ ...offlineData.schema,
578
+ settings: {
579
+ ...offlineData.schema.settings,
580
+ customCss: ""
581
+ }
582
+ },
538
583
  style: {
539
584
  ...offlineData.style,
540
585
  cache: "",
@@ -761,6 +806,43 @@ var createOfflineDataLoader = (read) => {
761
806
  let pending;
762
807
  return () => pending ??= read();
763
808
  };
809
+ // src/helpers/documentParts.ts
810
+ var served = /* @__PURE__ */ new WeakMap();
811
+ /** A part as it is fetched: its root and its elements, escaped as the document is. */
812
+ var textOf = (part) => escapeJson(JSON.stringify(part));
813
+ var servedOf = (schema, withheld) => {
814
+ const known = served.get(schema);
815
+ if (known) return known;
816
+ const texts = /* @__PURE__ */ new Map();
817
+ const parts = {
818
+ split: splitSchema(schema, (part) => {
819
+ const text = textOf(part);
820
+ const name = digest(text);
821
+ texts.set(name, text);
822
+ return name;
823
+ }, withheld),
824
+ texts,
825
+ pages: /* @__PURE__ */ new Map()
826
+ };
827
+ served.set(schema, parts);
828
+ return parts;
829
+ };
830
+ /**
831
+ * Whether this space is sent in parts: unless it asks for the whole (`settings.wholeDocument`), or has a single page —
832
+ * nothing to fetch later, so the shell would only be split for nothing.
833
+ */
834
+ var sentInParts = (schema) => schema.settings.wholeDocument !== true && schema.pages.length > 1;
835
+ /** The schema a page is sent with: the shell, that page's part and its layouts' — the same object for every visit. */
836
+ var pageSchemaOf = (schema, withheld, pageId) => {
837
+ const parts = servedOf(schema, withheld);
838
+ const known = parts.pages.get(pageId);
839
+ if (known) return known;
840
+ const page = schemaForPage(parts.split, pageId);
841
+ parts.pages.set(pageId, page);
842
+ return page;
843
+ };
844
+ /** A part's text by its name, for this group of visitors; none for a name their shell does not give. */
845
+ var partTextOf = (schema, withheld, name) => servedOf(schema, withheld).texts.get(name);
764
846
  // src/modules/ssr/scriptPolicy.ts
765
847
  /** Where a browser reports what the page's script policy would have refused (`cspReportStage`). */
766
848
  var CSP_REPORT_PATH = "/_plitzi/csp-report";
@@ -2115,4 +2197,4 @@ var createRedisPageStore = (client, { prefix = "plitzi:{pages}:", maxBytes = byt
2115
2197
  return typeof count === "number" ? count : 0;
2116
2198
  }
2117
2199
  });
2118
- export { visitorScheme as $, shareCache as A, renderLimitOf as B, createOfflineDataLoader as C, cacheLimitsOf as D, normalizePlugins as E, offlineDataWith as F, buildCacheManager as G, keepPage as H, spaceDocument as I, keepsVersion as J, buildHtmlCacheKey as K, styleSheetOf as L, destroyServerCaches as M, digest as N, cacheFilterOf as O, hydrationPayload as P, SCHEME_HINT_HEADER as Q, DEFAULT_RENDER_WAIT_MS as R, sendScriptPolicy as S, normalizePluginSource as T, pageHtml as U, fromSharedPage as V, toSharedPage as W, ignoredQueryParamsOf as X, offlineDataCacheKeyOf as Y, renderedQuery as Z, buildServerInfo as _, presentsCredential as a, CSP_REPORT_PATH as b, wildcardSubdomain as c, createAuthAdapters as d, readCookie as et, createJsonAdapters as f, resolveDebugMode as g, escapeHtml as h, fixedSpace as i, requestPaintedState as it, createServerCaches as j, createCacheInvalidator as k, createMemoryCache as l, RequestMetrics as m, createSpaceAdapters as n, DEFAULT_IGNORED_QUERY_PARAMS as nt, renderGrant as o, createCloudAdapters as p, buildRscCacheKey as q, authoringPreview as r, DEFAULT_TTL_MS as rt, verifiedDomain as s, createRedisPageStore as t, DEFAULT_CACHE_BYTES as tt, refuse as u, googleFontsStage as v, reportReactBuild as w, scriptTemplateParams as x, googleFontsUrlOf as y, renderLimitFor as z };
2200
+ export { ignoredQueryParamsOf as $, cacheLimitsOf as A, styleSheetOf as B, pageSchemaOf as C, reportReactBuild as D, createOfflineDataLoader as E, destroyServerCaches as F, keepPage as G, renderLimitFor as H, digest as I, buildCacheManager as J, pageHtml as K, hydrationPayload as L, createCacheInvalidator as M, shareCache as N, normalizePluginSource as O, createServerCaches as P, offlineDataCacheKeyOf as Q, offlineDataWith as R, sendScriptPolicy as S, sentInParts as T, renderLimitOf as U, DEFAULT_RENDER_WAIT_MS as V, fromSharedPage as W, buildRscCacheKey as X, buildHtmlCacheKey as Y, keepsVersion as Z, buildServerInfo as _, presentsCredential as a, DEFAULT_IGNORED_QUERY_PARAMS as at, CSP_REPORT_PATH as b, wildcardSubdomain as c, createAuthAdapters as d, renderedQuery as et, createJsonAdapters as f, resolveDebugMode as g, escapeHtml as h, fixedSpace as i, DEFAULT_CACHE_BYTES as it, cacheFilterOf as j, normalizePlugins as k, createMemoryCache as l, RequestMetrics as m, createSpaceAdapters as n, visitorScheme as nt, renderGrant as o, DEFAULT_TTL_MS as ot, createCloudAdapters as p, toSharedPage as q, authoringPreview as r, readCookie as rt, verifiedDomain as s, requestPaintedStateWithDefaults as st, createRedisPageStore as t, SCHEME_HINT_HEADER as tt, refuse as u, googleFontsStage as v, partTextOf as w, scriptTemplateParams as x, googleFontsUrlOf as y, spaceDocument as z };
@@ -1,11 +1,11 @@
1
- import { C as draftSessionCookie, E as matchRscPage, S as createMemoryDraftStore, T as invalidatePluginComponentCache, _ as handleSpaceDocument, a as resolveSdkAssetsDir, b as resolveServices, c as applySSRResult, d as withNotFound, f as withRefusal, g as handleCurrentSpace, h as answerCurrentSpacePreflight, i as pageAssets, l as isReusable, n as prepareRender, o as imagesStage, s as Component, t as buildBody, u as renderParamsOf, v as meterPage, w as takeDraftOverride, x as DRAFT_STORE_METHODS, y as resolveRscEndpoint } from "./buildBody-W9D8ySNY.js";
2
- import { A as shareCache, B as renderLimitOf, C as createOfflineDataLoader, D as cacheLimitsOf, E as normalizePlugins, G as buildCacheManager, H as keepPage, J as keepsVersion, K as buildHtmlCacheKey, L as styleSheetOf, M as destroyServerCaches, O as cacheFilterOf, Q as SCHEME_HINT_HEADER, S as sendScriptPolicy, T as normalizePluginSource, U as pageHtml, V as fromSharedPage, W as toSharedPage, X as ignoredQueryParamsOf, Y as offlineDataCacheKeyOf, Z as renderedQuery, h as escapeHtml, it as requestPaintedState, j as createServerCaches, m as RequestMetrics, q as buildRscCacheKey, rt as DEFAULT_TTL_MS$1, tt as DEFAULT_CACHE_BYTES, v as googleFontsStage, w as reportReactBuild, z as renderLimitFor } from "./core-TlrWmT4B.js";
1
+ import { A as matchRscPage, C as spaceIconsOf, D as draftSessionCookie, E as createMemoryDraftStore, O as takeDraftOverride, S as ICONS_PATH, T as DRAFT_STORE_METHODS, _ as resolveServices, a as applySSRResult, b as pageAssets, c as withNotFound, f as answerCurrentSpacePreflight, g as resolveRscEndpoint, h as meterPage, i as Component, k as invalidatePluginComponentCache, l as withRefusal, m as handleSpaceDocument, n as prepareRender, o as isReusable, p as handleCurrentSpace, r as imagesStage, s as renderParamsOf, t as buildBody, v as resolvePageSeo, w as iconGlyphsAt, x as resolveSdkAssetsDir } from "./buildBody-BSC0UbjP.js";
2
+ import { $ as ignoredQueryParamsOf, A as cacheLimitsOf, B as styleSheetOf, D as reportReactBuild, E as createOfflineDataLoader, F as destroyServerCaches, G as keepPage, H as renderLimitFor, J as buildCacheManager, K as pageHtml, N as shareCache, O as normalizePluginSource, P as createServerCaches, Q as offlineDataCacheKeyOf, S as sendScriptPolicy, U as renderLimitOf, W as fromSharedPage, X as buildRscCacheKey, Y as buildHtmlCacheKey, Z as keepsVersion, et as renderedQuery, h as escapeHtml, it as DEFAULT_CACHE_BYTES, j as cacheFilterOf, k as normalizePlugins, m as RequestMetrics, ot as DEFAULT_TTL_MS$1, q as toSharedPage, st as requestPaintedStateWithDefaults, tt as SCHEME_HINT_HEADER, v as googleFontsStage } from "./core-w7FIMpgv.js";
3
3
  import { n as renewForNavigation, t as isDocumentNavigation } from "./renewal-D98v6-Jd.js";
4
4
  import { t as compileTemplate } from "./template-M3IEZ6os.js";
5
- import { n as createMemoryRateLimit, t as RATE_LIMIT_METHODS } from "./throttle-BH7JLIOF.js";
5
+ import { n as createRateLimit, t as RATE_LIMIT_METHODS } from "./throttle-CRiZB6_A.js";
6
6
  import { dataDirLookup } from "@plitzi/sdk-kernel/data";
7
7
  import { cappedResponse, fetchOutbound, privateOriginsOf } from "@plitzi/sdk-kernel/outbound";
8
- import { DEFAULT_FAVICON, RSC_FAILURE, collectServerElements, inputProviders, inputReadings, pageAccessOf, pageAccessRefusal, serverInputOf, serverProviderSource, serverQueryOf, serverWhenValues, whenOf, whenProviders, whenUnknownToServer, withholdPages } from "@plitzi/sdk-shared/schema";
8
+ import { DEFAULT_FAVICON, PLITZI_MARK_SVG, RSC_FAILURE, blockedAiCrawlers, collectServerElements, inputProviders, inputReadings, pageAccessOf, pageAccessRefusal, serverInputOf, serverProviderSource, serverQueryOf, serverWhenValues, whenOf, whenProviders, whenUnknownToServer, withholdPages } from "@plitzi/sdk-shared/schema";
9
9
  import http from "node:http";
10
10
  import https from "node:https";
11
11
  import fs, { readFile } from "node:fs/promises";
@@ -17,7 +17,7 @@ import { evaluateRuleGroup } from "@plitzi/sdk-shared/conditions";
17
17
  import { getSourceName } from "@plitzi/sdk-shared/dataSource/helpers";
18
18
  import { resolveVariables } from "@plitzi/sdk-shared/dataSource/variables";
19
19
  import { flagUserFromSSR, flagValues, forcedFlagsFromCookies, requestFlagOverrides, resolveFlags } from "@plitzi/sdk-shared/flags";
20
- import { sitemapPaths } from "@plitzi/sdk-shared/navigation";
20
+ import { sitemapPages, sitemapPaths } from "@plitzi/sdk-shared/navigation";
21
21
  import { isRecord } from "@plitzi/sdk-shared/helpers";
22
22
  import { knowHostDeployment } from "@plitzi/sdk-kernel/deployment";
23
23
  import { PREVIEW_TOKEN_PARAM, appendCookies, clearSessionCookies, readCookies, readDraftToken, readRenewalGuard, readSessionHint, readSessionToken, resolveDebugAuthorization, writeRenewalGuard, writeSessionCookies } from "@plitzi/sdk-kernel/identity";
@@ -328,7 +328,7 @@ var withBudget = async (run, timeoutMs, label, asked) => {
328
328
  * and the route params are what the browser will see. Each `runtime: 'server'` element resolves independently:
329
329
  * a provider that fails or hangs costs its own slice and nothing else.
330
330
  */
331
- var resolveRscData = async ({ schema, req, spaceId, environment, user, ids, resolveElement, flagOverrides, timeoutMs = DEFAULT_ELEMENT_TIMEOUT_MS, signal, sayFailures = false }) => {
331
+ var resolveRscData = async ({ schema, req, spaceId, environment, user, ids, resolveElement, flagOverrides, timeoutMs = DEFAULT_ELEMENT_TIMEOUT_MS, signal, sayFailures = false, paintedDefaults }) => {
332
332
  if (schema.rsc?.enabled === false) return {};
333
333
  const match = matchRscPage(schema, req.path, user);
334
334
  if (!match) return { serverData: {} };
@@ -345,7 +345,11 @@ var resolveRscData = async ({ schema, req, spaceId, environment, user, ids, reso
345
345
  const asked = ids ? new Set(ids) : void 0;
346
346
  const targets = asked ? all.filter((element) => asked.has(element.id)) : all;
347
347
  if (targets.length === 0) return { serverData: {} };
348
- const painted = requestPaintedState(req, schema.settings, user?.id);
348
+ const painted = await requestPaintedStateWithDefaults(req, schema.settings, {
349
+ spaceId,
350
+ environment,
351
+ account: user?.id
352
+ }, paintedDefaults);
349
353
  const templateData = {
350
354
  variables: resolveVariables(schema.variables, {
351
355
  routeParams,
@@ -450,7 +454,7 @@ var resolveRscData = async ({ schema, req, spaceId, environment, user, ids, reso
450
454
  *
451
455
  * A deployment that resolves server elements some other way still supplies its own `getRscData`, and that one wins.
452
456
  */
453
- var connectorRscData = ({ engine, publicDir, data, elementTimeoutMs, sayFailures = false, outbound, visitorCredentials }) => {
457
+ var connectorRscData = ({ engine, publicDir, data, elementTimeoutMs, sayFailures = false, outbound, visitorCredentials, paintedDefaults }) => {
454
458
  const resolvePublicFile = publicDir ? publicFileResolver(publicDir) : void 0;
455
459
  const resolveDataFile = data ? dataLookupResolver(data) : void 0;
456
460
  const readExternal = externalQueryReader({
@@ -501,6 +505,7 @@ var connectorRscData = ({ engine, publicDir, data, elementTimeoutMs, sayFailures
501
505
  ...flagOverrides ? { flagOverrides } : {},
502
506
  ...signal ? { signal } : {},
503
507
  ...elementTimeoutMs === void 0 ? {} : { timeoutMs: elementTimeoutMs },
508
+ ...paintedDefaults ? { paintedDefaults } : {},
504
509
  sayFailures
505
510
  });
506
511
  };
@@ -1501,6 +1506,68 @@ var createLivePages = () => {
1501
1506
  }
1502
1507
  };
1503
1508
  };
1509
+ // src/modules/icons/handler.ts
1510
+ var FACE_PATH = new RegExp(`^${ICONS_PATH.replace(/\//g, "\\/")}([\\w-]{16})-(solid|regular|brands)\\.woff2$`);
1511
+ /** The faces cut, by hash and face: a few kilobytes each, the same for every replica that cuts them. */
1512
+ var CUT_KEEP = 128;
1513
+ var cut = /* @__PURE__ */ new Map();
1514
+ var cutFace = (sdkDir, face, key) => {
1515
+ const known = cut.get(key);
1516
+ if (known) return known;
1517
+ const made = (async () => {
1518
+ const { default: subsetFont } = await import("subset-font");
1519
+ return subsetFont(await readFile(path.join(sdkDir, "webfonts", face.file)), String.fromCodePoint(...face.codepoints), { targetFormat: "woff2" });
1520
+ })();
1521
+ cut.set(key, made);
1522
+ made.catch(() => cut.delete(key));
1523
+ if (cut.size > CUT_KEEP) {
1524
+ const oldest = cut.keys().next().value;
1525
+ if (oldest !== void 0) cut.delete(oldest);
1526
+ }
1527
+ return made;
1528
+ };
1529
+ var notFound = (res, message) => {
1530
+ res.setStatus(404);
1531
+ res.setHeader("Cache-Control", "no-store");
1532
+ res.setHeader("Content-Type", "text/plain; charset=utf-8");
1533
+ res.send(message);
1534
+ };
1535
+ /**
1536
+ * A face of the icon font cut to the glyphs the space names (`spaceIconsOf`), linked by its pages' heads — answered by
1537
+ * whichever replica the request reaches, from the space as the request resolves it, as the stylesheet is. The name is
1538
+ * the glyphs': asked for by the name it has now, it is kept for good; by an older one, it answers the space's glyphs as
1539
+ * they are, kept by nobody — a glyph either lacks is drawn from the whole font all the same.
1540
+ */
1541
+ var handleIconFace = async (req, res, config, sdkDir, offlineDataCache) => {
1542
+ const asked = FACE_PATH.exec(req.path);
1543
+ if (!asked || !sdkDir) {
1544
+ notFound(res, sdkDir ? "No such icon face" : "This server has no SDK installed to cut icon faces from");
1545
+ return;
1546
+ }
1547
+ const [, hash, key] = asked;
1548
+ const { environment = "main", revision = 0 } = req.ctx.spaceDeployment ?? {};
1549
+ const spaceId = req.ctx.spaceDeployment?.spaceId ?? 1;
1550
+ const cacheKey = offlineDataCacheKeyOf(req.ctx.spaceDeployment);
1551
+ const offlineData = (cacheKey ? offlineDataCache?.get(cacheKey) : void 0) ?? await config.adapters.getOfflineData(spaceId, environment, revision);
1552
+ const icons = offlineData ? spaceIconsOf(offlineData, iconGlyphsAt(sdkDir)) : void 0;
1553
+ const face = icons?.faces.find((candidate) => candidate.key === key);
1554
+ if (!icons || !face) {
1555
+ notFound(res, `Space ${String(spaceId)} (${environment}) names no ${key} icon`);
1556
+ return;
1557
+ }
1558
+ const font = await cutFace(sdkDir, face, `${icons.hash}-${key}`);
1559
+ res.setHeader("Content-Type", "font/woff2");
1560
+ res.setHeader("Cache-Control", icons.hash === hash ? "public, max-age=31536000, immutable" : "no-store");
1561
+ res.send(font);
1562
+ };
1563
+ // src/core/services/iconFaces.ts
1564
+ var iconFacesStage = async (ctx) => {
1565
+ const { config, req } = ctx;
1566
+ if (req.method !== "GET" || !req.path.startsWith("/_plitzi/icons/")) return false;
1567
+ ctx.operation = "icons";
1568
+ await handleIconFace(req, ctx.res, config, resolveSdkAssetsDir(), ctx.caches.offlineData);
1569
+ return true;
1570
+ };
1504
1571
  // src/core/services/servedSpace.ts
1505
1572
  /**
1506
1573
  * The space a page at this address renders (no deployment: the server's one space), for a file the server answers from
@@ -1514,32 +1581,61 @@ var servedSpace = async (ctx, file) => {
1514
1581
  serverLog.warn("SSR", `${file} answered without the space: space ${String(spaceId)} could not be read`, error);
1515
1582
  });
1516
1583
  };
1584
+ // src/core/services/llmsTxt.ts
1585
+ var LLMS_TXT_PATH = "/llms.txt";
1586
+ /** A line of Markdown that cannot break the list it is in: no line break, no bracket that closes a link early. */
1587
+ var inline = (value) => value.replace(/\s+/g, " ").replace(/[[\]]/g, "").trim();
1588
+ /**
1589
+ * The index an assistant reads (llmstxt.org): the site's name, the home page's description as its summary, and a link
1590
+ * to each page the sitemap lists with its SEO title and description — the same words a search result shows.
1591
+ */
1592
+ var llmsTxtOf = (schema, origin) => {
1593
+ const pages = sitemapPages(schema).map((page) => ({
1594
+ ...page,
1595
+ seo: resolvePageSeo(schema, page.pageId)
1596
+ }));
1597
+ const home = pages.find((page) => page.path === "/");
1598
+ const name = inline(schema.settings.siteName ?? home?.seo.title ?? new URL(origin).hostname);
1599
+ const summary = home?.seo.description ? inline(home.seo.description) : "";
1600
+ const links = pages.map(({ path, seo }) => {
1601
+ return `- [${inline(seo.title ?? path)}](${origin}${path})${seo.description ? `: ${inline(seo.description)}` : ""}`;
1602
+ });
1603
+ return [
1604
+ `# ${name}`,
1605
+ ...summary ? [`> ${summary}`] : [],
1606
+ "## Pages",
1607
+ links.join("\n")
1608
+ ].join("\n\n");
1609
+ };
1610
+ /**
1611
+ * `/llms.txt`: the space's own (`settings.llmsTxt`), or the one its pages make (`llmsTxtOf`). A space that keeps
1612
+ * assistants out (`blockAiCrawlers: ['assistants']`) answers 404 — an index for them invites what it refuses. Never the
1613
+ * space's page for that address, which an assistant would read as the index.
1614
+ */
1615
+ var llmsTxtStage = async (ctx) => {
1616
+ const { req } = ctx;
1617
+ if (req.method !== "GET" || req.path !== "/llms.txt") return false;
1618
+ ctx.operation = "llms";
1619
+ const schema = (await servedSpace(ctx, LLMS_TXT_PATH))?.schema;
1620
+ const origin = requestOrigin(req);
1621
+ ctx.res.setHeader("Content-Type", "text/plain; charset=utf-8");
1622
+ if (!schema || !origin || schema.settings.blockAiCrawlers?.includes("assistants")) {
1623
+ ctx.res.setStatus(404);
1624
+ ctx.res.send("This site publishes no llms.txt.\n");
1625
+ return true;
1626
+ }
1627
+ const own = schema.settings.llmsTxt?.trim();
1628
+ ctx.res.setStatus(200);
1629
+ ctx.res.send(`${own || llmsTxtOf(schema, origin)}\n`);
1630
+ return true;
1631
+ };
1517
1632
  // src/core/services/robotsTxt.ts
1518
1633
  /** What a space that says nothing answers: everything may be crawled. */
1519
1634
  var DEFAULT_ROBOTS_TXT = "User-agent: *\nAllow: /\n";
1520
- /**
1521
- * The crawlers that gather pages to train AI models, by the user agent each reads `/robots.txt` as — what a space that
1522
- * says `blockAiCrawlers` keeps out. A search engine's own crawler is none of them: Googlebot reads on, Google-Extended
1523
- * (the one that trains) does not.
1524
- */
1525
- var AI_CRAWLERS = [
1526
- "GPTBot",
1527
- "ChatGPT-User",
1528
- "OAI-SearchBot",
1529
- "ClaudeBot",
1530
- "anthropic-ai",
1531
- "Google-Extended",
1532
- "Applebot-Extended",
1533
- "CCBot",
1534
- "PerplexityBot",
1535
- "Bytespider",
1536
- "Amazonbot",
1537
- "meta-externalagent"
1538
- ];
1539
1635
  var SITEMAP_LINE = /^\s*sitemap\s*:/im;
1540
1636
  /**
1541
- * `/robots.txt`: the space's own (`settings.robotsTxt`) or one that lets crawlers read everything, then — when the space
1542
- * keeps them out (`settings.blockAiCrawlers`) — a `Disallow: /` for each AI crawler, and the address of its sitemap
1637
+ * `/robots.txt`: the space's own (`settings.robotsTxt`) or one that lets crawlers read everything, then a `Disallow: /`
1638
+ * for each AI crawler of the kinds the space keeps out (`settings.blockAiCrawlers`), and the address of its sitemap
1543
1639
  * unless its own text names one. Never the space's page for an address it has none for: a crawler reads a 404 page as
1544
1640
  * "no rules", and an HTML page as rules it cannot parse.
1545
1641
  */
@@ -1552,7 +1648,7 @@ var robotsTxtStage = async (ctx) => {
1552
1648
  const origin = requestOrigin(req);
1553
1649
  const sections = [
1554
1650
  own,
1555
- ...settings?.blockAiCrawlers ? AI_CRAWLERS.map((agent) => `User-agent: ${agent}\nDisallow: /`) : [],
1651
+ ...blockedAiCrawlers(settings?.blockAiCrawlers).map((agent) => `User-agent: ${agent}\nDisallow: /`),
1556
1652
  ...origin && !SITEMAP_LINE.test(own) ? [`Sitemap: ${origin}/sitemap.xml`] : []
1557
1653
  ];
1558
1654
  ctx.res.setStatus(200);
@@ -1739,6 +1835,29 @@ var rscStage = async (ctx) => {
1739
1835
  await handleRsc(req, ctx.res, config, ctx.pluginManager, ctx.caches.rsc, ctx.signal);
1740
1836
  return true;
1741
1837
  };
1838
+ // src/core/services/securityTxt.ts
1839
+ var SECURITY_TXT_PATH = "/.well-known/security.txt";
1840
+ /**
1841
+ * `/.well-known/security.txt` (RFC 9116): the space's own words (`settings.securityTxt`), as plain text — where somebody
1842
+ * who found a flaw writes, and until when that holds. A space that says nothing answers 404: a contact the site never
1843
+ * gave would send a researcher's report nowhere. Never the space's page for that address, which a reader takes for the
1844
+ * file.
1845
+ */
1846
+ var securityTxtStage = async (ctx) => {
1847
+ const { req } = ctx;
1848
+ if (req.method !== "GET" || req.path !== "/.well-known/security.txt") return false;
1849
+ ctx.operation = "security";
1850
+ const own = (await servedSpace(ctx, SECURITY_TXT_PATH))?.schema.settings.securityTxt?.trim();
1851
+ ctx.res.setHeader("Content-Type", "text/plain; charset=utf-8");
1852
+ if (!own) {
1853
+ ctx.res.setStatus(404);
1854
+ ctx.res.send("This site publishes no security.txt.\n");
1855
+ return true;
1856
+ }
1857
+ ctx.res.setStatus(200);
1858
+ ctx.res.send(`${own}\n`);
1859
+ return true;
1860
+ };
1742
1861
  // src/core/services/sitemapXml.ts
1743
1862
  var XML_ESCAPES = {
1744
1863
  "&": "&",
@@ -2616,7 +2735,7 @@ var cspReportStage = async (ctx) => {
2616
2735
  * Kept as text rather than a file beside the module: the server's build moves its modules into chunks, and a deployment
2617
2736
  * bundles them again (a project's server, `bundleProject`) — a string goes wherever its module goes.
2618
2737
  */
2619
- var DEFAULT_FAVICON_SVG = `<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="147.5px" height="149px" viewBox="0 0 147.5 149" enable-background="new 0 0 147.5 149" xml:space="preserve"> <path fill="#4422EE" d="M94.008,120.333l-14.699,14.699c-17.816,17.816-46.86,17.816-64.676,0s-17.816-46.86,0-64.676l14.699-14.699 l5.88,5.88L20.513,76.236c-14.581,14.581-14.581,38.335,0,52.917s38.335,14.581,52.917,0l14.699-14.699L94.008,120.333z"/> <circle fill="#4422EE" cx="32.058" cy="58.79" r="4.178"/> <ellipse fill="#4422EE" cx="90.876" cy="117.587" rx="4.165" ry="4.15"/> <path fill="#4422EE" d="M73.469,44.587c1.562,1.562,1.546,4.111-0.037,5.694L54.09,69.623c-1.583,1.583-4.132,1.599-5.694,0.037l0,0 c-1.562-1.562-1.546-4.111,0.037-5.694l19.342-19.342C69.357,43.041,71.907,43.025,73.469,44.587L73.469,44.587z"/> <path fill="#4422EE" d="M112.978,5.077c1.667,1.667,1.655,4.001,0.208,5.449L81.746,41.967c-1.447,1.447-3.781,1.459-5.449-0.208 l0,0c-1.667-1.667-1.655-4.001-0.208-5.449L107.53,4.869C108.977,3.422,111.311,3.41,112.978,5.077L112.978,5.077z"/> <path fill="#4422EE" d="M82.843,8.292c1.647,1.647,1.599,4.765-0.354,6.718L46.427,51.072c-1.953,1.953-5.071,2-6.718,0.354l0,0 c-1.647-1.647-1.599-4.765,0.354-6.718L76.125,8.646C78.078,6.693,81.196,6.645,82.843,8.292L82.843,8.292z"/> <path fill="#4422EE" d="M99.814,49.304c1.367,1.367,1.367,3.583,0,4.95L87.086,66.982c-1.367,1.367-3.583,1.367-4.95,0l0,0 c-1.367-1.367-1.367-3.583,0-4.95l12.728-12.728C96.231,47.937,98.447,47.937,99.814,49.304L99.814,49.304z"/> <path fill="#4422EE" d="M136.605,12.557c1.355,1.355,1.355,3.551,0,4.906l-28.328,28.328c-1.355,1.355-3.551,1.355-4.906,0 l-0.044-0.044c-1.355-1.355-1.355-3.551,0-4.906l28.328-28.328c1.355-1.355,3.551-1.355,4.906,0L136.605,12.557z"/> <path fill="#4422EE" d="M105.824,77.942c1.562,1.562,1.546,4.111-0.037,5.694l-19.342,19.342c-1.583,1.583-4.132,1.599-5.694,0.037 l0,0c-1.562-1.562-1.546-4.111,0.037-5.694l19.342-19.342C101.713,76.397,104.262,76.38,105.824,77.942L105.824,77.942z"/> <path fill="#4422EE" d="M145.334,38.432c1.667,1.667,1.655,4.001,0.208,5.449l-31.441,31.441c-1.447,1.447-3.781,1.459-5.449-0.208 l0,0c-1.667-1.667-1.655-4.001-0.208-5.449l31.441-31.441C141.332,36.777,143.666,36.765,145.334,38.432L145.334,38.432z"/> <path fill="#4422EE" d="M141.533,66.982c1.647,1.647,1.599,4.765-0.354,6.718l-36.062,36.062c-1.953,1.953-5.071,2-6.718,0.354l0,0 c-1.647-1.647-1.599-4.765,0.354-6.718l36.062-36.062C136.768,65.383,139.886,65.335,141.533,66.982L141.533,66.982z"/> <g> <path fill="#4422EE" d="M80.474,72.436c-1.181,2.571-4.779,10.395-4.779,30.029c0,16.274-13.242,29.516-29.516,29.516 s-29.516-13.242-29.516-29.516s13.242-29.516,29.516-29.516c19.642,0,27.477-3.585,30.053-4.76 c0.985-0.453,2.646-1.216,4.057,0.193C81.692,69.788,80.93,71.446,80.474,72.436z M64.907,79.179 c-1.921,0.202-4.232,1.481-7.065,3.909c-5.126,4.393-11.172,11.979-15.066,17.437c-2.843-0.443-5.84,0.773-7.615,2.991 c-3.257,4.071-0.53,7.704-3.603,10.944c-0.535,0.564-0.344,1.491,0.371,1.797c5.026,2.152,11.451,0.811,14.464-2.367 c1.842-1.942,2.844-4.809,2.341-7.509c5.386-4.133,12.828-10.504,17.042-15.789c2.334-2.927,3.518-5.281,3.62-7.198 C69.535,80.812,67.531,78.903,64.907,79.179L64.907,79.179z"/> <path fill="#4422EE" d="M44.727,112.307c-2.039,2.15-6.55,3.402-10.564,2.331c2.244-3.58,0.315-6.79,2.699-9.77 c1.956-2.445,5.889-3.129,8.175-0.843C47.708,106.696,46.464,110.476,44.727,112.307z"/> <path fill="#4422EE" d="M44.956,101.215c0.548-0.758,1.407-1.927,2.481-3.328l3.668,3.668c-1.351,1.111-2.479,2.002-3.21,2.57 C47.236,102.943,46.216,101.882,44.956,101.215L44.956,101.215z"/> <path fill="#4422EE" d="M67.12,83.23c-0.251,4.695-10.719,13.862-14.292,16.887l-4.008-4.008 c2.94-3.723,11.57-14.256,16.276-14.751C66.352,81.226,67.185,82.018,67.12,83.23z"/> </g> </svg>`;
2738
+ var DEFAULT_FAVICON_SVG = PLITZI_MARK_SVG;
2620
2739
  // src/core/http/stages/defaultFavicon.ts
2621
2740
  /** Plitzi's icon, at the address a page that names none points its tab at — see `DEFAULT_FAVICON_SVG`. */
2622
2741
  var defaultFaviconStage = (ctx) => {
@@ -2702,6 +2821,7 @@ var buildPagePipeline = (services, extensions = {}, engine) => {
2702
2821
  publicDirStage,
2703
2822
  defaultFaviconStage,
2704
2823
  cspReportStage,
2824
+ ...services.ssr ? [securityTxtStage] : [],
2705
2825
  wellKnownStage,
2706
2826
  pluginAssetsStage,
2707
2827
  fontAssetsStage,
@@ -2721,8 +2841,10 @@ var buildPagePipeline = (services, extensions = {}, engine) => {
2721
2841
  if (services.ssr) {
2722
2842
  stages.push(spaceDocumentStage);
2723
2843
  stages.push(styleSheetStage);
2844
+ stages.push(iconFacesStage);
2724
2845
  stages.push(robotsTxtStage);
2725
2846
  stages.push(sitemapXmlStage);
2847
+ stages.push(llmsTxtStage);
2726
2848
  }
2727
2849
  stages.push(services.ssr ? ssrStage : notFoundStage);
2728
2850
  return stages;
@@ -2825,7 +2947,7 @@ var createPageServer = (config, services, extensions, engine) => {
2825
2947
  fleetStores: {
2826
2948
  ...engine?.fleetStores,
2827
2949
  "ssr.drafts": hostable(createMemoryDraftStore, DRAFT_STORE_METHODS),
2828
- "auth.rateLimit": hostable(() => ({ check: createMemoryRateLimit() }), RATE_LIMIT_METHODS)
2950
+ "auth.rateLimit": hostable(() => ({ check: createRateLimit() }), RATE_LIMIT_METHODS)
2829
2951
  },
2830
2952
  onStopping: () => {
2831
2953
  engine?.stopping?.();
@@ -2862,7 +2984,7 @@ var createPageServer = (config, services, extensions, engine) => {
2862
2984
  // src/core/createServer.ts
2863
2985
  /**
2864
2986
  * What a page server is not configured with: the actions engine's own configuration, which `createPlatform` builds the
2865
- * engine from and hands the server (`engine`), or a worker runs elsewhere (RFC 0032, D12).
2987
+ * engine from and hands the server (`engine`), or a worker runs elsewhere (docs/en/server-packages.md, D12).
2866
2988
  */
2867
2989
  var ENGINE_KEYS = [
2868
2990
  "action",
@@ -2903,7 +3025,8 @@ var withRsc = (config, engine) => {
2903
3025
  elementTimeoutMs: config.rsc?.elementTimeoutMs,
2904
3026
  sayFailures: config.devMode === true,
2905
3027
  outbound: { privateOrigins: privateOriginsOf(config.outbound?.privateOrigins) },
2906
- visitorCredentials: config.rsc?.visitorCredentials
3028
+ visitorCredentials: config.rsc?.visitorCredentials,
3029
+ ...config.paintedDefaults ? { paintedDefaults: config.paintedDefaults } : {}
2907
3030
  })
2908
3031
  }
2909
3032
  };
@@ -1,4 +1,4 @@
1
- import { t as createServer } from "./createServer-Bd_b7T3k.js";
1
+ import { t as createServer } from "./createServer-BQ0KE0Qu.js";
2
2
  import { dataDirLookup } from "@plitzi/sdk-kernel/data";
3
3
  import { createPageEngine } from "@plitzi/sdk-actions/worker";
4
4
  // src/core/platform.ts
@@ -13,7 +13,7 @@ var engineLookups = (lookups, dataDir, auth) => ({
13
13
  ...!lookups.getVisitor && auth ? { getVisitor: (_space, _environment, who) => auth.publicAccount(who) } : {}
14
14
  });
15
15
  /**
16
- * Pages and actions in one process (RFC 0032, D11): the actions engine built from `action`, `functions`, `connectors`
16
+ * Pages and actions in one process (docs/en/server-packages.md, D11): the actions engine built from `action`, `functions`, `connectors`
17
17
  * and `realtime`, and handed to the page server `createServer` makes of the rest. What `yarn start`, a project's own
18
18
  * server and most self-hosted deployments run; a deployment whose actions run on a worker of their own uses
19
19
  * `createServer` for its pages.