@plitzi/sdk-server 0.30.19

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 (93) hide show
  1. package/CHANGELOG.md +192 -0
  2. package/README.md +870 -0
  3. package/dist/.gitkeep +0 -0
  4. package/dist/adapters/jsonAdapters.js +46 -0
  5. package/dist/core/createServer.js +47 -0
  6. package/dist/core/mimeTypes.js +41 -0
  7. package/dist/core/requestHandler.js +108 -0
  8. package/dist/core/requestParser.js +34 -0
  9. package/dist/core/staticFiles.js +42 -0
  10. package/dist/core/transports.js +51 -0
  11. package/dist/helpers/buildResponseHelpers.js +43 -0
  12. package/dist/helpers/buildServerInfo.js +55 -0
  13. package/dist/helpers/cache/TtlCache.js +55 -0
  14. package/dist/helpers/cache/cacheManager.js +25 -0
  15. package/dist/helpers/cache/defaults.js +9 -0
  16. package/dist/helpers/cache/keys.js +6 -0
  17. package/dist/helpers/cache/serverCaches.js +15 -0
  18. package/dist/helpers/compress.js +17 -0
  19. package/dist/helpers/escapeJson.js +4 -0
  20. package/dist/helpers/metrics.js +36 -0
  21. package/dist/helpers/normalizePlugins.js +16 -0
  22. package/dist/helpers/runMiddlewares.js +21 -0
  23. package/dist/index.d.ts +2 -0
  24. package/dist/index.js +3 -0
  25. package/dist/middlewares/auth.js +10 -0
  26. package/dist/middlewares/basicAuth.js +67 -0
  27. package/dist/middlewares/spaceDeployment.js +16 -0
  28. package/dist/modules/mcp/handler.js +34 -0
  29. package/dist/modules/mcp/server.js +120 -0
  30. package/dist/modules/rsc/handler.js +69 -0
  31. package/dist/modules/ssr/Component.js +20 -0
  32. package/dist/modules/ssr/buildBody.js +20 -0
  33. package/dist/modules/ssr/handler.js +36 -0
  34. package/dist/modules/ssr/loadPluginComponents.js +45 -0
  35. package/dist/modules/ssr/prepareRender.js +64 -0
  36. package/dist/modules/ssr/registerExternalPlugins.js +54 -0
  37. package/dist/modules/ssr/streamBody.js +54 -0
  38. package/dist/modules/ssr/template.js +10 -0
  39. package/dist/modules/ssr/views/template.ejs +71 -0
  40. package/dist/plugins/compile.js +29 -0
  41. package/dist/plugins/copy.js +13 -0
  42. package/dist/plugins/detect.js +9 -0
  43. package/dist/plugins/manager.js +251 -0
  44. package/dist/public/.gitkeep +0 -0
  45. package/dist/server.d.ts +1 -0
  46. package/dist/server.js +82 -0
  47. package/dist/src/adapters/jsonAdapters.d.ts +7 -0
  48. package/dist/src/core/createServer.d.ts +2 -0
  49. package/dist/src/core/mimeTypes.d.ts +4 -0
  50. package/dist/src/core/requestHandler.d.ts +5 -0
  51. package/dist/src/core/requestParser.d.ts +3 -0
  52. package/dist/src/core/staticFiles.d.ts +2 -0
  53. package/dist/src/core/transports.d.ts +18 -0
  54. package/dist/src/helpers/buildResponseHelpers.d.ts +10 -0
  55. package/dist/src/helpers/buildServerInfo.d.ts +2 -0
  56. package/dist/src/helpers/cache/TtlCache.d.ts +15 -0
  57. package/dist/src/helpers/cache/cacheManager.d.ts +3 -0
  58. package/dist/src/helpers/cache/defaults.d.ts +1 -0
  59. package/dist/src/helpers/cache/index.d.ts +6 -0
  60. package/dist/src/helpers/cache/keys.d.ts +7 -0
  61. package/dist/src/helpers/cache/serverCaches.d.ts +9 -0
  62. package/dist/src/helpers/compress.d.ts +3 -0
  63. package/dist/src/helpers/escapeJson.d.ts +1 -0
  64. package/dist/src/helpers/metrics.d.ts +11 -0
  65. package/dist/src/helpers/normalizePlugins.d.ts +4 -0
  66. package/dist/src/helpers/runMiddlewares.d.ts +2 -0
  67. package/dist/src/index.d.ts +4 -0
  68. package/dist/src/middlewares/auth.d.ts +2 -0
  69. package/dist/src/middlewares/basicAuth.d.ts +6 -0
  70. package/dist/src/middlewares/spaceDeployment.d.ts +2 -0
  71. package/dist/src/modules/mcp/handler.d.ts +3 -0
  72. package/dist/src/modules/mcp/server.d.ts +3 -0
  73. package/dist/src/modules/rsc/handler.d.ts +17 -0
  74. package/dist/src/modules/ssr/Component.d.ts +11 -0
  75. package/dist/src/modules/ssr/buildBody.d.ts +5 -0
  76. package/dist/src/modules/ssr/handler.d.ts +4 -0
  77. package/dist/src/modules/ssr/loadPluginComponents.d.ts +13 -0
  78. package/dist/src/modules/ssr/prepareRender.d.ts +13 -0
  79. package/dist/src/modules/ssr/registerExternalPlugins.d.ts +7 -0
  80. package/dist/src/modules/ssr/streamBody.d.ts +5 -0
  81. package/dist/src/modules/ssr/template.d.ts +6 -0
  82. package/dist/src/plugins/compile.d.ts +3 -0
  83. package/dist/src/plugins/copy.d.ts +1 -0
  84. package/dist/src/plugins/detect.d.ts +3 -0
  85. package/dist/src/plugins/manager.d.ts +40 -0
  86. package/dist/src/standalone/alias-loader.d.mts +1 -0
  87. package/dist/src/standalone/plugins/ClientInfo.d.ts +2 -0
  88. package/dist/src/standalone/plugins/ServerInfo.d.ts +2 -0
  89. package/dist/src/standalone/plugins/SharedInfo.d.ts +2 -0
  90. package/dist/src/standalone/plugins/styles.d.ts +5 -0
  91. package/dist/src/standalone/register-alias.d.mts +1 -0
  92. package/dist/src/standalone/server.d.ts +1 -0
  93. package/package.json +60 -0
