@demiurgejs/core 0.2.0-beta.3 → 0.2.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -11
- package/bin/demiurge.mjs +30 -12
- package/dist/browser/file-router.d.ts +388 -5
- package/dist/browser/file-router.d.ts.map +1 -1
- package/dist/browser/focus.d.ts +20 -0
- package/dist/browser/focus.d.ts.map +1 -0
- package/dist/browser/index.d.ts +7 -1
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/mutation-action.d.ts +81 -0
- package/dist/browser/mutation-action.d.ts.map +1 -0
- package/dist/chunks/document-shell-CpJnFtSC.js +36 -0
- package/dist/chunks/document-shell-CpJnFtSC.js.map +1 -0
- package/dist/chunks/env-startup-DOBYWlZD.js +257 -0
- package/dist/chunks/env-startup-DOBYWlZD.js.map +1 -0
- package/dist/chunks/{image-codec-Di53WpcH.js → image-codec-BmzWnH6W.js} +2 -2
- package/dist/chunks/{image-codec-Di53WpcH.js.map → image-codec-BmzWnH6W.js.map} +1 -1
- package/dist/chunks/{images-Edar3eU1.js → images-BQ80950B.js} +99 -91
- package/dist/chunks/images-BQ80950B.js.map +1 -0
- package/dist/chunks/index-BVk9zWbe.js +832 -0
- package/dist/chunks/index-BVk9zWbe.js.map +1 -0
- package/dist/chunks/manifest-vO6c0G0W.js +19 -0
- package/dist/chunks/manifest-vO6c0G0W.js.map +1 -0
- package/dist/chunks/plugin-BQgMiHxa.js +1827 -0
- package/dist/chunks/plugin-BQgMiHxa.js.map +1 -0
- package/dist/chunks/session-store-ChModVcq.js +92 -0
- package/dist/chunks/session-store-ChModVcq.js.map +1 -0
- package/dist/chunks/static-files-ehaD1kE7.js +51 -0
- package/dist/chunks/static-files-ehaD1kE7.js.map +1 -0
- package/dist/chunks/{streaming-D0fGAuiO.js → streaming-BEbPN7Uk.js} +163 -163
- package/dist/chunks/streaming-BEbPN7Uk.js.map +1 -0
- package/dist/chunks/testing-DueXbMo4.js +4167 -0
- package/dist/chunks/testing-DueXbMo4.js.map +1 -0
- package/dist/chunks/vite-DO70kZA6.js +259 -0
- package/dist/chunks/vite-DO70kZA6.js.map +1 -0
- package/dist/cli.d.ts +17 -25
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +159 -124
- package/dist/cli.js.map +1 -1
- package/dist/config/define.d.ts +3 -0
- package/dist/config/define.d.ts.map +1 -0
- package/dist/config/index.d.ts +7 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +78 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/load.d.ts +12 -0
- package/dist/config/load.d.ts.map +1 -0
- package/dist/config/types.d.ts +64 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/validate.d.ts +9 -0
- package/dist/config/validate.d.ts.map +1 -0
- package/dist/config/vite.d.ts +12 -0
- package/dist/config/vite.d.ts.map +1 -0
- package/dist/data/cache.d.ts +2 -0
- package/dist/data/cache.d.ts.map +1 -1
- package/dist/data/idempotency.d.ts.map +1 -1
- package/dist/deployment/testing.d.ts +25 -0
- package/dist/deployment/testing.d.ts.map +1 -0
- package/dist/deployment/testing.js +171 -0
- package/dist/deployment/testing.js.map +1 -0
- package/dist/document/hydration.d.ts +9 -0
- package/dist/document/hydration.d.ts.map +1 -1
- package/dist/document/index.d.ts +4 -2
- package/dist/document/index.d.ts.map +1 -1
- package/dist/document/metadata.d.ts +8 -0
- package/dist/document/metadata.d.ts.map +1 -1
- package/dist/document/navigation.d.ts +28 -0
- package/dist/document/navigation.d.ts.map +1 -0
- package/dist/document/render.d.ts +3 -1
- package/dist/document/render.d.ts.map +1 -1
- package/dist/document/seo.d.ts.map +1 -1
- package/dist/edge/assets.d.ts.map +1 -1
- package/dist/edge/index.js +55 -73
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +12 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1860 -691
- package/dist/index.js.map +1 -1
- package/dist/internal/testing.js +12 -12
- package/dist/kv/index.d.ts +2 -0
- package/dist/kv/index.d.ts.map +1 -1
- package/dist/kv/index.js +170 -73
- package/dist/kv/index.js.map +1 -1
- package/dist/kv/session-store.d.ts +20 -0
- package/dist/kv/session-store.d.ts.map +1 -0
- package/dist/manifest.d.ts +10 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/node/image.d.ts.map +1 -1
- package/dist/node/index.d.ts +3 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +251 -178
- package/dist/node/index.js.map +1 -1
- package/dist/node/serve.d.ts +47 -0
- package/dist/node/serve.d.ts.map +1 -0
- package/dist/node/static.d.ts.map +1 -1
- package/dist/platform/fonts.d.ts.map +1 -1
- package/dist/platform/image-url.d.ts.map +1 -1
- package/dist/platform/url.d.ts +19 -0
- package/dist/platform/url.d.ts.map +1 -0
- package/dist/platform/web-vitals.d.ts.map +1 -1
- package/dist/redis/index.d.ts +2 -0
- package/dist/redis/index.d.ts.map +1 -1
- package/dist/redis/index.js +186 -69
- package/dist/redis/index.js.map +1 -1
- package/dist/redis/session-store.d.ts +9 -0
- package/dist/redis/session-store.d.ts.map +1 -0
- package/dist/route/index.d.ts +2 -2
- package/dist/route/index.d.ts.map +1 -1
- package/dist/route/mutation.d.ts +97 -0
- package/dist/route/mutation.d.ts.map +1 -0
- package/dist/route/types.d.ts +6 -1
- package/dist/route/types.d.ts.map +1 -1
- package/dist/router/manifest.d.ts +8 -0
- package/dist/router/manifest.d.ts.map +1 -1
- package/dist/router/navigation-data.d.ts +9 -1
- package/dist/router/navigation-data.d.ts.map +1 -1
- package/dist/routing/generate.d.ts +3 -0
- package/dist/routing/generate.d.ts.map +1 -1
- package/dist/routing/index.d.ts +3 -1
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/locale.d.ts +43 -0
- package/dist/routing/locale.d.ts.map +1 -0
- package/dist/routing/types.d.ts +12 -0
- package/dist/routing/types.d.ts.map +1 -1
- package/dist/security/cookie-session.d.ts +43 -0
- package/dist/security/cookie-session.d.ts.map +1 -0
- package/dist/security/csrf.d.ts +1 -1
- package/dist/security/csrf.d.ts.map +1 -1
- package/dist/security/env-startup.d.ts +15 -0
- package/dist/security/env-startup.d.ts.map +1 -0
- package/dist/security/env.d.ts +25 -6
- package/dist/security/env.d.ts.map +1 -1
- package/dist/security/index.d.ts +9 -1
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/report.d.ts.map +1 -1
- package/dist/security/session-manager.d.ts +32 -0
- package/dist/security/session-manager.d.ts.map +1 -0
- package/dist/security/session-store.d.ts +51 -0
- package/dist/security/session-store.d.ts.map +1 -0
- package/dist/security/testing.d.ts +10 -0
- package/dist/security/testing.d.ts.map +1 -0
- package/dist/security/testing.js +145 -0
- package/dist/security/testing.js.map +1 -0
- package/dist/security/types.d.ts +1 -0
- package/dist/security/types.d.ts.map +1 -1
- package/dist/server/document-shell.d.ts.map +1 -1
- package/dist/server/errors.d.ts +1 -0
- package/dist/server/errors.d.ts.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/not-found.d.ts +1 -0
- package/dist/server/not-found.d.ts.map +1 -1
- package/dist/server/render-tree.d.ts.map +1 -1
- package/dist/server/request-handler.d.ts +4 -0
- package/dist/server/request-handler.d.ts.map +1 -1
- package/dist/server/request-metadata.d.ts +1 -0
- package/dist/server/request-metadata.d.ts.map +1 -1
- package/dist/server/ssr.d.ts +2 -0
- package/dist/server/ssr.d.ts.map +1 -1
- package/dist/static/index.d.ts +2 -0
- package/dist/static/index.d.ts.map +1 -1
- package/dist/static/index.js +380 -363
- package/dist/static/index.js.map +1 -1
- package/dist/static/preview.d.ts.map +1 -1
- package/dist/static/vercel.d.ts +11 -2
- package/dist/static/vercel.d.ts.map +1 -1
- package/dist/static-files.d.ts +12 -0
- package/dist/static-files.d.ts.map +1 -1
- package/dist/type-guards.d.ts +19 -0
- package/dist/type-guards.d.ts.map +1 -0
- package/dist/vite/env-boundary.d.ts +14 -0
- package/dist/vite/env-boundary.d.ts.map +1 -0
- package/dist/vite/index.d.ts +5 -3
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +22 -1560
- package/dist/vite/index.js.map +1 -1
- package/dist/vite/plugin.d.ts +6 -1
- package/dist/vite/plugin.d.ts.map +1 -1
- package/dist/vite/policy-verification.d.ts.map +1 -1
- package/package.json +19 -6
- package/dist/chunks/document-shell-WoM8yZlR.js +0 -35
- package/dist/chunks/document-shell-WoM8yZlR.js.map +0 -1
- package/dist/chunks/images-Edar3eU1.js.map +0 -1
- package/dist/chunks/request-metadata-DaIYq4Ea.js +0 -677
- package/dist/chunks/request-metadata-DaIYq4Ea.js.map +0 -1
- package/dist/chunks/static-files-DUjHw-4H.js +0 -11
- package/dist/chunks/static-files-DUjHw-4H.js.map +0 -1
- package/dist/chunks/streaming-D0fGAuiO.js.map +0 -1
- package/dist/chunks/testing-CRflAw4X.js +0 -3475
- package/dist/chunks/testing-CRflAw4X.js.map +0 -1
- package/dist/route/action.d.ts +0 -33
- package/dist/route/action.d.ts.map +0 -1
|
@@ -0,0 +1,1827 @@
|
|
|
1
|
+
import { existsSync as ae } from "node:fs";
|
|
2
|
+
import { mkdir as Qe, writeFile as Xe, readdir as Ae, readFile as Fe } from "node:fs/promises";
|
|
3
|
+
import { dirname as ce, resolve as x, relative as D, sep as j, join as Ze } from "node:path";
|
|
4
|
+
import et from "magic-string";
|
|
5
|
+
import { parseAst as Q, transformWithEsbuild as tt } from "vite";
|
|
6
|
+
import { e as nt, f as rt } from "./index-BVk9zWbe.js";
|
|
7
|
+
import { v as ot, k as it, i as F, n as st, s as G, o as fe, p as at, q as ee, t as ct, u as lt, w as ke, M as ut, x as ft, y as Y, z as de, A as dt, B as pt, C as mt, e as ht, f as yt, h as gt, D as vt } from "./testing-DueXbMo4.js";
|
|
8
|
+
import "react";
|
|
9
|
+
import "react-dom/server";
|
|
10
|
+
import "react/jsx-runtime";
|
|
11
|
+
import { c as wt, t as pe, U as me, w as he, b as J, d as bt, e as $t } from "./streaming-BEbPN7Uk.js";
|
|
12
|
+
import { p as Rt } from "./images-BQ80950B.js";
|
|
13
|
+
import { s as _e } from "./env-startup-DOBYWlZD.js";
|
|
14
|
+
const M = "@demiurgejs/core";
|
|
15
|
+
async function St(e) {
|
|
16
|
+
const t = await Et(e.routesDir), n = t.map((s) => Pt(e, s)).filter((s) => !!s), r = t.map((s) => Nt(e, s, n)).filter((s) => !!s).sort((s, i) => s.pattern.localeCompare(i.pattern));
|
|
17
|
+
xt(r, e.localeNamespaces ?? []);
|
|
18
|
+
const o = Ot(r, n, e.locales);
|
|
19
|
+
return await Qe(ce(e.outputFile), { recursive: !0 }), await Xe(e.outputFile, o), {
|
|
20
|
+
routes: r,
|
|
21
|
+
source: o
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function xt(e, t) {
|
|
25
|
+
const n = new Set(t.map((r) => r.toLowerCase()));
|
|
26
|
+
for (const r of e) {
|
|
27
|
+
const [o] = r.pattern.slice(1).split("/");
|
|
28
|
+
if (o && !o.startsWith("[") && n.has(o.toLowerCase()))
|
|
29
|
+
throw new Error(
|
|
30
|
+
`Route "${r.pattern}" conflicts with the locale URL namespace "${o}". Move the route or change the locale label.`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function Et(e) {
|
|
35
|
+
return (await Ae(e, {
|
|
36
|
+
recursive: !0,
|
|
37
|
+
withFileTypes: !0
|
|
38
|
+
})).filter((n) => n.isFile() && /\.tsx?$/.test(n.name)).map((n) => x(n.parentPath, n.name));
|
|
39
|
+
}
|
|
40
|
+
function Nt(e, t, n) {
|
|
41
|
+
const o = D(e.routesDir, t).split(j).join("/").replace(/\.tsx?$/, "").split("/");
|
|
42
|
+
if (o.at(-1)?.startsWith("@"))
|
|
43
|
+
return null;
|
|
44
|
+
const i = o.flatMap((c) => ye(c) ? [] : c === "index" ? [] : c.startsWith("[...") && c.endsWith("]") ? [c] : c.startsWith("[") && c.endsWith("]") ? [c] : [c]), a = o.flatMap((c) => ye(c) ? [] : c.startsWith("[...") && c.endsWith("]") ? [c.slice(4, -1)] : c.startsWith("[") && c.endsWith("]") ? [c.slice(1, -1)] : []);
|
|
45
|
+
return {
|
|
46
|
+
contextMiddleware: n.filter((c) => Dt(c.fileSegments, o)).map((c) => n.indexOf(c)),
|
|
47
|
+
fileSegments: o,
|
|
48
|
+
importPath: Le(e.outputFile, t),
|
|
49
|
+
pathVars: a,
|
|
50
|
+
pattern: `/${i.join("/")}`.replace(/\/$/, "") || "/"
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function Pt(e, t) {
|
|
54
|
+
const r = D(e.routesDir, t).split(j).join("/").replace(/\.tsx?$/, "").split("/");
|
|
55
|
+
return r.at(-1) !== "@middleware" ? null : {
|
|
56
|
+
file: t,
|
|
57
|
+
fileSegments: r.slice(0, -1),
|
|
58
|
+
importPath: Le(e.outputFile, t)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function Le(e, t) {
|
|
62
|
+
let n = D(ce(e), t).split(j).join("/").replace(/\.tsx?$/, "");
|
|
63
|
+
return n.startsWith(".") || (n = `./${n}`), n;
|
|
64
|
+
}
|
|
65
|
+
function Dt(e, t) {
|
|
66
|
+
return e.every(
|
|
67
|
+
(n, r) => t[r] === n
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
function ye(e) {
|
|
71
|
+
return e.startsWith("(") && e.endsWith(")");
|
|
72
|
+
}
|
|
73
|
+
function Ot(e, t, n = []) {
|
|
74
|
+
return `// Generated by Demiurge. Do not edit by hand.
|
|
75
|
+
import "${M}";
|
|
76
|
+
import type { MiddlewareContextOf, MutationMethodsOf, PathValue } from "${M}";
|
|
77
|
+
${t.map(Mt).join(`
|
|
78
|
+
`)}
|
|
79
|
+
|
|
80
|
+
${t.map((r, o) => jt(o)).join(`
|
|
81
|
+
`)}
|
|
82
|
+
|
|
83
|
+
declare module "${M}" {
|
|
84
|
+
interface RouteLocales {
|
|
85
|
+
${n.map((r) => ` ${JSON.stringify(r)}: true;`).join(`
|
|
86
|
+
`)}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface RoutePathVars {
|
|
90
|
+
${e.map(It).join(`
|
|
91
|
+
`)}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
interface RouteConcretePaths {
|
|
95
|
+
${e.map(Tt).join(`
|
|
96
|
+
`)}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
interface RouteRequestContexts {
|
|
100
|
+
${e.map(Ct).join(`
|
|
101
|
+
`)}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
interface RouteMutationMethods {
|
|
105
|
+
${e.map(At).join(`
|
|
106
|
+
`)}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export {};
|
|
111
|
+
`;
|
|
112
|
+
}
|
|
113
|
+
function Mt(e, t) {
|
|
114
|
+
return `type __DemiurgeMiddleware${t} = typeof import(${JSON.stringify(e.importPath)}) extends { middleware?: infer T } ? T : never;`;
|
|
115
|
+
}
|
|
116
|
+
function jt(e) {
|
|
117
|
+
return `type __DemiurgeMiddlewareContext${e} = MiddlewareContextOf<__DemiurgeMiddleware${e}>;`;
|
|
118
|
+
}
|
|
119
|
+
function It(e) {
|
|
120
|
+
if (e.pathVars.length === 0)
|
|
121
|
+
return ` ${JSON.stringify(e.pattern)}: {};`;
|
|
122
|
+
const t = e.pathVars.map((n) => `${n}: PathValue`).join("; ");
|
|
123
|
+
return ` ${JSON.stringify(e.pattern)}: { ${t} };`;
|
|
124
|
+
}
|
|
125
|
+
function Tt(e) {
|
|
126
|
+
return ` ${JSON.stringify(e.pattern)}: ${Ft(e.pattern)};`;
|
|
127
|
+
}
|
|
128
|
+
function Ct(e) {
|
|
129
|
+
const t = e.contextMiddleware.map((r) => `__DemiurgeMiddlewareContext${r}`), n = t.length > 0 ? t.join(" & ") : "Record<never, never>";
|
|
130
|
+
return ` ${JSON.stringify(e.pattern)}: ${n};`;
|
|
131
|
+
}
|
|
132
|
+
function At(e) {
|
|
133
|
+
return ` ${JSON.stringify(e.pattern)}: MutationMethodsOf<typeof import(${JSON.stringify(e.importPath)})>;`;
|
|
134
|
+
}
|
|
135
|
+
function Ft(e) {
|
|
136
|
+
return e.includes("[") ? `\`${e.split(/(\[\.\.\.[^\]]+\]|\[[^\]]+\])/g).filter(Boolean).map((n) => n.startsWith("[") ? "${PathValue}" : kt(n)).join("")}\`` : JSON.stringify(e);
|
|
137
|
+
}
|
|
138
|
+
function kt(e) {
|
|
139
|
+
return e.replace(/[`$\\]/g, "\\$&");
|
|
140
|
+
}
|
|
141
|
+
function _t(e) {
|
|
142
|
+
const t = /* @__PURE__ */ new Map();
|
|
143
|
+
for (const [n, r] of Object.entries(e ?? {}))
|
|
144
|
+
r.client || t.set(n, { sensitive: r.sensitive });
|
|
145
|
+
return t;
|
|
146
|
+
}
|
|
147
|
+
function Lt(e, t) {
|
|
148
|
+
const n = new Set(t), r = /* @__PURE__ */ new Set();
|
|
149
|
+
return n.size ? [...n].some((o) => e.includes(o)) ? (Ve(Q(e), n, r), [...r].sort()) : [] : [];
|
|
150
|
+
}
|
|
151
|
+
function Vt(e, t, n) {
|
|
152
|
+
if (e === t) return [e];
|
|
153
|
+
const r = /* @__PURE__ */ new Set([e]), o = [[e]];
|
|
154
|
+
for (; o.length; ) {
|
|
155
|
+
const s = o.shift();
|
|
156
|
+
for (const i of n(s[s.length - 1]))
|
|
157
|
+
if (!r.has(i)) {
|
|
158
|
+
if (i === t) return [...s, i];
|
|
159
|
+
r.add(i), o.push([...s, i]);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function Wt(e) {
|
|
164
|
+
return [
|
|
165
|
+
"Demiurge stopped the build. Client code reads an environment variable that stays on the server.",
|
|
166
|
+
"",
|
|
167
|
+
...e.flatMap(Jt)
|
|
168
|
+
].join(`
|
|
169
|
+
`);
|
|
170
|
+
}
|
|
171
|
+
function Jt(e) {
|
|
172
|
+
return [
|
|
173
|
+
` variable: ${e.key}`,
|
|
174
|
+
` module: ${e.module}`,
|
|
175
|
+
` import path: ${e.importPath.join(" -> ")}`,
|
|
176
|
+
e.code === "client-secret" ? " A secret variable never reaches the browser. Read the value on the server, then send the result through route data." : " Declare the variable with client: true to put the value in the browser bundle.",
|
|
177
|
+
""
|
|
178
|
+
];
|
|
179
|
+
}
|
|
180
|
+
function Ve(e, t, n) {
|
|
181
|
+
if (e.type !== "ImportDeclaration" && !(e.type === "ExportNamedDeclaration" && !e.declaration) && e.type !== "ExportAllDeclaration") {
|
|
182
|
+
if (e.type === "Identifier") {
|
|
183
|
+
re(e.name, t, n);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (e.type === "MemberExpression") {
|
|
187
|
+
k(e.object, t, n), ge(e.property, !!e.computed, t, n);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (e.type === "Property" || e.type === "PropertyDefinition") {
|
|
191
|
+
(e.computed || Ht(e)) && ge(e.key, !!e.computed, t, n), k(e.value, t, n);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
Ut(e, t, n);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function Ht(e) {
|
|
198
|
+
const t = le(e.value);
|
|
199
|
+
return t?.type === "Identifier" || t?.type === "ObjectPattern" || t?.type === "ArrayPattern" || t?.type === "AssignmentPattern";
|
|
200
|
+
}
|
|
201
|
+
function ge(e, t, n, r) {
|
|
202
|
+
const o = le(e);
|
|
203
|
+
if (o) {
|
|
204
|
+
if (o.type === "Literal") {
|
|
205
|
+
re(o.value, n, r);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (!t) {
|
|
209
|
+
o.type === "Identifier" && re(o.name, n, r);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
k(o, n, r);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function re(e, t, n) {
|
|
216
|
+
typeof e == "string" && t.has(e) && n.add(e);
|
|
217
|
+
}
|
|
218
|
+
function Ut(e, t, n) {
|
|
219
|
+
for (const [r, o] of Object.entries(e))
|
|
220
|
+
r === "end" || r === "loc" || r === "start" || r === "type" || k(o, t, n);
|
|
221
|
+
}
|
|
222
|
+
function k(e, t, n) {
|
|
223
|
+
if (!e || typeof e != "object") return;
|
|
224
|
+
if (Array.isArray(e)) {
|
|
225
|
+
for (const o of e) k(o, t, n);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const r = le(e);
|
|
229
|
+
if (r) {
|
|
230
|
+
Ve(r, t, n);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
for (const o of Object.values(e))
|
|
234
|
+
k(o, t, n);
|
|
235
|
+
}
|
|
236
|
+
function le(e) {
|
|
237
|
+
return e && typeof e == "object" && "type" in e && typeof e.type == "string" ? e : void 0;
|
|
238
|
+
}
|
|
239
|
+
const zt = [
|
|
240
|
+
"GET",
|
|
241
|
+
"POST",
|
|
242
|
+
"PUT",
|
|
243
|
+
"PATCH",
|
|
244
|
+
"DELETE",
|
|
245
|
+
"OPTIONS",
|
|
246
|
+
"HEAD"
|
|
247
|
+
], Bt = /* @__PURE__ */ new Set([
|
|
248
|
+
"mutation",
|
|
249
|
+
"html",
|
|
250
|
+
"json",
|
|
251
|
+
"jsonl",
|
|
252
|
+
"notFound",
|
|
253
|
+
"redirect",
|
|
254
|
+
"response",
|
|
255
|
+
"sse",
|
|
256
|
+
"stream",
|
|
257
|
+
"text"
|
|
258
|
+
]);
|
|
259
|
+
async function Gt(e) {
|
|
260
|
+
const t = await Fe(e, "utf8");
|
|
261
|
+
return await qt(t, e);
|
|
262
|
+
}
|
|
263
|
+
async function qt(e, t) {
|
|
264
|
+
const n = t.endsWith(".tsx") ? "tsx" : "ts", r = await tt(e, t, {
|
|
265
|
+
format: "esm",
|
|
266
|
+
loader: n,
|
|
267
|
+
target: "esnext"
|
|
268
|
+
}), o = Kt(r.code);
|
|
269
|
+
return en(o, t);
|
|
270
|
+
}
|
|
271
|
+
function Kt(e) {
|
|
272
|
+
const t = Q(e), n = nn(t), r = rn(t), o = Yt(t), s = Qt(t), i = {}, a = /* @__PURE__ */ new Set();
|
|
273
|
+
let c;
|
|
274
|
+
for (const [l, u] of s) {
|
|
275
|
+
const d = o.get(u);
|
|
276
|
+
if (l === "policy") {
|
|
277
|
+
d && (c = We(d, n, r));
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (!on(l) || (a.add(l), !d)) continue;
|
|
281
|
+
const h = Xt(d, n, r);
|
|
282
|
+
h && (i[l] = h);
|
|
283
|
+
}
|
|
284
|
+
return { capabilities: i, declaredMethods: a, policy: c };
|
|
285
|
+
}
|
|
286
|
+
function Yt(e) {
|
|
287
|
+
const t = /* @__PURE__ */ new Map();
|
|
288
|
+
for (const n of y(e.body)) {
|
|
289
|
+
const r = n.type === "ExportNamedDeclaration" ? $(n.declaration) : n;
|
|
290
|
+
if (r?.type === "VariableDeclaration")
|
|
291
|
+
for (const o of y(r.declarations)) {
|
|
292
|
+
const s = T(o.id), i = $(o.init);
|
|
293
|
+
s && i && t.set(s, i);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return t;
|
|
297
|
+
}
|
|
298
|
+
function Qt(e) {
|
|
299
|
+
const t = /* @__PURE__ */ new Map();
|
|
300
|
+
for (const n of y(e.body)) {
|
|
301
|
+
if (n.type !== "ExportNamedDeclaration") continue;
|
|
302
|
+
const r = $(n.declaration);
|
|
303
|
+
if (r?.type === "VariableDeclaration")
|
|
304
|
+
for (const o of y(r.declarations)) {
|
|
305
|
+
const s = T(o.id);
|
|
306
|
+
s && t.set(s, s);
|
|
307
|
+
}
|
|
308
|
+
for (const o of y(n.specifiers)) {
|
|
309
|
+
const s = I(o.exported), i = I(o.local);
|
|
310
|
+
s && i && t.set(s, i);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return t;
|
|
314
|
+
}
|
|
315
|
+
function Xt(e, t, n) {
|
|
316
|
+
if (e.type !== "CallExpression") return;
|
|
317
|
+
const r = T(e.callee), o = r ? t.get(r) : void 0;
|
|
318
|
+
if (!o || !Bt.has(o)) return;
|
|
319
|
+
const s = y(e.arguments), i = o === "mutation" ? s[0] : s[1];
|
|
320
|
+
if (!i) return {};
|
|
321
|
+
const a = ve(i, "cors", n), c = ve(
|
|
322
|
+
i,
|
|
323
|
+
"security",
|
|
324
|
+
n
|
|
325
|
+
);
|
|
326
|
+
return {
|
|
327
|
+
cors: F(a) ? a : void 0,
|
|
328
|
+
security: F(c) ? c : void 0
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
function ve(e, t, n) {
|
|
332
|
+
if (e.type === "Identifier") {
|
|
333
|
+
const o = n.get(String(e.name));
|
|
334
|
+
return F(o) ? o[t] : b;
|
|
335
|
+
}
|
|
336
|
+
if (e.type !== "ObjectExpression") return b;
|
|
337
|
+
let r;
|
|
338
|
+
for (const o of y(e.properties)) {
|
|
339
|
+
if (o.type !== "Property" || o.computed) return b;
|
|
340
|
+
I(o.key) === t && (r = P($(o.value), n));
|
|
341
|
+
}
|
|
342
|
+
return r;
|
|
343
|
+
}
|
|
344
|
+
function We(e, t, n) {
|
|
345
|
+
if (e.type === "CallExpression") {
|
|
346
|
+
const o = T(e.callee);
|
|
347
|
+
if (o && t.get(o) === "defineRoutePolicy") {
|
|
348
|
+
const s = y(e.arguments)[0];
|
|
349
|
+
return s ? We(s, t, n) : void 0;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
if (e.type !== "ObjectExpression") {
|
|
353
|
+
const o = P(e, n);
|
|
354
|
+
return F(o) ? o : void 0;
|
|
355
|
+
}
|
|
356
|
+
const r = {};
|
|
357
|
+
for (const o of y(e.properties)) {
|
|
358
|
+
if (o.type !== "Property" || o.computed) return;
|
|
359
|
+
const s = I(o.key), i = $(o.value);
|
|
360
|
+
if (!s || !i) return;
|
|
361
|
+
if (s === "document") {
|
|
362
|
+
const c = Zt(i, t, n);
|
|
363
|
+
if (!c) return;
|
|
364
|
+
r.document = c;
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
const a = P(i, n);
|
|
368
|
+
if (a === b) return;
|
|
369
|
+
r[s] = a;
|
|
370
|
+
}
|
|
371
|
+
return r;
|
|
372
|
+
}
|
|
373
|
+
function Zt(e, t, n) {
|
|
374
|
+
if (e.type !== "CallExpression") {
|
|
375
|
+
const a = P(e, n);
|
|
376
|
+
return F(a) ? a : void 0;
|
|
377
|
+
}
|
|
378
|
+
const r = $(e.callee);
|
|
379
|
+
if (r?.type !== "MemberExpression") return;
|
|
380
|
+
const o = T(r.object), s = I(r.property);
|
|
381
|
+
if (!o || t.get(o) !== "security" || !s)
|
|
382
|
+
return;
|
|
383
|
+
const i = P(y(e.arguments)[0], n);
|
|
384
|
+
if (i !== b && !(i !== void 0 && !F(i))) {
|
|
385
|
+
if (s === "api")
|
|
386
|
+
return G.api(i);
|
|
387
|
+
if (s === "crossOriginIsolated")
|
|
388
|
+
return G.crossOriginIsolated(i);
|
|
389
|
+
if (s === "static")
|
|
390
|
+
return G.static(i);
|
|
391
|
+
if (s === "strict")
|
|
392
|
+
return G.strict(i);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
function en(e, t) {
|
|
396
|
+
const n = [], r = new Set(e.declaredMethods);
|
|
397
|
+
r.has("GET") && r.add("HEAD"), r.add("OPTIONS");
|
|
398
|
+
for (const [o, s] of Object.entries(
|
|
399
|
+
e.capabilities
|
|
400
|
+
)) {
|
|
401
|
+
if (s.cors) {
|
|
402
|
+
try {
|
|
403
|
+
ot(s.cors);
|
|
404
|
+
} catch (i) {
|
|
405
|
+
n.push(K(
|
|
406
|
+
"cors-invalid",
|
|
407
|
+
t,
|
|
408
|
+
oe(i, "The CORS policy is invalid."),
|
|
409
|
+
o
|
|
410
|
+
));
|
|
411
|
+
}
|
|
412
|
+
for (const i of s.cors.methods ?? [])
|
|
413
|
+
r.has(i) || n.push(K(
|
|
414
|
+
"cors-method-unavailable",
|
|
415
|
+
t,
|
|
416
|
+
`CORS method ${i} is not available from this route.`,
|
|
417
|
+
o
|
|
418
|
+
));
|
|
419
|
+
}
|
|
420
|
+
we(s.security, t, o, n);
|
|
421
|
+
}
|
|
422
|
+
if (we(e.policy?.security, t, void 0, n), e.policy?.document)
|
|
423
|
+
try {
|
|
424
|
+
it(tn(e.policy.document), {
|
|
425
|
+
nonce: "build-verification-nonce"
|
|
426
|
+
});
|
|
427
|
+
} catch (o) {
|
|
428
|
+
n.push(K(
|
|
429
|
+
"security-header-render-failed",
|
|
430
|
+
t,
|
|
431
|
+
oe(o, "The security headers are invalid.")
|
|
432
|
+
));
|
|
433
|
+
}
|
|
434
|
+
return n;
|
|
435
|
+
}
|
|
436
|
+
function tn(e) {
|
|
437
|
+
const t = e.headers?.reportingEndpoints, n = !!(t && Object.keys(t).length), r = e.csp === !1 ? void 0 : e.csp?.reportTo;
|
|
438
|
+
return n || !r ? e : {
|
|
439
|
+
...e,
|
|
440
|
+
csp: { ...e.csp, reportTo: void 0 },
|
|
441
|
+
headers: t ? { ...e.headers, reportingEndpoints: void 0 } : e.headers
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
function we(e, t, n, r) {
|
|
445
|
+
if (e?.rateLimit)
|
|
446
|
+
try {
|
|
447
|
+
st(e.rateLimit);
|
|
448
|
+
} catch (o) {
|
|
449
|
+
r.push(K(
|
|
450
|
+
"rate-limit-invalid",
|
|
451
|
+
t,
|
|
452
|
+
oe(o, "The rate limit policy is invalid."),
|
|
453
|
+
n
|
|
454
|
+
));
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
function K(e, t, n, r) {
|
|
458
|
+
return { code: e, exportName: r, file: t, message: n, severity: "error" };
|
|
459
|
+
}
|
|
460
|
+
function nn(e) {
|
|
461
|
+
const t = /* @__PURE__ */ new Map();
|
|
462
|
+
for (const n of y(e.body))
|
|
463
|
+
if (!(n.type !== "ImportDeclaration" || $(n.source)?.value !== "@demiurgejs/core"))
|
|
464
|
+
for (const r of y(n.specifiers)) {
|
|
465
|
+
if (r.type !== "ImportSpecifier") continue;
|
|
466
|
+
const o = T(r.local), s = I(r.imported);
|
|
467
|
+
o && s && t.set(o, s);
|
|
468
|
+
}
|
|
469
|
+
return t;
|
|
470
|
+
}
|
|
471
|
+
function rn(e) {
|
|
472
|
+
const t = /* @__PURE__ */ new Map();
|
|
473
|
+
for (const n of y(e.body)) {
|
|
474
|
+
const r = n.type === "ExportNamedDeclaration" ? $(n.declaration) : n;
|
|
475
|
+
if (r?.type === "VariableDeclaration")
|
|
476
|
+
for (const o of y(r.declarations)) {
|
|
477
|
+
const s = T(o.id), i = $(o.init);
|
|
478
|
+
if (!s || !i) continue;
|
|
479
|
+
const a = P(i, t);
|
|
480
|
+
a !== b && t.set(s, a);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
return t;
|
|
484
|
+
}
|
|
485
|
+
const b = Symbol("unresolved");
|
|
486
|
+
function P(e, t) {
|
|
487
|
+
if (e) {
|
|
488
|
+
if (e.type === "Literal") return e.value;
|
|
489
|
+
if (e.type === "Identifier")
|
|
490
|
+
return e.name === "undefined" ? void 0 : t.has(String(e.name)) ? t.get(String(e.name)) : b;
|
|
491
|
+
if (e.type === "TemplateLiteral")
|
|
492
|
+
return y(e.expressions).length ? b : y(e.quasis).map((n) => $(n.value)?.cooked ?? "").join("");
|
|
493
|
+
if (e.type === "UnaryExpression") {
|
|
494
|
+
const n = P($(e.argument), t);
|
|
495
|
+
return typeof n != "number" ? b : e.operator === "-" ? -n : e.operator === "+" ? n : b;
|
|
496
|
+
}
|
|
497
|
+
if (e.type === "ArrayExpression") {
|
|
498
|
+
const n = [];
|
|
499
|
+
for (const r of y(e.elements)) {
|
|
500
|
+
const o = P(r, t);
|
|
501
|
+
if (o === b) return b;
|
|
502
|
+
n.push(o);
|
|
503
|
+
}
|
|
504
|
+
return n;
|
|
505
|
+
}
|
|
506
|
+
if (e.type === "ObjectExpression") {
|
|
507
|
+
const n = {};
|
|
508
|
+
for (const r of y(e.properties)) {
|
|
509
|
+
if (r.type !== "Property" || r.computed) return b;
|
|
510
|
+
const o = I(r.key), s = P($(r.value), t);
|
|
511
|
+
if (!o || s === b) return b;
|
|
512
|
+
n[o] = s;
|
|
513
|
+
}
|
|
514
|
+
return n;
|
|
515
|
+
}
|
|
516
|
+
return b;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
function on(e) {
|
|
520
|
+
return zt.includes(e);
|
|
521
|
+
}
|
|
522
|
+
function oe(e, t) {
|
|
523
|
+
return e instanceof Error ? e.message : t;
|
|
524
|
+
}
|
|
525
|
+
function $(e) {
|
|
526
|
+
return e && typeof e == "object" && "type" in e ? e : void 0;
|
|
527
|
+
}
|
|
528
|
+
function y(e) {
|
|
529
|
+
return Array.isArray(e) ? e.map($).filter((t) => !!t) : [];
|
|
530
|
+
}
|
|
531
|
+
function T(e) {
|
|
532
|
+
const t = $(e);
|
|
533
|
+
return t?.type === "Identifier" ? String(t.name) : void 0;
|
|
534
|
+
}
|
|
535
|
+
function I(e) {
|
|
536
|
+
const t = $(e);
|
|
537
|
+
return t?.type === "Identifier" || t?.type === "Literal" ? String(t.name ?? t.value) : void 0;
|
|
538
|
+
}
|
|
539
|
+
const Je = "/_demiurge/audit", He = [
|
|
540
|
+
"GET",
|
|
541
|
+
"POST",
|
|
542
|
+
"PUT",
|
|
543
|
+
"PATCH",
|
|
544
|
+
"DELETE",
|
|
545
|
+
"OPTIONS",
|
|
546
|
+
"HEAD"
|
|
547
|
+
];
|
|
548
|
+
function sn(e) {
|
|
549
|
+
return new URL(e.url).pathname === Je;
|
|
550
|
+
}
|
|
551
|
+
async function an(e, t) {
|
|
552
|
+
const n = new URL(t.url), r = await cn(
|
|
553
|
+
e,
|
|
554
|
+
n.searchParams.get("path") || "/",
|
|
555
|
+
t
|
|
556
|
+
), o = n.searchParams.get("format") === "json";
|
|
557
|
+
return new Response(
|
|
558
|
+
o ? JSON.stringify(r, null, 2) : dn(r),
|
|
559
|
+
{
|
|
560
|
+
headers: {
|
|
561
|
+
"cache-control": "no-store",
|
|
562
|
+
// The panel is a side channel. It declares its own policy, so the
|
|
563
|
+
// policy of the application stays unchanged. The panel runs no script.
|
|
564
|
+
"content-security-policy": "default-src 'none'; base-uri 'none'; form-action 'self'; style-src 'unsafe-inline'",
|
|
565
|
+
"content-type": o ? "application/json; charset=utf-8" : "text/html; charset=utf-8",
|
|
566
|
+
"x-robots-tag": "noindex"
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
async function cn(e, t, n) {
|
|
572
|
+
const r = new URL(n.url).origin, o = new URL(t, r), s = o.pathname, i = new Request(o, { headers: n.headers }), a = ln(e, s);
|
|
573
|
+
if (!a) {
|
|
574
|
+
const f = await fe(
|
|
575
|
+
e,
|
|
576
|
+
{ fileSegments: [] },
|
|
577
|
+
{},
|
|
578
|
+
void 0
|
|
579
|
+
);
|
|
580
|
+
return be({
|
|
581
|
+
cacheReads: [],
|
|
582
|
+
kind: "unmatched",
|
|
583
|
+
method: "GET",
|
|
584
|
+
pathname: s,
|
|
585
|
+
policy: f,
|
|
586
|
+
request: i,
|
|
587
|
+
scripts: []
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
const c = await a.route.load(), l = un(c), u = c[l], d = await fe(
|
|
591
|
+
e,
|
|
592
|
+
a.route,
|
|
593
|
+
c,
|
|
594
|
+
u
|
|
595
|
+
), h = [], v = u?.kind === "page" ? await at(
|
|
596
|
+
e,
|
|
597
|
+
s,
|
|
598
|
+
i,
|
|
599
|
+
void 0,
|
|
600
|
+
fn(h)
|
|
601
|
+
) : void 0, _ = v?.status === "ready" ? v.match : void 0;
|
|
602
|
+
return be({
|
|
603
|
+
cacheReads: h,
|
|
604
|
+
cors: u && u.kind !== "page" ? u.cors : void 0,
|
|
605
|
+
kind: u?.kind === "page" ? "page" : "resource",
|
|
606
|
+
metadata: _?.metadata,
|
|
607
|
+
method: l,
|
|
608
|
+
pathname: s,
|
|
609
|
+
policy: d,
|
|
610
|
+
request: i,
|
|
611
|
+
route: {
|
|
612
|
+
file: a.route.file,
|
|
613
|
+
groups: a.route.fileSegments.filter(lt),
|
|
614
|
+
layouts: e.layouts.filter((f) => ee(f.fileSegments, a.route.fileSegments)).map((f) => f.file),
|
|
615
|
+
methods: He.filter((f) => c[f]),
|
|
616
|
+
middlewares: e.middlewares.filter((f) => ee(f.fileSegments, a.route.fileSegments)).map((f) => f.file),
|
|
617
|
+
params: a.path,
|
|
618
|
+
pattern: ct(a.route.segments),
|
|
619
|
+
policies: e.policies.filter((f) => ee(f.fileSegments, a.route.fileSegments)).map((f) => f.file),
|
|
620
|
+
render: _?.render.mode
|
|
621
|
+
},
|
|
622
|
+
scripts: _?.scripts ?? []
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
function be(e) {
|
|
626
|
+
const t = e.kind === "page", n = t && ft(e.policy.document) ? Y() : void 0, r = e.scripts.map((i) => ({
|
|
627
|
+
...i,
|
|
628
|
+
nonce: i.nonce ?? n
|
|
629
|
+
})), o = {
|
|
630
|
+
headers: { nonce: n, request: e.request },
|
|
631
|
+
policy: e.policy.document ?? {},
|
|
632
|
+
scriptDependencies: !0
|
|
633
|
+
};
|
|
634
|
+
return {
|
|
635
|
+
audit: de({
|
|
636
|
+
document: t ? { ...o, scripts: r } : void 0,
|
|
637
|
+
route: {
|
|
638
|
+
cors: e.cors,
|
|
639
|
+
method: e.method,
|
|
640
|
+
security: e.policy.security
|
|
641
|
+
}
|
|
642
|
+
}),
|
|
643
|
+
// A nonce makes a document unique for each response. The request handler
|
|
644
|
+
// therefore replaces the cache directives of the application.
|
|
645
|
+
cacheControl: n ? "private, no-store" : void 0,
|
|
646
|
+
cacheReads: e.cacheReads,
|
|
647
|
+
kind: e.kind,
|
|
648
|
+
metadata: e.metadata,
|
|
649
|
+
method: e.method,
|
|
650
|
+
nonce: n,
|
|
651
|
+
pathname: e.pathname,
|
|
652
|
+
policy: e.policy,
|
|
653
|
+
route: e.route,
|
|
654
|
+
scripts: r.map((i) => ({
|
|
655
|
+
// One audit for each script gives the status of that script alone. The
|
|
656
|
+
// panel reads the same code path that the complete audit reads.
|
|
657
|
+
findings: de({
|
|
658
|
+
document: { ...o, scripts: [i] }
|
|
659
|
+
}).findings,
|
|
660
|
+
integrity: i.integrity,
|
|
661
|
+
nonce: i.nonce,
|
|
662
|
+
purpose: i.purpose,
|
|
663
|
+
src: i.src,
|
|
664
|
+
strategy: i.strategy
|
|
665
|
+
}))
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
function ln(e, t) {
|
|
669
|
+
try {
|
|
670
|
+
return ke(e.routes, t);
|
|
671
|
+
} catch (n) {
|
|
672
|
+
if (n instanceof ut)
|
|
673
|
+
return null;
|
|
674
|
+
throw n;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
function un(e) {
|
|
678
|
+
return He.find((t) => e[t]) ?? "GET";
|
|
679
|
+
}
|
|
680
|
+
function fn(e) {
|
|
681
|
+
const t = dt();
|
|
682
|
+
return {
|
|
683
|
+
get: async (n) => (e.push({
|
|
684
|
+
key: mt(n.key),
|
|
685
|
+
scope: n.scope ?? "request",
|
|
686
|
+
staleWhileRevalidate: $e(n.staleWhileRevalidate),
|
|
687
|
+
tags: (n.tags ?? []).map(pt),
|
|
688
|
+
ttl: $e(n.ttl)
|
|
689
|
+
}), await t.get(n)),
|
|
690
|
+
invalidateKey: t.invalidateKey,
|
|
691
|
+
invalidateTags: t.invalidateTags
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
function $e(e) {
|
|
695
|
+
return e === void 0 ? void 0 : String(e);
|
|
696
|
+
}
|
|
697
|
+
function dn(e) {
|
|
698
|
+
return `<!doctype html>
|
|
699
|
+
<html lang="en">
|
|
700
|
+
<head>
|
|
701
|
+
<meta charset="utf-8" />
|
|
702
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
703
|
+
<title>Demiurge route audit</title>
|
|
704
|
+
<style>${pn}</style>
|
|
705
|
+
</head>
|
|
706
|
+
<body>
|
|
707
|
+
<h1>Demiurge route audit</h1>
|
|
708
|
+
<form method="get" action="${Je}">
|
|
709
|
+
<label for="path">Path</label>
|
|
710
|
+
<input id="path" name="path" value="${p(e.pathname)}" />
|
|
711
|
+
<button type="submit">Audit</button>
|
|
712
|
+
</form>
|
|
713
|
+
${mn(e)}
|
|
714
|
+
${hn(e.audit.findings)}
|
|
715
|
+
${yn(e.audit.headers)}
|
|
716
|
+
${gn(e)}
|
|
717
|
+
${vn(e.metadata)}
|
|
718
|
+
${wn(e.scripts)}
|
|
719
|
+
${bn(e)}
|
|
720
|
+
<p class="footer">
|
|
721
|
+
The development server serves this panel. A production build and a static
|
|
722
|
+
export do not contain it.
|
|
723
|
+
</p>
|
|
724
|
+
</body>
|
|
725
|
+
</html>
|
|
726
|
+
`;
|
|
727
|
+
}
|
|
728
|
+
const pn = `
|
|
729
|
+
:root { color-scheme: light dark; }
|
|
730
|
+
body {
|
|
731
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
732
|
+
line-height: 1.5;
|
|
733
|
+
margin: 0 auto;
|
|
734
|
+
max-width: 60rem;
|
|
735
|
+
padding: 2rem 1rem;
|
|
736
|
+
}
|
|
737
|
+
h1 { font-size: 1.25rem; }
|
|
738
|
+
h2 { font-size: 1rem; margin-bottom: 0.25rem; }
|
|
739
|
+
form { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; }
|
|
740
|
+
input { flex: 1; padding: 0.25rem 0.5rem; }
|
|
741
|
+
section { border-top: 1px solid currentColor; padding: 0.75rem 0; }
|
|
742
|
+
table { border-collapse: collapse; width: 100%; }
|
|
743
|
+
td, th { padding: 0.25rem 0.5rem 0.25rem 0; text-align: left; vertical-align: top; }
|
|
744
|
+
th { white-space: nowrap; width: 12rem; }
|
|
745
|
+
ul { margin: 0; padding-left: 1.25rem; }
|
|
746
|
+
.empty { opacity: 0.7; }
|
|
747
|
+
.error { font-weight: 700; }
|
|
748
|
+
.footer { opacity: 0.7; }
|
|
749
|
+
`;
|
|
750
|
+
function mn(e) {
|
|
751
|
+
if (!e.route)
|
|
752
|
+
return E(
|
|
753
|
+
"Route",
|
|
754
|
+
`<p class="empty">No route matches ${p(e.pathname)}.</p>`
|
|
755
|
+
);
|
|
756
|
+
const t = e.route;
|
|
757
|
+
return E(
|
|
758
|
+
"Route",
|
|
759
|
+
A([
|
|
760
|
+
["Pathname", p(e.pathname)],
|
|
761
|
+
["Pattern", p(t.pattern)],
|
|
762
|
+
["File", p(t.file)],
|
|
763
|
+
["Kind", p(e.kind)],
|
|
764
|
+
["Method", p(e.method)],
|
|
765
|
+
["Methods", p(t.methods.join(", "))],
|
|
766
|
+
["Render mode", t.render ? p(t.render) : N()],
|
|
767
|
+
["Path values", $n(t.params)],
|
|
768
|
+
["Route groups", C(t.groups)],
|
|
769
|
+
["Layouts", C(t.layouts)],
|
|
770
|
+
["Policies", C(t.policies)],
|
|
771
|
+
["Middleware", C(t.middlewares)]
|
|
772
|
+
])
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
function hn(e) {
|
|
776
|
+
return e.length === 0 ? E("Findings", '<p class="empty">No findings.</p>') : E(
|
|
777
|
+
"Findings",
|
|
778
|
+
`<ul>${e.map(Ue).join("")}</ul>`
|
|
779
|
+
);
|
|
780
|
+
}
|
|
781
|
+
function Ue(e) {
|
|
782
|
+
return `<li${e.severity === "error" ? ' class="error"' : ""}>${p(e.severity)}: ${p(e.message)} <code>${p(e.code)}</code></li>`;
|
|
783
|
+
}
|
|
784
|
+
function yn(e) {
|
|
785
|
+
const t = Object.keys(e).sort();
|
|
786
|
+
return t.length === 0 ? E(
|
|
787
|
+
"Response headers",
|
|
788
|
+
'<p class="empty">The response carries no document header.</p>'
|
|
789
|
+
) : E(
|
|
790
|
+
"Response headers",
|
|
791
|
+
A(t.map((n) => [n, p(e[n])]))
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
function gn(e) {
|
|
795
|
+
const t = {
|
|
796
|
+
cors: e.audit.route?.cors,
|
|
797
|
+
document: e.policy.document,
|
|
798
|
+
security: e.policy.security
|
|
799
|
+
};
|
|
800
|
+
return E(
|
|
801
|
+
"Effective policy",
|
|
802
|
+
`<pre>${p(JSON.stringify(t, null, 2))}</pre>`
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
function vn(e) {
|
|
806
|
+
return e ? E(
|
|
807
|
+
"Metadata",
|
|
808
|
+
`<pre>${p(JSON.stringify(e, null, 2))}</pre>`
|
|
809
|
+
) : E("Metadata", '<p class="empty">No document metadata.</p>');
|
|
810
|
+
}
|
|
811
|
+
function wn(e) {
|
|
812
|
+
return e.length === 0 ? E("Scripts", '<p class="empty">No contributed scripts.</p>') : E(
|
|
813
|
+
"Scripts",
|
|
814
|
+
e.map(
|
|
815
|
+
(t) => A([
|
|
816
|
+
["Source", p(t.src)],
|
|
817
|
+
["Strategy", p(t.strategy)],
|
|
818
|
+
["Purpose", t.purpose ? p(t.purpose) : N()],
|
|
819
|
+
["Integrity", t.integrity ? p(t.integrity) : N()],
|
|
820
|
+
["Nonce", t.nonce ? "applied" : N()],
|
|
821
|
+
[
|
|
822
|
+
"Policy status",
|
|
823
|
+
t.findings.length === 0 ? "allowed" : `<ul>${t.findings.map(Ue).join("")}</ul>`
|
|
824
|
+
]
|
|
825
|
+
])
|
|
826
|
+
).join("")
|
|
827
|
+
);
|
|
828
|
+
}
|
|
829
|
+
function bn(e) {
|
|
830
|
+
const t = [
|
|
831
|
+
[
|
|
832
|
+
"Response cache-control",
|
|
833
|
+
e.cacheControl ? p(e.cacheControl) : N()
|
|
834
|
+
],
|
|
835
|
+
["Nonce", e.nonce ? "required" : N()]
|
|
836
|
+
];
|
|
837
|
+
return e.cacheReads.length === 0 ? E(
|
|
838
|
+
"Cache behavior",
|
|
839
|
+
`${A(t)}<p class="empty">The request read no cache entry.</p>`
|
|
840
|
+
) : E(
|
|
841
|
+
"Cache behavior",
|
|
842
|
+
`${A(t)}${e.cacheReads.map(
|
|
843
|
+
(n) => A([
|
|
844
|
+
["Key", p(n.key)],
|
|
845
|
+
["Scope", p(n.scope)],
|
|
846
|
+
["Time to live", n.ttl ? p(n.ttl) : N()],
|
|
847
|
+
[
|
|
848
|
+
"Stale while revalidate",
|
|
849
|
+
n.staleWhileRevalidate ? p(n.staleWhileRevalidate) : N()
|
|
850
|
+
],
|
|
851
|
+
["Tags", C(n.tags)]
|
|
852
|
+
])
|
|
853
|
+
).join("")}`
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
function E(e, t) {
|
|
857
|
+
return ` <section>
|
|
858
|
+
<h2>${p(e)}</h2>
|
|
859
|
+
${t}
|
|
860
|
+
</section>`;
|
|
861
|
+
}
|
|
862
|
+
function A(e) {
|
|
863
|
+
return `<table><tbody>${e.map(
|
|
864
|
+
([t, n]) => `<tr><th scope="row">${p(t)}</th><td>${n}</td></tr>`
|
|
865
|
+
).join("")}</tbody></table>`;
|
|
866
|
+
}
|
|
867
|
+
function C(e) {
|
|
868
|
+
return e.length === 0 ? N() : `<ul>${e.map((t) => `<li>${p(t)}</li>`).join("")}</ul>`;
|
|
869
|
+
}
|
|
870
|
+
function $n(e) {
|
|
871
|
+
return C(
|
|
872
|
+
Object.entries(e).map(([t, n]) => `${t} = ${String(n)}`)
|
|
873
|
+
);
|
|
874
|
+
}
|
|
875
|
+
function N() {
|
|
876
|
+
return '<span class="empty">none</span>';
|
|
877
|
+
}
|
|
878
|
+
function p(e) {
|
|
879
|
+
return e.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
880
|
+
}
|
|
881
|
+
const X = "virtual:demiurge/client-entry", ie = `/@id/${X}`, te = `\0${X}`, ze = "virtual:demiurge/server-entry", Re = `\0${ze}`, Se = ".demiurge/route-manifest.d.ts";
|
|
882
|
+
function xr(e = {}) {
|
|
883
|
+
e.locales && (e = { ...e, locales: ht(e.locales) });
|
|
884
|
+
let t = process.cwd(), n = !1;
|
|
885
|
+
const r = _t(e.env), o = /* @__PURE__ */ new Map(), s = `demiurge-${Y()}`;
|
|
886
|
+
return {
|
|
887
|
+
api: {
|
|
888
|
+
demiurge: !0,
|
|
889
|
+
fonts: e.fonts,
|
|
890
|
+
images: e.images,
|
|
891
|
+
staticDeployment: e.static?.deployment,
|
|
892
|
+
staticFileHeaders: e.static?.headers
|
|
893
|
+
},
|
|
894
|
+
enforce: "post",
|
|
895
|
+
name: "demiurge",
|
|
896
|
+
config(i, a) {
|
|
897
|
+
return In(i, a, s);
|
|
898
|
+
},
|
|
899
|
+
configResolved(i) {
|
|
900
|
+
t = i.root, n = i.command === "build";
|
|
901
|
+
},
|
|
902
|
+
resolveId(i) {
|
|
903
|
+
return i === X ? te : i === ze ? Re : null;
|
|
904
|
+
},
|
|
905
|
+
load(i) {
|
|
906
|
+
return i === te ? Fn(t, e) : i === Re ? kn(t, e) : null;
|
|
907
|
+
},
|
|
908
|
+
transform: {
|
|
909
|
+
order: "post",
|
|
910
|
+
handler(i, a, c) {
|
|
911
|
+
if (n && !c?.ssr && Tn(o, r, i, a), !Pn(t, e, a))
|
|
912
|
+
return null;
|
|
913
|
+
if (c?.ssr)
|
|
914
|
+
return n ? null : Rn(i, a);
|
|
915
|
+
const l = Sn(i);
|
|
916
|
+
return l === i ? null : { code: l, map: null };
|
|
917
|
+
}
|
|
918
|
+
},
|
|
919
|
+
generateBundle(i, a) {
|
|
920
|
+
const c = Object.values(a).find(
|
|
921
|
+
(d) => d.type === "chunk" && d.isEntry && d.facadeModuleId === te
|
|
922
|
+
);
|
|
923
|
+
if (!c)
|
|
924
|
+
return;
|
|
925
|
+
const l = Object.values(a).filter(
|
|
926
|
+
(d) => d.type === "asset" && d.fileName.endsWith(".css")
|
|
927
|
+
).map((d) => `/${d.fileName}`), u = `/${c.fileName}`;
|
|
928
|
+
this.emitFile({
|
|
929
|
+
fileName: "index.html",
|
|
930
|
+
source: rr({
|
|
931
|
+
entrySrc: u,
|
|
932
|
+
lang: e.document?.lang,
|
|
933
|
+
styles: l,
|
|
934
|
+
title: e.document?.title
|
|
935
|
+
}),
|
|
936
|
+
type: "asset"
|
|
937
|
+
}), this.emitFile({
|
|
938
|
+
fileName: "demiurge-manifest.json",
|
|
939
|
+
source: JSON.stringify({ clientEntry: u, styles: l }, null, 2),
|
|
940
|
+
type: "asset"
|
|
941
|
+
});
|
|
942
|
+
},
|
|
943
|
+
buildEnd() {
|
|
944
|
+
const i = Cn({
|
|
945
|
+
moduleIds: [...this.getModuleIds()],
|
|
946
|
+
moduleInfo: (a) => this.getModuleInfo(a),
|
|
947
|
+
references: o,
|
|
948
|
+
root: t,
|
|
949
|
+
serverEnvKeys: r
|
|
950
|
+
});
|
|
951
|
+
i.length && this.error(Wt(i));
|
|
952
|
+
},
|
|
953
|
+
async buildStart() {
|
|
954
|
+
if (o.clear(), n) {
|
|
955
|
+
await Qn(t, e);
|
|
956
|
+
const i = await Ce(t, e);
|
|
957
|
+
if (i.length)
|
|
958
|
+
throw new Error(lr(i));
|
|
959
|
+
}
|
|
960
|
+
e.typedRoutes && await Te(t, e);
|
|
961
|
+
},
|
|
962
|
+
configureServer(i) {
|
|
963
|
+
const a = async () => {
|
|
964
|
+
const f = await Ce(i.config.root, e);
|
|
965
|
+
for (const g of f)
|
|
966
|
+
i.config.logger.warn(Ye(g));
|
|
967
|
+
};
|
|
968
|
+
let c, l = Promise.resolve();
|
|
969
|
+
const u = () => {
|
|
970
|
+
l = l.then(a).catch(() => {
|
|
971
|
+
});
|
|
972
|
+
}, d = () => {
|
|
973
|
+
c && clearTimeout(c), c = setTimeout(() => {
|
|
974
|
+
c = void 0, u();
|
|
975
|
+
}, ar), c.unref?.();
|
|
976
|
+
};
|
|
977
|
+
if (i.httpServer?.once("close", () => {
|
|
978
|
+
c && (clearTimeout(c), c = void 0);
|
|
979
|
+
}), u(), e.typedRoutes) {
|
|
980
|
+
const f = x(
|
|
981
|
+
i.config.root,
|
|
982
|
+
e.routesDir ?? "src/routes"
|
|
983
|
+
), g = () => {
|
|
984
|
+
Te(i.config.root, e).catch(
|
|
985
|
+
(w) => {
|
|
986
|
+
i.config.logger.error(
|
|
987
|
+
w instanceof Error ? w.message : String(w)
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
);
|
|
991
|
+
};
|
|
992
|
+
g(), i.watcher.add(f), i.watcher.on("add", (w) => {
|
|
993
|
+
q(f, w) && (g(), d());
|
|
994
|
+
}), i.watcher.on("change", (w) => {
|
|
995
|
+
q(f, w) && (g(), d());
|
|
996
|
+
}), i.watcher.on("unlink", (w) => {
|
|
997
|
+
q(f, w) && (g(), d());
|
|
998
|
+
});
|
|
999
|
+
} else {
|
|
1000
|
+
const f = x(
|
|
1001
|
+
i.config.root,
|
|
1002
|
+
e.routesDir ?? "src/routes"
|
|
1003
|
+
);
|
|
1004
|
+
i.watcher.add(f);
|
|
1005
|
+
for (const g of ["add", "change", "unlink"])
|
|
1006
|
+
i.watcher.on(g, (w) => {
|
|
1007
|
+
q(f, w) && d();
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
const h = Jn(e), v = Hn(i, e), _ = wt({
|
|
1011
|
+
fonts: e.fonts,
|
|
1012
|
+
root: i.config.root
|
|
1013
|
+
});
|
|
1014
|
+
return i.middlewares.use(async (f, g, w) => {
|
|
1015
|
+
try {
|
|
1016
|
+
let S;
|
|
1017
|
+
try {
|
|
1018
|
+
S = pe(f, {
|
|
1019
|
+
// Vite performs its own configured host allowlist check before
|
|
1020
|
+
// Demiurge's middleware runs. Production Node listeners require
|
|
1021
|
+
// an explicit application allowlist instead.
|
|
1022
|
+
allowedHosts: [f.headers.host ?? "localhost"]
|
|
1023
|
+
});
|
|
1024
|
+
} catch (B) {
|
|
1025
|
+
if (B instanceof me) {
|
|
1026
|
+
he(g);
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1029
|
+
throw B;
|
|
1030
|
+
}
|
|
1031
|
+
if (h && sn(S)) {
|
|
1032
|
+
const B = await ne(
|
|
1033
|
+
i,
|
|
1034
|
+
f,
|
|
1035
|
+
x(i.config.root, e.routesDir ?? "src/routes")
|
|
1036
|
+
);
|
|
1037
|
+
await J(
|
|
1038
|
+
g,
|
|
1039
|
+
await an(B, S)
|
|
1040
|
+
);
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
const L = await _(S);
|
|
1044
|
+
if (L) {
|
|
1045
|
+
await J(g, L);
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
const V = await v(S);
|
|
1049
|
+
if (V) {
|
|
1050
|
+
await J(g, V);
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
1053
|
+
const U = x(
|
|
1054
|
+
i.config.root,
|
|
1055
|
+
e.routesDir ?? "src/routes"
|
|
1056
|
+
), z = await ne(i, f, U), W = Ne(
|
|
1057
|
+
i,
|
|
1058
|
+
s
|
|
1059
|
+
), Z = await ir(
|
|
1060
|
+
z,
|
|
1061
|
+
S,
|
|
1062
|
+
Un(e, W.transform)
|
|
1063
|
+
);
|
|
1064
|
+
if (Z === "next") {
|
|
1065
|
+
w();
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
De(Z, W.nonce), await J(g, Z);
|
|
1069
|
+
} catch (S) {
|
|
1070
|
+
w(S);
|
|
1071
|
+
}
|
|
1072
|
+
}), () => {
|
|
1073
|
+
i.middlewares.use(async (f, g, w) => {
|
|
1074
|
+
try {
|
|
1075
|
+
let S;
|
|
1076
|
+
try {
|
|
1077
|
+
S = pe(f, {
|
|
1078
|
+
allowedHosts: [f.headers.host ?? "localhost"]
|
|
1079
|
+
});
|
|
1080
|
+
} catch (W) {
|
|
1081
|
+
if (W instanceof me) {
|
|
1082
|
+
he(g);
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
throw W;
|
|
1086
|
+
}
|
|
1087
|
+
const L = x(
|
|
1088
|
+
i.config.root,
|
|
1089
|
+
e.routesDir ?? "src/routes"
|
|
1090
|
+
), V = await ne(i, f, L);
|
|
1091
|
+
Yn(V, L);
|
|
1092
|
+
const U = Ne(
|
|
1093
|
+
i,
|
|
1094
|
+
s
|
|
1095
|
+
), z = await yt(
|
|
1096
|
+
V,
|
|
1097
|
+
S,
|
|
1098
|
+
Kn(e, U.transform)
|
|
1099
|
+
);
|
|
1100
|
+
De(
|
|
1101
|
+
z,
|
|
1102
|
+
U.nonce
|
|
1103
|
+
), await J(g, z);
|
|
1104
|
+
} catch (S) {
|
|
1105
|
+
w(S);
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
function Rn(e, t) {
|
|
1113
|
+
if (!e.includes("import.meta"))
|
|
1114
|
+
return null;
|
|
1115
|
+
const n = Q(e), r = R(n.body).find(
|
|
1116
|
+
(l) => l.type === "ImportDeclaration" && R(l.specifiers).some(
|
|
1117
|
+
(u) => m(u.local)?.type === "Identifier" && m(u.local)?.name === "meta"
|
|
1118
|
+
)
|
|
1119
|
+
), o = r && R(r.specifiers).find(
|
|
1120
|
+
(l) => m(l.local)?.type === "Identifier" && m(l.local)?.name === "meta"
|
|
1121
|
+
), s = o && m(o.local);
|
|
1122
|
+
if (!r || !o || !s)
|
|
1123
|
+
return null;
|
|
1124
|
+
let i = "__demiurge_imported_meta__";
|
|
1125
|
+
for (; new RegExp(`\\b${i}\\b`).test(e); )
|
|
1126
|
+
i += "_";
|
|
1127
|
+
const a = new et(e), c = m(o.imported);
|
|
1128
|
+
return a.overwrite(
|
|
1129
|
+
s.start,
|
|
1130
|
+
s.end,
|
|
1131
|
+
c?.start === s.start ? `meta as ${i}` : i
|
|
1132
|
+
), a.appendLeft(r.end, `
|
|
1133
|
+
const meta = ${i};`), {
|
|
1134
|
+
code: a.toString(),
|
|
1135
|
+
map: a.generateMap({
|
|
1136
|
+
hires: "boundary",
|
|
1137
|
+
includeContent: !0,
|
|
1138
|
+
source: t
|
|
1139
|
+
})
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
function Sn(e) {
|
|
1143
|
+
const t = Q(e), n = [], r = Nn(t), o = xn(t), s = En(t), i = [];
|
|
1144
|
+
H(t, (l) => {
|
|
1145
|
+
if (l.type === "ImportDeclaration" && On(l)) {
|
|
1146
|
+
i.push(l);
|
|
1147
|
+
return;
|
|
1148
|
+
}
|
|
1149
|
+
if (l.type !== "CallExpression" || !Dn(l.callee))
|
|
1150
|
+
return;
|
|
1151
|
+
const u = R(l.arguments)[0];
|
|
1152
|
+
if (u?.type === "ObjectExpression")
|
|
1153
|
+
for (const d of R(u.properties))
|
|
1154
|
+
d.type === "Property" && O(d.key) === "data" && n.push({ end: d.end, start: d.start });
|
|
1155
|
+
});
|
|
1156
|
+
const a = [
|
|
1157
|
+
...n,
|
|
1158
|
+
...r,
|
|
1159
|
+
...o,
|
|
1160
|
+
...s
|
|
1161
|
+
];
|
|
1162
|
+
if (a.length === 0)
|
|
1163
|
+
return e;
|
|
1164
|
+
const c = [...a];
|
|
1165
|
+
for (const l of i) {
|
|
1166
|
+
const u = R(l.specifiers).map((v) => m(v.local)).filter((v) => v?.type === "Identifier").map((v) => String(v.name)), d = Mn(e, [
|
|
1167
|
+
...a,
|
|
1168
|
+
{ end: l.end, start: l.start }
|
|
1169
|
+
]), h = u.find(
|
|
1170
|
+
(v) => new RegExp(`\\b${Be(v)}\\b`).test(d)
|
|
1171
|
+
);
|
|
1172
|
+
if (h)
|
|
1173
|
+
throw new Error(
|
|
1174
|
+
`Server-only import ${JSON.stringify(h)} is used by client route code. Move that use into page data, a document contribution, or a client-safe module.`
|
|
1175
|
+
);
|
|
1176
|
+
c.push({ end: l.end, start: l.start });
|
|
1177
|
+
}
|
|
1178
|
+
return jn(e, c, (l) => n.includes(l) ? "data: undefined" : r.includes(l) || o.includes(l) ? "undefined" : s.find((u) => u === l)?.replacement ?? "");
|
|
1179
|
+
}
|
|
1180
|
+
const se = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
1181
|
+
function xn(e) {
|
|
1182
|
+
const t = [], n = /* @__PURE__ */ new Set();
|
|
1183
|
+
for (const r of R(e.body)) {
|
|
1184
|
+
if (r.type !== "ExportNamedDeclaration") continue;
|
|
1185
|
+
const o = m(r.declaration);
|
|
1186
|
+
if (o?.type === "VariableDeclaration")
|
|
1187
|
+
for (const s of R(o.declarations)) {
|
|
1188
|
+
const i = m(s.id);
|
|
1189
|
+
i?.type === "Identifier" && se.has(String(i.name)) && n.add(String(i.name));
|
|
1190
|
+
}
|
|
1191
|
+
for (const s of R(r.specifiers)) {
|
|
1192
|
+
const i = O(s.exported), a = O(s.local);
|
|
1193
|
+
i && a && se.has(i) && n.add(a);
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
return H(e, (r) => {
|
|
1197
|
+
if (r.type !== "VariableDeclarator") return;
|
|
1198
|
+
const o = m(r.id), s = m(r.init);
|
|
1199
|
+
o?.type === "Identifier" && n.has(String(o.name)) && s && t.push({ end: s.end, start: s.start });
|
|
1200
|
+
}), t;
|
|
1201
|
+
}
|
|
1202
|
+
function En(e) {
|
|
1203
|
+
const t = [];
|
|
1204
|
+
for (const n of R(e.body)) {
|
|
1205
|
+
if (n.type !== "ExportNamedDeclaration") continue;
|
|
1206
|
+
const r = m(n.source)?.value;
|
|
1207
|
+
if (typeof r != "string") continue;
|
|
1208
|
+
const o = [], s = [];
|
|
1209
|
+
for (const c of R(n.specifiers)) {
|
|
1210
|
+
const l = O(c.exported), u = O(c.local);
|
|
1211
|
+
!l || !u || (se.has(l) ? s.push(l) : o.push(u === l ? u : `${u} as ${l}`));
|
|
1212
|
+
}
|
|
1213
|
+
if (s.length === 0) continue;
|
|
1214
|
+
const i = o.length > 0 ? `export { ${o.join(", ")} } from ${JSON.stringify(r)};
|
|
1215
|
+
` : "", a = s.map((c) => `export const ${c} = undefined;`).join(`
|
|
1216
|
+
`);
|
|
1217
|
+
t.push({
|
|
1218
|
+
end: n.end,
|
|
1219
|
+
replacement: `${i}${a}`,
|
|
1220
|
+
start: n.start
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
return t;
|
|
1224
|
+
}
|
|
1225
|
+
const xe = /* @__PURE__ */ new Set(["links", "metadata", "scripts"]);
|
|
1226
|
+
function Nn(e) {
|
|
1227
|
+
const t = /* @__PURE__ */ new Set();
|
|
1228
|
+
for (const r of R(e.body)) {
|
|
1229
|
+
if (r.type !== "ExportNamedDeclaration") continue;
|
|
1230
|
+
const o = m(r.declaration);
|
|
1231
|
+
if (o?.type === "VariableDeclaration")
|
|
1232
|
+
for (const s of R(o.declarations)) {
|
|
1233
|
+
const i = m(s.id);
|
|
1234
|
+
i?.type === "Identifier" && xe.has(String(i.name)) && t.add(String(i.name));
|
|
1235
|
+
}
|
|
1236
|
+
for (const s of R(r.specifiers)) {
|
|
1237
|
+
const i = O(s.exported), a = O(s.local);
|
|
1238
|
+
i && a && xe.has(i) && t.add(a);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
const n = [];
|
|
1242
|
+
return H(e, (r) => {
|
|
1243
|
+
if (r.type !== "VariableDeclarator") return;
|
|
1244
|
+
const o = m(r.id), s = m(r.init);
|
|
1245
|
+
o?.type === "Identifier" && t.has(String(o.name)) && s && n.push({ end: s.end, start: s.start });
|
|
1246
|
+
}), n;
|
|
1247
|
+
}
|
|
1248
|
+
function Pn(e, t, n) {
|
|
1249
|
+
const r = n.split("?", 1)[0] ?? n, o = x(e, t.routesDir ?? "src/routes"), s = D(o, r);
|
|
1250
|
+
return s !== "" && s !== ".." && !s.startsWith(`..${j}`);
|
|
1251
|
+
}
|
|
1252
|
+
function H(e, t) {
|
|
1253
|
+
if (!e || typeof e != "object") return;
|
|
1254
|
+
if (Array.isArray(e)) {
|
|
1255
|
+
for (const r of e) H(r, t);
|
|
1256
|
+
return;
|
|
1257
|
+
}
|
|
1258
|
+
const n = e;
|
|
1259
|
+
if (typeof n.type == "string") {
|
|
1260
|
+
t(n);
|
|
1261
|
+
for (const [r, o] of Object.entries(n))
|
|
1262
|
+
(/* @__PURE__ */ new Set(["end", "loc", "start", "type"])).has(r) || H(o, t);
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
function m(e) {
|
|
1266
|
+
return e && typeof e == "object" && "type" in e ? e : void 0;
|
|
1267
|
+
}
|
|
1268
|
+
function R(e) {
|
|
1269
|
+
return Array.isArray(e) ? e.map(m).filter((t) => !!t) : [];
|
|
1270
|
+
}
|
|
1271
|
+
function Dn(e) {
|
|
1272
|
+
const t = m(e);
|
|
1273
|
+
return t?.type === "Identifier" ? t.name === "page" : t?.type === "MemberExpression" && O(t.property) === "page";
|
|
1274
|
+
}
|
|
1275
|
+
function O(e) {
|
|
1276
|
+
const t = m(e);
|
|
1277
|
+
return t?.type === "Identifier" || t?.type === "Literal" ? String(t.name ?? t.value) : void 0;
|
|
1278
|
+
}
|
|
1279
|
+
function On(e) {
|
|
1280
|
+
const t = m(e.source)?.value;
|
|
1281
|
+
return typeof t == "string" && /(?:^|[/.-])server(?:[/.-]|$)/.test(t);
|
|
1282
|
+
}
|
|
1283
|
+
function Mn(e, t) {
|
|
1284
|
+
const n = [...e];
|
|
1285
|
+
for (const { end: r, start: o } of t)
|
|
1286
|
+
n.fill(" ", o, r);
|
|
1287
|
+
return n.join("");
|
|
1288
|
+
}
|
|
1289
|
+
function jn(e, t, n) {
|
|
1290
|
+
return [...t].sort((r, o) => o.start - r.start).reduce(
|
|
1291
|
+
(r, o) => `${r.slice(0, o.start)}${n(o)}${r.slice(o.end)}`,
|
|
1292
|
+
e
|
|
1293
|
+
);
|
|
1294
|
+
}
|
|
1295
|
+
function Be(e) {
|
|
1296
|
+
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1297
|
+
}
|
|
1298
|
+
function In(e, t, n) {
|
|
1299
|
+
return {
|
|
1300
|
+
appType: "custom",
|
|
1301
|
+
build: {
|
|
1302
|
+
assetsInlineLimit: e.build?.assetsInlineLimit ?? 0,
|
|
1303
|
+
...t.isSsrBuild && e.build?.target === void 0 && e.ssr?.target !== "webworker" ? { target: "node22.13" } : {},
|
|
1304
|
+
rollupOptions: {
|
|
1305
|
+
input: e.build?.rollupOptions?.input ?? X
|
|
1306
|
+
}
|
|
1307
|
+
},
|
|
1308
|
+
...t.command === "serve" ? {
|
|
1309
|
+
html: { cspNonce: n },
|
|
1310
|
+
ssr: { external: [M] }
|
|
1311
|
+
} : {}
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
function Tn(e, t, n, r) {
|
|
1315
|
+
if (!t.size || r.includes("/node_modules/") || r.startsWith("\0")) return;
|
|
1316
|
+
const o = Lt(n, t.keys());
|
|
1317
|
+
o.length && e.set(r, o);
|
|
1318
|
+
}
|
|
1319
|
+
function Cn(e) {
|
|
1320
|
+
const { moduleIds: t, moduleInfo: n, references: r, root: o, serverEnvKeys: s } = e;
|
|
1321
|
+
if (!r.size) return [];
|
|
1322
|
+
const i = t.filter((l) => n(l)?.isEntry), a = (l) => {
|
|
1323
|
+
const u = n(l);
|
|
1324
|
+
return u ? [...u.importedIds, ...u.dynamicallyImportedIds] : [];
|
|
1325
|
+
}, c = [];
|
|
1326
|
+
for (const l of [...r.keys()].sort()) {
|
|
1327
|
+
const d = i.map((h) => Vt(h, l, a)).filter((h) => !!h).sort((h, v) => h.length - v.length)[0];
|
|
1328
|
+
if (d)
|
|
1329
|
+
for (const h of r.get(l) ?? [])
|
|
1330
|
+
c.push({
|
|
1331
|
+
code: s.get(h)?.sensitive ? "client-secret" : "client-server-only",
|
|
1332
|
+
importPath: d.map((v) => Ee(o, v)),
|
|
1333
|
+
key: h,
|
|
1334
|
+
module: Ee(o, l)
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
return c;
|
|
1338
|
+
}
|
|
1339
|
+
function Ee(e, t) {
|
|
1340
|
+
const n = t.startsWith("\0") ? t.slice(1) : t;
|
|
1341
|
+
return n.startsWith(e) && D(e, n) || n;
|
|
1342
|
+
}
|
|
1343
|
+
function An(e = {}, t = process.env) {
|
|
1344
|
+
const n = Object.entries(e.env ?? {}).filter(([, i]) => i.client);
|
|
1345
|
+
if (!n.length) return "";
|
|
1346
|
+
const r = n.filter(
|
|
1347
|
+
([i, a]) => a.critical && !t[i]
|
|
1348
|
+
);
|
|
1349
|
+
if (r.length)
|
|
1350
|
+
throw new Error(
|
|
1351
|
+
[
|
|
1352
|
+
"Demiurge stopped the build. The environment of the build does not have a critical client variable.",
|
|
1353
|
+
...r.map(([i]) => ` variable: ${i}`),
|
|
1354
|
+
" The build inlines the value of a client variable. Give the value to the build."
|
|
1355
|
+
].join(`
|
|
1356
|
+
`)
|
|
1357
|
+
);
|
|
1358
|
+
const o = _e(Object.fromEntries(n)), s = Object.fromEntries(
|
|
1359
|
+
n.map(([i]) => [i, t[i]]).filter(([, i]) => i !== void 0)
|
|
1360
|
+
);
|
|
1361
|
+
return `
|
|
1362
|
+
// The build put these values in the browser bundle. The schema declares each
|
|
1363
|
+
// one as a client variable.
|
|
1364
|
+
unstable_startEnvironment(${JSON.stringify(o)}, { source: ${JSON.stringify(s)} });
|
|
1365
|
+
`;
|
|
1366
|
+
}
|
|
1367
|
+
function Fn(e, t = {}, n = process.env) {
|
|
1368
|
+
const r = t.routesDir ?? "src/routes", o = Wn(e, t), s = An(t, n);
|
|
1369
|
+
return `import { hydrateFileRouter${s ? ", unstable_startEnvironment" : ""} } from "${M}";
|
|
1370
|
+
${o}
|
|
1371
|
+
${s}
|
|
1372
|
+
${Ge(r, {
|
|
1373
|
+
exportRoutes: !1,
|
|
1374
|
+
includeServerOnly: !1
|
|
1375
|
+
})}
|
|
1376
|
+
|
|
1377
|
+
void hydrateFileRouter({ routes${t.locales ? `, locales: ${JSON.stringify(t.locales)}` : ""} });
|
|
1378
|
+
`;
|
|
1379
|
+
}
|
|
1380
|
+
function kn(e, t = {}) {
|
|
1381
|
+
const n = t.routesDir ?? "src/routes", r = !!(t.env && Object.keys(t.env).length), o = r ? ", unstable_startEnvironment" : "", s = r ? `
|
|
1382
|
+
// The framework validates the declared environment before the server accepts
|
|
1383
|
+
// traffic. A critical variable that is absent or invalid stops the start.
|
|
1384
|
+
export const env = unstable_startEnvironment(${JSON.stringify(_e(t.env ?? {}))}).values;
|
|
1385
|
+
` : "";
|
|
1386
|
+
return `import { createRequestHandler${o} } from "${M}";
|
|
1387
|
+
${s}
|
|
1388
|
+
${Ge(n, {
|
|
1389
|
+
exportRoutes: !0,
|
|
1390
|
+
includeServerOnly: !0,
|
|
1391
|
+
eagerModules: !0
|
|
1392
|
+
})}
|
|
1393
|
+
|
|
1394
|
+
export function createHandler(options = {}) {
|
|
1395
|
+
const { clientEntry, lang, locales, styles, title, ...handlerOptions } = options;
|
|
1396
|
+
|
|
1397
|
+
return createRequestHandler({
|
|
1398
|
+
...handlerOptions,
|
|
1399
|
+
routes,
|
|
1400
|
+
routeModules,
|
|
1401
|
+
locales: locales ?? ${JSON.stringify(t.locales)},
|
|
1402
|
+
ssr: {
|
|
1403
|
+
clientEntry,
|
|
1404
|
+
lang: lang ?? ${JSON.stringify(t.document?.lang)},
|
|
1405
|
+
styles,
|
|
1406
|
+
title: title ?? ${JSON.stringify(t.document?.title)},
|
|
1407
|
+
},
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
`;
|
|
1411
|
+
}
|
|
1412
|
+
function Ge(e, {
|
|
1413
|
+
exportRoutes: t,
|
|
1414
|
+
eagerModules: n = !1,
|
|
1415
|
+
includeServerOnly: r
|
|
1416
|
+
}) {
|
|
1417
|
+
const o = Ln(e, r), s = Vn(e);
|
|
1418
|
+
return n ? `const eagerRouteModules = import.meta.glob(${JSON.stringify(o)}, { eager: true });
|
|
1419
|
+
const routePrefix = ${JSON.stringify(s)};
|
|
1420
|
+
export const routeModules = Object.fromEntries(
|
|
1421
|
+
Object.entries(eagerRouteModules).map(([file, module]) => [
|
|
1422
|
+
\`./routes/\${file.slice(routePrefix.length)}\`,
|
|
1423
|
+
module,
|
|
1424
|
+
]),
|
|
1425
|
+
);
|
|
1426
|
+
${t ? "export " : ""}const routes = Object.fromEntries(
|
|
1427
|
+
Object.entries(routeModules).map(([file, module]) => [
|
|
1428
|
+
file,
|
|
1429
|
+
async () => module,
|
|
1430
|
+
]),
|
|
1431
|
+
);` : `const routeModules = import.meta.glob(${JSON.stringify(o)});
|
|
1432
|
+
const routePrefix = ${JSON.stringify(s)};
|
|
1433
|
+
${t ? "export " : ""}const routes = Object.fromEntries(
|
|
1434
|
+
Object.entries(routeModules).map(([file, load]) => [
|
|
1435
|
+
\`./routes/\${file.slice(routePrefix.length)}\`,
|
|
1436
|
+
load,
|
|
1437
|
+
]),
|
|
1438
|
+
);`;
|
|
1439
|
+
}
|
|
1440
|
+
const _n = ["@middleware.ts", "@policy.ts"];
|
|
1441
|
+
function Ln(e, t) {
|
|
1442
|
+
const n = `/${e.replace(/^\/|\/$/g, "")}`, r = [`${n}/**/*.{ts,tsx}`];
|
|
1443
|
+
return t || r.push(
|
|
1444
|
+
..._n.flatMap((o) => [
|
|
1445
|
+
`!${n}/${o}`,
|
|
1446
|
+
`!${n}/**/${o}`
|
|
1447
|
+
])
|
|
1448
|
+
), r;
|
|
1449
|
+
}
|
|
1450
|
+
function Vn(e) {
|
|
1451
|
+
return `/${e.replace(/^\/|\/$/g, "")}/`;
|
|
1452
|
+
}
|
|
1453
|
+
function Wn(e, t) {
|
|
1454
|
+
if (t.styles === !1)
|
|
1455
|
+
return "";
|
|
1456
|
+
const n = t.styles ?? "src/styles.css", r = x(e, n);
|
|
1457
|
+
return ae(r) ? `import ${JSON.stringify(`/${n.replace(/^\/+/, "")}`)};` : "";
|
|
1458
|
+
}
|
|
1459
|
+
function Jn(e) {
|
|
1460
|
+
return e.devtools !== !1 && process.env.NODE_ENV !== "production";
|
|
1461
|
+
}
|
|
1462
|
+
function Hn(e, t) {
|
|
1463
|
+
const n = e.config.publicDir, r = t.images?.optimizerPath ?? "/_demiurge/image";
|
|
1464
|
+
return n ? bt({
|
|
1465
|
+
policy: t.images,
|
|
1466
|
+
resolveVariant: (o) => Rt(o, r),
|
|
1467
|
+
root: n
|
|
1468
|
+
}) : async () => null;
|
|
1469
|
+
}
|
|
1470
|
+
function Un(e, t) {
|
|
1471
|
+
return {
|
|
1472
|
+
dev: !0,
|
|
1473
|
+
ssr: Ke(e),
|
|
1474
|
+
transformDocument: t,
|
|
1475
|
+
renderPage: async (n, r) => {
|
|
1476
|
+
if (n.render.mode === "streaming")
|
|
1477
|
+
return await $t(n, {
|
|
1478
|
+
...r,
|
|
1479
|
+
clientEntry: ie,
|
|
1480
|
+
transformDocument: t
|
|
1481
|
+
});
|
|
1482
|
+
const o = await t(
|
|
1483
|
+
rt(n, {
|
|
1484
|
+
...r,
|
|
1485
|
+
clientEntry: ie
|
|
1486
|
+
})
|
|
1487
|
+
);
|
|
1488
|
+
return new Response(o, {
|
|
1489
|
+
headers: { "content-type": "text/html; charset=utf-8" }
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1492
|
+
};
|
|
1493
|
+
}
|
|
1494
|
+
function Ne(e, t) {
|
|
1495
|
+
const n = Y(), r = Y();
|
|
1496
|
+
return {
|
|
1497
|
+
nonce: n,
|
|
1498
|
+
transform: async (o) => {
|
|
1499
|
+
const s = zn(o, r), i = await e.transformIndexHtml("/", s);
|
|
1500
|
+
return Pe(
|
|
1501
|
+
Pe(i, r),
|
|
1502
|
+
t,
|
|
1503
|
+
n
|
|
1504
|
+
);
|
|
1505
|
+
}
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1508
|
+
function zn(e, t) {
|
|
1509
|
+
const n = e.toLowerCase();
|
|
1510
|
+
let r = 0, o = "";
|
|
1511
|
+
for (; r < e.length; ) {
|
|
1512
|
+
const s = e.indexOf("<", r);
|
|
1513
|
+
if (s === -1)
|
|
1514
|
+
return o + e.slice(r);
|
|
1515
|
+
if (o += e.slice(r, s), n.startsWith("<!--", s)) {
|
|
1516
|
+
const l = n.indexOf("-->", s + 4), u = l === -1 ? e.length : l + 3;
|
|
1517
|
+
o += e.slice(s, u), r = u;
|
|
1518
|
+
continue;
|
|
1519
|
+
}
|
|
1520
|
+
const i = n.slice(s).match(/^<\s*(script|style|link)\b/)?.[1];
|
|
1521
|
+
if (!i) {
|
|
1522
|
+
o += "<", r = s + 1;
|
|
1523
|
+
continue;
|
|
1524
|
+
}
|
|
1525
|
+
const a = Bn(e, s);
|
|
1526
|
+
if (a === -1)
|
|
1527
|
+
return o + e.slice(s);
|
|
1528
|
+
const c = e.slice(s, a + 1);
|
|
1529
|
+
if (o += /(?:^|\s)nonce(?:\s|=|>)/i.test(c) ? c : Gn(c, t), r = a + 1, i === "script" || i === "style") {
|
|
1530
|
+
const l = n.indexOf(`</${i}`, r);
|
|
1531
|
+
if (l === -1)
|
|
1532
|
+
return o + e.slice(r);
|
|
1533
|
+
o += e.slice(r, l), r = l;
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
return o;
|
|
1537
|
+
}
|
|
1538
|
+
function Bn(e, t) {
|
|
1539
|
+
let n;
|
|
1540
|
+
for (let r = t + 1; r < e.length; r++) {
|
|
1541
|
+
const o = e[r];
|
|
1542
|
+
if (n) {
|
|
1543
|
+
o === n && (n = void 0);
|
|
1544
|
+
continue;
|
|
1545
|
+
}
|
|
1546
|
+
if (o === '"' || o === "'")
|
|
1547
|
+
n = o;
|
|
1548
|
+
else if (o === ">")
|
|
1549
|
+
return r;
|
|
1550
|
+
}
|
|
1551
|
+
return -1;
|
|
1552
|
+
}
|
|
1553
|
+
function Gn(e, t) {
|
|
1554
|
+
const n = /\/\s*>$/.test(e) ? e.lastIndexOf("/") : e.length - 1;
|
|
1555
|
+
return `${e.slice(0, n)} nonce="${t}"${e.slice(n)}`;
|
|
1556
|
+
}
|
|
1557
|
+
function Pe(e, t, n) {
|
|
1558
|
+
const r = new RegExp(
|
|
1559
|
+
`(\\snonce\\s*=\\s*)(["'])${Be(t)}\\2`,
|
|
1560
|
+
"g"
|
|
1561
|
+
);
|
|
1562
|
+
return e.replace(
|
|
1563
|
+
r,
|
|
1564
|
+
n ? `$1"${n}"` : ""
|
|
1565
|
+
);
|
|
1566
|
+
}
|
|
1567
|
+
function De(e, t) {
|
|
1568
|
+
const n = e.headers.get("content-type"), r = e.headers.get("content-security-policy");
|
|
1569
|
+
if (!n?.toLowerCase().startsWith("text/html") || !r)
|
|
1570
|
+
return;
|
|
1571
|
+
const o = `'nonce-${t}'`, s = Oe(
|
|
1572
|
+
r,
|
|
1573
|
+
["script-src-elem", "script-src"],
|
|
1574
|
+
"script-src",
|
|
1575
|
+
o
|
|
1576
|
+
), i = qn(
|
|
1577
|
+
s,
|
|
1578
|
+
["style-src-elem", "style-src"]
|
|
1579
|
+
) ? s : Oe(
|
|
1580
|
+
s,
|
|
1581
|
+
["style-src-elem", "style-src"],
|
|
1582
|
+
"style-src",
|
|
1583
|
+
o
|
|
1584
|
+
);
|
|
1585
|
+
e.headers.set("content-security-policy", i), e.headers.set("cache-control", "private, no-store");
|
|
1586
|
+
}
|
|
1587
|
+
function Oe(e, t, n, r) {
|
|
1588
|
+
const o = e.split(";").map((u) => u.trim()), s = qe(o, t), i = o.find(
|
|
1589
|
+
(u) => u.split(/\s+/, 1)[0]?.toLowerCase() === "default-src"
|
|
1590
|
+
);
|
|
1591
|
+
if (s === -1 && !i) return e;
|
|
1592
|
+
const [a, ...c] = (s === -1 ? i : o[s]).split(/\s+/), l = [
|
|
1593
|
+
s === -1 ? n : a,
|
|
1594
|
+
.../* @__PURE__ */ new Set([
|
|
1595
|
+
...c.filter((u) => u !== "'none'"),
|
|
1596
|
+
r
|
|
1597
|
+
])
|
|
1598
|
+
].join(" ");
|
|
1599
|
+
return s === -1 ? o.push(l) : o[s] = l, o.join("; ");
|
|
1600
|
+
}
|
|
1601
|
+
function qn(e, t) {
|
|
1602
|
+
const n = e.split(";").map((i) => i.trim()), r = qe(n, t), s = (r === -1 ? n.find(
|
|
1603
|
+
(i) => i.split(/\s+/, 1)[0]?.toLowerCase() === "default-src"
|
|
1604
|
+
) : n[r])?.split(/\s+/).slice(1) ?? [];
|
|
1605
|
+
return s.includes("'unsafe-inline'") && !s.some((i) => /^'(?:nonce-|sha(?:256|384|512)-)/i.test(i));
|
|
1606
|
+
}
|
|
1607
|
+
function qe(e, t) {
|
|
1608
|
+
for (const n of t) {
|
|
1609
|
+
const r = e.findIndex(
|
|
1610
|
+
(o) => o.split(/\s+/, 1)[0]?.toLowerCase() === n
|
|
1611
|
+
);
|
|
1612
|
+
if (r !== -1) return r;
|
|
1613
|
+
}
|
|
1614
|
+
return -1;
|
|
1615
|
+
}
|
|
1616
|
+
const Me = Symbol.for("demiurge.devManifest");
|
|
1617
|
+
async function ne(e, t, n) {
|
|
1618
|
+
const r = t, o = r[Me];
|
|
1619
|
+
if (o)
|
|
1620
|
+
return o;
|
|
1621
|
+
const s = vt(
|
|
1622
|
+
await or(e, n)
|
|
1623
|
+
);
|
|
1624
|
+
return r[Me] = s, s;
|
|
1625
|
+
}
|
|
1626
|
+
function Ke(e) {
|
|
1627
|
+
return {
|
|
1628
|
+
clientEntry: ie,
|
|
1629
|
+
lang: e.document?.lang,
|
|
1630
|
+
title: e.document?.title
|
|
1631
|
+
};
|
|
1632
|
+
}
|
|
1633
|
+
function Kn(e, t) {
|
|
1634
|
+
return {
|
|
1635
|
+
...Ke(e),
|
|
1636
|
+
dev: !0,
|
|
1637
|
+
transformDocument: t
|
|
1638
|
+
};
|
|
1639
|
+
}
|
|
1640
|
+
const je = /* @__PURE__ */ new Set();
|
|
1641
|
+
function Yn(e, t) {
|
|
1642
|
+
je.has(t) || e.fallbacks.notFound.some(
|
|
1643
|
+
(n) => n.fileSegments.length === 0
|
|
1644
|
+
) || (je.add(t), console.warn(nr(Ze(t, "@not-found.tsx"))));
|
|
1645
|
+
}
|
|
1646
|
+
async function Qn(e, t = {}) {
|
|
1647
|
+
const n = t.routesDir ?? "src/routes", r = x(e, n);
|
|
1648
|
+
if (!ae(r))
|
|
1649
|
+
return;
|
|
1650
|
+
const o = await ue(r);
|
|
1651
|
+
if (o.map(
|
|
1652
|
+
(a) => D(r, a).split(j).join("/")
|
|
1653
|
+
).some((a) => /^@not-found\.tsx?$/.test(a)))
|
|
1654
|
+
return;
|
|
1655
|
+
const i = await Xn(o);
|
|
1656
|
+
if (i)
|
|
1657
|
+
throw new Error(
|
|
1658
|
+
tr(
|
|
1659
|
+
n,
|
|
1660
|
+
D(r, i).split(j).join("/")
|
|
1661
|
+
)
|
|
1662
|
+
);
|
|
1663
|
+
}
|
|
1664
|
+
async function Xn(e) {
|
|
1665
|
+
for (const t of e)
|
|
1666
|
+
if (!D(ce(t), t).startsWith("@") && er(await Fe(t, "utf8")))
|
|
1667
|
+
return t;
|
|
1668
|
+
}
|
|
1669
|
+
const Zn = M.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), Ie = new RegExp(
|
|
1670
|
+
`import\\s*\\{([^}]*)\\}\\s*from\\s*["']${Zn}["']`,
|
|
1671
|
+
"g"
|
|
1672
|
+
);
|
|
1673
|
+
function er(e) {
|
|
1674
|
+
const t = [...e.matchAll(Ie)].flatMap(
|
|
1675
|
+
(r) => r[1].split(",").flatMap((o) => {
|
|
1676
|
+
const [s, i] = o.trim().split(/\s+as\s+/);
|
|
1677
|
+
return s.replace(/^type\s+/, "") === "page" ? [i ?? s] : [];
|
|
1678
|
+
})
|
|
1679
|
+
);
|
|
1680
|
+
if (t.length === 0)
|
|
1681
|
+
return !1;
|
|
1682
|
+
const n = e.replace(Ie, "");
|
|
1683
|
+
return t.some((r) => new RegExp(`\\b${r}\\s*\\(`).test(n));
|
|
1684
|
+
}
|
|
1685
|
+
function tr(e, t) {
|
|
1686
|
+
return `Demiurge will not build an app with page routes and no ${e}/@not-found.tsx.
|
|
1687
|
+
|
|
1688
|
+
"${t}" declares a page, so a browser can reach a path this app does not serve. Decide what that looks like rather than shipping the framework built-in.
|
|
1689
|
+
|
|
1690
|
+
Create ${e}/@not-found.tsx:
|
|
1691
|
+
|
|
1692
|
+
export default function NotFound({ pathname }: { pathname: string }) {
|
|
1693
|
+
return <h1>Nothing at {pathname}</h1>;
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
It renders inside the layouts above the requested path. Opt out with "export const layout = false".`;
|
|
1697
|
+
}
|
|
1698
|
+
function nr(e) {
|
|
1699
|
+
return `Demiurge is serving its built-in 404 because ${e} does not exist.
|
|
1700
|
+
|
|
1701
|
+
Create it before building for production:
|
|
1702
|
+
|
|
1703
|
+
export default function NotFound({ pathname }: { pathname: string }) {
|
|
1704
|
+
return <h1>Nothing at {pathname}</h1>;
|
|
1705
|
+
}
|
|
1706
|
+
`;
|
|
1707
|
+
}
|
|
1708
|
+
function rr({
|
|
1709
|
+
entrySrc: e,
|
|
1710
|
+
lang: t,
|
|
1711
|
+
links: n,
|
|
1712
|
+
metadata: r,
|
|
1713
|
+
nonce: o,
|
|
1714
|
+
scripts: s,
|
|
1715
|
+
styles: i,
|
|
1716
|
+
title: a
|
|
1717
|
+
}) {
|
|
1718
|
+
return nt({
|
|
1719
|
+
entrySrc: e,
|
|
1720
|
+
lang: t,
|
|
1721
|
+
links: n,
|
|
1722
|
+
metadata: r,
|
|
1723
|
+
nonce: o,
|
|
1724
|
+
scripts: s,
|
|
1725
|
+
styles: i,
|
|
1726
|
+
title: a
|
|
1727
|
+
});
|
|
1728
|
+
}
|
|
1729
|
+
async function Te(e, t) {
|
|
1730
|
+
const n = x(e, t.routesDir ?? "src/routes"), r = x(
|
|
1731
|
+
e,
|
|
1732
|
+
typeof t.typedRoutes == "object" ? t.typedRoutes.outputFile ?? Se : Se
|
|
1733
|
+
);
|
|
1734
|
+
await St({
|
|
1735
|
+
outputFile: r,
|
|
1736
|
+
routesDir: n,
|
|
1737
|
+
locales: t.locales?.supportedLocales,
|
|
1738
|
+
localeNamespaces: [
|
|
1739
|
+
...Object.values(t.locales?.path?.labels ?? {}),
|
|
1740
|
+
...Object.keys(t.locales?.aliases ?? {}),
|
|
1741
|
+
...t.locales?.path?.reserved ?? []
|
|
1742
|
+
]
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1745
|
+
function q(e, t) {
|
|
1746
|
+
return t.startsWith(e) && /\.tsx?$/.test(t);
|
|
1747
|
+
}
|
|
1748
|
+
async function or(e, t) {
|
|
1749
|
+
const n = await ue(t), r = {};
|
|
1750
|
+
for (const o of n) {
|
|
1751
|
+
const s = ur(t, o);
|
|
1752
|
+
r[s] = async () => await e.ssrLoadModule(o);
|
|
1753
|
+
}
|
|
1754
|
+
return r;
|
|
1755
|
+
}
|
|
1756
|
+
async function ir(e, t, n = {}) {
|
|
1757
|
+
const r = new URL(t.url);
|
|
1758
|
+
return ke(e.routes, r.pathname) ? await gt(e, t, n) : "next";
|
|
1759
|
+
}
|
|
1760
|
+
async function ue(e) {
|
|
1761
|
+
return (await Ae(e, {
|
|
1762
|
+
recursive: !0,
|
|
1763
|
+
withFileTypes: !0
|
|
1764
|
+
})).filter((n) => n.isFile() && /\.tsx?$/.test(n.name)).map((n) => x(n.parentPath, n.name));
|
|
1765
|
+
}
|
|
1766
|
+
const sr = 8, ar = 50;
|
|
1767
|
+
async function cr(e, t, n) {
|
|
1768
|
+
const r = new Array(e.length);
|
|
1769
|
+
let o = 0;
|
|
1770
|
+
const s = Array.from(
|
|
1771
|
+
{ length: Math.min(t, e.length) },
|
|
1772
|
+
async () => {
|
|
1773
|
+
for (; o < e.length; ) {
|
|
1774
|
+
const i = o++;
|
|
1775
|
+
r[i] = await n(e[i]);
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
);
|
|
1779
|
+
return await Promise.all(s), r;
|
|
1780
|
+
}
|
|
1781
|
+
async function Ce(e, t = {}) {
|
|
1782
|
+
const n = x(e, t.routesDir ?? "src/routes");
|
|
1783
|
+
return ae(n) ? (await cr(
|
|
1784
|
+
await ue(n),
|
|
1785
|
+
sr,
|
|
1786
|
+
Gt
|
|
1787
|
+
)).flat().sort(
|
|
1788
|
+
(o, s) => o.file.localeCompare(s.file) || (o.exportName ?? "").localeCompare(s.exportName ?? "") || o.code.localeCompare(s.code)
|
|
1789
|
+
) : [];
|
|
1790
|
+
}
|
|
1791
|
+
function lr(e) {
|
|
1792
|
+
return [
|
|
1793
|
+
"Demiurge found invalid static route policy:",
|
|
1794
|
+
...e.map(Ye)
|
|
1795
|
+
].join(`
|
|
1796
|
+
`);
|
|
1797
|
+
}
|
|
1798
|
+
function Ye(e) {
|
|
1799
|
+
return `${e.exportName ? `${e.file} export ${e.exportName}` : e.file}: [${e.code}] ${e.message}`;
|
|
1800
|
+
}
|
|
1801
|
+
function ur(e, t) {
|
|
1802
|
+
return `./routes/${D(e, t).split(j).join("/")}`;
|
|
1803
|
+
}
|
|
1804
|
+
export {
|
|
1805
|
+
Je as R,
|
|
1806
|
+
Qn as a,
|
|
1807
|
+
An as b,
|
|
1808
|
+
Fn as c,
|
|
1809
|
+
or as d,
|
|
1810
|
+
rr as e,
|
|
1811
|
+
cn as f,
|
|
1812
|
+
kn as g,
|
|
1813
|
+
er as h,
|
|
1814
|
+
xr as i,
|
|
1815
|
+
Vt as j,
|
|
1816
|
+
Lt as k,
|
|
1817
|
+
_t as l,
|
|
1818
|
+
Wt as m,
|
|
1819
|
+
lr as n,
|
|
1820
|
+
ir as o,
|
|
1821
|
+
Jn as p,
|
|
1822
|
+
qt as q,
|
|
1823
|
+
dn as r,
|
|
1824
|
+
Sn as s,
|
|
1825
|
+
Ce as v
|
|
1826
|
+
};
|
|
1827
|
+
//# sourceMappingURL=plugin-BQgMiHxa.js.map
|