noofpi 2.0.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +6 -2
  2. package/client.d.ts +2 -0
  3. package/dist/build-W5VMPOTQ.js +212 -0
  4. package/dist/chunk-A7XQWIA6.js +562 -0
  5. package/dist/chunk-GOJZ36X5.js +217 -0
  6. package/dist/{chunk-YJVMBHNL.js → chunk-JUVQEKLE.js} +43 -12
  7. package/dist/chunk-LJEKK4AK.js +51 -0
  8. package/dist/{chunk-G35DW4NA.js → chunk-PC3ZJN4D.js} +11 -1
  9. package/dist/{chunk-NHBXVKEQ.js → chunk-ROMSHDCI.js} +160 -86
  10. package/dist/{chunk-IE3WF5XF.js → chunk-SUECMRBX.js} +87 -4
  11. package/dist/{chunk-MN5PVHC5.js → chunk-W7ASRDAJ.js} +229 -7
  12. package/dist/cli.js +21 -9
  13. package/dist/{dev-OAGCOGHA.js → dev-2DM7VOYX.js} +7 -6
  14. package/dist/{devtools-PLUN2DYV.js → devtools-C3PFU57C.js} +1 -1
  15. package/dist/handler-BpyI3a5D.d.ts +26 -0
  16. package/dist/index.d.ts +26 -11
  17. package/dist/index.js +3 -2
  18. package/dist/payload-Cgul9YUP.d.ts +66 -0
  19. package/dist/{prepare-BN7NMCVQ.js → prepare-APN2E6PX.js} +6 -5
  20. package/dist/runtime/entry-client.js +4 -4
  21. package/dist/runtime/entry-server.d.ts +6 -4
  22. package/dist/runtime/entry-server.js +88 -25
  23. package/dist/runtime/index.d.ts +24 -6
  24. package/dist/runtime/index.js +5 -3
  25. package/dist/server/bun.d.ts +3 -3
  26. package/dist/server/index.d.ts +35 -7
  27. package/dist/server/index.js +12 -7
  28. package/dist/server/node.d.ts +3 -3
  29. package/dist/session-CAP_PIlN.d.ts +272 -0
  30. package/dist/{start-ITRND3BY.js → start-PXOLWPL4.js} +7 -6
  31. package/dist/{types-B6rQOOxS.d.ts → types-B7xDyUbg.d.ts} +30 -5
  32. package/package.json +6 -1
  33. package/dist/build-WPHZ7TYZ.js +0 -49
  34. package/dist/chunk-MTXQR32N.js +0 -8
  35. package/dist/chunk-X3DYEZLK.js +0 -253
  36. package/dist/handler-C6NnwBfC.d.ts +0 -17
  37. package/dist/payload-CL6tYBin.d.ts +0 -121
  38. package/dist/route-rules-COilNsVT.d.ts +0 -127
@@ -1,6 +1,119 @@
1
1
  // src/fetch-mode.ts
2
2
  var FETCH_MODES = ["dfetch", "pfetch", "lfetch", "sfetch"];
3
3
 