@@ -0,0 +1,71 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title><%= locals.title || '' %></title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <link rel="shortcut icon" href="https://cdn.plitzi.com/resources/img/favicon.svg" />
8
+
9
+ <link rel="preconnect" href="https://fonts.gstatic.com" />
10
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
11
+ <link rel="preconnect" href="https://cdn.plitzi.com" />
12
+
13
+ <link rel="modulepreload" href="<%= locals.react || '' %>" crossorigin />
14
+ <link rel="modulepreload" href="<%= locals.reactDom || '' %>" crossorigin />
15
+
16
+ <script type="importmap">
17
+ {
18
+ "imports": {
19
+ "react": "<%= locals.react || '' %>",
20
+ "react-dom": "<%= locals.reactDom || '' %>",
21
+ "react-dom/client": "<%= locals.reactDomClient || '' %>",
22
+ "react/jsx-runtime": "<%= locals.reactJsx || '' %>",
23
+ "@plitzi/plitzi-sdk": "<%= locals.jsPath || '' %>"
24
+ }
25
+ }
26
+ </script>
27
+
28
+ <link
29
+ rel="preload"
30
+ href="https://fonts.googleapis.com/icon?family=Material+Icons"
31
+ as="style"
32
+ onload="this.onload=null;this.rel='stylesheet';"
33
+ />
34
+ <noscript>
35
+ <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
36
+ </noscript>
37
+
38
+ <link href="<%= locals.cssPath || '' %>" rel="preload" as="style" />
39
+ <link href="<%= locals.cssPath || '' %>" rel="stylesheet" />
40
+ <% if (locals.builderCssPath) { %>
41
+ <link href="<%= locals.builderCssPath %>" rel="preload" as="style" />
42
+ <link href="<%= locals.builderCssPath %>" rel="stylesheet" />
43
+ <% } %>
44
+ <% if (locals.plugins && locals.plugins.length > 0) { %>
45
+ <% for (const plugin of locals.plugins) { if (plugin.css) { %>
46
+ <link href="<%= plugin.css %>" rel="preload" as="style" />
47
+ <link href="<%= plugin.css %>" rel="stylesheet" />
48
+ <% } } %>
49
+ <% } %>
50
+ </head>
51
+
52
+ <body>
53
+ <noscript>You need to enable JavaScript to run this app.</noscript>
54
+ <div id="plitzi" class="plitzi-root-container"><%- locals.html || '' %></div>
55
+ <% if (!locals.ssrOnly) { %>
56
+ <script type="module">
57
+ import { render } from '<%= locals.jsPath || '' %>';
58
+ <% const activePlugins = (locals.plugins || []).filter(p => p.js); %>
59
+ <% if (activePlugins.length > 0) { %>
60
+ <% for (const plugin of activePlugins) { %>
61
+ import { default as <%= plugin.varName %> } from '<%= plugin.js %>';
62
+ <% } %>
63
+ const __plitziPlugins = { <%- activePlugins.map(p => `'${p.keyName}': {component: ${p.varName}, props: ${JSON.stringify(p.props)}}`).join(', ') %> };
64
+ render('plitzi', <%- locals.offlineData || '{}' %>, __plitziPlugins, <%= locals.debugMode ? true : false %>, true);
65
+ <% } else { %>
66
+ render('plitzi', <%- locals.offlineData || '{}' %>, {}, <%= locals.debugMode ? true : false %>, true);
67
+ <% } %>
68
+ </script>
69
+ <% } %>
70
+ </body>
71
+ </html>
@@ -0,0 +1,29 @@
1
+ import path from "node:path";
2
+ import fs from "node:fs/promises";
3
+ import esbuild from "esbuild";
4
+ //#region src/plugins/compile.ts
5
+ var EXTERNAL = [
6
+ "react",
7
+ "react-dom",
8
+ "react-dom/client",
9
+ "react/jsx-runtime",
10
+ "@plitzi/plitzi-sdk",
11
+ "@plitzi/sdk-shared"
12
+ ];
13
+ var compilePlugin = async (jsPath, outDir, devMode = false) => {
14
+ await esbuild.build({
15
+ entryPoints: [jsPath],
16
+ bundle: true,
17
+ format: "esm",
18
+ external: EXTERNAL,
19
+ outdir: outDir,
20
+ entryNames: "index",
21
+ jsx: "automatic",
22
+ minify: !devMode,
23
+ splitting: false,
24
+ logLevel: "warning"
25
+ });
26
+ return { hasCSS: await fs.access(path.join(outDir, "index.css")).then(() => true).catch(() => false) };
27
+ };
28
+ //#endregion
29
+ export { compilePlugin };
@@ -0,0 +1,13 @@
1
+ import path from "node:path";
2
+ import fs from "node:fs/promises";
3
+ //#region src/plugins/copy.ts
4
+ var copyPlugin = async (src, destDir, filename) => {
5
+ const dest = path.join(destDir, filename);
6
+ if (src.startsWith("http://") || src.startsWith("https://")) {
7
+ const res = await fetch(src);
8
+ if (!res.ok) throw new Error(`[SSR] Plugin fetch failed ${src}: ${res.status}`);
9
+ await fs.writeFile(dest, await res.text(), "utf-8");
10
+ } else await fs.copyFile(src, dest);
11
+ };
12
+ //#endregion
13
+ export { copyPlugin };
@@ -0,0 +1,9 @@
1
+ //#region src/plugins/detect.ts
2
+ var isComponentSource = (source) => "component" in source;
3
+ var detectAction = (js) => {
4
+ if (js.startsWith("http://") || js.startsWith("https://")) return "copy";
5
+ if (js.endsWith(".tsx") || js.endsWith(".ts") || js.endsWith(".jsx")) return "compile";
6
+ return "copy";
7
+ };
8
+ //#endregion
9
+ export { detectAction, isComponentSource };
@@ -0,0 +1,251 @@
1
+ import { compilePlugin } from "./compile.js";
2
+ import { copyPlugin } from "./copy.js";
3
+ import { detectAction, isComponentSource } from "./detect.js";
4
+ import path from "node:path";
5
+ import fs from "node:fs/promises";
6
+ //#region src/plugins/manager.ts
7
+ var META_FILE = "meta.json";
8
+ var DEFAULT_TTL_MS = 10080 * 60 * 1e3;
9
+ var DEFAULT_CACHE_DIR = ".sdk-plugins";
10
+ var PluginManager = class {
11
+ urlPrefix = "/sdk-plugins";
12
+ outputDir;
13
+ plugins;
14
+ ttlMs;
15
+ mem = /* @__PURE__ */ new Map();
16
+ inflight = /* @__PURE__ */ new Map();
17
+ failed = /* @__PURE__ */ new Set();
18
+ /** Maps base plugin name → most recently registered effective key (may include @version) */
19
+ nameIndex = /* @__PURE__ */ new Map();
20
+ devMode = false;
21
+ constructor(plugins, cacheDir, ttlMs, devMode = false) {
22
+ this.plugins = plugins;
23
+ this.outputDir = path.resolve(process.cwd(), cacheDir ?? DEFAULT_CACHE_DIR);
24
+ this.ttlMs = ttlMs ?? DEFAULT_TTL_MS;
25
+ this.devMode = devMode;
26
+ for (const key of Object.keys(plugins)) {
27
+ const baseName = key.replace(/@[^@]*$/, "");
28
+ this.nameIndex.set(baseName, key);
29
+ }
30
+ }
31
+ hasPlugin(name) {
32
+ return this.resolveKey(name) !== null;
33
+ }
34
+ register(name, source) {
35
+ this.plugins[name] = source;
36
+ this.mem.delete(name);
37
+ this.failed.delete(name);
38
+ const baseName = name.replace(/@[^@]*$/, "");
39
+ this.nameIndex.set(baseName, name);
40
+ }
41
+ /**
42
+ * Registers a plugin only if it is not yet known under its effective key.
43
+ * Returns the effective key (`name@version` when version is set, `name` otherwise)
44
+ * so the caller can pass it directly to getEntries().
45
+ */
46
+ ensure(name, source) {
47
+ const key = source.version ? `${name}@${source.version}` : name;
48
+ if (!(key in this.plugins)) this.register(key, source);
49
+ return key;
50
+ }
51
+ /**
52
+ * Resolves a caller-supplied name to the effective key stored in the plugins map.
53
+ * Accepts both the exact key (`plitziBuilder@1.0.0`) and the base name (`plitziBuilder`).
54
+ */
55
+ resolveKey(name) {
56
+ if (name in this.plugins) return name;
57
+ const indexed = this.nameIndex.get(name);
58
+ if (indexed && indexed in this.plugins) return indexed;
59
+ return null;
60
+ }
61
+ pluginDir(name) {
62
+ return path.join(this.outputDir, name);
63
+ }
64
+ isExpired(compiledAt) {
65
+ return Date.now() - compiledAt > this.ttlMs;
66
+ }
67
+ toEntry(name, hasJS, cssUrl, props = {}) {
68
+ const keyName = name.split("@")[0];
69
+ return {
70
+ name,
71
+ varName: keyName.split("-").join("_").split(".").join("_"),
72
+ keyName,
73
+ js: hasJS ? `${this.urlPrefix}/${name}/index.js` : void 0,
74
+ filePath: hasJS ? path.join(this.outputDir, name, "index.js") : void 0,
75
+ css: cssUrl,
76
+ props
77
+ };
78
+ }
79
+ isWebUrl(s) {
80
+ return s.startsWith("/") || s.startsWith("http://") || s.startsWith("https://");
81
+ }
82
+ async prepare(name) {
83
+ const key = this.resolveKey(name) ?? name;
84
+ if (this.failed.has(key)) return null;
85
+ const inflight = this.inflight.get(key);
86
+ if (inflight !== void 0) return inflight;
87
+ const source = this.plugins[key];
88
+ if (source === void 0) return null;
89
+ if (isComponentSource(source) && !source.js) return this.toEntry(key, false, void 0, source.props);
90
+ const cached = this.mem.get(key);
91
+ if (cached && !this.isExpired(cached.compiledAt)) {
92
+ if (await this.fileExists(path.join(this.pluginDir(key), "index.js"))) return cached.entry;
93
+ console.warn(`[SSR] Plugin "${key}" cache invalidated: output file missing, rebuilding…`);
94
+ this.mem.delete(key);
95
+ }
96
+ const meta = await this.readMeta(key);
97
+ if (meta) {
98
+ const sourceVersion = source.version;
99
+ if (sourceVersion && meta.version !== sourceVersion) {
100
+ console.log(`[SSR] Plugin "${key}" version changed (${meta.version ?? "none"} → ${sourceVersion}), rebuilding…`);
101
+ await fs.rm(this.pluginDir(key), {
102
+ recursive: true,
103
+ force: true
104
+ });
105
+ } else if (sourceVersion || !this.isExpired(meta.compiledAt)) {
106
+ if (await this.fileExists(path.join(this.pluginDir(key), "index.js"))) {
107
+ const sourceCss = source.css;
108
+ let cssUrl;
109
+ if (await this.fileExists(path.join(this.pluginDir(key), "index.css"))) cssUrl = `${this.urlPrefix}/${key}/index.css`;
110
+ else if (sourceCss && this.isWebUrl(sourceCss)) cssUrl = sourceCss;
111
+ const entry = this.toEntry(key, true, cssUrl, source.props);
112
+ this.mem.set(key, {
113
+ compiledAt: meta.compiledAt,
114
+ entry
115
+ });
116
+ return entry;
117
+ }
118
+ }
119
+ }
120
+ const promise = this.build(key, source).finally(() => this.inflight.delete(key));
121
+ this.inflight.set(key, promise);
122
+ return promise;
123
+ }
124
+ async build(name, source) {
125
+ const dir = this.pluginDir(name);
126
+ await fs.mkdir(dir, { recursive: true });
127
+ const jsPath = source.js;
128
+ const cssPath = source.css;
129
+ const action = isComponentSource(source) ? source.js ? detectAction(source.js) : void 0 : source.action ?? detectAction(source.js);
130
+ if (!jsPath || !action) return this.toEntry(name, false, void 0, source.props);
131
+ console.log(`[SSR] Plugin "${name}" building (${action}: ${jsPath})…`);
132
+ try {
133
+ let cssUrl;
134
+ if (action === "compile") {
135
+ const { hasCSS } = await compilePlugin(jsPath, dir, this.devMode);
136
+ if (hasCSS) cssUrl = `${this.urlPrefix}/${name}/index.css`;
137
+ else if (cssPath) if (this.isWebUrl(cssPath)) cssUrl = cssPath;
138
+ else {
139
+ await copyPlugin(cssPath, dir, "index.css");
140
+ cssUrl = `${this.urlPrefix}/${name}/index.css`;
141
+ }
142
+ } else if (action === "download") {
143
+ const jsRes = await fetch(jsPath);
144
+ if (!jsRes.ok) throw new Error(`HTTP ${jsRes.status} downloading ${jsPath}`);
145
+ await fs.writeFile(path.join(dir, "index.js"), await jsRes.text());
146
+ if (cssPath) {
147
+ if (cssPath.startsWith("http://") || cssPath.startsWith("https://")) {
148
+ const cssRes = await fetch(cssPath);
149
+ if (!cssRes.ok) throw new Error(`HTTP ${cssRes.status} downloading ${cssPath}`);
150
+ await fs.writeFile(path.join(dir, "index.css"), await cssRes.text());
151
+ } else if (this.isWebUrl(cssPath)) cssUrl = cssPath;
152
+ else await copyPlugin(cssPath, dir, "index.css");
153
+ cssUrl = `${this.urlPrefix}/${name}/index.css`;
154
+ }
155
+ } else {
156
+ await copyPlugin(jsPath, dir, "index.js");
157
+ if (cssPath) if (this.isWebUrl(cssPath)) cssUrl = cssPath;
158
+ else {
159
+ await copyPlugin(cssPath, dir, "index.css");
160
+ cssUrl = `${this.urlPrefix}/${name}/index.css`;
161
+ }
162
+ }
163
+ const compiledAt = Date.now();
164
+ await this.writeMeta(name, {
165
+ compiledAt,
166
+ version: source.version
167
+ });
168
+ const entry = this.toEntry(name, true, cssUrl, source.props);
169
+ this.mem.set(name, {
170
+ compiledAt,
171
+ entry
172
+ });
173
+ console.log(`[SSR] Plugin "${name}" ready → ${entry.js}`);
174
+ return entry;
175
+ } catch (err) {
176
+ console.error(`[SSR] Plugin "${name}" build failed (js: ${source.js ?? "none"}):`, err);
177
+ this.failed.add(name);
178
+ return null;
179
+ }
180
+ }
181
+ async getEntries(names) {
182
+ if (names.length === 0) return [];
183
+ return (await Promise.all(names.map((n) => this.prepare(n)))).filter((e) => e !== null && e.js !== void 0);
184
+ }
185
+ getComponents() {
186
+ const out = {};
187
+ for (const [name, source] of Object.entries(this.plugins)) if (isComponentSource(source)) out[name.replace(/@[^@]*$/, "")] = source.component;
188
+ return out;
189
+ }
190
+ async invalidate(name, version) {
191
+ if (!name) {
192
+ this.mem.clear();
193
+ this.failed.clear();
194
+ this.nameIndex.clear();
195
+ await fs.rm(this.outputDir, {
196
+ recursive: true,
197
+ force: true
198
+ });
199
+ return;
200
+ }
201
+ if (version) {
202
+ const key = `${name}@${version}`;
203
+ this.mem.delete(key);
204
+ this.failed.delete(key);
205
+ if (this.nameIndex.get(name) === key) this.nameIndex.delete(name);
206
+ await fs.rm(this.pluginDir(key), {
207
+ recursive: true,
208
+ force: true
209
+ });
210
+ return;
211
+ }
212
+ const prefix = `${name}@`;
213
+ const keysToEvict = /* @__PURE__ */ new Set();
214
+ keysToEvict.add(name);
215
+ for (const key of Object.keys(this.plugins)) if (key.startsWith(prefix)) keysToEvict.add(key);
216
+ for (const key of this.mem.keys()) if (key.startsWith(prefix)) keysToEvict.add(key);
217
+ for (const key of keysToEvict) {
218
+ this.mem.delete(key);
219
+ this.failed.delete(key);
220
+ }
221
+ this.nameIndex.delete(name);
222
+ try {
223
+ const entries = await fs.readdir(this.outputDir);
224
+ await Promise.all(entries.filter((e) => e === name || e.startsWith(prefix)).map((e) => fs.rm(path.join(this.outputDir, e), {
225
+ recursive: true,
226
+ force: true
227
+ })));
228
+ } catch {}
229
+ }
230
+ destroy() {
231
+ this.mem.clear();
232
+ this.failed.clear();
233
+ this.nameIndex.clear();
234
+ }
235
+ async readMeta(name) {
236
+ try {
237
+ const raw = await fs.readFile(path.join(this.pluginDir(name), META_FILE), "utf-8");
238
+ return JSON.parse(raw);
239
+ } catch {
240
+ return null;
241
+ }
242
+ }
243
+ async writeMeta(name, meta) {
244
+ await fs.writeFile(path.join(this.pluginDir(name), META_FILE), JSON.stringify(meta), "utf-8");
245
+ }
246
+ async fileExists(p) {
247
+ return fs.access(p).then(() => true).catch(() => false);
248
+ }
249
+ };
250
+ //#endregion
251
+ export { PluginManager };
File without changes
@@ -0,0 +1 @@
1
+ export {}
package/dist/server.js ADDED
@@ -0,0 +1,82 @@
1
+ import { createSSRServer } from "./core/createServer.js";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { readFileSync } from "node:fs";
5
+ //#region src/standalone/server.ts
6
+ var PORT = parseInt(process.env.SSR_PORT ?? "3002", 10);
7
+ var HOST = process.env.SSR_HOST ?? "0.0.0.0";
8
+ var getOfflineData = () => {
9
+ const fileSchema = JSON.parse(readFileSync(path.resolve(__dirname, "schemas/basic", "space.json"), "utf-8"));
10
+ const style = JSON.parse(readFileSync(path.resolve(__dirname, "schemas/basic", "style.json"), "utf-8"));
11
+ const offlineData = {
12
+ schema: fileSchema.schema,
13
+ style
14
+ };
15
+ console.warn("[SSR] getOfflineData: using stub adapter — returning spaceId=1");
16
+ return Promise.resolve(offlineData);
17
+ };
18
+ var getSpaceDeployment = () => {
19
+ console.warn("[SSR] getSpaceDeployment: using stub adapter — returning spaceId=1");
20
+ return Promise.resolve({
21
+ spaceId: 1,
22
+ environment: "main",
23
+ revision: 0,
24
+ pluginNames: [
25
+ "serverInfo",
26
+ "clientInfo",
27
+ "sharedInfo"
28
+ ]
29
+ });
30
+ };
31
+ var getRscData = async (_req, _spaceId, _environment, _revision, user, ids) => {
32
+ const all = {
33
+ "rsc-server": {
34
+ message: "Hello from the Node.js SSR server!",
35
+ renderedAt: (/* @__PURE__ */ new Date()).toISOString(),
36
+ nodeVersion: process.version,
37
+ uptime: Math.round(process.uptime()),
38
+ authenticated: !!user,
39
+ userId: user?.id ?? null
40
+ },
41
+ "rsc-shared": {
42
+ serverTimestamp: (/* @__PURE__ */ new Date()).toISOString(),
43
+ nodeVersion: process.version
44
+ }
45
+ };
46
+ return { serverData: ids?.length ? Object.fromEntries(ids.filter((id) => id in all).map((id) => [id, all[id]])) : all };
47
+ };
48
+ var adapters = {
49
+ getOfflineData,
50
+ getSpaceDeployment,
51
+ getRscData
52
+ };
53
+ var __filename = fileURLToPath(import.meta.url);
54
+ var __dirname = path.dirname(__filename);
55
+ createSSRServer({
56
+ port: PORT,
57
+ host: HOST,
58
+ frameOptions: "SAMEORIGIN",
59
+ devMode: false,
60
+ static: { "/sdk-assets": path.resolve(process.cwd(), "../sdk/dist") },
61
+ httpVersion: 1,
62
+ plugins: {
63
+ serverInfo: {
64
+ js: path.resolve(__dirname, "plugins/ServerInfo.tsx"),
65
+ action: "compile",
66
+ props: { var1: "value1" }
67
+ },
68
+ clientInfo: {
69
+ js: path.resolve(__dirname, "plugins/ClientInfo.tsx"),
70
+ action: "compile",
71
+ props: { var2: "value2" }
72
+ },
73
+ sharedInfo: {
74
+ js: path.resolve(__dirname, "plugins/SharedInfo.tsx"),
75
+ action: "compile",
76
+ props: { var3: "value3" }
77
+ }
78
+ },
79
+ adapters
80
+ }).listen(PORT, HOST);
81
+ //#endregion
82
+ export {};
@@ -0,0 +1,7 @@
1
+ import { SSRAdapters, SSRRequest, SSRSpaceDeployment, SSRUser } from '@plitzi/sdk-shared';
2
+ export type JsonAdaptersConfig = {
3
+ offlineData: string | ((spaceId: number, environment: string, revision?: number) => string);
4
+ deployment?: string | SSRSpaceDeployment | Record<string, SSRSpaceDeployment>;
5
+ user?: SSRUser | ((req: SSRRequest) => SSRUser | undefined | Promise<SSRUser | undefined>);
6
+ };
7
+ export declare const createJsonAdapters: (config: JsonAdaptersConfig) => SSRAdapters;
@@ -0,0 +1,2 @@
1
+ import { SSRServer, SSRServerConfig } from '@plitzi/sdk-shared';
2
+ export declare const createSSRServer: (config: SSRServerConfig) => SSRServer;
@@ -0,0 +1,4 @@
1
+ export declare const MIME_TYPES: Record<string, string>;
2
+ export declare const IMMUTABLE_EXTS: Set<string>;
3
+ export declare const getMimeType: (filePath: string) => string;
4
+ export declare const getCacheControl: (filePath: string) => string;
@@ -0,0 +1,5 @@
1
+ import { Handler } from './transports';
2
+ import { ServerCaches } from '../helpers/cache';
3
+ import { PluginManager } from '../plugins/manager';
4
+ import { SSRServerConfig, SSRTemplateFn } from '@plitzi/sdk-shared';
5
+ export declare const makeHandler: (config: SSRServerConfig, port: number, renderFn: SSRTemplateFn, caches: ServerCaches, pluginManager: PluginManager) => Handler;
@@ -0,0 +1,3 @@
1
+ import { SSRRequest } from '@plitzi/sdk-shared';
2
+ import { IncomingMessage } from 'node:http';
3
+ export declare const parseRequest: (raw: IncomingMessage) => SSRRequest;
@@ -0,0 +1,2 @@
1
+ import { SSRRequest, SSRResponseHelpers } from '@plitzi/sdk-shared';
2
+ export declare const serveStatic: (req: SSRRequest, res: SSRResponseHelpers, rootDir: string) => boolean;
@@ -0,0 +1,18 @@
1
+ import { RawResponse } from '../helpers/buildResponseHelpers';
2
+ import { SSRServerConfig } from '@plitzi/sdk-shared';
3
+ import { IncomingMessage } from 'node:http';
4
+ export type CloseableServer = {
5
+ close: (cb?: (err?: Error) => void) => unknown;
6
+ listen: (port: number, host: string, cb: () => void) => unknown;
7
+ };
8
+ export type Handler = (req: IncomingMessage, res: RawResponse) => void;
9
+ export declare const tlsOptions: (config: SSRServerConfig) => {
10
+ key: string | Buffer<ArrayBufferLike>;
11
+ cert: string | Buffer<ArrayBufferLike>;
12
+ minVersion: "TLSv1.3";
13
+ };
14
+ export declare const protoLabel: (version: number, hasTls: boolean) => string;
15
+ export declare const buildTransport: (config: SSRServerConfig, handler: Handler, port: number) => {
16
+ primary: CloseableServer;
17
+ h3?: CloseableServer;
18
+ };
@@ -0,0 +1,10 @@
1
+ import { SSRResponseHelpers } from '@plitzi/sdk-shared';
2
+ export type RawResponse = {
3
+ headersSent: boolean;
4
+ setHeader(name: string, value: string | number | readonly string[]): unknown;
5
+ getHeaders(): Record<string, string | number | readonly string[]>;
6
+ writeHead(statusCode: number, headers?: Record<string, string | number | readonly string[]>): unknown;
7
+ write(chunk: string | Buffer): unknown;
8
+ end(chunk?: string | Buffer): unknown;
9
+ };
10
+ export declare const buildResponseHelpers: (raw: RawResponse, acceptEncoding?: string) => SSRResponseHelpers;
@@ -0,0 +1,2 @@
1
+ import { Server, SSRRequest, SSRServerConfig } from '@plitzi/sdk-shared';
2
+ export declare const buildServerInfo: (req: SSRRequest, config: SSRServerConfig) => Promise<Partial<Server>>;
@@ -0,0 +1,15 @@
1
+ export declare class TtlCache<T> {
2
+ private readonly ttlMs;
3
+ private readonly maxSize;
4
+ private readonly store;
5
+ private sweepTimer;
6
+ constructor(ttlMs?: number, maxSize?: number, sweepIntervalMs?: number);
7
+ get(key: string): T | undefined;
8
+ set(key: string, value: T): void;
9
+ delete(key: string): void;
10
+ invalidateWhere(predicate: (key: string) => boolean): number;
11
+ clear(): void;
12
+ destroy(): void;
13
+ get size(): number;
14
+ private sweep;
15
+ }
@@ -0,0 +1,3 @@
1
+ import { TtlCache } from './TtlCache';
2
+ import { CacheManager } from '@plitzi/sdk-shared';
3
+ export declare const buildCacheManager: (store: TtlCache<string>) => CacheManager;
@@ -0,0 +1 @@
1
+ export declare const DEFAULT_TTL_MS: Record<string, number>;
@@ -0,0 +1,6 @@
1
+ export { DEFAULT_TTL_MS } from './defaults';
2
+ export { TtlCache } from './TtlCache';
3
+ export { buildHtmlCacheKey, buildOfflineDataCacheKey, buildRscCacheKey } from './keys';
4
+ export { buildCacheManager } from './cacheManager';
5
+ export type { ServerCaches } from './serverCaches';
6
+ export { createServerCaches, destroyServerCaches } from './serverCaches';
@@ -0,0 +1,7 @@
1
+ export declare const buildHtmlCacheKey: (accessToken: string | undefined, spaceId: number | string | null, environment: string, revision: number, req: {
2
+ hostname: string;
3
+ path: string;
4
+ search: string;
5
+ }) => string;
6
+ export declare const buildOfflineDataCacheKey: (spaceId: number, environment: string, revision: number) => string;
7
+ export declare const buildRscCacheKey: (spaceId: number, environment: string, revision: number, userId: string | number | undefined, idsParam: string | undefined) => string;
@@ -0,0 +1,9 @@
1
+ import { TtlCache } from './TtlCache';
2
+ export type ServerCaches = {
3
+ html: TtlCache<string> | undefined;
4
+ rsc: TtlCache<string> | undefined;
5
+ /** JSON-serialized OfflineDataRaw — keyed by spaceId|env|revision, same TTL as html. */
6
+ offlineData: TtlCache<string> | undefined;
7
+ };
8
+ export declare const createServerCaches: (htmlTtlMs?: number, rscTtlMs?: number) => ServerCaches;
9
+ export declare const destroyServerCaches: ({ html, rsc, offlineData }: ServerCaches) => void;
@@ -0,0 +1,3 @@
1
+ export type ContentEncoding = 'br' | 'gzip' | 'identity';
2
+ export declare const selectEncoding: (acceptEncoding: string | undefined) => ContentEncoding;
3
+ export declare const compressBody: (body: string, encoding: ContentEncoding) => Buffer | string;
@@ -0,0 +1 @@
1
+ export declare const escapeJson: (str: string) => string;
@@ -0,0 +1,11 @@
1
+ export declare class RequestMetrics {
2
+ private readonly start;
3
+ private readonly phases;
4
+ constructor();
5
+ measure<T>(name: string, fn: () => T | Promise<T>): Promise<T>;
6
+ /** Formats as Server-Timing header value. */
7
+ toServerTimingHeader(): string;
8
+ record(name: string, dur: number): void;
9
+ /** Logs a one-line summary to stdout (dev mode only). */
10
+ log(label: string): void;
11
+ }
@@ -0,0 +1,4 @@
1
+ import { PluginSource } from '@plitzi/sdk-shared';
2
+ export declare const normalizePluginSource: (source: PluginSource) => PluginSource;
3
+ declare const normalizePlugins: (plugins: Record<string, PluginSource>) => Record<string, PluginSource>;
4
+ export default normalizePlugins;
@@ -0,0 +1,2 @@
1
+ import { SSRMiddleware, SSRRequest, SSRResponseHelpers, SSRContext } from '@plitzi/sdk-shared';
2
+ export declare const runMiddlewares: (middlewares: SSRMiddleware[], req: SSRRequest & Partial<SSRContext>, res: SSRResponseHelpers) => Promise<boolean>;
@@ -0,0 +1,4 @@
1
+ export { createSSRServer } from './core/createServer';
2
+ export { createJsonAdapters } from './adapters/jsonAdapters';
3
+ export type { JsonAdaptersConfig } from './adapters/jsonAdapters';
4
+ export type { SSRAdapters, SSRServerConfig, SSRRequest, SSRResponseHelpers, SSRMiddleware, SSRMiddlewareNext, SSRContext, SSRSpaceDeployment, SSRTemplateProps, SSRTemplateFn, SSRCredential, SSRUser, SSRHeaders, SSRRscData, SSRRscConfig, SSRServer, PluginSource, PluginSourceFile, PluginSourceComponent, PluginAction, PluginEntry, PluginRegistry, CacheFilter, CacheManager, McpAdapters, McpElement, McpPlugin, McpSchema, McpServerConfig, McpSpace } from '@plitzi/sdk-shared';
@@ -0,0 +1,2 @@
1
+ import { SSRAdapters, SSRMiddleware } from '@plitzi/sdk-shared';
2
+ export declare const authMiddleware: (adapters: SSRAdapters) => SSRMiddleware;
@@ -0,0 +1,6 @@
1
+ import { SSRMiddleware } from '@plitzi/sdk-shared';
2
+ export type BasicAuthOptions = {
3
+ realm?: string;
4
+ cacheTtlMs?: number;
5
+ };
6
+ export declare const basicAuthMiddleware: (options?: BasicAuthOptions) => SSRMiddleware;
@@ -0,0 +1,2 @@
1
+ import { SSRAdapters, SSRMiddleware } from '@plitzi/sdk-shared';
2
+ export declare const spaceDeploymentMiddleware: (adapters: SSRAdapters) => SSRMiddleware;
@@ -0,0 +1,3 @@
1
+ import { McpServerConfig } from '@plitzi/sdk-shared';
2
+ import { IncomingMessage, ServerResponse } from 'node:http';
3
+ export declare const handleMcp: (req: IncomingMessage, res: ServerResponse, config: McpServerConfig) => Promise<void>;
@@ -0,0 +1,3 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { McpAdapters } from '@plitzi/sdk-shared';
3
+ export declare const createMcpServer: (adapters: McpAdapters) => McpServer;