@plitzi/sdk-server 0.39.3 → 0.39.6
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 +33 -0
- package/README.md +50 -8
- package/dist/adapters/cloudAdapters.d.ts +7 -0
- package/dist/adapters/space/index.d.ts +2 -0
- package/dist/adapters/space/resolvers.d.ts +14 -3
- package/dist/adapters/space/snapshotPreview.d.ts +45 -0
- package/dist/adapters/space/types.d.ts +4 -1
- package/dist/auth.d.ts +3 -2
- package/dist/auth.js +26 -107
- package/dist/cache.js +1 -1
- package/dist/chunks/{buildBody-W9D8ySNY.js → buildBody-Bm398uxH.js} +893 -114
- package/dist/chunks/{core-TlrWmT4B.js → core-CoKORAOg.js} +234 -26
- package/dist/chunks/{createServer-Bd_b7T3k.js → createServer-BSmQqzwb.js} +186 -639
- package/dist/chunks/{platform-DhdFYWm5.js → platform-BTssQQXp.js} +2 -2
- package/dist/chunks/sdkAssets-CXGoc_WE.js +60 -0
- package/dist/chunks/throttle-CRiZB6_A.js +330 -0
- package/dist/chunks/{token-B2uY9JzU.js → token-XEz1n4jp.js} +1 -1
- package/dist/chunks/views/template.ejs +12 -0
- package/dist/core/auth/api/context.d.ts +4 -4
- package/dist/core/auth/api/values.d.ts +6 -0
- package/dist/core/auth/createAuth.d.ts +1 -1
- package/dist/core/auth/throttle.d.ts +54 -4
- package/dist/core/createServer.d.ts +1 -1
- package/dist/core/platform.d.ts +1 -1
- package/dist/core/services/iconFaces.d.ts +3 -0
- package/dist/core/services/llmsTxt.d.ts +15 -0
- package/dist/core/services/robotsTxt.d.ts +5 -9
- package/dist/core/services/securityTxt.d.ts +10 -0
- package/dist/deploy/aws/s3.d.ts +51 -0
- package/dist/deploy/aws/sigv4.d.ts +33 -0
- package/dist/deploy/contentType.d.ts +2 -0
- package/dist/deploy/fingerprint.d.ts +18 -0
- package/dist/deploy/folder.d.ts +6 -0
- package/dist/deploy/ftp.d.ts +27 -0
- package/dist/deploy/sdkFiles.d.ts +11 -0
- package/dist/deploy/spaShell.d.ts +35 -0
- package/dist/deploy/staticSite.d.ts +44 -0
- package/dist/deploy/types.d.ts +58 -0
- package/dist/deploy/zip.d.ts +8 -0
- package/dist/deploy.d.ts +24 -0
- package/dist/deploy.js +938 -0
- package/dist/handlers.js +1 -1
- package/dist/helpers/documentParts.d.ts +10 -0
- package/dist/helpers/ownVersion.d.ts +1 -0
- package/dist/helpers/paintedCookie.d.ts +15 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/modules/icons/glyphs.d.ts +21 -0
- package/dist/modules/icons/handler.d.ts +11 -0
- package/dist/modules/icons/spaceIcons.d.ts +26 -0
- package/dist/modules/rsc/connectorRscData.d.ts +4 -2
- package/dist/modules/rsc/resolveRscData.d.ts +4 -1
- package/dist/modules/ssr/csrfHint.d.ts +12 -0
- package/dist/modules/ssr/defaultFavicon.d.ts +1 -1
- package/dist/modules/ssr/spaceDocument.d.ts +8 -1
- package/dist/oauth.js +1 -1
- package/dist/platform.d.ts +1 -1
- package/dist/platform.js +1 -1
- package/dist/project.js +3 -3
- package/dist/spaces.d.ts +2 -2
- package/dist/spaces.js +1 -1
- package/dist/ssr.d.ts +1 -1
- package/dist/ssr.js +1 -1
- package/dist/types/config.d.ts +24 -0
- package/dist/types/index.d.ts +1 -1
- package/package.json +17 -13
- package/skills/plitzi-authoring/recipes/accordion.ts +3 -1
- package/skills/plitzi-authoring/recipes/carousel.ts +68 -63
- package/skills/plitzi-authoring/recipes/detail-page.ts +43 -33
- package/skills/plitzi-authoring/recipes/embed-and-svg.ts +16 -11
- package/skills/plitzi-authoring/recipes/every-few-seconds.ts +52 -42
- package/skills/plitzi-authoring/recipes/feature-flag.ts +7 -2
- package/skills/plitzi-authoring/recipes/filter-a-list.ts +39 -31
- package/skills/plitzi-authoring/recipes/forms-and-modals.ts +34 -28
- package/skills/plitzi-authoring/recipes/from-tailwind.ts +11 -6
- package/skills/plitzi-authoring/recipes/link-to-a-section.ts +11 -6
- package/skills/plitzi-authoring/recipes/link-with-data.ts +21 -16
- package/skills/plitzi-authoring/recipes/marquee.ts +17 -12
- package/skills/plitzi-authoring/recipes/plugin.ts +16 -10
- package/skills/plitzi-authoring/recipes/scroll-a-row.ts +30 -25
- package/skills/plitzi-authoring/recipes/server-data.ts +15 -10
- package/skills/plitzi-authoring/recipes/show-data.ts +32 -24
- package/skills/plitzi-authoring/recipes/style-a-page.ts +9 -4
- package/skills/plitzi-authoring/recipes/typed-data.ts +26 -21
- package/skills/plitzi-authoring/recipes/usable-without-sight.ts +16 -11
- package/skills/plitzi-authoring/reference/authoring-errors.md +11 -4
- package/skills/plitzi-authoring/reference/efficiency.md +3 -1
- package/skills/plitzi-authoring/reference/layouts.md +2 -1
- package/dist/chunks/throttle-BH7JLIOF.js +0 -108
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
import {
|
|
1
|
+
import { C as DRAFT_STORE_METHODS, D as invalidatePluginComponentCache, E as takeDraftOverride, O as matchRscPage, S as PluginManager, T as draftSessionCookie, _ as resolveServices, a as applySSRResult, b as spaceIconsOf, c as withNotFound, f as answerCurrentSpacePreflight, g as resolveRscEndpoint, h as meterPage, i as Component, 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 createMemoryDraftStore, x as iconGlyphsAt, y as ICONS_PATH } from "./buildBody-Bm398uxH.js";
|
|
2
|
+
import { $ as toSharedPage, B as destroyServerCaches, C as googleFontsStage, D as sendScriptPolicy, F as cacheLimitsOf, G as styleSheetOf, I as cacheFilterOf, J as renderLimitFor, M as reportReactBuild, N as normalizePluginSource, P as normalizePlugins, Q as pageHtml, R as shareCache, X as fromSharedPage, Y as renderLimitOf, Z as keepPage, at as ignoredQueryParamsOf, b as escapeHtml, et as buildCacheManager, ft as DEFAULT_TTL_MS, it as offlineDataCacheKeyOf, j as createOfflineDataLoader, nt as buildRscCacheKey, ot as renderedQuery, pt as requestPaintedStateWithDefaults, rt as keepsVersion, st as SCHEME_HINT_HEADER, tt as buildHtmlCacheKey, ut as DEFAULT_CACHE_BYTES, y as RequestMetrics, z as createServerCaches } from "./core-CoKORAOg.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
|
|
5
|
+
import { n as createRateLimit, t as RATE_LIMIT_METHODS } from "./throttle-CRiZB6_A.js";
|
|
6
|
+
import { n as pageAssets, r as resolveSdkAssetsDir } from "./sdkAssets-CXGoc_WE.js";
|
|
6
7
|
import { dataDirLookup } from "@plitzi/sdk-kernel/data";
|
|
7
8
|
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";
|
|
9
|
+
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
10
|
import http from "node:http";
|
|
10
11
|
import https from "node:https";
|
|
11
|
-
import
|
|
12
|
+
import { readFile } from "node:fs/promises";
|
|
12
13
|
import path from "node:path";
|
|
13
14
|
import { PROJECT_DATA_PREFIX } from "@plitzi/sdk-shared/project/paths";
|
|
14
15
|
import { broadcast, configStaticStage, createHttpServer, createMiddlewaresStage, crossSiteWritesStage, fleetRole, fleetStore, healthStage, hostable, isNavigation, makeHandler, onAbort, onBroadcast, openEventStream, publicDirStage, readRawBody, refusedCrossSite, requestAuthority, requestOrigin, resolveCompression, resolveWorkers, safeRedirectTarget, serveStatic, wellKnownStage } from "@plitzi/sdk-kernel/http";
|
|
@@ -17,16 +18,13 @@ import { evaluateRuleGroup } from "@plitzi/sdk-shared/conditions";
|
|
|
17
18
|
import { getSourceName } from "@plitzi/sdk-shared/dataSource/helpers";
|
|
18
19
|
import { resolveVariables } from "@plitzi/sdk-shared/dataSource/variables";
|
|
19
20
|
import { flagUserFromSSR, flagValues, forcedFlagsFromCookies, requestFlagOverrides, resolveFlags } from "@plitzi/sdk-shared/flags";
|
|
20
|
-
import { sitemapPaths } from "@plitzi/sdk-shared/navigation";
|
|
21
|
+
import { sitemapPages, sitemapPaths } from "@plitzi/sdk-shared/navigation";
|
|
21
22
|
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
22
23
|
import { knowHostDeployment } from "@plitzi/sdk-kernel/deployment";
|
|
23
24
|
import { PREVIEW_TOKEN_PARAM, appendCookies, clearSessionCookies, readCookies, readDraftToken, readRenewalGuard, readSessionHint, readSessionToken, resolveDebugAuthorization, writeRenewalGuard, writeSessionCookies } from "@plitzi/sdk-kernel/identity";
|
|
24
25
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
25
|
-
import { STYLE_SHEET_PATH
|
|
26
|
-
import
|
|
27
|
-
import { copyFileAtomic, writeFileAtomic } from "@plitzi/sdk-kernel/files";
|
|
28
|
-
import { esbuildBuild } from "@plitzi/sdk-kernel/build";
|
|
29
|
-
import { pluginAssetLoaders, pluginImportQueries } from "@plitzi/sdk-shared/plugins/bundle";
|
|
26
|
+
import { STYLE_SHEET_PATH } from "@plitzi/sdk-shared/style";
|
|
27
|
+
import { watch } from "node:fs";
|
|
30
28
|
import { statsStage } from "@plitzi/sdk-kernel/stats";
|
|
31
29
|
import { renderToPipeableStream } from "react-dom/server";
|
|
32
30
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -328,7 +326,7 @@ var withBudget = async (run, timeoutMs, label, asked) => {
|
|
|
328
326
|
* and the route params are what the browser will see. Each `runtime: 'server'` element resolves independently:
|
|
329
327
|
* a provider that fails or hangs costs its own slice and nothing else.
|
|
330
328
|
*/
|
|
331
|
-
var resolveRscData = async ({ schema, req, spaceId, environment, user, ids, resolveElement, flagOverrides, timeoutMs = DEFAULT_ELEMENT_TIMEOUT_MS, signal, sayFailures = false }) => {
|
|
329
|
+
var resolveRscData = async ({ schema, req, spaceId, environment, user, ids, resolveElement, flagOverrides, timeoutMs = DEFAULT_ELEMENT_TIMEOUT_MS, signal, sayFailures = false, paintedDefaults }) => {
|
|
332
330
|
if (schema.rsc?.enabled === false) return {};
|
|
333
331
|
const match = matchRscPage(schema, req.path, user);
|
|
334
332
|
if (!match) return { serverData: {} };
|
|
@@ -345,7 +343,11 @@ var resolveRscData = async ({ schema, req, spaceId, environment, user, ids, reso
|
|
|
345
343
|
const asked = ids ? new Set(ids) : void 0;
|
|
346
344
|
const targets = asked ? all.filter((element) => asked.has(element.id)) : all;
|
|
347
345
|
if (targets.length === 0) return { serverData: {} };
|
|
348
|
-
const painted =
|
|
346
|
+
const painted = await requestPaintedStateWithDefaults(req, schema.settings, {
|
|
347
|
+
spaceId,
|
|
348
|
+
environment,
|
|
349
|
+
account: user?.id
|
|
350
|
+
}, paintedDefaults);
|
|
349
351
|
const templateData = {
|
|
350
352
|
variables: resolveVariables(schema.variables, {
|
|
351
353
|
routeParams,
|
|
@@ -450,7 +452,7 @@ var resolveRscData = async ({ schema, req, spaceId, environment, user, ids, reso
|
|
|
450
452
|
*
|
|
451
453
|
* A deployment that resolves server elements some other way still supplies its own `getRscData`, and that one wins.
|
|
452
454
|
*/
|
|
453
|
-
var connectorRscData = ({ engine, publicDir, data, elementTimeoutMs, sayFailures = false, outbound, visitorCredentials }) => {
|
|
455
|
+
var connectorRscData = ({ engine, publicDir, data, elementTimeoutMs, sayFailures = false, outbound, visitorCredentials, paintedDefaults }) => {
|
|
454
456
|
const resolvePublicFile = publicDir ? publicFileResolver(publicDir) : void 0;
|
|
455
457
|
const resolveDataFile = data ? dataLookupResolver(data) : void 0;
|
|
456
458
|
const readExternal = externalQueryReader({
|
|
@@ -501,6 +503,7 @@ var connectorRscData = ({ engine, publicDir, data, elementTimeoutMs, sayFailures
|
|
|
501
503
|
...flagOverrides ? { flagOverrides } : {},
|
|
502
504
|
...signal ? { signal } : {},
|
|
503
505
|
...elementTimeoutMs === void 0 ? {} : { timeoutMs: elementTimeoutMs },
|
|
506
|
+
...paintedDefaults ? { paintedDefaults } : {},
|
|
504
507
|
sayFailures
|
|
505
508
|
});
|
|
506
509
|
};
|
|
@@ -756,601 +759,11 @@ var seconds = (ms) => `${Math.round(ms / 1e3)} s`;
|
|
|
756
759
|
*/
|
|
757
760
|
var reportCacheSharing = (config, { ttlMs, bus, store }) => {
|
|
758
761
|
if (config.devMode && !bus && !store) return;
|
|
759
|
-
const kept = `Pages are kept ${seconds(ttlMs)} (served ${seconds(config.cache?.staleMs ?? DEFAULT_TTL_MS
|
|
762
|
+
const kept = `Pages are kept ${seconds(ttlMs)} (served ${seconds(config.cache?.staleMs ?? DEFAULT_TTL_MS.stale)} more while rendered again), up to ${megabytes(config.cache?.maxBytes ?? DEFAULT_CACHE_BYTES.html)} a process`;
|
|
760
763
|
const where = store ? ", and shared by every replica (cache.store)" : ", each process its own";
|
|
761
764
|
const reach = bus ? "an invalidation reaches every replica (cache.bus)." : "an invalidation reaches this host's processes only — with several replicas, give the server cache.bus (createRedisPubSub) or each serves what a write made untrue until its copy expires.";
|
|
762
765
|
serverLog.info("SSR cache", `${kept}${where}; ${reach}`);
|
|
763
766
|
};
|
|
764
|
-
// src/plugins/compile.ts
|
|
765
|
-
var EXTERNAL = [
|
|
766
|
-
"react",
|
|
767
|
-
"react-dom",
|
|
768
|
-
"react-dom/client",
|
|
769
|
-
"react/jsx-runtime",
|
|
770
|
-
"@plitzi/plitzi-sdk",
|
|
771
|
-
"@plitzi/sdk-shared"
|
|
772
|
-
];
|
|
773
|
-
/**
|
|
774
|
-
* Everything that went into the bundle, so a server can tell when any of it has moved on: a dev server as it is
|
|
775
|
-
* edited, and any server — a deployment — when it finds a bundle built from something else (its content digest).
|
|
776
|
-
*
|
|
777
|
-
* The entry file is one file and a plugin is a directory: a component edited beside its `index.ts` leaves the entry's
|
|
778
|
-
* timestamp exactly where it was, and a watcher looking only at that never rebuilds. esbuild already knows the answer
|
|
779
|
-
* — this is its own list of inputs — so nothing has to be guessed from the file system.
|
|
780
|
-
*
|
|
781
|
-
* Dependencies are left out. They change when something is installed, which is not an edit anybody is waiting to see,
|
|
782
|
-
* and stat'ing a few thousand files on every cache miss to find that out is a real cost for no answer.
|
|
783
|
-
*/
|
|
784
|
-
var sourceInputs = (metafile) => metafile ? Object.keys(metafile.inputs).filter((input) => !input.includes("node_modules")).map((input) => path.resolve(input.replace(/^plitzi-(raw|inline):/, ""))) : [];
|
|
785
|
-
var compilePlugin = async (jsPath, outDir, devMode = false) => {
|
|
786
|
-
const result = await esbuildBuild({
|
|
787
|
-
entryPoints: [jsPath],
|
|
788
|
-
bundle: true,
|
|
789
|
-
format: "esm",
|
|
790
|
-
external: EXTERNAL,
|
|
791
|
-
loader: pluginAssetLoaders(),
|
|
792
|
-
plugins: [pluginImportQueries()],
|
|
793
|
-
outdir: outDir,
|
|
794
|
-
entryNames: "index",
|
|
795
|
-
jsx: "automatic",
|
|
796
|
-
minify: !devMode,
|
|
797
|
-
splitting: false,
|
|
798
|
-
logLevel: "warning",
|
|
799
|
-
metafile: true,
|
|
800
|
-
write: false
|
|
801
|
-
});
|
|
802
|
-
await fs.mkdir(outDir, { recursive: true });
|
|
803
|
-
await Promise.all(result.outputFiles.map((output) => writeFileAtomic(output.path, output.path.endsWith(".css") ? inPluginLayer(output.text) : output.contents)));
|
|
804
|
-
return {
|
|
805
|
-
hasCSS: result.outputFiles.some((output) => path.basename(output.path) === "index.css"),
|
|
806
|
-
inputs: sourceInputs(result.metafile)
|
|
807
|
-
};
|
|
808
|
-
};
|
|
809
|
-
// src/plugins/copy.ts
|
|
810
|
-
var copyPlugin = async (src, destDir, filename) => {
|
|
811
|
-
const dest = path.join(destDir, filename);
|
|
812
|
-
if (src.startsWith("http://") || src.startsWith("https://")) {
|
|
813
|
-
const res = await fetch(src);
|
|
814
|
-
if (!res.ok) throw new Error(`[SSR] Plugin fetch failed ${src}: ${res.status}`);
|
|
815
|
-
await writeFileAtomic(dest, await res.text());
|
|
816
|
-
} else await copyFileAtomic(src, dest);
|
|
817
|
-
};
|
|
818
|
-
/**
|
|
819
|
-
* A plugin's stylesheet, copied or downloaded into the cache in the plugins' cascade layer — below the space's styles,
|
|
820
|
-
* as a compiled one is — whatever the file it came from says.
|
|
821
|
-
*/
|
|
822
|
-
var copyPluginStylesheet = async (src, destDir) => {
|
|
823
|
-
let css;
|
|
824
|
-
if (src.startsWith("http://") || src.startsWith("https://")) {
|
|
825
|
-
const res = await fetch(src);
|
|
826
|
-
if (!res.ok) throw new Error(`[SSR] Plugin stylesheet fetch failed ${src}: ${res.status}`);
|
|
827
|
-
css = await res.text();
|
|
828
|
-
} else css = await fs.readFile(src, "utf8");
|
|
829
|
-
await writeFileAtomic(path.join(destDir, "index.css"), inPluginLayer(css));
|
|
830
|
-
};
|
|
831
|
-
// src/plugins/detect.ts
|
|
832
|
-
var isComponentSource = (source) => "component" in source;
|
|
833
|
-
var detectAction = (js) => {
|
|
834
|
-
if (js.startsWith("http://") || js.startsWith("https://")) return "copy";
|
|
835
|
-
if (js.endsWith(".tsx") || js.endsWith(".ts") || js.endsWith(".jsx")) return "compile";
|
|
836
|
-
return "copy";
|
|
837
|
-
};
|
|
838
|
-
// src/plugins/validate.ts
|
|
839
|
-
var isRemote = (js) => js.startsWith("http://") || js.startsWith("https://");
|
|
840
|
-
/** The file a plugin source needs on disk, or null when nothing local is involved — a remote URL (fetched and
|
|
841
|
-
* cached at request time) or a component handed in directly. */
|
|
842
|
-
var localSourcePath = (source) => {
|
|
843
|
-
if (isComponentSource(source) || isRemote(source.js)) return null;
|
|
844
|
-
return source.js;
|
|
845
|
-
};
|
|
846
|
-
/** Fail at boot on a plugin whose entry file is missing. A plugin entry is a plain string path in the server
|
|
847
|
-
* config, so nothing — not tsc, not eslint — notices when that file is moved or deleted; without this check the
|
|
848
|
-
* server starts happily and only dies on the first render that needs the plugin, with an esbuild resolve error
|
|
849
|
-
* far from its cause. */
|
|
850
|
-
var assertPluginSources = (plugins) => {
|
|
851
|
-
const missing = Object.entries(plugins).map(([name, source]) => ({
|
|
852
|
-
name,
|
|
853
|
-
file: localSourcePath(source)
|
|
854
|
-
})).filter((entry) => entry.file !== null && !fs$1.existsSync(entry.file)).map((entry) => ` ${entry.name}: ${entry.file ?? ""}`);
|
|
855
|
-
if (missing.length > 0) throw new Error(`Plugin entry file not found (declared in the server config):\n${missing.join("\n")}`);
|
|
856
|
-
};
|
|
857
|
-
// src/plugins/manager.ts
|
|
858
|
-
var META_FILE = "meta.json";
|
|
859
|
-
var DEFAULT_TTL_MS = 6048e5;
|
|
860
|
-
var DEFAULT_CACHE_DIR = "tmp/.sdk-plugins";
|
|
861
|
-
/** How long a rebuild of vanished bundles waits, once none is pending, for another of the same render to be noticed. */
|
|
862
|
-
var RESTORE_SETTLE_MS = 100;
|
|
863
|
-
/** One hash over every input's path and content — a file gone counts as changed, like a file edited. */
|
|
864
|
-
var digestOf = async (files) => {
|
|
865
|
-
const hash = createHash("sha256");
|
|
866
|
-
for (const file of [...files].sort()) {
|
|
867
|
-
hash.update(file);
|
|
868
|
-
hash.update("\0");
|
|
869
|
-
hash.update(await fs.readFile(file).catch(() => Buffer.from("\0missing")));
|
|
870
|
-
}
|
|
871
|
-
return hash.digest("hex");
|
|
872
|
-
};
|
|
873
|
-
/**
|
|
874
|
-
* Whether a key is this plugin — every version of it, or with `version` that one release — counting the sources a
|
|
875
|
-
* render named under it (`name@1.0.0+<identity>`, see {@link PluginManager.ensure}).
|
|
876
|
-
*/
|
|
877
|
-
var isKeyOf = (key, name, version) => {
|
|
878
|
-
if (version) return key === `${name}@${version}` || key.startsWith(`${name}@${version}+`);
|
|
879
|
-
return key === name || key.startsWith(`${name}@`);
|
|
880
|
-
};
|
|
881
|
-
/**
|
|
882
|
-
* How often a dev server re-asks whether a cached plugin is still current.
|
|
883
|
-
*
|
|
884
|
-
* The check is a handful of `stat`s and this runs on every render, so it is throttled rather than free — a second is
|
|
885
|
-
* far below what anybody notices between saving a file and reloading a page, and far above per-request.
|
|
886
|
-
*/
|
|
887
|
-
var STALE_CHECK_MS = 1e3;
|
|
888
|
-
var PluginManager = class {
|
|
889
|
-
urlPrefix = "/sdk-plugins";
|
|
890
|
-
outputDir;
|
|
891
|
-
plugins;
|
|
892
|
-
ttlMs;
|
|
893
|
-
mem = /* @__PURE__ */ new Map();
|
|
894
|
-
inflight = /* @__PURE__ */ new Map();
|
|
895
|
-
failed = /* @__PURE__ */ new Set();
|
|
896
|
-
/** Maps base plugin name → most recently registered effective key (may include @version) */
|
|
897
|
-
nameIndex = /* @__PURE__ */ new Map();
|
|
898
|
-
devMode = false;
|
|
899
|
-
/** Who is told what each built plugin was built from — a dev server's watcher (`watchPluginSources`). */
|
|
900
|
-
sourceListeners = /* @__PURE__ */ new Set();
|
|
901
|
-
/** The bundles being built again because they vanished from disk under this server — see `restore`. */
|
|
902
|
-
restoring;
|
|
903
|
-
constructor(plugins, cacheDir, ttlMs, devMode = false) {
|
|
904
|
-
assertPluginSources(plugins);
|
|
905
|
-
this.plugins = plugins;
|
|
906
|
-
this.outputDir = path.resolve(process.cwd(), cacheDir ?? DEFAULT_CACHE_DIR);
|
|
907
|
-
this.ttlMs = ttlMs ?? DEFAULT_TTL_MS;
|
|
908
|
-
this.devMode = devMode;
|
|
909
|
-
for (const key of Object.keys(plugins)) {
|
|
910
|
-
const baseName = key.replace(/@[^@]*$/, "");
|
|
911
|
-
this.nameIndex.set(baseName, key);
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
/**
|
|
915
|
-
* Tells `listener` the files every built plugin was built from — those built so far, at once, and each one built or
|
|
916
|
-
* found built from now on. Only a compiled plugin has any: a copied or downloaded one is not this server's source.
|
|
917
|
-
*/
|
|
918
|
-
onSources(listener) {
|
|
919
|
-
this.sourceListeners.add(listener);
|
|
920
|
-
this.mem.forEach((cached, key) => {
|
|
921
|
-
if (cached.inputs?.length) listener(key, cached.inputs);
|
|
922
|
-
});
|
|
923
|
-
return () => {
|
|
924
|
-
this.sourceListeners.delete(listener);
|
|
925
|
-
};
|
|
926
|
-
}
|
|
927
|
-
/**
|
|
928
|
-
* Builds a plugin again because its source changed — and again after a build that failed, which `prepare` otherwise
|
|
929
|
-
* never retries: the edit that fixes a syntax error is exactly the one a dev server must not ignore.
|
|
930
|
-
*/
|
|
931
|
-
async rebuild(name) {
|
|
932
|
-
const key = this.resolveKey(name) ?? name;
|
|
933
|
-
this.mem.delete(key);
|
|
934
|
-
this.failed.delete(key);
|
|
935
|
-
return this.prepare(key);
|
|
936
|
-
}
|
|
937
|
-
remember(key, cached) {
|
|
938
|
-
this.mem.set(key, cached);
|
|
939
|
-
const { inputs } = cached;
|
|
940
|
-
if (inputs?.length) this.sourceListeners.forEach((listener) => {
|
|
941
|
-
listener(key, inputs);
|
|
942
|
-
});
|
|
943
|
-
}
|
|
944
|
-
hasPlugin(name) {
|
|
945
|
-
return this.resolveKey(name) !== null;
|
|
946
|
-
}
|
|
947
|
-
/**
|
|
948
|
-
* A plugin no longer there — its folder removed under a dev server: never built again, nothing of it remembered. A run's
|
|
949
|
-
* preview logged "build failed … Could not resolve" for a plugin a task had deleted, build after build.
|
|
950
|
-
*/
|
|
951
|
-
unregister(name) {
|
|
952
|
-
const base = name.replace(/@[^@]*$/, "");
|
|
953
|
-
for (const key of Object.keys(this.plugins).filter((each) => each.replace(/@[^@]*$/, "") === base)) Reflect.deleteProperty(this.plugins, key);
|
|
954
|
-
this.forget(base);
|
|
955
|
-
}
|
|
956
|
-
register(name, source) {
|
|
957
|
-
this.plugins[name] = source;
|
|
958
|
-
this.mem.delete(name);
|
|
959
|
-
this.failed.delete(name);
|
|
960
|
-
const baseName = name.replace(/@[^@]*$/, "");
|
|
961
|
-
this.nameIndex.set(baseName, name);
|
|
962
|
-
}
|
|
963
|
-
/**
|
|
964
|
-
* Keeps a source a render names, and returns the key to pass to getEntries(): `name@version+<identity>`, or
|
|
965
|
-
* `name@<identity>` without a version.
|
|
966
|
-
*
|
|
967
|
-
* The identity is what the source IS — where its files are, how they are served, the props it carries — because a
|
|
968
|
-
* name and a version are only what its author said about it. Keyed on those alone, the first source to arrive held
|
|
969
|
-
* the key for as long as the process ran: a plugin published again under the same version kept its old, now missing
|
|
970
|
-
* URLs, and two spaces each with a `board@1.0.0` of their own were served whichever this process had met first.
|
|
971
|
-
* Worked out from the source rather than handed out in order of arrival, so every worker names one source the same
|
|
972
|
-
* way — the key is also the folder a built bundle is written to, and all of them share it.
|
|
973
|
-
*
|
|
974
|
-
* Never taken as what a bare name means: {@link resolveKey} answers for the plugins this server was set up with, not
|
|
975
|
-
* for whichever space rendered last.
|
|
976
|
-
*/
|
|
977
|
-
ensure(name, source) {
|
|
978
|
-
const identity = createHash("sha256").update(JSON.stringify([
|
|
979
|
-
source.js,
|
|
980
|
-
source.css,
|
|
981
|
-
isComponentSource(source) ? void 0 : source.action,
|
|
982
|
-
source.props
|
|
983
|
-
])).digest("hex").slice(0, 12);
|
|
984
|
-
const key = `${name}@${source.version ? `${source.version}+` : ""}${identity}`;
|
|
985
|
-
if (!(key in this.plugins)) this.plugins[key] = source;
|
|
986
|
-
return key;
|
|
987
|
-
}
|
|
988
|
-
/**
|
|
989
|
-
* Resolves a caller-supplied name to the effective key stored in the plugins map.
|
|
990
|
-
* Accepts both the exact key (`plitziBuilder@1.0.0`) and the base name (`plitziBuilder`).
|
|
991
|
-
*/
|
|
992
|
-
resolveKey(name) {
|
|
993
|
-
if (name in this.plugins) return name;
|
|
994
|
-
const indexed = this.nameIndex.get(name);
|
|
995
|
-
if (indexed && indexed in this.plugins) return indexed;
|
|
996
|
-
return null;
|
|
997
|
-
}
|
|
998
|
-
pluginDir(name) {
|
|
999
|
-
return path.join(this.outputDir, name);
|
|
1000
|
-
}
|
|
1001
|
-
isExpired(compiledAt) {
|
|
1002
|
-
return Date.now() - compiledAt > this.ttlMs;
|
|
1003
|
-
}
|
|
1004
|
-
/**
|
|
1005
|
-
* Whether anything the bundle was built from has moved on since. Dev mode only.
|
|
1006
|
-
*
|
|
1007
|
-
* The cache is keyed on time and version, neither of which changes when somebody edits a component: a versioned
|
|
1008
|
-
* plugin never expires and an unversioned one lasts a week, so a change to the source showed up nowhere and the
|
|
1009
|
-
* server kept serving the bundle it built the first time. In production that is exactly right — a deployment's
|
|
1010
|
-
* plugins do not change under it — and while somebody is writing one it is a file that appears to do nothing.
|
|
1011
|
-
*
|
|
1012
|
-
* Every INPUT, not the entry file. A plugin is a directory and the entry is usually a barrel that re-exports it, so
|
|
1013
|
-
* watching only `source.js` answers "nothing has changed" to every edit anybody actually makes — the file whose
|
|
1014
|
-
* timestamp moves is the component next to it. The list comes from the build itself (see `compilePlugin`), so it is
|
|
1015
|
-
* exactly what went in, including a file imported from another plugin's folder. A bundle built before this existed
|
|
1016
|
-
* has no list, and falls back to the entry file rather than claiming to be fresh.
|
|
1017
|
-
*/
|
|
1018
|
-
/**
|
|
1019
|
-
* The same question of the entry this process is holding, asked at most once a second.
|
|
1020
|
-
*
|
|
1021
|
-
* `checkedAt` is stamped on the cached entry rather than kept in a second map, so it cannot outlive what it is about.
|
|
1022
|
-
*/
|
|
1023
|
-
async isStaleInMemory(cached, source) {
|
|
1024
|
-
if (!this.devMode) return false;
|
|
1025
|
-
const now = Date.now();
|
|
1026
|
-
if (cached.checkedAt && now - cached.checkedAt < STALE_CHECK_MS) return false;
|
|
1027
|
-
cached.checkedAt = now;
|
|
1028
|
-
return this.isStale({
|
|
1029
|
-
compiledAt: cached.compiledAt,
|
|
1030
|
-
inputs: cached.inputs
|
|
1031
|
-
}, source);
|
|
1032
|
-
}
|
|
1033
|
-
/**
|
|
1034
|
-
* Whether what a bundle on disk was built from reads differently now — asked once, when a process first finds the
|
|
1035
|
-
* bundle, in production as much as in development.
|
|
1036
|
-
*
|
|
1037
|
-
* A version names a release, and a release is only as good as whoever bumps it: a deployment rebuilt from new source
|
|
1038
|
-
* under the same version found last deployment's bundle in its cache folder and served it, with nothing anywhere
|
|
1039
|
-
* saying so. The content decides instead. A bundle written before digests were recorded has none, and is built again
|
|
1040
|
-
* once. What this server does not build from files — a download, a CDN, a component — is its version's business.
|
|
1041
|
-
*/
|
|
1042
|
-
async contentChanged(meta, source) {
|
|
1043
|
-
const inputs = this.inputsOf(source, meta.inputs ?? []);
|
|
1044
|
-
if (inputs.length === 0) return false;
|
|
1045
|
-
return meta.digest !== await digestOf(inputs);
|
|
1046
|
-
}
|
|
1047
|
-
/** The local files a bundle is built from: what the compiler reported, or the files it was copied from. */
|
|
1048
|
-
inputsOf(source, compiled) {
|
|
1049
|
-
if (isComponentSource(source) || source.action === "download" || source.action === "cdn") return [];
|
|
1050
|
-
if (compiled.length > 0) return compiled;
|
|
1051
|
-
return [source.js, source.css].filter((file) => typeof file === "string" && file !== "" && !/^https?:\/\//.test(file));
|
|
1052
|
-
}
|
|
1053
|
-
async isStale(meta, source) {
|
|
1054
|
-
if (!this.devMode || !source.js || /^https?:\/\//.test(source.js) || isComponentSource(source)) return false;
|
|
1055
|
-
const watched = meta.inputs?.length ? meta.inputs : [source.js];
|
|
1056
|
-
if (meta.inputs?.length) {
|
|
1057
|
-
const entry = await fs.realpath(source.js).catch(() => path.resolve(source.js));
|
|
1058
|
-
if (!meta.inputs.includes(entry)) return true;
|
|
1059
|
-
}
|
|
1060
|
-
return (await Promise.all(watched.map((file) => fs.stat(file).then((stats) => stats.mtimeMs).catch(() => Number.POSITIVE_INFINITY)))).some((modifiedAt) => modifiedAt > meta.compiledAt);
|
|
1061
|
-
}
|
|
1062
|
-
/**
|
|
1063
|
-
* The bundle's URL, stamped with when it was built.
|
|
1064
|
-
*
|
|
1065
|
-
* Plugin assets are served `immutable` for a year, which is right for a file whose URL identifies its contents
|
|
1066
|
-
* and catastrophic for one whose URL never changes: a browser told a resource is immutable does not revalidate
|
|
1067
|
-
* it at all — no conditional request, no ETag — so a rebuilt plugin never reaches anyone who had already loaded
|
|
1068
|
-
* the old one. Not a stale render either: the page's own CSS is fresh while the plugin's is a year old, and the
|
|
1069
|
-
* two disagree in ways nobody can read. The stamp is what makes the promise true.
|
|
1070
|
-
*/
|
|
1071
|
-
assetUrl(name, file, compiledAt) {
|
|
1072
|
-
return `${this.urlPrefix}/${name}/${file}?v=${compiledAt.toString(36)}`;
|
|
1073
|
-
}
|
|
1074
|
-
toEntry(name, hasJS, cssUrl, props = {}, compiledAt = 0) {
|
|
1075
|
-
const keyName = name.split("@")[0];
|
|
1076
|
-
return {
|
|
1077
|
-
name,
|
|
1078
|
-
varName: keyName.split("-").join("_").split(".").join("_"),
|
|
1079
|
-
keyName,
|
|
1080
|
-
js: hasJS ? this.assetUrl(name, "index.js", compiledAt) : void 0,
|
|
1081
|
-
filePath: hasJS ? path.join(this.outputDir, name, "index.js") : void 0,
|
|
1082
|
-
css: cssUrl,
|
|
1083
|
-
props
|
|
1084
|
-
};
|
|
1085
|
-
}
|
|
1086
|
-
/**
|
|
1087
|
-
* A plugin served from where it was published, with nothing on this server's disk.
|
|
1088
|
-
*
|
|
1089
|
-
* No `filePath`, which is the whole point: `loadPluginComponents` only imports entries that have one, so a
|
|
1090
|
-
* bundle this server did not build never enters the render process — and cannot bring a second copy of React
|
|
1091
|
-
* in with it. The template already imports `js` in the browser, so the plugin still renders, just on the
|
|
1092
|
-
* client.
|
|
1093
|
-
*/
|
|
1094
|
-
toRemoteEntry(name, source) {
|
|
1095
|
-
const keyName = name.split("@")[0];
|
|
1096
|
-
return {
|
|
1097
|
-
name,
|
|
1098
|
-
varName: keyName.split("-").join("_").split(".").join("_"),
|
|
1099
|
-
keyName,
|
|
1100
|
-
js: source.js,
|
|
1101
|
-
css: source.css,
|
|
1102
|
-
props: source.props ?? {}
|
|
1103
|
-
};
|
|
1104
|
-
}
|
|
1105
|
-
isWebUrl(s) {
|
|
1106
|
-
return s.startsWith("/") || s.startsWith("http://") || s.startsWith("https://");
|
|
1107
|
-
}
|
|
1108
|
-
/**
|
|
1109
|
-
* Builds every registered plugin now rather than on first use. A primary does it before starting its workers, so
|
|
1110
|
-
* the workers find each one built — instead of all of them compiling the same plugin into the same folder at once.
|
|
1111
|
-
*/
|
|
1112
|
-
async prepareAll() {
|
|
1113
|
-
await Promise.all(Object.keys(this.plugins).map((key) => this.prepare(key)));
|
|
1114
|
-
}
|
|
1115
|
-
async prepare(name) {
|
|
1116
|
-
const key = this.resolveKey(name) ?? name;
|
|
1117
|
-
if (this.failed.has(key)) return null;
|
|
1118
|
-
const inflight = this.inflight.get(key);
|
|
1119
|
-
if (inflight !== void 0) return inflight;
|
|
1120
|
-
const source = this.plugins[key];
|
|
1121
|
-
if (source === void 0) return null;
|
|
1122
|
-
if (isComponentSource(source) && !source.js) return this.toEntry(key, false, void 0, source.props);
|
|
1123
|
-
if (!isComponentSource(source) && source.action === "cdn") return this.toRemoteEntry(key, source);
|
|
1124
|
-
const cached = this.mem.get(key);
|
|
1125
|
-
let missing = false;
|
|
1126
|
-
if (cached && !this.isExpired(cached.compiledAt)) {
|
|
1127
|
-
if (await this.fileExists(path.join(this.pluginDir(key), "index.js"))) {
|
|
1128
|
-
/**
|
|
1129
|
-
* The disk check below never runs while this process holds the entry in memory, and a versioned plugin never
|
|
1130
|
-
* expires — so without this a dev server serves the bundle it built when it started, for as long as it runs.
|
|
1131
|
-
* Nothing else brings it back either: the components are named by PATH rather than imported, so editing one
|
|
1132
|
-
* does not even restart the watcher.
|
|
1133
|
-
*/
|
|
1134
|
-
if (!await this.isStaleInMemory(cached, source)) return cached.entry;
|
|
1135
|
-
serverLog.info("SSR", `Plugin "${key}" source changed since it was built, rebuilding…`);
|
|
1136
|
-
this.mem.delete(key);
|
|
1137
|
-
await fs.rm(this.pluginDir(key), {
|
|
1138
|
-
recursive: true,
|
|
1139
|
-
force: true
|
|
1140
|
-
});
|
|
1141
|
-
} else {
|
|
1142
|
-
serverLog.info("SSR", `Plugin "${key}" output missing, rebuilding…`);
|
|
1143
|
-
this.mem.delete(key);
|
|
1144
|
-
missing = true;
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
const meta = await this.readMeta(key);
|
|
1148
|
-
if (meta) {
|
|
1149
|
-
const sourceVersion = source.version;
|
|
1150
|
-
if (await this.isStale(meta, source) || await this.contentChanged(meta, source)) {
|
|
1151
|
-
serverLog.info("SSR", `Plugin "${key}" source changed since it was built, rebuilding…`);
|
|
1152
|
-
await fs.rm(this.pluginDir(key), {
|
|
1153
|
-
recursive: true,
|
|
1154
|
-
force: true
|
|
1155
|
-
});
|
|
1156
|
-
} else if (sourceVersion && meta.version !== sourceVersion) {
|
|
1157
|
-
serverLog.info("SSR", `Plugin "${key}" version changed (${meta.version ?? "none"} → ${sourceVersion}), rebuilding…`);
|
|
1158
|
-
await fs.rm(this.pluginDir(key), {
|
|
1159
|
-
recursive: true,
|
|
1160
|
-
force: true
|
|
1161
|
-
});
|
|
1162
|
-
} else if (sourceVersion || !this.isExpired(meta.compiledAt)) {
|
|
1163
|
-
if (await this.fileExists(path.join(this.pluginDir(key), "index.js"))) {
|
|
1164
|
-
const sourceCss = source.css;
|
|
1165
|
-
let cssUrl;
|
|
1166
|
-
if (await this.fileExists(path.join(this.pluginDir(key), "index.css"))) cssUrl = this.assetUrl(key, "index.css", meta.compiledAt);
|
|
1167
|
-
else if (sourceCss && this.isWebUrl(sourceCss)) cssUrl = sourceCss;
|
|
1168
|
-
const entry = this.toEntry(key, true, cssUrl, source.props, meta.compiledAt);
|
|
1169
|
-
this.remember(key, {
|
|
1170
|
-
compiledAt: meta.compiledAt,
|
|
1171
|
-
entry,
|
|
1172
|
-
inputs: meta.inputs
|
|
1173
|
-
});
|
|
1174
|
-
return entry;
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
const promise = this.build(key, source).finally(() => this.inflight.delete(key));
|
|
1179
|
-
this.inflight.set(key, promise);
|
|
1180
|
-
if (missing) this.restore(key, promise);
|
|
1181
|
-
return promise;
|
|
1182
|
-
}
|
|
1183
|
-
/**
|
|
1184
|
-
* Bundles that vanished from disk under a running server are built again as one episode: said once when the first
|
|
1185
|
-
* is noticed and once when the last is built — how many, how long, which failed — at the level it was noticed at.
|
|
1186
|
-
* Said per plugin, it was a warning for each and a "ready" for each at a level a project's terminal does not show,
|
|
1187
|
-
* so the rebuild never said it had finished.
|
|
1188
|
-
*/
|
|
1189
|
-
restore(key, build) {
|
|
1190
|
-
if (!this.restoring) {
|
|
1191
|
-
this.restoring = {
|
|
1192
|
-
started: Date.now(),
|
|
1193
|
-
pending: /* @__PURE__ */ new Set(),
|
|
1194
|
-
rebuilt: 0,
|
|
1195
|
-
failed: []
|
|
1196
|
-
};
|
|
1197
|
-
const where = path.relative(process.cwd(), this.outputDir) || this.outputDir;
|
|
1198
|
-
serverLog.warn("SSR", `Plugin bundles missing from ${where}: building them again…`);
|
|
1199
|
-
}
|
|
1200
|
-
const episode = this.restoring;
|
|
1201
|
-
clearTimeout(episode.closing);
|
|
1202
|
-
episode.pending.add(key);
|
|
1203
|
-
build.then((entry) => {
|
|
1204
|
-
episode.pending.delete(key);
|
|
1205
|
-
if (entry) episode.rebuilt += 1;
|
|
1206
|
-
else episode.failed.push(key);
|
|
1207
|
-
if (episode.pending.size > 0) return;
|
|
1208
|
-
episode.closing = setTimeout(() => {
|
|
1209
|
-
if (this.restoring !== episode || episode.pending.size > 0) return;
|
|
1210
|
-
this.restoring = void 0;
|
|
1211
|
-
const seconds = ((Date.now() - episode.started) / 1e3).toFixed(1);
|
|
1212
|
-
const failed = episode.failed.length > 0 ? ` — ${String(episode.failed.length)} failed (${episode.failed.join(", ")}), said above` : "";
|
|
1213
|
-
serverLog.warn("SSR", `Plugin bundles built again: ${String(episode.rebuilt)} in ${seconds}s${failed}`);
|
|
1214
|
-
}, RESTORE_SETTLE_MS);
|
|
1215
|
-
episode.closing.unref();
|
|
1216
|
-
});
|
|
1217
|
-
}
|
|
1218
|
-
async build(name, source) {
|
|
1219
|
-
const dir = this.pluginDir(name);
|
|
1220
|
-
await fs.mkdir(dir, { recursive: true });
|
|
1221
|
-
const jsPath = source.js;
|
|
1222
|
-
const cssPath = source.css;
|
|
1223
|
-
const action = isComponentSource(source) ? source.js ? detectAction(source.js) : void 0 : source.action ?? detectAction(source.js);
|
|
1224
|
-
if (!jsPath || !action) return this.toEntry(name, false, void 0, source.props);
|
|
1225
|
-
serverLog.info("SSR", `Plugin "${name}" building (${action}: ${jsPath})…`);
|
|
1226
|
-
try {
|
|
1227
|
-
let cssUrl;
|
|
1228
|
-
let buildInputs = [];
|
|
1229
|
-
if (action === "compile") {
|
|
1230
|
-
const { hasCSS, inputs } = await compilePlugin(jsPath, dir, this.devMode);
|
|
1231
|
-
buildInputs = inputs;
|
|
1232
|
-
if (hasCSS) cssUrl = `${this.urlPrefix}/${name}/index.css`;
|
|
1233
|
-
else if (cssPath) {
|
|
1234
|
-
if (this.isWebUrl(cssPath)) cssUrl = cssPath;
|
|
1235
|
-
else {
|
|
1236
|
-
await copyPluginStylesheet(cssPath, dir);
|
|
1237
|
-
cssUrl = `${this.urlPrefix}/${name}/index.css`;
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
} else if (action === "download") {
|
|
1241
|
-
const jsRes = await fetch(jsPath);
|
|
1242
|
-
if (!jsRes.ok) throw new Error(`HTTP ${jsRes.status} downloading ${jsPath}`);
|
|
1243
|
-
await writeFileAtomic(path.join(dir, "index.js"), await jsRes.text());
|
|
1244
|
-
if (cssPath) {
|
|
1245
|
-
if (cssPath.startsWith("http://") || cssPath.startsWith("https://")) await copyPluginStylesheet(cssPath, dir);
|
|
1246
|
-
else if (this.isWebUrl(cssPath)) cssUrl = cssPath;
|
|
1247
|
-
else await copyPluginStylesheet(cssPath, dir);
|
|
1248
|
-
cssUrl = `${this.urlPrefix}/${name}/index.css`;
|
|
1249
|
-
}
|
|
1250
|
-
} else {
|
|
1251
|
-
await copyPlugin(jsPath, dir, "index.js");
|
|
1252
|
-
if (cssPath) {
|
|
1253
|
-
if (this.isWebUrl(cssPath)) cssUrl = cssPath;
|
|
1254
|
-
else {
|
|
1255
|
-
await copyPluginStylesheet(cssPath, dir);
|
|
1256
|
-
cssUrl = `${this.urlPrefix}/${name}/index.css`;
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
const compiledAt = Date.now();
|
|
1261
|
-
const inputs = this.inputsOf(source, buildInputs);
|
|
1262
|
-
await this.writeMeta(name, {
|
|
1263
|
-
compiledAt,
|
|
1264
|
-
version: source.version,
|
|
1265
|
-
inputs: buildInputs,
|
|
1266
|
-
...inputs.length > 0 ? { digest: await digestOf(inputs) } : {}
|
|
1267
|
-
});
|
|
1268
|
-
if (cssUrl?.startsWith(this.urlPrefix)) cssUrl = this.assetUrl(name, "index.css", compiledAt);
|
|
1269
|
-
const entry = this.toEntry(name, true, cssUrl, source.props, compiledAt);
|
|
1270
|
-
this.remember(name, {
|
|
1271
|
-
compiledAt,
|
|
1272
|
-
entry,
|
|
1273
|
-
inputs: buildInputs
|
|
1274
|
-
});
|
|
1275
|
-
serverLog.info("SSR", `Plugin "${name}" ready → ${entry.js}`);
|
|
1276
|
-
return entry;
|
|
1277
|
-
} catch (err) {
|
|
1278
|
-
serverLog.error("SSR", `Plugin "${name}" build failed (js: ${source.js ?? "none"})`, err);
|
|
1279
|
-
this.failed.add(name);
|
|
1280
|
-
return null;
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
async getEntries(names) {
|
|
1284
|
-
if (names.length === 0) return [];
|
|
1285
|
-
return (await Promise.all(names.map((n) => this.prepare(n)))).filter((e) => e !== null && e.js !== void 0);
|
|
1286
|
-
}
|
|
1287
|
-
getComponents() {
|
|
1288
|
-
const out = {};
|
|
1289
|
-
for (const [name, source] of Object.entries(this.plugins)) if (isComponentSource(source)) out[name.replace(/@[^@]*$/, "")] = source.component;
|
|
1290
|
-
return out;
|
|
1291
|
-
}
|
|
1292
|
-
/**
|
|
1293
|
-
* Drops what this process remembers of a plugin — its entry, its failure, which version its name means — and
|
|
1294
|
-
* leaves the disk alone. What an invalidation elsewhere in the fleet does here: that process removes the files,
|
|
1295
|
-
* and each of the others only has to stop pointing at them.
|
|
1296
|
-
*/
|
|
1297
|
-
forget(name, version) {
|
|
1298
|
-
if (!name) {
|
|
1299
|
-
this.mem.clear();
|
|
1300
|
-
this.failed.clear();
|
|
1301
|
-
this.nameIndex.clear();
|
|
1302
|
-
return;
|
|
1303
|
-
}
|
|
1304
|
-
const keysToEvict = /* @__PURE__ */ new Set();
|
|
1305
|
-
for (const key of [
|
|
1306
|
-
...Object.keys(this.plugins),
|
|
1307
|
-
...this.mem.keys(),
|
|
1308
|
-
...this.failed
|
|
1309
|
-
]) if (isKeyOf(key, name, version)) keysToEvict.add(key);
|
|
1310
|
-
for (const key of keysToEvict) {
|
|
1311
|
-
this.mem.delete(key);
|
|
1312
|
-
this.failed.delete(key);
|
|
1313
|
-
}
|
|
1314
|
-
const indexed = this.nameIndex.get(name);
|
|
1315
|
-
if (indexed !== void 0 && isKeyOf(indexed, name, version)) this.nameIndex.delete(name);
|
|
1316
|
-
}
|
|
1317
|
-
async invalidate(name, version) {
|
|
1318
|
-
this.forget(name, version);
|
|
1319
|
-
if (!name) {
|
|
1320
|
-
await fs.rm(this.outputDir, {
|
|
1321
|
-
recursive: true,
|
|
1322
|
-
force: true
|
|
1323
|
-
});
|
|
1324
|
-
return;
|
|
1325
|
-
}
|
|
1326
|
-
try {
|
|
1327
|
-
const entries = await fs.readdir(this.outputDir);
|
|
1328
|
-
await Promise.all(entries.filter((entry) => isKeyOf(entry, name, version)).map((entry) => fs.rm(path.join(this.outputDir, entry), {
|
|
1329
|
-
recursive: true,
|
|
1330
|
-
force: true
|
|
1331
|
-
})));
|
|
1332
|
-
} catch {}
|
|
1333
|
-
}
|
|
1334
|
-
destroy() {
|
|
1335
|
-
this.mem.clear();
|
|
1336
|
-
this.failed.clear();
|
|
1337
|
-
this.nameIndex.clear();
|
|
1338
|
-
}
|
|
1339
|
-
async readMeta(name) {
|
|
1340
|
-
try {
|
|
1341
|
-
const raw = await fs.readFile(path.join(this.pluginDir(name), META_FILE), "utf-8");
|
|
1342
|
-
return JSON.parse(raw);
|
|
1343
|
-
} catch {
|
|
1344
|
-
return null;
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
async writeMeta(name, meta) {
|
|
1348
|
-
await writeFileAtomic(path.join(this.pluginDir(name), META_FILE), JSON.stringify(meta));
|
|
1349
|
-
}
|
|
1350
|
-
async fileExists(p) {
|
|
1351
|
-
return fs.access(p).then(() => true).catch(() => false);
|
|
1352
|
-
}
|
|
1353
|
-
};
|
|
1354
767
|
// src/plugins/watch.ts
|
|
1355
768
|
/** How long a burst of writes — an editor saving, formatting, saving again — is waited out before one rebuild. */
|
|
1356
769
|
var SETTLE_MS = 80;
|
|
@@ -1501,6 +914,68 @@ var createLivePages = () => {
|
|
|
1501
914
|
}
|
|
1502
915
|
};
|
|
1503
916
|
};
|
|
917
|
+
// src/modules/icons/handler.ts
|
|
918
|
+
var FACE_PATH = new RegExp(`^${ICONS_PATH.replace(/\//g, "\\/")}([\\w-]{16})-(solid|regular|brands)\\.woff2$`);
|
|
919
|
+
/** The faces cut, by hash and face: a few kilobytes each, the same for every replica that cuts them. */
|
|
920
|
+
var CUT_KEEP = 128;
|
|
921
|
+
var cut = /* @__PURE__ */ new Map();
|
|
922
|
+
var cutFace = (sdkDir, face, key) => {
|
|
923
|
+
const known = cut.get(key);
|
|
924
|
+
if (known) return known;
|
|
925
|
+
const made = (async () => {
|
|
926
|
+
const { default: subsetFont } = await import("subset-font");
|
|
927
|
+
return subsetFont(await readFile(path.join(sdkDir, "webfonts", face.file)), String.fromCodePoint(...face.codepoints), { targetFormat: "woff2" });
|
|
928
|
+
})();
|
|
929
|
+
cut.set(key, made);
|
|
930
|
+
made.catch(() => cut.delete(key));
|
|
931
|
+
if (cut.size > CUT_KEEP) {
|
|
932
|
+
const oldest = cut.keys().next().value;
|
|
933
|
+
if (oldest !== void 0) cut.delete(oldest);
|
|
934
|
+
}
|
|
935
|
+
return made;
|
|
936
|
+
};
|
|
937
|
+
var notFound = (res, message) => {
|
|
938
|
+
res.setStatus(404);
|
|
939
|
+
res.setHeader("Cache-Control", "no-store");
|
|
940
|
+
res.setHeader("Content-Type", "text/plain; charset=utf-8");
|
|
941
|
+
res.send(message);
|
|
942
|
+
};
|
|
943
|
+
/**
|
|
944
|
+
* A face of the icon font cut to the glyphs the space names (`spaceIconsOf`), linked by its pages' heads — answered by
|
|
945
|
+
* whichever replica the request reaches, from the space as the request resolves it, as the stylesheet is. The name is
|
|
946
|
+
* 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
|
|
947
|
+
* they are, kept by nobody — a glyph either lacks is drawn from the whole font all the same.
|
|
948
|
+
*/
|
|
949
|
+
var handleIconFace = async (req, res, config, sdkDir, offlineDataCache) => {
|
|
950
|
+
const asked = FACE_PATH.exec(req.path);
|
|
951
|
+
if (!asked || !sdkDir) {
|
|
952
|
+
notFound(res, sdkDir ? "No such icon face" : "This server has no SDK installed to cut icon faces from");
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
const [, hash, key] = asked;
|
|
956
|
+
const { environment = "main", revision = 0 } = req.ctx.spaceDeployment ?? {};
|
|
957
|
+
const spaceId = req.ctx.spaceDeployment?.spaceId ?? 1;
|
|
958
|
+
const cacheKey = offlineDataCacheKeyOf(req.ctx.spaceDeployment);
|
|
959
|
+
const offlineData = (cacheKey ? offlineDataCache?.get(cacheKey) : void 0) ?? await config.adapters.getOfflineData(spaceId, environment, revision);
|
|
960
|
+
const icons = offlineData ? spaceIconsOf(offlineData, iconGlyphsAt(sdkDir)) : void 0;
|
|
961
|
+
const face = icons?.faces.find((candidate) => candidate.key === key);
|
|
962
|
+
if (!icons || !face) {
|
|
963
|
+
notFound(res, `Space ${String(spaceId)} (${environment}) names no ${key} icon`);
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
const font = await cutFace(sdkDir, face, `${icons.hash}-${key}`);
|
|
967
|
+
res.setHeader("Content-Type", "font/woff2");
|
|
968
|
+
res.setHeader("Cache-Control", icons.hash === hash ? "public, max-age=31536000, immutable" : "no-store");
|
|
969
|
+
res.send(font);
|
|
970
|
+
};
|
|
971
|
+
// src/core/services/iconFaces.ts
|
|
972
|
+
var iconFacesStage = async (ctx) => {
|
|
973
|
+
const { config, req } = ctx;
|
|
974
|
+
if (req.method !== "GET" || !req.path.startsWith("/_plitzi/icons/")) return false;
|
|
975
|
+
ctx.operation = "icons";
|
|
976
|
+
await handleIconFace(req, ctx.res, config, resolveSdkAssetsDir(), ctx.caches.offlineData);
|
|
977
|
+
return true;
|
|
978
|
+
};
|
|
1504
979
|
// src/core/services/servedSpace.ts
|
|
1505
980
|
/**
|
|
1506
981
|
* The space a page at this address renders (no deployment: the server's one space), for a file the server answers from
|
|
@@ -1514,49 +989,85 @@ var servedSpace = async (ctx, file) => {
|
|
|
1514
989
|
serverLog.warn("SSR", `${file} answered without the space: space ${String(spaceId)} could not be read`, error);
|
|
1515
990
|
});
|
|
1516
991
|
};
|
|
992
|
+
// src/core/services/llmsTxt.ts
|
|
993
|
+
var LLMS_TXT_PATH = "/llms.txt";
|
|
994
|
+
/** A line of Markdown that cannot break the list it is in: no line break, no bracket that closes a link early. */
|
|
995
|
+
var inline = (value) => value.replace(/\s+/g, " ").replace(/[[\]]/g, "").trim();
|
|
996
|
+
/**
|
|
997
|
+
* The index an assistant reads (llmstxt.org): the site's name, the home page's description as its summary, and a link
|
|
998
|
+
* to each page the sitemap lists with its SEO title and description — the same words a search result shows.
|
|
999
|
+
*/
|
|
1000
|
+
var llmsTxtOf = (schema, origin) => {
|
|
1001
|
+
const pages = sitemapPages(schema).map((page) => ({
|
|
1002
|
+
...page,
|
|
1003
|
+
seo: resolvePageSeo(schema, page.pageId)
|
|
1004
|
+
}));
|
|
1005
|
+
const home = pages.find((page) => page.path === "/");
|
|
1006
|
+
const name = inline(schema.settings.siteName ?? home?.seo.title ?? new URL(origin).hostname);
|
|
1007
|
+
const summary = home?.seo.description ? inline(home.seo.description) : "";
|
|
1008
|
+
const links = pages.map(({ path, seo }) => {
|
|
1009
|
+
return `- [${inline(seo.title ?? path)}](${origin}${path})${seo.description ? `: ${inline(seo.description)}` : ""}`;
|
|
1010
|
+
});
|
|
1011
|
+
return [
|
|
1012
|
+
`# ${name}`,
|
|
1013
|
+
...summary ? [`> ${summary}`] : [],
|
|
1014
|
+
"## Pages",
|
|
1015
|
+
links.join("\n")
|
|
1016
|
+
].join("\n\n");
|
|
1017
|
+
};
|
|
1018
|
+
/**
|
|
1019
|
+
* `/llms.txt`: the space's own (`settings.llmsTxt`), or the one its pages make (`llmsTxtOf`). A space that keeps
|
|
1020
|
+
* assistants out (`blockAiCrawlers: ['assistants']`) answers 404 — an index for them invites what it refuses. Never the
|
|
1021
|
+
* space's page for that address, which an assistant would read as the index.
|
|
1022
|
+
*/
|
|
1023
|
+
var llmsTxtStage = async (ctx) => {
|
|
1024
|
+
const { req } = ctx;
|
|
1025
|
+
if (req.method !== "GET" || req.path !== "/llms.txt") return false;
|
|
1026
|
+
ctx.operation = "llms";
|
|
1027
|
+
const schema = (await servedSpace(ctx, LLMS_TXT_PATH))?.schema;
|
|
1028
|
+
const origin = requestOrigin(req);
|
|
1029
|
+
ctx.res.setHeader("Content-Type", "text/plain; charset=utf-8");
|
|
1030
|
+
if (!schema || !origin || schema.settings.blockAiCrawlers?.includes("assistants")) {
|
|
1031
|
+
ctx.res.setStatus(404);
|
|
1032
|
+
ctx.res.send("This site publishes no llms.txt.\n");
|
|
1033
|
+
return true;
|
|
1034
|
+
}
|
|
1035
|
+
const own = schema.settings.llmsTxt?.trim();
|
|
1036
|
+
ctx.res.setStatus(200);
|
|
1037
|
+
ctx.res.send(`${own || llmsTxtOf(schema, origin)}\n`);
|
|
1038
|
+
return true;
|
|
1039
|
+
};
|
|
1517
1040
|
// src/core/services/robotsTxt.ts
|
|
1518
1041
|
/** What a space that says nothing answers: everything may be crawled. */
|
|
1519
1042
|
var DEFAULT_ROBOTS_TXT = "User-agent: *\nAllow: /\n";
|
|
1520
|
-
/**
|
|
1521
|
-
|
|
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
|
-
];
|
|
1043
|
+
/** What an address made for people, never for search, answers (a snapshot's preview): nothing may be crawled. */
|
|
1044
|
+
var NOINDEX_ROBOTS_TXT = "User-agent: *\nDisallow: /\n";
|
|
1539
1045
|
var SITEMAP_LINE = /^\s*sitemap\s*:/im;
|
|
1540
1046
|
/**
|
|
1541
|
-
* `/robots.txt`: the space's own (`settings.robotsTxt`) or one that lets crawlers read everything, then
|
|
1542
|
-
* keeps
|
|
1543
|
-
* 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
|
|
1047
|
+
* `/robots.txt`: the space's own (`settings.robotsTxt`) or one that lets crawlers read everything, then a `Disallow: /`
|
|
1048
|
+
* for each AI crawler of the kinds the space keeps out (`settings.blockAiCrawlers`), and the address of its sitemap
|
|
1049
|
+
* unless its own text names one — and on an address that is never for search (`noindex`), nothing at all. Never the space's page for an address it has none for: a crawler reads a 404 page as
|
|
1544
1050
|
* "no rules", and an HTML page as rules it cannot parse.
|
|
1545
1051
|
*/
|
|
1546
1052
|
var robotsTxtStage = async (ctx) => {
|
|
1547
1053
|
const { req } = ctx;
|
|
1548
1054
|
if (req.method !== "GET" || req.path !== "/robots.txt") return false;
|
|
1549
1055
|
ctx.operation = "robots";
|
|
1056
|
+
ctx.res.setHeader("Content-Type", "text/plain; charset=utf-8");
|
|
1057
|
+
if (req.ctx.spaceDeployment?.noindex) {
|
|
1058
|
+
ctx.res.setStatus(200);
|
|
1059
|
+
ctx.res.send(NOINDEX_ROBOTS_TXT);
|
|
1060
|
+
return true;
|
|
1061
|
+
}
|
|
1550
1062
|
const settings = (await servedSpace(ctx, "/robots.txt"))?.schema.settings;
|
|
1551
1063
|
const own = settings?.robotsTxt?.trim() ? settings.robotsTxt.trim() : DEFAULT_ROBOTS_TXT.trim();
|
|
1552
1064
|
const origin = requestOrigin(req);
|
|
1553
1065
|
const sections = [
|
|
1554
1066
|
own,
|
|
1555
|
-
...settings?.blockAiCrawlers
|
|
1067
|
+
...blockedAiCrawlers(settings?.blockAiCrawlers).map((agent) => `User-agent: ${agent}\nDisallow: /`),
|
|
1556
1068
|
...origin && !SITEMAP_LINE.test(own) ? [`Sitemap: ${origin}/sitemap.xml`] : []
|
|
1557
1069
|
];
|
|
1558
1070
|
ctx.res.setStatus(200);
|
|
1559
|
-
ctx.res.setHeader("Content-Type", "text/plain; charset=utf-8");
|
|
1560
1071
|
ctx.res.send(`${sections.join("\n\n")}\n`);
|
|
1561
1072
|
return true;
|
|
1562
1073
|
};
|
|
@@ -1671,7 +1182,7 @@ var handleRsc = async (req, res, config, _pluginManager, cache, signal) => {
|
|
|
1671
1182
|
*/
|
|
1672
1183
|
const forcingFlags = Object.keys(forcedFlagsFromCookies(req.headers.cookie, requestAuthority(req))).length > 0;
|
|
1673
1184
|
const uncached = previewing || forcingFlags;
|
|
1674
|
-
const ttlMs = config.rsc?.cacheTtlMs ?? DEFAULT_TTL_MS
|
|
1185
|
+
const ttlMs = config.rsc?.cacheTtlMs ?? DEFAULT_TTL_MS.rsc;
|
|
1675
1186
|
const isAuthenticated = !!req.ctx.user;
|
|
1676
1187
|
const cacheControl = environment === "main" || uncached ? "no-store" : isAuthenticated ? `private, max-age=${Math.floor(ttlMs / 1e3)}` : `public, max-age=${Math.floor(ttlMs / 1e3)}`;
|
|
1677
1188
|
const cacheKey = environment !== "main" && !uncached ? buildRscCacheKey(spaceId, environment, revision, req.ctx.user?.id, idsParam, req) : void 0;
|
|
@@ -1739,6 +1250,29 @@ var rscStage = async (ctx) => {
|
|
|
1739
1250
|
await handleRsc(req, ctx.res, config, ctx.pluginManager, ctx.caches.rsc, ctx.signal);
|
|
1740
1251
|
return true;
|
|
1741
1252
|
};
|
|
1253
|
+
// src/core/services/securityTxt.ts
|
|
1254
|
+
var SECURITY_TXT_PATH = "/.well-known/security.txt";
|
|
1255
|
+
/**
|
|
1256
|
+
* `/.well-known/security.txt` (RFC 9116): the space's own words (`settings.securityTxt`), as plain text — where somebody
|
|
1257
|
+
* who found a flaw writes, and until when that holds. A space that says nothing answers 404: a contact the site never
|
|
1258
|
+
* gave would send a researcher's report nowhere. Never the space's page for that address, which a reader takes for the
|
|
1259
|
+
* file.
|
|
1260
|
+
*/
|
|
1261
|
+
var securityTxtStage = async (ctx) => {
|
|
1262
|
+
const { req } = ctx;
|
|
1263
|
+
if (req.method !== "GET" || req.path !== "/.well-known/security.txt") return false;
|
|
1264
|
+
ctx.operation = "security";
|
|
1265
|
+
const own = (await servedSpace(ctx, SECURITY_TXT_PATH))?.schema.settings.securityTxt?.trim();
|
|
1266
|
+
ctx.res.setHeader("Content-Type", "text/plain; charset=utf-8");
|
|
1267
|
+
if (!own) {
|
|
1268
|
+
ctx.res.setStatus(404);
|
|
1269
|
+
ctx.res.send("This site publishes no security.txt.\n");
|
|
1270
|
+
return true;
|
|
1271
|
+
}
|
|
1272
|
+
ctx.res.setStatus(200);
|
|
1273
|
+
ctx.res.send(`${own}\n`);
|
|
1274
|
+
return true;
|
|
1275
|
+
};
|
|
1742
1276
|
// src/core/services/sitemapXml.ts
|
|
1743
1277
|
var XML_ESCAPES = {
|
|
1744
1278
|
"&": "&",
|
|
@@ -1834,8 +1368,8 @@ var pageSlot = (config, caches, key, facts, anonymous, compression) => {
|
|
|
1834
1368
|
key: sharedKeyOf(key),
|
|
1835
1369
|
facts
|
|
1836
1370
|
} } : {},
|
|
1837
|
-
ttlMs: config.cacheTtlMs ?? DEFAULT_TTL_MS
|
|
1838
|
-
staleMs: config.cache?.staleMs ?? DEFAULT_TTL_MS
|
|
1371
|
+
ttlMs: config.cacheTtlMs ?? DEFAULT_TTL_MS.html,
|
|
1372
|
+
staleMs: config.cache?.staleMs ?? DEFAULT_TTL_MS.stale,
|
|
1839
1373
|
compression
|
|
1840
1374
|
};
|
|
1841
1375
|
};
|
|
@@ -1909,7 +1443,10 @@ var streamBody = async (req, res, config, spaceId, environment, revision, render
|
|
|
1909
1443
|
metrics?.record("template", Math.round(performance.now() - templateStart));
|
|
1910
1444
|
const sentinelIdx = fullTemplate.indexOf(SSR_SENTINEL);
|
|
1911
1445
|
const head = sentinelIdx >= 0 ? fullTemplate.slice(0, sentinelIdx) : fullTemplate;
|
|
1912
|
-
const
|
|
1446
|
+
const tailOf = (template) => {
|
|
1447
|
+
const at = template.indexOf(SSR_SENTINEL);
|
|
1448
|
+
return at >= 0 ? template.slice(at + 18) : "";
|
|
1449
|
+
};
|
|
1913
1450
|
const result = {};
|
|
1914
1451
|
const nonce = prep.templateParams.nonce ?? "";
|
|
1915
1452
|
await new Promise((resolve, reject) => {
|
|
@@ -1921,6 +1458,11 @@ var streamBody = async (req, res, config, spaceId, environment, revision, render
|
|
|
1921
1458
|
cb();
|
|
1922
1459
|
},
|
|
1923
1460
|
final(cb) {
|
|
1461
|
+
const tail = tailOf(result.prePaint ? renderFn({
|
|
1462
|
+
...prep.templateParams,
|
|
1463
|
+
html: SSR_SENTINEL,
|
|
1464
|
+
prePaint: result.prePaint
|
|
1465
|
+
}) : fullTemplate);
|
|
1924
1466
|
const tailBuf = Buffer.from(tail, "utf-8");
|
|
1925
1467
|
res.write(tailBuf);
|
|
1926
1468
|
res.end();
|
|
@@ -1983,6 +1525,7 @@ var renderSSR = async (req, res, config, renderFn, pluginManager, caches, publis
|
|
|
1983
1525
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
1984
1526
|
res.setHeader("Accept-CH", SCHEME_HINT_HEADER);
|
|
1985
1527
|
res.setHeader("Vary", SCHEME_HINT_HEADER);
|
|
1528
|
+
if (req.ctx.spaceDeployment?.noindex) res.setHeader("X-Robots-Tag", "noindex, nofollow");
|
|
1986
1529
|
const hint = pageHints(config, res);
|
|
1987
1530
|
const draft = await takeDraftOverride(req, config);
|
|
1988
1531
|
const offlineDataOverride = draft?.data;
|
|
@@ -2616,7 +2159,7 @@ var cspReportStage = async (ctx) => {
|
|
|
2616
2159
|
* Kept as text rather than a file beside the module: the server's build moves its modules into chunks, and a deployment
|
|
2617
2160
|
* bundles them again (a project's server, `bundleProject`) — a string goes wherever its module goes.
|
|
2618
2161
|
*/
|
|
2619
|
-
var DEFAULT_FAVICON_SVG =
|
|
2162
|
+
var DEFAULT_FAVICON_SVG = PLITZI_MARK_SVG;
|
|
2620
2163
|
// src/core/http/stages/defaultFavicon.ts
|
|
2621
2164
|
/** Plitzi's icon, at the address a page that names none points its tab at — see `DEFAULT_FAVICON_SVG`. */
|
|
2622
2165
|
var defaultFaviconStage = (ctx) => {
|
|
@@ -2702,6 +2245,7 @@ var buildPagePipeline = (services, extensions = {}, engine) => {
|
|
|
2702
2245
|
publicDirStage,
|
|
2703
2246
|
defaultFaviconStage,
|
|
2704
2247
|
cspReportStage,
|
|
2248
|
+
...services.ssr ? [securityTxtStage] : [],
|
|
2705
2249
|
wellKnownStage,
|
|
2706
2250
|
pluginAssetsStage,
|
|
2707
2251
|
fontAssetsStage,
|
|
@@ -2721,8 +2265,10 @@ var buildPagePipeline = (services, extensions = {}, engine) => {
|
|
|
2721
2265
|
if (services.ssr) {
|
|
2722
2266
|
stages.push(spaceDocumentStage);
|
|
2723
2267
|
stages.push(styleSheetStage);
|
|
2268
|
+
stages.push(iconFacesStage);
|
|
2724
2269
|
stages.push(robotsTxtStage);
|
|
2725
2270
|
stages.push(sitemapXmlStage);
|
|
2271
|
+
stages.push(llmsTxtStage);
|
|
2726
2272
|
}
|
|
2727
2273
|
stages.push(services.ssr ? ssrStage : notFoundStage);
|
|
2728
2274
|
return stages;
|
|
@@ -2732,7 +2278,7 @@ var buildPagePipeline = (services, extensions = {}, engine) => {
|
|
|
2732
2278
|
* pipeline. Which services it mounts is the CALLER's decision — {@link createServer} passes whatever the config
|
|
2733
2279
|
* enables — so this unit never second-guesses a factory's promise. */
|
|
2734
2280
|
var createPageServer = (config, services, extensions, engine) => {
|
|
2735
|
-
const { cacheTtlMs: htmlTtlMs = DEFAULT_TTL_MS
|
|
2281
|
+
const { cacheTtlMs: htmlTtlMs = DEFAULT_TTL_MS.html } = config;
|
|
2736
2282
|
const logLevel = config.logLevel ?? defaultLogLevel(config.devMode);
|
|
2737
2283
|
const { logger } = config;
|
|
2738
2284
|
config.logLevel = logLevel;
|
|
@@ -2753,7 +2299,7 @@ var createPageServer = (config, services, extensions, engine) => {
|
|
|
2753
2299
|
config.renderLimit = renderLimitOf(config.renderLimit);
|
|
2754
2300
|
const caches = createServerCaches({
|
|
2755
2301
|
htmlTtlMs,
|
|
2756
|
-
rscTtlMs: config.rsc?.cacheTtlMs ?? DEFAULT_TTL_MS
|
|
2302
|
+
rscTtlMs: config.rsc?.cacheTtlMs ?? DEFAULT_TTL_MS.rsc,
|
|
2757
2303
|
htmlBytes: config.cache.maxBytes,
|
|
2758
2304
|
staleMs: config.cache.staleMs
|
|
2759
2305
|
});
|
|
@@ -2825,7 +2371,7 @@ var createPageServer = (config, services, extensions, engine) => {
|
|
|
2825
2371
|
fleetStores: {
|
|
2826
2372
|
...engine?.fleetStores,
|
|
2827
2373
|
"ssr.drafts": hostable(createMemoryDraftStore, DRAFT_STORE_METHODS),
|
|
2828
|
-
"auth.rateLimit": hostable(() => ({ check:
|
|
2374
|
+
"auth.rateLimit": hostable(() => ({ check: createRateLimit() }), RATE_LIMIT_METHODS)
|
|
2829
2375
|
},
|
|
2830
2376
|
onStopping: () => {
|
|
2831
2377
|
engine?.stopping?.();
|
|
@@ -2862,7 +2408,7 @@ var createPageServer = (config, services, extensions, engine) => {
|
|
|
2862
2408
|
// src/core/createServer.ts
|
|
2863
2409
|
/**
|
|
2864
2410
|
* 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 (
|
|
2411
|
+
* engine from and hands the server (`engine`), or a worker runs elsewhere (docs/en/server-packages.md, D12).
|
|
2866
2412
|
*/
|
|
2867
2413
|
var ENGINE_KEYS = [
|
|
2868
2414
|
"action",
|
|
@@ -2903,7 +2449,8 @@ var withRsc = (config, engine) => {
|
|
|
2903
2449
|
elementTimeoutMs: config.rsc?.elementTimeoutMs,
|
|
2904
2450
|
sayFailures: config.devMode === true,
|
|
2905
2451
|
outbound: { privateOrigins: privateOriginsOf(config.outbound?.privateOrigins) },
|
|
2906
|
-
visitorCredentials: config.rsc?.visitorCredentials
|
|
2452
|
+
visitorCredentials: config.rsc?.visitorCredentials,
|
|
2453
|
+
...config.paintedDefaults ? { paintedDefaults: config.paintedDefaults } : {}
|
|
2907
2454
|
})
|
|
2908
2455
|
}
|
|
2909
2456
|
};
|