4
+ // src/http.ts
5
+ var HEADER_NAME = /^[A-Za-z0-9-]+$/;
6
+ var FORBIDDEN_HEADER_VALUE = /[\u0000-\u001f\u007f]/;
7
+ var isHeaderName = (name) => HEADER_NAME.test(name);
8
+ var isHeaderValue = (value) => typeof value === "string" && !FORBIDDEN_HEADER_VALUE.test(value);
9
+ function modifyHeaders(response, change) {
10
+ try {
11
+ change(response.headers);
12
+ return response;
13
+ } catch {
14
+ const headers = new Headers(response.headers);
15
+ change(headers);
16
+ return new Response(response.body, {
17
+ status: response.status,
18
+ statusText: response.statusText,
19
+ headers
20
+ });
21
+ }
22
+ }
23
+ function appendVary(headers, value) {
24
+ const current = headers.get("vary");
25
+ if (current === "*") return;
26
+ const listed = (current ?? "").split(",").map((item) => item.trim().toLowerCase());
27
+ if (listed.includes(value.toLowerCase())) return;
28
+ headers.set("vary", current ? `${current}, ${value}` : value);
29
+ }
30
+
31
+ // src/cors.ts
32
+ var DEFAULT_METHODS = ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"];
33
+ var DEFAULT_MAX_AGE = 86400;
34
+ var METHOD = /^[A-Za-z]+$/;
35
+ var optionError = (option, expected) => new Error(`cors.${option} must be ${expected}`);
36
+ function originList(origin) {
37
+ if (origin === void 0 || origin === "*") return "*";
38
+ const list = typeof origin === "string" ? [origin] : origin;
39
+ if (!Array.isArray(list))
40
+ throw optionError("origin", '"*" or a list of origins');
41
+ return list.map((entry) => {
42
+ if (entry === "*") return "*";
43
+ try {
44
+ const parsed = new URL(entry);
45
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
46
+ throw new Error();
47
+ return parsed.origin;
48
+ } catch {
49
+ throw optionError("origin", `absolute http(s) origins (got "${entry}")`);
50
+ }
51
+ });
52
+ }
53
+ var stringList = (value, option, valid) => {
54
+ if (value === void 0) return void 0;
55
+ if (!Array.isArray(value) || value.some((item) => typeof item !== "string" || !valid(item)))
56
+ throw optionError(option, "a list of valid names");
57
+ return value;
58
+ };
59
+ function validateCors(options) {
60
+ if (typeof options === "boolean") return;
61
+ if (typeof options !== "object" || options === null)
62
+ throw new Error("cors must be a boolean or an object");
63
+ originList(options.origin);
64
+ stringList(options.methods, "methods", (item) => METHOD.test(item));
65
+ stringList(options.allowHeaders, "allowHeaders", isHeaderName);
66
+ stringList(options.exposeHeaders, "exposeHeaders", isHeaderName);
67
+ if (options.credentials !== void 0 && typeof options.credentials !== "boolean")
68
+ throw optionError("credentials", "a boolean");
69
+ if (options.maxAge !== void 0 && (!Number.isInteger(options.maxAge) || options.maxAge < 0))
70
+ throw optionError("maxAge", "a non-negative number of seconds");
71
+ }
72
+ function isPreflight(request) {
73
+ return request.method === "OPTIONS" && request.headers.has("origin") && request.headers.has("access-control-request-method");
74
+ }
75
+ function corsHeaders(options, request, preflight = false) {
76
+ const result = new Headers();
77
+ if (options === false) return result;
78
+ const config = options === true ? {} : options;
79
+ const requestOrigin = request.headers.get("origin");
80
+ if (requestOrigin === null) return result;
81
+ const allowed = originList(config.origin);
82
+ const credentials = config.credentials === true;
83
+ const wildcard = allowed === "*" || allowed.includes("*");
84
+ if (!wildcard && !allowed.includes(requestOrigin)) {
85
+ appendVary(result, "Origin");
86
+ return result;
87
+ }
88
+ if (wildcard && !credentials) result.set("Access-Control-Allow-Origin", "*");
89
+ else {
90
+ result.set("Access-Control-Allow-Origin", requestOrigin);
91
+ appendVary(result, "Origin");
92
+ }
93
+ if (credentials) result.set("Access-Control-Allow-Credentials", "true");
94
+ if (config.exposeHeaders?.length)
95
+ result.set(
96
+ "Access-Control-Expose-Headers",
97
+ config.exposeHeaders.join(", ")
98
+ );
99
+ if (preflight) {
100
+ result.set(
101
+ "Access-Control-Allow-Methods",
102
+ (config.methods ?? DEFAULT_METHODS).join(", ")
103
+ );
104
+ const requested = request.headers.get("access-control-request-headers");
105
+ const headers = config.allowHeaders?.join(", ") ?? requested;
106
+ if (headers) result.set("Access-Control-Allow-Headers", headers);
107
+ if (!config.allowHeaders)
108
+ appendVary(result, "Access-Control-Request-Headers");
109
+ result.set(
110
+ "Access-Control-Max-Age",
111
+ String(config.maxAge ?? DEFAULT_MAX_AGE)
112
+ );
113
+ }
114
+ return result;
115
+ }
116
+
4
117
  // src/csp.ts
5
118
  var NONCE_TOKEN = "'nonce'";
6
119
  var DIRECTIVE_NAME = /^[a-z][a-z0-9-]*$/;
@@ -85,18 +198,18 @@ var DEFAULT_HEADERS = {
85
198
  "Permissions-Policy": "camera=(), microphone=(), geolocation=()",
86
199
  [HSTS]: "max-age=15552000"
87
200
  };
88
- var HEADER_NAME = /^[A-Za-z0-9-]+$/;
89
- var FORBIDDEN_HEADER_VALUE = /[\u0000-\u001f\u007f]/;
201
+ var HEADER_NAME2 = /^[A-Za-z0-9-]+$/;
202
+ var FORBIDDEN_HEADER_VALUE2 = /[\u0000-\u001f\u007f]/;
90
203
  function overlayHeaders(base, input) {
91
204
  if (input === false) return {};
92
205
  const merged = { ...base };
93
206
  if (input && typeof input === "object") {
94
207
  for (const [name, value] of Object.entries(input)) {
95
- if (!HEADER_NAME.test(name))
208
+ if (!HEADER_NAME2.test(name))
96
209
  throw new Error(
97
210
  `[noofpi] security.headers: "${name}" is not a valid header name`
98
211
  );
99
- if (value !== false && (typeof value !== "string" || FORBIDDEN_HEADER_VALUE.test(value)))
212
+ if (value !== false && (typeof value !== "string" || FORBIDDEN_HEADER_VALUE2.test(value)))
100
213
  throw new Error(
101
214
  `[noofpi] security.headers: "${name}" must be a string without control characters, or false`
102
215
  );
@@ -260,6 +373,7 @@ function applySecurityHeaders(response, headers, https) {
260
373
  }
261
374
 
262
375
  // src/route-rules.ts
376
+ var REDIRECT_STATUSES = [301, 302, 303, 307, 308];
263
377
  function patternToRegExp(pattern) {
264
378
  const source = pattern.split("/").map(
265
379
  (segment) => segment === "**" ? ".*" : segment.split("*").map((part) => part.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join("[^/]*")
@@ -306,22 +420,124 @@ function validateRouteRules(rules, ssr) {
306
420
  );
307
421
  }
308
422
  }
423
+ validateServerRule(pattern, rule, ssr);
309
424
  }
310
425
  }
426
+ var fail = (pattern, message) => {
427
+ throw new Error(`[noofpi] routeRules["${pattern}"].${message}`);
428
+ };
429
+ var isCount = (value) => Number.isInteger(value) && value >= 0;
430
+ var isRedirectTarget = (to) => {
431
+ if (typeof to !== "string") return false;
432
+ if (to.startsWith("/")) return !to.startsWith("//") && !/[\s\\]/.test(to);
433
+ try {
434
+ const { protocol } = new URL(to);
435
+ return protocol === "http:" || protocol === "https:";
436
+ } catch {
437
+ return false;
438
+ }
439
+ };
440
+ function validateServerRule(pattern, rule, ssr) {
441
+ const rendered = ssr && rule.ssr !== false;
442
+ for (const option of ["prerender", "stream"]) {
443
+ const value = rule[option];
444
+ if (value === void 0) continue;
445
+ if (typeof value !== "boolean")
446
+ fail(pattern, `${option} must be a boolean`);
447
+ if (value && !rendered)
448
+ fail(
449
+ pattern,
450
+ `${option}: true needs server rendering (ssr: true, and no ssr: false on the route)`
451
+ );
452
+ }
453
+ const { cache } = rule;
454
+ if (cache !== void 0 && cache !== false) {
455
+ if (typeof cache !== "object" || cache === null)
456
+ fail(pattern, "cache must be an object or false");
457
+ if (!isCount(cache.maxAge))
458
+ fail(pattern, "cache.maxAge must be a number of seconds (0 or more)");
459
+ if (cache.swr !== void 0 && !isCount(cache.swr))
460
+ fail(pattern, "cache.swr must be a number of seconds (0 or more)");
461
+ if (cache.vary !== void 0 && (!Array.isArray(cache.vary) || !cache.vary.every(isVaryHeader)))
462
+ fail(pattern, "cache.vary must be a list of header names");
463
+ if (cache.server !== void 0 && typeof cache.server !== "boolean")
464
+ fail(pattern, "cache.server must be a boolean");
465
+ if (!rendered)
466
+ fail(pattern, "cache only applies to server-rendered pages (needs ssr)");
467
+ }
468
+ if (rule.headers !== void 0) {
469
+ if (typeof rule.headers !== "object" || rule.headers === null)
470
+ fail(pattern, "headers must be an object");
471
+ for (const [name, value] of Object.entries(rule.headers)) {
472
+ if (!isHeaderName(name))
473
+ fail(pattern, `headers: "${name}" is not a valid header name`);
474
+ if (!isHeaderValue(value))
475
+ fail(
476
+ pattern,
477
+ `headers: "${name}" must be a string without control characters`
478
+ );
479
+ }
480
+ }
481
+ if (rule.redirect !== void 0) {
482
+ const { to, status } = normalizeRedirect(rule.redirect);
483
+ if (!isRedirectTarget(to))
484
+ fail(
485
+ pattern,
486
+ `redirect must be a path starting with "/" or an absolute http(s) URL (got "${String(to)}")`
487
+ );
488
+ if (!REDIRECT_STATUSES.includes(status))
489
+ fail(
490
+ pattern,
491
+ `redirect.status must be one of ${REDIRECT_STATUSES.join(", ")} (got ${String(status)})`
492
+ );
493
+ if (to.endsWith("/**") && !/^[^*]*\/\*\*$/.test(pattern))
494
+ fail(
495
+ pattern,
496
+ `redirect to "${to}" keeps the rest of the path, so the pattern has to end with "/**" and have no other "*"`
497
+ );
498
+ }
499
+ if (rule.cors !== void 0) {
500
+ try {
501
+ validateCors(rule.cors);
502
+ } catch (error) {
503
+ fail(pattern, error.message);
504
+ }
505
+ }
506
+ }
507
+ var isVaryHeader = (name) => typeof name === "string" && isHeaderName(name);
508
+ function normalizeRedirect(redirect) {
509
+ return typeof redirect === "string" ? { to: redirect, status: 307 } : { to: redirect?.to, status: redirect?.status ?? 307 };
510
+ }
311
511
  function matchRouteRules(rules, pathname) {
312
512
  const merged = {};
313
513
  Object.keys(rules).filter((pattern) => patternToRegExp(pattern).test(pathname)).sort((a, b) => a.length - b.length).forEach((pattern) => {
314
- const { security, ...rest } = rules[pattern];
514
+ const { security, headers, cors, ...rest } = rules[pattern];
315
515
  Object.assign(merged, rest);
316
516
  if (security) merged.security = { ...merged.security, ...security };
517
+ if (headers) merged.headers = { ...merged.headers, ...headers };
518
+ if (cors !== void 0)
519
+ merged.cors = typeof cors === "object" && typeof merged.cors === "object" ? { ...merged.cors, ...cors } : cors;
317
520
  });
318
521
  return merged;
319
522
  }
523
+ function matchRedirect(rules, pathname) {
524
+ const pattern = Object.keys(rules).filter(
525
+ (candidate) => rules[candidate].redirect !== void 0 && patternToRegExp(candidate).test(pathname)
526
+ ).sort((a, b) => b.length - a.length)[0];
527
+ if (pattern === void 0) return void 0;
528
+ const { to, status } = normalizeRedirect(rules[pattern].redirect);
529
+ if (!to.endsWith("/**")) return { to, status };
530
+ const rest = pathname.slice(pattern.length - "/**".length);
531
+ return { to: to.slice(0, -3) + rest, status };
532
+ }
320
533
  function toPublicRouteRules(rules) {
321
534
  return Object.fromEntries(
322
- Object.entries(rules).map(([pattern, { security: _security, ...rule }]) => [
535
+ Object.entries(rules).map(([pattern, { ssr, fetch }]) => [
323
536
  pattern,
324
- rule
537
+ {
538
+ ...ssr !== void 0 ? { ssr } : {},
539
+ ...fetch !== void 0 ? { fetch } : {}
540
+ }
325
541
  ])
326
542
  );
327
543
  }
@@ -337,6 +553,10 @@ function isServerRendered(ssr, rules, pathname) {
337
553
 
338
554
  export {
339
555
  FETCH_MODES,
556
+ modifyHeaders,
557
+ appendVary,
558
+ isPreflight,
559
+ corsHeaders,
340
560
  usesNonce,
341
561
  generateNonce,
342
562
  buildCspHeader,
@@ -347,9 +567,11 @@ export {
347
567
  limitRequestBody,
348
568
  isCrossSiteWrite,
349
569
  applySecurityHeaders,
570
+ REDIRECT_STATUSES,
350
571
  matchesRoutePattern,
351
572
  validateRouteRules,
352
573
  matchRouteRules,
574
+ matchRedirect,
353
575
  toPublicRouteRules,
354
576
  resolveFetchMode,
355
577
  usesFetchMode,
package/dist/cli.js CHANGED
@@ -4,10 +4,12 @@ import {
4
4
  import {
5
5
  BUILD_PRESETS,
6
6
  assertBuildPreset,
7
+ generatePreset,
7
8
  resolveConfig
8
- } from "./chunk-IE3WF5XF.js";
9
+ } from "./chunk-SUECMRBX.js";
10
+ import "./chunk-GOJZ36X5.js";
9
11
  import "./chunk-ELXCFUA4.js";
10
- import "./chunk-MN5PVHC5.js";
12
+ import "./chunk-W7ASRDAJ.js";
11
13
 
12
14
  // src/cli.ts
13
15
  import path2 from "path";
@@ -17,6 +19,7 @@ import { parseArgs } from "util";
17
19
  var COMMANDS = [
18
20
  "dev",
19
21
  "build",
22
+ "generate",
20
23
  "start",
21
24
  "preview",
22
25
  "prepare",
@@ -109,6 +112,7 @@ var USAGE = `noofpi <command> [options]
109
112
  Commands:
110
113
  dev Start the dev server with live reload
111
114
  build Build for production into .output/
115
+ generate Prerender the pages into static HTML files in .output/public (github-pages | cloudflare-pages)
112
116
  start Run the production build
113
117
  preview Build, then run the production build
114
118
  prepare Generate the .noofpi/ type declarations (for a postinstall script)
@@ -120,10 +124,11 @@ Options:
120
124
  --host <host> Server host (dev, start, preview)
121
125
  --open Open the browser once the server is ready (dev, start, preview)
122
126
  --preset <name> Build target: ${BUILD_PRESETS.join(" | ")} (default: build.preset or node)
123
- preview needs a preset that \`noofpi start\` can run: node | bun | docker
127
+ preview needs a preset that \`noofpi start\` can run: node | bun | docker-node | docker-bun
128
+ generate needs a static one: github-pages | cloudflare-pages (default: build.preset when static, else github-pages)
124
129
  -h, --help Show this help
125
130
  -v, --version Show the noofpi version`;
126
- var PREVIEW_PRESETS = ["node", "bun", "docker"];
131
+ var PREVIEW_PRESETS = ["node", "bun", "docker-node", "docker-bun"];
127
132
  async function loadEnvFiles(root, mode) {
128
133
  const { loadEnv } = await import("vite");
129
134
  const env = loadEnv(mode, root, "");
@@ -150,7 +155,7 @@ async function main() {
150
155
  await loadEnvFiles(root, mode);
151
156
  const config = await loadConfig(root);
152
157
  if (command === "dev") {
153
- const { startDev } = await import("./dev-OAGCOGHA.js");
158
+ const { startDev } = await import("./dev-2DM7VOYX.js");
154
159
  await startDev(root, config, overrides);
155
160
  } else if (command === "build" || command === "preview") {
156
161
  const preset = args.preset ? assertBuildPreset(args.preset, "--preset") : void 0;
@@ -161,17 +166,24 @@ async function main() {
161
166
  `[noofpi] preview can not run the "${target}" preset (use ${PREVIEW_PRESETS.join(" | ")}, or build it and serve .output/ with its own tooling)`
162
167
  );
163
168
  }
164
- const { buildApp } = await import("./build-WPHZ7TYZ.js");
169
+ const { buildApp } = await import("./build-W5VMPOTQ.js");
165
170
  await buildApp(root, config, preset);
166
171
  if (command === "preview") {
167
- const { startProd } = await import("./start-ITRND3BY.js");
172
+ const { startProd } = await import("./start-PXOLWPL4.js");
168
173
  await startProd(root, config, overrides);
169
174
  }
175
+ } else if (command === "generate") {
176
+ const preset = generatePreset(
177
+ args.preset ? assertBuildPreset(args.preset, "--preset") : void 0,
178
+ config.build.preset
179
+ );
180
+ const { buildApp } = await import("./build-W5VMPOTQ.js");
181
+ await buildApp(root, config, preset, { generate: true });
170
182
  } else if (command === "start") {
171
- const { startProd } = await import("./start-ITRND3BY.js");
183
+ const { startProd } = await import("./start-PXOLWPL4.js");
172
184
  await startProd(root, config, overrides);
173
185
  } else {
174
- const { prepareApp } = await import("./prepare-BN7NMCVQ.js");
186
+ const { prepareApp } = await import("./prepare-APN2E6PX.js");
175
187
  await prepareApp(root, config);
176
188
  if (command === "prepare") {
177
189
  console.log("noofpi: generated .noofpi/");
@@ -16,13 +16,14 @@ import {
16
16
  resolveCss,
17
17
  resolveFonts,
18
18
  startPlatformProxy
19
- } from "./chunk-NHBXVKEQ.js";
19
+ } from "./chunk-ROMSHDCI.js";
20
20
  import "./chunk-OKNF6XDO.js";
21
- import "./chunk-IE3WF5XF.js";
21
+ import "./chunk-SUECMRBX.js";
22
22
  import {
23
23
  createHandler
24
- } from "./chunk-X3DYEZLK.js";
25
- import "./chunk-MTXQR32N.js";
24
+ } from "./chunk-A7XQWIA6.js";
25
+ import "./chunk-LJEKK4AK.js";
26
+ import "./chunk-GOJZ36X5.js";
26
27
  import {
27
28
  sendWebResponse,
28
29
  toWebRequest
@@ -30,8 +31,8 @@ import {
30
31
  import "./chunk-PPUFFGCH.js";
31
32
  import "./chunk-ELXCFUA4.js";
32
33
  import "./chunk-EZPJF4D4.js";
33
- import "./chunk-G35DW4NA.js";
34
- import "./chunk-MN5PVHC5.js";
34
+ import "./chunk-PC3ZJN4D.js";
35
+ import "./chunk-W7ASRDAJ.js";
35
36
  import "./chunk-Y3NBZ6DW.js";
36
37
 
37
38
  // src/vite/dev.ts
@@ -11,7 +11,7 @@ import {
11
11
  isServerRendered,
12
12
  matchRouteRules,
13
13
  resolveFetchMode
14
- } from "./chunk-MN5PVHC5.js";
14
+ } from "./chunk-W7ASRDAJ.js";
15
15
 
16
16
  // src/runtime/devtools.ts
17
17
  import {
@@ -0,0 +1,26 @@
1
+ import { f as ServerModule } from './types-B7xDyUbg.js';
2
+
3
+ interface HandlerOptions {
4
+ /** Returns the generated server module (`virtual:noofpi/server`, or the built bundle in production) */
5
+ load: () => Promise<ServerModule>;
6
+ /** Returns the HTML shell for a page URL */
7
+ getTemplate: (url: string) => Promise<string>;
8
+ onError?: (error: unknown) => void;
9
+ /**
10
+ * Rendering pages into files (`noofpi generate`): no streaming, no server cache, no visitor session and no CSP
11
+ * nonces, because the HTML is written once and served to everybody
12
+ */
13
+ prerender?: boolean;
14
+ }
15
+ /** What a runtime that kills the request's work when the response is sent (Workers) offers to keep it alive */
16
+ interface HandlerContext {
17
+ waitUntil(promise: Promise<unknown>): void;
18
+ }
19
+ type Handler = (request: Request, env?: unknown, ctx?: HandlerContext) => Promise<Response>;
20
+ /**: one web-standard `fetch(Request) -> Response` handler.
21
+ * Order: redirects and CORS preflights -> middleware -> proxy (pfetch) -> local doofpi API -> HTML (SSR render or SPA shell).
22
+ */
23
+ declare function createHandler(options: HandlerOptions): Handler;
24
+
25
+ export { createHandler as c };
26
+ export type { Handler as H, HandlerContext as a, HandlerOptions as b };
package/dist/index.d.ts CHANGED
@@ -1,17 +1,19 @@
1
1
  import { UserConfig } from 'vite';
2
- import { R as RouteRules, H as HeadConfig, S as SecurityConfig, F as FetchMode } from './route-rules-COilNsVT.js';
3
- export { C as CspConfig, a as CspDirectiveName, b as CspDirectiveValue, c as CsrfConfig, d as FETCH_MODES, e as HeadInput, f as HeadTag, g as RouteRule } from './route-rules-COilNsVT.js';
2
+ import { R as RouteRules, S as SessionConfig, H as HeadConfig, a as SecurityConfig, F as FetchMode } from './session-CAP_PIlN.js';
3
+ export { C as CacheRule, b as CorsOptions, c as CspConfig, d as CspDirectiveName, e as CspDirectiveValue, f as CsrfConfig, g as FETCH_MODES, h as HeadInput, i as HeadTag, j as RedirectRule, k as RouteRule, l as Session, m as SessionData } from './session-CAP_PIlN.js';
4
4
  import { I as ImagesConfig, a as I18nConfig } from './images-BNwTAi50.js';
5
5
  export { b as ImageFormat } from './images-BNwTAi50.js';
6
6
 
7
- declare const BUILD_PRESETS: readonly ["node", "bun", "docker", "cloudflare-worker", "cloudflare-pages", "github-pages"];
7
+ declare const BUILD_PRESETS: readonly ["node", "bun", "docker-node", "docker-bun", "cloudflare-worker", "cloudflare-pages", "github-pages"];
8
8
  /**
9
9
  * - `node`: `.output/` runs with `noofpi start` or `node .output/server/start.mjs`
10
10
  * - `bun`: like `node`, served with `Bun.serve` (`bun .output/server/start.mjs`)
11
- * - `docker`: like `node`, plus `.output/Dockerfile`
11
+ * - `docker-node`: like `node`, plus `.output/Dockerfile` for a Node image
12
+ * - `docker-bun`: like `bun`, plus `.output/Dockerfile` for a Bun image
12
13
  * - `cloudflare-worker`: one bundled Worker (`server/index.mjs`) with static assets, plus `wrangler.json`
13
14
  * - `cloudflare-pages`: `public/` with a bundled `_worker.js`, deployable with `wrangler pages deploy`
14
- * - `github-pages`: static client-only SPA in `public/` (no server): `index.html`, a `404.html` fallback and `.nojekyll`
15
+ * - `github-pages`: static files in `public/` (no server): `index.html`, a `404.html` client-router fallback and `.nojekyll`. A client-only SPA, or with `routeRules` `prerender` (`noofpi generate`) real HTML for the marked pages
16
+ * - `cloudflare-pages` also takes `noofpi generate`: static files with `_headers` and `_redirects` instead of a Worker
15
17
  */
16
18
  type BuildPreset = (typeof BUILD_PRESETS)[number];
17
19
 
@@ -67,6 +69,13 @@ interface FontsConfig {
67
69
  families: FontFamily[];
68
70
  }
69
71
 
72
+ interface PrerenderConfig {
73
+ /** Pages to prerender besides the ones `routeRules` marks: URLs of dynamic pages that nothing links to (`/users/42`) */
74
+ routes?: string[];
75
+ /** Also prerender the pages that prerendered pages link to, when they are marked for prerendering. Default: `true` */
76
+ crawlLinks?: boolean;
77
+ }
78
+
70
79
  interface SeoConfig {
71
80
  /** Public URL of the site (`https://example.com`, or with a path for project sites). Needed for the sitemap, whose URLs are absolute */
72
81
  siteUrl?: string;
@@ -81,8 +90,14 @@ interface SeoConfig {
81
90
  interface NoofpiConfig {
82
91
  /** Render pages on the server (`true`, default) or ship a client-only SPA (`false`) */
83
92
  ssr?: boolean;
84
- /** Per-route overrides keyed by URL pattern (`/admin/**`, `/users/*`, `/about`), e.g. `{ "/admin/**": { ssr: false, fetch: "pfetch" } }` */
93
+ /** Stream server-rendered pages: the HTML shell is sent as soon as the route is resolved and the page follows while data loads. Default: `false`. `routeRules[...].stream` overrides it per route */
94
+ streaming?: boolean;
95
+ /** Per-route overrides keyed by URL pattern (`/admin/**`, `/users/*`, `/about`), e.g. `{ "/admin/**": { ssr: false, fetch: "pfetch" }, "/blog/**": { prerender: true, cache: { maxAge: 60, swr: 600 } } }` */
85
96
  routeRules?: RouteRules;
97
+ /** What `noofpi generate` prerenders besides the pages `routeRules` marks with `prerender: true` */
98
+ prerender?: PrerenderConfig;
99
+ /** Signed or encrypted cookie sessions: `getSession(request)` on the server, `useSession()` in components, `sessionGuard()` for a server middleware. Needs the `NOOFPI_SESSION_SECRET` environment variable. `true` for the defaults. Off unless set */
100
+ session?: boolean | SessionConfig;
86
101
  /** Default `<head>` of every page: `title` (put `%s` where a page's `useHead({ title })` goes), `meta`, `link`, `htmlAttrs`, `bodyAttrs` */
87
102
  head?: HeadConfig;
88
103
  /** Enable the built-in Tailwind CSS (v4) vite plugin */
@@ -114,11 +129,11 @@ interface NoofpiConfig {
114
129
  host?: string;
115
130
  };
116
131
  build?: {
117
- /** Deploy target of `noofpi build`: `node` (default), `bun`, `docker`, `cloudflare-worker`, `cloudflare-pages` or `github-pages` (static SPA). `--preset` overrides it */
132
+ /** Deploy target of `noofpi build`: `node` (default), `bun`, `docker-node`, `docker-bun`, `cloudflare-worker`, `cloudflare-pages` or `github-pages` (static SPA). `--preset` overrides it */
118
133
  preset?: BuildPreset;
119
- /** Options of the generated `.output/Dockerfile` (`docker` preset) */
134
+ /** Options of the generated `.output/Dockerfile` (`docker-node` and `docker-bun` presets) */
120
135
  docker?: {
121
- /** Base image of both build stages. Default: `node:22-alpine` (`oven/bun:1` when the project uses bun) */
136
+ /** Base image of both build stages. Default: `node:22-alpine` (`oven/bun:1` with `docker-bun`) */
122
137
  image?: string;
123
138
  /** Path the image `HEALTHCHECK` requests (any status below 500 is healthy), or `false` for no healthcheck. Default: `/` */
124
139
  healthcheck?: string | false;
@@ -131,5 +146,5 @@ interface NoofpiConfig {
131
146
  }
132
147
  declare function defineNoofpiConfig(config: NoofpiConfig): NoofpiConfig;
133
148
 
134
- export { BUILD_PRESETS, FONT_PROVIDERS, FetchMode, HeadConfig, I18nConfig, ImagesConfig, RouteRules, SecurityConfig, defineNoofpiConfig };
135
- export type { BuildPreset, FontDisplay, FontFamily, FontProviderName, FontStyle, FontWeight, FontsConfig, GoogleFontFamily, LocalFontFamily, LocalFontFile, NoofpiConfig, SeoConfig };
149
+ export { BUILD_PRESETS, FONT_PROVIDERS, FetchMode, HeadConfig, I18nConfig, ImagesConfig, RouteRules, SecurityConfig, SessionConfig, defineNoofpiConfig };
150
+ export type { BuildPreset, FontDisplay, FontFamily, FontProviderName, FontStyle, FontWeight, FontsConfig, GoogleFontFamily, LocalFontFamily, LocalFontFile, NoofpiConfig, PrerenderConfig, SeoConfig };
package/dist/index.js CHANGED
@@ -2,11 +2,12 @@ import {
2
2
  BUILD_PRESETS,
3
3
  FONT_PROVIDERS,
4
4
  defineNoofpiConfig
5
- } from "./chunk-IE3WF5XF.js";
5
+ } from "./chunk-SUECMRBX.js";
6
+ import "./chunk-GOJZ36X5.js";
6
7
  import "./chunk-ELXCFUA4.js";
7
8
  import {
8
9
  FETCH_MODES
9
- } from "./chunk-MN5PVHC5.js";
10
+ } from "./chunk-W7ASRDAJ.js";
10
11
  export {
11
12
  BUILD_PRESETS,
12
13
  FETCH_MODES,
@@ -0,0 +1,66 @@
1
+ import { F as FetchMode } from './session-CAP_PIlN.js';
2
+
3
+ /** The error shown by `app/error.vue`: what the page receives in its `error` prop */
4
+ interface NoofpiErrorData {
5
+ statusCode: number;
6
+ statusMessage: string;
7
+ message: string;
8
+ /** The URL that was being rendered */
9
+ url?: string;
10
+ }
11
+ interface CreateErrorInput {
12
+ statusCode?: number;
13
+ statusMessage?: string;
14
+ message?: string;
15
+ }
16
+ /** Marks errors made by `createError()`, which stay recognizable when the module is loaded twice */
17
+ declare const BRAND = "__noofpiError";
18
+ declare class NoofpiError extends Error implements NoofpiErrorData {
19
+ readonly [BRAND] = true;
20
+ statusCode: number;
21
+ statusMessage: string;
22
+ url?: string;
23
+ constructor(input?: CreateErrorInput);
24
+ }
25
+ /**
26
+ * Creates an error to `throw` from a page's setup, a route middleware (or pass it to
27
+ * `showError()`): when the project has an `app/error.vue`, it is rendered with this error and the response gets its status.
28
+ */
29
+ declare function createError(input: string | CreateErrorInput): NoofpiError;
30
+
31
+ /** A doofpi request seen by the dev request inspector */
32
+ interface RequestEntry {
33
+ /** Where the request was made: while rendering on the server or in the browser */
34
+ side: "server" | "browser";
35
+ mode: FetchMode;
36
+ /** `in-process` never touches the network (SSR `lfetch` / `pfetch` call the noofpi server directly) */
37
+ transport: "in-process" | "http";
38
+ method: string;
39
+ url: string;
40
+ /** `undefined` while the request is pending or when it failed before a response */
41
+ status?: number;
42
+ /** Milliseconds until the response headers arrived (or the request failed) */
43
+ ms?: number;
44
+ error?: string;
45
+ }
46
+
47
+ /** Data collected during SSR and handed to the browser so it does not fetch again */
48
+ interface PayloadData {
49
+ data: Record<string, unknown>;
50
+ errors: Record<string, AsyncDataError>;
51
+ /** Values of `useState` by key */
52
+ state?: Record<string, unknown>;
53
+ /** Set when the server rendered the error page, so the browser hydrates the same one */
54
+ error?: NoofpiErrorData;
55
+ /** The locale the server rendered in (only with `i18n`), so the browser hydrates in the same one */
56
+ locale?: string;
57
+ /** Dev only: the doofpi requests the server made while rendering, for the dev request inspector */
58
+ requests?: RequestEntry[];
59
+ }
60
+ interface AsyncDataError {
61
+ message: string;
62
+ status?: number;
63
+ }
64
+
65
+ export { NoofpiError as a, createError as c };
66
+ export type { AsyncDataError as A, CreateErrorInput as C, NoofpiErrorData as N, PayloadData as P, RequestEntry as R };
@@ -1,12 +1,13 @@
1
1
  import {
2
2
  createViteConfig
3
- } from "./chunk-NHBXVKEQ.js";
4
- import "./chunk-IE3WF5XF.js";
5
- import "./chunk-MTXQR32N.js";
3
+ } from "./chunk-ROMSHDCI.js";
4
+ import "./chunk-SUECMRBX.js";
5
+ import "./chunk-LJEKK4AK.js";
6
+ import "./chunk-GOJZ36X5.js";
6
7
  import "./chunk-PPUFFGCH.js";
7
8
  import "./chunk-ELXCFUA4.js";
8
- import "./chunk-G35DW4NA.js";
9
- import "./chunk-MN5PVHC5.js";
9
+ import "./chunk-PC3ZJN4D.js";
10
+ import "./chunk-W7ASRDAJ.js";
10
11
  import "./chunk-Y3NBZ6DW.js";
11
12
 
12
13
  // src/vite/prepare.ts
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  createNoofpiApp
3
- } from "../chunk-YJVMBHNL.js";
3
+ } from "../chunk-JUVQEKLE.js";
4
4
  import "../chunk-6OWKWAIW.js";
5
5
  import "../chunk-ELXCFUA4.js";
6
6
  import "../chunk-EZPJF4D4.js";
7
- import "../chunk-G35DW4NA.js";
8
- import "../chunk-MN5PVHC5.js";
7
+ import "../chunk-PC3ZJN4D.js";
8
+ import "../chunk-W7ASRDAJ.js";
9
9
 
10
10
  // src/runtime/entry-client.ts
11
11
  import { publicConfig } from "virtual:noofpi/config";
@@ -53,7 +53,7 @@ async function mount() {
53
53
  );
54
54
  await i18n?.ready;
55
55
  if (import.meta.env.DEV && publicConfig.devtools) {
56
- const { mountDevtools } = await import("../devtools-PLUN2DYV.js");
56
+ const { mountDevtools } = await import("../devtools-C3PFU57C.js");
57
57
  mountDevtools({
58
58
  router,
59
59
  config: publicConfig,